[poppler] poppler/FontInfo.cc poppler/FontInfo.h poppler/GlobalParams.cc poppler/GlobalParams.h utils/pdffonts.1 utils/pdffonts.cc
Adrian Johnson
ajohnson at kemper.freedesktop.org
Fri Jan 6 16:09:33 PST 2012
poppler/FontInfo.cc | 8 ++++-
poppler/FontInfo.h | 2 +
poppler/GlobalParams.cc | 29 +++++++++++++++++++-
poppler/GlobalParams.h | 3 +-
utils/pdffonts.1 | 3 ++
utils/pdffonts.cc | 67 ++++++++++++++++++++++++++++++++++--------------
6 files changed, 88 insertions(+), 24 deletions(-)
New commits:
commit da6bfacb0f858f27bd47f247a25d6bc9ab778411
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Sat Jan 7 10:35:17 2012 +1030
Add -subst option to pdffonts to list the substitute font name and filename
Bug 44416
diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc
index 440e6f5..0952f3c 100644
--- a/poppler/FontInfo.cc
+++ b/poppler/FontInfo.cc
@@ -189,17 +189,19 @@ FontInfo::FontInfo(GfxFont *font, PDFDoc *doc) {
emb = font->getEmbeddedFontID(&embRef);
}
+ file = NULL;
+ substituteName = NULL;
if (!emb)
{
DisplayFontParam *dfp = globalParams->getDisplayFont(font);
if (dfp)
{
+ if (dfp->substituteName)
+ substituteName = dfp->substituteName->copy();
if (dfp->kind == displayFontT1) file = dfp->t1.fileName->copy();
else file = dfp->tt.fileName->copy();
}
- else file = NULL;
}
- else file = NULL;
// look for a ToUnicode map
hasToUnicode = gFalse;
@@ -236,4 +238,6 @@ FontInfo::FontInfo(FontInfo& f) {
FontInfo::~FontInfo() {
delete name;
delete file;
+ if (substituteName)
+ delete substituteName;
}
diff --git a/poppler/FontInfo.h b/poppler/FontInfo.h
index 733194d..a10a5d6 100644
--- a/poppler/FontInfo.h
+++ b/poppler/FontInfo.h
@@ -55,6 +55,7 @@ public:
~FontInfo();
GooString *getName() { return name; };
+ GooString *getSubstituteName() { return substituteName; };
GooString *getFile() { return file; };
Type getType() { return type; };
GBool getEmbedded() { return emb; };
@@ -65,6 +66,7 @@ public:
private:
GooString *name;
+ GooString *substituteName;
GooString *file;
Type type;
GBool emb;
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index 1e0ddc0..df9cc06 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -126,8 +126,10 @@ GlobalParams *globalParams = NULL;
//------------------------------------------------------------------------
DisplayFontParam::DisplayFontParam(GooString *nameA,
+ GooString *substNameA,
DisplayFontParamKind kindA) {
name = nameA;
+ substituteName = substNameA;
kind = kindA;
switch (kind) {
case displayFontT1:
@@ -141,6 +143,7 @@ DisplayFontParam::DisplayFontParam(GooString *nameA,
DisplayFontParam::~DisplayFontParam() {
delete name;
+ delete substituteName;
switch (kind) {
case displayFontT1:
if (t1.fileName) {
@@ -1244,18 +1247,40 @@ DisplayFontParam *GlobalParams::getDisplayFont(GfxFont *font) {
continue;
}
}
+ FcChar8* s2;
+ GooString *substName = NULL;
+ res = FcPatternGetString(set->fonts[i], FC_FULLNAME, 0, &s2);
+ if (res == FcResultMatch && s2) {
+ substName = new GooString((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) {
+ substName = new GooString((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) {
+ substName->append(" ");
+ substName->append(style);
+ }
+ delete style;
+ }
+ }
+ }
ext = strrchr((char*)s,'.');
if (!ext)
continue;
if (!strncasecmp(ext,".ttf",4) || !strncasecmp(ext, ".ttc", 4) || !strncasecmp(ext, ".otf", 4))
{
- dfp = new DisplayFontParam(fontName->copy(), displayFontTT);
+ dfp = new DisplayFontParam(fontName->copy(), substName, displayFontTT);
dfp->tt.fileName = new GooString((char*)s);
FcPatternGetInteger(set->fonts[i], FC_INDEX, 0, &(dfp->tt.faceIndex));
}
else if (!strncasecmp(ext,".pfa",4) || !strncasecmp(ext,".pfb",4))
{
- dfp = new DisplayFontParam(fontName->copy(), displayFontT1);
+ dfp = new DisplayFontParam(fontName->copy(), substName, displayFontT1);
dfp->t1.fileName = new GooString((char*)s);
}
else
diff --git a/poppler/GlobalParams.h b/poppler/GlobalParams.h
index 5fff49d..825ff7a 100644
--- a/poppler/GlobalParams.h
+++ b/poppler/GlobalParams.h
@@ -91,13 +91,14 @@ public:
GooString *name; // font name for 8-bit fonts and named
// CID fonts; collection name for
// generic CID fonts
+ GooString *substituteName;
DisplayFontParamKind kind;
union {
DisplayFontParamT1 t1;
DisplayFontParamTT tt;
};
- DisplayFontParam(GooString *nameA, DisplayFontParamKind kindA);
+ DisplayFontParam(GooString *nameA, GooString *substNameA, DisplayFontParamKind kindA);
void setFileName(GooString *fileNameA) {
if (displayFontT1 == kind)
t1.fileName = fileNameA;
diff --git a/utils/pdffonts.1 b/utils/pdffonts.1
index e125cfd..7e95579 100644
--- a/utils/pdffonts.1
+++ b/utils/pdffonts.1
@@ -66,6 +66,9 @@ Specifies the first page to analyze.
.BI \-l " number"
Specifies the last page to analyze.
.TP
+.BI \-subst
+List the substitute fonts that poppler will use for non embdedded fonts.
+.TP
.BI \-opw " password"
Specify the owner password for the PDF file. Providing this will
bypass all security restrictions.
diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc
index f2e49e5..205bb82 100644
--- a/utils/pdffonts.cc
+++ b/utils/pdffonts.cc
@@ -55,6 +55,7 @@ static char *fontTypeNames[] = {
static int firstPage = 1;
static int lastPage = 0;
+static GBool showSubst = gFalse;
static char ownerPassword[33] = "\001";
static char userPassword[33] = "\001";
static GBool printVersion = gFalse;
@@ -65,6 +66,8 @@ static const ArgDesc argDesc[] = {
"first page to examine"},
{"-l", argInt, &lastPage, 0,
"last page to examine"},
+ {"-subst", argFlag, &showSubst, 0,
+ "show font substitutions"},
{"-opw", argString, ownerPassword, sizeof(ownerPassword),
"owner password (for encrypted files)"},
{"-upw", argString, userPassword, sizeof(userPassword),
@@ -152,27 +155,53 @@ int main(int argc, char *argv[]) {
FontInfoScanner scanner(doc, firstPage - 1);
GooList *fonts = scanner.scan(lastPage - firstPage + 1);
- // print the font info
- printf("name type 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",
- font->getName() ? font->getName()->getCString() : "[none]",
- fontTypeNames[font->getType()],
- font->getEmbedded() ? "yes" : "no",
- font->getSubset() ? "yes" : "no",
- font->getToUnicode() ? "yes" : "no");
- const Ref fontRef = font->getRef();
- if (fontRef.gen >= 100000) {
- printf(" [none]\n");
- } else {
- printf(" %6d %2d\n", fontRef.num, fontRef.gen);
+ if (showSubst) {
+ // print the font substitutions
+ printf("name object ID substitute font substitute font file\n");
+ printf("------------------------------------ --------- ------------------------------------ ------------------------------------\n");
+ if (fonts) {
+ for (int i = 0; i < fonts->getLength(); ++i) {
+ FontInfo *font = (FontInfo *)fonts->get(i);
+ if (font->getFile()) {
+ printf("%-36s",
+ font->getName() ? font->getName()->getCString() : "[none]");
+ const Ref fontRef = font->getRef();
+ if (fontRef.gen >= 100000) {
+ printf(" [none]");
+ } else {
+ printf(" %6d %2d", fontRef.num, fontRef.gen);
+ }
+ printf(" %-36s %s\n",
+ font->getSubstituteName() ? font->getSubstituteName()->getCString() : "[none]",
+ font->getFile()->getCString());
+ }
+ delete font;
}
- delete font;
+ delete fonts;
+ }
+ } else {
+ // print the font info
+ printf("name type 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",
+ font->getName() ? font->getName()->getCString() : "[none]",
+ fontTypeNames[font->getType()],
+ font->getEmbedded() ? "yes" : "no",
+ font->getSubset() ? "yes" : "no",
+ font->getToUnicode() ? "yes" : "no");
+ const Ref fontRef = font->getRef();
+ if (fontRef.gen >= 100000) {
+ printf(" [none]\n");
+ } else {
+ printf(" %6d %2d\n", fontRef.num, fontRef.gen);
+ }
+ delete font;
+ }
+ delete fonts;
}
- delete fonts;
}
}
More information about the poppler
mailing list