hexapdf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (346) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTERS +3 -0
  3. data/LICENSE +26 -0
  4. data/README.md +88 -0
  5. data/Rakefile +121 -0
  6. data/VERSION +1 -0
  7. data/agpl-3.0.txt +661 -0
  8. data/bin/hexapdf +6 -0
  9. data/data/hexapdf/afm/Courier-Bold.afm +342 -0
  10. data/data/hexapdf/afm/Courier-BoldOblique.afm +342 -0
  11. data/data/hexapdf/afm/Courier-Oblique.afm +342 -0
  12. data/data/hexapdf/afm/Courier.afm +342 -0
  13. data/data/hexapdf/afm/Helvetica-Bold.afm +2827 -0
  14. data/data/hexapdf/afm/Helvetica-BoldOblique.afm +2827 -0
  15. data/data/hexapdf/afm/Helvetica-Oblique.afm +3051 -0
  16. data/data/hexapdf/afm/Helvetica.afm +3051 -0
  17. data/data/hexapdf/afm/MustRead.html +1 -0
  18. data/data/hexapdf/afm/Symbol.afm +213 -0
  19. data/data/hexapdf/afm/Times-Bold.afm +2588 -0
  20. data/data/hexapdf/afm/Times-BoldItalic.afm +2384 -0
  21. data/data/hexapdf/afm/Times-Italic.afm +2667 -0
  22. data/data/hexapdf/afm/Times-Roman.afm +2419 -0
  23. data/data/hexapdf/afm/ZapfDingbats.afm +225 -0
  24. data/data/hexapdf/encoding/glyphlist.txt +4305 -0
  25. data/data/hexapdf/encoding/zapfdingbats.txt +225 -0
  26. data/examples/arc.rb +50 -0
  27. data/examples/graphics.rb +274 -0
  28. data/examples/hello_world.rb +16 -0
  29. data/examples/machupicchu.jpg +0 -0
  30. data/examples/merging.rb +24 -0
  31. data/examples/optimizing.rb +20 -0
  32. data/examples/show_char_bboxes.rb +55 -0
  33. data/examples/standard_pdf_fonts.rb +72 -0
  34. data/examples/truetype.rb +45 -0
  35. data/lib/hexapdf/cli/extract.rb +128 -0
  36. data/lib/hexapdf/cli/info.rb +121 -0
  37. data/lib/hexapdf/cli/inspect.rb +157 -0
  38. data/lib/hexapdf/cli/modify.rb +218 -0
  39. data/lib/hexapdf/cli.rb +121 -0
  40. data/lib/hexapdf/configuration.rb +392 -0
  41. data/lib/hexapdf/content/canvas.rb +1974 -0
  42. data/lib/hexapdf/content/color_space.rb +364 -0
  43. data/lib/hexapdf/content/graphic_object/arc.rb +267 -0
  44. data/lib/hexapdf/content/graphic_object/endpoint_arc.rb +208 -0
  45. data/lib/hexapdf/content/graphic_object/solid_arc.rb +173 -0
  46. data/lib/hexapdf/content/graphic_object.rb +81 -0
  47. data/lib/hexapdf/content/graphics_state.rb +579 -0
  48. data/lib/hexapdf/content/operator.rb +1072 -0
  49. data/lib/hexapdf/content/parser.rb +204 -0
  50. data/lib/hexapdf/content/processor.rb +451 -0
  51. data/lib/hexapdf/content/transformation_matrix.rb +172 -0
  52. data/lib/hexapdf/content.rb +47 -0
  53. data/lib/hexapdf/data_dir.rb +51 -0
  54. data/lib/hexapdf/dictionary.rb +303 -0
  55. data/lib/hexapdf/dictionary_fields.rb +382 -0
  56. data/lib/hexapdf/document.rb +589 -0
  57. data/lib/hexapdf/document_utils.rb +209 -0
  58. data/lib/hexapdf/encryption/aes.rb +206 -0
  59. data/lib/hexapdf/encryption/arc4.rb +93 -0
  60. data/lib/hexapdf/encryption/fast_aes.rb +79 -0
  61. data/lib/hexapdf/encryption/fast_arc4.rb +67 -0
  62. data/lib/hexapdf/encryption/identity.rb +63 -0
  63. data/lib/hexapdf/encryption/ruby_aes.rb +447 -0
  64. data/lib/hexapdf/encryption/ruby_arc4.rb +96 -0
  65. data/lib/hexapdf/encryption/security_handler.rb +494 -0
  66. data/lib/hexapdf/encryption/standard_security_handler.rb +616 -0
  67. data/lib/hexapdf/encryption.rb +94 -0
  68. data/lib/hexapdf/error.rb +73 -0
  69. data/lib/hexapdf/filter/ascii85_decode.rb +160 -0
  70. data/lib/hexapdf/filter/ascii_hex_decode.rb +87 -0
  71. data/lib/hexapdf/filter/dct_decode.rb +57 -0
  72. data/lib/hexapdf/filter/encryption.rb +59 -0
  73. data/lib/hexapdf/filter/flate_decode.rb +93 -0
  74. data/lib/hexapdf/filter/jpx_decode.rb +56 -0
  75. data/lib/hexapdf/filter/lzw_decode.rb +191 -0
  76. data/lib/hexapdf/filter/predictor.rb +266 -0
  77. data/lib/hexapdf/filter/run_length_decode.rb +108 -0
  78. data/lib/hexapdf/filter.rb +176 -0
  79. data/lib/hexapdf/font/cmap/parser.rb +146 -0
  80. data/lib/hexapdf/font/cmap/writer.rb +176 -0
  81. data/lib/hexapdf/font/cmap.rb +90 -0
  82. data/lib/hexapdf/font/encoding/base.rb +77 -0
  83. data/lib/hexapdf/font/encoding/difference_encoding.rb +64 -0
  84. data/lib/hexapdf/font/encoding/glyph_list.rb +150 -0
  85. data/lib/hexapdf/font/encoding/mac_expert_encoding.rb +221 -0
  86. data/lib/hexapdf/font/encoding/mac_roman_encoding.rb +265 -0
  87. data/lib/hexapdf/font/encoding/standard_encoding.rb +205 -0
  88. data/lib/hexapdf/font/encoding/symbol_encoding.rb +244 -0
  89. data/lib/hexapdf/font/encoding/win_ansi_encoding.rb +280 -0
  90. data/lib/hexapdf/font/encoding/zapf_dingbats_encoding.rb +250 -0
  91. data/lib/hexapdf/font/encoding.rb +68 -0
  92. data/lib/hexapdf/font/true_type/font.rb +179 -0
  93. data/lib/hexapdf/font/true_type/table/cmap.rb +103 -0
  94. data/lib/hexapdf/font/true_type/table/cmap_subtable.rb +384 -0
  95. data/lib/hexapdf/font/true_type/table/directory.rb +92 -0
  96. data/lib/hexapdf/font/true_type/table/glyf.rb +166 -0
  97. data/lib/hexapdf/font/true_type/table/head.rb +143 -0
  98. data/lib/hexapdf/font/true_type/table/hhea.rb +109 -0
  99. data/lib/hexapdf/font/true_type/table/hmtx.rb +79 -0
  100. data/lib/hexapdf/font/true_type/table/loca.rb +79 -0
  101. data/lib/hexapdf/font/true_type/table/maxp.rb +112 -0
  102. data/lib/hexapdf/font/true_type/table/name.rb +218 -0
  103. data/lib/hexapdf/font/true_type/table/os2.rb +200 -0
  104. data/lib/hexapdf/font/true_type/table/post.rb +230 -0
  105. data/lib/hexapdf/font/true_type/table.rb +155 -0
  106. data/lib/hexapdf/font/true_type.rb +48 -0
  107. data/lib/hexapdf/font/true_type_wrapper.rb +240 -0
  108. data/lib/hexapdf/font/type1/afm_parser.rb +230 -0
  109. data/lib/hexapdf/font/type1/character_metrics.rb +67 -0
  110. data/lib/hexapdf/font/type1/font.rb +123 -0
  111. data/lib/hexapdf/font/type1/font_metrics.rb +117 -0
  112. data/lib/hexapdf/font/type1/pfb_parser.rb +71 -0
  113. data/lib/hexapdf/font/type1.rb +52 -0
  114. data/lib/hexapdf/font/type1_wrapper.rb +193 -0
  115. data/lib/hexapdf/font_loader/from_configuration.rb +70 -0
  116. data/lib/hexapdf/font_loader/standard14.rb +98 -0
  117. data/lib/hexapdf/font_loader.rb +85 -0
  118. data/lib/hexapdf/font_utils.rb +89 -0
  119. data/lib/hexapdf/image_loader/jpeg.rb +166 -0
  120. data/lib/hexapdf/image_loader/pdf.rb +89 -0
  121. data/lib/hexapdf/image_loader/png.rb +410 -0
  122. data/lib/hexapdf/image_loader.rb +68 -0
  123. data/lib/hexapdf/importer.rb +139 -0
  124. data/lib/hexapdf/name_tree_node.rb +78 -0
  125. data/lib/hexapdf/number_tree_node.rb +67 -0
  126. data/lib/hexapdf/object.rb +363 -0
  127. data/lib/hexapdf/parser.rb +349 -0
  128. data/lib/hexapdf/rectangle.rb +99 -0
  129. data/lib/hexapdf/reference.rb +98 -0
  130. data/lib/hexapdf/revision.rb +206 -0
  131. data/lib/hexapdf/revisions.rb +194 -0
  132. data/lib/hexapdf/serializer.rb +326 -0
  133. data/lib/hexapdf/stream.rb +279 -0
  134. data/lib/hexapdf/task/dereference.rb +109 -0
  135. data/lib/hexapdf/task/optimize.rb +230 -0
  136. data/lib/hexapdf/task.rb +68 -0
  137. data/lib/hexapdf/tokenizer.rb +406 -0
  138. data/lib/hexapdf/type/catalog.rb +107 -0
  139. data/lib/hexapdf/type/embedded_file.rb +87 -0
  140. data/lib/hexapdf/type/file_specification.rb +232 -0
  141. data/lib/hexapdf/type/font.rb +81 -0
  142. data/lib/hexapdf/type/font_descriptor.rb +109 -0
  143. data/lib/hexapdf/type/font_simple.rb +190 -0
  144. data/lib/hexapdf/type/font_true_type.rb +47 -0
  145. data/lib/hexapdf/type/font_type1.rb +162 -0
  146. data/lib/hexapdf/type/form.rb +103 -0
  147. data/lib/hexapdf/type/graphics_state_parameter.rb +79 -0
  148. data/lib/hexapdf/type/image.rb +73 -0
  149. data/lib/hexapdf/type/info.rb +70 -0
  150. data/lib/hexapdf/type/names.rb +69 -0
  151. data/lib/hexapdf/type/object_stream.rb +224 -0
  152. data/lib/hexapdf/type/page.rb +355 -0
  153. data/lib/hexapdf/type/page_tree_node.rb +269 -0
  154. data/lib/hexapdf/type/resources.rb +212 -0
  155. data/lib/hexapdf/type/trailer.rb +128 -0
  156. data/lib/hexapdf/type/viewer_preferences.rb +73 -0
  157. data/lib/hexapdf/type/xref_stream.rb +204 -0
  158. data/lib/hexapdf/type.rb +67 -0
  159. data/lib/hexapdf/utils/bit_field.rb +87 -0
  160. data/lib/hexapdf/utils/bit_stream.rb +148 -0
  161. data/lib/hexapdf/utils/lru_cache.rb +65 -0
  162. data/lib/hexapdf/utils/math_helpers.rb +55 -0
  163. data/lib/hexapdf/utils/object_hash.rb +130 -0
  164. data/lib/hexapdf/utils/pdf_doc_encoding.rb +93 -0
  165. data/lib/hexapdf/utils/sorted_tree_node.rb +339 -0
  166. data/lib/hexapdf/version.rb +39 -0
  167. data/lib/hexapdf/writer.rb +199 -0
  168. data/lib/hexapdf/xref_section.rb +152 -0
  169. data/lib/hexapdf.rb +34 -0
  170. data/man/man1/hexapdf.1 +249 -0
  171. data/test/data/aes-test-vectors/CBCGFSbox-128-decrypt.data.gz +0 -0
  172. data/test/data/aes-test-vectors/CBCGFSbox-128-encrypt.data.gz +0 -0
  173. data/test/data/aes-test-vectors/CBCGFSbox-192-decrypt.data.gz +0 -0
  174. data/test/data/aes-test-vectors/CBCGFSbox-192-encrypt.data.gz +0 -0
  175. data/test/data/aes-test-vectors/CBCGFSbox-256-decrypt.data.gz +0 -0
  176. data/test/data/aes-test-vectors/CBCGFSbox-256-encrypt.data.gz +0 -0
  177. data/test/data/aes-test-vectors/CBCKeySbox-128-decrypt.data.gz +0 -0
  178. data/test/data/aes-test-vectors/CBCKeySbox-128-encrypt.data.gz +0 -0
  179. data/test/data/aes-test-vectors/CBCKeySbox-192-decrypt.data.gz +0 -0
  180. data/test/data/aes-test-vectors/CBCKeySbox-192-encrypt.data.gz +0 -0
  181. data/test/data/aes-test-vectors/CBCKeySbox-256-decrypt.data.gz +0 -0
  182. data/test/data/aes-test-vectors/CBCKeySbox-256-encrypt.data.gz +0 -0
  183. data/test/data/aes-test-vectors/CBCVarKey-128-decrypt.data.gz +0 -0
  184. data/test/data/aes-test-vectors/CBCVarKey-128-encrypt.data.gz +0 -0
  185. data/test/data/aes-test-vectors/CBCVarKey-192-decrypt.data.gz +0 -0
  186. data/test/data/aes-test-vectors/CBCVarKey-192-encrypt.data.gz +0 -0
  187. data/test/data/aes-test-vectors/CBCVarKey-256-decrypt.data.gz +0 -0
  188. data/test/data/aes-test-vectors/CBCVarKey-256-encrypt.data.gz +0 -0
  189. data/test/data/aes-test-vectors/CBCVarTxt-128-decrypt.data.gz +0 -0
  190. data/test/data/aes-test-vectors/CBCVarTxt-128-encrypt.data.gz +0 -0
  191. data/test/data/aes-test-vectors/CBCVarTxt-192-decrypt.data.gz +0 -0
  192. data/test/data/aes-test-vectors/CBCVarTxt-192-encrypt.data.gz +0 -0
  193. data/test/data/aes-test-vectors/CBCVarTxt-256-decrypt.data.gz +0 -0
  194. data/test/data/aes-test-vectors/CBCVarTxt-256-encrypt.data.gz +0 -0
  195. data/test/data/fonts/Ubuntu-Title.ttf +0 -0
  196. data/test/data/images/cmyk.jpg +0 -0
  197. data/test/data/images/fillbytes.jpg +0 -0
  198. data/test/data/images/gray.jpg +0 -0
  199. data/test/data/images/greyscale-1bit.png +0 -0
  200. data/test/data/images/greyscale-2bit.png +0 -0
  201. data/test/data/images/greyscale-4bit.png +0 -0
  202. data/test/data/images/greyscale-8bit.png +0 -0
  203. data/test/data/images/greyscale-alpha-8bit.png +0 -0
  204. data/test/data/images/greyscale-trns-8bit.png +0 -0
  205. data/test/data/images/greyscale-with-gamma1.0.png +0 -0
  206. data/test/data/images/greyscale-with-gamma1.5.png +0 -0
  207. data/test/data/images/indexed-1bit.png +0 -0
  208. data/test/data/images/indexed-2bit.png +0 -0
  209. data/test/data/images/indexed-4bit.png +0 -0
  210. data/test/data/images/indexed-8bit.png +0 -0
  211. data/test/data/images/indexed-alpha-4bit.png +0 -0
  212. data/test/data/images/indexed-alpha-8bit.png +0 -0
  213. data/test/data/images/rgb.jpg +0 -0
  214. data/test/data/images/truecolour-8bit.png +0 -0
  215. data/test/data/images/truecolour-alpha-8bit.png +0 -0
  216. data/test/data/images/truecolour-gama-chrm-8bit.png +0 -0
  217. data/test/data/images/truecolour-srgb-8bit.png +0 -0
  218. data/test/data/minimal.pdf +44 -0
  219. data/test/data/standard-security-handler/README +9 -0
  220. data/test/data/standard-security-handler/bothpwd-aes-128bit-V4.pdf +44 -0
  221. data/test/data/standard-security-handler/bothpwd-aes-256bit-V5.pdf +0 -0
  222. data/test/data/standard-security-handler/bothpwd-arc4-128bit-V2.pdf +43 -0
  223. data/test/data/standard-security-handler/bothpwd-arc4-128bit-V4.pdf +43 -0
  224. data/test/data/standard-security-handler/bothpwd-arc4-40bit-V1.pdf +0 -0
  225. data/test/data/standard-security-handler/nopwd-aes-128bit-V4.pdf +43 -0
  226. data/test/data/standard-security-handler/nopwd-aes-256bit-V5.pdf +0 -0
  227. data/test/data/standard-security-handler/nopwd-arc4-128bit-V2.pdf +43 -0
  228. data/test/data/standard-security-handler/nopwd-arc4-128bit-V4.pdf +43 -0
  229. data/test/data/standard-security-handler/nopwd-arc4-40bit-V1.pdf +43 -0
  230. data/test/data/standard-security-handler/ownerpwd-aes-128bit-V4.pdf +0 -0
  231. data/test/data/standard-security-handler/ownerpwd-aes-256bit-V5.pdf +43 -0
  232. data/test/data/standard-security-handler/ownerpwd-arc4-128bit-V2.pdf +43 -0
  233. data/test/data/standard-security-handler/ownerpwd-arc4-128bit-V4.pdf +43 -0
  234. data/test/data/standard-security-handler/ownerpwd-arc4-40bit-V1.pdf +43 -0
  235. data/test/data/standard-security-handler/userpwd-aes-128bit-V4.pdf +43 -0
  236. data/test/data/standard-security-handler/userpwd-aes-256bit-V5.pdf +43 -0
  237. data/test/data/standard-security-handler/userpwd-arc4-128bit-V2.pdf +0 -0
  238. data/test/data/standard-security-handler/userpwd-arc4-128bit-V4.pdf +0 -0
  239. data/test/data/standard-security-handler/userpwd-arc4-40bit-V1.pdf +43 -0
  240. data/test/hexapdf/common_tokenizer_tests.rb +204 -0
  241. data/test/hexapdf/content/common.rb +31 -0
  242. data/test/hexapdf/content/graphic_object/test_arc.rb +93 -0
  243. data/test/hexapdf/content/graphic_object/test_endpoint_arc.rb +91 -0
  244. data/test/hexapdf/content/graphic_object/test_solid_arc.rb +86 -0
  245. data/test/hexapdf/content/test_canvas.rb +1113 -0
  246. data/test/hexapdf/content/test_color_space.rb +97 -0
  247. data/test/hexapdf/content/test_graphics_state.rb +138 -0
  248. data/test/hexapdf/content/test_operator.rb +619 -0
  249. data/test/hexapdf/content/test_parser.rb +66 -0
  250. data/test/hexapdf/content/test_processor.rb +156 -0
  251. data/test/hexapdf/content/test_transformation_matrix.rb +64 -0
  252. data/test/hexapdf/encryption/common.rb +87 -0
  253. data/test/hexapdf/encryption/test_aes.rb +121 -0
  254. data/test/hexapdf/encryption/test_arc4.rb +39 -0
  255. data/test/hexapdf/encryption/test_fast_aes.rb +17 -0
  256. data/test/hexapdf/encryption/test_fast_arc4.rb +12 -0
  257. data/test/hexapdf/encryption/test_identity.rb +21 -0
  258. data/test/hexapdf/encryption/test_ruby_aes.rb +23 -0
  259. data/test/hexapdf/encryption/test_ruby_arc4.rb +20 -0
  260. data/test/hexapdf/encryption/test_security_handler.rb +356 -0
  261. data/test/hexapdf/encryption/test_standard_security_handler.rb +274 -0
  262. data/test/hexapdf/filter/common.rb +53 -0
  263. data/test/hexapdf/filter/test_ascii85_decode.rb +60 -0
  264. data/test/hexapdf/filter/test_ascii_hex_decode.rb +33 -0
  265. data/test/hexapdf/filter/test_encryption.rb +24 -0
  266. data/test/hexapdf/filter/test_flate_decode.rb +35 -0
  267. data/test/hexapdf/filter/test_lzw_decode.rb +52 -0
  268. data/test/hexapdf/filter/test_predictor.rb +183 -0
  269. data/test/hexapdf/filter/test_run_length_decode.rb +32 -0
  270. data/test/hexapdf/font/cmap/test_parser.rb +67 -0
  271. data/test/hexapdf/font/cmap/test_writer.rb +58 -0
  272. data/test/hexapdf/font/encoding/test_base.rb +35 -0
  273. data/test/hexapdf/font/encoding/test_difference_encoding.rb +21 -0
  274. data/test/hexapdf/font/encoding/test_glyph_list.rb +59 -0
  275. data/test/hexapdf/font/encoding/test_zapf_dingbats_encoding.rb +16 -0
  276. data/test/hexapdf/font/test_encoding.rb +27 -0
  277. data/test/hexapdf/font/test_true_type_wrapper.rb +110 -0
  278. data/test/hexapdf/font/test_type1_wrapper.rb +66 -0
  279. data/test/hexapdf/font/true_type/common.rb +19 -0
  280. data/test/hexapdf/font/true_type/table/test_cmap.rb +59 -0
  281. data/test/hexapdf/font/true_type/table/test_cmap_subtable.rb +133 -0
  282. data/test/hexapdf/font/true_type/table/test_directory.rb +35 -0
  283. data/test/hexapdf/font/true_type/table/test_glyf.rb +58 -0
  284. data/test/hexapdf/font/true_type/table/test_head.rb +76 -0
  285. data/test/hexapdf/font/true_type/table/test_hhea.rb +40 -0
  286. data/test/hexapdf/font/true_type/table/test_hmtx.rb +38 -0
  287. data/test/hexapdf/font/true_type/table/test_loca.rb +43 -0
  288. data/test/hexapdf/font/true_type/table/test_maxp.rb +62 -0
  289. data/test/hexapdf/font/true_type/table/test_name.rb +95 -0
  290. data/test/hexapdf/font/true_type/table/test_os2.rb +65 -0
  291. data/test/hexapdf/font/true_type/table/test_post.rb +89 -0
  292. data/test/hexapdf/font/true_type/test_font.rb +120 -0
  293. data/test/hexapdf/font/true_type/test_table.rb +41 -0
  294. data/test/hexapdf/font/type1/test_afm_parser.rb +51 -0
  295. data/test/hexapdf/font/type1/test_font.rb +68 -0
  296. data/test/hexapdf/font/type1/test_pfb_parser.rb +37 -0
  297. data/test/hexapdf/font_loader/test_from_configuration.rb +28 -0
  298. data/test/hexapdf/font_loader/test_standard14.rb +22 -0
  299. data/test/hexapdf/image_loader/test_jpeg.rb +83 -0
  300. data/test/hexapdf/image_loader/test_pdf.rb +47 -0
  301. data/test/hexapdf/image_loader/test_png.rb +258 -0
  302. data/test/hexapdf/task/test_dereference.rb +46 -0
  303. data/test/hexapdf/task/test_optimize.rb +137 -0
  304. data/test/hexapdf/test_configuration.rb +82 -0
  305. data/test/hexapdf/test_data_dir.rb +32 -0
  306. data/test/hexapdf/test_dictionary.rb +284 -0
  307. data/test/hexapdf/test_dictionary_fields.rb +185 -0
  308. data/test/hexapdf/test_document.rb +574 -0
  309. data/test/hexapdf/test_document_utils.rb +144 -0
  310. data/test/hexapdf/test_filter.rb +96 -0
  311. data/test/hexapdf/test_font_utils.rb +47 -0
  312. data/test/hexapdf/test_importer.rb +78 -0
  313. data/test/hexapdf/test_object.rb +177 -0
  314. data/test/hexapdf/test_parser.rb +394 -0
  315. data/test/hexapdf/test_rectangle.rb +36 -0
  316. data/test/hexapdf/test_reference.rb +41 -0
  317. data/test/hexapdf/test_revision.rb +139 -0
  318. data/test/hexapdf/test_revisions.rb +93 -0
  319. data/test/hexapdf/test_serializer.rb +169 -0
  320. data/test/hexapdf/test_stream.rb +262 -0
  321. data/test/hexapdf/test_tokenizer.rb +30 -0
  322. data/test/hexapdf/test_writer.rb +120 -0
  323. data/test/hexapdf/test_xref_section.rb +35 -0
  324. data/test/hexapdf/type/test_catalog.rb +30 -0
  325. data/test/hexapdf/type/test_embedded_file.rb +16 -0
  326. data/test/hexapdf/type/test_file_specification.rb +148 -0
  327. data/test/hexapdf/type/test_font.rb +35 -0
  328. data/test/hexapdf/type/test_font_descriptor.rb +51 -0
  329. data/test/hexapdf/type/test_font_simple.rb +190 -0
  330. data/test/hexapdf/type/test_font_type1.rb +128 -0
  331. data/test/hexapdf/type/test_form.rb +60 -0
  332. data/test/hexapdf/type/test_info.rb +14 -0
  333. data/test/hexapdf/type/test_names.rb +9 -0
  334. data/test/hexapdf/type/test_object_stream.rb +84 -0
  335. data/test/hexapdf/type/test_page.rb +260 -0
  336. data/test/hexapdf/type/test_page_tree_node.rb +255 -0
  337. data/test/hexapdf/type/test_resources.rb +167 -0
  338. data/test/hexapdf/type/test_trailer.rb +109 -0
  339. data/test/hexapdf/type/test_xref_stream.rb +131 -0
  340. data/test/hexapdf/utils/test_bit_field.rb +47 -0
  341. data/test/hexapdf/utils/test_lru_cache.rb +22 -0
  342. data/test/hexapdf/utils/test_object_hash.rb +115 -0
  343. data/test/hexapdf/utils/test_pdf_doc_encoding.rb +18 -0
  344. data/test/hexapdf/utils/test_sorted_tree_node.rb +232 -0
  345. data/test/test_helper.rb +56 -0
  346. metadata +427 -0
@@ -0,0 +1,89 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ #--
4
+ # This file is part of HexaPDF.
5
+ #
6
+ # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
+ # Copyright (C) 2016 Thomas Leitner
8
+ #
9
+ # HexaPDF is free software: you can redistribute it and/or modify it
10
+ # under the terms of the GNU Affero General Public License version 3 as
11
+ # published by the Free Software Foundation with the addition of the
12
+ # following permission added to Section 15 as permitted in Section 7(a):
13
+ # FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
14
+ # THOMAS LEITNER, THOMAS LEITNER DISCLAIMS THE WARRANTY OF NON
15
+ # INFRINGEMENT OF THIRD PARTY RIGHTS.
16
+ #
17
+ # HexaPDF is distributed in the hope that it will be useful, but WITHOUT
18
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
20
+ # License for more details.
21
+ #
22
+ # You should have received a copy of the GNU Affero General Public License
23
+ # along with HexaPDF. If not, see <http://www.gnu.org/licenses/>.
24
+ #
25
+ # The interactive user interfaces in modified source and object code
26
+ # versions of HexaPDF must display Appropriate Legal Notices, as required
27
+ # under Section 5 of the GNU Affero General Public License version 3.
28
+ #
29
+ # In accordance with Section 7(b) of the GNU Affero General Public
30
+ # License, a covered work must retain the producer line in every PDF that
31
+ # is created or manipulated using HexaPDF.
32
+ #++
33
+
34
+ require 'hexapdf/error'
35
+ require 'hexapdf/document'
36
+
37
+ module HexaPDF
38
+ module ImageLoader
39
+
40
+ # This module is used for loading the first page of a PDF file.
41
+ #
42
+ # Loaded PDF graphics are represented by form XObjects instead of image XObjects. However, the
43
+ # image/xobject drawing methods of HexaPDF::Content::Canvas know how to handle them correctly so
44
+ # that this doesn't matter from a user's point of view.
45
+ #
46
+ # See: PDF1.7 s8.10
47
+ module PDF
48
+
49
+ # The magic marker that tells us if the file/IO contains an PDF file.
50
+ MAGIC_FILE_MARKER = "%PDF-".b
51
+
52
+ # :call-seq:
53
+ # PDF.handles?(filename) -> true or false
54
+ # PDF.handles?(io) -> true or false
55
+ #
56
+ # Returns +true+ if the given file or IO stream can be handled, ie. if it contains an image
57
+ # in JPEG format.
58
+ def self.handles?(file_or_io)
59
+ if file_or_io.kind_of?(String)
60
+ File.read(file_or_io, 5, mode: 'rb') == MAGIC_FILE_MARKER
61
+ else
62
+ file_or_io.rewind
63
+ file_or_io.read(5) == MAGIC_FILE_MARKER
64
+ end
65
+ end
66
+
67
+ # :call-seq:
68
+ # PDF.load(document, filename) -> form_obj
69
+ # PDF.load(document, io) -> form_obj
70
+ #
71
+ # Creates a PDF form XObject from the PDF file or IO stream.
72
+ #
73
+ # See: DefaultConfiguration for the meaning of 'image_loader.pdf.use_stringio'.
74
+ def self.load(document, file_or_io)
75
+ idoc = if file_or_io.kind_of?(String) && document.config['image_loader.pdf.use_stringio']
76
+ HexaPDF::Document.open(file_or_io)
77
+ elsif file_or_io.kind_of?(String)
78
+ HexaPDF::Document.new(io: File.open(file_or_io, 'rb'))
79
+ else
80
+ HexaPDF::Document.new(io: file_or_io)
81
+ end
82
+ form = idoc.pages.page(0).to_form_xobject
83
+ document.add(document.import(form))
84
+ end
85
+
86
+ end
87
+
88
+ end
89
+ end
@@ -0,0 +1,410 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ #--
4
+ # This file is part of HexaPDF.
5
+ #
6
+ # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
+ # Copyright (C) 2016 Thomas Leitner
8
+ #
9
+ # HexaPDF is free software: you can redistribute it and/or modify it
10
+ # under the terms of the GNU Affero General Public License version 3 as
11
+ # published by the Free Software Foundation with the addition of the
12
+ # following permission added to Section 15 as permitted in Section 7(a):
13
+ # FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
14
+ # THOMAS LEITNER, THOMAS LEITNER DISCLAIMS THE WARRANTY OF NON
15
+ # INFRINGEMENT OF THIRD PARTY RIGHTS.
16
+ #
17
+ # HexaPDF is distributed in the hope that it will be useful, but WITHOUT
18
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
20
+ # License for more details.
21
+ #
22
+ # You should have received a copy of the GNU Affero General Public License
23
+ # along with HexaPDF. If not, see <http://www.gnu.org/licenses/>.
24
+ #
25
+ # The interactive user interfaces in modified source and object code
26
+ # versions of HexaPDF must display Appropriate Legal Notices, as required
27
+ # under Section 5 of the GNU Affero General Public License version 3.
28
+ #
29
+ # In accordance with Section 7(b) of the GNU Affero General Public
30
+ # License, a covered work must retain the producer line in every PDF that
31
+ # is created or manipulated using HexaPDF.
32
+ #++
33
+
34
+ require 'hexapdf/error'
35
+ require 'hexapdf/content/graphics_state'
36
+ require 'hexapdf/utils/bit_stream'
37
+
38
+ module HexaPDF
39
+ module ImageLoader
40
+
41
+ # This class is used for loading images in the PNG format from files or IO streams.
42
+ #
43
+ # It can handle all five types of PNG images: greyscale w/wo alpha, truecolor w/wo alpha and
44
+ # indexed-color. Furthermore, it recognizes the gAMA, cHRM, sRGB and tRNS chunks and handles
45
+ # them appropriately. However, Adam7 interlaced images are not supported!
46
+ #
47
+ # Note that greyscale, truecolor and indexed-color images with alpha need to be decoded to get
48
+ # the alpha channel which takes time.
49
+ #
50
+ # All PNG specification section references are in reference to http://www.w3.org/TR/PNG/.
51
+ #
52
+ # See: PDF1.7 s7.4.4., s8.9
53
+ class PNG
54
+
55
+ # The magic marker that tells us if the file/IO contains an image in PNG format.
56
+ #
57
+ # See: PNG s5.2
58
+ MAGIC_FILE_MARKER = "\x89PNG\r\n\x1A\n".b
59
+
60
+ # The color type for PNG greyscale images without alpha, see PNG s11.2.2
61
+ GREYSCALE = 0
62
+
63
+ # The color type for PNG truecolor images without alpha, see PNG s11.2.2
64
+ TRUECOLOR = 2
65
+
66
+ # The color type for PNG indexed images with/without alpha, see PNG s11.2.2
67
+ INDEXED = 3
68
+
69
+ # The color type for PNG greyscale images with alpha, see PNG s11.2.2
70
+ GREYSCALE_ALPHA = 4
71
+
72
+ # The color type for PNG truecolor images with alpha, see PNG s11.2.2
73
+ TRUECOLOR_ALPHA = 6
74
+
75
+ # Mapping from sRGB chunk rendering intent byte to PDF rendering intent name.
76
+ RENDERING_INTENT_MAP = {
77
+ 0 => Content::RenderingIntent::PERCEPTUAL,
78
+ 1 => Content::RenderingIntent::RELATIVE_COLORIMETRIC,
79
+ 2 => Content::RenderingIntent::SATURATION,
80
+ 3 => Content::RenderingIntent::ABSOLUTE_COLORIMETRIC,
81
+ }
82
+
83
+ # The primary chromaticities and white point used by the sRGB specification.
84
+ SRGB_CHRM = [0.3127, 0.329, 0.64, 0.33, 0.3, 0.6, 0.15, 0.06]
85
+
86
+ # :call-seq:
87
+ # PNG.handles?(filename) -> true or false
88
+ # PNG.handles?(io) -> true or false
89
+ #
90
+ # Returns +true+ if the given file or IO stream can be handled, ie. if it contains an image
91
+ # in PNG format.
92
+ def self.handles?(file_or_io)
93
+ if file_or_io.kind_of?(String)
94
+ File.read(file_or_io, 8, mode: 'rb') == MAGIC_FILE_MARKER
95
+ else
96
+ file_or_io.rewind
97
+ file_or_io.read(8) == MAGIC_FILE_MARKER
98
+ end
99
+ end
100
+
101
+ # :call-seq:
102
+ # PNG.load(document, filename) -> image_obj
103
+ # PNG.load(document, io) -> image_obj
104
+ #
105
+ # Creates a PDF image object from the PNG file or IO stream.
106
+ def self.load(document, file_or_io)
107
+ new(document, file_or_io).load
108
+ end
109
+
110
+ def initialize(document, io) #:nodoc:
111
+ @document = document
112
+ @io = io
113
+
114
+ @color_type = nil
115
+ @intent = nil
116
+ @chrm = nil
117
+ @gamma = nil
118
+ end
119
+
120
+ def load #:nodoc:
121
+ with_io do |io|
122
+ io.seek(8, IO::SEEK_SET)
123
+
124
+ dict = {
125
+ Type: :XObject,
126
+ Subtype: :Image,
127
+ }
128
+
129
+ while true
130
+ length, type = io.read(8).unpack('Na4') # PNG s5.3
131
+
132
+ case type
133
+ when 'IDAT' # PNG s11.2.4
134
+ idat_offset = io.pos - 8
135
+ break
136
+ when 'IHDR' # PNG s11.2.2
137
+ values = io.read(length).unpack('NNC5')
138
+ dict[:Width] = values[0]
139
+ dict[:Height] = values[1]
140
+ dict[:BitsPerComponent] = values[2]
141
+ @color_type = values[3]
142
+
143
+ if values[4] != 0
144
+ raise HexaPDF::Error, "Unsupported PNG compression method"
145
+ elsif values[5] != 0
146
+ raise HexaPDF::Error, "Unsupported PNG filter method"
147
+ elsif values[6] != 0
148
+ raise HexaPDF::Error, "Unsupported PNG interlace method"
149
+ end
150
+ when 'PLTE' # PNG s11.2.3
151
+ if @color_type == INDEXED
152
+ palette = io.read(length)
153
+ hival = (palette.size / 3) - 1
154
+ if dict[:BitsPerComponent] == 8
155
+ palette = @document.add({Filter: :FlateDecode}, stream: palette)
156
+ end
157
+ dict[:ColorSpace] = [:Indexed, color_space, hival, palette]
158
+ else
159
+ io.seek(length, IO::SEEK_CUR)
160
+ end
161
+ when 'tRNS' # PNG s11.3.2
162
+ if @color_type == INDEXED
163
+ trns = io.read(length).unpack('C*')
164
+ elsif @color_type == TRUECOLOR || @color_type == GREYSCALE
165
+ dict[:Mask] = io.read(length).unpack('n*').map {|val| [val, val]}.flatten
166
+ else
167
+ io.seek(length, IO::SEEK_CUR)
168
+ end
169
+ when 'sRGB' # PNG s11.3.3.5
170
+ @intent = io.read(length).unpack('C').first
171
+ dict[:Intent] = RENDERING_INTENT_MAP[@intent]
172
+ @chrm = SRGB_CHRM
173
+ @gamma = 2.2
174
+ when 'gAMA' # PNG s11.3.3.2
175
+ gamma = 100_000.0 / io.read(length).unpack('N').first
176
+ unless @intent || gamma == 1.0 # sRGB trumps gAMA
177
+ @gamma = gamma
178
+ @chrm ||= SRGB_CHRM # don't overwrite data from a cHRM chunk
179
+ end
180
+ when 'cHRM' # PNG s11.3.3.1
181
+ chrm = io.read(length)
182
+ @chrm = chrm.unpack('N8').map {|v| v / 100_000.0} unless @intent # sRGB trumps cHRM
183
+ else
184
+ io.seek(length, IO::SEEK_CUR)
185
+ end
186
+
187
+ io.seek(4, IO::SEEK_CUR) # don't check the CRC
188
+ end
189
+
190
+ dict[:ColorSpace] ||= color_space
191
+
192
+ decode_parms = {
193
+ Predictor: 15,
194
+ Colors: @color_type == TRUECOLOR || @color_type == TRUECOLOR_ALPHA ? 3 : 1,
195
+ BitsPerComponent: dict[:BitsPerComponent],
196
+ Columns: dict[:Width],
197
+ }
198
+
199
+ if @color_type == TRUECOLOR_ALPHA || @color_type == GREYSCALE_ALPHA
200
+ image_data, mask_data = separate_alpha_channel(idat_offset, decode_parms)
201
+ add_smask_image(dict, mask_data)
202
+ stream = HexaPDF::StreamData.new(lambda { image_data },
203
+ filter: :FlateDecode,
204
+ decode_parms: decode_parms)
205
+ else
206
+ if @color_type == INDEXED && trns
207
+ mask_data = alpha_mask_for_indexed_image(idat_offset, decode_parms, trns)
208
+ add_smask_image(dict, mask_data, from_indexed: true)
209
+ end
210
+ stream = HexaPDF::StreamData.new(image_data_proc(idat_offset),
211
+ filter: :FlateDecode,
212
+ decode_parms: decode_parms)
213
+ end
214
+
215
+ obj = @document.add(dict, stream: stream)
216
+ obj.set_filter(:FlateDecode, decode_parms)
217
+ obj
218
+ end
219
+ end
220
+
221
+ private
222
+
223
+ # Yields the IO object for reading the PNG image.
224
+ #
225
+ # Automatically handles files and IO streams.
226
+ def with_io
227
+ io = (@io.kind_of?(String) ? File.new(@io, 'rb') : @io)
228
+ yield(io)
229
+ ensure
230
+ io.close if @io.kind_of?(String)
231
+ end
232
+
233
+ # Returns the PDF color space definition that should be used with the PDF image of the PNG
234
+ # file.
235
+ #
236
+ # In the case of an indexed PNG image, this returns the definition for the color space
237
+ # underlying the palette.
238
+ def color_space
239
+ if @color_type == GREYSCALE || @color_type == GREYSCALE_ALPHA
240
+ if @gamma
241
+ [:CalGray, {WhitePoint: [1.0, 1.0, 1.0], Gamma: @gamma}]
242
+ else
243
+ :DeviceGray
244
+ end
245
+ elsif @gamma || @chrm
246
+ dict = @chrm ? calrgb_definition_from_chrm(*@chrm) : {}
247
+ if @gamma
248
+ dict[:Gamma] = [@gamma, @gamma, @gamma]
249
+ dict[:WhitePoint] ||= [1.0, 1.0, 1.0]
250
+ end
251
+ [:CalRGB, dict]
252
+ else
253
+ :DeviceRGB
254
+ end
255
+ end
256
+
257
+ # Returns a hash for a CalRGB color space definition using the x,y chromaticity coordinates
258
+ # of the white point and the red, green and blue primaries.
259
+ #
260
+ # See: PDF1.7 s8.6.5.3
261
+ def calrgb_definition_from_chrm(xw, yw, xr, yr, xg, yg, xb, yb)
262
+ z = yw * ((xg - xb) * yr - (xr - xb) * yg + (xr - xg) * yb)
263
+
264
+ mya = yr * ((xg - xb) * yw - (xw - xb) * yg + (xw - xg) * yb) / z
265
+ mxa = mya * xr / yr
266
+ mza = mya * ((1 - xr) / yr - 1)
267
+
268
+ myb = - (yg * ((xr - xb) * yw - (xw - xb) * yr + (xw - xr) * yb)) / z
269
+ mxb = myb * xg / yg
270
+ mzb = myb * ((1 - xg) / yg - 1)
271
+ myc = yb * ((xr - xg) * yw - (xw - xg) * yr + (xw - xr) * yg) / z
272
+ mxc = myc * xb / yb
273
+ mzc = myc * ((1 - xb) / yb - 1)
274
+
275
+ mxw = mxa + mxb + mxc
276
+ myw = 1.0 # mya + myb + myc
277
+ mzw = mza + mzb + mzc
278
+
279
+ {WhitePoint: [mxw, myw, mzw], Matrix: [mxa, mya, mza, mxb, myb, mzb, mxc, myc, mzc]}
280
+ end
281
+
282
+ # Adds a source mask image to the image described by +dict+ using +mask_data+ as the source
283
+ # data.
284
+ #
285
+ # If the optional argument +from_indexed+ is +true+, it is assumed that the +mask_data+ was
286
+ # created from an indexed PNG and is not deflate encoded.
287
+ def add_smask_image(dict, mask_data, from_indexed: false)
288
+ decode_parms = {
289
+ Predictor: 15,
290
+ Colors: 1,
291
+ BitsPerComponent: (from_indexed ? 8 : dict[:BitsPerComponent]),
292
+ Columns: dict[:Width],
293
+ }
294
+ stream_opts = (from_indexed ? {} : {filter: :FlateDecode, decode_parms: decode_parms})
295
+ stream = HexaPDF::StreamData.new(lambda { mask_data }, stream_opts)
296
+
297
+ smask_dict = {
298
+ Type: :XObject,
299
+ Subtype: :Image,
300
+ Width: dict[:Width],
301
+ Height: dict[:Height],
302
+ ColorSpace: :DeviceGray,
303
+ BitsPerComponent: (from_indexed ? 8 : dict[:BitsPerComponent]),
304
+ }
305
+ smask = @document.add(smask_dict, stream: stream)
306
+ smask.set_filter(:FlateDecode, decode_parms)
307
+ dict[:SMask] = smask
308
+ end
309
+
310
+ # Returns a Proc object that can be used with a StreamData object to read the image data.
311
+ #
312
+ # This method is efficient because it doesn't need to uncompress or filter the image data
313
+ # but it only works for PNG images without embedded alpha channel data.
314
+ def image_data_proc(offset)
315
+ lambda do
316
+ with_io do |io|
317
+ io.seek(offset, IO::SEEK_SET)
318
+
319
+ while true
320
+ length, type = io.read(8).unpack('Na4') # PNG s5.3
321
+ break if type != 'IDAT'
322
+
323
+ chunk_size = @document.config['io.chunk_size'.freeze]
324
+ while length > 0
325
+ chunk_size = length if chunk_size > length
326
+ Fiber.yield(io.read(chunk_size))
327
+ length -= chunk_size
328
+ end
329
+ io.seek(4, IO::SEEK_CUR)
330
+ end
331
+ end
332
+
333
+ nil
334
+ end
335
+ end
336
+
337
+ # Separates the color data from the alpha data and returns an array containing the image and
338
+ # alpha data, both deflate encoded with predictor.
339
+ #
340
+ # Since we need to decompress the PNG chunks and extract the color/alpha bytes this method
341
+ # is not very fast but gets the job done as fast as possible in plain Ruby.
342
+ def separate_alpha_channel(offset, decode_parms)
343
+ bytes_per_colors = (decode_parms[:BitsPerComponent] * decode_parms[:Colors] + 7) / 8
344
+ bytes_per_alpha = (decode_parms[:BitsPerComponent] + 7) / 8
345
+ bytes_per_row = (decode_parms[:Columns] * decode_parms[:BitsPerComponent] *
346
+ (decode_parms[:Colors] + 1) + 7) / 8 + 1
347
+ image_data = ''.b
348
+ mask_data = ''.b
349
+
350
+ flate_decode = GlobalConfiguration.constantize('filter.map', :FlateDecode)
351
+ source = flate_decode.decoder(Fiber.new(&image_data_proc(offset)))
352
+
353
+ data = ''.b
354
+ while source.alive? && (new_data = source.resume)
355
+ data << new_data
356
+ while data.length >= bytes_per_row
357
+ i = 1
358
+ image_data << data.getbyte(0)
359
+ mask_data << data.getbyte(0)
360
+ while i < bytes_per_row
361
+ image_data << data.byteslice(i, bytes_per_colors)
362
+ i += bytes_per_colors
363
+ mask_data << data.byteslice(i, bytes_per_alpha)
364
+ i += bytes_per_alpha
365
+ end
366
+ data[0, bytes_per_row] = ''.freeze
367
+ end
368
+ end
369
+
370
+ image_data = Filter.string_from_source(flate_decode.encoder(Fiber.new { image_data }))
371
+ mask_data = Filter.string_from_source(flate_decode.encoder(Fiber.new { mask_data }))
372
+
373
+ [image_data, mask_data]
374
+ end
375
+
376
+ # Creates the alpha mask source data for an indexed PNG with alpha values.
377
+ #
378
+ # The returned data is *not* deflate encoded!
379
+ def alpha_mask_for_indexed_image(offset, decode_parms, trns)
380
+ width = decode_parms[:Columns]
381
+ bpc = decode_parms[:BitsPerComponent]
382
+ bytes_per_row = (width * bpc + 7) / 8 + 1
383
+
384
+ flate_decode = GlobalConfiguration.constantize('filter.map', :FlateDecode)
385
+ source = flate_decode.decoder(Fiber.new(&image_data_proc(offset)))
386
+
387
+ mask_data = ''.b
388
+ stream = HexaPDF::Utils::BitStreamReader.new
389
+ while source.alive? && (data = source.resume)
390
+ stream.append_data(data)
391
+
392
+ while stream.remaining_bits / 8 >= bytes_per_row
393
+ stream.read(8) # read filter byte
394
+ i = 0
395
+ while i < width
396
+ index = stream.read(bpc)
397
+ mask_data << (trns[index] || 255)
398
+ i += 1
399
+ end
400
+ stream.read(8 - ((width * bpc) % 8)) if bpc != 8 # read remaining fill bits
401
+ end
402
+ end
403
+
404
+ mask_data
405
+ end
406
+
407
+ end
408
+
409
+ end
410
+ end
@@ -0,0 +1,68 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ #--
4
+ # This file is part of HexaPDF.
5
+ #
6
+ # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
+ # Copyright (C) 2016 Thomas Leitner
8
+ #
9
+ # HexaPDF is free software: you can redistribute it and/or modify it
10
+ # under the terms of the GNU Affero General Public License version 3 as
11
+ # published by the Free Software Foundation with the addition of the
12
+ # following permission added to Section 15 as permitted in Section 7(a):
13
+ # FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
14
+ # THOMAS LEITNER, THOMAS LEITNER DISCLAIMS THE WARRANTY OF NON
15
+ # INFRINGEMENT OF THIRD PARTY RIGHTS.
16
+ #
17
+ # HexaPDF is distributed in the hope that it will be useful, but WITHOUT
18
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
20
+ # License for more details.
21
+ #
22
+ # You should have received a copy of the GNU Affero General Public License
23
+ # along with HexaPDF. If not, see <http://www.gnu.org/licenses/>.
24
+ #
25
+ # The interactive user interfaces in modified source and object code
26
+ # versions of HexaPDF must display Appropriate Legal Notices, as required
27
+ # under Section 5 of the GNU Affero General Public License version 3.
28
+ #
29
+ # In accordance with Section 7(b) of the GNU Affero General Public
30
+ # License, a covered work must retain the producer line in every PDF that
31
+ # is created or manipulated using HexaPDF.
32
+ #++
33
+
34
+ module HexaPDF
35
+
36
+ # == Overview
37
+ #
38
+ # An *image loader* is used for loading an image and creating a suitable PDF object. Since some
39
+ # image information needs to be present in the PDF object itself (like height and width) the
40
+ # loader needs to parse the image to get the needed data.
41
+ #
42
+ #
43
+ # == Implementation of an Image Loader
44
+ #
45
+ # Each image loader is a (stateless) object (normally a module) that responds to two methods:
46
+ #
47
+ # handles?(file_or_io)::
48
+ # Should return +true+ if the given file or IO stream can be handled by the loader, i.e. if
49
+ # the content contains a suitable image.
50
+ #
51
+ # load(document, file_or_io)::
52
+ # Should add a new image XObject to the document that uses the file or IO stream as source
53
+ # and return this newly created object. This method is only invoked if #handles? has
54
+ # returned +true+ for the same +file_or_io+ object.
55
+ #
56
+ # The image XObject may use any implemented filter. For example, an image loader for JPEG files
57
+ # would typically use the DCTDecode filter instead of decoding the image itself.
58
+ #
59
+ # See: PDF1.7 s8.9
60
+ module ImageLoader
61
+
62
+ autoload(:JPEG, 'hexapdf/image_loader/jpeg')
63
+ autoload(:PNG, 'hexapdf/image_loader/png')
64
+ autoload(:PDF, 'hexapdf/image_loader/pdf')
65
+
66
+ end
67
+
68
+ end