1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00

working on font encoding

This commit is contained in:
Lu Wang 2012-08-27 06:51:35 +08:00
parent adf6d686c1
commit 09cf5f6d6a
3 changed files with 25 additions and 36 deletions

View File

@ -285,7 +285,6 @@ class HTMLRenderer : public OutputDev
static const std::string NECK_HTML_FILENAME; static const std::string NECK_HTML_FILENAME;
static const std::string TAIL_HTML_FILENAME; static const std::string TAIL_HTML_FILENAME;
static const std::string CSS_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 // for cross-platform purpose, use a "null" file instead of /dev/null
static const std::string NULL_FILENAME; static const std::string NULL_FILENAME;
}; };

View File

@ -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::TAIL_HTML_FILENAME = "tail.html";
const std::string HTMLRenderer::CSS_FILENAME = "all.css"; const std::string HTMLRenderer::CSS_FILENAME = "all.css";
const std::string HTMLRenderer::NULL_FILENAME = "null"; const std::string HTMLRenderer::NULL_FILENAME = "null";
const std::string HTMLRenderer::FONTFORGE_SCRIPT_FILENAME = "pdf2htmlEX.pe";

View File

@ -122,9 +122,9 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix,
string fn = (format("f%|1$x|") % fn_id).str(); 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); 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; 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; int maxcode = 0;
// if we cannot map to unicode through ctu, map the char to private Unicode values // 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; int n = 0;
if(ctu) 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; return (Unicode)(c + 0xE000);
_ = c + 0xE000;
*u = &_;
n = 1;
} }
else
return n; return *u;
}; };
if(!font->isCIDFont()) if(!font->isCIDFont())
@ -158,6 +156,8 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix,
maxcode = 0xff; maxcode = 0xff;
if(suffix == ".ttf") if(suffix == ".ttf")
{ {
/*
script_fout << "Reencode(\"original\")" << endl;
int buflen; int buflen;
char * buf = nullptr; char * buf = nullptr;
if((buf = font->readEmbFontFile(xref, &buflen))) if((buf = font->readEmbFontFile(xref, &buflen)))
@ -171,15 +171,18 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix,
} }
gfree(buf); gfree(buf);
} }
*/
} }
else else
{ {
script_fout << "Reencode(\"unicode\")" << endl; // 1 pfa do not need this
// script_fout << "Reencode(\"unicode\")" << endl;
} }
} }
else else
{ {
maxcode = 0xffff; maxcode = 0xffff;
if(suffix == ".ttf") if(suffix == ".ttf")
{ {
script_fout << "Reencode(\"original\")" << endl; 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")); map_fout << format("0x%|1$X|") % ((code2GID && (i < code2GID_len))? code2GID[i] : i);
add_tmp_file(fn+".encoding"); map_fout << format(" 0x%|1$X|") % map_to_unicode(i);
map_fout << format(" # 0x%|1$X|") % i << endl;
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;
}
} }
script_fout << format("LoadEncodingFile(%1%, \"%2%\")") % (tmp_dir / (fn+".encoding")) % fn << endl;
script_fout << format("Reencode(\"%1%\", 1)") % fn << endl;
if(ctu) if(ctu)
ctu->decRefCnt(); ctu->decRefCnt();