[poppler] [PATCH] Get font type from fontconfig if possible.
Kusanagi Kouichi
slash at ac.auone-net.jp
Thu Mar 3 22:14:54 PST 2011
Signed-off-by: Kusanagi Kouichi <slash at ac.auone-net.jp>
---
poppler/GlobalParams.cc | 51 +++++++++++++++++++++++++++++++++++------------
1 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index 1e0cdc4..1b0ec1e 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -1187,8 +1187,6 @@ DisplayFontParam *GlobalParams::getDisplayFont(GfxFont *font) {
dfp = font->dfp;
if (!dfp)
{
- FcChar8* s;
- char * ext;
FcResult res;
FcFontSet *set;
int i;
@@ -1201,27 +1199,54 @@ DisplayFontParam *GlobalParams::getDisplayFont(GfxFont *font) {
set = FcFontSort(NULL, p, FcFalse, NULL, &res);
if (!set)
goto fin;
+
for (i = 0; i < set->nfont; ++i)
{
+ FcChar8 *s;
+ DisplayFontParamKind kind;
+
res = FcPatternGetString(set->fonts[i], FC_FILE, 0, &s);
if (res != FcResultMatch || !s)
continue;
- ext = strrchr((char*)s,'.');
- if (!ext)
- continue;
- if (!strncasecmp(ext,".ttf",4) || !strncasecmp(ext, ".ttc", 4))
+
+#ifdef FC_FONTFORMAT
+ FcChar8 *format;
+ res = FcPatternGetString(set->fonts[i], FC_FONTFORMAT, 0, &format);
+ if (res == FcResultMatch && format != NULL)
{
- dfp = new DisplayFontParam(fontName->copy(), displayFontTT);
- dfp->tt.fileName = new GooString((char*)s);
- FcPatternGetInteger(set->fonts[i], FC_INDEX, 0, &(dfp->tt.faceIndex));
+ if (!strcmp((const char *)format, "TrueType"))
+ kind = displayFontTT;
+ else if (!strcmp((const char *)format, "Type1"))
+ kind = displayFontT1;
+ else
+ continue;
}
- else if (!strncasecmp(ext,".pfa",4) || !strncasecmp(ext,".pfb",4))
+ else
+#endif
{
- dfp = new DisplayFontParam(fontName->copy(), displayFontT1);
+ const char * const ext = strrchr((char*)s, '.');
+ if (!ext)
+ continue;
+
+ if (!strncasecmp(ext, ".ttf", 4) || !strncasecmp(ext, ".ttc", 4))
+ kind = displayFontTT;
+ else if (!strncasecmp(ext, ".pfa", 4) || !strncasecmp(ext, ".pfb", 4))
+ kind = displayFontT1;
+ else
+ continue;
+ }
+
+ dfp = new DisplayFontParam(fontName->copy(), kind);
+ switch (kind)
+ {
+ case displayFontTT:
+ dfp->tt.fileName = new GooString((char*)s);
+ FcPatternGetInteger(set->fonts[i], FC_INDEX, 0, &(dfp->tt.faceIndex));
+ break;
+ case displayFontT1:
dfp->t1.fileName = new GooString((char*)s);
+ break;
}
- else
- continue;
font->dfp = dfp;
break;
}
--
1.7.4.1
More information about the poppler
mailing list