diff --git a/DesktopEditor/graphics/pro/js/drawingfile.json b/DesktopEditor/graphics/pro/js/drawingfile.json index f9a3f1c582..059921ba32 100644 --- a/DesktopEditor/graphics/pro/js/drawingfile.json +++ b/DesktopEditor/graphics/pro/js/drawingfile.json @@ -31,6 +31,7 @@ "_GetStructure", "_InitializeFontsBin", "_InitializeFontsBase64", + "_InitializeFontsRanges", "_SetFontBinary", "_IsFontBinaryExist", "_DestroyTextInfo", diff --git a/DesktopEditor/graphics/pro/js/qt/nativegraphics.pro b/DesktopEditor/graphics/pro/js/qt/nativegraphics.pro index 0a827e4124..b70cab5222 100644 --- a/DesktopEditor/graphics/pro/js/qt/nativegraphics.pro +++ b/DesktopEditor/graphics/pro/js/qt/nativegraphics.pro @@ -8,7 +8,7 @@ CONFIG += console CONFIG += object_parallel_to_source CONFIG -= app_bundle -DEFINES += TEST_AS_EXECUTABLE \ +DEFINES += TEST_CPP_BINARY \ GRAPHICS_NO_USE_DYNAMIC_LIBRARY \ BUILDING_WASM_MODULE \ CMAP_USE_MEMORY \ @@ -651,6 +651,7 @@ HEADERS +=\ $$PDF_ROOT_DIR/SrcReader/Adaptors.h \ $$PDF_ROOT_DIR/SrcReader/MemoryUtils.h \ $$PDF_ROOT_DIR/SrcReader/GfxClip.h \ + $$PDF_ROOT_DIR/SrcReader/FontsWasm.h \ $$PDF_ROOT_DIR/PdfReader.h \ $$PDF_ROOT_DIR/PdfFile.h diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js index f154d698b6..9ff22d254a 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js @@ -32,354 +32,409 @@ (function(window, undefined) { - function getMemoryPathIE(name) - { - if (self["AscViewer"] && self["AscViewer"]["baseUrl"]) - return self["AscViewer"]["baseUrl"] + name; - return name; - } + function getMemoryPathIE(name) + { + if (self["AscViewer"] && self["AscViewer"]["baseUrl"]) + return self["AscViewer"]["baseUrl"] + name; + return name; + } - var FS = undefined; + var FS = undefined; - //desktop_fetch + //desktop_fetch - //polyfill + //polyfill - //string_utf8 + //string_utf8 - //module + //module - self.drawingFileCurrentPageIndex = -1; - self.fontStreams = {}; - self.drawingFile = null; + self.drawingFileCurrentPageIndex = -1; + self.fontStreams = {}; + self.drawingFile = null; - function CBinaryReader(data, start, size) - { - this.data = data; - this.pos = start; - this.limit = start + size; - } - CBinaryReader.prototype.readInt = function() - { - var val = this.data[this.pos] | this.data[this.pos + 1] << 8 | this.data[this.pos + 2] << 16 | this.data[this.pos + 3] << 24; - this.pos += 4; - return val; - }; - CBinaryReader.prototype.readDouble = function() - { - return this.readInt() / 100; - }; - CBinaryReader.prototype.readString = function() - { - var len = this.readInt(); - var val = String.prototype.fromUtf8(this.data, this.pos, len); - this.pos += len; - return val; - }; - CBinaryReader.prototype.readData = function() - { - var len = this.readInt(); - var val = this.data.slice(this.pos, this.pos + len); - this.pos += len; - return val; - }; - CBinaryReader.prototype.isValid = function() - { - return (this.pos < this.limit) ? true : false; - }; - CBinaryReader.prototype.Skip = function(nPos) - { - this.pos += nPos; - }; + function CBinaryReader(data, start, size) + { + this.data = data; + this.pos = start; + this.limit = start + size; + } + CBinaryReader.prototype.readInt = function() + { + var val = this.data[this.pos] | this.data[this.pos + 1] << 8 | this.data[this.pos + 2] << 16 | this.data[this.pos + 3] << 24; + this.pos += 4; + return val; + }; + CBinaryReader.prototype.readDouble = function() + { + return this.readInt() / 100; + }; + CBinaryReader.prototype.readString = function() + { + var len = this.readInt(); + var val = String.prototype.fromUtf8(this.data, this.pos, len); + this.pos += len; + return val; + }; + CBinaryReader.prototype.readData = function() + { + var len = this.readInt(); + var val = this.data.slice(this.pos, this.pos + len); + this.pos += len; + return val; + }; + CBinaryReader.prototype.isValid = function() + { + return (this.pos < this.limit) ? true : false; + }; + CBinaryReader.prototype.Skip = function(nPos) + { + this.pos += nPos; + }; - function CFile() - { - this.nativeFile = 0; - this.stream = -1; - this.stream_size = 0; - this.type = -1; - this.pages = []; - this.info = null; - this._isNeedPassword = false; - } + function CBinaryWriter() + { + this.size = 100000; + this.dataSize = 0; + this.buffer = new Uint8Array(this.size); + } + CBinaryWriter.prototype.checkAlloc = function(addition) + { + if ((this.dataSize + addition) <= this.size) + return; - CFile.prototype["loadFromData"] = function(arrayBuffer) - { - var data = new Uint8Array(arrayBuffer); - var _stream = Module["_malloc"](data.length); - Module["HEAP8"].set(data, _stream); - this.nativeFile = Module["_Open"](_stream, data.length, 0); - var error = Module["_GetErrorCode"](this.nativeFile); - this.stream = _stream; - this.stream_size = data.length; - this.type = Module["_GetType"](_stream, data.length); - self.drawingFile = this; - this.getInfo(); - this._isNeedPassword = (4 === error) ? true : false; + let newSize = Math.max(this.size * 2, this.size + addition); + let newBuffer = new Uint8Array(newSize); + newBuffer.set(this.buffer, 0); - // 0 - ok - // 4 - password - // else - error - return error; - }; - CFile.prototype["loadFromDataWithPassword"] = function(password) - { - if (0 != this.nativeFile) - Module["_Close"](this.nativeFile); + this.size = newSize; + this.buffer = newBuffer; + }; + CBinaryWriter.prototype.writeUint = function(value) + { + this.checkAlloc(4); + let val = (value>2147483647)?value-4294967296:value; + this.buffer[this.dataSize++] = (val) & 0xFF; + this.buffer[this.dataSize++] = (val >>> 8) & 0xFF; + this.buffer[this.dataSize++] = (val >>> 16) & 0xFF; + this.buffer[this.dataSize++] = (val >>> 24) & 0xFF; + }; + CBinaryWriter.prototype.writeString = function(value) + { + let valueUtf8 = value.toUtf8(); + this.checkAlloc(valueUtf8.length); + this.buffer.set(valueUtf8, this.dataSize); + this.dataSize += valueUtf8.length; + }; - var passBuffer = password.toUtf8(); - var passPointer = Module["_malloc"](passBuffer.length); - Module["HEAP8"].set(passBuffer, passPointer); - this.nativeFile = Module["_Open"](this.stream, this.stream_size, passPointer); - Module["_free"](passPointer); - var error = Module["_GetErrorCode"](this.nativeFile); - this.type = Module["_GetType"](this.stream, this.stream_size); - self.drawingFile = this; - this.getInfo(); - this._isNeedPassword = (4 === error) ? true : false; + function CFile() + { + this.nativeFile = 0; + this.stream = -1; + this.stream_size = 0; + this.type = -1; + this.pages = []; + this.info = null; + this._isNeedPassword = false; + } - // 0 - ok - // 4 - password - // else - error - return error; - }; - CFile.prototype["isNeedPassword"] = function() - { - return this._isNeedPassword; - }; - CFile.prototype["isNeedCMap"] = function() - { - if (!this.nativeFile) - return false; + CFile.prototype["loadFromData"] = function(arrayBuffer) + { + var data = new Uint8Array(arrayBuffer); + var _stream = Module["_malloc"](data.length); + Module["HEAP8"].set(data, _stream); + this.nativeFile = Module["_Open"](_stream, data.length, 0); + var error = Module["_GetErrorCode"](this.nativeFile); + this.stream = _stream; + this.stream_size = data.length; + this.type = Module["_GetType"](_stream, data.length); + self.drawingFile = this; + this.getInfo(); + this._isNeedPassword = (4 === error) ? true : false; - var isNeed = Module["_IsNeedCMap"](this.nativeFile); - return (isNeed === 1) ? true : false; - }; - CFile.prototype["setCMap"] = function(memoryBuffer) - { - if (!this.nativeFile) - return; + // 0 - ok + // 4 - password + // else - error + return error; + }; + CFile.prototype["loadFromDataWithPassword"] = function(password) + { + if (0 != this.nativeFile) + Module["_Close"](this.nativeFile); - var pointer = Module["_malloc"](memoryBuffer.length); - Module.HEAP8.set(memoryBuffer, pointer); - Module["_SetCMapData"](this.nativeFile, pointer, memoryBuffer.length); - }; - CFile.prototype["getInfo"] = function() - { - if (!this.nativeFile) - return false; + var passBuffer = password.toUtf8(); + var passPointer = Module["_malloc"](passBuffer.length); + Module["HEAP8"].set(passBuffer, passPointer); + this.nativeFile = Module["_Open"](this.stream, this.stream_size, passPointer); + Module["_free"](passPointer); + var error = Module["_GetErrorCode"](this.nativeFile); + this.type = Module["_GetType"](this.stream, this.stream_size); + self.drawingFile = this; + this.getInfo(); + this._isNeedPassword = (4 === error) ? true : false; - var _info = Module["_GetInfo"](this.nativeFile); - if (_info == 0) - return false; + // 0 - ok + // 4 - password + // else - error + return error; + }; + CFile.prototype["isNeedPassword"] = function() + { + return this._isNeedPassword; + }; + CFile.prototype["isNeedCMap"] = function() + { + if (!this.nativeFile) + return false; - var lenArray = new Int32Array(Module["HEAP8"].buffer, _info, 4); - if (lenArray == null) - return false; + var isNeed = Module["_IsNeedCMap"](this.nativeFile); + return (isNeed === 1) ? true : false; + }; + CFile.prototype["setCMap"] = function(memoryBuffer) + { + if (!this.nativeFile) + return; - var len = lenArray[0]; - len -= 4; - if (len <= 0) - return false; + var pointer = Module["_malloc"](memoryBuffer.length); + Module.HEAP8.set(memoryBuffer, pointer); + Module["_SetCMapData"](this.nativeFile, pointer, memoryBuffer.length); + }; + CFile.prototype["getInfo"] = function() + { + if (!this.nativeFile) + return false; - var buffer = new Uint8Array(Module["HEAP8"].buffer, _info + 4, len); - var reader = new CBinaryReader(buffer, 0, len); + var _info = Module["_GetInfo"](this.nativeFile); + if (_info == 0) + return false; - var _pages = reader.readInt(); - for (var i = 0; i < _pages; i++) - { - var rec = {}; - rec["W"] = reader.readInt(); - rec["H"] = reader.readInt(); - rec["Dpi"] = reader.readInt(); - rec.fonts = []; - rec.text = null; - this.pages.push(rec); - } - var json_info = reader.readString(); - try - { - this.info = JSON.parse(json_info); - } catch(err) {} + var lenArray = new Int32Array(Module["HEAP8"].buffer, _info, 4); + if (lenArray == null) + return false; - Module["_free"](_info); - return this.pages.length > 0; - }; - CFile.prototype["close"] = function() - { - Module["_Close"](this.nativeFile); - this.nativeFile = 0; - this.pages = []; - this.info = null; - if (this.stream > 0) - Module["_free"](this.stream); - this.stream = -1; - self.drawingFile = null; - }; + var len = lenArray[0]; + len -= 4; + if (len <= 0) + return false; - CFile.prototype["getPages"] = function() - { - return this.pages; - }; + var buffer = new Uint8Array(Module["HEAP8"].buffer, _info + 4, len); + var reader = new CBinaryReader(buffer, 0, len); - CFile.prototype["getDocumentInfo"] = function() - { - return this.info; - }; + var _pages = reader.readInt(); + for (var i = 0; i < _pages; i++) + { + var rec = {}; + rec["W"] = reader.readInt(); + rec["H"] = reader.readInt(); + rec["Dpi"] = reader.readInt(); + rec.fonts = []; + rec.text = null; + this.pages.push(rec); + } + var json_info = reader.readString(); + try + { + this.info = JSON.parse(json_info); + } catch(err) {} - CFile.prototype["getPagePixmap"] = function(pageIndex, width, height, backgroundColor) - { - if (this.pages[pageIndex].fonts.length > 0) - { - // ждем загрузки шрифтов для этой страницы - return null; - } + Module["_free"](_info); + return this.pages.length > 0; + }; + CFile.prototype["close"] = function() + { + Module["_Close"](this.nativeFile); + this.nativeFile = 0; + this.pages = []; + this.info = null; + if (this.stream > 0) + Module["_free"](this.stream); + this.stream = -1; + self.drawingFile = null; + }; - self.drawingFileCurrentPageIndex = pageIndex; - var retValue = Module["_GetPixmap"](this.nativeFile, pageIndex, width, height, backgroundColor === undefined ? 0xFFFFFF : backgroundColor); - self.drawingFileCurrentPageIndex = -1; + CFile.prototype["getPages"] = function() + { + return this.pages; + }; - if (this.pages[pageIndex].fonts.length > 0) - { - // ждем загрузки шрифтов для этой страницы - Module["_free"](retValue); - retValue = null; - } - return retValue; - }; - CFile.prototype["getGlyphs"] = function(pageIndex) - { - if (this.pages[pageIndex].fonts.length > 0) - { - // ждем загрузки шрифтов для этой страницы - return null; - } + CFile.prototype["getDocumentInfo"] = function() + { + return this.info; + }; - self.drawingFileCurrentPageIndex = pageIndex; - var retValue = Module["_GetGlyphs"](this.nativeFile, pageIndex); - // удалять результат не надо, этот буфер используется в качестве текстового буфера - // для текстовых команд других страниц. После получения ВСЕХ текстовых страниц - - // нужно вызвать destroyTextInfo() - self.drawingFileCurrentPageIndex = -1; + CFile.prototype["getPagePixmap"] = function(pageIndex, width, height, backgroundColor) + { + if (this.pages[pageIndex].fonts.length > 0) + { + // ждем загрузки шрифтов для этой страницы + return null; + } - if (this.pages[pageIndex].fonts.length > 0) - { - // ждем загрузки шрифтов для этой страницы - retValue = null; - } + self.drawingFileCurrentPageIndex = pageIndex; + var retValue = Module["_GetPixmap"](this.nativeFile, pageIndex, width, height, backgroundColor === undefined ? 0xFFFFFF : backgroundColor); + self.drawingFileCurrentPageIndex = -1; - if (null == retValue) - return null; + if (this.pages[pageIndex].fonts.length > 0) + { + // ждем загрузки шрифтов для этой страницы + Module["_free"](retValue); + retValue = null; + } + return retValue; + }; + CFile.prototype["getGlyphs"] = function(pageIndex) + { + if (this.pages[pageIndex].fonts.length > 0) + { + // ждем загрузки шрифтов для этой страницы + return null; + } - var lenArray = new Int32Array(Module["HEAP8"].buffer, retValue, 5); - var len = lenArray[0]; - len -= 20; + self.drawingFileCurrentPageIndex = pageIndex; + var retValue = Module["_GetGlyphs"](this.nativeFile, pageIndex); + // удалять результат не надо, этот буфер используется в качестве текстового буфера + // для текстовых команд других страниц. После получения ВСЕХ текстовых страниц - + // нужно вызвать destroyTextInfo() + self.drawingFileCurrentPageIndex = -1; - if (self.drawingFile.onUpdateStatistics) - self.drawingFile.onUpdateStatistics(lenArray[1], lenArray[2], lenArray[3], lenArray[4]); + if (this.pages[pageIndex].fonts.length > 0) + { + // ждем загрузки шрифтов для этой страницы + retValue = null; + } - if (len <= 0) - { - return []; - } + if (null == retValue) + return null; - var textCommandsSrc = new Uint8Array(Module["HEAP8"].buffer, retValue + 20, len); - var textCommands = new Uint8Array(len); - textCommands.set(textCommandsSrc); + var lenArray = new Int32Array(Module["HEAP8"].buffer, retValue, 5); + var len = lenArray[0]; + len -= 20; - textCommandsSrc = null; - return textCommands; - }; - CFile.prototype["destroyTextInfo"] = function() - { - Module["_DestroyTextInfo"](); - }; - CFile.prototype["getLinks"] = function(pageIndex) - { - var res = []; - var ext = Module["_GetLinks"](this.nativeFile, pageIndex); - if (ext == 0) - return res; + if (self.drawingFile.onUpdateStatistics) + self.drawingFile.onUpdateStatistics(lenArray[1], lenArray[2], lenArray[3], lenArray[4]); - var lenArray = new Int32Array(Module["HEAP8"].buffer, ext, 4); - if (lenArray == null) - return res; + if (len <= 0) + { + return []; + } - var len = lenArray[0]; - len -= 4; - if (len <= 0) - return res; + var textCommandsSrc = new Uint8Array(Module["HEAP8"].buffer, retValue + 20, len); + var textCommands = new Uint8Array(len); + textCommands.set(textCommandsSrc); - var buffer = new Uint8Array(Module["HEAP8"].buffer, ext + 4, len); - var reader = new CBinaryReader(buffer, 0, len); + textCommandsSrc = null; + return textCommands; + }; + CFile.prototype["destroyTextInfo"] = function() + { + Module["_DestroyTextInfo"](); + }; + CFile.prototype["getLinks"] = function(pageIndex) + { + var res = []; + var ext = Module["_GetLinks"](this.nativeFile, pageIndex); + if (ext == 0) + return res; - while (reader.isValid()) - { - var rec = {}; - rec["link"] = reader.readString(); - rec["dest"] = reader.readDouble(); - rec["x"] = reader.readDouble(); - rec["y"] = reader.readDouble(); - rec["w"] = reader.readDouble(); - rec["h"] = reader.readDouble(); - res.push(rec); - } + var lenArray = new Int32Array(Module["HEAP8"].buffer, ext, 4); + if (lenArray == null) + return res; - Module["_free"](ext); - return res; - }; - CFile.prototype["getStructure"] = function() - { - var res = []; - var str = Module["_GetStructure"](this.nativeFile); - if (str == 0) - return res; - var lenArray = new Int32Array(Module["HEAP8"].buffer, str, 4); - if (lenArray == null) - return res; - var len = lenArray[0]; - len -= 4; - if (len <= 0) - return res; + var len = lenArray[0]; + len -= 4; + if (len <= 0) + return res; - var buffer = new Uint8Array(Module["HEAP8"].buffer, str + 4, len); - var reader = new CBinaryReader(buffer, 0, len); + var buffer = new Uint8Array(Module["HEAP8"].buffer, ext + 4, len); + var reader = new CBinaryReader(buffer, 0, len); - while (reader.isValid()) - { - var rec = {}; - rec["page"] = reader.readInt(); - rec["level"] = reader.readInt(); - rec["y"] = reader.readDouble(); - rec["description"] = reader.readString(); - res.push(rec); - } + while (reader.isValid()) + { + var rec = {}; + rec["link"] = reader.readString(); + rec["dest"] = reader.readDouble(); + rec["x"] = reader.readDouble(); + rec["y"] = reader.readDouble(); + rec["w"] = reader.readDouble(); + rec["h"] = reader.readDouble(); + res.push(rec); + } - Module["_free"](str); - return res; - }; + Module["_free"](ext); + return res; + }; + CFile.prototype["getStructure"] = function() + { + var res = []; + var str = Module["_GetStructure"](this.nativeFile); + if (str == 0) + return res; + var lenArray = new Int32Array(Module["HEAP8"].buffer, str, 4); + if (lenArray == null) + return res; + var len = lenArray[0]; + len -= 4; + if (len <= 0) + return res; - CFile.prototype.memory = function() - { - return Module["HEAP8"]; - }; - CFile.prototype.free = function(pointer) - { - Module["_free"](pointer); - }; + var buffer = new Uint8Array(Module["HEAP8"].buffer, str + 4, len); + var reader = new CBinaryReader(buffer, 0, len); - self["AscViewer"]["CDrawingFile"] = CFile; + while (reader.isValid()) + { + var rec = {}; + rec["page"] = reader.readInt(); + rec["level"] = reader.readInt(); + rec["y"] = reader.readDouble(); + rec["description"] = reader.readString(); + res.push(rec); + } + + Module["_free"](str); + return res; + }; + + CFile.prototype.memory = function() + { + return Module["HEAP8"]; + }; + CFile.prototype.free = function(pointer) + { + Module["_free"](pointer); + }; + + self["AscViewer"]["CDrawingFile"] = CFile; self["AscViewer"]["InitializeFonts"] = function() { if (!window["g_fonts_selection_bin"]) return; var memoryBuffer = window["g_fonts_selection_bin"].toUtf8(); var pointer = Module["_malloc"](memoryBuffer.length); - Module.HEAP8.set(memoryBuffer, pointer); + Module.HEAP8.set(memoryBuffer, pointer); Module["_InitializeFontsBase64"](pointer, memoryBuffer.length); Module["_free"](pointer); delete window["g_fonts_selection_bin"]; + + // ranges + let rangesBuffer = new CBinaryWriter(); + let ranges = AscFonts.getSymbolRanges(); + + let rangesCount = ranges.length; + rangesBuffer.writeUint(rangesCount); + for (let i = 0; i < rangesCount; i++) + { + rangesBuffer.writeString(ranges[i].getName()); + rangesBuffer.writeUint(ranges[i].getStart()); + rangesBuffer.writeUint(ranges[i].getEnd()); + } + + let rangesFinalLen = rangesBuffer.dataSize; + let rangesFinal = new Uint8Array(rangesBuffer.buffer.buffer, 0, rangesFinalLen); + pointer = Module["_malloc"](rangesFinalLen); + Module.HEAP8.set(rangesFinal, pointer); + Module["_InitializeFontsRanges"](pointer, rangesFinalLen); + Module["_free"](pointer); }; - self["AscViewer"]["Free"] = function(pointer) { + self["AscViewer"]["Free"] = function(pointer) { Module["_free"](pointer); }; @@ -399,114 +454,114 @@ return isFound; } - self["AscViewer"]["CheckStreamId"] = function(data, status) { - var lenArray = new Int32Array(Module["HEAP8"].buffer, data, 4); - var len = lenArray[0]; - len -= 4; + self["AscViewer"]["CheckStreamId"] = function(data, status) { + var lenArray = new Int32Array(Module["HEAP8"].buffer, data, 4); + var len = lenArray[0]; + len -= 4; - var buffer = new Uint8Array(Module["HEAP8"].buffer, data + 4, len); - var reader = new CBinaryReader(buffer, 0, len); + var buffer = new Uint8Array(Module["HEAP8"].buffer, data + 4, len); + var reader = new CBinaryReader(buffer, 0, len); - var name = reader.readString(); - var style = 0; - if (reader.readInt() != 0) - style |= 1;//AscFonts.FontStyle.FontStyleBold; - if (reader.readInt() != 0) - style |= 2;//AscFonts.FontStyle.FontStyleItalic; + var name = reader.readString(); + var style = 0; + if (reader.readInt() != 0) + style |= 1;//AscFonts.FontStyle.FontStyleBold; + if (reader.readInt() != 0) + style |= 2;//AscFonts.FontStyle.FontStyleItalic; - var file = AscFonts.pickFont(name, style); - var fileId = file.GetID(); - var fileStatus = file.GetStatus(); + var file = AscFonts.pickFont(name, style); + var fileId = file.GetID(); + var fileStatus = file.GetStatus(); - if (fileStatus == 0) - { - // шрифт загружен. - fontToMemory(file, true); - } - else - { - self.fontStreams[fileId] = self.fontStreams[fileId] || {}; - self.fontStreams[fileId].pages = self.fontStreams[fileId].pages || []; - addToArrayAsDictionary(self.fontStreams[fileId].pages, self.drawingFileCurrentPageIndex); + if (fileStatus == 0) + { + // шрифт загружен. + fontToMemory(file, true); + } + else + { + self.fontStreams[fileId] = self.fontStreams[fileId] || {}; + self.fontStreams[fileId].pages = self.fontStreams[fileId].pages || []; + addToArrayAsDictionary(self.fontStreams[fileId].pages, self.drawingFileCurrentPageIndex); - if (self.drawingFile) - { - addToArrayAsDictionary(self.drawingFile.pages[self.drawingFileCurrentPageIndex].fonts, fileId); - } + if (self.drawingFile) + { + addToArrayAsDictionary(self.drawingFile.pages[self.drawingFileCurrentPageIndex].fonts, fileId); + } - if (fileStatus != 2) - { - // шрифт не грузится - надо загрузить - var _t = file; - file.LoadFontAsync("../../../../fonts/", function(){ - fontToMemory(_t, true); + if (fileStatus != 2) + { + // шрифт не грузится - надо загрузить + var _t = file; + file.LoadFontAsync("../../../../fonts/", function(){ + fontToMemory(_t, true); - var pages = self.fontStreams[fileId].pages; - delete self.fontStreams[fileId]; - var pagesRepaint = []; - for (var i = 0, len = pages.length; i < len; i++) - { - var pageObj = self.drawingFile.pages[pages[i]]; - var fonts = pageObj.fonts; - - for (var j = 0, len_fonts = fonts.length; j < len_fonts; j++) - { - if (fonts[j] == fileId) - { - fonts.splice(j, 1); - break; - } - } - if (0 == fonts.length) - pagesRepaint.push(pages[i]); - } + var pages = self.fontStreams[fileId].pages; + delete self.fontStreams[fileId]; + var pagesRepaint = []; + for (var i = 0, len = pages.length; i < len; i++) + { + var pageObj = self.drawingFile.pages[pages[i]]; + var fonts = pageObj.fonts; + + for (var j = 0, len_fonts = fonts.length; j < len_fonts; j++) + { + if (fonts[j] == fileId) + { + fonts.splice(j, 1); + break; + } + } + if (0 == fonts.length) + pagesRepaint.push(pages[i]); + } - if (pagesRepaint.length > 0) - { - if (self.drawingFile.onRepaintPages) - self.drawingFile.onRepaintPages(pagesRepaint); - } - }); - } - } + if (pagesRepaint.length > 0) + { + if (self.drawingFile.onRepaintPages) + self.drawingFile.onRepaintPages(pagesRepaint); + } + }); + } + } - var memoryBuffer = fileId.toUtf8(); - var pointer = Module["_malloc"](memoryBuffer.length); - Module.HEAP8.set(memoryBuffer, pointer); - Module["HEAP8"][status] = (fileStatus == 0) ? 1 : 0; - return pointer; - }; + var memoryBuffer = fileId.toUtf8(); + var pointer = Module["_malloc"](memoryBuffer.length); + Module.HEAP8.set(memoryBuffer, pointer); + Module["HEAP8"][status] = (fileStatus == 0) ? 1 : 0; + return pointer; + }; - function fontToMemory(file, isCheck) - { - var idBuffer = file.GetID().toUtf8(); - var idPointer = Module["_malloc"](idBuffer.length); - Module["HEAP8"].set(idBuffer, idPointer); + function fontToMemory(file, isCheck) + { + var idBuffer = file.GetID().toUtf8(); + var idPointer = Module["_malloc"](idBuffer.length); + Module["HEAP8"].set(idBuffer, idPointer); - if (isCheck) - { - var nExist = Module["_IsFontBinaryExist"](idPointer); - if (nExist != 0) - { - Module["_free"](idPointer); - return; - } - } + if (isCheck) + { + var nExist = Module["_IsFontBinaryExist"](idPointer); + if (nExist != 0) + { + Module["_free"](idPointer); + return; + } + } - var stream_index = file.GetStreamIndex(); - - var stream = AscFonts.getFontStream(stream_index); - var streamPointer = Module["_malloc"](stream.size); - Module["HEAP8"].set(stream.data, streamPointer); + var stream_index = file.GetStreamIndex(); + + var stream = AscFonts.getFontStream(stream_index); + var streamPointer = Module["_malloc"](stream.size); + Module["HEAP8"].set(stream.data, streamPointer); - // не скидываем стрим, чтобы можно было использовать его а fonts.js - //var streams = AscFonts.getFontStreams(); - //streams[stream_index] = null; - //streams[stream_index] = AscFonts.updateFontStreamNative(streamPointer, stream.size); + // не скидываем стрим, чтобы можно было использовать его а fonts.js + //var streams = AscFonts.getFontStreams(); + //streams[stream_index] = null; + //streams[stream_index] = AscFonts.updateFontStreamNative(streamPointer, stream.size); - Module["_SetFontBinary"](idPointer, streamPointer, stream.size); + Module["_SetFontBinary"](idPointer, streamPointer, stream.size); - Module["_free"](streamPointer); - Module["_free"](idPointer); - } + Module["_free"](streamPointer); + Module["_free"](idPointer); + } })(window, undefined); diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp index 7435341ba9..ffa5b4b0bd 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp @@ -20,7 +20,7 @@ extern "C" { NSFonts::IApplicationFonts* g_applicationFonts = NULL; WASM_EXPORT void InitializeFontsBin(BYTE* data, int size) { - if (!g_applicationFonts) + if (!g_applicationFonts) { g_applicationFonts = NSFonts::NSApplication::Create(); g_applicationFonts->InitializeFromBin(data, (unsigned int)size); @@ -28,23 +28,28 @@ WASM_EXPORT void InitializeFontsBin(BYTE* data, int size) } WASM_EXPORT void InitializeFontsBase64(BYTE* pDataSrc, int nLenSrc) { - if (!g_applicationFonts) + if (!g_applicationFonts) { g_applicationFonts = NSFonts::NSApplication::Create(); int nLenDst = NSBase64::Base64DecodeGetRequiredLength(nLenSrc); - BYTE* pDataDst = new BYTE[nLenDst]; + BYTE* pDataDst = new BYTE[nLenDst]; - if (FALSE == NSBase64::Base64Decode((const char*)pDataSrc, nLenSrc, pDataDst, &nLenDst)) - { - RELEASEARRAYOBJECTS(pDataDst); - return; - } + if (FALSE == NSBase64::Base64Decode((const char*)pDataSrc, nLenSrc, pDataDst, &nLenDst)) + { + RELEASEARRAYOBJECTS(pDataDst); + return; + } g_applicationFonts->InitializeFromBin(pDataDst, (unsigned int)nLenDst); RELEASEARRAYOBJECTS(pDataDst); } } +WASM_EXPORT void InitializeFontsRanges(BYTE* pDataSrc) +{ + if (g_applicationFonts && pDataSrc) + g_applicationFonts->InitializeRanges(pDataSrc); +} WASM_EXPORT void SetFontBinary(char* path, BYTE* data, int size) { NSFonts::IFontsMemoryStorage* pStorage = NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage(); @@ -69,462 +74,297 @@ WASM_EXPORT int IsFontBinaryExist(char* path) WASM_EXPORT int GetType(BYTE* data, LONG size) { - // 0 - PDF - // 1 - DJVU - // 2 - XPS - char* pFirst = strstr((char*)data, "%PDF-" ); - if (pFirst) - return 0; - if ( (8 <= size) && (0x41 == data[0] && 0x54 == data[1] && 0x26 == data[2] && 0x54 == data[3] && - 0x46 == data[4] && 0x4f == data[5] && 0x52 == data[6] && 0x4d == data[7])) - return 1; - return 2; + // 0 - PDF + // 1 - DJVU + // 2 - XPS + char* pFirst = strstr((char*)data, "%PDF-" ); + if (pFirst) + return 0; + if ( (8 <= size) && (0x41 == data[0] && 0x54 == data[1] && 0x26 == data[2] && 0x54 == data[3] && + 0x46 == data[4] && 0x4f == data[5] && 0x52 == data[6] && 0x4d == data[7])) + return 1; + return 2; } WASM_EXPORT CGraphicsFileDrawing* Open(BYTE* data, LONG size, const char* password) { if (!g_applicationFonts) g_applicationFonts = NSFonts::NSApplication::Create(); - + // всегда пересоздаем сторадж NSFonts::NSApplicationFontStream::SetGlobalMemoryStorage(NSFonts::NSApplicationFontStream::CreateDefaultGlobalMemoryStorage()); - CGraphicsFileDrawing* pGraphics = new CGraphicsFileDrawing(g_applicationFonts); - pGraphics->Open(data, size, GetType(data, size), password); - return pGraphics; + CGraphicsFileDrawing* pGraphics = new CGraphicsFileDrawing(g_applicationFonts); + pGraphics->Open(data, size, GetType(data, size), password); + return pGraphics; } WASM_EXPORT int GetErrorCode(CGraphicsFileDrawing* pGraphics) { - if (!pGraphics) - return -1; - return pGraphics->GetErrorCode(); + if (!pGraphics) + return -1; + return pGraphics->GetErrorCode(); } WASM_EXPORT void Close (CGraphicsFileDrawing* pGraphics) { - delete pGraphics; - NSFonts::NSApplicationFontStream::SetGlobalMemoryStorage(NULL); + delete pGraphics; + NSFonts::NSApplicationFontStream::SetGlobalMemoryStorage(NULL); } WASM_EXPORT BYTE* GetInfo (CGraphicsFileDrawing* pGraphics) { - NSWasm::CData oRes; - oRes.SkipLen(); + NSWasm::CData oRes; + oRes.SkipLen(); - int pages_count = pGraphics->GetPagesCount(); - oRes.AddInt(pages_count); - for (int page = 0; page < pages_count; ++page) - { - int nW = 0; - int nH = 0; - int nDpi = 0; - pGraphics->GetPageInfo(page, nW, nH, nDpi); - oRes.AddInt(nW); - oRes.AddInt(nH); - oRes.AddInt(nDpi); - } - std::wstring wsInfo = pGraphics->GetInfo(); - std::string sInfo = U_TO_UTF8(wsInfo); - oRes.WriteString((BYTE*)sInfo.c_str(), sInfo.length()); + int pages_count = pGraphics->GetPagesCount(); + oRes.AddInt(pages_count); + for (int page = 0; page < pages_count; ++page) + { + int nW = 0; + int nH = 0; + int nDpi = 0; + pGraphics->GetPageInfo(page, nW, nH, nDpi); + oRes.AddInt(nW); + oRes.AddInt(nH); + oRes.AddInt(nDpi); + } + std::wstring wsInfo = pGraphics->GetInfo(); + std::string sInfo = U_TO_UTF8(wsInfo); + oRes.WriteString((BYTE*)sInfo.c_str(), sInfo.length()); - oRes.WriteLen(); - BYTE* bRes = oRes.GetBuffer(); - oRes.ClearWithoutAttack(); - return bRes; + oRes.WriteLen(); + BYTE* bRes = oRes.GetBuffer(); + oRes.ClearWithoutAttack(); + return bRes; } WASM_EXPORT BYTE* GetPixmap(CGraphicsFileDrawing* pGraphics, int nPageIndex, int nRasterW, int nRasterH, int nBackgroundColor) { - return pGraphics->GetPage(nPageIndex, nRasterW, nRasterH, nBackgroundColor); + return pGraphics->GetPage(nPageIndex, nRasterW, nRasterH, nBackgroundColor); } WASM_EXPORT BYTE* GetGlyphs (CGraphicsFileDrawing* pGraphics, int nPageIndex) { - return pGraphics->GetGlyphs(nPageIndex); + return pGraphics->GetGlyphs(nPageIndex); } WASM_EXPORT BYTE* GetLinks (CGraphicsFileDrawing* pGraphics, int nPageIndex) { - return pGraphics->GetLinks(nPageIndex); + return pGraphics->GetLinks(nPageIndex); } WASM_EXPORT BYTE* GetStructure(CGraphicsFileDrawing* pGraphics) { - return pGraphics->GetStructure(); + return pGraphics->GetStructure(); } WASM_EXPORT void DestroyTextInfo(CGraphicsFileDrawing* pGraphics) { - return pGraphics->DestroyText(); + return pGraphics->DestroyText(); } WASM_EXPORT int IsNeedCMap(CGraphicsFileDrawing* pGraphics) { - return pGraphics->IsNeedCMap() ? 1 : 0; + return pGraphics->IsNeedCMap() ? 1 : 0; } WASM_EXPORT void SetCMapData(CGraphicsFileDrawing* pGraphics, BYTE* data, int size) { - pGraphics->SetCMapData(data, size); + pGraphics->SetCMapData(data, size); } #ifdef __cplusplus } #endif -#ifdef TEST_AS_EXECUTABLE -static DWORD GetLength(BYTE* x) +#ifdef TEST_CPP_BINARY + +int READ_INT(BYTE* x) { - return x ? (x[0] | x[1] << 8 | x[2] << 16 | x[3] << 24) : 4; + return x ? (x[0] | x[1] << 8 | x[2] << 16 | x[3] << 24) : 4; } +#include "../../../../../fontengine/ApplicationFontsWorker.h" +#include "../../../../../common/Directory.h" + int main() { -#define XPS_TEST 0 -#define DJVU_TEST 0 -#define PDF_TEST 1 -#if PDF_TEST - BYTE* pPdfData = NULL; - DWORD nPdfBytesCount; - NSFile::CFileBinary oFile; - if (oFile.ReadAllBytes(NSFile::GetProcessDirectory() + L"/font_selection.bin", &pPdfData, nPdfBytesCount)) - { - InitializeFontsBin(pPdfData, nPdfBytesCount); - RELEASEARRAYOBJECTS(pPdfData); - oFile.CloseFile(); - } + // CHECK SYSTEM FONTS + CApplicationFontsWorker oWorker; + oWorker.m_sDirectory = NSFile::GetProcessDirectory() + L"/fonts_cache"; + //oWorker.m_arAdditionalFolders.push_back(L"D:\\GIT\\core-fonts"); + oWorker.m_bIsNeedThumbnails = false; - if (!oFile.ReadAllBytes(NSFile::GetProcessDirectory() + L"/test.pdf", &pPdfData, nPdfBytesCount)) - { - RELEASEARRAYOBJECTS(pPdfData); - return 1; - } - oFile.CloseFile(); + if (!NSDirectory::Exists(oWorker.m_sDirectory)) + { + NSDirectory::CreateDirectory(oWorker.m_sDirectory); + NSFonts::IApplicationFonts* pFonts = oWorker.Check(); + RELEASEINTERFACE(pFonts); + } - CGraphicsFileDrawing* test = Open(pPdfData, nPdfBytesCount, ""); - int nError = GetErrorCode(test); - if (nError != 0) - { - Close(test); - if (nError == 4) - { - std::string sPassword = "123456"; - test = Open(pPdfData, nPdfBytesCount, sPassword.c_str()); - } - else - { - RELEASEARRAYOBJECTS(pPdfData); - return 1; - } - } - BYTE* info = GetInfo(test); - DWORD nLength = GetLength(info); - nLength -= 4; - int pages_count = GetLength(info + 4); - int test_page = 0; - int width = GetLength(info + test_page * 12 + 8); - int height = GetLength(info + test_page * 12 + 12); - std::cout << "Page " << test_page << " width " << width << " height " << height << " dpi " << GetLength(info + test_page * 12 + 16) << std::endl; + // INITIALIZE FONTS + if (true) + { + BYTE* pFontSelection = NULL; + DWORD nFontSelectionLen = 0; + if (NSFile::CFileBinary::ReadAllBytes(NSFile::GetProcessDirectory() + L"/fonts_cache/font_selection.bin", &pFontSelection, nFontSelectionLen)) + { + char* pBase64 = NULL; + int nBase64Len = 0; + NSFile::CBase64Converter::Encode(pFontSelection, (int)nFontSelectionLen, pBase64, nBase64Len, NSBase64::B64_BASE64_FLAG_NOCRLF); - // Тест WASM_EXPORT SetCMapData - if (IsNeedCMap(test)) - { - BYTE* pCMapData = NULL; - DWORD nCMapDataLength; - if (oFile.ReadAllBytes(NSFile::GetProcessDirectory() + L"/../../../../../../../../PdfFile/Resources/CMapMemory/CMapData", &pCMapData, nCMapDataLength)) - { - SetCMapData(test, pCMapData, nCMapDataLength); - oFile.CloseFile(); - } - } + InitializeFontsBase64((BYTE*)pBase64, nBase64Len); - BYTE* res = NULL; - if (pages_count > 0) - res = GetPixmap(test, test_page, width, height, 0xFFFFFF); + RELEASEARRAYOBJECTS(pBase64); + } + RELEASEARRAYOBJECTS(pFontSelection); + } - CBgraFrame* resFrame = new CBgraFrame(); - resFrame->put_Data(res); - resFrame->put_Width(width); - resFrame->put_Height(height); - resFrame->put_Stride(4 * width); - resFrame->put_IsRGBA(true); - resFrame->SaveFile(NSFile::GetProcessDirectory() + L"/res.png", _CXIMAGE_FORMAT_PNG); - resFrame->ClearNoAttack(); + // OPEN FILE + std::wstring sFilePath = NSFile::GetProcessDirectory() + L"/test.pdf"; - nLength = GetLength(info + pages_count * 12 + 8); - std::cout << "json "<< std::string((char*)(info + pages_count * 12 + 12), nLength); + BYTE* pFileData = NULL; + DWORD nFileDataLen = 0; + if (!NSFile::CFileBinary::ReadAllBytes(sFilePath, &pFileData, nFileDataLen)) + return 1; - std::cout << std::endl; - BYTE* pLinks = GetLinks(test, test_page); - nLength = GetLength(pLinks); - DWORD i = 4; - nLength -= 4; - while (i < nLength) - { - DWORD nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << "Link "<< std::string((char*)(pLinks + i), nPathLength); - i += nPathLength; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " Ydest " << (double)nPathLength / 100.0; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " X " << (double)nPathLength / 100.0; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " Y " << (double)nPathLength / 100.0; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " W " << (double)nPathLength / 100.0; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " H " << (double)nPathLength / 100.0 << std::endl; - } + CGraphicsFileDrawing* pGrFile = Open(pFileData, (LONG)nFileDataLen, ""); + int nError = GetErrorCode(pGrFile); - std::cout << std::endl; - BYTE* pStructure = GetStructure(test); - nLength = GetLength(pStructure); - i = 4; - nLength -= 4; - while (i < nLength) - { - DWORD nPathLength = GetLength(pStructure + i); - i += 4; - std::cout << "Page " << nPathLength << ", "; - nPathLength = GetLength(pStructure + i); - i += 4; - std::cout << "Level " << nPathLength << ", "; - nPathLength = GetLength(pStructure + i); - i += 4; - std::cout << "Y " << (double)nPathLength / 100.0 << ", "; - nPathLength = GetLength(pStructure + i); - i += 4; - std::cout << "Description " << std::string((char*)(pStructure + i), nPathLength) << std::endl; - i += nPathLength; - } + if (nError != 0) + { + Close(pGrFile); + if (nError == 4) + { + std::string sPassword = "123456"; + pGrFile = Open(pFileData, nFileDataLen, sPassword.c_str()); + } + else + { + RELEASEARRAYOBJECTS(pFileData); + return 1; + } + } - if (false) - { - std::cout << std::endl; - BYTE* pGlyphs = GetGlyphs(test, test_page); - } + // INFO + BYTE* pInfo = GetInfo(pGrFile); + int nLength = READ_INT(pInfo); + nLength -= 4; - Close(test); - RELEASEARRAYOBJECTS(pPdfData); - RELEASEARRAYOBJECTS(pLinks); - RELEASEARRAYOBJECTS(pStructure); - RELEASEARRAYOBJECTS(info); - RELEASEARRAYOBJECTS(res); - RELEASEOBJECT(resFrame); - return 0; -#endif -#if XPS_TEST - BYTE* pXpsData = NULL; - DWORD nXpsBytesCount; - NSFile::CFileBinary oFile; - if (!oFile.ReadAllBytes(NSFile::GetProcessDirectory() + L"/test.xps", &pXpsData, nXpsBytesCount)) - { - RELEASEARRAYOBJECTS(pXpsData); - return 1; - } - oFile.CloseFile(); + int nPagesCount = 0; + int nTestPage = 0; + int nWidth = 100; + int nHeight = 100; - CGraphicsFileDrawing* test = Open(pXpsData, nXpsBytesCount, ""); - int nError = GetErrorCode(test); - if (nError != 0) - { - Close(test); - RELEASEARRAYOBJECTS(pXpsData); - return 1; - } - int* size = GetSize(test); - int pages_count = *size; - int test_page = 0; - int width = size[test_page * 3 + 1]; - int height = size[test_page * 3 + 2]; - std::cout << "Page " << test_page << " width " << width << " height " << height << std::endl; + if (nLength > 0) + { + nPagesCount = READ_INT(pInfo + 4); + if (nPagesCount > 0) + { + nWidth = READ_INT(pInfo + nTestPage * 12 + 8); + nHeight = READ_INT(pInfo + nTestPage * 12 + 12); + int dpi = READ_INT(pInfo + nTestPage * 12 + 16); + std::cout << "Page " << nTestPage << " width " << nWidth << " height " << nHeight << " dpi " << dpi << std::endl; - std::cout << std::endl; - BYTE* pStructure = GetStructure(test); - DWORD nLength = GetLength(pStructure); - DWORD i = 4; - nLength -= 4; - while (i < nLength) - { - DWORD nPathLength = GetLength(pStructure + i); - i += 4; - std::cout << "Page " << nPathLength << ", "; - nPathLength = GetLength(pStructure + i); - i += 4; - std::cout << "Level " << nPathLength << ", "; - nPathLength = GetLength(pStructure + i); - i += 4; - std::cout << "Y " << (double)nPathLength / 100.0 << ", "; - nPathLength = GetLength(pStructure + i); - i += 4; - std::cout << "Description " << std::string((char*)(pStructure + i), nPathLength) << std::endl; - i += nPathLength; - } + nLength = READ_INT(pInfo + nPagesCount * 12 + 8); + std::cout << "json "<< std::string((char*)(pInfo + nPagesCount * 12 + 12), nLength) << std::endl;; + } + } - BYTE* res = NULL; - if (pages_count > 0) - res = GetPixmap(test, test_page, width, height, 0xFFFFFF); - if (!res) - { - RELEASEARRAYOBJECTS(pXpsData); - RELEASEARRAYOBJECTS(size); - return 1; - } + free(pInfo); - CBgraFrame* resFrame = new CBgraFrame(); - resFrame->put_Data(res); - resFrame->put_Width(width); - resFrame->put_Height(height); - resFrame->put_Stride(4 * width); - resFrame->put_IsRGBA(true); - resFrame->SaveFile(NSFile::GetProcessDirectory() + L"/res.png", _CXIMAGE_FORMAT_PNG); - resFrame->ClearNoAttack(); + // CMAP + BYTE* pCMapData = NULL; + if (IsNeedCMap(pGrFile)) + { + DWORD nCMapDataLength = 0; + if (NSFile::CFileBinary::ReadAllBytes(NSFile::GetProcessDirectory() + L"/cmap.bin", &pCMapData, nCMapDataLength)) + { + SetCMapData(pGrFile, pCMapData, nCMapDataLength); + } + } - BYTE* info = GetInfo(test); - nLength = GetLength(info + 4); - std::cout << "json "<< std::string((char*)(info + 8), nLength); + // RASTER + if (true && nPagesCount > 0) + { + BYTE* res = NULL; + res = GetPixmap(pGrFile, nTestPage, nWidth, nHeight, 0xFFFFFF); - std::cout << std::endl; - BYTE* pGlyphs = GetGlyphs(test, test_page); + CBgraFrame oFrame; + oFrame.put_Data(res); + oFrame.put_Width(nWidth); + oFrame.put_Height(nHeight); + oFrame.put_Stride(4 * nWidth); + oFrame.put_IsRGBA(true); + oFrame.SaveFile(NSFile::GetProcessDirectory() + L"/res.png", _CXIMAGE_FORMAT_PNG); + oFrame.ClearNoAttack(); - std::cout << std::endl; - BYTE* pLinks = GetLinks(test, test_page); - nLength = GetLength(pLinks); - i = 4; - nLength -= 4; - while (i < nLength) - { - DWORD nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << "Link "<< std::string((char*)(pLinks + i), nPathLength); - i += nPathLength; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " Ydest " << (double)nPathLength / 100.0; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " X " << (double)nPathLength / 100.0; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " Y " << (double)nPathLength / 100.0; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " W " << (double)nPathLength / 100.0; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " H " << (double)nPathLength / 100.0 << std::endl; - } + RELEASEARRAYOBJECTS(res); + } - Close(test); - RELEASEARRAYOBJECTS(pXpsData); - RELEASEARRAYOBJECTS(size); - RELEASEARRAYOBJECTS(info); - RELEASEARRAYOBJECTS(res); - RELEASEARRAYOBJECTS(pLinks); - RELEASEARRAYOBJECTS(pStructure); - RELEASEOBJECT(resFrame); - return 0; -#endif -#if DJVU_TEST - BYTE* pDjVuData = NULL; - DWORD nDjVuBytesCount; - NSFile::CFileBinary oFile; - if (!oFile.ReadAllBytes(NSFile::GetProcessDirectory() + L"/test.djvu", &pDjVuData, nDjVuBytesCount)) - { - RELEASEARRAYOBJECTS(pDjVuData); - return 1; - } - oFile.CloseFile(); + if (nPagesCount > 0) + { + BYTE* pLinks = GetLinks(pGrFile, nTestPage); + nLength = READ_INT(pLinks); + DWORD i = 4; + nLength -= 4; + while (i < nLength) + { + DWORD nPathLength = READ_INT(pLinks + i); + i += 4; + std::cout << "Link " << std::string((char*)(pLinks + i), nPathLength); + i += nPathLength; + nPathLength = READ_INT(pLinks + i); + i += 4; + std::cout << " Ydest " << (double)nPathLength / 100.0; + nPathLength = READ_INT(pLinks + i); + i += 4; + std::cout << " X " << (double)nPathLength / 100.0; + nPathLength = READ_INT(pLinks + i); + i += 4; + std::cout << " Y " << (double)nPathLength / 100.0; + nPathLength = READ_INT(pLinks + i); + i += 4; + std::cout << " W " << (double)nPathLength / 100.0; + nPathLength = READ_INT(pLinks + i); + i += 4; + std::cout << " H " << (double)nPathLength / 100.0 << std::endl; + } - CGraphicsFileDrawing* test = Open(pDjVuData, nDjVuBytesCount, ""); - int nError = GetErrorCode(test); - if (nError != 0) - { - Close(test); - RELEASEARRAYOBJECTS(pDjVuData); - return 1; - } - int* size = GetSize(test); - int pages_count = *size; - int test_page = 1; - int width = size[test_page * 3 + 1]; - int height = size[test_page * 3 + 2]; - std::cout << "Page " << test_page << " width " << width << " height " << height << std::endl; + std::cout << std::endl; - std::cout << std::endl; - BYTE* pStructure = GetStructure(test); - DWORD nLength = GetLength(pStructure); - DWORD i = 4; - nLength -= 4; - while (i < nLength) - { - DWORD nPathLength = GetLength(pStructure + i); - i += 4; - std::cout << "Page " << nPathLength; - nPathLength = GetLength(pStructure + i); - i += 4; - std::cout << " Level " << nPathLength; - i += 4; // y 0.0 - nPathLength = GetLength(pStructure + i); - i += 4; - std::string oDs = std::string((char*)(pStructure + i), nPathLength); - std::wcout << L" Description "<< UTF8_TO_U(oDs) << std::endl; - i += nPathLength; - } + if (pLinks) + free(pLinks); + } - BYTE* res = NULL; - if (pages_count > 0) - res = GetPixmap(test, test_page, width, height, 0xFFFFFF); + if (true) + { + BYTE* pStructure = GetStructure(pGrFile); + nLength = READ_INT(pStructure); + DWORD i = 4; + nLength -= 4; + while (i < nLength) + { + DWORD nPathLength = READ_INT(pStructure + i); + i += 4; + std::cout << "Page " << nPathLength << ", "; + nPathLength = READ_INT(pStructure + i); + i += 4; + std::cout << "Level " << nPathLength << ", "; + nPathLength = READ_INT(pStructure + i); + i += 4; + std::cout << "Y " << (double)nPathLength / 100.0 << ", "; + nPathLength = READ_INT(pStructure + i); + i += 4; + std::cout << "Description " << std::string((char*)(pStructure + i), nPathLength) << std::endl; + i += nPathLength; + } - CBgraFrame* resFrame = new CBgraFrame(); - resFrame->put_Data(res); - resFrame->put_Width(width); - resFrame->put_Height(height); - resFrame->put_Stride(4 * width); - resFrame->put_IsRGBA(true); - resFrame->SaveFile(NSFile::GetProcessDirectory() + L"/res.png", _CXIMAGE_FORMAT_PNG); - resFrame->ClearNoAttack(); + std::cout << std::endl; - BYTE* info = GetInfo(test); - nLength = GetLength(info + 4); - std::cout << "json "<< std::string((char*)(info + 8), nLength); + if (pStructure) + free(pStructure); + } - std::cout << std::endl; - BYTE* pGlyphs = GetGlyphs(test, test_page); + if (false && nPagesCount > 0) + { + // TODO: + BYTE* pGlyphs = GetGlyphs(pGrFile, nTestPage); + } - std::cout << std::endl; - BYTE* pLinks = GetLinks(test, test_page); - nLength = GetLength(pLinks); - i = 4; - nLength -= 4; - while (i < nLength) - { - DWORD nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << "Link "<< std::string((char*)(pLinks + i), nPathLength); - i += nPathLength; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " Ydest " << (double)nPathLength / 100.0; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " X " << (double)nPathLength / 100.0; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " Y " << (double)nPathLength / 100.0; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " W " << (double)nPathLength / 100.0; - nPathLength = GetLength(pLinks + i); - i += 4; - std::cout << " H " << (double)nPathLength / 100.0 << std::endl; - } + Close(pGrFile); + RELEASEARRAYOBJECTS(pCMapData); - Close(test); - RELEASEARRAYOBJECTS(pDjVuData); - RELEASEARRAYOBJECTS(size); - RELEASEARRAYOBJECTS(info); - RELEASEARRAYOBJECTS(res); - RELEASEARRAYOBJECTS(pLinks); - RELEASEARRAYOBJECTS(pStructure); - RELEASEOBJECT(resFrame); - return 0; -#endif + return 0; } #endif diff --git a/DesktopEditor/raster/Metafile/Emf/EmfInterpretator/CEmfInterpretatorSvg.cpp b/DesktopEditor/raster/Metafile/Emf/EmfInterpretator/CEmfInterpretatorSvg.cpp index 9ccf641770..5a49ebd228 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfInterpretator/CEmfInterpretatorSvg.cpp +++ b/DesktopEditor/raster/Metafile/Emf/EmfInterpretator/CEmfInterpretatorSvg.cpp @@ -9,10 +9,10 @@ #include #include -#ifndef MININT8 -#define MAXUINT8 ((unsigned char)~((unsigned char)0)) -#define MAXINT8 ((char)(MAXUINT8 >> 1)) -#define MININT8 ((char)~MAXINT8) +#ifndef MININT32 +#define MAXUINT32 ((UINT32)~((UINT32)0)) +#define MAXINT32 ((INT32)(MAXUINT32 >> 1)) +#define MININT32 ((INT32)~MAXINT32) #endif namespace MetaFile @@ -1067,7 +1067,7 @@ namespace MetaFile NodeAttributes arAttributes = {{L"d", wsValue}}; AddStroke(arAttributes); - AddFill(arAttributes); + AddFill(arAttributes, std::fabs(oBounds.lRight - oBounds.lLeft), std::fabs(oBounds.lBottom - oBounds.lTop)); AddTransform(arAttributes); NodeAttributes arGAttributes; @@ -1542,7 +1542,7 @@ namespace MetaFile TRectD oPathRect = pPath->ConvertToRect(); - AddFill(arAttributes, oPathRect.dRight - oPathRect.dLeft, oPathRect.dBottom - oPathRect.dTop); + AddFill(arAttributes, std::fabs(oPathRect.dRight - oPathRect.dLeft), std::fabs(oPathRect.dBottom - oPathRect.dTop)); AddTransform(arAttributes); NodeAttributes arGAttributes; @@ -1749,6 +1749,26 @@ namespace MetaFile m_wsDefs += L""; } + void CEmfInterpretatorSvg::AddClip(NodeAttributes &arAttributes) + { + if (NULL == m_pParser) + return; + + if (m_wsLastClipId.empty()) + UpdateClip(); + + if (!m_wsLastClipId.empty()) + arAttributes.push_back({L"clip-path", L"url(#" + m_wsLastClipId + L')'}); + } + + void CEmfInterpretatorSvg::UpdateClip() + { + IClip* pClip = m_pParser->GetClip(); + + if (NULL != pClip) + pClip->ClipOnRenderer((CInterpretatorSvgBase*)this); + } + TRectD CEmfInterpretatorSvg::TranslateRect(const TEmfRectL &oRect) const { TRectD oNewRect(oRect.lLeft, oRect.lTop, oRect.lRight, oRect.lBottom); diff --git a/DesktopEditor/raster/Metafile/Emf/EmfInterpretator/CEmfInterpretatorSvg.h b/DesktopEditor/raster/Metafile/Emf/EmfInterpretator/CEmfInterpretatorSvg.h index 36289589af..b20bf756a4 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfInterpretator/CEmfInterpretatorSvg.h +++ b/DesktopEditor/raster/Metafile/Emf/EmfInterpretator/CEmfInterpretatorSvg.h @@ -221,6 +221,9 @@ namespace MetaFile void StartClipPath(unsigned int unMode, int nFillMode = -1) override {}; void EndClipPath(unsigned int unMode) override {}; + void AddClip(NodeAttributes &arAttributes); + void UpdateClip(); + void UpdateDC() override {}; void SetTransform(double& dM11, double& dM12, double& dM21, double& dM22, double& dX, double& dY) override {}; void GetTransform(double* pdM11, double* pdM12, double* pdM21, double* pdM22, double* pdX, double* pdY) override {}; diff --git a/DesktopEditor/raster/Metafile/Emf/EmfPlusObjects.h b/DesktopEditor/raster/Metafile/Emf/EmfPlusObjects.h index 6573ba7fd4..e47f145ea8 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfPlusObjects.h +++ b/DesktopEditor/raster/Metafile/Emf/EmfPlusObjects.h @@ -7,6 +7,12 @@ #include "../../../common/File.h" #include "../Common/MetaFileObjects.h" +#ifndef MININT32 +#define MAXUINT32 ((UINT32)~((UINT32)0)) +#define MAXINT32 ((INT32)(MAXUINT32 >> 1)) +#define MININT32 ((INT32)~MAXINT32) +#endif + namespace MetaFile { typedef enum @@ -417,7 +423,8 @@ namespace MetaFile { TRectD oRect; - oRect.dRight = oRect.dBottom = 0; + oRect.dRight = oRect.dBottom = MININT32; + oRect.dLeft = oRect.dTop = MAXINT32; for (unsigned int ulIndex = 0; ulIndex < m_pCommands.size(); ulIndex++) { diff --git a/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.cpp b/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.cpp index 5ea56bd2c5..14c275fb3d 100644 --- a/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.cpp +++ b/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.cpp @@ -4,10 +4,10 @@ #include #include -#ifndef MININT8 -#define MAXUINT8 ((unsigned char)~((unsigned char)0)) -#define MAXINT8 ((char)(MAXUINT8 >> 1)) -#define MININT8 ((char)~MAXINT8) +#ifndef MININT32 +#define MAXUINT32 ((UINT32)~((UINT32)0)) +#define MAXINT32 ((INT32)(MAXUINT32 >> 1)) +#define MININT32 ((INT32)~MAXINT32) #endif namespace MetaFile @@ -622,18 +622,18 @@ namespace MetaFile std::wstring CInterpretatorSvgBase::CreateHatchStyle(unsigned int unHatchStyle, double dWidth, double dHeight) { - if (NULL == m_pParser || NULL == m_pParser->GetBrush() || NULL == m_pParser->GetPen()) + if (NULL == m_pParser || NULL == m_pParser->GetBrush()) return std::wstring(); - double dStrokeWidth = std::fabs(m_pParser->GetPen()->GetWidth()); + double dStrokeWidth = 1. / m_pParser->GetTransform()->M11; - if (0.0 == dStrokeWidth || (1.0 == dStrokeWidth && PS_COSMETIC == (m_pParser->GetPen()->GetStyle() & PS_TYPE_MASK))) - dStrokeWidth = 1. / m_pParser->GetTransform()->M11; + if (NULL != m_pParser->GetPen()) + { + dStrokeWidth = std::fabs(m_pParser->GetPen()->GetWidth()); - std::wstring wsStrokeWidth = ConvertToWString(dStrokeWidth); - std::wstring wsValue = ConvertToWString(dStrokeWidth * 8., 6); - std::wstring wsValueW = ((0 != dWidth) ? ConvertToWString((dStrokeWidth * 8.) / dWidth, 6) : L"1"); - std::wstring wsValueH = ((0 != dHeight) ? ConvertToWString((dStrokeWidth * 8.) / dHeight, 6) : L"1"); + if (0.0 == dStrokeWidth || (1.0 == dStrokeWidth && PS_COSMETIC == (m_pParser->GetPen()->GetStyle() & PS_TYPE_MASK))) + dStrokeWidth = 1. / m_pParser->GetTransform()->M11; + } std::wstring wsStrokeColor = L"rgba(" + INTCOLOR_TO_RGB(m_pParser->GetBrush()->GetColor()) + L"," + ConvertToWString(m_pParser->GetBrush()->GetAlpha(), 0) + L")"; std::wstring wsBgColor; @@ -663,7 +663,7 @@ namespace MetaFile std::wstring CInterpretatorSvgBase::CreateDibPatternStyle(IBrush *pBrush) { - if (NULL == m_pParser || NULL == pBrush || NULL == m_pParser->GetPen()) + if (NULL == m_pParser || NULL == pBrush) return std::wstring(); BYTE* pBuffer = NULL; @@ -704,10 +704,15 @@ namespace MetaFile std::wstring wsImageDataW = NSFile::CUtf8Converter::GetUnicodeFromCharPtr(pImageData, (LONG)nImageSize); - double dStrokeWidth = std::fabs(m_pParser->GetPen()->GetWidth()); + double dStrokeWidth = 1. / m_pParser->GetTransform()->M11; - if (0.0 == dStrokeWidth || (1.0 == dStrokeWidth && PS_COSMETIC == (m_pParser->GetPen()->GetStyle() & PS_TYPE_MASK))) - dStrokeWidth = 1. / m_pParser->GetTransform()->M11; + if (NULL != m_pParser->GetPen()) + { + dStrokeWidth = std::fabs(m_pParser->GetPen()->GetWidth()); + + if (0.0 == dStrokeWidth || (1.0 == dStrokeWidth && PS_COSMETIC == (m_pParser->GetPen()->GetStyle() & PS_TYPE_MASK))) + dStrokeWidth = 1. / m_pParser->GetTransform()->M11; + } std::wstring wsWidth = ConvertToWString(dStrokeWidth * 10 * unHeight / unWidth); std::wstring wsHeight = ConvertToWString(dStrokeWidth * 10 * unWidth / unHeight); @@ -759,8 +764,6 @@ namespace MetaFile std::wstring wsImageDataW = NSFile::CUtf8Converter::GetUnicodeFromCharPtr(pImageData, (LONG)nImageSize); - double dStrokeWidth = 1. / m_pParser->GetTransform()->M11; - std::wstring wsWidth = ConvertToWString(oFrame.get_Width() / m_pParser->GetTransform()->M11); std::wstring wsHeight = ConvertToWString(oFrame.get_Height() / m_pParser->GetTransform()->M22); @@ -799,13 +802,13 @@ namespace MetaFile { wsStyleId = L"RADIALGRADIENT_" + ConvertToWString(++m_unNumberDefs, 0); - double dX = MININT8, dY = MININT8; + double dX = MININT32, dY = MININT32; pBrush->GetCenterPoint(dX, dY); std::wstring wsIndlude; - if (dX != MININT8 || dY != MININT8) + if (dX != MININT32 || dY != MININT32) { double dLeft, dTop, dWidth, dHeight; @@ -1374,8 +1377,8 @@ namespace MetaFile m_oStringBuilder.WriteNodeBegin(L"pattern", true); m_oStringBuilder.WriteAttribute(L"id", wsPatternId); - m_oStringBuilder.WriteAttribute(L"width", ((0 != m_dWidth) ? ConvertToWString((m_dStrokeWidth * 8.) / m_dWidth) : L"1")); - m_oStringBuilder.WriteAttribute(L"height", ((0 != m_dHeight) ? ConvertToWString((m_dStrokeWidth * 8.) / m_dHeight) : L"1")); + m_oStringBuilder.WriteAttribute(L"width", ((0 != m_dWidth) ? ConvertToWString((m_dStrokeWidth * 8.) / m_dWidth) : L"1")); + m_oStringBuilder.WriteAttribute(L"height", ((0 != m_dHeight) ? ConvertToWString((m_dStrokeWidth * 8.) / m_dHeight) : L"1")); m_oStringBuilder.WriteAttribute(L"patternUnits", L"objectBoundingBox"); m_oStringBuilder.WriteAttribute(L"shape-rendering", L"crispEdges"); m_oStringBuilder.WriteNodeEnd(L"pattern", true, false); diff --git a/MsBinaryFile/DocFile/DocumentMapping.cpp b/MsBinaryFile/DocFile/DocumentMapping.cpp index 25d3384542..840a52ed5b 100644 --- a/MsBinaryFile/DocFile/DocumentMapping.cpp +++ b/MsBinaryFile/DocFile/DocumentMapping.cpp @@ -1833,10 +1833,10 @@ namespace DocFileFormat { desc->bUsed = true; m_pXmlWriter->WriteNodeBegin( L"w:footnoteReference", true ); - if (desc->aFtnIdx == 0) - { - m_pXmlWriter->WriteAttribute( L"w:customMarkFollows", L"1"); - } + //if (desc->aFtnIdx == 0) + //{ + // m_pXmlWriter->WriteAttribute( L"w:customMarkFollows", L"1"); + //} m_pXmlWriter->WriteAttribute( L"w:id", FormatUtils::IntToWideString(_footnoteNr++ ) ); m_pXmlWriter->WriteNodeEnd( L"", true ); } @@ -1853,10 +1853,10 @@ namespace DocFileFormat { desc->bUsed = true; m_pXmlWriter->WriteNodeBegin( L"w:endnoteReference", true ); - if (desc->aEndIdx == 0) - { - m_pXmlWriter->WriteAttribute( L"w:customMarkFollows", L"1"); - } + //if (desc->aEndIdx == 0) + //{ + // m_pXmlWriter->WriteAttribute( L"w:customMarkFollows", L"1"); + //} m_pXmlWriter->WriteAttribute( L"w:id", FormatUtils::IntToWideString(_endnoteNr++ )); m_pXmlWriter->WriteNodeEnd( L"", true ); } diff --git a/OOXML/DocxFormat/Diagram/DiagramData.cpp b/OOXML/DocxFormat/Diagram/DiagramData.cpp index 036e6ee422..71a89458fd 100644 --- a/OOXML/DocxFormat/Diagram/DiagramData.cpp +++ b/OOXML/DocxFormat/Diagram/DiagramData.cpp @@ -950,6 +950,27 @@ namespace OOX *pPt = oReader; m_arrItems.push_back(pPt); } + else if (L"mc:AlternateContent" == sName) + { + int nCurDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nCurDepth)) + { + std::wstring strName = oReader.GetName(); + + if (oReader.IsEmptyNode()) + continue; + + if (strName == L"mc:Choice") + { + fromXML(oReader); + break; + } + else if (strName == L"mc:Fallback") + { + fromXML(oReader); + } + } + } } } diff --git a/OdfFile/Reader/Format/paragraph_elements.cpp b/OdfFile/Reader/Format/paragraph_elements.cpp index 95ee87e203..f72bc8bdc8 100644 --- a/OdfFile/Reader/Format/paragraph_elements.cpp +++ b/OdfFile/Reader/Format/paragraph_elements.cpp @@ -888,14 +888,13 @@ void note::docx_convert(oox::docx_conversion_context & Context) Context.get_notes_context().set_current_note(text_note_class_.get_type(), dynamic_cast(text_note_citation_.get())); - std::wstring sCustom = text_note_citation_ ? L" w:customMarkFollows=\"1\"" : L""; if (text_note_class_.get_type() == noteclass::Footnote) { - Context.output_stream() << ""; + Context.output_stream() << ""; } else { - Context.output_stream() << ""; + Context.output_stream() << ""; } if (text_note_citation_) diff --git a/PdfFile/PdfFile.pro b/PdfFile/PdfFile.pro index d5cd75b459..a76775e570 100644 --- a/PdfFile/PdfFile.pro +++ b/PdfFile/PdfFile.pro @@ -99,7 +99,7 @@ use_external_jpeg2000 { #CONFIG += build_viewer_module build_viewer_module { DEFINES += BUILDING_WASM_MODULE \ - TEST_AS_EXECUTABLE + TEST_CPP_BINARY HEADERS += $$CORE_ROOT_DIR/HtmlRenderer/include/HTMLRendererText.h SOURCES += $$CORE_ROOT_DIR/HtmlRenderer/src/HTMLRendererText.cpp @@ -201,5 +201,4 @@ HEADERS += PdfFile.h \ SOURCES += PdfFile.cpp \ PdfWriter.cpp \ PdfReader.cpp \ - OnlineOfficeBinToPdf.cpp \ - PdfWriter_empty.cpp + OnlineOfficeBinToPdf.cpp diff --git a/PdfFile/PdfWriter.cpp b/PdfFile/PdfWriter.cpp index 1bf785812d..044df413cd 100644 --- a/PdfFile/PdfWriter.cpp +++ b/PdfFile/PdfWriter.cpp @@ -34,7 +34,6 @@ #include "PdfWriter.h" -#ifndef BUILDING_WASM_MODULE #include "SrcWriter/Document.h" #include "SrcWriter/Pages.h" #include "SrcWriter/Image.h" @@ -2292,4 +2291,3 @@ std::wstring CPdfWriter::GetDownloadFile(const std::wstring& sUrl, const std::ws return L""; } -#endif // BUILDING_WASM_MODULE diff --git a/PdfFile/SrcReader/FontsWasm.h b/PdfFile/SrcReader/FontsWasm.h new file mode 100644 index 0000000000..bdd65ea9e5 --- /dev/null +++ b/PdfFile/SrcReader/FontsWasm.h @@ -0,0 +1,96 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2019 + * + * 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-12 Ernesta Birznieka-Upisha + * 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 + * + */ +#ifndef _FONTS_WASM_H +#define _FONTS_WASM_H + +#ifndef TEST_CPP_BINARY +#include "emscripten.h" +EM_JS(char*, js_get_stream_id, (unsigned char* data, unsigned char* status), { + return self.AscViewer.CheckStreamId(data, status); +}); +EM_JS(int, js_free_id, (unsigned char* data), { + self.AscViewer.Free(data); + return 1; +}); +#endif + +#include "../../DesktopEditor/graphics/pro/Fonts.h" +#include "../../DesktopEditor/common/File.h" + +namespace NSWasm +{ + bool IsJSEnv() + { +#ifdef TEST_CPP_BINARY + return false; +#else + return true; +#endif + } + + std::wstring LoadFont(const std::wstring& sFontPath, int bBold, int bItalic) + { + #ifndef TEST_CPP_BINARY + BYTE nStatus = 0; + NSWasm::CData oRes; + oRes.SkipLen(); + std::string sNameA = U_TO_UTF8(sFontPath); + oRes.WriteString((unsigned char*)sNameA.c_str(), (unsigned int)sNameA.length()); + oRes.AddInt(bBold); + oRes.AddInt(bItalic); + oRes.WriteLen(); + char* pFontId = js_get_stream_id(oRes.GetBuffer(), &nStatus); + std::wstring sRes; + if (nStatus) + { + std::string wsFileNameA(pFontId); + sRes = UTF8_TO_U(wsFileNameA); + } + js_free_id((unsigned char*)pFontId); + return sRes; + #else + // пока заглушка - тут надо прочитать в стрим, чтобы дальше правильно сработать с кодировками + if (!NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage()->Get(sFontPath)) + { + DWORD dwSize = 0; + BYTE* pData = NULL; + if (NSFile::CFileBinary::ReadAllBytes(sFontPath, &pData, dwSize)) + NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage()->Add(sFontPath, pData, (LONG)dwSize, true); + else + return std::wstring(); + } + return sFontPath; + #endif + } +} + +#endif // _FONTS_WASM_H diff --git a/PdfFile/SrcReader/RendererOutputDev.cpp b/PdfFile/SrcReader/RendererOutputDev.cpp index ea57d5d7f8..3682ca5067 100644 --- a/PdfFile/SrcReader/RendererOutputDev.cpp +++ b/PdfFile/SrcReader/RendererOutputDev.cpp @@ -57,17 +57,8 @@ #ifndef BUILDING_WASM_MODULE #define FONTS_USE_AFM_SETTINGS #else +#include "FontsWasm.h" #define FONTS_USE_ONLY_MEMORY_STREAMS -#ifndef TEST_AS_EXECUTABLE -#include "emscripten.h" -EM_JS(char*, js_get_stream_id, (unsigned char* data, unsigned char* status), { - return self.AscViewer.CheckStreamId(data, status); -}); -EM_JS(int, js_free_id, (unsigned char* data), { - self.AscViewer.Free(data); - return 1; -}); -#endif #endif #if defined(_MSC_VER) @@ -1223,7 +1214,7 @@ namespace PdfReader } } } - #ifndef BUILDING_WASM_MODULE + #ifndef FONTS_USE_ONLY_MEMORY_STREAMS else if (PdfReader::GetBaseFont(wsFontBaseName, pData14, nSize14)) { FILE* pFile = NULL; @@ -1382,38 +1373,20 @@ namespace PdfReader wsFileName = pFontInfo->m_wsFontPath; eFontType = pFont->isCIDFont() ? fontCIDType2 : fontTrueType; - #if defined(BUILDING_WASM_MODULE) && !defined(TEST_AS_EXECUTABLE) - BYTE nStatus = 0; - NSWasm::CData oRes; - oRes.SkipLen(); - std::string sNameA = U_TO_UTF8(pFontInfo->m_wsFontName); - oRes.WriteString((unsigned char*)sNameA.c_str(), (unsigned int)sNameA.length()); - oRes.AddInt(pFontInfo->m_bBold); - oRes.AddInt(pFontInfo->m_bItalic); - oRes.WriteLen(); - char* pFontId = js_get_stream_id(oRes.GetBuffer(), &nStatus); - if (!nStatus) - { - // шрифт не загружен. - m_pFontList->Remove(*pFont->getID()); - js_free_id((unsigned char*)pFontId); - return; - } - else - { - std::string wsFileNameA(pFontId); - wsFileName = UTF8_TO_U(wsFileNameA); - oMemoryFontStream.fromStream(wsFileName); - } - js_free_id((unsigned char*)pFontId); - #else #ifdef FONTS_USE_ONLY_MEMORY_STREAMS - // пока заглушка - тут надо прочитать в стрим, чтобы дальше правильно сработать с кодировками - DWORD dwSize = 0; - NSFile::CFileBinary::ReadAllBytes(wsFileName, &oMemoryFontStream.m_pData, dwSize); - oMemoryFontStream.m_nSize = (int)dwSize; - NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage()->Add(wsFileName, oMemoryFontStream.m_pData, (LONG)oMemoryFontStream.m_nSize, true); - #endif + if (NSWasm::IsJSEnv()) + wsFileName = pFontInfo->m_wsFontName; + + if (!wsFileName.empty()) + { + wsFileName = NSWasm::LoadFont(wsFileName, pFontInfo->m_bBold, pFontInfo->m_bItalic); + if (wsFileName.empty()) + { + m_pFontList->Remove(*pFont->getID()); + return; + } + } + oMemoryFontStream.fromStream(wsFileName); #endif bFontSubstitution = true; @@ -3909,9 +3882,58 @@ namespace PdfReader } } - float fAscent = pGState->getFontSize(); if (nRenderMode == 0 || nRenderMode == 2 || nRenderMode == 4 || nRenderMode == 6) { + #ifdef BUILDING_WASM_MODULE + std::wstring sFontPath; + m_pRenderer->get_FontPath(&sFontPath); + if (!unGid && !wsUnicodeText.empty() && !sFontPath.empty()) + { + unsigned int lUnicode = (unsigned int)wsUnicodeText[0]; + long lStyle; + m_pRenderer->get_FontStyle(&lStyle); + m_pFontManager->LoadFontFromFile(sFontPath, 0, 10, 72, 72); + + NSFonts::IFontFile* pFontFile = m_pFontManager->GetFile(); + if (pFontFile) + { + int nCMapIndex = 0; + int GID = pFontFile->SetCMapForCharCode(lUnicode, &nCMapIndex); + if (GID <= 0 && lUnicode < 0xF000) + GID = pFontFile->SetCMapForCharCode(lUnicode + 0xF000, &nCMapIndex); + + if (GID <= 0) + { + std::wstring sName = m_pFontManager->GetApplication()->GetFontBySymbol(lUnicode); + int bBold = lStyle & 0x01 ? 1 : 0; + int bItalic = lStyle & 0x02 ? 1 : 0; + + if (!sName.empty()) + { + if (!NSWasm::IsJSEnv()) + { + NSFonts::CFontSelectFormat oFormat; + oFormat.wsName = new std::wstring(sName); + oFormat.bBold = new INT(bBold); + oFormat.bItalic = new INT(bItalic); + NSFonts::CFontInfo* pFontInfo = m_pFontManager->GetFontInfoByParams(oFormat); + + sName = pFontInfo->m_wsFontPath; + } + + std::wstring wsFileName = NSWasm::LoadFont(sName, bBold, bItalic); + if (wsFileName.empty()) + { + m_pFontList->Remove(*pGState->getFont()->getID()); + return; + } + m_pRenderer->put_FontPath(wsFileName); + } + } + } + } + #endif + m_pRenderer->CommandDrawTextEx(wsUnicodeText, &unGid, unGidsCount, PDFCoordsToMM(0 + dShiftX), PDFCoordsToMM(dShiftY), PDFCoordsToMM(dDx), PDFCoordsToMM(dDy)); } diff --git a/PdfFile/SrcWriter/Field.h b/PdfFile/SrcWriter/Field.h index 317d85b2c1..8837a53158 100644 --- a/PdfFile/SrcWriter/Field.h +++ b/PdfFile/SrcWriter/Field.h @@ -36,7 +36,7 @@ #include "Objects.h" #include "Types.h" #include "Annotation.h" -#include "../DesktopEditor/graphics/FormField.h" +#include "../../DesktopEditor/graphics/FormField.h" namespace PdfWriter {