From 1878b8fc331fff643570ae6d02701e5d10c17448 Mon Sep 17 00:00:00 2001 From: Kulikova Svetlana Date: Tue, 6 Sep 2022 18:00:49 +0300 Subject: [PATCH] add cidToUnicode files --- DesktopEditor/graphics/pro/js/.gitignore | 1 + DesktopEditor/graphics/pro/js/before.py | 16 ++++++++++ .../graphics/pro/js/wasm/src/drawingfile.h | 2 +- PdfReader/lib/xpdf/CharCodeToUnicode.h | 9 +++--- PdfReader/lib/xpdf/GlobalParams.cc | 31 +++++++++++++++++++ 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/DesktopEditor/graphics/pro/js/.gitignore b/DesktopEditor/graphics/pro/js/.gitignore index e625b61da7..6d0075be4a 100644 --- a/DesktopEditor/graphics/pro/js/.gitignore +++ b/DesktopEditor/graphics/pro/js/.gitignore @@ -3,3 +3,4 @@ emsdk freetype-2.10.4 o xml +fonts diff --git a/DesktopEditor/graphics/pro/js/before.py b/DesktopEditor/graphics/pro/js/before.py index 769ccd2c4a..ec2e8522fd 100644 --- a/DesktopEditor/graphics/pro/js/before.py +++ b/DesktopEditor/graphics/pro/js/before.py @@ -32,4 +32,20 @@ if not base.is_dir("freetype-2.10.4"): common.apply_patch("./freetype-2.10.4/src/sfnt/sfnt.cpp", "./wasm/patches/sfnt.patch") common.apply_patch("./freetype-2.10.4/builds/unix/ftsystem.c", "./wasm/patches/ftsystem.patch") +def apply_font_patch(file_name, arr_name): + file_content = base.readFile("../../../../PdfReader/Resources/CMap/" + file_name) + arr_str_cidToUnicode = file_content.splitlines() + arr_int_cidToUnicode = [int(i, 16) for i in arr_str_cidToUnicode] + res_content = ("static const unsigned int c_arr" + arr_name + "[]={") + res_content += ','.join(map(str, arr_int_cidToUnicode)) + res_content += ("};\nstatic const unsigned int c_n" + arr_name + "=" + str(len(arr_int_cidToUnicode)) + ";") + base.writeFile("./fonts/" + file_name + ".h", res_content) + +if not base.is_dir("fonts"): + base.create_dir("./fonts") + apply_font_patch("Adobe-GB1.cidToUnicode", "Adobe_GB1") + apply_font_patch("Adobe-Korea1.cidToUnicode", "Adobe_Korea1") + apply_font_patch("Adobe-KR.cidToUnicode", "Adobe_KR") + apply_font_patch("Adobe-Japan1.cidToUnicode", "Adobe_Japan1") + base.replaceInFile("../../../../Common/3dParty/icu/icu/source/common/udata.cpp", "\n{\n UDataMemory tData;", "\n{\n#ifdef BUILDING_WASM_MODULE\nreturn NULL;\n#endif\n UDataMemory tData;") diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h index 8aed9da705..d9bf915406 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h @@ -47,7 +47,7 @@ public: if (nType == 0) { pReader = new PdfReader::CPdfReader(pApplicationFonts); - std::wstring sPath = NSFile::GetProcessDirectory() + L"../../../../../../../../PdfReader/Resources/CMap"; + std::wstring sPath = NSFile::GetProcessDirectory() + L"/../../../../../../../../PdfReader/Resources/CMap"; ((PdfReader::CPdfReader*)pReader)->SetCMapFolder(sPath.data()); } else if (nType == 1) diff --git a/PdfReader/lib/xpdf/CharCodeToUnicode.h b/PdfReader/lib/xpdf/CharCodeToUnicode.h index c390a8c5c5..feb45b8d49 100644 --- a/PdfReader/lib/xpdf/CharCodeToUnicode.h +++ b/PdfReader/lib/xpdf/CharCodeToUnicode.h @@ -30,6 +30,11 @@ struct CharCodeToUnicodeString; class CharCodeToUnicode { public: + CharCodeToUnicode(GString *tagA, Unicode *mapA, + CharCode mapLenA, GBool copyMap, + CharCodeToUnicodeString *sMapA, + int sMapLenA, int sMapSizeA); + // Create an identity mapping (Unicode = CharCode). static CharCodeToUnicode *makeIdentityMapping(); @@ -84,10 +89,6 @@ private: void addMappingInt(CharCode code, Unicode u); CharCodeToUnicode(); CharCodeToUnicode(GString *tagA); - CharCodeToUnicode(GString *tagA, Unicode *mapA, - CharCode mapLenA, GBool copyMap, - CharCodeToUnicodeString *sMapA, - int sMapLenA, int sMapSizeA); GString *tag; Unicode *map; diff --git a/PdfReader/lib/xpdf/GlobalParams.cc b/PdfReader/lib/xpdf/GlobalParams.cc index 3fa82904f6..e49b3ea617 100644 --- a/PdfReader/lib/xpdf/GlobalParams.cc +++ b/PdfReader/lib/xpdf/GlobalParams.cc @@ -125,6 +125,13 @@ static const char *displayFontDirs[] = { static const char *macSystemFontPath = "/System/Library/Fonts"; #endif +#ifdef BUILDING_WASM_MODULE +#include "../../../DesktopEditor/graphics/pro/js/fonts/Adobe-GB1.cidToUnicode.h" +#include "../../../DesktopEditor/graphics/pro/js/fonts/Adobe-Japan1.cidToUnicode.h" +#include "../../../DesktopEditor/graphics/pro/js/fonts/Adobe-Korea1.cidToUnicode.h" +#include "../../../DesktopEditor/graphics/pro/js/fonts/Adobe-KR.cidToUnicode.h" +#endif + struct Base14FontInfo { Base14FontInfo(GString *fileNameA, int fontNumA, double obliqueA) { fileName = fileNameA; @@ -3377,10 +3384,34 @@ CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) { lockGlobalParams; if (!(ctu = cidToUnicodeCache->getCharCodeToUnicode(collection))) { + +#ifdef BUILDING_WASM_MODULE + if (collection->cmp("Adobe-GB1") == 0) + { + ctu = new CharCodeToUnicode(collection->copy(), (Unicode*)c_arrAdobe_GB1, c_nAdobe_GB1, gTrue, NULL, 0, 0); + cidToUnicodeCache->add(ctu); + } + else if (collection->cmp("Adobe-Korea1") == 0) + { + ctu = new CharCodeToUnicode(collection->copy(), (Unicode*)c_arrAdobe_Korea1, c_nAdobe_Korea1, gTrue, NULL, 0, 0); + cidToUnicodeCache->add(ctu); + } + else if (collection->cmp("Adobe-KR") == 0) + { + ctu = new CharCodeToUnicode(collection->copy(), (Unicode*)c_arrAdobe_KR, c_nAdobe_KR, gTrue, NULL, 0, 0); + cidToUnicodeCache->add(ctu); + } + else if (collection->cmp("Adobe-Japan1") == 0) + { + ctu = new CharCodeToUnicode(collection->copy(), (Unicode*)c_arrAdobe_Japan1, c_nAdobe_Japan1, gTrue, NULL, 0, 0); + cidToUnicodeCache->add(ctu); + } +#elif if ((fileName = (GString *)cidToUnicodes->lookup(collection)) && (ctu = CharCodeToUnicode::parseCIDToUnicode(fileName, collection))) { cidToUnicodeCache->add(ctu); } +#endif } unlockGlobalParams; return ctu;