X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=inline;f=pdf%2Fxpdf%2Fpdffonts.cc;h=66d9c37e39ef6699b41587c09b115e6c6565934e;hb=e48cf2858b65aa026771a48d2b315cbc663d8234;hp=4a6ed40138d3df04c594c49e244e7b23590e8f5c;hpb=2a393c134fe3fe8eb85bf818cb7ad6ae4396322a;p=evince.git diff --git a/pdf/xpdf/pdffonts.cc b/pdf/xpdf/pdffonts.cc index 4a6ed401..66d9c37e 100644 --- a/pdf/xpdf/pdffonts.cc +++ b/pdf/xpdf/pdffonts.cc @@ -2,7 +2,7 @@ // // pdffonts.cc // -// Copyright 2001-2002 Glyph & Cog, LLC +// Copyright 2001-2003 Glyph & Cog, LLC // //======================================================================== @@ -22,7 +22,7 @@ #include "GfxFont.h" #include "Annot.h" #include "PDFDoc.h" -#include "config.h" +#include "xpdfconfig.h" static char *fontTypeNames[] = { "unknown", @@ -40,8 +40,8 @@ static void scanFont(GfxFont *font, PDFDoc *doc); static int firstPage = 1; static int lastPage = 0; -static char ownerPassword[33] = ""; -static char userPassword[33] = ""; +static char ownerPassword[33] = "\001"; +static char userPassword[33] = "\001"; static char cfgFileName[256] = ""; static GBool printVersion = gFalse; static GBool printHelp = gFalse; @@ -84,16 +84,19 @@ int main(int argc, char *argv[]) { Annots *annots; Object obj1, obj2; int pg, i; + int exitCode; + + exitCode = 99; // parse args ok = parseArgs(argDesc, &argc, argv); if (!ok || argc != 2 || printVersion || printHelp) { - fprintf(stderr, "pdfinfo version %s\n", xpdfVersion); + fprintf(stderr, "pdffonts version %s\n", xpdfVersion); fprintf(stderr, "%s\n", xpdfCopyright); if (!printVersion) { - printUsage("pdfinfo", "", argDesc); + printUsage("pdffonts", "", argDesc); } - exit(1); + goto err0; } fileName = new GString(argv[1]); @@ -101,12 +104,12 @@ int main(int argc, char *argv[]) { globalParams = new GlobalParams(cfgFileName); // open PDF file - if (ownerPassword[0]) { + if (ownerPassword[0] != '\001') { ownerPW = new GString(ownerPassword); } else { ownerPW = NULL; } - if (userPassword[0]) { + if (userPassword[0] != '\001') { userPW = new GString(userPassword); } else { userPW = NULL; @@ -119,7 +122,8 @@ int main(int argc, char *argv[]) { delete ownerPW; } if (!doc->isOk()) { - exit(1); + exitCode = 1; + goto err1; } // get page range @@ -155,35 +159,51 @@ int main(int argc, char *argv[]) { delete annots; } + exitCode = 0; + // clean up gfree(fonts); + err1: delete doc; delete globalParams; + err0: // check for memory leaks Object::memCheck(stderr); gMemReport(stderr); - return 0; + return exitCode; } static void scanFonts(Dict *resDict, PDFDoc *doc) { + Object obj1, obj2, xObjDict, xObj, resObj; + Ref r; GfxFontDict *gfxFontDict; GfxFont *font; - Object fontDict, xObjDict, xObj, resObj; int i; // scan the fonts in this resource dictionary - resDict->lookup("Font", &fontDict); - if (fontDict.isDict()) { - gfxFontDict = new GfxFontDict(doc->getXRef(), fontDict.getDict()); + gfxFontDict = NULL; + resDict->lookupNF("Font", &obj1); + if (obj1.isRef()) { + obj1.fetch(doc->getXRef(), &obj2); + if (obj2.isDict()) { + r = obj1.getRef(); + gfxFontDict = new GfxFontDict(doc->getXRef(), &r, obj2.getDict()); + } + obj2.free(); + } else if (obj1.isDict()) { + gfxFontDict = new GfxFontDict(doc->getXRef(), NULL, obj1.getDict()); + } + if (gfxFontDict) { for (i = 0; i < gfxFontDict->getNumFonts(); ++i) { - font = gfxFontDict->getFont(i); - scanFont(font, doc); + if ((font = gfxFontDict->getFont(i))) { + scanFont(font, doc); + } } delete gfxFontDict; } - fontDict.free(); + obj1.free(); // recursively scan any resource dictionaries in objects in this // resource dictionary @@ -206,9 +226,9 @@ static void scanFonts(Dict *resDict, PDFDoc *doc) { static void scanFont(GfxFont *font, PDFDoc *doc) { Ref fontRef, embRef; - Object fontObj, nameObj, toUnicodeObj; + Object fontObj, toUnicodeObj; GString *name; - GBool subset, hasToUnicode; + GBool emb, subset, hasToUnicode; int i; fontRef = *font->getID(); @@ -220,17 +240,19 @@ static void scanFont(GfxFont *font, PDFDoc *doc) { } } - // get the original font name -- the GfxFont class munges substitute - // Base-14 font names into proper form, so this code grabs the - // original name from the font dictionary; also look for a ToUnicode - // map - name = NULL; + // font name + name = font->getOrigName(); + + // check for an embedded font + if (font->getType() == fontType3) { + emb = gTrue; + } else { + emb = font->getEmbeddedFontID(&embRef); + } + + // look for a ToUnicode map hasToUnicode = gFalse; if (doc->getXRef()->fetch(fontRef.num, fontRef.gen, &fontObj)->isDict()) { - if (fontObj.dictLookup("BaseFont", &nameObj)->isName()) { - name = new GString(nameObj.getName()); - } - nameObj.free(); hasToUnicode = fontObj.dictLookup("ToUnicode", &toUnicodeObj)->isStream(); toUnicodeObj.free(); } @@ -249,15 +271,16 @@ static void scanFont(GfxFont *font, PDFDoc *doc) { } // print the font info - printf("%-36s %-12s %-3s %-3s %-3s %6d %2d\n", + printf("%-36s %-12s %-3s %-3s %-3s", name ? name->getCString() : "[none]", fontTypeNames[font->getType()], - font->getEmbeddedFontID(&embRef) ? "yes" : "no", + emb ? "yes" : "no", subset ? "yes" : "no", - hasToUnicode ? "yes" : "no", - fontRef.num, fontRef.gen); - if (name) { - delete name; + hasToUnicode ? "yes" : "no"); + if (fontRef.gen >= 100000) { + printf(" [none]\n"); + } else { + printf(" %6d %2d\n", fontRef.num, fontRef.gen); } // add this font to the list