From ef0a09fc4a0ba23d49b66f24d4cec9660d4cf657 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 2 Mar 2012 22:22:16 +1030 Subject: [PATCH] pdffonts: list the encoding of each font --- poppler/CMap.h | 2 ++ poppler/FontInfo.cc | 3 +++ poppler/FontInfo.h | 2 ++ poppler/GfxFont.cc | 26 ++++++++++++++++++++++++++ poppler/GfxFont.h | 4 ++++ utils/pdffonts.1 | 3 +++ utils/pdffonts.cc | 7 ++++--- 7 files changed, 44 insertions(+), 3 deletions(-) diff --git a/poppler/CMap.h b/poppler/CMap.h index 3f7085d..79f2802 100644 --- a/poppler/CMap.h +++ b/poppler/CMap.h @@ -76,6 +76,8 @@ public: // Return collection name (-). GooString *getCollection() { return collection; } + GooString *getCMapName() { return cMapName; } + // Return true if this CMap matches the specified , and // . GBool match(GooString *collectionA, GooString *cMapNameA); diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc index 76b2350..2a90c1e 100644 --- a/poppler/FontInfo.cc +++ b/poppler/FontInfo.cc @@ -200,6 +200,7 @@ FontInfo::FontInfo(GfxFont *font, PDFDoc *doc) { if (substituteNameAux.getLength() > 0) substituteName = substituteNameAux.copy(); } + encoding = font->getEncodingName()->copy(); // look for a ToUnicode map hasToUnicode = gFalse; @@ -225,6 +226,7 @@ FontInfo::FontInfo(GfxFont *font, PDFDoc *doc) { 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; type = f.type; emb = f.emb; subset = f.subset; @@ -236,6 +238,7 @@ FontInfo::FontInfo(FontInfo& f) { FontInfo::~FontInfo() { delete name; delete file; + delete encoding; if (substituteName) delete substituteName; } diff --git a/poppler/FontInfo.h b/poppler/FontInfo.h index fa6ed2c..db90440 100644 --- a/poppler/FontInfo.h +++ b/poppler/FontInfo.h @@ -58,6 +58,7 @@ public: GooString *getName() { return name; }; GooString *getSubstituteName() { return substituteName; }; GooString *getFile() { return file; }; + GooString *getEncoding() { return encoding; }; Type getType() { return type; }; GBool getEmbedded() { return emb; }; GBool getSubset() { return subset; }; @@ -69,6 +70,7 @@ private: GooString *name; GooString *substituteName; GooString *file; + GooString *encoding; Type type; GBool emb; GBool subset; diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc index fed5b2f..0501e7b 100644 --- a/poppler/GfxFont.cc +++ b/poppler/GfxFont.cc @@ -240,6 +240,7 @@ GfxFont::GfxFont(const char *tagA, Ref idA, GooString *nameA, stretch = StretchNotDefined; weight = WeightNotDefined; refCnt = 1; + encodingName = NULL; hasToUnicode = gFalse; } @@ -252,6 +253,9 @@ GfxFont::~GfxFont() { if (embFontName) { delete embFontName; } + if (encodingName) { + delete encodingName; + } } void GfxFont::incRefCnt() { @@ -1136,6 +1140,22 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA } } + if (baseEncFromFontFile) { + encodingName = new GooString("Builtin"); + } else if (baseEnc == winAnsiEncoding) { + encodingName = new GooString("WinAnsi"); + } else if (baseEnc == macRomanEncoding) { + encodingName = new GooString("MacRoman"); + } else if (baseEnc == macExpertEncoding) { + encodingName = new GooString("MacExpert"); + } else if (baseEnc == symbolEncoding) { + encodingName = new GooString("Symbol"); + } else if (baseEnc == zapfDingbatsEncoding) { + encodingName = new GooString("ZapfDingbats"); + } else { + encodingName = new GooString("Standard"); + } + // copy the base encoding for (i = 0; i < 256; ++i) { enc[i] = (char *)baseEnc[i]; @@ -1161,6 +1181,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA if (obj1.isDict()) { obj1.dictLookup("Differences", &obj2); if (obj2.isArray()) { + encodingName->Set("Custom"); hasEncoding = gTrue; code = 0; for (i = 0; i < obj2.arrayGetLength(); ++i) { @@ -1847,6 +1868,11 @@ GfxCIDFont::GfxCIDFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA, goto err2; } obj1.free(); + if (cMap->getCMapName()) { + encodingName = cMap->getCMapName()->copy(); + } else { + encodingName = new GooString("Custom"); + } // CIDToGIDMap (for embedded TrueType fonts) if (type == fontCIDType2 || type == fontCIDType2OT) { diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h index 0c32e0f..1ac9f6d 100644 --- a/poppler/GfxFont.h +++ b/poppler/GfxFont.h @@ -260,6 +260,9 @@ public: // Does this font have a toUnicode map? GBool hasToUnicodeCMap() { return hasToUnicode; } + // Return the name of the encoding + GooString *getEncodingName() { return encodingName; } + protected: virtual ~GfxFont(); @@ -288,6 +291,7 @@ protected: int refCnt; GBool ok; GBool hasToUnicode; + GooString *encodingName; }; //------------------------------------------------------------------------ diff --git a/utils/pdffonts.1 b/utils/pdffonts.1 index 4582d51..4afc395 100644 --- a/utils/pdffonts.1 +++ b/utils/pdffonts.1 @@ -21,6 +21,9 @@ a subset prefix) .B type the font type -- see below for details .TP +.B encoding +the font encoding +.TP .B emb "yes" if the font is embedded in the PDF file .TP diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc index 970cbc0..f734207 100644 --- a/utils/pdffonts.cc +++ b/utils/pdffonts.cc @@ -182,14 +182,15 @@ int main(int argc, char *argv[]) { } } else { // print the font info - printf("name type emb sub uni object ID\n"); - printf("------------------------------------ ----------------- --- --- --- ---------\n"); + printf("name type encoding emb sub uni object ID\n"); + printf("------------------------------------ ----------------- ---------------- --- --- --- ---------\n"); if (fonts) { for (int i = 0; i < fonts->getLength(); ++i) { FontInfo *font = (FontInfo *)fonts->get(i); - printf("%-36s %-17s %-3s %-3s %-3s", + printf("%-36s %-17s %-16s %-3s %-3s %-3s", font->getName() ? font->getName()->getCString() : "[none]", fontTypeNames[font->getType()], + font->getEncoding()->getCString(), font->getEmbedded() ? "yes" : "no", font->getSubset() ? "yes" : "no", font->getToUnicode() ? "yes" : "no"); -- 1.7.5.4