From 978b72c984e403422155055740e2ded38377df2d Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sun, 21 Sep 2014 09:53:13 +0930 Subject: [PATCH] Map Standard/Expert encoding ligatures to AGLFN names for use with substitute fonts that are not compatible with the Standard 14 fonts. Bug 80093 --- poppler/CairoFontEngine.cc | 10 ++++++++-- poppler/GfxFont.cc | 27 +++++++++++++++++++++++++++ poppler/GfxFont.h | 5 +++++ splash/SplashFTFontFile.cc | 7 +++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc index 1546594..7d6941f 100644 --- a/poppler/CairoFontEngine.cc +++ b/poppler/CairoFontEngine.cc @@ -395,7 +395,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, GfxFontType fontType; GfxFontLoc *fontLoc; char **enc; - char *name; + const char *name; FoFiTrueType *ff; FoFiType1C *ff1c; Ref ref; @@ -457,7 +457,13 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, for (i = 0; i < 256; ++i) { codeToGID[i] = 0; if ((name = enc[i])) { - codeToGID[i] = FT_Get_Name_Index(face, name); + codeToGID[i] = FT_Get_Name_Index(face, (char*)name); + if (codeToGID[i] == 0) { + name = (char*)GfxFont::getAlternateName(name); + if (name) { + codeToGID[i] = FT_Get_Name_Index(face, (char*)name); + } + } } } break; diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc index 6f6a125..1c554c2 100644 --- a/poppler/GfxFont.cc +++ b/poppler/GfxFont.cc @@ -913,6 +913,33 @@ char *GfxFont::readEmbFontFile(XRef *xref, int *len) { return buf; } + +struct AlternateNameMap { + const char *name; + const char *alt; +}; + +static const AlternateNameMap alternateNameMap[] = +{ + { "fi", "f_i" }, + { "fl", "f_l" }, + { "ff", "f_f" }, + { "ffi", "f_f_i" }, + { "ffl", "f_f_l" }, + { 0, 0 } +}; + +const char *GfxFont::getAlternateName(const char *name) { + const AlternateNameMap *map = alternateNameMap; + while (map->name) { + if (strcmp(name, map->name) == 0) { + return map->alt; + } + map++; + } + return 0; +} + //------------------------------------------------------------------------ // Gfx8BitFont //------------------------------------------------------------------------ diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h index f980668..5945daa 100644 --- a/poppler/GfxFont.h +++ b/poppler/GfxFont.h @@ -263,6 +263,11 @@ public: // Return the name of the encoding GooString *getEncodingName() { return encodingName; } + // Return AGLFN names of ligatures in the Standard and Expert encodings + // for use with fonts that are not compatible with the Standard 14 fonts. + // http://sourceforge.net/adobe/aglfn/wiki/AGL%20Specification/ + static const char *getAlternateName(const char *name); + protected: virtual ~GfxFont(); diff --git a/splash/SplashFTFontFile.cc b/splash/SplashFTFontFile.cc index 34f6ce5..8aefffe 100644 --- a/splash/SplashFTFontFile.cc +++ b/splash/SplashFTFontFile.cc @@ -28,6 +28,7 @@ #include "goo/gmem.h" #include "goo/GooString.h" +#include "poppler/GfxFont.h" #include "SplashFTFontEngine.h" #include "SplashFTFont.h" #include "SplashFTFontFile.h" @@ -57,6 +58,12 @@ SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA, codeToGIDA[i] = 0; if ((name = encA[i])) { codeToGIDA[i] = (int)FT_Get_Name_Index(faceA, (char *)name); + if (codeToGIDA[i] == 0) { + name = GfxFont::getAlternateName(name); + if (name) { + codeToGIDA[i] = FT_Get_Name_Index(faceA, (char *)name); + } + } } } -- 2.1.0