pdf2json 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (473) hide show
  1. data/README.markdown +9 -0
  2. data/bin/.gitkeep +0 -0
  3. data/ext/extconf.rb +30 -0
  4. data/lib/pdf2json.rb +8 -0
  5. data/pdf2json-0.52-source/AUTHORS +24 -0
  6. data/pdf2json-0.52-source/CHANGES +11 -0
  7. data/pdf2json-0.52-source/Makefile +84 -0
  8. data/pdf2json-0.52-source/Makefile.in +84 -0
  9. data/pdf2json-0.52-source/aclocal.m4 +274 -0
  10. data/pdf2json-0.52-source/aconf-win32.h +86 -0
  11. data/pdf2json-0.52-source/aconf.h +42 -0
  12. data/pdf2json-0.52-source/aconf.h.in +41 -0
  13. data/pdf2json-0.52-source/autom4te.cache/output.0 +6908 -0
  14. data/pdf2json-0.52-source/autom4te.cache/requests +76 -0
  15. data/pdf2json-0.52-source/autom4te.cache/traces.0 +466 -0
  16. data/pdf2json-0.52-source/config.log +1259 -0
  17. data/pdf2json-0.52-source/config.status +1050 -0
  18. data/pdf2json-0.52-source/configure +6908 -0
  19. data/pdf2json-0.52-source/configure.ac +93 -0
  20. data/pdf2json-0.52-source/doc/pdffonts.1 +130 -0
  21. data/pdf2json-0.52-source/doc/pdffonts.cat +107 -0
  22. data/pdf2json-0.52-source/doc/pdffonts.hlp +117 -0
  23. data/pdf2json-0.52-source/doc/pdfimages.1 +102 -0
  24. data/pdf2json-0.52-source/doc/pdfimages.cat +92 -0
  25. data/pdf2json-0.52-source/doc/pdfimages.hlp +101 -0
  26. data/pdf2json-0.52-source/doc/pdfinfo.1 +158 -0
  27. data/pdf2json-0.52-source/doc/pdfinfo.cat +119 -0
  28. data/pdf2json-0.52-source/doc/pdfinfo.hlp +129 -0
  29. data/pdf2json-0.52-source/doc/pdftoppm.1 +115 -0
  30. data/pdf2json-0.52-source/doc/pdftoppm.cat +105 -0
  31. data/pdf2json-0.52-source/doc/pdftoppm.hlp +114 -0
  32. data/pdf2json-0.52-source/doc/pdftops.1 +229 -0
  33. data/pdf2json-0.52-source/doc/pdftops.cat +221 -0
  34. data/pdf2json-0.52-source/doc/pdftops.hlp +231 -0
  35. data/pdf2json-0.52-source/doc/pdftotext.1 +137 -0
  36. data/pdf2json-0.52-source/doc/pdftotext.cat +120 -0
  37. data/pdf2json-0.52-source/doc/pdftotext.hlp +133 -0
  38. data/pdf2json-0.52-source/doc/sample-xpdfrc +91 -0
  39. data/pdf2json-0.52-source/doc/xpdf.1 +513 -0
  40. data/pdf2json-0.52-source/doc/xpdf.cat +476 -0
  41. data/pdf2json-0.52-source/doc/xpdf.hlp +489 -0
  42. data/pdf2json-0.52-source/doc/xpdfrc.5 +480 -0
  43. data/pdf2json-0.52-source/doc/xpdfrc.cat +474 -0
  44. data/pdf2json-0.52-source/doc/xpdfrc.hlp +479 -0
  45. data/pdf2json-0.52-source/fofi/.DS_Store +0 -0
  46. data/pdf2json-0.52-source/fofi/FoFiBase.cc +156 -0
  47. data/pdf2json-0.52-source/fofi/FoFiBase.h +57 -0
  48. data/pdf2json-0.52-source/fofi/FoFiBase.o +0 -0
  49. data/pdf2json-0.52-source/fofi/FoFiEncodings.cc +994 -0
  50. data/pdf2json-0.52-source/fofi/FoFiEncodings.h +36 -0
  51. data/pdf2json-0.52-source/fofi/FoFiEncodings.o +0 -0
  52. data/pdf2json-0.52-source/fofi/FoFiTrueType.cc +2027 -0
  53. data/pdf2json-0.52-source/fofi/FoFiTrueType.h +174 -0
  54. data/pdf2json-0.52-source/fofi/FoFiTrueType.o +0 -0
  55. data/pdf2json-0.52-source/fofi/FoFiType1.cc +252 -0
  56. data/pdf2json-0.52-source/fofi/FoFiType1.h +59 -0
  57. data/pdf2json-0.52-source/fofi/FoFiType1.o +0 -0
  58. data/pdf2json-0.52-source/fofi/FoFiType1C.cc +2603 -0
  59. data/pdf2json-0.52-source/fofi/FoFiType1C.h +233 -0
  60. data/pdf2json-0.52-source/fofi/FoFiType1C.o +0 -0
  61. data/pdf2json-0.52-source/fofi/Makefile +70 -0
  62. data/pdf2json-0.52-source/fofi/Makefile.dep +0 -0
  63. data/pdf2json-0.52-source/fofi/Makefile.in +70 -0
  64. data/pdf2json-0.52-source/fofi/libfofi.a +0 -0
  65. data/pdf2json-0.52-source/fofi/vms_make.com +0 -0
  66. data/pdf2json-0.52-source/freetype.win32/.DS_Store +0 -0
  67. data/pdf2json-0.52-source/freetype.win32/include/.DS_Store +0 -0
  68. data/pdf2json-0.52-source/freetype.win32/include/freetype/config/ftconfig.h +528 -0
  69. data/pdf2json-0.52-source/freetype.win32/include/freetype/config/ftheader.h +780 -0
  70. data/pdf2json-0.52-source/freetype.win32/include/freetype/config/ftmodule.h +32 -0
  71. data/pdf2json-0.52-source/freetype.win32/include/freetype/config/ftoption.h +733 -0
  72. data/pdf2json-0.52-source/freetype.win32/include/freetype/config/ftstdlib.h +173 -0
  73. data/pdf2json-0.52-source/freetype.win32/include/freetype/freetype.h +3919 -0
  74. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftadvanc.h +179 -0
  75. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftbbox.h +94 -0
  76. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftbdf.h +209 -0
  77. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftbitmap.h +227 -0
  78. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftcache.h +1128 -0
  79. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftchapters.h +103 -0
  80. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftcid.h +166 -0
  81. data/pdf2json-0.52-source/freetype.win32/include/freetype/fterrdef.h +244 -0
  82. data/pdf2json-0.52-source/freetype.win32/include/freetype/fterrors.h +206 -0
  83. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftgasp.h +120 -0
  84. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftglyph.h +613 -0
  85. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftgxval.h +358 -0
  86. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftgzip.h +102 -0
  87. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftimage.h +1313 -0
  88. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftincrem.h +353 -0
  89. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftlcdfil.h +213 -0
  90. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftlist.h +277 -0
  91. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftlzw.h +99 -0
  92. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftmac.h +274 -0
  93. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftmm.h +378 -0
  94. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftmodapi.h +483 -0
  95. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftmoderr.h +155 -0
  96. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftotval.h +203 -0
  97. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftoutln.h +537 -0
  98. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftpfr.h +172 -0
  99. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftrender.h +230 -0
  100. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftsizes.h +159 -0
  101. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftsnames.h +200 -0
  102. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftstroke.h +716 -0
  103. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftsynth.h +80 -0
  104. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftsystem.h +347 -0
  105. data/pdf2json-0.52-source/freetype.win32/include/freetype/fttrigon.h +350 -0
  106. data/pdf2json-0.52-source/freetype.win32/include/freetype/fttypes.h +588 -0
  107. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftwinfnt.h +274 -0
  108. data/pdf2json-0.52-source/freetype.win32/include/freetype/ftxf86.h +83 -0
  109. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/autohint.h +231 -0
  110. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftcalc.h +179 -0
  111. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftdebug.h +250 -0
  112. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftdriver.h +422 -0
  113. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftgloadr.h +168 -0
  114. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftmemory.h +380 -0
  115. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftobjs.h +1428 -0
  116. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftpic.h +67 -0
  117. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftrfork.h +196 -0
  118. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftserv.h +620 -0
  119. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftstream.h +539 -0
  120. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/fttrace.h +139 -0
  121. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/ftvalid.h +150 -0
  122. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/internal.h +51 -0
  123. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/pcftypes.h +56 -0
  124. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/psaux.h +873 -0
  125. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/pshints.h +712 -0
  126. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svbdf.h +77 -0
  127. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svcid.h +83 -0
  128. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svgldict.h +82 -0
  129. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svgxval.h +72 -0
  130. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svkern.h +51 -0
  131. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svmm.h +104 -0
  132. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svotval.h +55 -0
  133. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svpfr.h +66 -0
  134. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svpostnm.h +79 -0
  135. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svpscmap.h +164 -0
  136. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svpsinfo.h +92 -0
  137. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svsfnt.h +102 -0
  138. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svttcmap.h +106 -0
  139. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svtteng.h +53 -0
  140. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svttglyf.h +67 -0
  141. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svwinfnt.h +50 -0
  142. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/services/svxf86nm.h +55 -0
  143. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/sfnt.h +897 -0
  144. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/t1types.h +270 -0
  145. data/pdf2json-0.52-source/freetype.win32/include/freetype/internal/tttypes.h +1543 -0
  146. data/pdf2json-0.52-source/freetype.win32/include/freetype/t1tables.h +504 -0
  147. data/pdf2json-0.52-source/freetype.win32/include/freetype/ttnameid.h +1247 -0
  148. data/pdf2json-0.52-source/freetype.win32/include/freetype/tttables.h +759 -0
  149. data/pdf2json-0.52-source/freetype.win32/include/freetype/tttags.h +107 -0
  150. data/pdf2json-0.52-source/freetype.win32/include/freetype/ttunpat.h +59 -0
  151. data/pdf2json-0.52-source/freetype.win32/include/ft2build.h +39 -0
  152. data/pdf2json-0.52-source/freetype.win32/lib/freetype_a.lib +0 -0
  153. data/pdf2json-0.52-source/goo/.DS_Store +0 -0
  154. data/pdf2json-0.52-source/goo/FixedPoint.cc +118 -0
  155. data/pdf2json-0.52-source/goo/FixedPoint.h +155 -0
  156. data/pdf2json-0.52-source/goo/FixedPoint.o +0 -0
  157. data/pdf2json-0.52-source/goo/GHash.cc +380 -0
  158. data/pdf2json-0.52-source/goo/GHash.h +78 -0
  159. data/pdf2json-0.52-source/goo/GHash.o +0 -0
  160. data/pdf2json-0.52-source/goo/GList.cc +97 -0
  161. data/pdf2json-0.52-source/goo/GList.h +96 -0
  162. data/pdf2json-0.52-source/goo/GList.o +0 -0
  163. data/pdf2json-0.52-source/goo/GMutex.h +49 -0
  164. data/pdf2json-0.52-source/goo/GString.cc +724 -0
  165. data/pdf2json-0.52-source/goo/GString.cc.fixed +718 -0
  166. data/pdf2json-0.52-source/goo/GString.h +136 -0
  167. data/pdf2json-0.52-source/goo/GString.o +0 -0
  168. data/pdf2json-0.52-source/goo/ImgWriter.o +0 -0
  169. data/pdf2json-0.52-source/goo/JpegWriter.o +0 -0
  170. data/pdf2json-0.52-source/goo/Makefile +72 -0
  171. data/pdf2json-0.52-source/goo/Makefile.dep +0 -0
  172. data/pdf2json-0.52-source/goo/Makefile.in +72 -0
  173. data/pdf2json-0.52-source/goo/PNGWriter.o +0 -0
  174. data/pdf2json-0.52-source/goo/gfile.cc +731 -0
  175. data/pdf2json-0.52-source/goo/gfile.h +138 -0
  176. data/pdf2json-0.52-source/goo/gfile.o +0 -0
  177. data/pdf2json-0.52-source/goo/gmem.cc +264 -0
  178. data/pdf2json-0.52-source/goo/gmem.h +79 -0
  179. data/pdf2json-0.52-source/goo/gmem.o +0 -0
  180. data/pdf2json-0.52-source/goo/gmempp.cc +32 -0
  181. data/pdf2json-0.52-source/goo/gmempp.o +0 -0
  182. data/pdf2json-0.52-source/goo/gtypes.h +29 -0
  183. data/pdf2json-0.52-source/goo/libGoo.a +0 -0
  184. data/pdf2json-0.52-source/goo/parseargs.c +190 -0
  185. data/pdf2json-0.52-source/goo/parseargs.h +71 -0
  186. data/pdf2json-0.52-source/goo/parseargs.o +0 -0
  187. data/pdf2json-0.52-source/goo/vms_directory.c +214 -0
  188. data/pdf2json-0.52-source/goo/vms_dirent.h +67 -0
  189. data/pdf2json-0.52-source/goo/vms_make.com +82 -0
  190. data/pdf2json-0.52-source/goo/vms_sys_dirent.h +54 -0
  191. data/pdf2json-0.52-source/goo/vms_unix_time.h +102 -0
  192. data/pdf2json-0.52-source/goo/vms_unix_times.c +42 -0
  193. data/pdf2json-0.52-source/goo/vms_unlink.c +22 -0
  194. data/pdf2json-0.52-source/ms_make.bat +199 -0
  195. data/pdf2json-0.52-source/splash/.DS_Store +0 -0
  196. data/pdf2json-0.52-source/splash/Makefile +103 -0
  197. data/pdf2json-0.52-source/splash/Makefile.dep +0 -0
  198. data/pdf2json-0.52-source/splash/Makefile.in +103 -0
  199. data/pdf2json-0.52-source/splash/Splash.cc +3310 -0
  200. data/pdf2json-0.52-source/splash/Splash.h +293 -0
  201. data/pdf2json-0.52-source/splash/Splash.o +0 -0
  202. data/pdf2json-0.52-source/splash/SplashBitmap.cc +188 -0
  203. data/pdf2json-0.52-source/splash/SplashBitmap.h +64 -0
  204. data/pdf2json-0.52-source/splash/SplashBitmap.o +0 -0
  205. data/pdf2json-0.52-source/splash/SplashClip.cc +382 -0
  206. data/pdf2json-0.52-source/splash/SplashClip.h +107 -0
  207. data/pdf2json-0.52-source/splash/SplashClip.o +0 -0
  208. data/pdf2json-0.52-source/splash/SplashErrorCodes.h +32 -0
  209. data/pdf2json-0.52-source/splash/SplashFTFont.cc +357 -0
  210. data/pdf2json-0.52-source/splash/SplashFTFont.h +58 -0
  211. data/pdf2json-0.52-source/splash/SplashFTFont.o +0 -0
  212. data/pdf2json-0.52-source/splash/SplashFTFontEngine.cc +179 -0
  213. data/pdf2json-0.52-source/splash/SplashFTFontEngine.h +65 -0
  214. data/pdf2json-0.52-source/splash/SplashFTFontEngine.o +0 -0
  215. data/pdf2json-0.52-source/splash/SplashFTFontFile.cc +114 -0
  216. data/pdf2json-0.52-source/splash/SplashFTFontFile.h +73 -0
  217. data/pdf2json-0.52-source/splash/SplashFTFontFile.o +0 -0
  218. data/pdf2json-0.52-source/splash/SplashFont.cc +176 -0
  219. data/pdf2json-0.52-source/splash/SplashFont.h +104 -0
  220. data/pdf2json-0.52-source/splash/SplashFont.o +0 -0
  221. data/pdf2json-0.52-source/splash/SplashFontEngine.cc +317 -0
  222. data/pdf2json-0.52-source/splash/SplashFontEngine.h +91 -0
  223. data/pdf2json-0.52-source/splash/SplashFontEngine.o +0 -0
  224. data/pdf2json-0.52-source/splash/SplashFontFile.cc +55 -0
  225. data/pdf2json-0.52-source/splash/SplashFontFile.h +60 -0
  226. data/pdf2json-0.52-source/splash/SplashFontFile.o +0 -0
  227. data/pdf2json-0.52-source/splash/SplashFontFileID.cc +23 -0
  228. data/pdf2json-0.52-source/splash/SplashFontFileID.h +30 -0
  229. data/pdf2json-0.52-source/splash/SplashFontFileID.o +0 -0
  230. data/pdf2json-0.52-source/splash/SplashGlyphBitmap.h +26 -0
  231. data/pdf2json-0.52-source/splash/SplashMath.h +89 -0
  232. data/pdf2json-0.52-source/splash/SplashPath.cc +184 -0
  233. data/pdf2json-0.52-source/splash/SplashPath.h +121 -0
  234. data/pdf2json-0.52-source/splash/SplashPath.o +0 -0
  235. data/pdf2json-0.52-source/splash/SplashPattern.cc +40 -0
  236. data/pdf2json-0.52-source/splash/SplashPattern.h +65 -0
  237. data/pdf2json-0.52-source/splash/SplashPattern.o +0 -0
  238. data/pdf2json-0.52-source/splash/SplashScreen.cc +383 -0
  239. data/pdf2json-0.52-source/splash/SplashScreen.h +56 -0
  240. data/pdf2json-0.52-source/splash/SplashScreen.o +0 -0
  241. data/pdf2json-0.52-source/splash/SplashState.cc +165 -0
  242. data/pdf2json-0.52-source/splash/SplashState.h +103 -0
  243. data/pdf2json-0.52-source/splash/SplashState.o +0 -0
  244. data/pdf2json-0.52-source/splash/SplashT1Font.cc +287 -0
  245. data/pdf2json-0.52-source/splash/SplashT1Font.h +57 -0
  246. data/pdf2json-0.52-source/splash/SplashT1Font.o +0 -0
  247. data/pdf2json-0.52-source/splash/SplashT1FontEngine.cc +124 -0
  248. data/pdf2json-0.52-source/splash/SplashT1FontEngine.h +53 -0
  249. data/pdf2json-0.52-source/splash/SplashT1FontEngine.o +0 -0
  250. data/pdf2json-0.52-source/splash/SplashT1FontFile.cc +97 -0
  251. data/pdf2json-0.52-source/splash/SplashT1FontFile.h +58 -0
  252. data/pdf2json-0.52-source/splash/SplashT1FontFile.o +0 -0
  253. data/pdf2json-0.52-source/splash/SplashTypes.h +132 -0
  254. data/pdf2json-0.52-source/splash/SplashXPath.cc +438 -0
  255. data/pdf2json-0.52-source/splash/SplashXPath.h +100 -0
  256. data/pdf2json-0.52-source/splash/SplashXPath.o +0 -0
  257. data/pdf2json-0.52-source/splash/SplashXPathScanner.cc +428 -0
  258. data/pdf2json-0.52-source/splash/SplashXPathScanner.h +87 -0
  259. data/pdf2json-0.52-source/splash/SplashXPathScanner.o +0 -0
  260. data/pdf2json-0.52-source/splash/libsplash.a +0 -0
  261. data/pdf2json-0.52-source/splash/vms_make.com +0 -0
  262. data/pdf2json-0.52-source/src/.DS_Store +0 -0
  263. data/pdf2json-0.52-source/src/GVector.h +101 -0
  264. data/pdf2json-0.52-source/src/ImgOutputDev.cc +1243 -0
  265. data/pdf2json-0.52-source/src/ImgOutputDev.h +307 -0
  266. data/pdf2json-0.52-source/src/ImgOutputDev.o +0 -0
  267. data/pdf2json-0.52-source/src/Makefile +68 -0
  268. data/pdf2json-0.52-source/src/Makefile.in +68 -0
  269. data/pdf2json-0.52-source/src/XmlFonts.cc +367 -0
  270. data/pdf2json-0.52-source/src/XmlFonts.h +91 -0
  271. data/pdf2json-0.52-source/src/XmlFonts.o +0 -0
  272. data/pdf2json-0.52-source/src/XmlLinks.cc +101 -0
  273. data/pdf2json-0.52-source/src/XmlLinks.h +54 -0
  274. data/pdf2json-0.52-source/src/XmlLinks.o +0 -0
  275. data/pdf2json-0.52-source/src/pdf2json +0 -0
  276. data/pdf2json-0.52-source/src/pdf2json.cc +343 -0
  277. data/pdf2json-0.52-source/src/pdf2json.o +0 -0
  278. data/pdf2json-0.52-source/src/pdf2xml.dtd +22 -0
  279. data/pdf2json-0.52-source/src/pdf2xmljson.dtd +9 -0
  280. data/pdf2json-0.52-source/xpdf/.DS_Store +0 -0
  281. data/pdf2json-0.52-source/xpdf/Annot.cc +1556 -0
  282. data/pdf2json-0.52-source/xpdf/Annot.h +142 -0
  283. data/pdf2json-0.52-source/xpdf/Annot.o +0 -0
  284. data/pdf2json-0.52-source/xpdf/Array.cc +73 -0
  285. data/pdf2json-0.52-source/xpdf/Array.h +58 -0
  286. data/pdf2json-0.52-source/xpdf/Array.o +0 -0
  287. data/pdf2json-0.52-source/xpdf/BuiltinFont.cc +65 -0
  288. data/pdf2json-0.52-source/xpdf/BuiltinFont.h +57 -0
  289. data/pdf2json-0.52-source/xpdf/BuiltinFont.o +0 -0
  290. data/pdf2json-0.52-source/xpdf/BuiltinFontTables.cc +4284 -0
  291. data/pdf2json-0.52-source/xpdf/BuiltinFontTables.h +23 -0
  292. data/pdf2json-0.52-source/xpdf/BuiltinFontTables.o +0 -0
  293. data/pdf2json-0.52-source/xpdf/CMap.cc +408 -0
  294. data/pdf2json-0.52-source/xpdf/CMap.h +102 -0
  295. data/pdf2json-0.52-source/xpdf/CMap.o +0 -0
  296. data/pdf2json-0.52-source/xpdf/Catalog.cc +374 -0
  297. data/pdf2json-0.52-source/xpdf/Catalog.h +97 -0
  298. data/pdf2json-0.52-source/xpdf/Catalog.o +0 -0
  299. data/pdf2json-0.52-source/xpdf/CharCodeToUnicode.cc +540 -0
  300. data/pdf2json-0.52-source/xpdf/CharCodeToUnicode.h +117 -0
  301. data/pdf2json-0.52-source/xpdf/CharCodeToUnicode.o +0 -0
  302. data/pdf2json-0.52-source/xpdf/CharTypes.h +24 -0
  303. data/pdf2json-0.52-source/xpdf/CompactFontTables.h +464 -0
  304. data/pdf2json-0.52-source/xpdf/CoreOutputDev.cc +61 -0
  305. data/pdf2json-0.52-source/xpdf/CoreOutputDev.h +61 -0
  306. data/pdf2json-0.52-source/xpdf/Decrypt.cc +776 -0
  307. data/pdf2json-0.52-source/xpdf/Decrypt.h +95 -0
  308. data/pdf2json-0.52-source/xpdf/Decrypt.o +0 -0
  309. data/pdf2json-0.52-source/xpdf/Dict.cc +95 -0
  310. data/pdf2json-0.52-source/xpdf/Dict.h +77 -0
  311. data/pdf2json-0.52-source/xpdf/Dict.o +0 -0
  312. data/pdf2json-0.52-source/xpdf/Error.cc +38 -0
  313. data/pdf2json-0.52-source/xpdf/Error.h +23 -0
  314. data/pdf2json-0.52-source/xpdf/Error.o +0 -0
  315. data/pdf2json-0.52-source/xpdf/ErrorCodes.h +36 -0
  316. data/pdf2json-0.52-source/xpdf/FontEncodingTables.cc +1824 -0
  317. data/pdf2json-0.52-source/xpdf/FontEncodingTables.h +20 -0
  318. data/pdf2json-0.52-source/xpdf/FontEncodingTables.o +0 -0
  319. data/pdf2json-0.52-source/xpdf/Function.cc +1573 -0
  320. data/pdf2json-0.52-source/xpdf/Function.h +229 -0
  321. data/pdf2json-0.52-source/xpdf/Function.o +0 -0
  322. data/pdf2json-0.52-source/xpdf/Gfx.cc +4187 -0
  323. data/pdf2json-0.52-source/xpdf/Gfx.h +312 -0
  324. data/pdf2json-0.52-source/xpdf/Gfx.o +0 -0
  325. data/pdf2json-0.52-source/xpdf/GfxFont.cc +1568 -0
  326. data/pdf2json-0.52-source/xpdf/GfxFont.h +320 -0
  327. data/pdf2json-0.52-source/xpdf/GfxFont.o +0 -0
  328. data/pdf2json-0.52-source/xpdf/GfxState.cc +4137 -0
  329. data/pdf2json-0.52-source/xpdf/GfxState.h +1244 -0
  330. data/pdf2json-0.52-source/xpdf/GfxState.o +0 -0
  331. data/pdf2json-0.52-source/xpdf/GlobalParams.cc +2924 -0
  332. data/pdf2json-0.52-source/xpdf/GlobalParams.cc.old +2908 -0
  333. data/pdf2json-0.52-source/xpdf/GlobalParams.h +466 -0
  334. data/pdf2json-0.52-source/xpdf/GlobalParams.h.old +463 -0
  335. data/pdf2json-0.52-source/xpdf/GlobalParams.o +0 -0
  336. data/pdf2json-0.52-source/xpdf/ImageOutputDev.cc +195 -0
  337. data/pdf2json-0.52-source/xpdf/ImageOutputDev.h +76 -0
  338. data/pdf2json-0.52-source/xpdf/ImageOutputDev.o +0 -0
  339. data/pdf2json-0.52-source/xpdf/JArithmeticDecoder.cc +322 -0
  340. data/pdf2json-0.52-source/xpdf/JArithmeticDecoder.h +109 -0
  341. data/pdf2json-0.52-source/xpdf/JArithmeticDecoder.o +0 -0
  342. data/pdf2json-0.52-source/xpdf/JBIG2Stream.cc +3413 -0
  343. data/pdf2json-0.52-source/xpdf/JBIG2Stream.h +145 -0
  344. data/pdf2json-0.52-source/xpdf/JBIG2Stream.o +0 -0
  345. data/pdf2json-0.52-source/xpdf/JPXStream.cc +3144 -0
  346. data/pdf2json-0.52-source/xpdf/JPXStream.h +351 -0
  347. data/pdf2json-0.52-source/xpdf/JPXStream.o +0 -0
  348. data/pdf2json-0.52-source/xpdf/Lexer.cc +485 -0
  349. data/pdf2json-0.52-source/xpdf/Lexer.h +80 -0
  350. data/pdf2json-0.52-source/xpdf/Lexer.o +0 -0
  351. data/pdf2json-0.52-source/xpdf/Link.cc +806 -0
  352. data/pdf2json-0.52-source/xpdf/Link.cc.old +784 -0
  353. data/pdf2json-0.52-source/xpdf/Link.h +415 -0
  354. data/pdf2json-0.52-source/xpdf/Link.h.old +369 -0
  355. data/pdf2json-0.52-source/xpdf/Link.o +0 -0
  356. data/pdf2json-0.52-source/xpdf/Makefile +232 -0
  357. data/pdf2json-0.52-source/xpdf/Makefile.dep +0 -0
  358. data/pdf2json-0.52-source/xpdf/Makefile.in +232 -0
  359. data/pdf2json-0.52-source/xpdf/NameToCharCode.cc +116 -0
  360. data/pdf2json-0.52-source/xpdf/NameToCharCode.h +42 -0
  361. data/pdf2json-0.52-source/xpdf/NameToCharCode.o +0 -0
  362. data/pdf2json-0.52-source/xpdf/NameToUnicodeTable.h +1097 -0
  363. data/pdf2json-0.52-source/xpdf/Object.cc +231 -0
  364. data/pdf2json-0.52-source/xpdf/Object.h +303 -0
  365. data/pdf2json-0.52-source/xpdf/Object.o +0 -0
  366. data/pdf2json-0.52-source/xpdf/Outline.cc +151 -0
  367. data/pdf2json-0.52-source/xpdf/Outline.h +76 -0
  368. data/pdf2json-0.52-source/xpdf/Outline.o +0 -0
  369. data/pdf2json-0.52-source/xpdf/OutputDev.cc +131 -0
  370. data/pdf2json-0.52-source/xpdf/OutputDev.h +253 -0
  371. data/pdf2json-0.52-source/xpdf/OutputDev.o +0 -0
  372. data/pdf2json-0.52-source/xpdf/PDFCore.cc +2044 -0
  373. data/pdf2json-0.52-source/xpdf/PDFCore.h +321 -0
  374. data/pdf2json-0.52-source/xpdf/PDFDoc.cc +404 -0
  375. data/pdf2json-0.52-source/xpdf/PDFDoc.h +183 -0
  376. data/pdf2json-0.52-source/xpdf/PDFDoc.o +0 -0
  377. data/pdf2json-0.52-source/xpdf/PDFDocEncoding.cc +44 -0
  378. data/pdf2json-0.52-source/xpdf/PDFDocEncoding.h +16 -0
  379. data/pdf2json-0.52-source/xpdf/PDFDocEncoding.o +0 -0
  380. data/pdf2json-0.52-source/xpdf/PSOutputDev.cc +6224 -0
  381. data/pdf2json-0.52-source/xpdf/PSOutputDev.h +395 -0
  382. data/pdf2json-0.52-source/xpdf/PSOutputDev.o +0 -0
  383. data/pdf2json-0.52-source/xpdf/PSTokenizer.cc +135 -0
  384. data/pdf2json-0.52-source/xpdf/PSTokenizer.h +41 -0
  385. data/pdf2json-0.52-source/xpdf/PSTokenizer.o +0 -0
  386. data/pdf2json-0.52-source/xpdf/Page.cc +454 -0
  387. data/pdf2json-0.52-source/xpdf/Page.h +187 -0
  388. data/pdf2json-0.52-source/xpdf/Page.o +0 -0
  389. data/pdf2json-0.52-source/xpdf/Parser.cc +227 -0
  390. data/pdf2json-0.52-source/xpdf/Parser.h +59 -0
  391. data/pdf2json-0.52-source/xpdf/Parser.o +0 -0
  392. data/pdf2json-0.52-source/xpdf/PreScanOutputDev.cc +257 -0
  393. data/pdf2json-0.52-source/xpdf/PreScanOutputDev.h +130 -0
  394. data/pdf2json-0.52-source/xpdf/PreScanOutputDev.o +0 -0
  395. data/pdf2json-0.52-source/xpdf/SecurityHandler.cc +390 -0
  396. data/pdf2json-0.52-source/xpdf/SecurityHandler.h +160 -0
  397. data/pdf2json-0.52-source/xpdf/SecurityHandler.o +0 -0
  398. data/pdf2json-0.52-source/xpdf/SplashOutputDev.cc +2845 -0
  399. data/pdf2json-0.52-source/xpdf/SplashOutputDev.h +247 -0
  400. data/pdf2json-0.52-source/xpdf/SplashOutputDev.o +0 -0
  401. data/pdf2json-0.52-source/xpdf/Stream-CCITT.h +459 -0
  402. data/pdf2json-0.52-source/xpdf/Stream.cc +4627 -0
  403. data/pdf2json-0.52-source/xpdf/Stream.h +858 -0
  404. data/pdf2json-0.52-source/xpdf/Stream.o +0 -0
  405. data/pdf2json-0.52-source/xpdf/TextOutputDev.cc +4090 -0
  406. data/pdf2json-0.52-source/xpdf/TextOutputDev.h +661 -0
  407. data/pdf2json-0.52-source/xpdf/TextOutputDev.o +0 -0
  408. data/pdf2json-0.52-source/xpdf/UTF8.h +56 -0
  409. data/pdf2json-0.52-source/xpdf/UnicodeMap.cc +302 -0
  410. data/pdf2json-0.52-source/xpdf/UnicodeMap.cc.old +293 -0
  411. data/pdf2json-0.52-source/xpdf/UnicodeMap.h +135 -0
  412. data/pdf2json-0.52-source/xpdf/UnicodeMap.h.old +123 -0
  413. data/pdf2json-0.52-source/xpdf/UnicodeMap.o +0 -0
  414. data/pdf2json-0.52-source/xpdf/UnicodeMapTables.h +361 -0
  415. data/pdf2json-0.52-source/xpdf/UnicodeTypeTable.cc +949 -0
  416. data/pdf2json-0.52-source/xpdf/UnicodeTypeTable.h +20 -0
  417. data/pdf2json-0.52-source/xpdf/UnicodeTypeTable.o +0 -0
  418. data/pdf2json-0.52-source/xpdf/XPDFApp.cc +447 -0
  419. data/pdf2json-0.52-source/xpdf/XPDFApp.h +114 -0
  420. data/pdf2json-0.52-source/xpdf/XPDFCore.cc +1655 -0
  421. data/pdf2json-0.52-source/xpdf/XPDFCore.h +251 -0
  422. data/pdf2json-0.52-source/xpdf/XPDFTree.cc +931 -0
  423. data/pdf2json-0.52-source/xpdf/XPDFTree.h +45 -0
  424. data/pdf2json-0.52-source/xpdf/XPDFTreeP.h +87 -0
  425. data/pdf2json-0.52-source/xpdf/XPDFViewer.cc +3488 -0
  426. data/pdf2json-0.52-source/xpdf/XPDFViewer.h +352 -0
  427. data/pdf2json-0.52-source/xpdf/XRef.cc +896 -0
  428. data/pdf2json-0.52-source/xpdf/XRef.h +133 -0
  429. data/pdf2json-0.52-source/xpdf/XRef.o +0 -0
  430. data/pdf2json-0.52-source/xpdf/XpdfPluginAPI.cc +262 -0
  431. data/pdf2json-0.52-source/xpdf/XpdfPluginAPI.h +341 -0
  432. data/pdf2json-0.52-source/xpdf/XpdfPluginAPI.o +0 -0
  433. data/pdf2json-0.52-source/xpdf/about-text.h +48 -0
  434. data/pdf2json-0.52-source/xpdf/about.xbm +6 -0
  435. data/pdf2json-0.52-source/xpdf/backArrow.xbm +6 -0
  436. data/pdf2json-0.52-source/xpdf/backArrowDis.xbm +6 -0
  437. data/pdf2json-0.52-source/xpdf/config.h +112 -0
  438. data/pdf2json-0.52-source/xpdf/dblLeftArrow.xbm +6 -0
  439. data/pdf2json-0.52-source/xpdf/dblLeftArrowDis.xbm +6 -0
  440. data/pdf2json-0.52-source/xpdf/dblRightArrow.xbm +6 -0
  441. data/pdf2json-0.52-source/xpdf/dblRightArrowDis.xbm +6 -0
  442. data/pdf2json-0.52-source/xpdf/find.xbm +6 -0
  443. data/pdf2json-0.52-source/xpdf/findDis.xbm +6 -0
  444. data/pdf2json-0.52-source/xpdf/forwardArrow.xbm +6 -0
  445. data/pdf2json-0.52-source/xpdf/forwardArrowDis.xbm +6 -0
  446. data/pdf2json-0.52-source/xpdf/leftArrow.xbm +5 -0
  447. data/pdf2json-0.52-source/xpdf/leftArrowDis.xbm +5 -0
  448. data/pdf2json-0.52-source/xpdf/libXpdf.a +0 -0
  449. data/pdf2json-0.52-source/xpdf/pdffonts +0 -0
  450. data/pdf2json-0.52-source/xpdf/pdffonts.cc +298 -0
  451. data/pdf2json-0.52-source/xpdf/pdffonts.o +0 -0
  452. data/pdf2json-0.52-source/xpdf/pdfimages +0 -0
  453. data/pdf2json-0.52-source/xpdf/pdfimages.cc +155 -0
  454. data/pdf2json-0.52-source/xpdf/pdfimages.o +0 -0
  455. data/pdf2json-0.52-source/xpdf/pdfinfo +0 -0
  456. data/pdf2json-0.52-source/xpdf/pdfinfo.cc +387 -0
  457. data/pdf2json-0.52-source/xpdf/pdfinfo.o +0 -0
  458. data/pdf2json-0.52-source/xpdf/pdftoppm.cc +203 -0
  459. data/pdf2json-0.52-source/xpdf/pdftops +0 -0
  460. data/pdf2json-0.52-source/xpdf/pdftops.cc +344 -0
  461. data/pdf2json-0.52-source/xpdf/pdftops.o +0 -0
  462. data/pdf2json-0.52-source/xpdf/pdftotext +0 -0
  463. data/pdf2json-0.52-source/xpdf/pdftotext.cc +333 -0
  464. data/pdf2json-0.52-source/xpdf/pdftotext.o +0 -0
  465. data/pdf2json-0.52-source/xpdf/print.xbm +6 -0
  466. data/pdf2json-0.52-source/xpdf/printDis.xbm +6 -0
  467. data/pdf2json-0.52-source/xpdf/rightArrow.xbm +5 -0
  468. data/pdf2json-0.52-source/xpdf/rightArrowDis.xbm +5 -0
  469. data/pdf2json-0.52-source/xpdf/vms_make.com +129 -0
  470. data/pdf2json-0.52-source/xpdf/xpdf.cc +344 -0
  471. data/pdf2json-0.52-source/xpdf/xpdfIcon.xpm +62 -0
  472. data/pdf2json.gemspec +29 -0
  473. metadata +518 -0
@@ -0,0 +1,312 @@
1
+ //========================================================================
2
+ //
3
+ // Gfx.h
4
+ //
5
+ // Copyright 1996-2003 Glyph & Cog, LLC
6
+ //
7
+ //========================================================================
8
+
9
+ #ifndef GFX_H
10
+ #define GFX_H
11
+
12
+ #include <aconf.h>
13
+
14
+ #ifdef USE_GCC_PRAGMAS
15
+ #pragma interface
16
+ #endif
17
+
18
+ #include "gtypes.h"
19
+
20
+ class GString;
21
+ class XRef;
22
+ class Array;
23
+ class Stream;
24
+ class Parser;
25
+ class Dict;
26
+ class Function;
27
+ class OutputDev;
28
+ class GfxFontDict;
29
+ class GfxFont;
30
+ class GfxPattern;
31
+ class GfxTilingPattern;
32
+ class GfxShadingPattern;
33
+ class GfxShading;
34
+ class GfxFunctionShading;
35
+ class GfxAxialShading;
36
+ class GfxRadialShading;
37
+ class GfxGouraudTriangleShading;
38
+ class GfxPatchMeshShading;
39
+ struct GfxPatch;
40
+ class GfxState;
41
+ struct GfxColor;
42
+ class GfxColorSpace;
43
+ class Gfx;
44
+ class PDFRectangle;
45
+ class AnnotBorderStyle;
46
+
47
+ //------------------------------------------------------------------------
48
+
49
+ enum GfxClipType {
50
+ clipNone,
51
+ clipNormal,
52
+ clipEO
53
+ };
54
+
55
+ enum TchkType {
56
+ tchkBool, // boolean
57
+ tchkInt, // integer
58
+ tchkNum, // number (integer or real)
59
+ tchkString, // string
60
+ tchkName, // name
61
+ tchkArray, // array
62
+ tchkProps, // properties (dictionary or name)
63
+ tchkSCN, // scn/SCN args (number of name)
64
+ tchkNone // used to avoid empty initializer lists
65
+ };
66
+
67
+ #define maxArgs 33
68
+
69
+ struct Operator {
70
+ char name[4];
71
+ int numArgs;
72
+ TchkType tchk[maxArgs];
73
+ void (Gfx::*func)(Object args[], int numArgs);
74
+ };
75
+
76
+ //------------------------------------------------------------------------
77
+
78
+ class GfxResources {
79
+ public:
80
+
81
+ GfxResources(XRef *xref, Dict *resDict, GfxResources *nextA);
82
+ ~GfxResources();
83
+
84
+ GfxFont *lookupFont(char *name);
85
+ GBool lookupXObject(char *name, Object *obj);
86
+ GBool lookupXObjectNF(char *name, Object *obj);
87
+ void lookupColorSpace(char *name, Object *obj);
88
+ GfxPattern *lookupPattern(char *name);
89
+ GfxShading *lookupShading(char *name);
90
+ GBool lookupGState(char *name, Object *obj);
91
+
92
+ GfxResources *getNext() { return next; }
93
+
94
+ private:
95
+
96
+ GfxFontDict *fonts;
97
+ Object xObjDict;
98
+ Object colorSpaceDict;
99
+ Object patternDict;
100
+ Object shadingDict;
101
+ Object gStateDict;
102
+ GfxResources *next;
103
+ };
104
+
105
+ //------------------------------------------------------------------------
106
+ // Gfx
107
+ //------------------------------------------------------------------------
108
+
109
+ class Gfx {
110
+ public:
111
+
112
+ // Constructor for regular output.
113
+ Gfx(XRef *xrefA, OutputDev *outA, int pageNum, Dict *resDict,
114
+ double hDPI, double vDPI, PDFRectangle *box,
115
+ PDFRectangle *cropBox, int rotate,
116
+ GBool (*abortCheckCbkA)(void *data) = NULL,
117
+ void *abortCheckCbkDataA = NULL);
118
+
119
+ // Constructor for a sub-page object.
120
+ Gfx(XRef *xrefA, OutputDev *outA, Dict *resDict,
121
+ PDFRectangle *box, PDFRectangle *cropBox,
122
+ GBool (*abortCheckCbkA)(void *data) = NULL,
123
+ void *abortCheckCbkDataA = NULL);
124
+
125
+ ~Gfx();
126
+
127
+ // Interpret a stream or array of streams.
128
+ void display(Object *obj, GBool topLevel = gTrue);
129
+
130
+ // Display an annotation, given its appearance (a Form XObject),
131
+ // border style, and bounding box (in default user space).
132
+ void drawAnnot(Object *str, AnnotBorderStyle *borderStyle,
133
+ double xMin, double yMin, double xMax, double yMax);
134
+
135
+ // Save graphics state.
136
+ void saveState();
137
+
138
+ // Restore graphics state.
139
+ void restoreState();
140
+
141
+ // Get the current graphics state object.
142
+ GfxState *getState() { return state; }
143
+
144
+ private:
145
+
146
+ XRef *xref; // the xref table for this PDF file
147
+ OutputDev *out; // output device
148
+ GBool subPage; // is this a sub-page object?
149
+ GBool printCommands; // print the drawing commands (for debugging)
150
+ GfxResources *res; // resource stack
151
+ int updateLevel;
152
+
153
+ GfxState *state; // current graphics state
154
+ GBool fontChanged; // set if font or text matrix has changed
155
+ GfxClipType clip; // do a clip?
156
+ int ignoreUndef; // current BX/EX nesting level
157
+ double baseMatrix[6]; // default matrix for most recent
158
+ // page/form/pattern
159
+ int formDepth;
160
+
161
+ Parser *parser; // parser for page content stream(s)
162
+
163
+ GBool // callback to check for an abort
164
+ (*abortCheckCbk)(void *data);
165
+ void *abortCheckCbkData;
166
+
167
+ static Operator opTab[]; // table of operators
168
+
169
+ void go(GBool topLevel);
170
+ void execOp(Object *cmd, Object args[], int numArgs);
171
+ Operator *findOp(char *name);
172
+ GBool checkArg(Object *arg, TchkType type);
173
+ int getPos();
174
+
175
+ // graphics state operators
176
+ void opSave(Object args[], int numArgs);
177
+ void opRestore(Object args[], int numArgs);
178
+ void opConcat(Object args[], int numArgs);
179
+ void opSetDash(Object args[], int numArgs);
180
+ void opSetFlat(Object args[], int numArgs);
181
+ void opSetLineJoin(Object args[], int numArgs);
182
+ void opSetLineCap(Object args[], int numArgs);
183
+ void opSetMiterLimit(Object args[], int numArgs);
184
+ void opSetLineWidth(Object args[], int numArgs);
185
+ void opSetExtGState(Object args[], int numArgs);
186
+ void doSoftMask(Object *str, GBool alpha,
187
+ GfxColorSpace *blendingColorSpace,
188
+ GBool isolated, GBool knockout,
189
+ Function *transferFunc, GfxColor *backdropColor);
190
+ void opSetRenderingIntent(Object args[], int numArgs);
191
+
192
+ // color operators
193
+ void opSetFillGray(Object args[], int numArgs);
194
+ void opSetStrokeGray(Object args[], int numArgs);
195
+ void opSetFillCMYKColor(Object args[], int numArgs);
196
+ void opSetStrokeCMYKColor(Object args[], int numArgs);
197
+ void opSetFillRGBColor(Object args[], int numArgs);
198
+ void opSetStrokeRGBColor(Object args[], int numArgs);
199
+ void opSetFillColorSpace(Object args[], int numArgs);
200
+ void opSetStrokeColorSpace(Object args[], int numArgs);
201
+ void opSetFillColor(Object args[], int numArgs);
202
+ void opSetStrokeColor(Object args[], int numArgs);
203
+ void opSetFillColorN(Object args[], int numArgs);
204
+ void opSetStrokeColorN(Object args[], int numArgs);
205
+
206
+ // path segment operators
207
+ void opMoveTo(Object args[], int numArgs);
208
+ void opLineTo(Object args[], int numArgs);
209
+ void opCurveTo(Object args[], int numArgs);
210
+ void opCurveTo1(Object args[], int numArgs);
211
+ void opCurveTo2(Object args[], int numArgs);
212
+ void opRectangle(Object args[], int numArgs);
213
+ void opClosePath(Object args[], int numArgs);
214
+
215
+ // path painting operators
216
+ void opEndPath(Object args[], int numArgs);
217
+ void opStroke(Object args[], int numArgs);
218
+ void opCloseStroke(Object args[], int numArgs);
219
+ void opFill(Object args[], int numArgs);
220
+ void opEOFill(Object args[], int numArgs);
221
+ void opFillStroke(Object args[], int numArgs);
222
+ void opCloseFillStroke(Object args[], int numArgs);
223
+ void opEOFillStroke(Object args[], int numArgs);
224
+ void opCloseEOFillStroke(Object args[], int numArgs);
225
+ void doPatternFill(GBool eoFill);
226
+ void doPatternStroke();
227
+ void doTilingPatternFill(GfxTilingPattern *tPat,
228
+ GBool stroke, GBool eoFill);
229
+ void doShadingPatternFill(GfxShadingPattern *sPat,
230
+ GBool stroke, GBool eoFill);
231
+ void opShFill(Object args[], int numArgs);
232
+ void doFunctionShFill(GfxFunctionShading *shading);
233
+ void doFunctionShFill1(GfxFunctionShading *shading,
234
+ double x0, double y0,
235
+ double x1, double y1,
236
+ GfxColor *colors, int depth);
237
+ void doAxialShFill(GfxAxialShading *shading);
238
+ void doRadialShFill(GfxRadialShading *shading);
239
+ void doGouraudTriangleShFill(GfxGouraudTriangleShading *shading);
240
+ void gouraudFillTriangle(double x0, double y0, GfxColor *color0,
241
+ double x1, double y1, GfxColor *color1,
242
+ double x2, double y2, GfxColor *color2,
243
+ int nComps, int depth);
244
+ void doPatchMeshShFill(GfxPatchMeshShading *shading);
245
+ void fillPatch(GfxPatch *patch, int nComps, int depth);
246
+ void doEndPath();
247
+
248
+ // path clipping operators
249
+ void opClip(Object args[], int numArgs);
250
+ void opEOClip(Object args[], int numArgs);
251
+
252
+ // text object operators
253
+ void opBeginText(Object args[], int numArgs);
254
+ void opEndText(Object args[], int numArgs);
255
+
256
+ // text state operators
257
+ void opSetCharSpacing(Object args[], int numArgs);
258
+ void opSetFont(Object args[], int numArgs);
259
+ void opSetTextLeading(Object args[], int numArgs);
260
+ void opSetTextRender(Object args[], int numArgs);
261
+ void opSetTextRise(Object args[], int numArgs);
262
+ void opSetWordSpacing(Object args[], int numArgs);
263
+ void opSetHorizScaling(Object args[], int numArgs);
264
+
265
+ // text positioning operators
266
+ void opTextMove(Object args[], int numArgs);
267
+ void opTextMoveSet(Object args[], int numArgs);
268
+ void opSetTextMatrix(Object args[], int numArgs);
269
+ void opTextNextLine(Object args[], int numArgs);
270
+
271
+ // text string operators
272
+ void opShowText(Object args[], int numArgs);
273
+ void opMoveShowText(Object args[], int numArgs);
274
+ void opMoveSetShowText(Object args[], int numArgs);
275
+ void opShowSpaceText(Object args[], int numArgs);
276
+ void doShowText(GString *s);
277
+
278
+ // XObject operators
279
+ void opXObject(Object args[], int numArgs);
280
+ void doImage(Object *ref, Stream *str, GBool inlineImg);
281
+ void doForm(Object *str);
282
+ void doForm1(Object *str, Dict *resDict, double *matrix, double *bbox,
283
+ GBool transpGroup = gFalse, GBool softMask = gFalse,
284
+ GfxColorSpace *blendingColorSpace = NULL,
285
+ GBool isolated = gFalse, GBool knockout = gFalse,
286
+ GBool alpha = gFalse, Function *transferFunc = NULL,
287
+ GfxColor *backdropColor = NULL);
288
+
289
+ // in-line image operators
290
+ void opBeginImage(Object args[], int numArgs);
291
+ Stream *buildImageStream();
292
+ void opImageData(Object args[], int numArgs);
293
+ void opEndImage(Object args[], int numArgs);
294
+
295
+ // type 3 font operators
296
+ void opSetCharWidth(Object args[], int numArgs);
297
+ void opSetCacheDevice(Object args[], int numArgs);
298
+
299
+ // compatibility operators
300
+ void opBeginIgnoreUndef(Object args[], int numArgs);
301
+ void opEndIgnoreUndef(Object args[], int numArgs);
302
+
303
+ // marked content operators
304
+ void opBeginMarkedContent(Object args[], int numArgs);
305
+ void opEndMarkedContent(Object args[], int numArgs);
306
+ void opMarkPoint(Object args[], int numArgs);
307
+
308
+ void pushResources(Dict *resDict);
309
+ void popResources();
310
+ };
311
+
312
+ #endif
Binary file
@@ -0,0 +1,1568 @@
1
+ //========================================================================
2
+ //
3
+ // GfxFont.cc
4
+ //
5
+ // Copyright 1996-2003 Glyph & Cog, LLC
6
+ //
7
+ //========================================================================
8
+
9
+ #include <aconf.h>
10
+
11
+ #ifdef USE_GCC_PRAGMAS
12
+ #pragma implementation
13
+ #endif
14
+
15
+ #include <stdio.h>
16
+ #include <stdlib.h>
17
+ #include <string.h>
18
+ #include <ctype.h>
19
+ #include "gmem.h"
20
+ #include "Error.h"
21
+ #include "Object.h"
22
+ #include "Dict.h"
23
+ #include "GlobalParams.h"
24
+ #include "CMap.h"
25
+ #include "CharCodeToUnicode.h"
26
+ #include "FontEncodingTables.h"
27
+ #include "BuiltinFontTables.h"
28
+ #include "FoFiType1.h"
29
+ #include "FoFiType1C.h"
30
+ #include "FoFiTrueType.h"
31
+ #include "GfxFont.h"
32
+
33
+ //------------------------------------------------------------------------
34
+
35
+ struct StdFontMapEntry {
36
+ char *altName;
37
+ char *properName;
38
+ };
39
+
40
+ // Acrobat 4.0 and earlier substituted Base14-compatible fonts without
41
+ // providing Widths and a FontDescriptor, so we munge the names into
42
+ // the proper Base14 names. This table is from implementation note 44
43
+ // in the PDF 1.4 spec, with some additions based on empirical
44
+ // evidence.
45
+ static StdFontMapEntry stdFontMap[] = {
46
+ { "Arial", "Helvetica" },
47
+ { "Arial,Bold", "Helvetica-Bold" },
48
+ { "Arial,BoldItalic", "Helvetica-BoldOblique" },
49
+ { "Arial,Italic", "Helvetica-Oblique" },
50
+ { "Arial-Bold", "Helvetica-Bold" },
51
+ { "Arial-BoldItalic", "Helvetica-BoldOblique" },
52
+ { "Arial-BoldItalicMT", "Helvetica-BoldOblique" },
53
+ { "Arial-BoldMT", "Helvetica-Bold" },
54
+ { "Arial-Italic", "Helvetica-Oblique" },
55
+ { "Arial-ItalicMT", "Helvetica-Oblique" },
56
+ { "ArialMT", "Helvetica" },
57
+ { "Courier,Bold", "Courier-Bold" },
58
+ { "Courier,BoldItalic", "Courier-BoldOblique" },
59
+ { "Courier,Italic", "Courier-Oblique" },
60
+ { "CourierNew", "Courier" },
61
+ { "CourierNew,Bold", "Courier-Bold" },
62
+ { "CourierNew,BoldItalic", "Courier-BoldOblique" },
63
+ { "CourierNew,Italic", "Courier-Oblique" },
64
+ { "CourierNew-Bold", "Courier-Bold" },
65
+ { "CourierNew-BoldItalic", "Courier-BoldOblique" },
66
+ { "CourierNew-Italic", "Courier-Oblique" },
67
+ { "CourierNewPS-BoldItalicMT", "Courier-BoldOblique" },
68
+ { "CourierNewPS-BoldMT", "Courier-Bold" },
69
+ { "CourierNewPS-ItalicMT", "Courier-Oblique" },
70
+ { "CourierNewPSMT", "Courier" },
71
+ { "Helvetica,Bold", "Helvetica-Bold" },
72
+ { "Helvetica,BoldItalic", "Helvetica-BoldOblique" },
73
+ { "Helvetica,Italic", "Helvetica-Oblique" },
74
+ { "Helvetica-BoldItalic", "Helvetica-BoldOblique" },
75
+ { "Helvetica-Italic", "Helvetica-Oblique" },
76
+ { "Symbol,Bold", "Symbol" },
77
+ { "Symbol,BoldItalic", "Symbol" },
78
+ { "Symbol,Italic", "Symbol" },
79
+ { "TimesNewRoman", "Times-Roman" },
80
+ { "TimesNewRoman,Bold", "Times-Bold" },
81
+ { "TimesNewRoman,BoldItalic", "Times-BoldItalic" },
82
+ { "TimesNewRoman,Italic", "Times-Italic" },
83
+ { "TimesNewRoman-Bold", "Times-Bold" },
84
+ { "TimesNewRoman-BoldItalic", "Times-BoldItalic" },
85
+ { "TimesNewRoman-Italic", "Times-Italic" },
86
+ { "TimesNewRomanPS", "Times-Roman" },
87
+ { "TimesNewRomanPS-Bold", "Times-Bold" },
88
+ { "TimesNewRomanPS-BoldItalic", "Times-BoldItalic" },
89
+ { "TimesNewRomanPS-BoldItalicMT", "Times-BoldItalic" },
90
+ { "TimesNewRomanPS-BoldMT", "Times-Bold" },
91
+ { "TimesNewRomanPS-Italic", "Times-Italic" },
92
+ { "TimesNewRomanPS-ItalicMT", "Times-Italic" },
93
+ { "TimesNewRomanPSMT", "Times-Roman" },
94
+ { "TimesNewRomanPSMT,Bold", "Times-Bold" },
95
+ { "TimesNewRomanPSMT,BoldItalic", "Times-BoldItalic" },
96
+ { "TimesNewRomanPSMT,Italic", "Times-Italic" }
97
+ };
98
+
99
+ //------------------------------------------------------------------------
100
+ // GfxFont
101
+ //------------------------------------------------------------------------
102
+
103
+ GfxFont *GfxFont::makeFont(XRef *xref, char *tagA, Ref idA, Dict *fontDict) {
104
+ GString *nameA;
105
+ GfxFont *font;
106
+ Object obj1;
107
+
108
+ // get base font name
109
+ nameA = NULL;
110
+ fontDict->lookup("BaseFont", &obj1);
111
+ if (obj1.isName()) {
112
+ nameA = new GString(obj1.getName());
113
+ }
114
+ obj1.free();
115
+
116
+ // get font type
117
+ font = NULL;
118
+ fontDict->lookup("Subtype", &obj1);
119
+ if (obj1.isName("Type1") || obj1.isName("MMType1")) {
120
+ font = new Gfx8BitFont(xref, tagA, idA, nameA, fontType1, fontDict);
121
+ } else if (obj1.isName("Type1C")) {
122
+ font = new Gfx8BitFont(xref, tagA, idA, nameA, fontType1C, fontDict);
123
+ } else if (obj1.isName("Type3")) {
124
+ font = new Gfx8BitFont(xref, tagA, idA, nameA, fontType3, fontDict);
125
+ } else if (obj1.isName("TrueType")) {
126
+ font = new Gfx8BitFont(xref, tagA, idA, nameA, fontTrueType, fontDict);
127
+ } else if (obj1.isName("Type0")) {
128
+ font = new GfxCIDFont(xref, tagA, idA, nameA, fontDict);
129
+ } else {
130
+ error(-1, "Unknown font type: '%s'",
131
+ obj1.isName() ? obj1.getName() : "???");
132
+ font = new Gfx8BitFont(xref, tagA, idA, nameA, fontUnknownType, fontDict);
133
+ }
134
+ obj1.free();
135
+
136
+ return font;
137
+ }
138
+
139
+ GfxFont::GfxFont(char *tagA, Ref idA, GString *nameA) {
140
+ ok = gFalse;
141
+ tag = new GString(tagA);
142
+ id = idA;
143
+ name = nameA;
144
+ origName = nameA;
145
+ embFontName = NULL;
146
+ extFontFile = NULL;
147
+ }
148
+
149
+ GfxFont::~GfxFont() {
150
+ delete tag;
151
+ if (origName && origName != name) {
152
+ delete origName;
153
+ }
154
+ if (name) {
155
+ delete name;
156
+ }
157
+ if (embFontName) {
158
+ delete embFontName;
159
+ }
160
+ if (extFontFile) {
161
+ delete extFontFile;
162
+ }
163
+ }
164
+
165
+ void GfxFont::readFontDescriptor(XRef *xref, Dict *fontDict) {
166
+ Object obj1, obj2, obj3, obj4;
167
+ double t;
168
+ int i;
169
+
170
+ // assume Times-Roman by default (for substitution purposes)
171
+ flags = fontSerif;
172
+
173
+ embFontID.num = -1;
174
+ embFontID.gen = -1;
175
+ missingWidth = 0;
176
+
177
+ if (fontDict->lookup("FontDescriptor", &obj1)->isDict()) {
178
+
179
+ // get flags
180
+ if (obj1.dictLookup("Flags", &obj2)->isInt()) {
181
+ flags = obj2.getInt();
182
+ }
183
+ obj2.free();
184
+
185
+ // get name
186
+ obj1.dictLookup("FontName", &obj2);
187
+ if (obj2.isName()) {
188
+ embFontName = new GString(obj2.getName());
189
+ }
190
+ obj2.free();
191
+
192
+ // look for embedded font file
193
+ if (obj1.dictLookupNF("FontFile", &obj2)->isRef()) {
194
+ embFontID = obj2.getRef();
195
+ if (type != fontType1) {
196
+ error(-1, "Mismatch between font type and embedded font file");
197
+ type = fontType1;
198
+ }
199
+ }
200
+ obj2.free();
201
+ if (embFontID.num == -1 &&
202
+ obj1.dictLookupNF("FontFile2", &obj2)->isRef()) {
203
+ embFontID = obj2.getRef();
204
+ if (type != fontTrueType && type != fontCIDType2) {
205
+ error(-1, "Mismatch between font type and embedded font file");
206
+ type = type == fontCIDType0 ? fontCIDType2 : fontTrueType;
207
+ }
208
+ }
209
+ obj2.free();
210
+ if (embFontID.num == -1 &&
211
+ obj1.dictLookupNF("FontFile3", &obj2)->isRef()) {
212
+ if (obj2.fetch(xref, &obj3)->isStream()) {
213
+ obj3.streamGetDict()->lookup("Subtype", &obj4);
214
+ if (obj4.isName("Type1")) {
215
+ embFontID = obj2.getRef();
216
+ if (type != fontType1) {
217
+ error(-1, "Mismatch between font type and embedded font file");
218
+ type = fontType1;
219
+ }
220
+ } else if (obj4.isName("Type1C")) {
221
+ embFontID = obj2.getRef();
222
+ if (type != fontType1 && type != fontType1C) {
223
+ error(-1, "Mismatch between font type and embedded font file");
224
+ }
225
+ type = fontType1C;
226
+ } else if (obj4.isName("TrueType")) {
227
+ embFontID = obj2.getRef();
228
+ if (type != fontTrueType) {
229
+ error(-1, "Mismatch between font type and embedded font file");
230
+ type = fontTrueType;
231
+ }
232
+ } else if (obj4.isName("CIDFontType0C")) {
233
+ embFontID = obj2.getRef();
234
+ if (type != fontCIDType0) {
235
+ error(-1, "Mismatch between font type and embedded font file");
236
+ }
237
+ type = fontCIDType0C;
238
+ } else if (obj4.isName("OpenType")) {
239
+ embFontID = obj2.getRef();
240
+ if (type == fontTrueType) {
241
+ type = fontTrueTypeOT;
242
+ } else if (type == fontType1) {
243
+ type = fontType1COT;
244
+ } else if (type == fontCIDType0) {
245
+ type = fontCIDType0COT;
246
+ } else if (type == fontCIDType2) {
247
+ type = fontCIDType2OT;
248
+ } else {
249
+ error(-1, "Mismatch between font type and embedded font file");
250
+ }
251
+ } else {
252
+ error(-1, "Unknown embedded font type '%s'",
253
+ obj4.isName() ? obj4.getName() : "???");
254
+ }
255
+ obj4.free();
256
+ }
257
+ obj3.free();
258
+ }
259
+ obj2.free();
260
+
261
+ // look for MissingWidth
262
+ obj1.dictLookup("MissingWidth", &obj2);
263
+ if (obj2.isNum()) {
264
+ missingWidth = obj2.getNum();
265
+ }
266
+ obj2.free();
267
+
268
+ // get Ascent and Descent
269
+ obj1.dictLookup("Ascent", &obj2);
270
+ if (obj2.isNum()) {
271
+ t = 0.001 * obj2.getNum();
272
+ // some broken font descriptors set ascent and descent to 0
273
+ if (t != 0) {
274
+ ascent = t;
275
+ }
276
+ }
277
+ obj2.free();
278
+ obj1.dictLookup("Descent", &obj2);
279
+ if (obj2.isNum()) {
280
+ t = 0.001 * obj2.getNum();
281
+ // some broken font descriptors set ascent and descent to 0
282
+ if (t != 0) {
283
+ descent = t;
284
+ }
285
+ // some broken font descriptors specify a positive descent
286
+ if (descent > 0) {
287
+ descent = -descent;
288
+ }
289
+ }
290
+ obj2.free();
291
+
292
+ // font FontBBox
293
+ if (obj1.dictLookup("FontBBox", &obj2)->isArray()) {
294
+ for (i = 0; i < 4 && i < obj2.arrayGetLength(); ++i) {
295
+ if (obj2.arrayGet(i, &obj3)->isNum()) {
296
+ fontBBox[i] = 0.001 * obj3.getNum();
297
+ }
298
+ obj3.free();
299
+ }
300
+ }
301
+ obj2.free();
302
+
303
+ }
304
+ obj1.free();
305
+ }
306
+
307
+ CharCodeToUnicode *GfxFont::readToUnicodeCMap(Dict *fontDict, int nBits,
308
+ CharCodeToUnicode *ctu) {
309
+ GString *buf;
310
+ Object obj1;
311
+ int c;
312
+
313
+ if (!fontDict->lookup("ToUnicode", &obj1)->isStream()) {
314
+ obj1.free();
315
+ return NULL;
316
+ }
317
+ buf = new GString();
318
+ obj1.streamReset();
319
+ while ((c = obj1.streamGetChar()) != EOF) {
320
+ buf->append(c);
321
+ }
322
+ obj1.streamClose();
323
+ obj1.free();
324
+ if (ctu) {
325
+ ctu->mergeCMap(buf, nBits);
326
+ } else {
327
+ ctu = CharCodeToUnicode::parseCMap(buf, nBits);
328
+ }
329
+ delete buf;
330
+ return ctu;
331
+ }
332
+
333
+ void GfxFont::findExtFontFile() {
334
+ static char *type1Exts[] = { ".pfa", ".pfb", ".ps", "", NULL };
335
+ static char *ttExts[] = { ".ttf", NULL };
336
+
337
+ if (name) {
338
+ if (type == fontType1) {
339
+ extFontFile = globalParams->findFontFile(name, type1Exts);
340
+ } else if (type == fontTrueType) {
341
+ extFontFile = globalParams->findFontFile(name, ttExts);
342
+ }
343
+ }
344
+ }
345
+
346
+ char *GfxFont::readExtFontFile(int *len) {
347
+ FILE *f;
348
+ char *buf;
349
+
350
+ if (!(f = fopen(extFontFile->getCString(), "rb"))) {
351
+ error(-1, "External font file '%s' vanished", extFontFile->getCString());
352
+ return NULL;
353
+ }
354
+ fseek(f, 0, SEEK_END);
355
+ *len = (int)ftell(f);
356
+ fseek(f, 0, SEEK_SET);
357
+ buf = (char *)gmalloc(*len);
358
+ if ((int)fread(buf, 1, *len, f) != *len) {
359
+ error(-1, "Error reading external font file '%s'",
360
+ extFontFile->getCString());
361
+ }
362
+ fclose(f);
363
+ return buf;
364
+ }
365
+
366
+ char *GfxFont::readEmbFontFile(XRef *xref, int *len) {
367
+ char *buf;
368
+ Object obj1, obj2;
369
+ Stream *str;
370
+ int c;
371
+ int size, i;
372
+
373
+ obj1.initRef(embFontID.num, embFontID.gen);
374
+ obj1.fetch(xref, &obj2);
375
+ if (!obj2.isStream()) {
376
+ error(-1, "Embedded font file is not a stream");
377
+ obj2.free();
378
+ obj1.free();
379
+ embFontID.num = -1;
380
+ return NULL;
381
+ }
382
+ str = obj2.getStream();
383
+
384
+ buf = NULL;
385
+ i = size = 0;
386
+ str->reset();
387
+ while ((c = str->getChar()) != EOF) {
388
+ if (i == size) {
389
+ size += 4096;
390
+ buf = (char *)grealloc(buf, size);
391
+ }
392
+ buf[i++] = c;
393
+ }
394
+ *len = i;
395
+ str->close();
396
+
397
+ obj2.free();
398
+ obj1.free();
399
+
400
+ return buf;
401
+ }
402
+
403
+ //------------------------------------------------------------------------
404
+ // Gfx8BitFont
405
+ //------------------------------------------------------------------------
406
+
407
+ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
408
+ GfxFontType typeA, Dict *fontDict):
409
+ GfxFont(tagA, idA, nameA)
410
+ {
411
+ GString *name2;
412
+ BuiltinFont *builtinFont;
413
+ char **baseEnc;
414
+ GBool baseEncFromFontFile;
415
+ char *buf;
416
+ int len;
417
+ FoFiType1 *ffT1;
418
+ FoFiType1C *ffT1C;
419
+ int code, code2;
420
+ char *charName;
421
+ GBool missing, hex;
422
+ Unicode toUnicode[256];
423
+ CharCodeToUnicode *utu, *ctu2;
424
+ Unicode uBuf[8];
425
+ double mul;
426
+ int firstChar, lastChar;
427
+ Gushort w;
428
+ Object obj1, obj2, obj3;
429
+ int n, i, a, b, m;
430
+
431
+ type = typeA;
432
+ ctu = NULL;
433
+
434
+ // do font name substitution for various aliases of the Base 14 font
435
+ // names
436
+ if (name) {
437
+ name2 = name->copy();
438
+ i = 0;
439
+ while (i < name2->getLength()) {
440
+ if (name2->getChar(i) == ' ') {
441
+ name2->del(i);
442
+ } else {
443
+ ++i;
444
+ }
445
+ }
446
+ a = 0;
447
+ b = sizeof(stdFontMap) / sizeof(StdFontMapEntry);
448
+ // invariant: stdFontMap[a].altName <= name2 < stdFontMap[b].altName
449
+ while (b - a > 1) {
450
+ m = (a + b) / 2;
451
+ if (name2->cmp(stdFontMap[m].altName) >= 0) {
452
+ a = m;
453
+ } else {
454
+ b = m;
455
+ }
456
+ }
457
+ if (!name2->cmp(stdFontMap[a].altName)) {
458
+ name = new GString(stdFontMap[a].properName);
459
+ }
460
+ delete name2;
461
+ }
462
+
463
+ // is it a built-in font?
464
+ builtinFont = NULL;
465
+ if (name) {
466
+ for (i = 0; i < nBuiltinFonts; ++i) {
467
+ if (!name->cmp(builtinFonts[i].name)) {
468
+ builtinFont = &builtinFonts[i];
469
+ break;
470
+ }
471
+ }
472
+ }
473
+
474
+ // default ascent/descent values
475
+ if (builtinFont) {
476
+ ascent = 0.001 * builtinFont->ascent;
477
+ descent = 0.001 * builtinFont->descent;
478
+ fontBBox[0] = 0.001 * builtinFont->bbox[0];
479
+ fontBBox[1] = 0.001 * builtinFont->bbox[1];
480
+ fontBBox[2] = 0.001 * builtinFont->bbox[2];
481
+ fontBBox[3] = 0.001 * builtinFont->bbox[3];
482
+ } else {
483
+ ascent = 0.95;
484
+ descent = -0.35;
485
+ fontBBox[0] = fontBBox[1] = fontBBox[2] = fontBBox[3] = 0;
486
+ }
487
+
488
+ // get info from font descriptor
489
+ readFontDescriptor(xref, fontDict);
490
+
491
+ // for non-embedded fonts, don't trust the ascent/descent/bbox
492
+ // values from the font descriptor
493
+ if (builtinFont && embFontID.num < 0) {
494
+ ascent = 0.001 * builtinFont->ascent;
495
+ descent = 0.001 * builtinFont->descent;
496
+ fontBBox[0] = 0.001 * builtinFont->bbox[0];
497
+ fontBBox[1] = 0.001 * builtinFont->bbox[1];
498
+ fontBBox[2] = 0.001 * builtinFont->bbox[2];
499
+ fontBBox[3] = 0.001 * builtinFont->bbox[3];
500
+ }
501
+
502
+ // look for an external font file
503
+ findExtFontFile();
504
+
505
+ // get font matrix
506
+ fontMat[0] = fontMat[3] = 1;
507
+ fontMat[1] = fontMat[2] = fontMat[4] = fontMat[5] = 0;
508
+ if (fontDict->lookup("FontMatrix", &obj1)->isArray()) {
509
+ for (i = 0; i < 6 && i < obj1.arrayGetLength(); ++i) {
510
+ if (obj1.arrayGet(i, &obj2)->isNum()) {
511
+ fontMat[i] = obj2.getNum();
512
+ }
513
+ obj2.free();
514
+ }
515
+ }
516
+ obj1.free();
517
+
518
+ // get Type 3 bounding box, font definition, and resources
519
+ if (type == fontType3) {
520
+ if (fontDict->lookup("FontBBox", &obj1)->isArray()) {
521
+ for (i = 0; i < 4 && i < obj1.arrayGetLength(); ++i) {
522
+ if (obj1.arrayGet(i, &obj2)->isNum()) {
523
+ fontBBox[i] = obj2.getNum();
524
+ }
525
+ obj2.free();
526
+ }
527
+ }
528
+ obj1.free();
529
+ if (!fontDict->lookup("CharProcs", &charProcs)->isDict()) {
530
+ error(-1, "Missing or invalid CharProcs dictionary in Type 3 font");
531
+ charProcs.free();
532
+ }
533
+ if (!fontDict->lookup("Resources", &resources)->isDict()) {
534
+ resources.free();
535
+ }
536
+ }
537
+
538
+ //----- build the font encoding -----
539
+
540
+ // Encodings start with a base encoding, which can come from
541
+ // (in order of priority):
542
+ // 1. FontDict.Encoding or FontDict.Encoding.BaseEncoding
543
+ // - MacRoman / MacExpert / WinAnsi / Standard
544
+ // 2. embedded or external font file
545
+ // 3. default:
546
+ // - builtin --> builtin encoding
547
+ // - TrueType --> WinAnsiEncoding
548
+ // - others --> StandardEncoding
549
+ // and then add a list of differences (if any) from
550
+ // FontDict.Encoding.Differences.
551
+
552
+ // check FontDict for base encoding
553
+ hasEncoding = gFalse;
554
+ usesMacRomanEnc = gFalse;
555
+ baseEnc = NULL;
556
+ baseEncFromFontFile = gFalse;
557
+ fontDict->lookup("Encoding", &obj1);
558
+ if (obj1.isDict()) {
559
+ obj1.dictLookup("BaseEncoding", &obj2);
560
+ if (obj2.isName("MacRomanEncoding")) {
561
+ hasEncoding = gTrue;
562
+ usesMacRomanEnc = gTrue;
563
+ baseEnc = macRomanEncoding;
564
+ } else if (obj2.isName("MacExpertEncoding")) {
565
+ hasEncoding = gTrue;
566
+ baseEnc = macExpertEncoding;
567
+ } else if (obj2.isName("WinAnsiEncoding")) {
568
+ hasEncoding = gTrue;
569
+ baseEnc = winAnsiEncoding;
570
+ }
571
+ obj2.free();
572
+ } else if (obj1.isName("MacRomanEncoding")) {
573
+ hasEncoding = gTrue;
574
+ usesMacRomanEnc = gTrue;
575
+ baseEnc = macRomanEncoding;
576
+ } else if (obj1.isName("MacExpertEncoding")) {
577
+ hasEncoding = gTrue;
578
+ baseEnc = macExpertEncoding;
579
+ } else if (obj1.isName("WinAnsiEncoding")) {
580
+ hasEncoding = gTrue;
581
+ baseEnc = winAnsiEncoding;
582
+ }
583
+
584
+ // check embedded or external font file for base encoding
585
+ // (only for Type 1 fonts - trying to get an encoding out of a
586
+ // TrueType font is a losing proposition)
587
+ ffT1 = NULL;
588
+ ffT1C = NULL;
589
+ buf = NULL;
590
+ if (type == fontType1 && (extFontFile || embFontID.num >= 0)) {
591
+ if (extFontFile) {
592
+ ffT1 = FoFiType1::load(extFontFile->getCString());
593
+ } else {
594
+ buf = readEmbFontFile(xref, &len);
595
+ ffT1 = FoFiType1::make(buf, len);
596
+ }
597
+ if (ffT1) {
598
+ if (ffT1->getName()) {
599
+ if (embFontName) {
600
+ delete embFontName;
601
+ }
602
+ embFontName = new GString(ffT1->getName());
603
+ }
604
+ if (!baseEnc) {
605
+ baseEnc = ffT1->getEncoding();
606
+ baseEncFromFontFile = gTrue;
607
+ }
608
+ }
609
+ } else if (type == fontType1C && (extFontFile || embFontID.num >= 0)) {
610
+ if (extFontFile) {
611
+ ffT1C = FoFiType1C::load(extFontFile->getCString());
612
+ } else {
613
+ buf = readEmbFontFile(xref, &len);
614
+ ffT1C = FoFiType1C::make(buf, len);
615
+ }
616
+ if (ffT1C) {
617
+ if (ffT1C->getName()) {
618
+ if (embFontName) {
619
+ delete embFontName;
620
+ }
621
+ embFontName = new GString(ffT1C->getName());
622
+ }
623
+ if (!baseEnc) {
624
+ baseEnc = ffT1C->getEncoding();
625
+ baseEncFromFontFile = gTrue;
626
+ }
627
+ }
628
+ }
629
+ if (buf) {
630
+ gfree(buf);
631
+ }
632
+
633
+ // get default base encoding
634
+ if (!baseEnc) {
635
+ if (builtinFont && embFontID.num < 0) {
636
+ baseEnc = builtinFont->defaultBaseEnc;
637
+ hasEncoding = gTrue;
638
+ } else if (type == fontTrueType) {
639
+ baseEnc = winAnsiEncoding;
640
+ } else {
641
+ baseEnc = standardEncoding;
642
+ }
643
+ }
644
+
645
+ // copy the base encoding
646
+ for (i = 0; i < 256; ++i) {
647
+ enc[i] = baseEnc[i];
648
+ if ((encFree[i] = baseEncFromFontFile) && enc[i]) {
649
+ enc[i] = copyString(baseEnc[i]);
650
+ }
651
+ }
652
+
653
+ // some Type 1C font files have empty encodings, which can break the
654
+ // T1C->T1 conversion (since the 'seac' operator depends on having
655
+ // the accents in the encoding), so we fill in any gaps from
656
+ // StandardEncoding
657
+ if (type == fontType1C && (extFontFile || embFontID.num >= 0) &&
658
+ baseEncFromFontFile) {
659
+ for (i = 0; i < 256; ++i) {
660
+ if (!enc[i] && standardEncoding[i]) {
661
+ enc[i] = standardEncoding[i];
662
+ encFree[i] = gFalse;
663
+ }
664
+ }
665
+ }
666
+
667
+ // merge differences into encoding
668
+ if (obj1.isDict()) {
669
+ obj1.dictLookup("Differences", &obj2);
670
+ if (obj2.isArray()) {
671
+ hasEncoding = gTrue;
672
+ code = 0;
673
+ for (i = 0; i < obj2.arrayGetLength(); ++i) {
674
+ obj2.arrayGet(i, &obj3);
675
+ if (obj3.isInt()) {
676
+ code = obj3.getInt();
677
+ } else if (obj3.isName()) {
678
+ if (code >= 0 && code < 256) {
679
+ if (encFree[code]) {
680
+ gfree(enc[code]);
681
+ }
682
+ enc[code] = copyString(obj3.getName());
683
+ encFree[code] = gTrue;
684
+ }
685
+ ++code;
686
+ } else {
687
+ error(-1, "Wrong type in font encoding resource differences (%s)",
688
+ obj3.getTypeName());
689
+ }
690
+ obj3.free();
691
+ }
692
+ }
693
+ obj2.free();
694
+ }
695
+ obj1.free();
696
+ if (ffT1) {
697
+ delete ffT1;
698
+ }
699
+ if (ffT1C) {
700
+ delete ffT1C;
701
+ }
702
+
703
+ //----- build the mapping to Unicode -----
704
+
705
+ // pass 1: use the name-to-Unicode mapping table
706
+ missing = hex = gFalse;
707
+ for (code = 0; code < 256; ++code) {
708
+ if ((charName = enc[code])) {
709
+ if (!(toUnicode[code] = globalParams->mapNameToUnicode(charName)) &&
710
+ strcmp(charName, ".notdef")) {
711
+ // if it wasn't in the name-to-Unicode table, check for a
712
+ // name that looks like 'Axx' or 'xx', where 'A' is any letter
713
+ // and 'xx' is two hex digits
714
+ if ((strlen(charName) == 3 &&
715
+ isalpha(charName[0]) &&
716
+ isxdigit(charName[1]) && isxdigit(charName[2]) &&
717
+ ((charName[1] >= 'a' && charName[1] <= 'f') ||
718
+ (charName[1] >= 'A' && charName[1] <= 'F') ||
719
+ (charName[2] >= 'a' && charName[2] <= 'f') ||
720
+ (charName[2] >= 'A' && charName[2] <= 'F'))) ||
721
+ (strlen(charName) == 2 &&
722
+ isxdigit(charName[0]) && isxdigit(charName[1]) &&
723
+ ((charName[0] >= 'a' && charName[0] <= 'f') ||
724
+ (charName[0] >= 'A' && charName[0] <= 'F') ||
725
+ (charName[1] >= 'a' && charName[1] <= 'f') ||
726
+ (charName[1] >= 'A' && charName[1] <= 'F')))) {
727
+ hex = gTrue;
728
+ }
729
+ missing = gTrue;
730
+ }
731
+ } else {
732
+ toUnicode[code] = 0;
733
+ }
734
+ }
735
+
736
+ // pass 2: try to fill in the missing chars, looking for names of
737
+ // the form 'Axx', 'xx', 'Ann', 'ABnn', or 'nn', where 'A' and 'B'
738
+ // are any letters, 'xx' is two hex digits, and 'nn' is 2-4
739
+ // decimal digits
740
+ if (missing && globalParams->getMapNumericCharNames()) {
741
+ for (code = 0; code < 256; ++code) {
742
+ if ((charName = enc[code]) && !toUnicode[code] &&
743
+ strcmp(charName, ".notdef")) {
744
+ n = strlen(charName);
745
+ code2 = -1;
746
+ if (hex && n == 3 && isalpha(charName[0]) &&
747
+ isxdigit(charName[1]) && isxdigit(charName[2])) {
748
+ sscanf(charName+1, "%x", &code2);
749
+ } else if (hex && n == 2 &&
750
+ isxdigit(charName[0]) && isxdigit(charName[1])) {
751
+ sscanf(charName, "%x", &code2);
752
+ } else if (!hex && n >= 2 && n <= 4 &&
753
+ isdigit(charName[0]) && isdigit(charName[1])) {
754
+ code2 = atoi(charName);
755
+ } else if (n >= 3 && n <= 5 &&
756
+ isdigit(charName[1]) && isdigit(charName[2])) {
757
+ code2 = atoi(charName+1);
758
+ } else if (n >= 4 && n <= 6 &&
759
+ isdigit(charName[2]) && isdigit(charName[3])) {
760
+ code2 = atoi(charName+2);
761
+ }
762
+ if (code2 >= 0 && code2 <= 0xff) {
763
+ toUnicode[code] = (Unicode)code2;
764
+ }
765
+ }
766
+ }
767
+
768
+ // if the 'mapUnknownCharNames' flag is set, do a simple pass-through
769
+ // mapping for unknown character names
770
+ } else if (missing && globalParams->getMapUnknownCharNames()) {
771
+ for (code = 0; code < 256; ++code) {
772
+ if (!toUnicode[code]) {
773
+ toUnicode[code] = code;
774
+ }
775
+ }
776
+ }
777
+
778
+ // construct the char code -> Unicode mapping object
779
+ ctu = CharCodeToUnicode::make8BitToUnicode(toUnicode);
780
+
781
+ // merge in a ToUnicode CMap, if there is one -- this overwrites
782
+ // existing entries in ctu, i.e., the ToUnicode CMap takes
783
+ // precedence, but the other encoding info is allowed to fill in any
784
+ // holes
785
+ readToUnicodeCMap(fontDict, 8, ctu);
786
+
787
+ // look for a Unicode-to-Unicode mapping
788
+ if (name && (utu = globalParams->getUnicodeToUnicode(name))) {
789
+ for (i = 0; i < 256; ++i) {
790
+ toUnicode[i] = 0;
791
+ }
792
+ ctu2 = CharCodeToUnicode::make8BitToUnicode(toUnicode);
793
+ for (i = 0; i < 256; ++i) {
794
+ n = ctu->mapToUnicode((CharCode)i, uBuf, 8);
795
+ if (n >= 1) {
796
+ n = utu->mapToUnicode((CharCode)uBuf[0], uBuf, 8);
797
+ if (n >= 1) {
798
+ ctu2->setMapping((CharCode)i, uBuf, n);
799
+ }
800
+ }
801
+ }
802
+ utu->decRefCnt();
803
+ delete ctu;
804
+ ctu = ctu2;
805
+ }
806
+
807
+ //----- get the character widths -----
808
+
809
+ // initialize all widths
810
+ for (code = 0; code < 256; ++code) {
811
+ widths[code] = missingWidth * 0.001;
812
+ }
813
+
814
+ // use widths from font dict, if present
815
+ fontDict->lookup("FirstChar", &obj1);
816
+ firstChar = obj1.isInt() ? obj1.getInt() : 0;
817
+ obj1.free();
818
+ if (firstChar < 0 || firstChar > 255) {
819
+ firstChar = 0;
820
+ }
821
+ fontDict->lookup("LastChar", &obj1);
822
+ lastChar = obj1.isInt() ? obj1.getInt() : 255;
823
+ obj1.free();
824
+ if (lastChar < 0 || lastChar > 255) {
825
+ lastChar = 255;
826
+ }
827
+ mul = (type == fontType3) ? fontMat[0] : 0.001;
828
+ fontDict->lookup("Widths", &obj1);
829
+ if (obj1.isArray()) {
830
+ flags |= fontFixedWidth;
831
+ if (obj1.arrayGetLength() < lastChar - firstChar + 1) {
832
+ lastChar = firstChar + obj1.arrayGetLength() - 1;
833
+ }
834
+ for (code = firstChar; code <= lastChar; ++code) {
835
+ obj1.arrayGet(code - firstChar, &obj2);
836
+ if (obj2.isNum()) {
837
+ widths[code] = obj2.getNum() * mul;
838
+ if (widths[code] != widths[firstChar]) {
839
+ flags &= ~fontFixedWidth;
840
+ }
841
+ }
842
+ obj2.free();
843
+ }
844
+
845
+ // use widths from built-in font
846
+ } else if (builtinFont) {
847
+ // this is a kludge for broken PDF files that encode char 32
848
+ // as .notdef
849
+ if (builtinFont->widths->getWidth("space", &w)) {
850
+ widths[32] = 0.001 * w;
851
+ }
852
+ for (code = 0; code < 256; ++code) {
853
+ if (enc[code] && builtinFont->widths->getWidth(enc[code], &w)) {
854
+ widths[code] = 0.001 * w;
855
+ }
856
+ }
857
+
858
+ // couldn't find widths -- use defaults
859
+ } else {
860
+ // this is technically an error -- the Widths entry is required
861
+ // for all but the Base-14 fonts -- but certain PDF generators
862
+ // apparently don't include widths for Arial and TimesNewRoman
863
+ if (isFixedWidth()) {
864
+ i = 0;
865
+ } else if (isSerif()) {
866
+ i = 8;
867
+ } else {
868
+ i = 4;
869
+ }
870
+ if (isBold()) {
871
+ i += 2;
872
+ }
873
+ if (isItalic()) {
874
+ i += 1;
875
+ }
876
+ builtinFont = builtinFontSubst[i];
877
+ // this is a kludge for broken PDF files that encode char 32
878
+ // as .notdef
879
+ if (builtinFont->widths->getWidth("space", &w)) {
880
+ widths[32] = 0.001 * w;
881
+ }
882
+ for (code = 0; code < 256; ++code) {
883
+ if (enc[code] && builtinFont->widths->getWidth(enc[code], &w)) {
884
+ widths[code] = 0.001 * w;
885
+ }
886
+ }
887
+ }
888
+ obj1.free();
889
+
890
+ ok = gTrue;
891
+ }
892
+
893
+ Gfx8BitFont::~Gfx8BitFont() {
894
+ int i;
895
+
896
+ for (i = 0; i < 256; ++i) {
897
+ if (encFree[i] && enc[i]) {
898
+ gfree(enc[i]);
899
+ }
900
+ }
901
+ ctu->decRefCnt();
902
+ if (charProcs.isDict()) {
903
+ charProcs.free();
904
+ }
905
+ if (resources.isDict()) {
906
+ resources.free();
907
+ }
908
+ }
909
+
910
+ int Gfx8BitFont::getNextChar(char *s, int len, CharCode *code,
911
+ Unicode *u, int uSize, int *uLen,
912
+ double *dx, double *dy, double *ox, double *oy) {
913
+ CharCode c;
914
+
915
+ *code = c = (CharCode)(*s & 0xff);
916
+ *uLen = ctu->mapToUnicode(c, u, uSize);
917
+ *dx = widths[c];
918
+ *dy = *ox = *oy = 0;
919
+ return 1;
920
+ }
921
+
922
+ CharCodeToUnicode *Gfx8BitFont::getToUnicode() {
923
+ ctu->incRefCnt();
924
+ return ctu;
925
+ }
926
+
927
+ Gushort *Gfx8BitFont::getCodeToGIDMap(FoFiTrueType *ff) {
928
+ Gushort *map;
929
+ int cmapPlatform, cmapEncoding;
930
+ int unicodeCmap, macRomanCmap, msSymbolCmap, cmap;
931
+ GBool useMacRoman, useUnicode;
932
+ char *charName;
933
+ Unicode u;
934
+ int code, i, n;
935
+
936
+ map = (Gushort *)gmallocn(256, sizeof(Gushort));
937
+ for (i = 0; i < 256; ++i) {
938
+ map[i] = 0;
939
+ }
940
+
941
+ // To match up with the Adobe-defined behaviour, we choose a cmap
942
+ // like this:
943
+ // 1. If the PDF font has an encoding:
944
+ // 1a. If the PDF font specified MacRomanEncoding and the
945
+ // TrueType font has a Macintosh Roman cmap, use it, and
946
+ // reverse map the char names through MacRomanEncoding to
947
+ // get char codes.
948
+ // 1b. If the TrueType font has a Microsoft Unicode cmap or a
949
+ // non-Microsoft Unicode cmap, use it, and use the Unicode
950
+ // indexes, not the char codes.
951
+ // 1c. If the PDF font is symbolic and the TrueType font has a
952
+ // Microsoft Symbol cmap, use it, and use char codes
953
+ // directly (possibly with an offset of 0xf000).
954
+ // 1d. If the TrueType font has a Macintosh Roman cmap, use it,
955
+ // as in case 1a.
956
+ // 2. If the PDF font does not have an encoding or the PDF font is
957
+ // symbolic:
958
+ // 2a. If the TrueType font has a Macintosh Roman cmap, use it,
959
+ // and use char codes directly (possibly with an offset of
960
+ // 0xf000).
961
+ // 2b. If the TrueType font has a Microsoft Symbol cmap, use it,
962
+ // and use char codes directly (possible with an offset of
963
+ // 0xf000).
964
+ // 3. If none of these rules apply, use the first cmap and hope for
965
+ // the best (this shouldn't happen).
966
+ unicodeCmap = macRomanCmap = msSymbolCmap = -1;
967
+ for (i = 0; i < ff->getNumCmaps(); ++i) {
968
+ cmapPlatform = ff->getCmapPlatform(i);
969
+ cmapEncoding = ff->getCmapEncoding(i);
970
+ if ((cmapPlatform == 3 && cmapEncoding == 1) ||
971
+ cmapPlatform == 0) {
972
+ unicodeCmap = i;
973
+ } else if (cmapPlatform == 1 && cmapEncoding == 0) {
974
+ macRomanCmap = i;
975
+ } else if (cmapPlatform == 3 && cmapEncoding == 0) {
976
+ msSymbolCmap = i;
977
+ }
978
+ }
979
+ cmap = 0;
980
+ useMacRoman = gFalse;
981
+ useUnicode = gFalse;
982
+ if (hasEncoding) {
983
+ if (usesMacRomanEnc && macRomanCmap >= 0) {
984
+ cmap = macRomanCmap;
985
+ useMacRoman = gTrue;
986
+ } else if (unicodeCmap >= 0) {
987
+ cmap = unicodeCmap;
988
+ useUnicode = gTrue;
989
+ } else if ((flags & fontSymbolic) && msSymbolCmap >= 0) {
990
+ cmap = msSymbolCmap;
991
+ } else if ((flags & fontSymbolic) && macRomanCmap >= 0) {
992
+ cmap = macRomanCmap;
993
+ } else if (macRomanCmap >= 0) {
994
+ cmap = macRomanCmap;
995
+ useMacRoman = gTrue;
996
+ }
997
+ } else {
998
+ if (msSymbolCmap >= 0) {
999
+ cmap = msSymbolCmap;
1000
+ } else if (macRomanCmap >= 0) {
1001
+ cmap = macRomanCmap;
1002
+ }
1003
+ }
1004
+
1005
+ // reverse map the char names through MacRomanEncoding, then map the
1006
+ // char codes through the cmap
1007
+ if (useMacRoman) {
1008
+ for (i = 0; i < 256; ++i) {
1009
+ if ((charName = enc[i])) {
1010
+ if ((code = globalParams->getMacRomanCharCode(charName))) {
1011
+ map[i] = ff->mapCodeToGID(cmap, code);
1012
+ }
1013
+ }
1014
+ }
1015
+
1016
+ // map Unicode through the cmap
1017
+ } else if (useUnicode) {
1018
+ for (i = 0; i < 256; ++i) {
1019
+ if (((charName = enc[i]) &&
1020
+ (u = globalParams->mapNameToUnicode(charName))) ||
1021
+ (n = ctu->mapToUnicode((CharCode)i, &u, 1))) {
1022
+ map[i] = ff->mapCodeToGID(cmap, u);
1023
+ }
1024
+ }
1025
+
1026
+ // map the char codes through the cmap, possibly with an offset of
1027
+ // 0xf000
1028
+ } else {
1029
+ for (i = 0; i < 256; ++i) {
1030
+ if (!(map[i] = ff->mapCodeToGID(cmap, i))) {
1031
+ map[i] = ff->mapCodeToGID(cmap, 0xf000 + i);
1032
+ }
1033
+ }
1034
+ }
1035
+
1036
+ // try the TrueType 'post' table to handle any unmapped characters
1037
+ for (i = 0; i < 256; ++i) {
1038
+ if (!map[i] && (charName = enc[i])) {
1039
+ map[i] = (Gushort)(int)ff->mapNameToGID(charName);
1040
+ }
1041
+ }
1042
+
1043
+ return map;
1044
+ }
1045
+
1046
+ Dict *Gfx8BitFont::getCharProcs() {
1047
+ return charProcs.isDict() ? charProcs.getDict() : (Dict *)NULL;
1048
+ }
1049
+
1050
+ Object *Gfx8BitFont::getCharProc(int code, Object *proc) {
1051
+ if (enc[code] && charProcs.isDict()) {
1052
+ charProcs.dictLookup(enc[code], proc);
1053
+ } else {
1054
+ proc->initNull();
1055
+ }
1056
+ return proc;
1057
+ }
1058
+
1059
+ Dict *Gfx8BitFont::getResources() {
1060
+ return resources.isDict() ? resources.getDict() : (Dict *)NULL;
1061
+ }
1062
+
1063
+ //------------------------------------------------------------------------
1064
+ // GfxCIDFont
1065
+ //------------------------------------------------------------------------
1066
+
1067
+ static int CDECL cmpWidthExcep(const void *w1, const void *w2) {
1068
+ return ((GfxFontCIDWidthExcep *)w1)->first -
1069
+ ((GfxFontCIDWidthExcep *)w2)->first;
1070
+ }
1071
+
1072
+ static int CDECL cmpWidthExcepV(const void *w1, const void *w2) {
1073
+ return ((GfxFontCIDWidthExcepV *)w1)->first -
1074
+ ((GfxFontCIDWidthExcepV *)w2)->first;
1075
+ }
1076
+
1077
+ GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
1078
+ Dict *fontDict):
1079
+ GfxFont(tagA, idA, nameA)
1080
+ {
1081
+ Dict *desFontDict;
1082
+ GString *collection, *cMapName;
1083
+ Object desFontDictObj;
1084
+ Object obj1, obj2, obj3, obj4, obj5, obj6;
1085
+ CharCodeToUnicode *utu;
1086
+ CharCode c;
1087
+ Unicode uBuf[8];
1088
+ int c1, c2;
1089
+ int excepsSize, i, j, k, n;
1090
+
1091
+ ascent = 0.95;
1092
+ descent = -0.35;
1093
+ fontBBox[0] = fontBBox[1] = fontBBox[2] = fontBBox[3] = 0;
1094
+ cMap = NULL;
1095
+ ctu = NULL;
1096
+ widths.defWidth = 1.0;
1097
+ widths.defHeight = -1.0;
1098
+ widths.defVY = 0.880;
1099
+ widths.exceps = NULL;
1100
+ widths.nExceps = 0;
1101
+ widths.excepsV = NULL;
1102
+ widths.nExcepsV = 0;
1103
+ cidToGID = NULL;
1104
+ cidToGIDLen = 0;
1105
+
1106
+ // get the descendant font
1107
+ if (!fontDict->lookup("DescendantFonts", &obj1)->isArray()) {
1108
+ error(-1, "Missing DescendantFonts entry in Type 0 font");
1109
+ obj1.free();
1110
+ goto err1;
1111
+ }
1112
+ if (!obj1.arrayGet(0, &desFontDictObj)->isDict()) {
1113
+ error(-1, "Bad descendant font in Type 0 font");
1114
+ goto err3;
1115
+ }
1116
+ obj1.free();
1117
+ desFontDict = desFontDictObj.getDict();
1118
+
1119
+ // font type
1120
+ if (!desFontDict->lookup("Subtype", &obj1)) {
1121
+ error(-1, "Missing Subtype entry in Type 0 descendant font");
1122
+ goto err3;
1123
+ }
1124
+ if (obj1.isName("CIDFontType0")) {
1125
+ type = fontCIDType0;
1126
+ } else if (obj1.isName("CIDFontType2")) {
1127
+ type = fontCIDType2;
1128
+ } else {
1129
+ error(-1, "Unknown Type 0 descendant font type '%s'",
1130
+ obj1.isName() ? obj1.getName() : "???");
1131
+ goto err3;
1132
+ }
1133
+ obj1.free();
1134
+
1135
+ // get info from font descriptor
1136
+ readFontDescriptor(xref, desFontDict);
1137
+
1138
+ // look for an external font file
1139
+ findExtFontFile();
1140
+
1141
+ //----- encoding info -----
1142
+
1143
+ // char collection
1144
+ if (!desFontDict->lookup("CIDSystemInfo", &obj1)->isDict()) {
1145
+ error(-1, "Missing CIDSystemInfo dictionary in Type 0 descendant font");
1146
+ goto err3;
1147
+ }
1148
+ obj1.dictLookup("Registry", &obj2);
1149
+ obj1.dictLookup("Ordering", &obj3);
1150
+ if (!obj2.isString() || !obj3.isString()) {
1151
+ error(-1, "Invalid CIDSystemInfo dictionary in Type 0 descendant font");
1152
+ goto err4;
1153
+ }
1154
+ collection = obj2.getString()->copy()->append('-')->append(obj3.getString());
1155
+ obj3.free();
1156
+ obj2.free();
1157
+ obj1.free();
1158
+
1159
+ // look for a ToUnicode CMap
1160
+ if (!(ctu = readToUnicodeCMap(fontDict, 16, NULL))) {
1161
+
1162
+ // the "Adobe-Identity" and "Adobe-UCS" collections don't have
1163
+ // cidToUnicode files
1164
+ if (collection->cmp("Adobe-Identity") &&
1165
+ collection->cmp("Adobe-UCS")) {
1166
+
1167
+ // look for a user-supplied .cidToUnicode file
1168
+ if (!(ctu = globalParams->getCIDToUnicode(collection))) {
1169
+ error(-1, "Unknown character collection '%s'",
1170
+ collection->getCString());
1171
+ // fall-through, assuming the Identity mapping -- this appears
1172
+ // to match Adobe's behavior
1173
+ }
1174
+ }
1175
+ }
1176
+
1177
+ // look for a Unicode-to-Unicode mapping
1178
+ if (name && (utu = globalParams->getUnicodeToUnicode(name))) {
1179
+ if (ctu) {
1180
+ for (c = 0; c < ctu->getLength(); ++c) {
1181
+ n = ctu->mapToUnicode(c, uBuf, 8);
1182
+ if (n >= 1) {
1183
+ n = utu->mapToUnicode((CharCode)uBuf[0], uBuf, 8);
1184
+ if (n >= 1) {
1185
+ ctu->setMapping(c, uBuf, n);
1186
+ }
1187
+ }
1188
+ }
1189
+ utu->decRefCnt();
1190
+ } else {
1191
+ ctu = utu;
1192
+ }
1193
+ }
1194
+
1195
+ // encoding (i.e., CMap)
1196
+ //~ need to handle a CMap stream here
1197
+ //~ also need to deal with the UseCMap entry in the stream dict
1198
+ if (!fontDict->lookup("Encoding", &obj1)->isName()) {
1199
+ error(-1, "Missing or invalid Encoding entry in Type 0 font");
1200
+ delete collection;
1201
+ goto err3;
1202
+ }
1203
+ cMapName = new GString(obj1.getName());
1204
+ obj1.free();
1205
+ if (!(cMap = globalParams->getCMap(collection, cMapName))) {
1206
+ error(-1, "Unknown CMap '%s' for character collection '%s'",
1207
+ cMapName->getCString(), collection->getCString());
1208
+ delete collection;
1209
+ delete cMapName;
1210
+ goto err2;
1211
+ }
1212
+ delete collection;
1213
+ delete cMapName;
1214
+
1215
+ // CIDToGIDMap (for embedded TrueType fonts)
1216
+ if (type == fontCIDType2) {
1217
+ desFontDict->lookup("CIDToGIDMap", &obj1);
1218
+ if (obj1.isStream()) {
1219
+ cidToGIDLen = 0;
1220
+ i = 64;
1221
+ cidToGID = (Gushort *)gmallocn(i, sizeof(Gushort));
1222
+ obj1.streamReset();
1223
+ while ((c1 = obj1.streamGetChar()) != EOF &&
1224
+ (c2 = obj1.streamGetChar()) != EOF) {
1225
+ if (cidToGIDLen == i) {
1226
+ i *= 2;
1227
+ cidToGID = (Gushort *)greallocn(cidToGID, i, sizeof(Gushort));
1228
+ }
1229
+ cidToGID[cidToGIDLen++] = (Gushort)((c1 << 8) + c2);
1230
+ }
1231
+ } else if (!obj1.isName("Identity") && !obj1.isNull()) {
1232
+ error(-1, "Invalid CIDToGIDMap entry in CID font");
1233
+ }
1234
+ obj1.free();
1235
+ }
1236
+
1237
+ //----- character metrics -----
1238
+
1239
+ // default char width
1240
+ if (desFontDict->lookup("DW", &obj1)->isInt()) {
1241
+ widths.defWidth = obj1.getInt() * 0.001;
1242
+ }
1243
+ obj1.free();
1244
+
1245
+ // char width exceptions
1246
+ if (desFontDict->lookup("W", &obj1)->isArray()) {
1247
+ excepsSize = 0;
1248
+ i = 0;
1249
+ while (i + 1 < obj1.arrayGetLength()) {
1250
+ obj1.arrayGet(i, &obj2);
1251
+ obj1.arrayGet(i + 1, &obj3);
1252
+ if (obj2.isInt() && obj3.isInt() && i + 2 < obj1.arrayGetLength()) {
1253
+ if (obj1.arrayGet(i + 2, &obj4)->isNum()) {
1254
+ if (widths.nExceps == excepsSize) {
1255
+ excepsSize += 16;
1256
+ widths.exceps = (GfxFontCIDWidthExcep *)
1257
+ greallocn(widths.exceps,
1258
+ excepsSize, sizeof(GfxFontCIDWidthExcep));
1259
+ }
1260
+ widths.exceps[widths.nExceps].first = obj2.getInt();
1261
+ widths.exceps[widths.nExceps].last = obj3.getInt();
1262
+ widths.exceps[widths.nExceps].width = obj4.getNum() * 0.001;
1263
+ ++widths.nExceps;
1264
+ } else {
1265
+ error(-1, "Bad widths array in Type 0 font");
1266
+ }
1267
+ obj4.free();
1268
+ i += 3;
1269
+ } else if (obj2.isInt() && obj3.isArray()) {
1270
+ if (widths.nExceps + obj3.arrayGetLength() > excepsSize) {
1271
+ excepsSize = (widths.nExceps + obj3.arrayGetLength() + 15) & ~15;
1272
+ widths.exceps = (GfxFontCIDWidthExcep *)
1273
+ greallocn(widths.exceps,
1274
+ excepsSize, sizeof(GfxFontCIDWidthExcep));
1275
+ }
1276
+ j = obj2.getInt();
1277
+ for (k = 0; k < obj3.arrayGetLength(); ++k) {
1278
+ if (obj3.arrayGet(k, &obj4)->isNum()) {
1279
+ widths.exceps[widths.nExceps].first = j;
1280
+ widths.exceps[widths.nExceps].last = j;
1281
+ widths.exceps[widths.nExceps].width = obj4.getNum() * 0.001;
1282
+ ++j;
1283
+ ++widths.nExceps;
1284
+ } else {
1285
+ error(-1, "Bad widths array in Type 0 font");
1286
+ }
1287
+ obj4.free();
1288
+ }
1289
+ i += 2;
1290
+ } else {
1291
+ error(-1, "Bad widths array in Type 0 font");
1292
+ ++i;
1293
+ }
1294
+ obj3.free();
1295
+ obj2.free();
1296
+ }
1297
+ qsort(widths.exceps, widths.nExceps, sizeof(GfxFontCIDWidthExcep),
1298
+ &cmpWidthExcep);
1299
+ }
1300
+ obj1.free();
1301
+
1302
+ // default metrics for vertical font
1303
+ if (desFontDict->lookup("DW2", &obj1)->isArray() &&
1304
+ obj1.arrayGetLength() == 2) {
1305
+ if (obj1.arrayGet(0, &obj2)->isNum()) {
1306
+ widths.defVY = obj2.getNum() * 0.001;
1307
+ }
1308
+ obj2.free();
1309
+ if (obj1.arrayGet(1, &obj2)->isNum()) {
1310
+ widths.defHeight = obj2.getNum() * 0.001;
1311
+ }
1312
+ obj2.free();
1313
+ }
1314
+ obj1.free();
1315
+
1316
+ // char metric exceptions for vertical font
1317
+ if (desFontDict->lookup("W2", &obj1)->isArray()) {
1318
+ excepsSize = 0;
1319
+ i = 0;
1320
+ while (i + 1 < obj1.arrayGetLength()) {
1321
+ obj1.arrayGet(i, &obj2);
1322
+ obj1.arrayGet(i+ 1, &obj3);
1323
+ if (obj2.isInt() && obj3.isInt() && i + 4 < obj1.arrayGetLength()) {
1324
+ if (obj1.arrayGet(i + 2, &obj4)->isNum() &&
1325
+ obj1.arrayGet(i + 3, &obj5)->isNum() &&
1326
+ obj1.arrayGet(i + 4, &obj6)->isNum()) {
1327
+ if (widths.nExcepsV == excepsSize) {
1328
+ excepsSize += 16;
1329
+ widths.excepsV = (GfxFontCIDWidthExcepV *)
1330
+ greallocn(widths.excepsV,
1331
+ excepsSize, sizeof(GfxFontCIDWidthExcepV));
1332
+ }
1333
+ widths.excepsV[widths.nExcepsV].first = obj2.getInt();
1334
+ widths.excepsV[widths.nExcepsV].last = obj3.getInt();
1335
+ widths.excepsV[widths.nExcepsV].height = obj4.getNum() * 0.001;
1336
+ widths.excepsV[widths.nExcepsV].vx = obj5.getNum() * 0.001;
1337
+ widths.excepsV[widths.nExcepsV].vy = obj6.getNum() * 0.001;
1338
+ ++widths.nExcepsV;
1339
+ } else {
1340
+ error(-1, "Bad widths (W2) array in Type 0 font");
1341
+ }
1342
+ obj6.free();
1343
+ obj5.free();
1344
+ obj4.free();
1345
+ i += 5;
1346
+ } else if (obj2.isInt() && obj3.isArray()) {
1347
+ if (widths.nExcepsV + obj3.arrayGetLength() / 3 > excepsSize) {
1348
+ excepsSize =
1349
+ (widths.nExcepsV + obj3.arrayGetLength() / 3 + 15) & ~15;
1350
+ widths.excepsV = (GfxFontCIDWidthExcepV *)
1351
+ greallocn(widths.excepsV,
1352
+ excepsSize, sizeof(GfxFontCIDWidthExcepV));
1353
+ }
1354
+ j = obj2.getInt();
1355
+ for (k = 0; k < obj3.arrayGetLength(); k += 3) {
1356
+ if (obj3.arrayGet(k, &obj4)->isNum() &&
1357
+ obj3.arrayGet(k+1, &obj5)->isNum() &&
1358
+ obj3.arrayGet(k+2, &obj6)->isNum()) {
1359
+ widths.excepsV[widths.nExceps].first = j;
1360
+ widths.excepsV[widths.nExceps].last = j;
1361
+ widths.excepsV[widths.nExceps].height = obj4.getNum() * 0.001;
1362
+ widths.excepsV[widths.nExceps].vx = obj5.getNum() * 0.001;
1363
+ widths.excepsV[widths.nExceps].vy = obj6.getNum() * 0.001;
1364
+ ++j;
1365
+ ++widths.nExcepsV;
1366
+ } else {
1367
+ error(-1, "Bad widths (W2) array in Type 0 font");
1368
+ }
1369
+ obj6.free();
1370
+ obj5.free();
1371
+ obj4.free();
1372
+ }
1373
+ i += 2;
1374
+ } else {
1375
+ error(-1, "Bad widths (W2) array in Type 0 font");
1376
+ ++i;
1377
+ }
1378
+ obj3.free();
1379
+ obj2.free();
1380
+ }
1381
+ qsort(widths.excepsV, widths.nExcepsV, sizeof(GfxFontCIDWidthExcepV),
1382
+ &cmpWidthExcepV);
1383
+ }
1384
+ obj1.free();
1385
+
1386
+ desFontDictObj.free();
1387
+ ok = gTrue;
1388
+ return;
1389
+
1390
+ err4:
1391
+ obj3.free();
1392
+ obj2.free();
1393
+ err3:
1394
+ obj1.free();
1395
+ err2:
1396
+ desFontDictObj.free();
1397
+ err1:;
1398
+ }
1399
+
1400
+ GfxCIDFont::~GfxCIDFont() {
1401
+ if (cMap) {
1402
+ cMap->decRefCnt();
1403
+ }
1404
+ if (ctu) {
1405
+ ctu->decRefCnt();
1406
+ }
1407
+ gfree(widths.exceps);
1408
+ gfree(widths.excepsV);
1409
+ if (cidToGID) {
1410
+ gfree(cidToGID);
1411
+ }
1412
+ }
1413
+
1414
+ int GfxCIDFont::getNextChar(char *s, int len, CharCode *code,
1415
+ Unicode *u, int uSize, int *uLen,
1416
+ double *dx, double *dy, double *ox, double *oy) {
1417
+ CID cid;
1418
+ double w, h, vx, vy;
1419
+ int n, a, b, m;
1420
+
1421
+ if (!cMap) {
1422
+ *code = 0;
1423
+ *uLen = 0;
1424
+ *dx = *dy = 0;
1425
+ return 1;
1426
+ }
1427
+
1428
+ *code = (CharCode)(cid = cMap->getCID(s, len, &n));
1429
+ if (ctu) {
1430
+ *uLen = ctu->mapToUnicode(cid, u, uSize);
1431
+ } else {
1432
+ *uLen = 0;
1433
+ }
1434
+
1435
+ // horizontal
1436
+ if (cMap->getWMode() == 0) {
1437
+ w = widths.defWidth;
1438
+ h = vx = vy = 0;
1439
+ if (widths.nExceps > 0 && cid >= widths.exceps[0].first) {
1440
+ a = 0;
1441
+ b = widths.nExceps;
1442
+ // invariant: widths.exceps[a].first <= cid < widths.exceps[b].first
1443
+ while (b - a > 1) {
1444
+ m = (a + b) / 2;
1445
+ if (widths.exceps[m].first <= cid) {
1446
+ a = m;
1447
+ } else {
1448
+ b = m;
1449
+ }
1450
+ }
1451
+ if (cid <= widths.exceps[a].last) {
1452
+ w = widths.exceps[a].width;
1453
+ }
1454
+ }
1455
+
1456
+ // vertical
1457
+ } else {
1458
+ w = 0;
1459
+ h = widths.defHeight;
1460
+ vx = widths.defWidth / 2;
1461
+ vy = widths.defVY;
1462
+ if (widths.nExcepsV > 0 && cid >= widths.excepsV[0].first) {
1463
+ a = 0;
1464
+ b = widths.nExcepsV;
1465
+ // invariant: widths.excepsV[a].first <= cid < widths.excepsV[b].first
1466
+ while (b - a > 1) {
1467
+ m = (a + b) / 2;
1468
+ if (widths.excepsV[m].last <= cid) {
1469
+ a = m;
1470
+ } else {
1471
+ b = m;
1472
+ }
1473
+ }
1474
+ if (cid <= widths.excepsV[a].last) {
1475
+ h = widths.excepsV[a].height;
1476
+ vx = widths.excepsV[a].vx;
1477
+ vy = widths.excepsV[a].vy;
1478
+ }
1479
+ }
1480
+ }
1481
+
1482
+ *dx = w;
1483
+ *dy = h;
1484
+ *ox = vx;
1485
+ *oy = vy;
1486
+
1487
+ return n;
1488
+ }
1489
+
1490
+ int GfxCIDFont::getWMode() {
1491
+ return cMap ? cMap->getWMode() : 0;
1492
+ }
1493
+
1494
+ CharCodeToUnicode *GfxCIDFont::getToUnicode() {
1495
+ if (ctu) {
1496
+ ctu->incRefCnt();
1497
+ }
1498
+ return ctu;
1499
+ }
1500
+
1501
+ GString *GfxCIDFont::getCollection() {
1502
+ return cMap ? cMap->getCollection() : (GString *)NULL;
1503
+ }
1504
+
1505
+ //------------------------------------------------------------------------
1506
+ // GfxFontDict
1507
+ //------------------------------------------------------------------------
1508
+
1509
+ GfxFontDict::GfxFontDict(XRef *xref, Ref *fontDictRef, Dict *fontDict) {
1510
+ int i;
1511
+ Object obj1, obj2;
1512
+ Ref r;
1513
+
1514
+ numFonts = fontDict->getLength();
1515
+ fonts = (GfxFont **)gmallocn(numFonts, sizeof(GfxFont *));
1516
+ for (i = 0; i < numFonts; ++i) {
1517
+ fontDict->getValNF(i, &obj1);
1518
+ obj1.fetch(xref, &obj2);
1519
+ if (obj2.isDict()) {
1520
+ if (obj1.isRef()) {
1521
+ r = obj1.getRef();
1522
+ } else {
1523
+ // no indirect reference for this font, so invent a unique one
1524
+ // (legal generation numbers are five digits, so any 6-digit
1525
+ // number would be safe)
1526
+ r.num = i;
1527
+ if (fontDictRef) {
1528
+ r.gen = 100000 + fontDictRef->num;
1529
+ } else {
1530
+ r.gen = 999999;
1531
+ }
1532
+ }
1533
+ fonts[i] = GfxFont::makeFont(xref, fontDict->getKey(i),
1534
+ r, obj2.getDict());
1535
+ if (fonts[i] && !fonts[i]->isOk()) {
1536
+ delete fonts[i];
1537
+ fonts[i] = NULL;
1538
+ }
1539
+ } else {
1540
+ error(-1, "font resource is not a dictionary");
1541
+ fonts[i] = NULL;
1542
+ }
1543
+ obj1.free();
1544
+ obj2.free();
1545
+ }
1546
+ }
1547
+
1548
+ GfxFontDict::~GfxFontDict() {
1549
+ int i;
1550
+
1551
+ for (i = 0; i < numFonts; ++i) {
1552
+ if (fonts[i]) {
1553
+ delete fonts[i];
1554
+ }
1555
+ }
1556
+ gfree(fonts);
1557
+ }
1558
+
1559
+ GfxFont *GfxFontDict::lookup(char *tag) {
1560
+ int i;
1561
+
1562
+ for (i = 0; i < numFonts; ++i) {
1563
+ if (fonts[i] && fonts[i]->matches(tag)) {
1564
+ return fonts[i];
1565
+ }
1566
+ }
1567
+ return NULL;
1568
+ }