From b6b43c1b3325f80bdac9524bdc5a8d4045813c5e Mon Sep 17 00:00:00 2001 From: Vladimir Privezenov Date: Thu, 19 Jan 2023 03:15:59 +0300 Subject: [PATCH 1/9] Fix undo in smartArts --- common/Charts/charts.js | 2 ++ common/Drawings/Format/Data.js | 6 +++- common/Drawings/Format/DrawingContent.js | 22 ++++++++------- common/Drawings/Format/Shape.js | 35 ++++++++++++++++++++++-- common/collaborativeHistory.js | 20 ++++++++++++-- word/Editor/Paragraph.js | 21 ++++++++++++++ word/Editor/Run.js | 14 ++++++++++ word/Editor/RunChanges.js | 6 +++- 8 files changed, 110 insertions(+), 16 deletions(-) diff --git a/common/Charts/charts.js b/common/Charts/charts.js index 8e6fff2b33..1624b0458e 100644 --- a/common/Charts/charts.js +++ b/common/Charts/charts.js @@ -833,6 +833,8 @@ ChartPreviewManager.prototype.getChartPreviews = function(chartType, arrId, bEmp SmartArtPreviewDrawer.prototype.getSmartArt = function(nSmartArtType) { return AscFormat.ExecuteNoHistory(function () { const oSmartArt = new AscFormat.SmartArt(); + oSmartArt.bNeedUpdatePosition = false; + oSmartArt.bFirstRecalculate = false; const oApi = Asc.editor || editor; oSmartArt.bForceSlideTransform = true; oSmartArt.fillByPreset(nSmartArtType, true); diff --git a/common/Drawings/Format/Data.js b/common/Drawings/Format/Data.js index 15be2275b4..c27f691def 100644 --- a/common/Drawings/Format/Data.js +++ b/common/Drawings/Format/Data.js @@ -1659,7 +1659,7 @@ Because of this, the display is sometimes not correct. } Point.prototype.getShape = function () { - if (this.parent && this.parent.parent instanceof CShape) { + if (this.parent && this.parent.parent instanceof AscFormat.CShape) { return this.parent.parent; } } @@ -10048,6 +10048,7 @@ Because of this, the display is sometimes not correct. CBaseFormatObject.call(this); this.shapePoint = null; this.contentPoint = []; + this.maxFontSize = null; } InitClass(ShapeSmartArtInfo, CBaseFormatObject, AscDFH.historyitem_type_ShapeSmartArtInfo); @@ -10071,6 +10072,9 @@ Because of this, the display is sometimes not correct. nIdx === this.contentPoint.length - 1 ? this.contentPoint.pop() : this.contentPoint.splice(nIdx, 1); } } + ShapeSmartArtInfo.prototype.setMaxFontSize = function (oPr) { + this.maxFontSize = oPr; + } changesFactory[AscDFH.historyitem_SmartArtColorsDef] = CChangeObject; changesFactory[AscDFH.historyitem_SmartArtDrawing] = CChangeObject; diff --git a/common/Drawings/Format/DrawingContent.js b/common/Drawings/Format/DrawingContent.js index aef6fbfac8..ba72de0447 100644 --- a/common/Drawings/Format/DrawingContent.js +++ b/common/Drawings/Format/DrawingContent.js @@ -788,17 +788,19 @@ } } }; - CDrawingDocContent.prototype.Is_Empty = function() + CDrawingDocContent.prototype.Is_Empty = function(bDefault) { - if (this.isDocumentContentInSmartArtShape()) { - var oShape = this.Parent.parent; - var contentPoints = oShape.getSmartArtPointContent(); - if (contentPoints && contentPoints.length !== 0) { - var isPhldr = contentPoints.every(function (point) { - return point && point.prSet && point.prSet.phldr; - }); - if (isPhldr) { - return true; + if (!bDefault) { + if (this.isDocumentContentInSmartArtShape()) { + var oShape = this.Parent.parent; + var contentPoints = oShape.getSmartArtPointContent(); + if (contentPoints && contentPoints.length !== 0) { + var isPhldr = contentPoints.every(function (point) { + return point && point.prSet && point.prSet.phldr; + }); + if (isPhldr) { + return true; + } } } } diff --git a/common/Drawings/Format/Shape.js b/common/Drawings/Format/Shape.js index 204fab9ea3..ba5392f3fa 100644 --- a/common/Drawings/Format/Shape.js +++ b/common/Drawings/Format/Shape.js @@ -3299,12 +3299,12 @@ CShape.prototype.canAddButtonPlaceholder = function () { return (this.parent && (this.parent.getObjectType() === AscDFH.historyitem_type_Slide) || this.isObjectInSmartArt()); }; -CShape.prototype.isEmptyPlaceholder = function () { +CShape.prototype.isEmptyPlaceholder = function (bDefaultEmpty) { if (this.isObjectInSmartArt()) { if (this.isPlaceholderInSmartArt()) { if (this.txBody) { if (this.txBody.content) { - return this.txBody.content.Is_Empty(); + return this.txBody.content.Is_Empty(bDefaultEmpty); } return true; } @@ -4628,6 +4628,37 @@ var aScales = [25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70 this.recalculateContentWitCompiledPr(); } }; + CShape.prototype.resetSmartArtMaxFontSize = function () { + const oSmartArtInfo = this.getSmartArtInfo(); + if (oSmartArtInfo) { + delete oSmartArtInfo.maxFontSize; + } + }; + CShape.prototype.correctSmartArtUndo = function () { + if (this.isObjectInSmartArt()) { + this.group.group.fitFontSize(); + const oSmartArtInfo = this.getSmartArtInfo(); + if (oSmartArtInfo) { + if (!this.isEmptyPlaceholder(true)) { + if (this.isPlaceholderInSmartArt()) { + const oContent = this.getDocContent && this.getDocContent(); + const arrPointContent = this.getSmartArtPointContent(); + const bIsNotEmptyShape = oContent.Content.some(function (paragraph) { + return !paragraph.Is_Empty({SkipEnd: true, SkipPlcHldr: false}); + }); + if (bIsNotEmptyShape) { + arrPointContent.forEach(function (point) { + point.prSet.setPhldr(false); + }) + this.txBody.content2 = null; + } + } + } + } + this.setTruthFontSizeInSmartArt(); + } + + }; CShape.prototype.getInsets = function (properties) { const oBodyPr = properties.bodyPr || this.getBodyPr && this.getBodyPr(); diff --git a/common/collaborativeHistory.js b/common/collaborativeHistory.js index 9418eb8617..349d272a46 100644 --- a/common/collaborativeHistory.js +++ b/common/collaborativeHistory.js @@ -430,6 +430,7 @@ var bAddSlides = false; var mapAddedSlides = {}; var mapCommentsToDelete = {}; + const mapSmartArtShapes = {}; for (let nIndex = 0, nCount = arrReverseChanges.length; nIndex < nCount; ++nIndex) { @@ -446,9 +447,15 @@ } else if (oClass.IsParagraphContentElement && true === oClass.IsParagraphContentElement() && true === oChange.IsContentChange() && oClass.GetParagraph()) { - mapParagraphs[oClass.GetParagraph().Get_Id()] = oClass.GetParagraph(); + const oParagraph = oClass.GetParagraph(); + mapParagraphs[oParagraph.Get_Id()] = oParagraph; if (oClass instanceof AscCommonWord.ParaRun) mapRuns[oClass.Get_Id()] = oClass; + const oSmartArtShape = oParagraph.IsInsideSmartArtShape(true); + if (oSmartArtShape) + { + mapSmartArtShapes[oSmartArtShape.Get_Id()] = oSmartArtShape; + } } else if (oClass && oClass.parent && oClass.parent instanceof AscCommonWord.ParaDrawing) { @@ -461,6 +468,11 @@ else if (oClass instanceof AscCommonWord.ParaRun) { mapRuns[oClass.Get_Id()] = oClass; + const oSmartArtShape = oClass.IsInsideSmartArtShape(true); + if (oSmartArtShape) + { + mapSmartArtShapes[oSmartArtShape.Get_Id()] = oSmartArtShape; + } } else if (oClass instanceof AscCommonWord.CTable) { @@ -624,7 +636,11 @@ } } } - + for (let sId in mapSmartArtShapes) + { + const oSmartArtShape = mapSmartArtShapes[sId]; + oSmartArtShape.correctSmartArtUndo(); + } for (var sId in mapTables) { var oTable = mapTables[sId]; diff --git a/word/Editor/Paragraph.js b/word/Editor/Paragraph.js index b8cbc9521d..3e89b48ade 100644 --- a/word/Editor/Paragraph.js +++ b/word/Editor/Paragraph.js @@ -9451,6 +9451,27 @@ Paragraph.prototype.IsInText = function(X, Y, CurPage) return null; }; +/** + * Is paragraph inside SmartArt + * @param bReturnShape {boolean} + * @returns {boolean|null|AscFormat.CShape} + */ +Paragraph.prototype.IsInsideSmartArtShape = function (bReturnShape) +{ + const oShape = this.Parent.Is_DrawingShape(true); + if (oShape) + { + if (oShape.isObjectInSmartArt()) + { + if (bReturnShape) + { + return oShape; + } + return !!oShape; + } + } + return bReturnShape ? null : false; +}; Paragraph.prototype.IsUseInDocument = function(Id) { if (undefined !== Id && null !== Id) diff --git a/word/Editor/Run.js b/word/Editor/Run.js index a67914bf03..4f0d9d8dff 100644 --- a/word/Editor/Run.js +++ b/word/Editor/Run.js @@ -1095,6 +1095,20 @@ ParaRun.prototype.IsOnlyCommonTextScript = function() return isCommonScript; }; +/** + * Is a run inside smartArt + * @param [bReturnSmartArtShape] {boolean} + * @returns {boolean|null|AscFormat.CShape} + */ +ParaRun.prototype.IsInsideSmartArtShape = function (bReturnSmartArtShape) +{ + const oParagraph = this.GetParagraph(); + if (oParagraph) + { + return oParagraph.IsInsideSmartArtShape(bReturnSmartArtShape); + } + return bReturnSmartArtShape ? null : false; +}; /** * Проверяем, предзназначен ли данный ран чисто для математических формул. * @returns {boolean} diff --git a/word/Editor/RunChanges.js b/word/Editor/RunChanges.js index 090cef6cf0..b9966c26b9 100644 --- a/word/Editor/RunChanges.js +++ b/word/Editor/RunChanges.js @@ -629,7 +629,11 @@ CChangesRunFontSize.prototype.private_SetValue = function(Value) { var oRun = this.Class; oRun.Pr.FontSize = Value; - + const oSmartArtShape = oRun.IsInsideSmartArtShape(true); + if (oSmartArtShape) + { + oSmartArtShape.resetSmartArtMaxFontSize(); + } oRun.Recalc_CompiledPr(true); oRun.private_UpdateTrackRevisionOnChangeTextPr(false); }; From 1d2912208a1d694e853a360097a531b6a88481c9 Mon Sep 17 00:00:00 2001 From: Vladimir Privezenov Date: Thu, 19 Jan 2023 11:24:34 +0300 Subject: [PATCH 2/9] For bug 59888 --- common/Drawings/Format/Data.js | 12 +- common/Drawings/Format/Shape.js | 213 +++++++++++++++++++++----------- 2 files changed, 147 insertions(+), 78 deletions(-) diff --git a/common/Drawings/Format/Data.js b/common/Drawings/Format/Data.js index c27f691def..3d68ef5a1f 100644 --- a/common/Drawings/Format/Data.js +++ b/common/Drawings/Format/Data.js @@ -10117,6 +10117,7 @@ Because of this, the display is sometimes not correct. this.bNeedUpdatePosition = true; this.calcGeometry = null; + this.bFirstRecalculate = true; } InitClass(SmartArt, CGroupShape, AscDFH.historyitem_type_SmartArt); @@ -10182,10 +10183,9 @@ Because of this, the display is sometimes not correct. editor.ShowParaMarks = false; } CGroupShape.prototype.recalculate.call(this); - if (this.group && this.bNeedUpdatePosition) { - this.bNeedUpdatePosition = false; - var group = this.getMainGroup(); - group.updateCoordinatesAfterInternalResize(); + if (this.bFirstRecalculate) { + this.bFirstRecalculate = false; + this.fitFontSize(); } if (oldParaMarks) { editor.ShowParaMarks = oldParaMarks; @@ -10258,8 +10258,8 @@ Because of this, the display is sometimes not correct. SmartArt.prototype.fitFontSize = function () { this.spTree[0] && this.spTree[0].spTree.forEach(function (oShape) { - oShape.recalculateContent2() - oShape.findFitFontSizeForSmartArt(); + oShape.setTruthFontSizeInSmartArt(); + oShape.recalculateContentWitCompiledPr(); }); }; diff --git a/common/Drawings/Format/Shape.js b/common/Drawings/Format/Shape.js index ba5392f3fa..39483bb727 100644 --- a/common/Drawings/Format/Shape.js +++ b/common/Drawings/Format/Shape.js @@ -2249,12 +2249,14 @@ CShape.prototype.getTextRect = function () { var diffY = 0; if (oSmartArt.group) { if (bForceSlideTransform || (this.parent && this.parent.getObjectType() === AscDFH.historyitem_type_Slide || this.worksheet)) { - var mainGroup = oSmartArt.group.getRelativePosition(); - diffX = mainGroup.x; - diffY = mainGroup.y; + const oMainGroupRelativePosition = oSmartArt.group.getRelativePosition(); + diffX = oMainGroupRelativePosition.x; + diffY = oMainGroupRelativePosition.y; } else { - diffX = oSmartArt.bounds.x; - diffY = oSmartArt.bounds.y; + const oMainGroup = oSmartArt.getMainGroup(); + const oMainGroupRelativePosition = oSmartArt.getRelativePosition(); + diffX = oMainGroupRelativePosition.x - oMainGroup.x; + diffY = oMainGroupRelativePosition.y - oMainGroup.y; } } var oRect = this.getTextRect(); @@ -4575,7 +4577,7 @@ var aScales = [25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70 } }; - CShape.prototype.setFontSizeInSmartArt = function (fontSize) { + CShape.prototype.getFirstFontSize = function () { let currentFontSize; if (this.txBody && this.txBody.content) { this.txBody.content.CheckRunContent(function (paraRun) { @@ -4592,12 +4594,15 @@ var aScales = [25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70 } }); } - const bOldApplyToAll = this.txBody.content.ApplyToAll; - this.txBody.content.ApplyToAll = true; - this.txBody.content.AddToParagraph(new AscCommonWord.ParaTextPr({FontSize: (Math.min(fontSize, 300))})); - this.txBody.content.ApplyToAll = bOldApplyToAll; + } + return currentFontSize; + } - const oBodyPr = this.getBodyPr && this.getBodyPr(); + CShape.prototype.setFontSizeInSmartArt = function (fontSize) { + const oContent = this.txBody && this.txBody.content; + if (this.txBody && oContent) { + const currentFontSize = this.getFirstFontSize(); + const oBodyPr = this.txBody.getBodyPr(); if (oBodyPr) { const paddings = {}; const pointContent = this.getSmartArtPointContent(); @@ -4625,7 +4630,11 @@ var aScales = [25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70 // While there is no recalculation, we consider new insets as a dependency on the previous font size. this.setPaddings(paddings, {bNotCopyToPoints: true}); } - this.recalculateContentWitCompiledPr(); + const bOldApplyToAll = oContent.ApplyToAll; + oContent.ApplyToAll = true; + oContent.AddToParagraph(new AscCommonWord.ParaTextPr({FontSize: (Math.min(fontSize, 300))})); + oContent.ApplyToAll = bOldApplyToAll; + this.recalculateContent2(); } }; CShape.prototype.resetSmartArtMaxFontSize = function () { @@ -4757,10 +4766,34 @@ var aScales = [25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70 const sizesOfTextRectContent = this.getTextRectContentHW(); const vert = this.txBody && this.txBody.bodyPr.vert; - if (vert === AscFormat.nVertTTvert270 || vert === AscFormat.nVertTTvert) { - return this.contentHeight > sizesOfTextRectContent.width; + + let nContentHeight; + if (this.txBody && this.txBody.content2) { + this.recalculateContent(); + nContentHeight = this.contentHeight; + } else { + this.recalculateContent(); + nContentHeight = this.contentHeight; } - return this.contentHeight > sizesOfTextRectContent.height; + if (vert === AscFormat.nVertTTvert270 || vert === AscFormat.nVertTTvert || vert === AscFormat.nVertTTeaVert) { + return nContentHeight >= sizesOfTextRectContent.width; + } + return nContentHeight >= sizesOfTextRectContent.height; + }; + CShape.prototype.compareWidthOfBoundsTextInSmartArt = function (bMax) { + const oContent = this.getCurrentDocContentInSmartArt(); + const sizesOfTextRectContent = this.getTextRectContentHW(); + const vert = this.txBody && this.txBody.bodyPr.vert; + let widthOfContent = oContent.RecalculateMinMaxContentWidth(); + if (bMax) { + widthOfContent = widthOfContent.Max; + } else { + widthOfContent = widthOfContent.Min; + } + if (vert === AscFormat.nVertTTvert270 || vert === AscFormat.nVertTTvert || vert === AscFormat.nVertTTeaVert) { + return widthOfContent > sizesOfTextRectContent.height; + } + return widthOfContent > sizesOfTextRectContent.width; }; CShape.prototype.checkFitContentForSmartArt = function () { // почему-то у майков не подбирается шрифт для ширины, если вставлено только уравнение @@ -4779,43 +4812,39 @@ var aScales = [25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70 return false; }; CShape.prototype.findFitFontSizeForSmartArt = function (bMax) { - const MAX_FONT_SIZE = 65; - - const content = this.getCurrentDocContentInSmartArt(); - if (content) { - const scalesForSmartArt = Array((MAX_FONT_SIZE - 4) > 0 ? MAX_FONT_SIZE - 4 : 1).fill(0).map(function (e, ind) { - return ind + 5; - }); - let a = 0; - let b = scalesForSmartArt.length - 1; - let averageAmount = Math.floor((a + b) / 2); - const bNeedCheckWidth = this.checkFitContentForSmartArt(); - while (a !== averageAmount && b !== averageAmount) { - this.setFontSizeInSmartArt(scalesForSmartArt[averageAmount]); - let bCheck; - if (bNeedCheckWidth) { - let widthOfContent = content.RecalculateMinMaxContentWidth(); - if (bMax) { - widthOfContent = widthOfContent.Max; + return AscFormat.ExecuteNoHistory(function () { + const MAX_FONT_SIZE = 65; + const content = this.getCurrentDocContentInSmartArt(); + if (content) { + const nOldFontSize = this.getFirstFontSize(); + const scalesForSmartArt = Array((MAX_FONT_SIZE - 4) > 0 ? MAX_FONT_SIZE - 4 : 1).fill(0).map(function (e, ind) { + return ind + 5; + }); + let a = 0; + let b = scalesForSmartArt.length - 1; + let averageAmount = Math.floor((a + b) / 2); + const bNeedCheckWidth = this.checkFitContentForSmartArt(); + while (a !== averageAmount && b !== averageAmount) { + this.setFontSizeInSmartArt(scalesForSmartArt[averageAmount]); + let bCheck; + if (bNeedCheckWidth) { + bCheck = this.compareWidthOfBoundsTextInSmartArt(bMax) || this.compareHeightOfBoundsTextInSmartArt(); } else { - widthOfContent = widthOfContent.Min; + bCheck = this.compareHeightOfBoundsTextInSmartArt(); } - bCheck = widthOfContent > this.contentWidth || this.compareHeightOfBoundsTextInSmartArt(); - } else { - bCheck = this.compareHeightOfBoundsTextInSmartArt(); - } - if (bCheck) { - b = averageAmount; - } else { - a = averageAmount; + if (bCheck) { + b = averageAmount; + } else { + a = averageAmount; + } + averageAmount = Math.floor((a + b) / 2); } - averageAmount = Math.floor((a + b) / 2); + this.setFontSizeInSmartArt(nOldFontSize); + return scalesForSmartArt[averageAmount]; } - this.setFontSizeInSmartArt(scalesForSmartArt[averageAmount]); - return scalesForSmartArt[averageAmount]; - } - return MAX_FONT_SIZE; + return MAX_FONT_SIZE; + }, this, []); }; CShape.prototype.getShapesForFitText = function () { @@ -4823,38 +4852,78 @@ var aScales = [25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70 }; CShape.prototype.setTruthFontSizeInSmartArt = function () { - var shapes = this.getShapesForFitText(); - var maxFontSize = 65; - var arrOfFonts = shapes.reduce(function (arr, shape) { - var contentPoints = shape.getSmartArtPointContent(); - var isNotPlaceholder = contentPoints.every(function (point) { - return point && point.prSet && point.prSet.phldrT && !point.prSet.custT && !point.prSet.phldr; - }); - if (isNotPlaceholder) { - arr.push(shape.findFitFontSizeForSmartArt()); - } - return arr; - }, [maxFontSize]); + const arrMainContentPoints = this.getSmartArtPointContent(); + if (!arrMainContentPoints) return; + const bIsFitText = arrMainContentPoints.every(function (point) { + return point && point.prSet && point.prSet.phldrT && !point.prSet.custT && !point.prSet.phldr; + }); + let bIsPlaceholder = arrMainContentPoints.every(function (point) { + return point && point.prSet && point.prSet.phldrT && !point.prSet.custT && point.prSet.phldr; + }); - var minFont = Math.min.apply(Math, arrOfFonts); - shapes.forEach(function (shape) { - var contentPoints = shape.getSmartArtPointContent(); - var isPlaceholder = contentPoints.every(function (point) { + if (!bIsFitText && !bIsPlaceholder) { + return; + } + const oSmartArtInfo = this.getSmartArtInfo(); + if (oSmartArtInfo) { + oSmartArtInfo.setMaxFontSize(this.findFitFontSizeForSmartArt()); + } + const arrShapes = this.getShapesForFitText(); + const arrPlaceholders = []; + const arrFitText = []; + for (let i = 0; i < arrShapes.length; i += 1) { + const oShape = arrShapes[i]; + var contentPoints = oShape.getSmartArtPointContent(); + const isPlaceholder = contentPoints.every(function (point) { return point && point.prSet && point.prSet.phldrT && !point.prSet.custT && point.prSet.phldr; }); - var isFitText = contentPoints.every(function (point) { - return point && point.prSet && point.prSet.phldrT && !point.prSet.custT; + const isNotPlaceholder = contentPoints.every(function (point) { + return point && point.prSet && point.prSet.phldrT && !point.prSet.custT && !point.prSet.phldr; }); - if (isPlaceholder) { - var minFontSizeForPlaceholder = shape.findFitFontSizeForSmartArt(); - if (minFontSizeForPlaceholder > minFont) { - shape.setFontSizeInSmartArt(minFont); + arrPlaceholders.push(oShape); + } else if (isNotPlaceholder) { + arrFitText.push(oShape); + } + } + + let nFitFontSize = 65; + for (let i = 0; i < arrFitText.length; i += 1) { + const oShape = arrFitText[i]; + const oShapeSmartArtInfo = oShape.getSmartArtInfo(); + if (oShapeSmartArtInfo) { + if (!AscFormat.isRealNumber(oShapeSmartArtInfo.maxFontSize)) { + oShapeSmartArtInfo.setMaxFontSize(oShape.findFitFontSizeForSmartArt()); + } + if (oShapeSmartArtInfo.maxFontSize < nFitFontSize) { + nFitFontSize = oShapeSmartArtInfo.maxFontSize; } - } else if (isFitText) { - shape.setFontSizeInSmartArt(minFont); } - }); + } + for (let i = 0; i < arrFitText.length; i += 1) { + const oShape = arrFitText[i]; + const nCurrentFontSize = oShape.getFirstFontSize(); + if (nCurrentFontSize !== nFitFontSize) { + oShape.setFontSizeInSmartArt(nFitFontSize); + } + } + + for (let i = 0; i < arrPlaceholders.length; i += 1) { + const oShape = arrPlaceholders[i]; + const nCurrentFontSize = oShape.getFirstFontSize(); + const oPlaceholderSmartArtInfo = oShape.getSmartArtInfo(); + if (oPlaceholderSmartArtInfo) { + if (!AscFormat.isRealNumber(oPlaceholderSmartArtInfo.maxFontSize)) { + oPlaceholderSmartArtInfo.setMaxFontSize(oShape.findFitFontSizeForSmartArt()); + } + const nPlaceholderFontSize = Math.min(oPlaceholderSmartArtInfo.maxFontSize, nFitFontSize); + if (nCurrentFontSize !== nPlaceholderFontSize) { + oShape.setFontSizeInSmartArt(nPlaceholderFontSize); + } + } else if (nCurrentFontSize !== nFitFontSize) { + oShape.setFontSizeInSmartArt(nFitFontSize); + } + } }; CShape.prototype.checkExtentsByDocContent = function(bForce, bNeedRecalc) From a87f06254b81dde532e38a6d783ea303d56a649c Mon Sep 17 00:00:00 2001 From: Vladimir Privezenov Date: Thu, 19 Jan 2023 11:37:16 +0300 Subject: [PATCH 3/9] Fix fit font size in lists preview --- common/editorscommon.js | 5 ++++- word/Drawing/DrawingDocument.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common/editorscommon.js b/common/editorscommon.js index aee3ecce6e..03fd6bb6b2 100644 --- a/common/editorscommon.js +++ b/common/editorscommon.js @@ -10444,6 +10444,7 @@ oNewShape.extX = width_px * AscCommon.g_dKoef_pix_to_mm; oNewShape.extY = height_px * AscCommon.g_dKoef_pix_to_mm; oNewShape.contentWidth = oNewShape.extX; + oNewShape.setPaddings({Left: 0, Top: 0, Right: 0, Bottom: 0}); const par = oNewShape.txBody.content.GetAllParagraphs()[0]; par.MoveCursorToStartPos(); @@ -10462,7 +10463,9 @@ let parW = par.RecalculateMinMaxContentWidth().Max; if (parW > oNewShape.contentWidth) { - oNewShape.findFitFontSizeForSmartArt(true); + const nNewFontSize = oNewShape.findFitFontSizeForSmartArt(true); + oNewShape.setFontSizeInSmartArt(nNewFontSize); + oNewShape.recalculateContentWitCompiledPr(); parW = par.RecalculateMinMaxContentWidth().Max; } diff --git a/word/Drawing/DrawingDocument.js b/word/Drawing/DrawingDocument.js index ce6352aa0e..e73504e3ba 100644 --- a/word/Drawing/DrawingDocument.js +++ b/word/Drawing/DrawingDocument.js @@ -7291,6 +7291,7 @@ function CDrawingDocument() shape.contentWidth = shape.extX; shape.createTextBody(); var par = shape.txBody.content.GetAllParagraphs()[0]; + shape.setPaddings({Left: 0, Top: 0, Right: 0, Bottom: 0}); par.MoveCursorToStartPos(); @@ -7307,7 +7308,9 @@ function CDrawingDocument() var parW = par.RecalculateMinMaxContentWidth().Max; if (parW > shape.contentWidth) { - shape.findFitFontSizeForSmartArt(true); + const nNewFontSize = shape.findFitFontSizeForSmartArt(true); + shape.setFontSizeInSmartArt(nNewFontSize); + shape.recalculateContentWitCompiledPr(); parW = par.RecalculateMinMaxContentWidth().Max; } From 7d5d5fb32b7447e15c769fa1184c4e0cecedbfe2 Mon Sep 17 00:00:00 2001 From: Vladimir Privezenov Date: Thu, 19 Jan 2023 18:27:54 +0300 Subject: [PATCH 4/9] For bug 59888 --- common/Drawings/Format/Shape.js | 14 ++++++++------ word/Editor/Document.js | 19 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/common/Drawings/Format/Shape.js b/common/Drawings/Format/Shape.js index 39483bb727..1f109f15ad 100644 --- a/common/Drawings/Format/Shape.js +++ b/common/Drawings/Format/Shape.js @@ -4598,7 +4598,7 @@ var aScales = [25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70 return currentFontSize; } - CShape.prototype.setFontSizeInSmartArt = function (fontSize) { + CShape.prototype.setFontSizeInSmartArt = function (fontSize, bSkipRecalculateContent2) { const oContent = this.txBody && this.txBody.content; if (this.txBody && oContent) { const currentFontSize = this.getFirstFontSize(); @@ -4632,9 +4632,11 @@ var aScales = [25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70 } const bOldApplyToAll = oContent.ApplyToAll; oContent.ApplyToAll = true; - oContent.AddToParagraph(new AscCommonWord.ParaTextPr({FontSize: (Math.min(fontSize, 300))})); + oContent.AddToParagraph(new AscCommonWord.ParaTextPr({FontSize: (Math.min(fontSize, 300))}), false); oContent.ApplyToAll = bOldApplyToAll; - this.recalculateContent2(); + if (!bSkipRecalculateContent2) { + this.recalculateContent2(); + } } }; CShape.prototype.resetSmartArtMaxFontSize = function () { @@ -4904,7 +4906,7 @@ var aScales = [25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70 const oShape = arrFitText[i]; const nCurrentFontSize = oShape.getFirstFontSize(); if (nCurrentFontSize !== nFitFontSize) { - oShape.setFontSizeInSmartArt(nFitFontSize); + oShape.setFontSizeInSmartArt(nFitFontSize, true); } } @@ -4918,10 +4920,10 @@ var aScales = [25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70 } const nPlaceholderFontSize = Math.min(oPlaceholderSmartArtInfo.maxFontSize, nFitFontSize); if (nCurrentFontSize !== nPlaceholderFontSize) { - oShape.setFontSizeInSmartArt(nPlaceholderFontSize); + oShape.setFontSizeInSmartArt(nPlaceholderFontSize, true); } } else if (nCurrentFontSize !== nFitFontSize) { - oShape.setFontSizeInSmartArt(nFitFontSize); + oShape.setFontSizeInSmartArt(nFitFontSize, true); } } }; diff --git a/word/Editor/Document.js b/word/Editor/Document.js index dcfa8cf1c7..1c53079e09 100644 --- a/word/Editor/Document.js +++ b/word/Editor/Document.js @@ -17549,10 +17549,10 @@ CDocument.prototype.Replace_CompositeText = function(arrCharCodes) } this.Start_SilentMode(); - this.private_RemoveCompositeText(this.CompositeInput.Length); + this.private_RemoveCompositeText(this.CompositeInput.Length, true); for (var nIndex = 0, nCount = arrCharCodes.length; nIndex < nCount; ++nIndex) { - this.private_AddCompositeText(arrCharCodes[nIndex]); + this.private_AddCompositeText(arrCharCodes[nIndex], true); } this.End_SilentMode(false); @@ -17655,7 +17655,7 @@ CDocument.prototype.Get_MaxCursorPosInCompositeText = function() return this.CompositeInput.Length; }; -CDocument.prototype.private_AddCompositeText = function(nCharCode) +CDocument.prototype.private_AddCompositeText = function(nCharCode, bSkipCheckExtents) { var oRun = this.CompositeInput.Run; var nPos = this.CompositeInput.Pos + this.CompositeInput.Length; @@ -17680,12 +17680,14 @@ CDocument.prototype.private_AddCompositeText = function(nCharCode) var oForm = oRun.GetParentForm(); if (oForm && oForm.IsAutoFitContent()) this.CheckFormAutoFit(oForm); - - this.CheckCurrentTextObjectExtends(); + if (!bSkipCheckExtents) + { + this.CheckCurrentTextObjectExtends(); + } this.Recalculate(); this.UpdateSelection(); }; -CDocument.prototype.private_RemoveCompositeText = function(nCount) +CDocument.prototype.private_RemoveCompositeText = function(nCount, bSkipCheckExtents) { var oRun = this.CompositeInput.Run; var nPos = this.CompositeInput.Pos + this.CompositeInput.Length; @@ -17698,7 +17700,10 @@ CDocument.prototype.private_RemoveCompositeText = function(nCount) if (oForm && oForm.IsAutoFitContent()) this.CheckFormAutoFit(oForm); - this.CheckCurrentTextObjectExtends(); + if (!bSkipCheckExtents) + { + this.CheckCurrentTextObjectExtends(); + } this.Recalculate(); this.UpdateSelection(); }; From 5e8a69638a60fab8e1de37c370545b1767d47fde Mon Sep 17 00:00:00 2001 From: Vladimir Privezenov Date: Mon, 23 Jan 2023 00:55:50 +0300 Subject: [PATCH 5/9] Think about transform --- common/Drawings/Format/Data.js | 29 +++++++++++++++++------------ common/Drawings/Format/Shape.js | 1 - common/apiBase.js | 2 ++ word/Editor/Paragraph.js | 2 +- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/common/Drawings/Format/Data.js b/common/Drawings/Format/Data.js index c45e45e699..e070217f98 100644 --- a/common/Drawings/Format/Data.js +++ b/common/Drawings/Format/Data.js @@ -10201,18 +10201,22 @@ Because of this, the display is sometimes not correct. } SmartArt.prototype.recalculate = function () { - var oldParaMarks = editor && editor.ShowParaMarks; - if (oldParaMarks) { - editor.ShowParaMarks = false; - } - CGroupShape.prototype.recalculate.call(this); - if (this.bFirstRecalculate) { - this.bFirstRecalculate = false; - this.fitFontSize(); - } - if (oldParaMarks) { - editor.ShowParaMarks = oldParaMarks; - } + if(this.bDeleted) + return; + AscFormat.ExecuteNoHistory(function () { + var oldParaMarks = editor && editor.ShowParaMarks; + if (oldParaMarks) { + editor.ShowParaMarks = false; + } + CGroupShape.prototype.recalculate.call(this); + if (this.bFirstRecalculate) { + this.bFirstRecalculate = false; + this.fitFontSize(); + } + if (oldParaMarks) { + editor.ShowParaMarks = oldParaMarks; + } + }, this, []); } SmartArt.prototype.decorateParaDrawing = function (drawingObjects) { @@ -10281,6 +10285,7 @@ Because of this, the display is sometimes not correct. SmartArt.prototype.fitFontSize = function () { this.spTree[0] && this.spTree[0].spTree.forEach(function (oShape) { + oShape.recalculateContentWitCompiledPr(); oShape.setTruthFontSizeInSmartArt(); oShape.recalculateContentWitCompiledPr(); }); diff --git a/common/Drawings/Format/Shape.js b/common/Drawings/Format/Shape.js index 1f109f15ad..8c8abcf205 100644 --- a/common/Drawings/Format/Shape.js +++ b/common/Drawings/Format/Shape.js @@ -4666,7 +4666,6 @@ var aScales = [25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70 } } } - this.setTruthFontSizeInSmartArt(); } }; diff --git a/common/apiBase.js b/common/apiBase.js index 874bcedd7e..9e08d90fe9 100644 --- a/common/apiBase.js +++ b/common/apiBase.js @@ -1208,6 +1208,8 @@ } oSmartArt.fitToPageSize(); oSmartArt.fitFontSize(); + oSmartArt.recalculateBounds(); + const oParaDrawing = oSmartArt.decorateParaDrawing(oController); oSmartArt.setXfrmByParent(); if (oController) { diff --git a/word/Editor/Paragraph.js b/word/Editor/Paragraph.js index 366440d25b..1976a8cdba 100644 --- a/word/Editor/Paragraph.js +++ b/word/Editor/Paragraph.js @@ -9471,7 +9471,7 @@ Paragraph.prototype.IsInText = function(X, Y, CurPage) */ Paragraph.prototype.IsInsideSmartArtShape = function (bReturnShape) { - const oShape = this.Parent.Is_DrawingShape(true); + const oShape = this.Parent && this.Parent.Is_DrawingShape(true); if (oShape) { if (oShape.isObjectInSmartArt()) From 6561c7d1d2710261ad0e6ae819485545ebabb69b Mon Sep 17 00:00:00 2001 From: Sergey Luzyanin Date: Mon, 23 Jan 2023 21:40:07 +0530 Subject: [PATCH 6/9] fix calculation of text matrix after --- word/Editor/GraphicObjects/Format/GroupPrototype.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/word/Editor/GraphicObjects/Format/GroupPrototype.js b/word/Editor/GraphicObjects/Format/GroupPrototype.js index 2a82395d33..88948be7ad 100644 --- a/word/Editor/GraphicObjects/Format/GroupPrototype.js +++ b/word/Editor/GraphicObjects/Format/GroupPrototype.js @@ -225,9 +225,9 @@ CGroupShape.prototype.handleUpdatePosition = function() this.addToRecalculate(); for(var i = 0; i < this.spTree.length; ++i) { - if(this.spTree[i].recalcTransform) + if(this.spTree[i].handleUpdatePosition) { - this.spTree[i].recalcTransform(); + this.spTree[i].handleUpdatePosition(); } } }; From de573272449369f450b772c57e87b1bf5e8e37a8 Mon Sep 17 00:00:00 2001 From: Sergey Luzyanin Date: Wed, 25 Jan 2023 09:31:19 +0530 Subject: [PATCH 7/9] fix text transform calculation after collaborative undo --- common/collaborativeHistory.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/common/collaborativeHistory.js b/common/collaborativeHistory.js index 349d272a46..7f80ab69fe 100644 --- a/common/collaborativeHistory.js +++ b/common/collaborativeHistory.js @@ -385,10 +385,7 @@ // return false; // } - if(oChange.CheckCorrect && !oChange.CheckCorrect()) - { - return false; - } + return true; }; CCollaborativeHistory.prototype.CreateLocalHistoryPointByReverseChanges = function(reverseChanges) From cbdde310429a1598a868c6a2e87322900399463c Mon Sep 17 00:00:00 2001 From: Sergey Luzyanin Date: Wed, 25 Jan 2023 13:10:08 +0530 Subject: [PATCH 8/9] fix crash on undo in coauthoring --- common/Drawings/Format/ChartSpace.js | 1 + common/Drawings/Format/Data.js | 1 + common/Drawings/Format/GraphicFrame.js | 5 ++++- common/Drawings/Format/GroupShape.js | 5 ++++- common/Drawings/Format/Image.js | 5 ++++- common/Drawings/Format/Shape.js | 5 ++++- common/collaborativeHistory.js | 19 ++++++++++++++++--- 7 files changed, 34 insertions(+), 7 deletions(-) diff --git a/common/Drawings/Format/ChartSpace.js b/common/Drawings/Format/ChartSpace.js index 01253499d3..887cf23621 100644 --- a/common/Drawings/Format/ChartSpace.js +++ b/common/Drawings/Format/ChartSpace.js @@ -531,6 +531,7 @@ var GLOBAL_PATH_COUNT = 0; oClass.bDeleted = value; }; drawingsChangesMap[AscDFH.historyitem_ChartSpace_SetParent] = function(oClass, value) { + oClass.oldParent = oClass.parent; oClass.parent = value; }; drawingsChangesMap[AscDFH.historyitem_ChartSpace_SetChart] = function(oClass, value) { diff --git a/common/Drawings/Format/Data.js b/common/Drawings/Format/Data.js index e070217f98..f5cb72dc94 100644 --- a/common/Drawings/Format/Data.js +++ b/common/Drawings/Format/Data.js @@ -10125,6 +10125,7 @@ Because of this, the display is sometimes not correct. oClass.styleDef = value; }; drawingsChangesMap[AscDFH.historyitem_SmartArtParent] = function (oClass, value) { + oClass.oldParent = oClass.parent; oClass.parent = value; }; diff --git a/common/Drawings/Format/GraphicFrame.js b/common/Drawings/Format/GraphicFrame.js index 8d805aaf82..498d539c47 100644 --- a/common/Drawings/Format/GraphicFrame.js +++ b/common/Drawings/Format/GraphicFrame.js @@ -52,7 +52,10 @@ var History = AscCommon.History; } }; window['AscDFH'].drawingsChangesMap[AscDFH.historyitem_GraphicFrameSetSetNvSpPr] = function(oClass, value){oClass.nvGraphicFramePr = value;}; - window['AscDFH'].drawingsChangesMap[AscDFH.historyitem_GraphicFrameSetSetParent] = function(oClass, value){oClass.parent = value;}; + window['AscDFH'].drawingsChangesMap[AscDFH.historyitem_GraphicFrameSetSetParent] = function(oClass, value){ + oClass.oldParent = oClass.parent; + oClass.parent = value; + }; window['AscDFH'].drawingsChangesMap[AscDFH.historyitem_GraphicFrameSetSetGroup] = function(oClass, value){oClass.group = value;}; AscDFH.changesFactory[AscDFH.historyitem_GraphicFrameSetSpPr] = AscDFH.CChangesDrawingsObject; diff --git a/common/Drawings/Format/GroupShape.js b/common/Drawings/Format/GroupShape.js index ef9688caa8..00e07cce2e 100644 --- a/common/Drawings/Format/GroupShape.js +++ b/common/Drawings/Format/GroupShape.js @@ -60,7 +60,10 @@ var CShape = AscFormat.CShape; AscDFH.drawingsChangesMap[AscDFH.historyitem_GroupShapeSetNvGrpSpPr] = function(oClass, value){oClass.nvGrpSpPr = value;}; AscDFH.drawingsChangesMap[AscDFH.historyitem_GroupShapeSetSpPr] = function(oClass, value){oClass.spPr = value;}; - AscDFH.drawingsChangesMap[AscDFH.historyitem_GroupShapeSetParent] = function(oClass, value){oClass.parent = value;}; + AscDFH.drawingsChangesMap[AscDFH.historyitem_GroupShapeSetParent] = function(oClass, value){ + oClass.oldParent = oClass.parent; + oClass.parent = value; + }; AscDFH.drawingsChangesMap[AscDFH.historyitem_GroupShapeSetGroup] = function(oClass, value){oClass.group = value;}; AscDFH.drawingContentChanges[AscDFH.historyitem_GroupShapeAddToSpTree] = AscDFH.drawingContentChanges[AscDFH.historyitem_GroupShapeRemoveFromSpTree] = function(oClass){return oClass.spTree;}; diff --git a/common/Drawings/Format/Image.js b/common/Drawings/Format/Image.js index e94aa76024..679ed5cb1e 100644 --- a/common/Drawings/Format/Image.js +++ b/common/Drawings/Format/Image.js @@ -65,7 +65,10 @@ var isRealObject = AscCommon.isRealObject; } } }; - AscDFH.drawingsChangesMap[AscDFH.historyitem_ImageShapeSetParent] = function(oClass, value){oClass.parent = value;}; + AscDFH.drawingsChangesMap[AscDFH.historyitem_ImageShapeSetParent] = function(oClass, value){ + oClass.oldParent = oClass.parent; + oClass.parent = value; + }; AscDFH.drawingsChangesMap[AscDFH.historyitem_ImageShapeSetGroup] = function(oClass, value){oClass.group = value;}; AscDFH.drawingsChangesMap[AscDFH.historyitem_ImageShapeSetStyle] = function(oClass, value){oClass.style = value;}; AscDFH.drawingsChangesMap[AscDFH.historyitem_ImageShapeSetNvPicPr] = function(oClass, value){oClass.nvPicPr = value;}; diff --git a/common/Drawings/Format/Shape.js b/common/Drawings/Format/Shape.js index 8c8abcf205..d78ce17b93 100644 --- a/common/Drawings/Format/Shape.js +++ b/common/Drawings/Format/Shape.js @@ -969,7 +969,10 @@ function SetXfrmFromMetrics(oDrawing, metrics) AscDFH.drawingsChangesMap[AscDFH.historyitem_ShapeSetTextBoxContent] = function(oClass, value){oClass.textBoxContent = value;}; AscDFH.drawingsChangesMap[AscDFH.historyitem_ShapeSetBodyPr] = function(oClass, value){oClass.bodyPr = value;}; AscDFH.drawingsChangesMap[AscDFH.historyitem_AutoShapes_SetBFromSerialize] = function(oClass, value){oClass.fromSerialize = value;}; - AscDFH.drawingsChangesMap[AscDFH.historyitem_ShapeSetParent] = function(oClass, value){oClass.parent = value;}; + AscDFH.drawingsChangesMap[AscDFH.historyitem_ShapeSetParent] = function(oClass, value){ + oClass.oldParent = oClass.parent; + oClass.parent = value; + }; AscDFH.drawingsChangesMap[AscDFH.historyitem_ShapeSetGroup] = function(oClass, value){oClass.group = value;}; AscDFH.drawingsChangesMap[AscDFH.historyitem_ShapeSetWordShape] = function(oClass, value){oClass.bWordShape = value;}; AscDFH.drawingsChangesMap[AscDFH.historyitem_ShapeSetSignature] = function(oClass, value){ diff --git a/common/collaborativeHistory.js b/common/collaborativeHistory.js index 7f80ab69fe..46186f5cca 100644 --- a/common/collaborativeHistory.js +++ b/common/collaborativeHistory.js @@ -385,7 +385,7 @@ // return false; // } - + return true; }; CCollaborativeHistory.prototype.CreateLocalHistoryPointByReverseChanges = function(reverseChanges) @@ -580,9 +580,17 @@ { oShape.parent.removeFromSpTreeById(oShape.Get_Id()); } - else if (AscCommonWord.ParaDrawing && (oShape.parent instanceof AscCommonWord.ParaDrawing)) + else if (AscCommonWord.ParaDrawing) { - mapDrawings[oShape.parent.Get_Id()] = oShape.parent; + if(oShape.parent instanceof AscCommonWord.ParaDrawing) + { + mapDrawings[oShape.parent.Get_Id()] = oShape.parent; + } + if(oShape.oldParent && oShape.oldParent instanceof AscCommonWord.ParaDrawing) + { + mapDrawings[oShape.oldParent.Get_Id()] = oShape.oldParent; + oShape.oldParent = undefined; + } } } else @@ -602,6 +610,11 @@ if (!oDrawing.CheckCorrect()) { var oParentParagraph = oDrawing.Get_ParentParagraph(); + let oParentRun = oDrawing.Get_Run(); + if(oParentRun) + { + mapRuns[oParentRun.Id] = oParentRun; + } oDrawing.PreDelete(); oDrawing.Remove_FromDocument(false); if (oParentParagraph) From 18def1c331a0b0853596f266f6082dd5dc0f0099 Mon Sep 17 00:00:00 2001 From: Vladimir Privezenov Date: Wed, 25 Jan 2023 16:31:57 +0300 Subject: [PATCH 9/9] For bug 59888 --- common/Drawings/Format/Shape.js | 1 + word/Editor/Paragraph.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/common/Drawings/Format/Shape.js b/common/Drawings/Format/Shape.js index d78ce17b93..167e0e7adc 100644 --- a/common/Drawings/Format/Shape.js +++ b/common/Drawings/Format/Shape.js @@ -4845,6 +4845,7 @@ var aScales = [25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70 averageAmount = Math.floor((a + b) / 2); } this.setFontSizeInSmartArt(nOldFontSize); + this.recalculateContent(); return scalesForSmartArt[averageAmount]; } return MAX_FONT_SIZE; diff --git a/word/Editor/Paragraph.js b/word/Editor/Paragraph.js index 1976a8cdba..d1687a26b4 100644 --- a/word/Editor/Paragraph.js +++ b/word/Editor/Paragraph.js @@ -9474,7 +9474,7 @@ Paragraph.prototype.IsInsideSmartArtShape = function (bReturnShape) const oShape = this.Parent && this.Parent.Is_DrawingShape(true); if (oShape) { - if (oShape.isObjectInSmartArt()) + if (oShape.isObjectInSmartArt && oShape.isObjectInSmartArt()) { if (bReturnShape) {