From 09cf5f6d6aea246eac37e6de482ce9928fae7323 Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Mon, 27 Aug 2012 06:51:35 +0800 Subject: [PATCH] working on font encoding --- src/HTMLRenderer.h | 1 - src/HTMLRenderer/general.cc | 1 - src/HTMLRenderer/install.cc | 59 ++++++++++++++++--------------------- 3 files changed, 25 insertions(+), 36 deletions(-) diff --git a/src/HTMLRenderer.h b/src/HTMLRenderer.h index 2abc92e..2e6fd2f 100644 --- a/src/HTMLRenderer.h +++ b/src/HTMLRenderer.h @@ -285,7 +285,6 @@ class HTMLRenderer : public OutputDev static const std::string NECK_HTML_FILENAME; static const std::string TAIL_HTML_FILENAME; static const std::string CSS_FILENAME; - static const std::string FONTFORGE_SCRIPT_FILENAME; // for cross-platform purpose, use a "null" file instead of /dev/null static const std::string NULL_FILENAME; }; diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index 5fa45f8..fcc2d24 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -243,4 +243,3 @@ const std::string HTMLRenderer::NECK_HTML_FILENAME = "neck.html"; const std::string HTMLRenderer::TAIL_HTML_FILENAME = "tail.html"; const std::string HTMLRenderer::CSS_FILENAME = "all.css"; const std::string HTMLRenderer::NULL_FILENAME = "null"; -const std::string HTMLRenderer::FONTFORGE_SCRIPT_FILENAME = "pdf2htmlEX.pe"; diff --git a/src/HTMLRenderer/install.cc b/src/HTMLRenderer/install.cc index 745c319..57141e0 100644 --- a/src/HTMLRenderer/install.cc +++ b/src/HTMLRenderer/install.cc @@ -122,9 +122,9 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix, string fn = (format("f%|1$x|") % fn_id).str(); - path script_path = tmp_dir / FONTFORGE_SCRIPT_FILENAME; + path script_path = tmp_dir / (fn + ".pe"); ofstream script_fout(script_path, ofstream::binary); - add_tmp_file(FONTFORGE_SCRIPT_FILENAME); + add_tmp_file(fn+".pe"); script_fout << format("Open(%1%, 1)") % (tmp_dir / (fn + suffix)) << endl; @@ -134,23 +134,21 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix, int maxcode = 0; // if we cannot map to unicode through ctu, map the char to private Unicode values - auto map_to_unicode = [&ctu, this](int c, Unicode ** u)->int + auto map_to_unicode = [&ctu](int c)->Unicode { + Unicode *u; int n = 0; if(ctu) { - n = ctu->mapToUnicode(c, u); + n = ctu->mapToUnicode(c, &u); } - if((n == 0) || (!all_of(*u, (*u)+n, isLegalUnicode))) + if((n == 0) || (n > 1) || (!isLegalUnicode(*u))) { - static Unicode _ = 0; - _ = c + 0xE000; - *u = &_; - n = 1; + return (Unicode)(c + 0xE000); } - - return n; + else + return *u; }; if(!font->isCIDFont()) @@ -158,6 +156,8 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix, maxcode = 0xff; if(suffix == ".ttf") { + /* + script_fout << "Reencode(\"original\")" << endl; int buflen; char * buf = nullptr; if((buf = font->readEmbFontFile(xref, &buflen))) @@ -171,15 +171,18 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix, } gfree(buf); } + */ } else { - script_fout << "Reencode(\"unicode\")" << endl; + // 1 pfa do not need this +// script_fout << "Reencode(\"unicode\")" << endl; } } else { maxcode = 0xffff; + if(suffix == ".ttf") { script_fout << "Reencode(\"original\")" << endl; @@ -196,31 +199,19 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix, } } - if(maxcode > 0) + ofstream map_fout(tmp_dir / (fn + ".encoding")); + add_tmp_file(fn+".encoding"); + + for(int i = 0; i <= maxcode; ++i) { - ofstream map_fout(tmp_dir / (fn + ".encoding")); - add_tmp_file(fn+".encoding"); - - int cnt = 0; - for(int i = 0; i <= maxcode; ++i) - { - Unicode * u; - int n = map_to_unicode(i, &u); - // not sure what to do when n > 1 - ++cnt; - map_fout << format("0x%|1$X|") % ((code2GID && (i < code2GID_len))? code2GID[i] : i); - for(int j = 0; j < n; ++j) - map_fout << format(" 0x%|1$X|") % u[j]; - map_fout << format(" # 0x%|1$X|") % i << endl; - } - - if(cnt > 0) - { - script_fout << format("LoadEncodingFile(%1%, \"%2%\")") % (tmp_dir / (fn+".encoding")) % fn << endl; - script_fout << format("Reencode(\"%1%\", 1)") % fn << endl; - } + map_fout << format("0x%|1$X|") % ((code2GID && (i < code2GID_len))? code2GID[i] : i); + map_fout << format(" 0x%|1$X|") % map_to_unicode(i); + map_fout << format(" # 0x%|1$X|") % i << endl; } + script_fout << format("LoadEncodingFile(%1%, \"%2%\")") % (tmp_dir / (fn+".encoding")) % fn << endl; + script_fout << format("Reencode(\"%1%\", 1)") % fn << endl; + if(ctu) ctu->decRefCnt();