From 3891f57755f259c22e1b88d3118b7f3e4ac80bc3 Mon Sep 17 00:00:00 2001 From: Mike Kroutikov Date: Mon, 12 Jan 2015 01:37:54 +0000 Subject: [PATCH] attemp to fix disappearing chars bug by allowing to redefine only valid glyph names --- poppler/GfxFont.cc | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc index 39f026a..900bd58 100644 --- a/poppler/GfxFont.cc +++ b/poppler/GfxFont.cc @@ -1026,6 +1026,21 @@ static GBool testForNumericNames(Dict *fontDict, GBool hex) { return numeric; } +GBool isValidGlyphName(char const **names, char const *oldName, char const *name) { + + // allow override of empty encoding slots with anything + if (!oldName || strcmp(oldName, ".notdef") == 0) return gTrue; + + // .notdef is implicitly valid glyph name + if (strcmp(name, ".notdef") == 0) return gTrue; + + for(int i = 0; i < 256; i++) { + if (names[i] && strcmp(names[i], name) == 0) return gTrue; + } + + return gFalse; +} + Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA, GfxFontType typeA, Ref embFontIDA, Dict *fontDict): GfxFont(tagA, idA, nameA, typeA, embFontIDA) { @@ -1169,6 +1184,9 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA // - others --> StandardEncoding // and then add a list of differences (if any) from // FontDict.Encoding.Differences. + // + // When merging encodings make sure that glyph name exists + // in the font program (works only for 8bit type1 embedded fonts) // check FontDict for base encoding hasEncoding = gFalse; @@ -1304,11 +1322,13 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA code = obj3.getInt(); } else if (obj3.isName()) { if (code >= 0 && code < 256) { - if (encFree[code]) { - gfree(enc[code]); - } - enc[code] = copyString(obj3.getName()); - encFree[code] = gTrue; + if (!baseEncFromFontFile || type != fontType1 || isValidGlyphName(baseEnc, enc[code], obj3.getName())) { + if (encFree[code]) { + gfree(enc[code]); + } + enc[code] = copyString(obj3.getName()); + encFree[code] = gTrue; + } } ++code; } else { -- 1.9.1