Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- // Project: DocFontList - Sample app which reproduces Acrobat's Document Properties Fonts tab listing.
- // However, it does not sort the fonts into alphabetical order, and it does not
- // list substitute fonts (aka Actual Fonts)
- */
- #ifndef MAC_ENV
- #include <sys/types.h>
- #include <sys/stat.h>
- #endif
- #include <stdio.h>
- #include <stdlib.h>
- #include "PDFInit.h"
- #include "CosCalls.h"
- #include "CorCalls.h"
- #include "ASCalls.h"
- #include "ASExtraCalls.h"
- #include "PDCalls.h"
- #include "MyPDFLibUtils.h"
- #ifdef MAC_ENV
- #include "MacUtils.h"
- #endif
- ASBool DocFontEnumProc(PDFont font, PDFontFlags* fontFlags, void* clientData)
- {
- ASText asFontName = ASTextNew();
- PDFontGetASTextName(font, true, asFontName);
- char *displayFontName = (char *)ASTextGetUnicodeCopy(asFontName, kUTF8);
- ASAtom asSubtype = PDFontGetSubtype(font);
- char *fontTypeStr = (char *)ASAtomGetString(asSubtype);
- ASInt32 encodingIdx = PDFontGetEncodingIndex(font);
- char *encodingName = (char *)PDFontGetEncodingName(font);
- if (encodingName == NULL)
- {
- switch (encodingIdx){
- case PDBuiltInEncoding:
- encodingName = "Built-in encoding"; break;
- case PDStdEncoding:
- encodingName = "Standard encoding"; break;
- default:
- encodingName = (encodingIdx >= PDLastKnownEncoding) ? "Custom Encoding" : "unknown encoding";
- }
- }
- // if we have a composite font (Type0), then we need to dig deeper to get the correct values.
- if (asSubtype == ASAtomFromString("Type0"))
- {
- CosObj CosFontDict = PDFontGetCosObj(font);
- CosObj encodingVal = CosDictGetKeyString(CosFontDict, "Encoding");
- if (CosObjGetType(encodingVal) == CosName)
- encodingName = (char *)ASAtomGetString(CosNameValue(encodingVal));
- else
- encodingName = "unknown";
- PDFont descFont = PDFontGetDescendant(font);
- ASAtom asSubtype = PDFontGetSubtype(descFont);
- if (asSubtype == ASAtomFromString("CIDFontType2"))
- fontTypeStr = "TrueType (CID)";
- else if (asSubtype == ASAtomFromString("CIDFontType0"))
- fontTypeStr = "Type1 (CID)";
- }
- fprintf(stdout, "%s: %s\n\t%s\n\t%s\n",
- displayFontName,
- (PDFontIsEmbedded(font) ? "(Embedded)" : ""),
- fontTypeStr,
- encodingName);
- ASfree(displayFontName);
- ASTextDestroy(asFontName);
- return true;
- }
- void MainProc(int argc, char **argv)
- {
- PDDoc pdDoc;
- if(argc>1)
- pdDoc = MyPDDocOpen(argv[1]);
- else
- return;
- DURING
- PDDocEnumFonts(pdDoc,0,PDDocGetNumPages(pdDoc)-1,(PDFontEnumProc)DocFontEnumProc,NULL,NULL,NULL);
- PDDocClose(pdDoc);
- HANDLER
- char buf[512];
- ASGetErrorString(ERRORCODE, buf, sizeof(buf));
- fprintf(stderr, "Error code: 0x%lx, Error Message: %s\n", ERRORCODE, buf);
- END_HANDLER
- }
- #define INCLUDE_MYPDFLIBAPP_CPP 1
- #include "MyPDFLibApp.cpp"
- #undef INCLUDE_MYPDFLIBAPP_CPP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement