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

dump correct gid->unicode map for fontforge

This commit is contained in:
Lu Wang 2012-08-10 01:16:04 +08:00
parent 917dbc6233
commit 648f7a1e2a
2 changed files with 34 additions and 15 deletions

View File

@ -12,7 +12,9 @@ if [ -f convert.pe ]; then
echo -n "Converting fonts: "
fontforge -script convert.pe 2>/dev/null
echo "."
# rm convert.pe
rm convert.pe
fi
rm *.encoding 2>/dev/null
echo "Done."

View File

@ -442,26 +442,43 @@ void HTMLRenderer::install_embedded_font (GfxFont * font, long long fn_id)
{
//generate script for fontforge
fontscript_fout << boost::format("Open(\"%1%(%2%)\",1)") % param->input_filename % font->getName()->getCString() << endl;
if(font->hasToUnicodeCMap())
if(font->hasToUnicodeCMap() && (font->getType() == fontTrueType))
{
auto ctu = font->getToUnicode();
ofstream map_fout((boost::format("f%|1$x|.encoding") % fn_id).str().c_str());
for(int i = 0; i < 256; ++i)
char * buf;
int buflen;
FoFiTrueType * ttf;
if((buf = font->readEmbFontFile(xref, &buflen)))
{
Unicode * u;
auto n = ctu->mapToUnicode(i, &u);
// not sure what to do when n > 1
if(n > 0)
if((ttf = FoFiTrueType::make(buf, buflen)))
{
map_fout << boost::format("0x%|1$X|") % i;
for(int j = 0; j < n; ++j)
map_fout << boost::format(" 0x%|1$X|") % u[i];
map_fout << " #" << endl;
auto ctg = dynamic_cast<Gfx8BitFont*>(font)->getCodeToGIDMap(ttf);
auto ctu = font->getToUnicode();
ofstream map_fout((boost::format("f%|1$x|.encoding") % fn_id).str().c_str());
for(int i = 0; i < 256; ++i)
{
int code = ctg[i];
Unicode * u;
auto n = ctu->mapToUnicode(i, &u);
// not sure what to do when n > 1
if(n > 0)
{
map_fout << boost::format("0x%|1$X|") % code;
for(int j = 0; j < n; ++j)
map_fout << boost::format(" 0x%|1$X|") % u[j];
map_fout << boost::format(" # 0x%|1$X|") % i << endl;
}
}
fontscript_fout << boost::format("LoadEncodingFile(\"f%|1$x|.encoding\", \"f%|1$x|\")") % fn_id << endl;
fontscript_fout << boost::format("Reencode(\"f%|1$x|\", 1)") % fn_id << endl;
ctu->decRefCnt();
delete ttf;
}
gfree(buf);
}
fontscript_fout << boost::format("LoadEncodingFile(\"f%|1$x|.encoding\")") % fn_id << endl;
fontscript_fout << boost::format("Reencode(\"f%|1$x|.encoding\")") % fn_id << endl;
}
fontscript_fout << boost::format("Generate(\"f%|1$x|.ttf\")") % fn_id << endl;