[poppler] poppler/CMap.h poppler/FontInfo.cc poppler/FontInfo.h poppler/GfxFont.cc poppler/GfxFont.h utils/pdffonts.1 utils/pdffonts.cc

Adrian Johnson ajohnson at kemper.freedesktop.org
Sat Mar 3 06:38:49 PST 2012


 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(-)

New commits:
commit 670ea176495b8b580daba061840c914714bf422d
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Fri Mar 2 22:22:16 2012 +1030

    pdffonts: list the encoding of each font
    
    Bug 46888

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 (<registry>-<ordering>).
   GooString *getCollection() { return collection; }
 
+  GooString *getCMapName() { return cMapName; }
+
   // Return true if this CMap matches the specified <collectionA>, and
   // <cMapNameA>.
   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..ac4942d 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 = new GooString("");
   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->Set("Builtin");
+  } else if (baseEnc == winAnsiEncoding) {
+    encodingName->Set("WinAnsi");
+  } else if (baseEnc == macRomanEncoding) {
+    encodingName->Set("MacRoman");
+  } else if (baseEnc == macExpertEncoding) {
+    encodingName->Set("MacExpert");
+  } else if (baseEnc == symbolEncoding) {
+    encodingName->Set("Symbol");
+  } else if (baseEnc == zapfDingbatsEncoding) {
+    encodingName->Set("ZapfDingbats");
+  } else {
+    encodingName->Set("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->Set(cMap->getCMapName()->getCString());
+  } else {
+    encodingName->Set("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..820abbf 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");


More information about the poppler mailing list