From 419a0b803c0663490258cb1f6f23d2334cd08489 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Mon, 25 Aug 2014 18:21:32 +0200 Subject: [PATCH] if glyph name lookup failed, try alternate naming scheme for ligatures According to the Adobe spec., ligature glyphs may be named either e.g. "fi" ot "f_i". If text has been set with a font using the one naming scheme but is rendered with a font using the other, ligature glyphs may be missing from the rendering. Therefore, if a glyph name lookup failed, try again using the other naming scheme. This happened e.g. for the "fl" and "fi" ligatures in texts set in Times but rendered in Tex Gyre Termes. Closes Bug #73291, Bug #80093. --- poppler/CairoFontEngine.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc index 1546594..c30c7da 100644 --- a/poppler/CairoFontEngine.cc +++ b/poppler/CairoFontEngine.cc @@ -458,6 +458,47 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, codeToGID[i] = 0; if ((name = enc[i])) { codeToGID[i] = FT_Get_Name_Index(face, name); + + // glyph lookup failed, try alternate naming scheme for ligatures + if (!codeToGID[i]) + { + size_t j, k; + char newname[14]; + const size_t namelen = strlen(name); + + // unusual glyph name size for a ligature + if (namelen < 2 || namelen > 7) + continue; + + if (!strchr(name, '_')) + { + // glyph name contains no underscores, + // now try with interleaving them + newname[0] = name[0]; + for (j = k = 1; j < namelen; j++) + { + newname[k++] = '_'; + newname[k++] = name[j]; + } + newname[k] = '\0'; + } + else + { + // glyph name already contains underscores, + // now try without them + for (j = k = 0; j < namelen; j++) + { + if (name[j] != '_') + { + newname[k++] = name[j]; + } + } + newname[k] = '\0'; + } + + // repeat glyph lookup for the alternate name + codeToGID[i] = FT_Get_Name_Index(face, newname); + } } } break; -- 2.1.0