From b9a9904b8567c54f1cdec625b411f3f3400e7599 Mon Sep 17 00:00:00 2001 From: Mike Kroutikov Date: Fri, 9 Jan 2015 11:42:13 -0500 Subject: [PATCH] when merging encodings verify that glyph name exists before overriding enc entry --- poppler/GfxFont.cc | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc index 39f026a..f9fc7a4 100644 --- a/poppler/GfxFont.cc +++ b/poppler/GfxFont.cc @@ -1026,6 +1026,15 @@ static GBool testForNumericNames(Dict *fontDict, GBool hex) { return numeric; } +static GBoolean isValidGlyphName(char const **names, char const *name) { + + 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 +1178,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. + // + // mk. 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 +1316,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, obj3.getName())) { + if (encFree[code]) { + gfree(enc[code]); + } + enc[code] = copyString(obj3.getName()); + encFree[code] = gTrue; + } } ++code; } else { -- 1.9.4.msysgit.2