From cab38518decaa99b63832875407313b76c7faf02 Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Mon, 20 Aug 2012 23:48:21 +0200 Subject: [PATCH] working on cid truetype --- src/BackgroundRenderer.cc | 11 ++++++++++- src/HTMLRenderer/install.cc | 14 ++++++++++++-- src/HTMLRenderer/text.cc | 26 ++++++-------------------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/BackgroundRenderer.cc b/src/BackgroundRenderer.cc index 1044a63..602ff68 100644 --- a/src/BackgroundRenderer.cc +++ b/src/BackgroundRenderer.cc @@ -4,9 +4,14 @@ * Copyright (C) 2012 by Lu Wang coolwanglugmail.com */ +#include + #include "GfxFont.h" #include "BackgroundRenderer.h" +#include "util.h" + +using std::all_of; void BackgroundRenderer::drawChar(GfxState *state, double x, double y, double dx, double dy, @@ -14,7 +19,11 @@ void BackgroundRenderer::drawChar(GfxState *state, double x, double y, CharCode code, int nBytes, Unicode *u, int uLen) { auto font = state->getFont(); - if((font->getType() == fontType3) || (font->getWMode()) || (uLen == 0)) + if((font->getType() == fontType3) + || (font->getWMode()) + || (uLen == 0) + || (!all_of(u, u+uLen, isLegalUnicode)) + ) { SplashOutputDev::drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen); } diff --git a/src/HTMLRenderer/install.cc b/src/HTMLRenderer/install.cc index 486751f..fd5f684 100644 --- a/src/HTMLRenderer/install.cc +++ b/src/HTMLRenderer/install.cc @@ -125,6 +125,8 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix, script_fout << format("Open(%1%, 1)") % (tmp_dir / (fn + suffix)) << endl; + unordered_map gid2code; + auto ctu = font->getToUnicode(); int * code2GID = nullptr; if(ctu) @@ -150,9 +152,17 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix, else { script_fout << "Reencode(\"original\")" << endl; - int len; + + GfxCIDFont * _font = dynamic_cast(font); + // code2GID has been stored for embedded CID fonts - code2GID = dynamic_cast(font)->getCodeToGIDMap(nullptr, &len); + code2GID = _font->getCodeToGIDMap(nullptr, &maxcode); + + int * p = _font->getCIDToGID(); + int l = _font->getCIDToGIDLen(); + for(int i = 0; i < l; ++i) + gid2cid.insert(make_pair(p[i], i)); + // ?? } } diff --git a/src/HTMLRenderer/text.cc b/src/HTMLRenderer/text.cc index 760da7f..8d80aa2 100644 --- a/src/HTMLRenderer/text.cc +++ b/src/HTMLRenderer/text.cc @@ -8,12 +8,15 @@ */ #include +#include #include #include "HTMLRenderer.h" #include "namespace.h" +using std::all_of; + string HTMLRenderer::dump_embedded_font (GfxFont * font, long long fn_id) { // mupdf consulted @@ -187,27 +190,10 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s) ++nSpaces; } - if(uLen == 0) + if(uLen > 0) { - // TODO -#if 0 - CharCode c = 0; - for(int i = 0; i < n; ++i) - { - c = (c<<8) | (code&0xff); - code >>= 8; - } - for(int i = 0; i < n; ++i) - { - Unicode u = (c&0xff); - c >>= 8; - outputUnicodes(html_fout, &u, 1); - } -#endif - } - else - { - outputUnicodes(html_fout, u, uLen); + if(all_of(u, u+uLen, isLegalUnicode)) + outputUnicodes(html_fout, u, uLen); } dx += dx1;