From cd763064e3c0cbd6b292135efe5953783c1198d0 Mon Sep 17 00:00:00 2001 From: Jason Crain Date: Tue, 29 Dec 2015 21:40:21 -0600 Subject: [PATCH] Fallback to looking up glyph by Unicode code point Sometimes glyphs don't display in documents because either font substitution picks a font without the required glyphs, or the PDF document uses different names from the font. Provide fontconfig the required characters so it can better choose a font. Fallback to looking up the glyph id from the Unicode code point if lookup by name or character code fails. Bug #93299 --- poppler/CairoFontEngine.cc | 7 +++++++ poppler/GfxFont.cc | 4 ++++ poppler/GlobalParams.cc | 24 ++++++++++++++++++++++++ splash/SplashFTFontFile.cc | 8 ++++++++ 4 files changed, 43 insertions(+) diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc index 1d611b5..012b6ea 100644 --- a/poppler/CairoFontEngine.cc +++ b/poppler/CairoFontEngine.cc @@ -471,6 +471,13 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, codeToGID[i] = FT_Get_Name_Index(face, (char*)name); } } + if (codeToGID[i] == 0) { + // lookup by name failed, try by Unicode + Unicode u = globalParams->mapNameToUnicodeAll(enc[i]); + if (u) { + codeToGID[i] = FT_Get_Char_Index(face, u); + } + } } } break; diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc index 81f5903..bbb9fbc 100644 --- a/poppler/GfxFont.cc +++ b/poppler/GfxFont.cc @@ -1761,6 +1761,10 @@ int *Gfx8BitFont::getCodeToGIDMap(FoFiTrueType *ff) { if ((charName = enc[i])) { if ((code = globalParams->getMacRomanCharCode(charName))) { map[i] = ff->mapCodeToGID(cmap, code); + } else if (unicodeCmap >= 0 && + (code = globalParams->mapNameToUnicodeAll(charName))) { + // not in MacRoman encoding, try Unicode lookup + map[i] = ff->mapCodeToGID(unicodeCmap, code); } } else { map[i] = -1; diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc index e543408..b311310 100644 --- a/poppler/GlobalParams.cc +++ b/poppler/GlobalParams.cc @@ -1097,6 +1097,30 @@ static FcPattern *buildFcPattern(GfxFont *font, GooString *base14Name) if (width != -1) FcPatternAddInteger(p, FC_WIDTH, width); if (spacing != -1) FcPatternAddInteger(p, FC_SPACING, spacing); + // request character set + FcCharSet *charSet = FcCharSetCreate(); + char **enc = ((Gfx8BitFont *)font)->getEncoding(); + bool isZapfDingbats = strcmp(name, "ZapfDingbats") == 0; + + for (int i = 0; i < 256; ++i) { + if (enc[i]) { + Unicode u; + + if (isZapfDingbats) { + u = globalParams->mapNameToUnicodeAll(enc[i]); + } else { + u = globalParams->mapNameToUnicodeText(enc[i]); + } + + if (u) { + FcCharSetAddChar(charSet, u); + } + } + } + + FcPatternAddCharSet(p, FC_CHARSET, charSet); + FcCharSetDestroy(charSet); + if (deleteFamily) delete[] family; return p; diff --git a/splash/SplashFTFontFile.cc b/splash/SplashFTFontFile.cc index f0dcf50..815796b 100644 --- a/splash/SplashFTFontFile.cc +++ b/splash/SplashFTFontFile.cc @@ -30,6 +30,7 @@ #include "goo/gmem.h" #include "goo/GooString.h" #include "poppler/GfxFont.h" +#include "poppler/GlobalParams.h" #include "SplashFTFontEngine.h" #include "SplashFTFont.h" #include "SplashFTFontFile.h" @@ -65,6 +66,13 @@ SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA, codeToGIDA[i] = FT_Get_Name_Index(faceA, (char *)name); } } + if (codeToGIDA[i] == 0) { + // lookup by name failed, try by Unicode + Unicode u = globalParams->mapNameToUnicodeAll(encA[i]); + if (u) { + codeToGIDA[i] = FT_Get_Char_Index(faceA, u); + } + } } } -- 2.6.4