pdf2json 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,20 @@
1
+ //========================================================================
2
+ //
3
+ // FontEncodingTables.h
4
+ //
5
+ // Copyright 2001-2003 Glyph & Cog, LLC
6
+ //
7
+ //========================================================================
8
+
9
+ #ifndef FONTENCODINGTABLES_H
10
+ #define FONTENCODINGTABLES_H
11
+
12
+ extern char *macRomanEncoding[];
13
+ extern char *macExpertEncoding[];
14
+ extern char *winAnsiEncoding[];
15
+ extern char *standardEncoding[];
16
+ extern char *expertEncoding[];
17
+ extern char *symbolEncoding[];
18
+ extern char *zapfDingbatsEncoding[];
19
+
20
+ #endif
@@ -0,0 +1,1573 @@
1
+ //========================================================================
2
+ //
3
+ // Function.cc
4
+ //
5
+ // Copyright 2001-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 <stdlib.h>
16
+ #include <string.h>
17
+ #include <ctype.h>
18
+ #include <math.h>
19
+ #include "gmem.h"
20
+ #include "Object.h"
21
+ #include "Dict.h"
22
+ #include "Stream.h"
23
+ #include "Error.h"
24
+ #include "Function.h"
25
+
26
+ //------------------------------------------------------------------------
27
+ // Function
28
+ //------------------------------------------------------------------------
29
+
30
+ Function::Function() {
31
+ }
32
+
33
+ Function::~Function() {
34
+ }
35
+
36
+ Function *Function::parse(Object *funcObj) {
37
+ Function *func;
38
+ Dict *dict;
39
+ int funcType;
40
+ Object obj1;
41
+
42
+ if (funcObj->isStream()) {
43
+ dict = funcObj->streamGetDict();
44
+ } else if (funcObj->isDict()) {
45
+ dict = funcObj->getDict();
46
+ } else if (funcObj->isName("Identity")) {
47
+ return new IdentityFunction();
48
+ } else {
49
+ error(-1, "Expected function dictionary or stream");
50
+ return NULL;
51
+ }
52
+
53
+ if (!dict->lookup("FunctionType", &obj1)->isInt()) {
54
+ error(-1, "Function type is missing or wrong type");
55
+ obj1.free();
56
+ return NULL;
57
+ }
58
+ funcType = obj1.getInt();
59
+ obj1.free();
60
+
61
+ if (funcType == 0) {
62
+ func = new SampledFunction(funcObj, dict);
63
+ } else if (funcType == 2) {
64
+ func = new ExponentialFunction(funcObj, dict);
65
+ } else if (funcType == 3) {
66
+ func = new StitchingFunction(funcObj, dict);
67
+ } else if (funcType == 4) {
68
+ func = new PostScriptFunction(funcObj, dict);
69
+ } else {
70
+ error(-1, "Unimplemented function type (%d)", funcType);
71
+ return NULL;
72
+ }
73
+ if (!func->isOk()) {
74
+ delete func;
75
+ return NULL;
76
+ }
77
+
78
+ return func;
79
+ }
80
+
81
+ GBool Function::init(Dict *dict) {
82
+ Object obj1, obj2;
83
+ int i;
84
+
85
+ //----- Domain
86
+ if (!dict->lookup("Domain", &obj1)->isArray()) {
87
+ error(-1, "Function is missing domain");
88
+ goto err2;
89
+ }
90
+ m = obj1.arrayGetLength() / 2;
91
+ if (m > funcMaxInputs) {
92
+ error(-1, "Functions with more than %d inputs are unsupported",
93
+ funcMaxInputs);
94
+ goto err2;
95
+ }
96
+ for (i = 0; i < m; ++i) {
97
+ obj1.arrayGet(2*i, &obj2);
98
+ if (!obj2.isNum()) {
99
+ error(-1, "Illegal value in function domain array");
100
+ goto err1;
101
+ }
102
+ domain[i][0] = obj2.getNum();
103
+ obj2.free();
104
+ obj1.arrayGet(2*i+1, &obj2);
105
+ if (!obj2.isNum()) {
106
+ error(-1, "Illegal value in function domain array");
107
+ goto err1;
108
+ }
109
+ domain[i][1] = obj2.getNum();
110
+ obj2.free();
111
+ }
112
+ obj1.free();
113
+
114
+ //----- Range
115
+ hasRange = gFalse;
116
+ n = 0;
117
+ if (dict->lookup("Range", &obj1)->isArray()) {
118
+ hasRange = gTrue;
119
+ n = obj1.arrayGetLength() / 2;
120
+ if (n > funcMaxOutputs) {
121
+ error(-1, "Functions with more than %d outputs are unsupported",
122
+ funcMaxOutputs);
123
+ goto err2;
124
+ }
125
+ for (i = 0; i < n; ++i) {
126
+ obj1.arrayGet(2*i, &obj2);
127
+ if (!obj2.isNum()) {
128
+ error(-1, "Illegal value in function range array");
129
+ goto err1;
130
+ }
131
+ range[i][0] = obj2.getNum();
132
+ obj2.free();
133
+ obj1.arrayGet(2*i+1, &obj2);
134
+ if (!obj2.isNum()) {
135
+ error(-1, "Illegal value in function range array");
136
+ goto err1;
137
+ }
138
+ range[i][1] = obj2.getNum();
139
+ obj2.free();
140
+ }
141
+ }
142
+ obj1.free();
143
+
144
+ return gTrue;
145
+
146
+ err1:
147
+ obj2.free();
148
+ err2:
149
+ obj1.free();
150
+ return gFalse;
151
+ }
152
+
153
+ //------------------------------------------------------------------------
154
+ // IdentityFunction
155
+ //------------------------------------------------------------------------
156
+
157
+ IdentityFunction::IdentityFunction() {
158
+ int i;
159
+
160
+ // fill these in with arbitrary values just in case they get used
161
+ // somewhere
162
+ m = funcMaxInputs;
163
+ n = funcMaxOutputs;
164
+ for (i = 0; i < funcMaxInputs; ++i) {
165
+ domain[i][0] = 0;
166
+ domain[i][1] = 1;
167
+ }
168
+ hasRange = gFalse;
169
+ }
170
+
171
+ IdentityFunction::~IdentityFunction() {
172
+ }
173
+
174
+ void IdentityFunction::transform(double *in, double *out) {
175
+ int i;
176
+
177
+ for (i = 0; i < funcMaxOutputs; ++i) {
178
+ out[i] = in[i];
179
+ }
180
+ }
181
+
182
+ //------------------------------------------------------------------------
183
+ // SampledFunction
184
+ //------------------------------------------------------------------------
185
+
186
+ SampledFunction::SampledFunction(Object *funcObj, Dict *dict) {
187
+ Stream *str;
188
+ int sampleBits;
189
+ double sampleMul;
190
+ Object obj1, obj2;
191
+ Guint buf, bitMask;
192
+ int bits;
193
+ Guint s;
194
+ int i;
195
+
196
+ samples = NULL;
197
+ sBuf = NULL;
198
+ ok = gFalse;
199
+
200
+ //----- initialize the generic stuff
201
+ if (!init(dict)) {
202
+ goto err1;
203
+ }
204
+ if (!hasRange) {
205
+ error(-1, "Type 0 function is missing range");
206
+ goto err1;
207
+ }
208
+ if (m > sampledFuncMaxInputs) {
209
+ error(-1, "Sampled functions with more than %d inputs are unsupported",
210
+ sampledFuncMaxInputs);
211
+ goto err1;
212
+ }
213
+
214
+ //----- buffer
215
+ sBuf = (double *)gmallocn(1 << m, sizeof(double));
216
+
217
+ //----- get the stream
218
+ if (!funcObj->isStream()) {
219
+ error(-1, "Type 0 function isn't a stream");
220
+ goto err1;
221
+ }
222
+ str = funcObj->getStream();
223
+
224
+ //----- Size
225
+ if (!dict->lookup("Size", &obj1)->isArray() ||
226
+ obj1.arrayGetLength() != m) {
227
+ error(-1, "Function has missing or invalid size array");
228
+ goto err2;
229
+ }
230
+ for (i = 0; i < m; ++i) {
231
+ obj1.arrayGet(i, &obj2);
232
+ if (!obj2.isInt()) {
233
+ error(-1, "Illegal value in function size array");
234
+ goto err3;
235
+ }
236
+ sampleSize[i] = obj2.getInt();
237
+ obj2.free();
238
+ }
239
+ obj1.free();
240
+ idxMul[0] = n;
241
+ for (i = 1; i < m; ++i) {
242
+ idxMul[i] = idxMul[i-1] * sampleSize[i-1];
243
+ }
244
+
245
+ //----- BitsPerSample
246
+ if (!dict->lookup("BitsPerSample", &obj1)->isInt()) {
247
+ error(-1, "Function has missing or invalid BitsPerSample");
248
+ goto err2;
249
+ }
250
+ sampleBits = obj1.getInt();
251
+ sampleMul = 1.0 / (pow(2.0, (double)sampleBits) - 1);
252
+ obj1.free();
253
+
254
+ //----- Encode
255
+ if (dict->lookup("Encode", &obj1)->isArray() &&
256
+ obj1.arrayGetLength() == 2*m) {
257
+ for (i = 0; i < m; ++i) {
258
+ obj1.arrayGet(2*i, &obj2);
259
+ if (!obj2.isNum()) {
260
+ error(-1, "Illegal value in function encode array");
261
+ goto err3;
262
+ }
263
+ encode[i][0] = obj2.getNum();
264
+ obj2.free();
265
+ obj1.arrayGet(2*i+1, &obj2);
266
+ if (!obj2.isNum()) {
267
+ error(-1, "Illegal value in function encode array");
268
+ goto err3;
269
+ }
270
+ encode[i][1] = obj2.getNum();
271
+ obj2.free();
272
+ }
273
+ } else {
274
+ for (i = 0; i < m; ++i) {
275
+ encode[i][0] = 0;
276
+ encode[i][1] = sampleSize[i] - 1;
277
+ }
278
+ }
279
+ obj1.free();
280
+ for (i = 0; i < m; ++i) {
281
+ inputMul[i] = (encode[i][1] - encode[i][0]) /
282
+ (domain[i][1] - domain[i][0]);
283
+ }
284
+
285
+ //----- Decode
286
+ if (dict->lookup("Decode", &obj1)->isArray() &&
287
+ obj1.arrayGetLength() == 2*n) {
288
+ for (i = 0; i < n; ++i) {
289
+ obj1.arrayGet(2*i, &obj2);
290
+ if (!obj2.isNum()) {
291
+ error(-1, "Illegal value in function decode array");
292
+ goto err3;
293
+ }
294
+ decode[i][0] = obj2.getNum();
295
+ obj2.free();
296
+ obj1.arrayGet(2*i+1, &obj2);
297
+ if (!obj2.isNum()) {
298
+ error(-1, "Illegal value in function decode array");
299
+ goto err3;
300
+ }
301
+ decode[i][1] = obj2.getNum();
302
+ obj2.free();
303
+ }
304
+ } else {
305
+ for (i = 0; i < n; ++i) {
306
+ decode[i][0] = range[i][0];
307
+ decode[i][1] = range[i][1];
308
+ }
309
+ }
310
+ obj1.free();
311
+
312
+ //----- samples
313
+ nSamples = n;
314
+ for (i = 0; i < m; ++i)
315
+ nSamples *= sampleSize[i];
316
+ samples = (double *)gmallocn(nSamples, sizeof(double));
317
+ buf = 0;
318
+ bits = 0;
319
+ bitMask = (1 << sampleBits) - 1;
320
+ str->reset();
321
+ for (i = 0; i < nSamples; ++i) {
322
+ if (sampleBits == 8) {
323
+ s = str->getChar();
324
+ } else if (sampleBits == 16) {
325
+ s = str->getChar();
326
+ s = (s << 8) + str->getChar();
327
+ } else if (sampleBits == 32) {
328
+ s = str->getChar();
329
+ s = (s << 8) + str->getChar();
330
+ s = (s << 8) + str->getChar();
331
+ s = (s << 8) + str->getChar();
332
+ } else {
333
+ while (bits < sampleBits) {
334
+ buf = (buf << 8) | (str->getChar() & 0xff);
335
+ bits += 8;
336
+ }
337
+ s = (buf >> (bits - sampleBits)) & bitMask;
338
+ bits -= sampleBits;
339
+ }
340
+ samples[i] = (double)s * sampleMul;
341
+ }
342
+ str->close();
343
+
344
+ ok = gTrue;
345
+ return;
346
+
347
+ err3:
348
+ obj2.free();
349
+ err2:
350
+ obj1.free();
351
+ err1:
352
+ return;
353
+ }
354
+
355
+ SampledFunction::~SampledFunction() {
356
+ if (samples) {
357
+ gfree(samples);
358
+ }
359
+ if (sBuf) {
360
+ gfree(sBuf);
361
+ }
362
+ }
363
+
364
+ SampledFunction::SampledFunction(SampledFunction *func) {
365
+ memcpy(this, func, sizeof(SampledFunction));
366
+ samples = (double *)gmallocn(nSamples, sizeof(double));
367
+ memcpy(samples, func->samples, nSamples * sizeof(double));
368
+ sBuf = (double *)gmallocn(1 << m, sizeof(double));
369
+ }
370
+
371
+ void SampledFunction::transform(double *in, double *out) {
372
+ double x;
373
+ int e[funcMaxInputs][2];
374
+ double efrac0[funcMaxInputs];
375
+ double efrac1[funcMaxInputs];
376
+ int i, j, k, idx, t;
377
+
378
+ // map input values into sample array
379
+ for (i = 0; i < m; ++i) {
380
+ x = (in[i] - domain[i][0]) * inputMul[i] + encode[i][0];
381
+ if (x < 0) {
382
+ x = 0;
383
+ } else if (x > sampleSize[i] - 1) {
384
+ x = sampleSize[i] - 1;
385
+ }
386
+ e[i][0] = (int)x;
387
+ if ((e[i][1] = e[i][0] + 1) >= sampleSize[i]) {
388
+ // this happens if in[i] = domain[i][1]
389
+ e[i][1] = e[i][0];
390
+ }
391
+ efrac1[i] = x - e[i][0];
392
+ efrac0[i] = 1 - efrac1[i];
393
+ }
394
+
395
+ // for each output, do m-linear interpolation
396
+ for (i = 0; i < n; ++i) {
397
+
398
+ // pull 2^m values out of the sample array
399
+ for (j = 0; j < (1<<m); ++j) {
400
+ idx = i;
401
+ for (k = 0, t = j; k < m; ++k, t >>= 1) {
402
+ idx += idxMul[k] * (e[k][t & 1]);
403
+ }
404
+ sBuf[j] = samples[idx];
405
+ }
406
+
407
+ // do m sets of interpolations
408
+ for (j = 0, t = (1<<m); j < m; ++j, t >>= 1) {
409
+ for (k = 0; k < t; k += 2) {
410
+ sBuf[k >> 1] = efrac0[j] * sBuf[k] + efrac1[j] * sBuf[k+1];
411
+ }
412
+ }
413
+
414
+ // map output value to range
415
+ out[i] = sBuf[0] * (decode[i][1] - decode[i][0]) + decode[i][0];
416
+ if (out[i] < range[i][0]) {
417
+ out[i] = range[i][0];
418
+ } else if (out[i] > range[i][1]) {
419
+ out[i] = range[i][1];
420
+ }
421
+ }
422
+ }
423
+
424
+ //------------------------------------------------------------------------
425
+ // ExponentialFunction
426
+ //------------------------------------------------------------------------
427
+
428
+ ExponentialFunction::ExponentialFunction(Object *funcObj, Dict *dict) {
429
+ Object obj1, obj2;
430
+ int i;
431
+
432
+ ok = gFalse;
433
+
434
+ //----- initialize the generic stuff
435
+ if (!init(dict)) {
436
+ goto err1;
437
+ }
438
+ if (m != 1) {
439
+ error(-1, "Exponential function with more than one input");
440
+ goto err1;
441
+ }
442
+
443
+ //----- C0
444
+ if (dict->lookup("C0", &obj1)->isArray()) {
445
+ if (hasRange && obj1.arrayGetLength() != n) {
446
+ error(-1, "Function's C0 array is wrong length");
447
+ goto err2;
448
+ }
449
+ n = obj1.arrayGetLength();
450
+ for (i = 0; i < n; ++i) {
451
+ obj1.arrayGet(i, &obj2);
452
+ if (!obj2.isNum()) {
453
+ error(-1, "Illegal value in function C0 array");
454
+ goto err3;
455
+ }
456
+ c0[i] = obj2.getNum();
457
+ obj2.free();
458
+ }
459
+ } else {
460
+ if (hasRange && n != 1) {
461
+ error(-1, "Function's C0 array is wrong length");
462
+ goto err2;
463
+ }
464
+ n = 1;
465
+ c0[0] = 0;
466
+ }
467
+ obj1.free();
468
+
469
+ //----- C1
470
+ if (dict->lookup("C1", &obj1)->isArray()) {
471
+ if (obj1.arrayGetLength() != n) {
472
+ error(-1, "Function's C1 array is wrong length");
473
+ goto err2;
474
+ }
475
+ for (i = 0; i < n; ++i) {
476
+ obj1.arrayGet(i, &obj2);
477
+ if (!obj2.isNum()) {
478
+ error(-1, "Illegal value in function C1 array");
479
+ goto err3;
480
+ }
481
+ c1[i] = obj2.getNum();
482
+ obj2.free();
483
+ }
484
+ } else {
485
+ if (n != 1) {
486
+ error(-1, "Function's C1 array is wrong length");
487
+ goto err2;
488
+ }
489
+ c1[0] = 1;
490
+ }
491
+ obj1.free();
492
+
493
+ //----- N (exponent)
494
+ if (!dict->lookup("N", &obj1)->isNum()) {
495
+ error(-1, "Function has missing or invalid N");
496
+ goto err2;
497
+ }
498
+ e = obj1.getNum();
499
+ obj1.free();
500
+
501
+ ok = gTrue;
502
+ return;
503
+
504
+ err3:
505
+ obj2.free();
506
+ err2:
507
+ obj1.free();
508
+ err1:
509
+ return;
510
+ }
511
+
512
+ ExponentialFunction::~ExponentialFunction() {
513
+ }
514
+
515
+ ExponentialFunction::ExponentialFunction(ExponentialFunction *func) {
516
+ memcpy(this, func, sizeof(ExponentialFunction));
517
+ }
518
+
519
+ void ExponentialFunction::transform(double *in, double *out) {
520
+ double x;
521
+ int i;
522
+
523
+ if (in[0] < domain[0][0]) {
524
+ x = domain[0][0];
525
+ } else if (in[0] > domain[0][1]) {
526
+ x = domain[0][1];
527
+ } else {
528
+ x = in[0];
529
+ }
530
+ for (i = 0; i < n; ++i) {
531
+ out[i] = c0[i] + pow(x, e) * (c1[i] - c0[i]);
532
+ if (hasRange) {
533
+ if (out[i] < range[i][0]) {
534
+ out[i] = range[i][0];
535
+ } else if (out[i] > range[i][1]) {
536
+ out[i] = range[i][1];
537
+ }
538
+ }
539
+ }
540
+ return;
541
+ }
542
+
543
+ //------------------------------------------------------------------------
544
+ // StitchingFunction
545
+ //------------------------------------------------------------------------
546
+
547
+ StitchingFunction::StitchingFunction(Object *funcObj, Dict *dict) {
548
+ Object obj1, obj2;
549
+ int i;
550
+
551
+ ok = gFalse;
552
+ funcs = NULL;
553
+ bounds = NULL;
554
+ encode = NULL;
555
+ scale = NULL;
556
+
557
+ //----- initialize the generic stuff
558
+ if (!init(dict)) {
559
+ goto err1;
560
+ }
561
+ if (m != 1) {
562
+ error(-1, "Stitching function with more than one input");
563
+ goto err1;
564
+ }
565
+
566
+ //----- Functions
567
+ if (!dict->lookup("Functions", &obj1)->isArray()) {
568
+ error(-1, "Missing 'Functions' entry in stitching function");
569
+ goto err1;
570
+ }
571
+ k = obj1.arrayGetLength();
572
+ funcs = (Function **)gmallocn(k, sizeof(Function *));
573
+ bounds = (double *)gmallocn(k + 1, sizeof(double));
574
+ encode = (double *)gmallocn(2 * k, sizeof(double));
575
+ scale = (double *)gmallocn(k, sizeof(double));
576
+ for (i = 0; i < k; ++i) {
577
+ funcs[i] = NULL;
578
+ }
579
+ for (i = 0; i < k; ++i) {
580
+ if (!(funcs[i] = Function::parse(obj1.arrayGet(i, &obj2)))) {
581
+ goto err2;
582
+ }
583
+ if (i > 0 && (funcs[i]->getInputSize() != 1 ||
584
+ funcs[i]->getOutputSize() != funcs[0]->getOutputSize())) {
585
+ error(-1, "Incompatible subfunctions in stitching function");
586
+ goto err2;
587
+ }
588
+ obj2.free();
589
+ }
590
+ obj1.free();
591
+
592
+ //----- Bounds
593
+ if (!dict->lookup("Bounds", &obj1)->isArray() ||
594
+ obj1.arrayGetLength() != k - 1) {
595
+ error(-1, "Missing or invalid 'Bounds' entry in stitching function");
596
+ goto err1;
597
+ }
598
+ bounds[0] = domain[0][0];
599
+ for (i = 1; i < k; ++i) {
600
+ if (!obj1.arrayGet(i - 1, &obj2)->isNum()) {
601
+ error(-1, "Invalid type in 'Bounds' array in stitching function");
602
+ goto err2;
603
+ }
604
+ bounds[i] = obj2.getNum();
605
+ obj2.free();
606
+ }
607
+ bounds[k] = domain[0][1];
608
+ obj1.free();
609
+
610
+ //----- Encode
611
+ if (!dict->lookup("Encode", &obj1)->isArray() ||
612
+ obj1.arrayGetLength() != 2 * k) {
613
+ error(-1, "Missing or invalid 'Encode' entry in stitching function");
614
+ goto err1;
615
+ }
616
+ for (i = 0; i < 2 * k; ++i) {
617
+ if (!obj1.arrayGet(i, &obj2)->isNum()) {
618
+ error(-1, "Invalid type in 'Encode' array in stitching function");
619
+ goto err2;
620
+ }
621
+ encode[i] = obj2.getNum();
622
+ obj2.free();
623
+ }
624
+ obj1.free();
625
+
626
+ //----- pre-compute the scale factors
627
+ for (i = 0; i < k; ++i) {
628
+ if (bounds[i] == bounds[i+1]) {
629
+ // avoid a divide-by-zero -- in this situation, function i will
630
+ // never be used anyway
631
+ scale[i] = 0;
632
+ } else {
633
+ scale[i] = (encode[2*i+1] - encode[2*i]) / (bounds[i+1] - bounds[i]);
634
+ }
635
+ }
636
+
637
+ ok = gTrue;
638
+ return;
639
+
640
+ err2:
641
+ obj2.free();
642
+ err1:
643
+ obj1.free();
644
+ }
645
+
646
+ StitchingFunction::StitchingFunction(StitchingFunction *func) {
647
+ int i;
648
+
649
+ k = func->k;
650
+ funcs = (Function **)gmallocn(k, sizeof(Function *));
651
+ for (i = 0; i < k; ++i) {
652
+ funcs[i] = func->funcs[i]->copy();
653
+ }
654
+ bounds = (double *)gmallocn(k + 1, sizeof(double));
655
+ memcpy(bounds, func->bounds, (k + 1) * sizeof(double));
656
+ encode = (double *)gmallocn(2 * k, sizeof(double));
657
+ memcpy(encode, func->encode, 2 * k * sizeof(double));
658
+ scale = (double *)gmallocn(k, sizeof(double));
659
+ memcpy(scale, func->scale, k * sizeof(double));
660
+ ok = gTrue;
661
+ }
662
+
663
+ StitchingFunction::~StitchingFunction() {
664
+ int i;
665
+
666
+ if (funcs) {
667
+ for (i = 0; i < k; ++i) {
668
+ if (funcs[i]) {
669
+ delete funcs[i];
670
+ }
671
+ }
672
+ }
673
+ gfree(funcs);
674
+ gfree(bounds);
675
+ gfree(encode);
676
+ gfree(scale);
677
+ }
678
+
679
+ void StitchingFunction::transform(double *in, double *out) {
680
+ double x;
681
+ int i;
682
+
683
+ if (in[0] < domain[0][0]) {
684
+ x = domain[0][0];
685
+ } else if (in[0] > domain[0][1]) {
686
+ x = domain[0][1];
687
+ } else {
688
+ x = in[0];
689
+ }
690
+ for (i = 0; i < k - 1; ++i) {
691
+ if (x < bounds[i+1]) {
692
+ break;
693
+ }
694
+ }
695
+ x = encode[2*i] + (x - bounds[i]) * scale[i];
696
+ funcs[i]->transform(&x, out);
697
+ }
698
+
699
+ //------------------------------------------------------------------------
700
+ // PostScriptFunction
701
+ //------------------------------------------------------------------------
702
+
703
+ enum PSOp {
704
+ psOpAbs,
705
+ psOpAdd,
706
+ psOpAnd,
707
+ psOpAtan,
708
+ psOpBitshift,
709
+ psOpCeiling,
710
+ psOpCopy,
711
+ psOpCos,
712
+ psOpCvi,
713
+ psOpCvr,
714
+ psOpDiv,
715
+ psOpDup,
716
+ psOpEq,
717
+ psOpExch,
718
+ psOpExp,
719
+ psOpFalse,
720
+ psOpFloor,
721
+ psOpGe,
722
+ psOpGt,
723
+ psOpIdiv,
724
+ psOpIndex,
725
+ psOpLe,
726
+ psOpLn,
727
+ psOpLog,
728
+ psOpLt,
729
+ psOpMod,
730
+ psOpMul,
731
+ psOpNe,
732
+ psOpNeg,
733
+ psOpNot,
734
+ psOpOr,
735
+ psOpPop,
736
+ psOpRoll,
737
+ psOpRound,
738
+ psOpSin,
739
+ psOpSqrt,
740
+ psOpSub,
741
+ psOpTrue,
742
+ psOpTruncate,
743
+ psOpXor,
744
+ psOpIf,
745
+ psOpIfelse,
746
+ psOpReturn
747
+ };
748
+
749
+ // Note: 'if' and 'ifelse' are parsed separately.
750
+ // The rest are listed here in alphabetical order.
751
+ // The index in this table is equivalent to the entry in PSOp.
752
+ char *psOpNames[] = {
753
+ "abs",
754
+ "add",
755
+ "and",
756
+ "atan",
757
+ "bitshift",
758
+ "ceiling",
759
+ "copy",
760
+ "cos",
761
+ "cvi",
762
+ "cvr",
763
+ "div",
764
+ "dup",
765
+ "eq",
766
+ "exch",
767
+ "exp",
768
+ "false",
769
+ "floor",
770
+ "ge",
771
+ "gt",
772
+ "idiv",
773
+ "index",
774
+ "le",
775
+ "ln",
776
+ "log",
777
+ "lt",
778
+ "mod",
779
+ "mul",
780
+ "ne",
781
+ "neg",
782
+ "not",
783
+ "or",
784
+ "pop",
785
+ "roll",
786
+ "round",
787
+ "sin",
788
+ "sqrt",
789
+ "sub",
790
+ "true",
791
+ "truncate",
792
+ "xor"
793
+ };
794
+
795
+ #define nPSOps (sizeof(psOpNames) / sizeof(char *))
796
+
797
+ enum PSObjectType {
798
+ psBool,
799
+ psInt,
800
+ psReal,
801
+ psOperator,
802
+ psBlock
803
+ };
804
+
805
+ // In the code array, 'if'/'ifelse' operators take up three slots
806
+ // plus space for the code in the subclause(s).
807
+ //
808
+ // +---------------------------------+
809
+ // | psOperator: psOpIf / psOpIfelse |
810
+ // +---------------------------------+
811
+ // | psBlock: ptr=<A> |
812
+ // +---------------------------------+
813
+ // | psBlock: ptr=<B> |
814
+ // +---------------------------------+
815
+ // | if clause |
816
+ // | ... |
817
+ // | psOperator: psOpReturn |
818
+ // +---------------------------------+
819
+ // <A> | else clause |
820
+ // | ... |
821
+ // | psOperator: psOpReturn |
822
+ // +---------------------------------+
823
+ // <B> | ... |
824
+ //
825
+ // For 'if', pointer <A> is present in the code stream but unused.
826
+
827
+ struct PSObject {
828
+ PSObjectType type;
829
+ union {
830
+ GBool booln; // boolean (stack only)
831
+ int intg; // integer (stack and code)
832
+ double real; // real (stack and code)
833
+ PSOp op; // operator (code only)
834
+ int blk; // if/ifelse block pointer (code only)
835
+ };
836
+ };
837
+
838
+ #define psStackSize 100
839
+
840
+ class PSStack {
841
+ public:
842
+
843
+ PSStack() { sp = psStackSize; }
844
+ void pushBool(GBool booln);
845
+ void pushInt(int intg);
846
+ void pushReal(double real);
847
+ GBool popBool();
848
+ int popInt();
849
+ double popNum();
850
+ GBool empty() { return sp == psStackSize; }
851
+ GBool topIsInt() { return sp < psStackSize && stack[sp].type == psInt; }
852
+ GBool topTwoAreInts()
853
+ { return sp < psStackSize - 1 &&
854
+ stack[sp].type == psInt &&
855
+ stack[sp+1].type == psInt; }
856
+ GBool topIsReal() { return sp < psStackSize && stack[sp].type == psReal; }
857
+ GBool topTwoAreNums()
858
+ { return sp < psStackSize - 1 &&
859
+ (stack[sp].type == psInt || stack[sp].type == psReal) &&
860
+ (stack[sp+1].type == psInt || stack[sp+1].type == psReal); }
861
+ void copy(int n);
862
+ void roll(int n, int j);
863
+ void index(int i);
864
+ void pop();
865
+
866
+ private:
867
+
868
+ GBool checkOverflow(int n = 1);
869
+ GBool checkUnderflow();
870
+ GBool checkType(PSObjectType t1, PSObjectType t2);
871
+
872
+ PSObject stack[psStackSize];
873
+ int sp;
874
+ };
875
+
876
+ GBool PSStack::checkOverflow(int n) {
877
+ if (sp - n < 0) {
878
+ error(-1, "Stack overflow in PostScript function");
879
+ return gFalse;
880
+ }
881
+ return gTrue;
882
+ }
883
+
884
+ GBool PSStack::checkUnderflow() {
885
+ if (sp == psStackSize) {
886
+ error(-1, "Stack underflow in PostScript function");
887
+ return gFalse;
888
+ }
889
+ return gTrue;
890
+ }
891
+
892
+ GBool PSStack::checkType(PSObjectType t1, PSObjectType t2) {
893
+ if (stack[sp].type != t1 && stack[sp].type != t2) {
894
+ error(-1, "Type mismatch in PostScript function");
895
+ return gFalse;
896
+ }
897
+ return gTrue;
898
+ }
899
+
900
+ void PSStack::pushBool(GBool booln) {
901
+ if (checkOverflow()) {
902
+ stack[--sp].type = psBool;
903
+ stack[sp].booln = booln;
904
+ }
905
+ }
906
+
907
+ void PSStack::pushInt(int intg) {
908
+ if (checkOverflow()) {
909
+ stack[--sp].type = psInt;
910
+ stack[sp].intg = intg;
911
+ }
912
+ }
913
+
914
+ void PSStack::pushReal(double real) {
915
+ if (checkOverflow()) {
916
+ stack[--sp].type = psReal;
917
+ stack[sp].real = real;
918
+ }
919
+ }
920
+
921
+ GBool PSStack::popBool() {
922
+ if (checkUnderflow() && checkType(psBool, psBool)) {
923
+ return stack[sp++].booln;
924
+ }
925
+ return gFalse;
926
+ }
927
+
928
+ int PSStack::popInt() {
929
+ if (checkUnderflow() && checkType(psInt, psInt)) {
930
+ return stack[sp++].intg;
931
+ }
932
+ return 0;
933
+ }
934
+
935
+ double PSStack::popNum() {
936
+ double ret;
937
+
938
+ if (checkUnderflow() && checkType(psInt, psReal)) {
939
+ ret = (stack[sp].type == psInt) ? (double)stack[sp].intg : stack[sp].real;
940
+ ++sp;
941
+ return ret;
942
+ }
943
+ return 0;
944
+ }
945
+
946
+ void PSStack::copy(int n) {
947
+ int i;
948
+
949
+ if (sp + n > psStackSize) {
950
+ error(-1, "Stack underflow in PostScript function");
951
+ return;
952
+ }
953
+ if (!checkOverflow(n)) {
954
+ return;
955
+ }
956
+ for (i = sp + n - 1; i >= sp; --i) {
957
+ stack[i - n] = stack[i];
958
+ }
959
+ sp -= n;
960
+ }
961
+
962
+ void PSStack::roll(int n, int j) {
963
+ PSObject obj;
964
+ int i, k;
965
+
966
+ if (j >= 0) {
967
+ j %= n;
968
+ } else {
969
+ j = -j % n;
970
+ if (j != 0) {
971
+ j = n - j;
972
+ }
973
+ }
974
+ if (n <= 0 || j == 0) {
975
+ return;
976
+ }
977
+ for (i = 0; i < j; ++i) {
978
+ obj = stack[sp];
979
+ for (k = sp; k < sp + n - 1; ++k) {
980
+ stack[k] = stack[k+1];
981
+ }
982
+ stack[sp + n - 1] = obj;
983
+ }
984
+ }
985
+
986
+ void PSStack::index(int i) {
987
+ if (!checkOverflow()) {
988
+ return;
989
+ }
990
+ --sp;
991
+ stack[sp] = stack[sp + 1 + i];
992
+ }
993
+
994
+ void PSStack::pop() {
995
+ if (!checkUnderflow()) {
996
+ return;
997
+ }
998
+ ++sp;
999
+ }
1000
+
1001
+ PostScriptFunction::PostScriptFunction(Object *funcObj, Dict *dict) {
1002
+ Stream *str;
1003
+ int codePtr;
1004
+ GString *tok;
1005
+
1006
+ code = NULL;
1007
+ codeSize = 0;
1008
+ ok = gFalse;
1009
+
1010
+ //----- initialize the generic stuff
1011
+ if (!init(dict)) {
1012
+ goto err1;
1013
+ }
1014
+ if (!hasRange) {
1015
+ error(-1, "Type 4 function is missing range");
1016
+ goto err1;
1017
+ }
1018
+
1019
+ //----- get the stream
1020
+ if (!funcObj->isStream()) {
1021
+ error(-1, "Type 4 function isn't a stream");
1022
+ goto err1;
1023
+ }
1024
+ str = funcObj->getStream();
1025
+
1026
+ //----- parse the function
1027
+ codeString = new GString();
1028
+ str->reset();
1029
+ if (!(tok = getToken(str)) || tok->cmp("{")) {
1030
+ error(-1, "Expected '{' at start of PostScript function");
1031
+ if (tok) {
1032
+ delete tok;
1033
+ }
1034
+ goto err1;
1035
+ }
1036
+ delete tok;
1037
+ codePtr = 0;
1038
+ if (!parseCode(str, &codePtr)) {
1039
+ goto err2;
1040
+ }
1041
+ str->close();
1042
+
1043
+ ok = gTrue;
1044
+
1045
+ err2:
1046
+ str->close();
1047
+ err1:
1048
+ return;
1049
+ }
1050
+
1051
+ PostScriptFunction::PostScriptFunction(PostScriptFunction *func) {
1052
+ memcpy(this, func, sizeof(PostScriptFunction));
1053
+ code = (PSObject *)gmallocn(codeSize, sizeof(PSObject));
1054
+ memcpy(code, func->code, codeSize * sizeof(PSObject));
1055
+ codeString = func->codeString->copy();
1056
+ }
1057
+
1058
+ PostScriptFunction::~PostScriptFunction() {
1059
+ gfree(code);
1060
+ delete codeString;
1061
+ }
1062
+
1063
+ void PostScriptFunction::transform(double *in, double *out) {
1064
+ PSStack *stack;
1065
+ int i;
1066
+
1067
+ stack = new PSStack();
1068
+ for (i = 0; i < m; ++i) {
1069
+ //~ may need to check for integers here
1070
+ stack->pushReal(in[i]);
1071
+ }
1072
+ exec(stack, 0);
1073
+ for (i = n - 1; i >= 0; --i) {
1074
+ out[i] = stack->popNum();
1075
+ if (out[i] < range[i][0]) {
1076
+ out[i] = range[i][0];
1077
+ } else if (out[i] > range[i][1]) {
1078
+ out[i] = range[i][1];
1079
+ }
1080
+ }
1081
+ // if (!stack->empty()) {
1082
+ // error(-1, "Extra values on stack at end of PostScript function");
1083
+ // }
1084
+ delete stack;
1085
+ }
1086
+
1087
+ GBool PostScriptFunction::parseCode(Stream *str, int *codePtr) {
1088
+ GString *tok;
1089
+ char *p;
1090
+ GBool isReal;
1091
+ int opPtr, elsePtr;
1092
+ int a, b, mid, cmp;
1093
+
1094
+ while (1) {
1095
+ if (!(tok = getToken(str))) {
1096
+ error(-1, "Unexpected end of PostScript function stream");
1097
+ return gFalse;
1098
+ }
1099
+ p = tok->getCString();
1100
+ if (isdigit(*p) || *p == '.' || *p == '-') {
1101
+ isReal = gFalse;
1102
+ for (++p; *p; ++p) {
1103
+ if (*p == '.') {
1104
+ isReal = gTrue;
1105
+ break;
1106
+ }
1107
+ }
1108
+ resizeCode(*codePtr);
1109
+ if (isReal) {
1110
+ code[*codePtr].type = psReal;
1111
+ code[*codePtr].real = atof(tok->getCString());
1112
+ } else {
1113
+ code[*codePtr].type = psInt;
1114
+ code[*codePtr].intg = atoi(tok->getCString());
1115
+ }
1116
+ ++*codePtr;
1117
+ delete tok;
1118
+ } else if (!tok->cmp("{")) {
1119
+ delete tok;
1120
+ opPtr = *codePtr;
1121
+ *codePtr += 3;
1122
+ resizeCode(opPtr + 2);
1123
+ if (!parseCode(str, codePtr)) {
1124
+ return gFalse;
1125
+ }
1126
+ if (!(tok = getToken(str))) {
1127
+ error(-1, "Unexpected end of PostScript function stream");
1128
+ return gFalse;
1129
+ }
1130
+ if (!tok->cmp("{")) {
1131
+ elsePtr = *codePtr;
1132
+ if (!parseCode(str, codePtr)) {
1133
+ return gFalse;
1134
+ }
1135
+ delete tok;
1136
+ if (!(tok = getToken(str))) {
1137
+ error(-1, "Unexpected end of PostScript function stream");
1138
+ return gFalse;
1139
+ }
1140
+ } else {
1141
+ elsePtr = -1;
1142
+ }
1143
+ if (!tok->cmp("if")) {
1144
+ if (elsePtr >= 0) {
1145
+ error(-1, "Got 'if' operator with two blocks in PostScript function");
1146
+ return gFalse;
1147
+ }
1148
+ code[opPtr].type = psOperator;
1149
+ code[opPtr].op = psOpIf;
1150
+ code[opPtr+2].type = psBlock;
1151
+ code[opPtr+2].blk = *codePtr;
1152
+ } else if (!tok->cmp("ifelse")) {
1153
+ if (elsePtr < 0) {
1154
+ error(-1, "Got 'ifelse' operator with one blocks in PostScript function");
1155
+ return gFalse;
1156
+ }
1157
+ code[opPtr].type = psOperator;
1158
+ code[opPtr].op = psOpIfelse;
1159
+ code[opPtr+1].type = psBlock;
1160
+ code[opPtr+1].blk = elsePtr;
1161
+ code[opPtr+2].type = psBlock;
1162
+ code[opPtr+2].blk = *codePtr;
1163
+ } else {
1164
+ error(-1, "Expected if/ifelse operator in PostScript function");
1165
+ delete tok;
1166
+ return gFalse;
1167
+ }
1168
+ delete tok;
1169
+ } else if (!tok->cmp("}")) {
1170
+ delete tok;
1171
+ resizeCode(*codePtr);
1172
+ code[*codePtr].type = psOperator;
1173
+ code[*codePtr].op = psOpReturn;
1174
+ ++*codePtr;
1175
+ break;
1176
+ } else {
1177
+ a = -1;
1178
+ b = nPSOps;
1179
+ // invariant: psOpNames[a] < tok < psOpNames[b]
1180
+ while (b - a > 1) {
1181
+ mid = (a + b) / 2;
1182
+ cmp = tok->cmp(psOpNames[mid]);
1183
+ if (cmp > 0) {
1184
+ a = mid;
1185
+ } else if (cmp < 0) {
1186
+ b = mid;
1187
+ } else {
1188
+ a = b = mid;
1189
+ }
1190
+ }
1191
+ if (cmp != 0) {
1192
+ error(-1, "Unknown operator '%s' in PostScript function",
1193
+ tok->getCString());
1194
+ delete tok;
1195
+ return gFalse;
1196
+ }
1197
+ delete tok;
1198
+ resizeCode(*codePtr);
1199
+ code[*codePtr].type = psOperator;
1200
+ code[*codePtr].op = (PSOp)a;
1201
+ ++*codePtr;
1202
+ }
1203
+ }
1204
+ return gTrue;
1205
+ }
1206
+
1207
+ GString *PostScriptFunction::getToken(Stream *str) {
1208
+ GString *s;
1209
+ int c;
1210
+ GBool comment;
1211
+
1212
+ s = new GString();
1213
+ comment = gFalse;
1214
+ while (1) {
1215
+ if ((c = str->getChar()) == EOF) {
1216
+ break;
1217
+ }
1218
+ codeString->append(c);
1219
+ if (comment) {
1220
+ if (c == '\x0a' || c == '\x0d') {
1221
+ comment = gFalse;
1222
+ }
1223
+ } else if (c == '%') {
1224
+ comment = gTrue;
1225
+ } else if (!isspace(c)) {
1226
+ break;
1227
+ }
1228
+ }
1229
+ if (c == '{' || c == '}') {
1230
+ s->append((char)c);
1231
+ } else if (isdigit(c) || c == '.' || c == '-') {
1232
+ while (1) {
1233
+ s->append((char)c);
1234
+ c = str->lookChar();
1235
+ if (c == EOF || !(isdigit(c) || c == '.' || c == '-')) {
1236
+ break;
1237
+ }
1238
+ str->getChar();
1239
+ codeString->append(c);
1240
+ }
1241
+ } else {
1242
+ while (1) {
1243
+ s->append((char)c);
1244
+ c = str->lookChar();
1245
+ if (c == EOF || !isalnum(c)) {
1246
+ break;
1247
+ }
1248
+ str->getChar();
1249
+ codeString->append(c);
1250
+ }
1251
+ }
1252
+ return s;
1253
+ }
1254
+
1255
+ void PostScriptFunction::resizeCode(int newSize) {
1256
+ if (newSize >= codeSize) {
1257
+ codeSize += 64;
1258
+ code = (PSObject *)greallocn(code, codeSize, sizeof(PSObject));
1259
+ }
1260
+ }
1261
+
1262
+ void PostScriptFunction::exec(PSStack *stack, int codePtr) {
1263
+ int i1, i2;
1264
+ double r1, r2;
1265
+ GBool b1, b2;
1266
+
1267
+ while (1) {
1268
+ switch (code[codePtr].type) {
1269
+ case psInt:
1270
+ stack->pushInt(code[codePtr++].intg);
1271
+ break;
1272
+ case psReal:
1273
+ stack->pushReal(code[codePtr++].real);
1274
+ break;
1275
+ case psOperator:
1276
+ switch (code[codePtr++].op) {
1277
+ case psOpAbs:
1278
+ if (stack->topIsInt()) {
1279
+ stack->pushInt(abs(stack->popInt()));
1280
+ } else {
1281
+ stack->pushReal(fabs(stack->popNum()));
1282
+ }
1283
+ break;
1284
+ case psOpAdd:
1285
+ if (stack->topTwoAreInts()) {
1286
+ i2 = stack->popInt();
1287
+ i1 = stack->popInt();
1288
+ stack->pushInt(i1 + i2);
1289
+ } else {
1290
+ r2 = stack->popNum();
1291
+ r1 = stack->popNum();
1292
+ stack->pushReal(r1 + r2);
1293
+ }
1294
+ break;
1295
+ case psOpAnd:
1296
+ if (stack->topTwoAreInts()) {
1297
+ i2 = stack->popInt();
1298
+ i1 = stack->popInt();
1299
+ stack->pushInt(i1 & i2);
1300
+ } else {
1301
+ b2 = stack->popBool();
1302
+ b1 = stack->popBool();
1303
+ stack->pushBool(b1 && b2);
1304
+ }
1305
+ break;
1306
+ case psOpAtan:
1307
+ r2 = stack->popNum();
1308
+ r1 = stack->popNum();
1309
+ stack->pushReal(atan2(r1, r2));
1310
+ break;
1311
+ case psOpBitshift:
1312
+ i2 = stack->popInt();
1313
+ i1 = stack->popInt();
1314
+ if (i2 > 0) {
1315
+ stack->pushInt(i1 << i2);
1316
+ } else if (i2 < 0) {
1317
+ stack->pushInt((int)((Guint)i1 >> i2));
1318
+ } else {
1319
+ stack->pushInt(i1);
1320
+ }
1321
+ break;
1322
+ case psOpCeiling:
1323
+ if (!stack->topIsInt()) {
1324
+ stack->pushReal(ceil(stack->popNum()));
1325
+ }
1326
+ break;
1327
+ case psOpCopy:
1328
+ stack->copy(stack->popInt());
1329
+ break;
1330
+ case psOpCos:
1331
+ stack->pushReal(cos(stack->popNum()));
1332
+ break;
1333
+ case psOpCvi:
1334
+ if (!stack->topIsInt()) {
1335
+ stack->pushInt((int)stack->popNum());
1336
+ }
1337
+ break;
1338
+ case psOpCvr:
1339
+ if (!stack->topIsReal()) {
1340
+ stack->pushReal(stack->popNum());
1341
+ }
1342
+ break;
1343
+ case psOpDiv:
1344
+ r2 = stack->popNum();
1345
+ r1 = stack->popNum();
1346
+ stack->pushReal(r1 / r2);
1347
+ break;
1348
+ case psOpDup:
1349
+ stack->copy(1);
1350
+ break;
1351
+ case psOpEq:
1352
+ if (stack->topTwoAreInts()) {
1353
+ i2 = stack->popInt();
1354
+ i1 = stack->popInt();
1355
+ stack->pushBool(i1 == i2);
1356
+ } else if (stack->topTwoAreNums()) {
1357
+ r2 = stack->popNum();
1358
+ r1 = stack->popNum();
1359
+ stack->pushBool(r1 == r2);
1360
+ } else {
1361
+ b2 = stack->popBool();
1362
+ b1 = stack->popBool();
1363
+ stack->pushBool(b1 == b2);
1364
+ }
1365
+ break;
1366
+ case psOpExch:
1367
+ stack->roll(2, 1);
1368
+ break;
1369
+ case psOpExp:
1370
+ r2 = stack->popNum();
1371
+ r1 = stack->popNum();
1372
+ stack->pushReal(pow(r1, r2));
1373
+ break;
1374
+ case psOpFalse:
1375
+ stack->pushBool(gFalse);
1376
+ break;
1377
+ case psOpFloor:
1378
+ if (!stack->topIsInt()) {
1379
+ stack->pushReal(floor(stack->popNum()));
1380
+ }
1381
+ break;
1382
+ case psOpGe:
1383
+ if (stack->topTwoAreInts()) {
1384
+ i2 = stack->popInt();
1385
+ i1 = stack->popInt();
1386
+ stack->pushBool(i1 >= i2);
1387
+ } else {
1388
+ r2 = stack->popNum();
1389
+ r1 = stack->popNum();
1390
+ stack->pushBool(r1 >= r2);
1391
+ }
1392
+ break;
1393
+ case psOpGt:
1394
+ if (stack->topTwoAreInts()) {
1395
+ i2 = stack->popInt();
1396
+ i1 = stack->popInt();
1397
+ stack->pushBool(i1 > i2);
1398
+ } else {
1399
+ r2 = stack->popNum();
1400
+ r1 = stack->popNum();
1401
+ stack->pushBool(r1 > r2);
1402
+ }
1403
+ break;
1404
+ case psOpIdiv:
1405
+ i2 = stack->popInt();
1406
+ i1 = stack->popInt();
1407
+ stack->pushInt(i1 / i2);
1408
+ break;
1409
+ case psOpIndex:
1410
+ stack->index(stack->popInt());
1411
+ break;
1412
+ case psOpLe:
1413
+ if (stack->topTwoAreInts()) {
1414
+ i2 = stack->popInt();
1415
+ i1 = stack->popInt();
1416
+ stack->pushBool(i1 <= i2);
1417
+ } else {
1418
+ r2 = stack->popNum();
1419
+ r1 = stack->popNum();
1420
+ stack->pushBool(r1 <= r2);
1421
+ }
1422
+ break;
1423
+ case psOpLn:
1424
+ stack->pushReal(log(stack->popNum()));
1425
+ break;
1426
+ case psOpLog:
1427
+ stack->pushReal(log10(stack->popNum()));
1428
+ break;
1429
+ case psOpLt:
1430
+ if (stack->topTwoAreInts()) {
1431
+ i2 = stack->popInt();
1432
+ i1 = stack->popInt();
1433
+ stack->pushBool(i1 < i2);
1434
+ } else {
1435
+ r2 = stack->popNum();
1436
+ r1 = stack->popNum();
1437
+ stack->pushBool(r1 < r2);
1438
+ }
1439
+ break;
1440
+ case psOpMod:
1441
+ i2 = stack->popInt();
1442
+ i1 = stack->popInt();
1443
+ stack->pushInt(i1 % i2);
1444
+ break;
1445
+ case psOpMul:
1446
+ if (stack->topTwoAreInts()) {
1447
+ i2 = stack->popInt();
1448
+ i1 = stack->popInt();
1449
+ //~ should check for out-of-range, and push a real instead
1450
+ stack->pushInt(i1 * i2);
1451
+ } else {
1452
+ r2 = stack->popNum();
1453
+ r1 = stack->popNum();
1454
+ stack->pushReal(r1 * r2);
1455
+ }
1456
+ break;
1457
+ case psOpNe:
1458
+ if (stack->topTwoAreInts()) {
1459
+ i2 = stack->popInt();
1460
+ i1 = stack->popInt();
1461
+ stack->pushBool(i1 != i2);
1462
+ } else if (stack->topTwoAreNums()) {
1463
+ r2 = stack->popNum();
1464
+ r1 = stack->popNum();
1465
+ stack->pushBool(r1 != r2);
1466
+ } else {
1467
+ b2 = stack->popBool();
1468
+ b1 = stack->popBool();
1469
+ stack->pushBool(b1 != b2);
1470
+ }
1471
+ break;
1472
+ case psOpNeg:
1473
+ if (stack->topIsInt()) {
1474
+ stack->pushInt(-stack->popInt());
1475
+ } else {
1476
+ stack->pushReal(-stack->popNum());
1477
+ }
1478
+ break;
1479
+ case psOpNot:
1480
+ if (stack->topIsInt()) {
1481
+ stack->pushInt(~stack->popInt());
1482
+ } else {
1483
+ stack->pushBool(!stack->popBool());
1484
+ }
1485
+ break;
1486
+ case psOpOr:
1487
+ if (stack->topTwoAreInts()) {
1488
+ i2 = stack->popInt();
1489
+ i1 = stack->popInt();
1490
+ stack->pushInt(i1 | i2);
1491
+ } else {
1492
+ b2 = stack->popBool();
1493
+ b1 = stack->popBool();
1494
+ stack->pushBool(b1 || b2);
1495
+ }
1496
+ break;
1497
+ case psOpPop:
1498
+ stack->pop();
1499
+ break;
1500
+ case psOpRoll:
1501
+ i2 = stack->popInt();
1502
+ i1 = stack->popInt();
1503
+ stack->roll(i1, i2);
1504
+ break;
1505
+ case psOpRound:
1506
+ if (!stack->topIsInt()) {
1507
+ r1 = stack->popNum();
1508
+ stack->pushReal((r1 >= 0) ? floor(r1 + 0.5) : ceil(r1 - 0.5));
1509
+ }
1510
+ break;
1511
+ case psOpSin:
1512
+ stack->pushReal(sin(stack->popNum()));
1513
+ break;
1514
+ case psOpSqrt:
1515
+ stack->pushReal(sqrt(stack->popNum()));
1516
+ break;
1517
+ case psOpSub:
1518
+ if (stack->topTwoAreInts()) {
1519
+ i2 = stack->popInt();
1520
+ i1 = stack->popInt();
1521
+ stack->pushInt(i1 - i2);
1522
+ } else {
1523
+ r2 = stack->popNum();
1524
+ r1 = stack->popNum();
1525
+ stack->pushReal(r1 - r2);
1526
+ }
1527
+ break;
1528
+ case psOpTrue:
1529
+ stack->pushBool(gTrue);
1530
+ break;
1531
+ case psOpTruncate:
1532
+ if (!stack->topIsInt()) {
1533
+ r1 = stack->popNum();
1534
+ stack->pushReal((r1 >= 0) ? floor(r1) : ceil(r1));
1535
+ }
1536
+ break;
1537
+ case psOpXor:
1538
+ if (stack->topTwoAreInts()) {
1539
+ i2 = stack->popInt();
1540
+ i1 = stack->popInt();
1541
+ stack->pushInt(i1 ^ i2);
1542
+ } else {
1543
+ b2 = stack->popBool();
1544
+ b1 = stack->popBool();
1545
+ stack->pushBool(b1 ^ b2);
1546
+ }
1547
+ break;
1548
+ case psOpIf:
1549
+ b1 = stack->popBool();
1550
+ if (b1) {
1551
+ exec(stack, codePtr + 2);
1552
+ }
1553
+ codePtr = code[codePtr + 1].blk;
1554
+ break;
1555
+ case psOpIfelse:
1556
+ b1 = stack->popBool();
1557
+ if (b1) {
1558
+ exec(stack, codePtr + 2);
1559
+ } else {
1560
+ exec(stack, code[codePtr].blk);
1561
+ }
1562
+ codePtr = code[codePtr + 1].blk;
1563
+ break;
1564
+ case psOpReturn:
1565
+ return;
1566
+ }
1567
+ break;
1568
+ default:
1569
+ error(-1, "Internal: bad object in PostScript function code");
1570
+ break;
1571
+ }
1572
+ }
1573
+ }