From 0fde40d9ca14c0b4d22d63c642f13a869127aa55 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 22 Feb 2012 22:59:41 +1030 Subject: [PATCH] Support Identity-H ToUnicode map Also required fixing a bug when calling CharCodeToUnicode::mapToUnicode() with a mapping created by CharCodeToUnicode::makeIdentityMapping(). mapToUnicode needs set *u to a pointer to the unicode value instead of trying to write to **u. Bug 35468 --- poppler/CharCodeToUnicode.cc | 13 +++++++------ poppler/GfxFont.cc | 35 ++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/poppler/CharCodeToUnicode.cc b/poppler/CharCodeToUnicode.cc index e44f304..5cd5c6e 100644 --- a/poppler/CharCodeToUnicode.cc +++ b/poppler/CharCodeToUnicode.cc @@ -462,9 +462,14 @@ void CharCodeToUnicode::addMapping(CharCode code, char *uStr, int n, } CharCodeToUnicode::CharCodeToUnicode() { + CharCode i; + tag = NULL; - map = NULL; - mapLen = 0; + mapLen = 65536; + map = (Unicode *)gmallocn(mapLen, sizeof(Unicode)); + for (i = 0; i < mapLen; ++i) { + map[i] = i; + } sMap = NULL; sMapLen = sMapSize = 0; refCnt = 1; @@ -590,10 +595,6 @@ void CharCodeToUnicode::setMapping(CharCode c, Unicode *u, int len) { int CharCodeToUnicode::mapToUnicode(CharCode c, Unicode **u) { int i; - if (!map) { - *u[0] = (Unicode)c; - return 1; - } if (c >= mapLen) { return 0; } diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc index cc0f092..81654ac 100644 --- a/poppler/GfxFont.cc +++ b/poppler/GfxFont.cc @@ -583,22 +583,31 @@ CharCodeToUnicode *GfxFont::readToUnicodeCMap(Dict *fontDict, int nBits, GooString *buf; Object obj1; - if (!fontDict->lookup("ToUnicode", &obj1)->isStream()) { + fontDict->lookup("ToUnicode", &obj1); + if (obj1.isName() && obj1.isName("Identity-H")) { + if (ctu) + delete ctu; + ctu = CharCodeToUnicode::makeIdentityMapping(); obj1.free(); - return NULL; - } - buf = new GooString(); - obj1.getStream()->fillGooString(buf); - obj1.streamClose(); - obj1.free(); - if (ctu) { - ctu->mergeCMap(buf, nBits); + hasToUnicode = gTrue; + return ctu; + } else if (obj1.isStream()) { + buf = new GooString(); + obj1.getStream()->fillGooString(buf); + obj1.streamClose(); + obj1.free(); + if (ctu) { + ctu->mergeCMap(buf, nBits); + } else { + ctu = CharCodeToUnicode::parseCMap(buf, nBits); + } + hasToUnicode = gTrue; + delete buf; + return ctu; } else { - ctu = CharCodeToUnicode::parseCMap(buf, nBits); + obj1.free(); + return NULL; } - hasToUnicode = gTrue; - delete buf; - return ctu; } GfxFontLoc *GfxFont::locateFont(XRef *xref, GBool ps) { -- 1.7.5.4