Commit da6bfacb authored by Adrian Johnson's avatar Adrian Johnson

Add -subst option to pdffonts to list the substitute font name and filename

Bug 44416
parent 9979b1b3
......@@ -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;
}
......@@ -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;
......
......@@ -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
......
......@@ -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;
......
......@@ -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.
......
......@@ -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;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment