diff --git a/configs/word.json b/configs/word.json index a6050b3d62..4ff2f757a8 100644 --- a/configs/word.json +++ b/configs/word.json @@ -343,6 +343,7 @@ "pdf/src/viewer.js", "pdf/src/file.js", "pdf/src/pdfSearch.js", + "pdf/src/previews.js", "pdf/src/forms/formActions.js", "pdf/src/forms/base/base.js", "pdf/src/forms/apiFunctions.js", diff --git a/pdf/api.js b/pdf/api.js index b85af20136..a8b6e2b151 100644 --- a/pdf/api.js +++ b/pdf/api.js @@ -1858,6 +1858,14 @@ oDoc.BlurActiveObject(); AscCommon.DocumentEditorApi.prototype.asc_Save.call(this, isAutoSave, isIdle); }; + PDFEditorApi.prototype._onEndLoadSdk = function() { + AscCommon.DocumentEditorApi.prototype._onEndLoadSdk.call(this); + + this.stampAnnotPreviewManager = new AscPDF.StampAnnotPreviewManager(); + }; + PDFEditorApi.prototype.asc_getPropertyEditorStamps = function() { + return this.stampAnnotPreviewManager.getStampPreviews(); + }; PDFEditorApi.prototype._coAuthoringInitEnd = function() { AscCommon.DocumentEditorApi.prototype._coAuthoringInitEnd.call(this); @@ -2864,6 +2872,7 @@ // stamp PDFEditorApi.prototype['AddStampAnnot'] = PDFEditorApi.prototype.AddStampAnnot; + PDFEditorApi.prototype['asc_getPropertyEditorStamps'] = PDFEditorApi.prototype.asc_getPropertyEditorStamps; // freetext PDFEditorApi.prototype['AddFreeTextAnnot'] = PDFEditorApi.prototype.AddFreeTextAnnot; diff --git a/pdf/src/previews.js b/pdf/src/previews.js new file mode 100644 index 0000000000..e8e0627120 --- /dev/null +++ b/pdf/src/previews.js @@ -0,0 +1,112 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2024 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ + +"use strict"; + +( + /** + * @param {Window} window + * @param {undefined} undefined + */ + function(window, undefined) { + + function StampAnnotPreviewManager() { + } + + StampAnnotPreviewManager.prototype.clear = function() { + this.StampStyles.length = 0; + }; + + StampAnnotPreviewManager.prototype.getStampStyles = function() { + if (this.StampStyles.length === 0) { + this.generateStampStyles(); + } + return this.StampStyles; + }; + + StampAnnotPreviewManager.prototype.createCanvas = function(width, height) { + var oCanvas = document.createElement('canvas'); + oCanvas.width = AscCommon.AscBrowser.convertToRetinaValue(width, true); + oCanvas.height = AscCommon.AscBrowser.convertToRetinaValue(height, true); + return oCanvas; + }; + + StampAnnotPreviewManager.prototype.getStampRender = function(sType) { + let oDoc = Asc.editor.getPDFDoc(); + let oTextDrawer = oDoc.CreateStampRender(sType); + + return oTextDrawer; + }; + + StampAnnotPreviewManager.prototype.getStampPreview = function(type) { + return this.getStampPreviewCanvas(type).toDataURL("image/png"); + }; + StampAnnotPreviewManager.prototype.getStampPreviews = function() { + let aRet = []; + + let _t = this; + Object.entries(AscPDF.STAMP_XML).forEach(function(entry) { + let type = entry[0]; + + let oPreview = {}; + oPreview["Type"] = type; + oPreview["Image"] = _t.getStampPreview(type); + aRet.push(oPreview); + }); + + return aRet; + }; + StampAnnotPreviewManager.prototype.getStampPreviewCanvas = function(type) { + let oTextDrawer = this.getStampRender(type); + if (!oTextDrawer) { + return ""; + } + + let pxWidth = oTextDrawer.Width * g_dKoef_mm_to_pix; + let pxHeight = oTextDrawer.Height * g_dKoef_mm_to_pix; + + let canvas = this.createCanvas(pxWidth, pxHeight); + let ctx = canvas.getContext('2d'); + let graphics = new AscCommon.CGraphics(); + + graphics.init(ctx, canvas.width, canvas.height, oTextDrawer.Width, oTextDrawer.Height); + graphics.m_oFontManager = AscCommon.g_fontManager; + graphics.transform(1, 0, 0, 1, 0, 0); + + oTextDrawer.m_aStack[0].draw(graphics); + return canvas; + }; + + //----------------------------------------------------------export---------------------------------------------------- + window['AscPDF'] = window['AscPDF'] || {}; + window['AscPDF'].StampAnnotPreviewManager = StampAnnotPreviewManager; + })(window); \ No newline at end of file diff --git a/previews.js b/previews.js new file mode 100644 index 0000000000..e8e0627120 --- /dev/null +++ b/previews.js @@ -0,0 +1,112 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2024 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ + +"use strict"; + +( + /** + * @param {Window} window + * @param {undefined} undefined + */ + function(window, undefined) { + + function StampAnnotPreviewManager() { + } + + StampAnnotPreviewManager.prototype.clear = function() { + this.StampStyles.length = 0; + }; + + StampAnnotPreviewManager.prototype.getStampStyles = function() { + if (this.StampStyles.length === 0) { + this.generateStampStyles(); + } + return this.StampStyles; + }; + + StampAnnotPreviewManager.prototype.createCanvas = function(width, height) { + var oCanvas = document.createElement('canvas'); + oCanvas.width = AscCommon.AscBrowser.convertToRetinaValue(width, true); + oCanvas.height = AscCommon.AscBrowser.convertToRetinaValue(height, true); + return oCanvas; + }; + + StampAnnotPreviewManager.prototype.getStampRender = function(sType) { + let oDoc = Asc.editor.getPDFDoc(); + let oTextDrawer = oDoc.CreateStampRender(sType); + + return oTextDrawer; + }; + + StampAnnotPreviewManager.prototype.getStampPreview = function(type) { + return this.getStampPreviewCanvas(type).toDataURL("image/png"); + }; + StampAnnotPreviewManager.prototype.getStampPreviews = function() { + let aRet = []; + + let _t = this; + Object.entries(AscPDF.STAMP_XML).forEach(function(entry) { + let type = entry[0]; + + let oPreview = {}; + oPreview["Type"] = type; + oPreview["Image"] = _t.getStampPreview(type); + aRet.push(oPreview); + }); + + return aRet; + }; + StampAnnotPreviewManager.prototype.getStampPreviewCanvas = function(type) { + let oTextDrawer = this.getStampRender(type); + if (!oTextDrawer) { + return ""; + } + + let pxWidth = oTextDrawer.Width * g_dKoef_mm_to_pix; + let pxHeight = oTextDrawer.Height * g_dKoef_mm_to_pix; + + let canvas = this.createCanvas(pxWidth, pxHeight); + let ctx = canvas.getContext('2d'); + let graphics = new AscCommon.CGraphics(); + + graphics.init(ctx, canvas.width, canvas.height, oTextDrawer.Width, oTextDrawer.Height); + graphics.m_oFontManager = AscCommon.g_fontManager; + graphics.transform(1, 0, 0, 1, 0, 0); + + oTextDrawer.m_aStack[0].draw(graphics); + return canvas; + }; + + //----------------------------------------------------------export---------------------------------------------------- + window['AscPDF'] = window['AscPDF'] || {}; + window['AscPDF'].StampAnnotPreviewManager = StampAnnotPreviewManager; + })(window); \ No newline at end of file