From bded5e4dfc1eb3d77767a983b8c965c1ef11d0a9 Mon Sep 17 00:00:00 2001 From: Nikita Khromov Date: Tue, 29 Apr 2025 16:14:53 +0700 Subject: [PATCH] [pdf] Fix replace page content method --- common/apiBase_plugins.js | 4 +-- pdf/api_plugins.js | 49 +++++--------------------- pdf/src/document.js | 73 ++++++++++++++++++++++++++++----------- 3 files changed, 62 insertions(+), 64 deletions(-) diff --git a/common/apiBase_plugins.js b/common/apiBase_plugins.js index bab0605954..241a1e1aca 100644 --- a/common/apiBase_plugins.js +++ b/common/apiBase_plugins.js @@ -307,7 +307,7 @@ if (!AscCommon.g_clipboardBase) return null; - if (!this.canEdit() || this.isPdfEditor()) + if (!this.canEdit()) return null; let _elem = document.getElementById("pmpastehtml"); @@ -321,7 +321,7 @@ if (this.editorId === AscCommon.c_oEditorId.Word || this.editorId === AscCommon.c_oEditorId.Presentation) { let textPr = this.get_TextProps(); - if (textPr) { + if (textPr && textPr.TextPr) { if (undefined !== textPr.TextPr.FontSize) _elem.style.fontSize = textPr.TextPr.FontSize + "pt"; diff --git a/pdf/api_plugins.js b/pdf/api_plugins.js index 62da13bd24..5f121e8025 100644 --- a/pdf/api_plugins.js +++ b/pdf/api_plugins.js @@ -145,52 +145,19 @@ Api.prototype["pluginMethod_ReplacePageContent"] = function(nPage, oParams) { let oDoc = this.getPDFDoc(); + let oPageInfo = oDoc.GetPageInfo(nPage); + if (null == oPageInfo || (oPageInfo && (oPageInfo.IsDeleteLock() || oPageInfo.IsRecognized())) || true == this.isRestrictionView()) { + return false; + } + if (oParams['xmls']) { return oDoc.EditPage(nPage, oParams['xmls']); } else if (oParams['html']) { - let _elem = document.getElementById("pmpastehtml"); - if (_elem) - return; - - window.g_asc_plugins && window.g_asc_plugins.setPluginMethodReturnAsync(); - - _elem = document.createElement("div"); - _elem.id = "pmpastehtml"; - _elem.style.color = "rgb(0,0,0)"; - _elem.innerHTML = oParams['html']; - document.body.appendChild(_elem); - - this.incrementCounterLongAction(); - let b_old_save_format = AscCommon.g_clipboardBase.bSaveFormat; - AscCommon.g_clipboardBase.bSaveFormat = false; - let _t = this; - - let currRestrictionType = this.restrictions; - this.asc_setRestriction(Asc.c_oAscRestrictionType.None); - this.asc_PasteData(AscCommon.c_oAscClipboardDataFormat.HtmlElement, _elem, undefined, undefined, undefined, - function () { - let oPageInfo = oDoc.GetPageInfo(nPage); - oPageInfo.SetRecognized(true); - - _t.decrementCounterLongAction(); - - let fCallback = function () { - document.body.removeChild(_elem); - _elem = null; - AscCommon.g_clipboardBase.bSaveFormat = b_old_save_format; - }; - if (_t.checkLongActionCallback(fCallback, null)) { - fCallback(); - } - window.g_asc_plugins && window.g_asc_plugins.onPluginMethodReturn(true); - _t.asc_setRestriction(currRestrictionType); - } - ); - - - return true; + this['pluginMethod_PasteHtml'](oParams['html']); } + + return true; }; })(window); diff --git a/pdf/src/document.js b/pdf/src/document.js index 05cc1f3fd7..456ddf9ad9 100644 --- a/pdf/src/document.js +++ b/pdf/src/document.js @@ -5131,30 +5131,61 @@ var CPresentation = CPresentation || function(){}; return pasteObj.Drawing; }); - aDrToPaste.forEach(function(drawing, index) { - let oXfrm = drawing.getXfrm(); - let oPos = oThis.private_computeDrawingAddingPos(nCurPage, oXfrm.extX, oXfrm.extY); - oXfrm.setOffX(oPos.x); - oXfrm.setOffY(oPos.y); + if (false == Asc.editor.replacePageContentAction) { + aDrToPaste.forEach(function(drawing, index) { + let oXfrm = drawing.getXfrm(); + let oPos = oThis.private_computeDrawingAddingPos(nCurPage, oXfrm.extX, oXfrm.extY); + oXfrm.setOffX(oPos.x); + oXfrm.setOffY(oPos.y); + + // чуть-чуть смещаем при вставке, чтобы было видно вставленную фигуру + let nShift = oController.getDrawingsPasteShift([drawing]); + + if (nShift > 0) { + oXfrm.shift(nShift, nShift); + } + + oThis.AddDrawing(drawing, oThis.GetCurPage()); + + if (drawing.IsGraphicFrame()) { + oController.Check_GraphicFrameRowHeight(drawing); + } + + if (index == 0) { + oThis.SetMouseDownObject(drawing); + } + drawing.select(oController, nCurPage); + }); + } + else { + let nCurYmm = 10; + let nPageW = oThis.GetPageWidthMM(nCurPage); - // чуть-чуть смещаем при вставке, чтобы было видно вставленную фигуру - let nShift = oController.getDrawingsPasteShift([drawing]); + aDrToPaste.forEach(function(drawing, index) { + let oXfrm = drawing.getXfrm(); + if (drawing.IsShape()) { + oXfrm.setExtX(nPageW * 0.95); + drawing.checkExtentsByDocContent(); + } + + oXfrm.setOffX(nPageW * 0.05 / 2); + oXfrm.setOffY(nCurYmm); - if (nShift > 0) { - oXfrm.shift(nShift, nShift); - } + nCurYmm += oXfrm.extY + 2; - oThis.AddDrawing(drawing, oThis.GetCurPage()); - - if (drawing.IsGraphicFrame()) { - oController.Check_GraphicFrameRowHeight(drawing); - } - - if (index == 0) { - oThis.SetMouseDownObject(drawing); - } - drawing.select(oController, nCurPage); - }); + oThis.AddDrawing(drawing, oThis.GetCurPage()); + + if (drawing.IsGraphicFrame()) { + oController.Check_GraphicFrameRowHeight(drawing); + } + + if (index == 0) { + oThis.SetMouseDownObject(drawing); + } + + drawing.select(oController, nCurPage); + }); + } bResult = true; }