Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample app which reproduces Acrobat's Document Properties Fonts tab listing.
/*
// 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.