From 4fec08e764fd4801a114b13d1bf73713951ee1c9 Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Thu, 23 Aug 2012 21:30:37 +0200 Subject: [PATCH] better font processing --- src/HTMLRenderer/install.cc | 35 +++++++++++++++++++++++++++-------- src/HTMLRenderer/text.cc | 2 +- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/HTMLRenderer/install.cc b/src/HTMLRenderer/install.cc index 1c7d56e..7632027 100644 --- a/src/HTMLRenderer/install.cc +++ b/src/HTMLRenderer/install.cc @@ -12,6 +12,7 @@ #include #include +#include #include "HTMLRenderer.h" #include "namespace.h" @@ -130,25 +131,39 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix, int code2GID_len = 0; if(ctu) { - // TODO: ctu could be CID2Unicode for CID fonts int maxcode = 0; if(!font->isCIDFont()) { - maxcode = 0xff; - if(suffix != ".ttf") + if(suffix == ".ttf") { + maxcode = 0xff; + script_fout << "Reencode(\"original\")" << endl; + int buflen; + char * buf = nullptr; + if((buf = font->readEmbFontFile(xref, &buflen))) + { + FoFiTrueType *fftt = nullptr; + if((fftt = FoFiTrueType::make(buf, buflen))) + { + code2GID = dynamic_cast(font)->getCodeToGIDMap(fftt); + code2GID_len = 256; + delete fftt; + } + gfree(buf); + } + } + else + { + // don't reencode non-ttf 8bit fonts with ToUnicode + maxcode = 0; script_fout << "Reencode(\"unicode\")" << endl; } } else { maxcode = 0xffff; - if(suffix != ".ttf") - { - script_fout << "CIDFlatten()" << endl; - } - else + if(suffix == ".ttf") { script_fout << "Reencode(\"original\")" << endl; @@ -158,6 +173,10 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix, code2GID = _font->getCIDToGID(); code2GID_len = _font->getCIDToGIDLen(); } + else + { + script_fout << "CIDFlatten()" << endl; + } } if(maxcode > 0) diff --git a/src/HTMLRenderer/text.cc b/src/HTMLRenderer/text.cc index d431497..8f69280 100644 --- a/src/HTMLRenderer/text.cc +++ b/src/HTMLRenderer/text.cc @@ -102,7 +102,7 @@ string HTMLRenderer::dump_embedded_font (GfxFont * font, long long fn_id) } else if (dict->lookup("FontFile", &obj)->isStream()) { - suffix = ".ttf"; + suffix = ".pfa"; } else {