From 52141627182e7de47b660535e5caac9898c62c7d Mon Sep 17 00:00:00 2001 From: Kulikova Svetlana Date: Mon, 26 Jul 2021 18:37:49 +0300 Subject: [PATCH] general compilation and optimization glyphs --- DesktopEditor/fontengine/FontManager.cpp | 2 + .../graphics/pro/js/wasm/js/xps_base.js | 73 +++++++++++++------ .../graphics/pro/js/wasm/src/wasmgraphics.cpp | 34 +++++---- DesktopEditor/graphics/pro/js/xps_make.py | 5 +- DjVuFile/DjVuFileImplementation.cpp | 3 + DjVuFile/wasm/make.py | 4 +- XpsFile/XpsLib/Page.cpp | 33 +++++---- 7 files changed, 99 insertions(+), 55 deletions(-) diff --git a/DesktopEditor/fontengine/FontManager.cpp b/DesktopEditor/fontengine/FontManager.cpp index b1a82c72e0..04cd9d15a7 100644 --- a/DesktopEditor/fontengine/FontManager.cpp +++ b/DesktopEditor/fontengine/FontManager.cpp @@ -231,6 +231,8 @@ NSFonts::IFontFile* CFontsCache::LockFont(NSFonts::CLibrary& library, const std: return pFile; CFontStream* pStream = (CFontStream*)m_pApplicationFontStreams->GetStream(strFileName); + if (NULL == pStream) + return NULL; pFile = (CFontFile*)CFontManager::LoadFontFile(library, pStream, lFaceIndex); if (NULL == pFile) return NULL; diff --git a/DesktopEditor/graphics/pro/js/wasm/js/xps_base.js b/DesktopEditor/graphics/pro/js/wasm/js/xps_base.js index 61b478a2bf..c3fa9dfe98 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/xps_base.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/xps_base.js @@ -153,33 +153,62 @@ index += lenRec; lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24; index += 4; - var _X = parseFloat("".fromUtf8(buffer, index, lenRec)); - index += lenRec; - lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24; - index += 4; - var _Y = parseFloat("".fromUtf8(buffer, index, lenRec)); - // TODO: близость - if (_Y != prevY) + let amount = lenRec; + for (var i = 0; i < amount; i++) { - if (Line >= 0) - this.pages[pageIndex].Lines[Line].Glyphs.sort((prev, next) => prev.X - next.X); - Line++; - this.pages[pageIndex].Lines.push({ Glyphs : [] }); - prevY = _Y; + lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24; + index += 4; + var _X = parseFloat("".fromUtf8(buffer, index, lenRec)); + index += lenRec; + lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24; + index += 4; + var _Y = parseFloat("".fromUtf8(buffer, index, lenRec)); + if (_Y != prevY) + { + if (Line >= 0) + this.pages[pageIndex].Lines[Line].Glyphs.sort((prev, next) => prev.X - next.X); + Line++; + this.pages[pageIndex].Lines.push({ Glyphs : [] }); + prevY = _Y; + } + index += lenRec; + lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24; + index += 4; + this.pages[pageIndex].Lines[Line].Glyphs.push({ + fontName : _fontName, + fontSize : _fontSize, + X : _X * 1.015, + Y : _Y * 1.015, + UChar : String.fromCharCode(lenRec) + }); } - index += lenRec; - lenRec = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24; - index += 4; - this.pages[pageIndex].Lines[Line].Glyphs.push({ - fontName : _fontName, - fontSize : _fontSize, - X : _X * 1.015, - Y : _Y * 1.015, - UChar : String.fromCharCode(lenRec) - }); } this.pages[pageIndex].Lines.sort((prev, next) => prev.Glyphs[0].Y - next.Glyphs[0].Y); + + prevY = -1; + var prevFontName = ""; + var prevFontSize = ""; + for (let i = 0; i < this.pages[pageIndex].Lines.length; i++) + { + for (let j = 0; j < this.pages[pageIndex].Lines[i].Glyphs.length; j++) + { + let glyph = this.pages[pageIndex].Lines[i].Glyphs[j]; + if (glyph.fontName == prevFontName) + delete glyph.fontName; + else + prevFontName = glyph.fontName; + if (glyph.fontSize == prevFontSize && j != 0) + delete glyph.fontSize; + else + prevFontSize = glyph.fontSize; + if (glyph.Y == prevY && j != 0) + delete glyph.Y; + else + prevY = glyph.Y; + } + } Module["_XPS_Delete"](glyphs); + return res; }; CFile.prototype.structure = function() diff --git a/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.cpp b/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.cpp index 42ec13b6d8..b67ea05e5f 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.cpp @@ -112,9 +112,6 @@ int main() int width = info[1] * 96 / info[3]; int height = info[2] * 96 / info[3]; BYTE* res = NULL; - if (pages_count > 0) - res = XPS_GetPixmap(test, 0, width, height); - RELEASEARRAYOBJECTS(res); if (pages_count > 0) res = XPS_GetPixmap(test, 0, width, height); @@ -138,23 +135,30 @@ int main() { DWORD nPathLength = GetLength(pGlyphs + i); i += 4; - std::cout << std::string((char*)(pGlyphs + i), nPathLength) << " "; + std::cout << "Font " << std::string((char*)(pGlyphs + i), nPathLength) << " "; i += nPathLength; nPathLength = GetLength(pGlyphs + i); i += 4; - std::cout << std::string((char*)(pGlyphs + i), nPathLength) << " "; + std::cout << "Size " << std::string((char*)(pGlyphs + i), nPathLength) << " "; i += nPathLength; nPathLength = GetLength(pGlyphs + i); i += 4; - std::cout << std::string((char*)(pGlyphs + i), nPathLength) << " "; - i += nPathLength; - nPathLength = GetLength(pGlyphs + i); - i += 4; - std::cout << std::string((char*)(pGlyphs + i), nPathLength) << " "; - i += nPathLength; - nPathLength = GetLength(pGlyphs + i); - i += 4; - std::cout << nPathLength << std::endl; + std::cout << "Amount " << nPathLength << std::endl; + DWORD nAmount = nPathLength; + for (DWORD j = 0; j < nAmount; j++) + { + nPathLength = GetLength(pGlyphs + i); + i += 4; + std::cout << "X " << std::string((char*)(pGlyphs + i), nPathLength) << " "; + i += nPathLength; + nPathLength = GetLength(pGlyphs + i); + i += 4; + std::cout << "Y " << std::string((char*)(pGlyphs + i), nPathLength) << " "; + i += nPathLength; + nPathLength = GetLength(pGlyphs + i); + i += 4; + std::cout << "Symbol " << nPathLength << std::endl; + } } BYTE* pStructure = XPS_GetStructure(test); @@ -206,7 +210,7 @@ int main() int height = info[2] * 96 / info[3]; BYTE* res = NULL; if (pages_count > 0) - res = XPS_GetPixmap(test, 0, width, height); + res = XPS_GetPixmap(test, 1, width, height); for (int i = 0; i < 100; i++) std::cout << (int)res[i] << " "; diff --git a/DesktopEditor/graphics/pro/js/xps_make.py b/DesktopEditor/graphics/pro/js/xps_make.py index 907d6cce2b..8e1752c28e 100644 --- a/DesktopEditor/graphics/pro/js/xps_make.py +++ b/DesktopEditor/graphics/pro/js/xps_make.py @@ -4,8 +4,9 @@ import base import os if not base.is_file("raster.o"): - print("Please use raster_make.py previously") - exit(0) + base.cmd("python", ["raster_make.py"]) +if not base.is_file("raster.o"): + exit(0) base.configure_common_apps() diff --git a/DjVuFile/DjVuFileImplementation.cpp b/DjVuFile/DjVuFileImplementation.cpp index 82f8e7b2fe..9b852ac08f 100644 --- a/DjVuFile/DjVuFileImplementation.cpp +++ b/DjVuFile/DjVuFileImplementation.cpp @@ -698,6 +698,9 @@ void CDjVuFileImplementation::CreateFrame(IRenderer* pRenderer, GP { TextToRenderer(pRenderer, text, dPixToMM / nDpi); } + #ifdef WASM_MODE + TextToRenderer(pRenderer, text, dPixToMM / nDpi); + #endif pRenderer->DrawImage((IGrObject*)&oImage, 0, 0, dRendWidth, dRendHeight); pRenderer->EndCommand(c_nPageType); diff --git a/DjVuFile/wasm/make.py b/DjVuFile/wasm/make.py index f942e63a91..40cdc4d379 100644 --- a/DjVuFile/wasm/make.py +++ b/DjVuFile/wasm/make.py @@ -94,12 +94,14 @@ base.copy_file("./all_files_test/index.html", "./deploy/index.html") base.copy_file("./all_files_test/code.js", "./deploy/code.js") base.copy_file("./all_files_test/file.js", "./deploy/file.js") base.copy_dir("./all_files_test/pdf", "./deploy/pdf") +if not base.is_dir("./../../DesktopEditor/graphics/pro/js/deploy"): + base.cmd_in_dir("./../../DesktopEditor/graphics/pro/js", "python", ["xps_make.py"]) if base.is_dir("./../../DesktopEditor/graphics/pro/js/deploy"): base.create_dir("./deploy/xps") base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/xps.js", "./deploy/xps/xps.js") base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/xps.wasm", "./deploy/xps/xps.wasm") else: - print("xps_make.py not used. core/DesktopEditor/graphics/pro/js/xps_make.py") + print("xps_make.py error") base.copy_dir("./all_files_test/xps", "./deploy/xps") base.delete_file("djvu.js") diff --git a/XpsFile/XpsLib/Page.cpp b/XpsFile/XpsLib/Page.cpp index c0f4159588..f2c7403814 100644 --- a/XpsFile/XpsLib/Page.cpp +++ b/XpsFile/XpsLib/Page.cpp @@ -684,6 +684,24 @@ namespace XPS if (!bIsSideways) { + #ifdef BUILDING_WASM_MODULE + if (!m_pGlyphs) + { + m_pGlyphs = new CData(); + m_pGlyphs->SkipLen(); + } + + double pdA, pdB, pdC, pdD, pdE, pdF; + pRenderer->GetTransform(&pdA, &pdB, &pdC, &pdD, &pdE, &pdF); + Aggplus::CMatrix oTransform(pdA, pdB, pdC, pdD, pdE, pdF); + + std::string sFontName = U_TO_UTF8(m_pFontManager->GetName()); + m_pGlyphs->WriteString((BYTE*)sFontName.c_str(), sFontName.length()); + std::string sFontSize = std::to_string(dFontSize * pdA + pdE); + m_pGlyphs->WriteString((BYTE*)sFontSize.c_str(), sFontSize.length()); + m_pGlyphs->AddInt(unUtf16Len); + #endif + while (GetNextGlyph(wsIndices.c_str(), nIndicesPos, nIndicesLen, pUtf16, nUtf16Pos, unUtf16Len, oEntry)) { double dAdvance, dRealAdvance; @@ -716,25 +734,10 @@ namespace XPS } #ifdef BUILDING_WASM_MODULE - if (!m_pGlyphs) - { - m_pGlyphs = new CData(); - m_pGlyphs->SkipLen(); - } - double _dX = dXorigin; double _dY = dYorigin; - double pdA, pdB, pdC, pdD, pdE, pdF; - pRenderer->GetTransform(&pdA, &pdB, &pdC, &pdD, &pdE, &pdF); - Aggplus::CMatrix oTransform(pdA, pdB, pdC, pdD, pdE, pdF); oTransform.TransformPoint(_dX, _dY); - std::wstring wsFontName; - pRenderer->get_FontName(&wsFontName); - std::string sFontName = U_TO_UTF8(wsFontName); - m_pGlyphs->WriteString((BYTE*)sFontName.c_str(), sFontName.length()); - std::string sFontSize = std::to_string(dFontSize * pdA + pdE); - m_pGlyphs->WriteString((BYTE*)sFontSize.c_str(), sFontSize.length()); std::string sX = std::to_string(_dX); m_pGlyphs->WriteString((BYTE*)sX.c_str(), sX.length()); std::string sY = std::to_string(_dY);