Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. /*
  2. // Project: DocFontList - Sample app which reproduces Acrobat's Document Properties Fonts tab listing.
  3. // However, it does not sort the fonts into alphabetical order, and it does not
  4. // list substitute fonts (aka Actual Fonts)
  5. */
  6.  
  7. #ifndef MAC_ENV
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #endif
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14.  
  15. #include "PDFInit.h"
  16. #include "CosCalls.h"
  17. #include "CorCalls.h"
  18. #include "ASCalls.h"
  19. #include "ASExtraCalls.h"
  20. #include "PDCalls.h"
  21. #include "MyPDFLibUtils.h"
  22.  
  23. #ifdef MAC_ENV
  24. #include "MacUtils.h"
  25. #endif
  26.  
  27. ASBool DocFontEnumProc(PDFont font, PDFontFlags* fontFlags, void* clientData)
  28. {
  29. ASText asFontName = ASTextNew();
  30. PDFontGetASTextName(font, true, asFontName);
  31. char *displayFontName = (char *)ASTextGetUnicodeCopy(asFontName, kUTF8);
  32.  
  33. ASAtom asSubtype = PDFontGetSubtype(font);
  34. char *fontTypeStr = (char *)ASAtomGetString(asSubtype);
  35.  
  36. ASInt32 encodingIdx = PDFontGetEncodingIndex(font);
  37. char *encodingName = (char *)PDFontGetEncodingName(font);
  38. if (encodingName == NULL)
  39. {
  40. switch (encodingIdx){
  41. case PDBuiltInEncoding:
  42. encodingName = "Built-in encoding"; break;
  43. case PDStdEncoding:
  44. encodingName = "Standard encoding"; break;
  45. default:
  46. encodingName = (encodingIdx >= PDLastKnownEncoding) ? "Custom Encoding" : "unknown encoding";
  47. }
  48. }
  49.  
  50. // if we have a composite font (Type0), then we need to dig deeper to get the correct values.
  51. if (asSubtype == ASAtomFromString("Type0"))
  52. {
  53. CosObj CosFontDict = PDFontGetCosObj(font);
  54. CosObj encodingVal = CosDictGetKeyString(CosFontDict, "Encoding");
  55. if (CosObjGetType(encodingVal) == CosName)
  56. encodingName = (char *)ASAtomGetString(CosNameValue(encodingVal));
  57. else
  58. encodingName = "unknown";
  59.  
  60. PDFont descFont = PDFontGetDescendant(font);
  61. ASAtom asSubtype = PDFontGetSubtype(descFont);
  62. if (asSubtype == ASAtomFromString("CIDFontType2"))
  63. fontTypeStr = "TrueType (CID)";
  64. else if (asSubtype == ASAtomFromString("CIDFontType0"))
  65. fontTypeStr = "Type1 (CID)";
  66. }
  67.  
  68. fprintf(stdout, "%s: %s\n\t%s\n\t%s\n",
  69. displayFontName,
  70. (PDFontIsEmbedded(font) ? "(Embedded)" : ""),
  71. fontTypeStr,
  72. encodingName);
  73.  
  74. ASfree(displayFontName);
  75. ASTextDestroy(asFontName);
  76. return true;
  77. }
  78.  
  79. void MainProc(int argc, char **argv)
  80. {
  81. PDDoc pdDoc;
  82.  
  83. if(argc>1)
  84. pdDoc = MyPDDocOpen(argv[1]);
  85. else
  86. return;
  87. DURING
  88. PDDocEnumFonts(pdDoc,0,PDDocGetNumPages(pdDoc)-1,(PDFontEnumProc)DocFontEnumProc,NULL,NULL,NULL);
  89.  
  90. PDDocClose(pdDoc);
  91. HANDLER
  92. char buf[512];
  93. ASGetErrorString(ERRORCODE, buf, sizeof(buf));
  94. fprintf(stderr, "Error code: 0x%lx, Error Message: %s\n", ERRORCODE, buf);
  95. END_HANDLER
  96. }
  97.  
  98. #define INCLUDE_MYPDFLIBAPP_CPP 1
  99. #include "MyPDFLibApp.cpp"
  100. #undef INCLUDE_MYPDFLIBAPP_CPP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement