diff --git a/DesktopEditor/fontengine/js/allfonts/module.js b/DesktopEditor/fontengine/js/allfonts/module.js index a5dcfdd166..1a6bc5c684 100644 --- a/DesktopEditor/fontengine/js/allfonts/module.js +++ b/DesktopEditor/fontengine/js/allfonts/module.js @@ -1,5 +1,5 @@ /* - * (c) Copyright Ascensio System SIA 2010-2023 + * (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) diff --git a/DesktopEditor/fontengine/js/cpp/text.cpp b/DesktopEditor/fontengine/js/cpp/text.cpp index 6679455e8e..9857242738 100644 --- a/DesktopEditor/fontengine/js/cpp/text.cpp +++ b/DesktopEditor/fontengine/js/cpp/text.cpp @@ -1,5 +1,5 @@ /* - * (c) Copyright Ascensio System SIA 2010-2023 + * (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) diff --git a/DesktopEditor/fontengine/js/engine/module_native.js b/DesktopEditor/fontengine/js/engine/module_native.js index 6c28f43e00..27d3e765e3 100644 --- a/DesktopEditor/fontengine/js/engine/module_native.js +++ b/DesktopEditor/fontengine/js/engine/module_native.js @@ -1,5 +1,5 @@ /* - * (c) Copyright Ascensio System SIA 2010-2023 + * (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) diff --git a/DesktopEditor/fontengine/js/module.js b/DesktopEditor/fontengine/js/module.js index cf71f0ed43..6207edc44d 100644 --- a/DesktopEditor/fontengine/js/module.js +++ b/DesktopEditor/fontengine/js/module.js @@ -1,5 +1,5 @@ /* - * (c) Copyright Ascensio System SIA 2010-2023 + * (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) @@ -761,6 +761,14 @@ function onLoadFontsModule(window, undefined) { return this.engine["getImageBlob"](path); }; + /** + * Get image file raw data. this memory was copied and detach from archive. + * @returns {Uint8Array} + */ + ZLib.prototype.getImageBuffer = function(path) + { + return this.engine["getImageBuffer"](path); + }; /** * Get all file paths in archive * @returns {Array} @@ -772,10 +780,84 @@ function onLoadFontsModule(window, undefined) AscCommon.ZLib = ZLib; + function ZlibImageBlobs() + { + this.url2BlobUrl = {}; + this.blobUrl2Data = {}; + this.url2Base64 = {}; + + this.nativeBlobCounter = 1; + } + ZlibImageBlobs.prototype.getBlobUrl = function(path, zip) + { + if (this.url2BlobUrl[path]) + return this.url2BlobUrl[path]; + + let result = zip.getImageBuffer(path); + if (result == null) + return ""; + + let blobUrl = ""; + let blobType = AscCommon.openXml.GetMimeType((24 !== result.type) ? AscCommon.GetFileExtension(path) : "svg"); + + if (window["NATIVE_EDITOR_ENJINE"]) + { + blobUrl = "blob:internal-image" + this.nativeBlobCounter++; + } + else + { + try + { + let blob = new Blob([result.data], {type: blobType}); + blobUrl = window.URL.createObjectURL(blob); + } + catch (e) + { + blobUrl = "error"; + AscCommon.consoleLog("ERROR: Image blob was not loaded"); + } + } + + this.blobUrl2Data[blobUrl] = result; + this.url2BlobUrl[path] = blobUrl; + return blobUrl; + }; + ZlibImageBlobs.prototype.getImageBase64 = function(url) + { + if (this.url2Base64[url]) + return this.url2Base64[url]; + + let obj = this.blobUrl2Data[url]; + if (!obj) + return url; + + let header = ""; + switch (obj.type) + { + case 3: + header = "data:image/jpeg;base64,"; + break; + case 24: + header = "data:image/svg+xml;base64,"; + break; + case 4: + default: + header = "data:image/png;base64,"; + } + + this.url2Base64[url] = header + AscCommon.Base64.encode(obj.data); + return this.url2Base64[url]; + }; + + window["AscCommon"].g_oDocumentBlobUrls = new ZlibImageBlobs(); + if (AscCommon["CZLibEngineJS"]) AscCommon["CZLibEngineJS"].prototype["isModuleInit"] = true; - window.nativeZlibEngine = new ZLib(); + if (window["NATIVE_EDITOR_ENJINE"]) + window["InitNativeZLib"] = function() { window.nativeZlibEngine = new ZLib(); }; + else + window.nativeZlibEngine = new ZLib(); function Hyphenation() { diff --git a/DesktopEditor/graphics/pro/js/qt/raster/pro_Fonts_empty.cpp b/DesktopEditor/graphics/pro/js/qt/raster/pro_Fonts_empty.cpp index 5f06695023..1cb3a84884 100644 --- a/DesktopEditor/graphics/pro/js/qt/raster/pro_Fonts_empty.cpp +++ b/DesktopEditor/graphics/pro/js/qt/raster/pro_Fonts_empty.cpp @@ -1,5 +1,5 @@ /* - * (c) Copyright Ascensio System SIA 2010-2023 + * (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) diff --git a/DesktopEditor/graphics/pro/js/qt/raster/pro_Graphics_empty.cpp b/DesktopEditor/graphics/pro/js/qt/raster/pro_Graphics_empty.cpp index aeae76a4cc..12c2f84ffd 100644 --- a/DesktopEditor/graphics/pro/js/qt/raster/pro_Graphics_empty.cpp +++ b/DesktopEditor/graphics/pro/js/qt/raster/pro_Graphics_empty.cpp @@ -1,5 +1,5 @@ /* - * (c) Copyright Ascensio System SIA 2010-2023 + * (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)