From f00eff51810fa234cb3bbde36215a4ab3e577b7b Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sat, 12 May 2012 16:31:38 +0930 Subject: [PATCH] Include substitute font name in system font cache --- poppler/FontInfo.cc | 1 + poppler/GlobalParams.cc | 58 ++++++++++++++++++++++++++--------------------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc index 4f30f05..35d5f5f 100644 --- a/poppler/FontInfo.cc +++ b/poppler/FontInfo.cc @@ -224,6 +224,7 @@ FontInfo::FontInfo(FontInfo& f) { name = f.name ? f.name->copy() : NULL; file = f.file ? f.file->copy() : NULL; encoding = f.encoding ? f.encoding->copy() : NULL; + substituteName = f.substituteName ? f.substituteName->copy() : NULL; type = f.type; emb = f.emb; subset = f.subset; diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc index 13053ac..098e4a4 100644 --- a/poppler/GlobalParams.cc +++ b/poppler/GlobalParams.cc @@ -214,9 +214,10 @@ public: GooString *path; SysFontType type; int fontNum; // for TrueType collections + GooString *substituteName; SysFontInfo(GooString *nameA, GBool boldA, GBool italicA, GBool obliqueA, GBool fixedWidthA, - GooString *pathA, SysFontType typeA, int fontNumA); + GooString *pathA, SysFontType typeA, int fontNumA, GooString *substituteNameA); ~SysFontInfo(); GBool match(SysFontInfo *fi); GBool match(GooString *nameA, GBool boldA, GBool italicA, GBool obliqueA, GBool fixedWidthA); @@ -224,7 +225,7 @@ public: }; SysFontInfo::SysFontInfo(GooString *nameA, GBool boldA, GBool italicA, GBool obliqueA, GBool fixedWidthA, - GooString *pathA, SysFontType typeA, int fontNumA) { + GooString *pathA, SysFontType typeA, int fontNumA, GooString *substituteNameA) { name = nameA; bold = boldA; italic = italicA; @@ -233,11 +234,13 @@ SysFontInfo::SysFontInfo(GooString *nameA, GBool boldA, GBool italicA, GBool obl path = pathA; type = typeA; fontNum = fontNumA; + substituteName = substituteNameA; } SysFontInfo::~SysFontInfo() { delete name; delete path; + delete substituteName; } GBool SysFontInfo::match(SysFontInfo *fi) { @@ -1163,6 +1166,7 @@ GooString *GlobalParams::findSystemFontFile(GfxFont *font, FcPattern *p=0; GooString *path = NULL; GooString *fontName = font->getName(); + GooString substituteName; if (!fontName) return NULL; lockGlobalParams; @@ -1170,6 +1174,7 @@ GooString *GlobalParams::findSystemFontFile(GfxFont *font, path = fi->path->copy(); *type = fi->type; *fontNum = fi->fontNum; + substituteName.Set(fi->substituteName->getCString()); } else { FcChar8* s; char * ext; @@ -1214,28 +1219,26 @@ GooString *GlobalParams::findSystemFontFile(GfxFont *font, } } FcChar8* s2; - if (substituteFontName) { - res = FcPatternGetString(set->fonts[i], FC_FULLNAME, 0, &s2); - if (res == FcResultMatch && s2) { - substituteFontName->Set((char*)s2); - } else { - // fontconfig does not extract fullname for some fonts - // create the fullname from family and style - res = FcPatternGetString(set->fonts[i], FC_FAMILY, 0, &s2); - if (res == FcResultMatch && s2) { - substituteFontName->Set((char*)s2); - res = FcPatternGetString(set->fonts[i], FC_STYLE, 0, &s2); - if (res == FcResultMatch && s2) { - GooString *style = new GooString((char*)s2); - if (style->cmp("Regular") != 0) { - substituteFontName->append(" "); - substituteFontName->append(style); - } - delete style; - } - } - } - } + res = FcPatternGetString(set->fonts[i], FC_FULLNAME, 0, &s2); + if (res == FcResultMatch && s2) { + substituteName.Set((char*)s2); + } else { + // fontconfig does not extract fullname for some fonts + // create the fullname from family and style + res = FcPatternGetString(set->fonts[i], FC_FAMILY, 0, &s2); + if (res == FcResultMatch && s2) { + substituteName.Set((char*)s2); + res = FcPatternGetString(set->fonts[i], FC_STYLE, 0, &s2); + if (res == FcResultMatch && s2) { + GooString *style = new GooString((char*)s2); + if (style->cmp("Regular") != 0) { + substituteName.append(" "); + substituteName.append(style); + } + delete style; + } + } + } ext = strrchr((char*)s,'.'); if (!ext) continue; @@ -1260,7 +1263,7 @@ GooString *GlobalParams::findSystemFontFile(GfxFont *font, *type = (!strncasecmp(ext,".ttc",4)) ? sysFontTTC : sysFontTTF; FcPatternGetInteger(set->fonts[i], FC_INDEX, 0, fontNum); fi = new SysFontInfo(fontName->copy(), bold, italic, oblique, font->isFixedWidth(), - new GooString((char*)s), *type, *fontNum); + new GooString((char*)s), *type, *fontNum, substituteName.copy()); sysFonts->addFcFont(fi); path = new GooString((char*)s); } @@ -1285,7 +1288,7 @@ GooString *GlobalParams::findSystemFontFile(GfxFont *font, *type = (!strncasecmp(ext,".pfa",4)) ? sysFontPFA : sysFontPFB; FcPatternGetInteger(set->fonts[i], FC_INDEX, 0, fontNum); fi = new SysFontInfo(fontName->copy(), bold, italic, oblique, font->isFixedWidth(), - new GooString((char*)s), *type, *fontNum); + new GooString((char*)s), *type, *fontNum, substituteName.copy()); sysFonts->addFcFont(fi); path = new GooString((char*)s); } @@ -1308,6 +1311,9 @@ GooString *GlobalParams::findSystemFontFile(GfxFont *font, *type = fi->type; *fontNum = fi->fontNum; } + if (substituteFontName) { + substituteFontName->Set(substituteName.getCString()); + } fin: if (p) FcPatternDestroy(p); -- 1.7.9.5