hexapdf 0.15.7 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (446) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hexapdf/cli/batch.rb +1 -1
  3. data/lib/hexapdf/cli/command.rb +11 -2
  4. data/lib/hexapdf/cli/files.rb +1 -1
  5. data/lib/hexapdf/cli/fonts.rb +145 -0
  6. data/lib/hexapdf/cli/form.rb +27 -26
  7. data/lib/hexapdf/cli/image2pdf.rb +1 -1
  8. data/lib/hexapdf/cli/images.rb +1 -10
  9. data/lib/hexapdf/cli/info.rb +1 -1
  10. data/lib/hexapdf/cli/inspect.rb +1 -1
  11. data/lib/hexapdf/cli/merge.rb +1 -1
  12. data/lib/hexapdf/cli/modify.rb +1 -1
  13. data/lib/hexapdf/cli/optimize.rb +1 -1
  14. data/lib/hexapdf/cli/split.rb +1 -1
  15. data/lib/hexapdf/cli/watermark.rb +1 -1
  16. data/lib/hexapdf/cli.rb +3 -1
  17. data/lib/hexapdf/composer.rb +1 -1
  18. data/lib/hexapdf/configuration.rb +2 -2
  19. data/lib/hexapdf/content/canvas.rb +658 -167
  20. data/lib/hexapdf/content/color_space.rb +185 -3
  21. data/lib/hexapdf/content/graphic_object/arc.rb +111 -12
  22. data/lib/hexapdf/content/graphic_object/endpoint_arc.rb +1 -1
  23. data/lib/hexapdf/content/graphic_object/geom2d.rb +1 -1
  24. data/lib/hexapdf/content/graphic_object/solid_arc.rb +1 -1
  25. data/lib/hexapdf/content/graphic_object.rb +1 -1
  26. data/lib/hexapdf/content/graphics_state.rb +1 -1
  27. data/lib/hexapdf/content/operator.rb +1 -1
  28. data/lib/hexapdf/content/parser.rb +1 -1
  29. data/lib/hexapdf/content/processor.rb +1 -1
  30. data/lib/hexapdf/content/transformation_matrix.rb +1 -1
  31. data/lib/hexapdf/content.rb +1 -1
  32. data/lib/hexapdf/data_dir.rb +1 -1
  33. data/lib/hexapdf/dictionary.rb +1 -1
  34. data/lib/hexapdf/dictionary_fields.rb +23 -2
  35. data/lib/hexapdf/document/files.rb +3 -3
  36. data/lib/hexapdf/document/fonts.rb +1 -1
  37. data/lib/hexapdf/document/images.rb +1 -1
  38. data/lib/hexapdf/document/pages.rb +1 -1
  39. data/lib/hexapdf/document.rb +1 -1
  40. data/lib/hexapdf/encryption/aes.rb +1 -1
  41. data/lib/hexapdf/encryption/arc4.rb +1 -1
  42. data/lib/hexapdf/encryption/fast_aes.rb +1 -1
  43. data/lib/hexapdf/encryption/fast_arc4.rb +1 -1
  44. data/lib/hexapdf/encryption/identity.rb +1 -1
  45. data/lib/hexapdf/encryption/ruby_aes.rb +1 -1
  46. data/lib/hexapdf/encryption/ruby_arc4.rb +1 -1
  47. data/lib/hexapdf/encryption/security_handler.rb +1 -1
  48. data/lib/hexapdf/encryption/standard_security_handler.rb +1 -1
  49. data/lib/hexapdf/encryption.rb +1 -1
  50. data/lib/hexapdf/error.rb +1 -1
  51. data/lib/hexapdf/filter/ascii85_decode.rb +1 -1
  52. data/lib/hexapdf/filter/ascii_hex_decode.rb +1 -1
  53. data/lib/hexapdf/filter/crypt.rb +1 -1
  54. data/lib/hexapdf/filter/encryption.rb +1 -1
  55. data/lib/hexapdf/filter/flate_decode.rb +1 -1
  56. data/lib/hexapdf/filter/lzw_decode.rb +1 -1
  57. data/lib/hexapdf/filter/pass_through.rb +1 -1
  58. data/lib/hexapdf/filter/predictor.rb +1 -1
  59. data/lib/hexapdf/filter/run_length_decode.rb +1 -1
  60. data/lib/hexapdf/filter.rb +1 -1
  61. data/lib/hexapdf/font/cmap/parser.rb +1 -1
  62. data/lib/hexapdf/font/cmap/writer.rb +1 -1
  63. data/lib/hexapdf/font/cmap.rb +1 -1
  64. data/lib/hexapdf/font/encoding/base.rb +1 -1
  65. data/lib/hexapdf/font/encoding/difference_encoding.rb +1 -1
  66. data/lib/hexapdf/font/encoding/glyph_list.rb +1 -1
  67. data/lib/hexapdf/font/encoding/mac_expert_encoding.rb +1 -1
  68. data/lib/hexapdf/font/encoding/mac_roman_encoding.rb +1 -1
  69. data/lib/hexapdf/font/encoding/standard_encoding.rb +1 -1
  70. data/lib/hexapdf/font/encoding/symbol_encoding.rb +1 -1
  71. data/lib/hexapdf/font/encoding/win_ansi_encoding.rb +1 -1
  72. data/lib/hexapdf/font/encoding/zapf_dingbats_encoding.rb +1 -1
  73. data/lib/hexapdf/font/encoding.rb +1 -1
  74. data/lib/hexapdf/font/invalid_glyph.rb +1 -1
  75. data/lib/hexapdf/font/true_type/builder.rb +1 -1
  76. data/lib/hexapdf/font/true_type/font.rb +1 -1
  77. data/lib/hexapdf/font/true_type/optimizer.rb +1 -1
  78. data/lib/hexapdf/font/true_type/subsetter.rb +1 -1
  79. data/lib/hexapdf/font/true_type/table/cmap.rb +1 -1
  80. data/lib/hexapdf/font/true_type/table/cmap_subtable.rb +1 -1
  81. data/lib/hexapdf/font/true_type/table/directory.rb +1 -1
  82. data/lib/hexapdf/font/true_type/table/glyf.rb +1 -1
  83. data/lib/hexapdf/font/true_type/table/head.rb +1 -1
  84. data/lib/hexapdf/font/true_type/table/hhea.rb +1 -1
  85. data/lib/hexapdf/font/true_type/table/hmtx.rb +1 -1
  86. data/lib/hexapdf/font/true_type/table/kern.rb +1 -1
  87. data/lib/hexapdf/font/true_type/table/loca.rb +1 -1
  88. data/lib/hexapdf/font/true_type/table/maxp.rb +1 -1
  89. data/lib/hexapdf/font/true_type/table/name.rb +1 -1
  90. data/lib/hexapdf/font/true_type/table/os2.rb +1 -1
  91. data/lib/hexapdf/font/true_type/table/post.rb +1 -1
  92. data/lib/hexapdf/font/true_type/table.rb +1 -1
  93. data/lib/hexapdf/font/true_type.rb +1 -1
  94. data/lib/hexapdf/font/true_type_wrapper.rb +1 -1
  95. data/lib/hexapdf/font/type1/afm_parser.rb +1 -1
  96. data/lib/hexapdf/font/type1/character_metrics.rb +1 -1
  97. data/lib/hexapdf/font/type1/font.rb +1 -1
  98. data/lib/hexapdf/font/type1/font_metrics.rb +1 -1
  99. data/lib/hexapdf/font/type1/pfb_parser.rb +1 -1
  100. data/lib/hexapdf/font/type1.rb +1 -1
  101. data/lib/hexapdf/font/type1_wrapper.rb +1 -1
  102. data/lib/hexapdf/font_loader/from_configuration.rb +1 -1
  103. data/lib/hexapdf/font_loader/from_file.rb +1 -1
  104. data/lib/hexapdf/font_loader/standard14.rb +1 -1
  105. data/lib/hexapdf/font_loader.rb +1 -1
  106. data/lib/hexapdf/image_loader/jpeg.rb +1 -1
  107. data/lib/hexapdf/image_loader/pdf.rb +1 -1
  108. data/lib/hexapdf/image_loader/png.rb +1 -1
  109. data/lib/hexapdf/image_loader.rb +1 -1
  110. data/lib/hexapdf/importer.rb +1 -1
  111. data/lib/hexapdf/layout/box.rb +4 -2
  112. data/lib/hexapdf/layout/frame.rb +1 -1
  113. data/lib/hexapdf/layout/image_box.rb +1 -1
  114. data/lib/hexapdf/layout/inline_box.rb +1 -1
  115. data/lib/hexapdf/layout/line.rb +1 -1
  116. data/lib/hexapdf/layout/numeric_refinements.rb +1 -1
  117. data/lib/hexapdf/layout/style.rb +40 -2
  118. data/lib/hexapdf/layout/text_box.rb +1 -1
  119. data/lib/hexapdf/layout/text_fragment.rb +1 -1
  120. data/lib/hexapdf/layout/text_layouter.rb +1 -1
  121. data/lib/hexapdf/layout/text_shaper.rb +1 -1
  122. data/lib/hexapdf/layout/width_from_polygon.rb +2 -2
  123. data/lib/hexapdf/layout.rb +1 -1
  124. data/lib/hexapdf/name_tree_node.rb +1 -1
  125. data/lib/hexapdf/number_tree_node.rb +1 -1
  126. data/lib/hexapdf/object.rb +1 -1
  127. data/lib/hexapdf/parser.rb +2 -2
  128. data/lib/hexapdf/pdf_array.rb +1 -1
  129. data/lib/hexapdf/rectangle.rb +1 -1
  130. data/lib/hexapdf/reference.rb +1 -1
  131. data/lib/hexapdf/revision.rb +1 -1
  132. data/lib/hexapdf/revisions.rb +1 -1
  133. data/lib/hexapdf/serializer.rb +1 -1
  134. data/lib/hexapdf/stream.rb +1 -1
  135. data/lib/hexapdf/task/dereference.rb +1 -1
  136. data/lib/hexapdf/task/optimize.rb +1 -1
  137. data/lib/hexapdf/task.rb +1 -1
  138. data/lib/hexapdf/tokenizer.rb +1 -1
  139. data/lib/hexapdf/type/acro_form/appearance_generator.rb +14 -7
  140. data/lib/hexapdf/type/acro_form/button_field.rb +53 -28
  141. data/lib/hexapdf/type/acro_form/choice_field.rb +1 -1
  142. data/lib/hexapdf/type/acro_form/field.rb +21 -2
  143. data/lib/hexapdf/type/acro_form/form.rb +48 -29
  144. data/lib/hexapdf/type/acro_form/text_field.rb +2 -2
  145. data/lib/hexapdf/type/acro_form/variable_text_field.rb +17 -9
  146. data/lib/hexapdf/type/acro_form.rb +1 -1
  147. data/lib/hexapdf/type/action.rb +1 -1
  148. data/lib/hexapdf/type/actions/go_to.rb +1 -1
  149. data/lib/hexapdf/type/actions/go_to_r.rb +1 -1
  150. data/lib/hexapdf/type/actions/launch.rb +1 -1
  151. data/lib/hexapdf/type/actions/uri.rb +1 -1
  152. data/lib/hexapdf/type/actions.rb +1 -1
  153. data/lib/hexapdf/type/annotation.rb +1 -1
  154. data/lib/hexapdf/type/annotations/link.rb +1 -1
  155. data/lib/hexapdf/type/annotations/markup_annotation.rb +1 -1
  156. data/lib/hexapdf/type/annotations/text.rb +1 -1
  157. data/lib/hexapdf/type/annotations/widget.rb +2 -2
  158. data/lib/hexapdf/type/annotations.rb +1 -1
  159. data/lib/hexapdf/type/catalog.rb +1 -1
  160. data/lib/hexapdf/type/cid_font.rb +1 -1
  161. data/lib/hexapdf/type/embedded_file.rb +1 -1
  162. data/lib/hexapdf/type/file_specification.rb +1 -1
  163. data/lib/hexapdf/type/font.rb +1 -1
  164. data/lib/hexapdf/type/font_descriptor.rb +1 -1
  165. data/lib/hexapdf/type/font_simple.rb +1 -1
  166. data/lib/hexapdf/type/font_true_type.rb +1 -1
  167. data/lib/hexapdf/type/font_type0.rb +1 -1
  168. data/lib/hexapdf/type/font_type1.rb +1 -1
  169. data/lib/hexapdf/type/font_type3.rb +1 -1
  170. data/lib/hexapdf/type/form.rb +1 -1
  171. data/lib/hexapdf/type/graphics_state_parameter.rb +1 -1
  172. data/lib/hexapdf/type/icon_fit.rb +1 -1
  173. data/lib/hexapdf/type/image.rb +1 -1
  174. data/lib/hexapdf/type/info.rb +1 -1
  175. data/lib/hexapdf/type/names.rb +1 -1
  176. data/lib/hexapdf/type/object_stream.rb +1 -1
  177. data/lib/hexapdf/type/page.rb +15 -1
  178. data/lib/hexapdf/type/page_tree_node.rb +1 -1
  179. data/lib/hexapdf/type/resources.rb +1 -1
  180. data/lib/hexapdf/type/trailer.rb +1 -1
  181. data/lib/hexapdf/type/viewer_preferences.rb +1 -1
  182. data/lib/hexapdf/type/xref_stream.rb +1 -1
  183. data/lib/hexapdf/type.rb +1 -1
  184. data/lib/hexapdf/utils/bit_field.rb +1 -1
  185. data/lib/hexapdf/utils/bit_stream.rb +1 -1
  186. data/lib/hexapdf/utils/graphics_helpers.rb +1 -1
  187. data/lib/hexapdf/utils/lru_cache.rb +1 -1
  188. data/lib/hexapdf/utils/math_helpers.rb +1 -1
  189. data/lib/hexapdf/utils/object_hash.rb +1 -1
  190. data/lib/hexapdf/utils/pdf_doc_encoding.rb +1 -1
  191. data/lib/hexapdf/utils/sorted_tree_node.rb +1 -1
  192. data/lib/hexapdf/version.rb +2 -2
  193. data/lib/hexapdf/writer.rb +1 -1
  194. data/lib/hexapdf/xref_section.rb +1 -1
  195. data/lib/hexapdf.rb +1 -1
  196. metadata +5 -264
  197. data/CHANGELOG.md +0 -947
  198. data/LICENSE +0 -29
  199. data/README.md +0 -120
  200. data/Rakefile +0 -108
  201. data/agpl-3.0.txt +0 -661
  202. data/examples/001-hello_world.rb +0 -16
  203. data/examples/002-graphics.rb +0 -275
  204. data/examples/003-arcs.rb +0 -50
  205. data/examples/004-optimizing.rb +0 -23
  206. data/examples/005-merging.rb +0 -27
  207. data/examples/006-standard_pdf_fonts.rb +0 -73
  208. data/examples/007-truetype.rb +0 -42
  209. data/examples/008-show_char_bboxes.rb +0 -55
  210. data/examples/009-text_layouter_alignment.rb +0 -47
  211. data/examples/010-text_layouter_inline_boxes.rb +0 -64
  212. data/examples/011-text_layouter_line_wrapping.rb +0 -57
  213. data/examples/012-text_layouter_styling.rb +0 -122
  214. data/examples/013-text_layouter_shapes.rb +0 -176
  215. data/examples/014-text_in_polygon.rb +0 -60
  216. data/examples/015-boxes.rb +0 -76
  217. data/examples/016-frame_automatic_box_placement.rb +0 -90
  218. data/examples/017-frame_text_flow.rb +0 -60
  219. data/examples/018-composer.rb +0 -44
  220. data/examples/019-acro_form.rb +0 -88
  221. data/examples/emoji-smile.png +0 -0
  222. data/examples/emoji-wink.png +0 -0
  223. data/examples/machupicchu.jpg +0 -0
  224. data/test/data/aes-test-vectors/CBCGFSbox-128-decrypt.data.gz +0 -0
  225. data/test/data/aes-test-vectors/CBCGFSbox-128-encrypt.data.gz +0 -0
  226. data/test/data/aes-test-vectors/CBCGFSbox-192-decrypt.data.gz +0 -0
  227. data/test/data/aes-test-vectors/CBCGFSbox-192-encrypt.data.gz +0 -0
  228. data/test/data/aes-test-vectors/CBCGFSbox-256-decrypt.data.gz +0 -0
  229. data/test/data/aes-test-vectors/CBCGFSbox-256-encrypt.data.gz +0 -0
  230. data/test/data/aes-test-vectors/CBCKeySbox-128-decrypt.data.gz +0 -0
  231. data/test/data/aes-test-vectors/CBCKeySbox-128-encrypt.data.gz +0 -0
  232. data/test/data/aes-test-vectors/CBCKeySbox-192-decrypt.data.gz +0 -0
  233. data/test/data/aes-test-vectors/CBCKeySbox-192-encrypt.data.gz +0 -0
  234. data/test/data/aes-test-vectors/CBCKeySbox-256-decrypt.data.gz +0 -0
  235. data/test/data/aes-test-vectors/CBCKeySbox-256-encrypt.data.gz +0 -0
  236. data/test/data/aes-test-vectors/CBCVarKey-128-decrypt.data.gz +0 -0
  237. data/test/data/aes-test-vectors/CBCVarKey-128-encrypt.data.gz +0 -0
  238. data/test/data/aes-test-vectors/CBCVarKey-192-decrypt.data.gz +0 -0
  239. data/test/data/aes-test-vectors/CBCVarKey-192-encrypt.data.gz +0 -0
  240. data/test/data/aes-test-vectors/CBCVarKey-256-decrypt.data.gz +0 -0
  241. data/test/data/aes-test-vectors/CBCVarKey-256-encrypt.data.gz +0 -0
  242. data/test/data/aes-test-vectors/CBCVarTxt-128-decrypt.data.gz +0 -0
  243. data/test/data/aes-test-vectors/CBCVarTxt-128-encrypt.data.gz +0 -0
  244. data/test/data/aes-test-vectors/CBCVarTxt-192-decrypt.data.gz +0 -0
  245. data/test/data/aes-test-vectors/CBCVarTxt-192-encrypt.data.gz +0 -0
  246. data/test/data/aes-test-vectors/CBCVarTxt-256-decrypt.data.gz +0 -0
  247. data/test/data/aes-test-vectors/CBCVarTxt-256-encrypt.data.gz +0 -0
  248. data/test/data/fonts/Ubuntu-Title.ttf +0 -0
  249. data/test/data/images/cmyk.jpg +0 -0
  250. data/test/data/images/fillbytes.jpg +0 -0
  251. data/test/data/images/gray.jpg +0 -0
  252. data/test/data/images/greyscale-1bit.png +0 -0
  253. data/test/data/images/greyscale-2bit.png +0 -0
  254. data/test/data/images/greyscale-4bit.png +0 -0
  255. data/test/data/images/greyscale-8bit.png +0 -0
  256. data/test/data/images/greyscale-alpha-8bit.png +0 -0
  257. data/test/data/images/greyscale-trns-8bit.png +0 -0
  258. data/test/data/images/greyscale-with-gamma1.0.png +0 -0
  259. data/test/data/images/greyscale-with-gamma1.5.png +0 -0
  260. data/test/data/images/indexed-1bit.png +0 -0
  261. data/test/data/images/indexed-2bit.png +0 -0
  262. data/test/data/images/indexed-4bit.png +0 -0
  263. data/test/data/images/indexed-8bit.png +0 -0
  264. data/test/data/images/indexed-alpha-4bit.png +0 -0
  265. data/test/data/images/indexed-alpha-8bit.png +0 -0
  266. data/test/data/images/rgb.jpg +0 -0
  267. data/test/data/images/truecolour-8bit.png +0 -0
  268. data/test/data/images/truecolour-alpha-8bit.png +0 -0
  269. data/test/data/images/truecolour-gama-chrm-8bit.png +0 -0
  270. data/test/data/images/truecolour-srgb-8bit.png +0 -0
  271. data/test/data/images/ycck.jpg +0 -0
  272. data/test/data/minimal.pdf +0 -44
  273. data/test/data/standard-security-handler/README +0 -9
  274. data/test/data/standard-security-handler/bothpwd-aes-128bit-V4.pdf +0 -44
  275. data/test/data/standard-security-handler/bothpwd-aes-256bit-V5.pdf +0 -0
  276. data/test/data/standard-security-handler/bothpwd-arc4-128bit-V2.pdf +0 -43
  277. data/test/data/standard-security-handler/bothpwd-arc4-128bit-V4.pdf +0 -43
  278. data/test/data/standard-security-handler/bothpwd-arc4-40bit-V1.pdf +0 -0
  279. data/test/data/standard-security-handler/nopwd-aes-128bit-V4.pdf +0 -43
  280. data/test/data/standard-security-handler/nopwd-aes-256bit-V5.pdf +0 -0
  281. data/test/data/standard-security-handler/nopwd-arc4-128bit-V2.pdf +0 -43
  282. data/test/data/standard-security-handler/nopwd-arc4-128bit-V4.pdf +0 -43
  283. data/test/data/standard-security-handler/nopwd-arc4-40bit-V1.pdf +0 -43
  284. data/test/data/standard-security-handler/ownerpwd-aes-128bit-V4.pdf +0 -0
  285. data/test/data/standard-security-handler/ownerpwd-aes-256bit-V5.pdf +0 -43
  286. data/test/data/standard-security-handler/ownerpwd-arc4-128bit-V2.pdf +0 -43
  287. data/test/data/standard-security-handler/ownerpwd-arc4-128bit-V4.pdf +0 -43
  288. data/test/data/standard-security-handler/ownerpwd-arc4-40bit-V1.pdf +0 -43
  289. data/test/data/standard-security-handler/userpwd-aes-128bit-V4.pdf +0 -43
  290. data/test/data/standard-security-handler/userpwd-aes-256bit-V5.pdf +0 -43
  291. data/test/data/standard-security-handler/userpwd-arc4-128bit-V2.pdf +0 -0
  292. data/test/data/standard-security-handler/userpwd-arc4-128bit-V4.pdf +0 -0
  293. data/test/data/standard-security-handler/userpwd-arc4-40bit-V1.pdf +0 -43
  294. data/test/hexapdf/common_tokenizer_tests.rb +0 -236
  295. data/test/hexapdf/content/common.rb +0 -39
  296. data/test/hexapdf/content/graphic_object/test_arc.rb +0 -93
  297. data/test/hexapdf/content/graphic_object/test_endpoint_arc.rb +0 -90
  298. data/test/hexapdf/content/graphic_object/test_geom2d.rb +0 -79
  299. data/test/hexapdf/content/graphic_object/test_solid_arc.rb +0 -86
  300. data/test/hexapdf/content/test_canvas.rb +0 -1216
  301. data/test/hexapdf/content/test_color_space.rb +0 -164
  302. data/test/hexapdf/content/test_graphics_state.rb +0 -151
  303. data/test/hexapdf/content/test_operator.rb +0 -619
  304. data/test/hexapdf/content/test_parser.rb +0 -99
  305. data/test/hexapdf/content/test_processor.rb +0 -163
  306. data/test/hexapdf/content/test_transformation_matrix.rb +0 -64
  307. data/test/hexapdf/document/test_files.rb +0 -72
  308. data/test/hexapdf/document/test_fonts.rb +0 -60
  309. data/test/hexapdf/document/test_images.rb +0 -72
  310. data/test/hexapdf/document/test_pages.rb +0 -130
  311. data/test/hexapdf/encryption/common.rb +0 -87
  312. data/test/hexapdf/encryption/test_aes.rb +0 -129
  313. data/test/hexapdf/encryption/test_arc4.rb +0 -39
  314. data/test/hexapdf/encryption/test_fast_aes.rb +0 -17
  315. data/test/hexapdf/encryption/test_fast_arc4.rb +0 -12
  316. data/test/hexapdf/encryption/test_identity.rb +0 -21
  317. data/test/hexapdf/encryption/test_ruby_aes.rb +0 -23
  318. data/test/hexapdf/encryption/test_ruby_arc4.rb +0 -20
  319. data/test/hexapdf/encryption/test_security_handler.rb +0 -380
  320. data/test/hexapdf/encryption/test_standard_security_handler.rb +0 -322
  321. data/test/hexapdf/filter/common.rb +0 -53
  322. data/test/hexapdf/filter/test_ascii85_decode.rb +0 -59
  323. data/test/hexapdf/filter/test_ascii_hex_decode.rb +0 -38
  324. data/test/hexapdf/filter/test_crypt.rb +0 -21
  325. data/test/hexapdf/filter/test_encryption.rb +0 -24
  326. data/test/hexapdf/filter/test_flate_decode.rb +0 -44
  327. data/test/hexapdf/filter/test_lzw_decode.rb +0 -52
  328. data/test/hexapdf/filter/test_predictor.rb +0 -219
  329. data/test/hexapdf/filter/test_run_length_decode.rb +0 -32
  330. data/test/hexapdf/font/cmap/test_parser.rb +0 -102
  331. data/test/hexapdf/font/cmap/test_writer.rb +0 -66
  332. data/test/hexapdf/font/encoding/test_base.rb +0 -45
  333. data/test/hexapdf/font/encoding/test_difference_encoding.rb +0 -29
  334. data/test/hexapdf/font/encoding/test_glyph_list.rb +0 -59
  335. data/test/hexapdf/font/encoding/test_zapf_dingbats_encoding.rb +0 -16
  336. data/test/hexapdf/font/test_cmap.rb +0 -104
  337. data/test/hexapdf/font/test_encoding.rb +0 -27
  338. data/test/hexapdf/font/test_invalid_glyph.rb +0 -34
  339. data/test/hexapdf/font/test_true_type_wrapper.rb +0 -186
  340. data/test/hexapdf/font/test_type1_wrapper.rb +0 -107
  341. data/test/hexapdf/font/true_type/common.rb +0 -17
  342. data/test/hexapdf/font/true_type/table/common.rb +0 -27
  343. data/test/hexapdf/font/true_type/table/test_cmap.rb +0 -47
  344. data/test/hexapdf/font/true_type/table/test_cmap_subtable.rb +0 -141
  345. data/test/hexapdf/font/true_type/table/test_directory.rb +0 -30
  346. data/test/hexapdf/font/true_type/table/test_glyf.rb +0 -58
  347. data/test/hexapdf/font/true_type/table/test_head.rb +0 -56
  348. data/test/hexapdf/font/true_type/table/test_hhea.rb +0 -26
  349. data/test/hexapdf/font/true_type/table/test_hmtx.rb +0 -30
  350. data/test/hexapdf/font/true_type/table/test_kern.rb +0 -61
  351. data/test/hexapdf/font/true_type/table/test_loca.rb +0 -33
  352. data/test/hexapdf/font/true_type/table/test_maxp.rb +0 -50
  353. data/test/hexapdf/font/true_type/table/test_name.rb +0 -76
  354. data/test/hexapdf/font/true_type/table/test_os2.rb +0 -55
  355. data/test/hexapdf/font/true_type/table/test_post.rb +0 -78
  356. data/test/hexapdf/font/true_type/test_builder.rb +0 -42
  357. data/test/hexapdf/font/true_type/test_font.rb +0 -116
  358. data/test/hexapdf/font/true_type/test_optimizer.rb +0 -26
  359. data/test/hexapdf/font/true_type/test_subsetter.rb +0 -73
  360. data/test/hexapdf/font/true_type/test_table.rb +0 -48
  361. data/test/hexapdf/font/type1/common.rb +0 -6
  362. data/test/hexapdf/font/type1/test_afm_parser.rb +0 -65
  363. data/test/hexapdf/font/type1/test_font.rb +0 -104
  364. data/test/hexapdf/font/type1/test_font_metrics.rb +0 -22
  365. data/test/hexapdf/font/type1/test_pfb_parser.rb +0 -37
  366. data/test/hexapdf/font_loader/test_from_configuration.rb +0 -43
  367. data/test/hexapdf/font_loader/test_from_file.rb +0 -36
  368. data/test/hexapdf/font_loader/test_standard14.rb +0 -33
  369. data/test/hexapdf/image_loader/test_jpeg.rb +0 -93
  370. data/test/hexapdf/image_loader/test_pdf.rb +0 -47
  371. data/test/hexapdf/image_loader/test_png.rb +0 -259
  372. data/test/hexapdf/layout/test_box.rb +0 -152
  373. data/test/hexapdf/layout/test_frame.rb +0 -350
  374. data/test/hexapdf/layout/test_image_box.rb +0 -73
  375. data/test/hexapdf/layout/test_inline_box.rb +0 -71
  376. data/test/hexapdf/layout/test_line.rb +0 -206
  377. data/test/hexapdf/layout/test_style.rb +0 -779
  378. data/test/hexapdf/layout/test_text_box.rb +0 -140
  379. data/test/hexapdf/layout/test_text_fragment.rb +0 -375
  380. data/test/hexapdf/layout/test_text_layouter.rb +0 -758
  381. data/test/hexapdf/layout/test_text_shaper.rb +0 -62
  382. data/test/hexapdf/layout/test_width_from_polygon.rb +0 -108
  383. data/test/hexapdf/task/test_dereference.rb +0 -51
  384. data/test/hexapdf/task/test_optimize.rb +0 -162
  385. data/test/hexapdf/test_composer.rb +0 -258
  386. data/test/hexapdf/test_configuration.rb +0 -93
  387. data/test/hexapdf/test_data_dir.rb +0 -32
  388. data/test/hexapdf/test_dictionary.rb +0 -340
  389. data/test/hexapdf/test_dictionary_fields.rb +0 -245
  390. data/test/hexapdf/test_document.rb +0 -641
  391. data/test/hexapdf/test_filter.rb +0 -100
  392. data/test/hexapdf/test_importer.rb +0 -106
  393. data/test/hexapdf/test_object.rb +0 -258
  394. data/test/hexapdf/test_parser.rb +0 -637
  395. data/test/hexapdf/test_pdf_array.rb +0 -169
  396. data/test/hexapdf/test_rectangle.rb +0 -73
  397. data/test/hexapdf/test_reference.rb +0 -50
  398. data/test/hexapdf/test_revision.rb +0 -188
  399. data/test/hexapdf/test_revisions.rb +0 -196
  400. data/test/hexapdf/test_serializer.rb +0 -195
  401. data/test/hexapdf/test_stream.rb +0 -274
  402. data/test/hexapdf/test_tokenizer.rb +0 -80
  403. data/test/hexapdf/test_type.rb +0 -18
  404. data/test/hexapdf/test_writer.rb +0 -140
  405. data/test/hexapdf/test_xref_section.rb +0 -61
  406. data/test/hexapdf/type/acro_form/test_appearance_generator.rb +0 -794
  407. data/test/hexapdf/type/acro_form/test_button_field.rb +0 -302
  408. data/test/hexapdf/type/acro_form/test_choice_field.rb +0 -220
  409. data/test/hexapdf/type/acro_form/test_field.rb +0 -247
  410. data/test/hexapdf/type/acro_form/test_form.rb +0 -353
  411. data/test/hexapdf/type/acro_form/test_signature_field.rb +0 -38
  412. data/test/hexapdf/type/acro_form/test_text_field.rb +0 -195
  413. data/test/hexapdf/type/acro_form/test_variable_text_field.rb +0 -77
  414. data/test/hexapdf/type/actions/test_launch.rb +0 -24
  415. data/test/hexapdf/type/actions/test_uri.rb +0 -23
  416. data/test/hexapdf/type/annotations/test_markup_annotation.rb +0 -22
  417. data/test/hexapdf/type/annotations/test_text.rb +0 -34
  418. data/test/hexapdf/type/annotations/test_widget.rb +0 -225
  419. data/test/hexapdf/type/test_annotation.rb +0 -97
  420. data/test/hexapdf/type/test_catalog.rb +0 -48
  421. data/test/hexapdf/type/test_cid_font.rb +0 -61
  422. data/test/hexapdf/type/test_file_specification.rb +0 -141
  423. data/test/hexapdf/type/test_font.rb +0 -67
  424. data/test/hexapdf/type/test_font_descriptor.rb +0 -61
  425. data/test/hexapdf/type/test_font_simple.rb +0 -176
  426. data/test/hexapdf/type/test_font_true_type.rb +0 -31
  427. data/test/hexapdf/type/test_font_type0.rb +0 -120
  428. data/test/hexapdf/type/test_font_type1.rb +0 -142
  429. data/test/hexapdf/type/test_font_type3.rb +0 -26
  430. data/test/hexapdf/type/test_form.rb +0 -120
  431. data/test/hexapdf/type/test_image.rb +0 -261
  432. data/test/hexapdf/type/test_info.rb +0 -9
  433. data/test/hexapdf/type/test_object_stream.rb +0 -117
  434. data/test/hexapdf/type/test_page.rb +0 -587
  435. data/test/hexapdf/type/test_page_tree_node.rb +0 -315
  436. data/test/hexapdf/type/test_resources.rb +0 -209
  437. data/test/hexapdf/type/test_trailer.rb +0 -116
  438. data/test/hexapdf/type/test_xref_stream.rb +0 -143
  439. data/test/hexapdf/utils/test_bit_field.rb +0 -63
  440. data/test/hexapdf/utils/test_bit_stream.rb +0 -69
  441. data/test/hexapdf/utils/test_graphics_helpers.rb +0 -37
  442. data/test/hexapdf/utils/test_lru_cache.rb +0 -22
  443. data/test/hexapdf/utils/test_object_hash.rb +0 -120
  444. data/test/hexapdf/utils/test_pdf_doc_encoding.rb +0 -18
  445. data/test/hexapdf/utils/test_sorted_tree_node.rb +0 -239
  446. data/test/test_helper.rb +0 -58
@@ -1,641 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require 'tempfile'
4
- require 'test_helper'
5
- require 'hexapdf/document'
6
- require 'stringio'
7
-
8
- describe HexaPDF::Document do
9
- before do
10
- @io = StringIO.new(<<~EOF)
11
- %PDF-1.7
12
- 1 0 obj
13
- 10
14
- endobj
15
-
16
- 2 0 obj
17
- 20
18
- endobj
19
-
20
- 3 0 obj
21
- 30
22
- endobj
23
-
24
- xref
25
- 0 4
26
- 0000000000 65535 f
27
- 0000000009 00000 n
28
- 0000000028 00000 n
29
- 0000000047 00000 n
30
- trailer
31
- << /Size 4 >>
32
- startxref
33
- 66
34
- %%EOF
35
-
36
- 2 0 obj
37
- 200
38
- endobj
39
-
40
- xref
41
- 2 2
42
- 0000000197 00000 n
43
- 0000000000 00001 f
44
- trailer
45
- << /Size 4 /Prev 66 >>
46
- startxref
47
- 217
48
- %%EOF
49
- EOF
50
- @io_doc = HexaPDF::Document.new(io: @io)
51
- @doc = HexaPDF::Document.new
52
- end
53
-
54
- describe "::open" do
55
- before do
56
- @file = Tempfile.new('hexapdf-document')
57
- @io_doc.write(@file)
58
- @file.close
59
- end
60
-
61
- after do
62
- @file.unlink
63
- end
64
-
65
- it "works without block" do
66
- doc = HexaPDF::Document.open(@file.path)
67
- assert_equal(200, doc.object(2).value)
68
- end
69
-
70
- it "works with a block" do
71
- HexaPDF::Document.open(@file.path) do |doc|
72
- assert_equal(200, doc.object(2).value)
73
- end
74
- end
75
- end
76
-
77
- describe "initialize" do
78
- it "doesn't need any arguments" do
79
- doc = HexaPDF::Document.new
80
- assert_equal(:A4, doc.config['page.default_media_box'])
81
- end
82
-
83
- it "takes a configuration hash as option" do
84
- doc = HexaPDF::Document.new(config: {'page.default_media_box' => :A5})
85
- assert_equal(:A5, doc.config['page.default_media_box'])
86
- end
87
-
88
- it "takes an IO object as option" do
89
- doc = HexaPDF::Document.new(io: @io)
90
- assert_equal(10, doc.object(1).value)
91
- end
92
- end
93
-
94
- describe "object" do
95
- it "accepts a Reference object as argument" do
96
- assert_equal(10, @io_doc.object(HexaPDF::Reference.new(1, 0)).value)
97
- end
98
-
99
- it "accepts an object number as arguments" do
100
- assert_equal(10, @io_doc.object(1).value)
101
- end
102
-
103
- it "returns added objects" do
104
- obj = @io_doc.add(@io_doc.wrap({Type: :Test}, oid: 100))
105
- assert_equal(obj, @io_doc.object(100))
106
- end
107
-
108
- it "returns nil for unknown object references" do
109
- assert_nil(@io_doc.object(100))
110
- end
111
-
112
- it "returns only the newest version of an object" do
113
- assert_equal(200, @io_doc.object(2).value)
114
- assert_equal(200, @io_doc.object(HexaPDF::Reference.new(2, 0)).value)
115
- assert_nil(@io_doc.object(3).value)
116
- assert_nil(@io_doc.object(HexaPDF::Reference.new(3, 1)).value)
117
- assert_equal(30, @io_doc.object(HexaPDF::Reference.new(3, 0)).value)
118
- end
119
- end
120
-
121
- describe "object?" do
122
- it "works with a Reference object as argument" do
123
- assert(@io_doc.object?(HexaPDF::Reference.new(1, 0)))
124
- end
125
-
126
- it "works with an object number as arguments" do
127
- assert(@io_doc.object?(1))
128
- end
129
- end
130
-
131
- describe "deref" do
132
- it "returns a dereferenced object when given a Reference object" do
133
- assert_equal(@io_doc.object(1), @io_doc.deref(HexaPDF::Reference.new(1, 0)))
134
- end
135
-
136
- it "returns the given object when it is not a Reference object" do
137
- assert_equal(5, @io_doc.deref(5))
138
- end
139
- end
140
-
141
- describe "add" do
142
- it "automatically assigns free object numbers" do
143
- assert_equal(1, @doc.add(5).oid)
144
- assert_equal(2, @doc.add(5).oid)
145
- @doc.revisions.add
146
- assert_equal(3, @doc.add(5).oid)
147
- end
148
-
149
- it "assigns the object's document" do
150
- obj = @doc.add(5)
151
- assert_equal(@doc, obj.document)
152
- end
153
-
154
- it "allows adding a native ruby object" do
155
- obj = @doc.add(5)
156
- assert_equal(5, obj.value)
157
- end
158
-
159
- it "allows passing arguments to the wrap call" do
160
- obj = @doc.add({}, type: HexaPDF::Dictionary)
161
- assert_equal(HexaPDF::Dictionary, obj.class)
162
- end
163
-
164
- it "allows adding a HexaPDF::Object" do
165
- obj = @doc.add(HexaPDF::Object.new(5))
166
- assert_equal(5, obj.value)
167
- end
168
-
169
- it "returns the given object if it is already stored in the document" do
170
- obj = @doc.add(5)
171
- assert_same(obj, @doc.add(obj))
172
- end
173
-
174
- it "allows specifying a revision to which the object should be added" do
175
- @doc.revisions.add
176
- @doc.revisions.add
177
-
178
- @doc.add(@doc.wrap(5, oid: 1), revision: 0)
179
- assert_equal(5, @doc.object(1).value)
180
-
181
- @doc.add(@doc.wrap(10, oid: 1), revision: 2)
182
- assert_equal(10, @doc.object(1).value)
183
-
184
- @doc.add(@doc.wrap(7.5, oid: 1), revision: 1)
185
- assert_equal(10, @doc.object(1).value)
186
- end
187
-
188
- it "fails if the specified revision index is invalid" do
189
- assert_raises(ArgumentError) { @doc.add(5, revision: 5) }
190
- end
191
-
192
- it "fails if the object to be added is associated with another document" do
193
- doc = HexaPDF::Document.new
194
- obj = doc.add(5)
195
- assert_raises(HexaPDF::Error) { @doc.add(obj) }
196
- end
197
-
198
- it "fails if the object number is already associated with another object" do
199
- obj = @doc.add(5)
200
- assert_raises(HexaPDF::Error) { @doc.add(@doc.wrap(5, oid: obj.oid, gen: 1)) }
201
- end
202
- end
203
-
204
- describe "delete" do
205
- it "works with a Reference object as argument" do
206
- obj = @doc.add(5)
207
- @doc.delete(obj, mark_as_free: false)
208
- refute(@doc.object?(obj))
209
- end
210
-
211
- it "works with an object number as arguments" do
212
- @doc.add(5)
213
- @doc.delete(1, mark_as_free: false)
214
- refute(@doc.object?(1))
215
- end
216
-
217
- describe "with an object in multiple revisions" do
218
- before do
219
- @ref = HexaPDF::Reference.new(2, 3)
220
- obj = @doc.wrap(5, oid: @ref.oid, gen: @ref.gen)
221
- @doc.revisions.add
222
- @doc.add(obj, revision: 0)
223
- @doc.add(obj, revision: 1)
224
- end
225
-
226
- it "deletes an object for all revisions when revision = :all" do
227
- @doc.delete(@ref, revision: :all, mark_as_free: false)
228
- refute(@doc.object?(@ref))
229
- end
230
-
231
- it "deletes an object only in the current revision when revision = :current" do
232
- @doc.delete(@ref, revision: :current, mark_as_free: false)
233
- assert(@doc.object?(@ref))
234
- end
235
-
236
- it "marks the object as PDF null object when using mark_as_free=true" do
237
- @doc.delete(@ref, revision: :current)
238
- assert(@doc.object(@ref).null?)
239
- end
240
- end
241
-
242
- it "fails if the revision argument is invalid" do
243
- assert_raises(ArgumentError) { @doc.delete(1, revision: :invalid) }
244
- end
245
- end
246
-
247
- describe "import" do
248
- it "allows importing objects from another document" do
249
- obj = @doc.import(@io_doc.object(2))
250
- assert_equal(200, obj.value)
251
- refute_equal(0, obj.oid)
252
- end
253
-
254
- it "fails if the given object is not a PDF object" do
255
- assert_raises(ArgumentError) { @doc.import(5) }
256
- end
257
-
258
- it "fails if the given object is associated with no or the destination document" do
259
- assert_raises(ArgumentError) { @doc.import(HexaPDF::Object.new(5)) }
260
- obj = @doc.add(5)
261
- assert_raises(ArgumentError) { @doc.import(obj) }
262
- end
263
- end
264
-
265
- describe "wrap" do
266
- before do
267
- @myclass = Class.new(HexaPDF::Dictionary)
268
- @myclass.define_type(:MyClass)
269
- @myclass2 = Class.new(HexaPDF::Dictionary)
270
- @myclass2.define_field(:Test, type: String, required: true)
271
- HexaPDF::GlobalConfiguration['object.type_map'][:MyClass] = @myclass
272
- HexaPDF::GlobalConfiguration['object.subtype_map'][nil][:Global] = @myclass2
273
- HexaPDF::GlobalConfiguration['object.subtype_map'][:MyClass] = {TheSecond: @myclass2}
274
- end
275
-
276
- after do
277
- HexaPDF::GlobalConfiguration['object.type_map'].delete(:MyClass)
278
- HexaPDF::GlobalConfiguration['object.subtype_map'][nil].delete(:Global)
279
- HexaPDF::GlobalConfiguration['object.subtype_map'][:MyClass].delete(:TheSecond)
280
- end
281
-
282
- it "uses a suitable default type if no special type is specified" do
283
- assert_instance_of(HexaPDF::Object, @doc.wrap(5))
284
- assert_instance_of(HexaPDF::Stream, @doc.wrap({a: 5}, stream: ''))
285
- assert_instance_of(HexaPDF::Dictionary, @doc.wrap({a: 5}))
286
- assert_instance_of(HexaPDF::PDFArray, @doc.wrap([1, 2]))
287
- end
288
-
289
- it "returns an object of type HexaPDF::Object" do
290
- assert_kind_of(HexaPDF::Object, @doc.wrap(5))
291
- assert_kind_of(HexaPDF::Object, @doc.wrap({}, stream: ''))
292
- end
293
-
294
- it "associates the returned object with the document" do
295
- assert_equal(@doc, @doc.wrap(5).document)
296
- end
297
-
298
- it "sets the given object (not === HexaPDF::Object) as value for the PDF object" do
299
- assert_equal(5, @doc.wrap(5).value)
300
- end
301
-
302
- it "uses the data of the given PDF object for re-wrapping" do
303
- obj = @doc.wrap({a: :b}, oid: 10, gen: 20, stream: 'hallo')
304
- new_obj = @doc.wrap(obj)
305
- assert_equal({a: :b}, new_obj.value)
306
- assert_equal('hallo', new_obj.raw_stream)
307
- assert_equal(10, new_obj.oid)
308
- assert_equal(20, new_obj.gen)
309
- refute_same(obj, new_obj)
310
-
311
- obj = @doc.wrap({a: :b}, oid: 10, gen: 20)
312
- new_obj = @doc.wrap(obj)
313
- refute_same(obj, new_obj)
314
- end
315
-
316
- it "allows overrding the data of the given PDF object" do
317
- obj = @doc.wrap({a: :b}, oid: 10, gen: 20, stream: 'hallo')
318
- new_obj = @doc.wrap(obj, oid: 15, gen: 25, stream: 'not')
319
- assert_equal('not', new_obj.raw_stream)
320
- assert_equal(15, new_obj.oid)
321
- assert_equal(25, new_obj.gen)
322
- end
323
-
324
- it "sets the given oid/gen values on the returned object" do
325
- obj = @doc.wrap(5, oid: 10, gen: 20)
326
- assert_equal(10, obj.oid)
327
- assert_equal(20, obj.gen)
328
- end
329
-
330
- it "uses the type/subtype information in the hash that should be wrapped" do
331
- assert_kind_of(@myclass, @doc.wrap({Type: :MyClass}))
332
- refute_kind_of(@myclass2, @doc.wrap({Subtype: :TheSecond}))
333
- refute_kind_of(@myclass2, @doc.wrap({Subtype: :Global}))
334
- assert_kind_of(@myclass2, @doc.wrap({Subtype: :Global, Test: "true"}))
335
- assert_kind_of(@myclass2, @doc.wrap({Type: :MyClass, S: :TheSecond}))
336
- assert_kind_of(@myclass, @doc.wrap({Type: :MyClass, Subtype: :TheThird}))
337
- end
338
-
339
- it "respects the given type/subtype arguments" do
340
- assert_kind_of(@myclass, @doc.wrap({Type: :Other}, type: :MyClass))
341
- refute_kind_of(@myclass2, @doc.wrap({Subtype: :Other}, subtype: :Global))
342
- assert_kind_of(@myclass2, @doc.wrap({Subtype: :Other, Test: "true"}, subtype: :Global))
343
- assert_kind_of(@myclass2, @doc.wrap({Type: :Other, Subtype: :Other},
344
- type: :MyClass, subtype: :TheSecond))
345
- assert_kind_of(@myclass2, @doc.wrap({Subtype: :TheSecond}, type: @myclass))
346
- end
347
-
348
- it "directly uses a class given via the type argument" do
349
- obj = @doc.wrap({a: :b}, type: @myclass, oid: 5)
350
- assert_kind_of(@myclass, obj)
351
- obj = @doc.wrap(obj, type: @myclass2)
352
- assert_kind_of(@myclass2, obj)
353
- assert_equal(:b, obj.value[:a])
354
- assert_equal(5, obj.oid)
355
- end
356
- end
357
-
358
- describe "unwrap" do
359
- it "returns a simple native ruby type" do
360
- assert_equal(5, @doc.unwrap(5))
361
- end
362
-
363
- it "recursively unwraps arrays" do
364
- assert_equal([5, 10, [200], [200]],
365
- @io_doc.unwrap([5, HexaPDF::Reference.new(1, 0), [HexaPDF::Reference.new(2, 0)],
366
- [HexaPDF::Reference.new(2, 0)]]))
367
- end
368
-
369
- it "recursively unwraps hashes" do
370
- assert_equal({a: 5, b: 10, c: [200], d: [200]},
371
- @io_doc.unwrap({a: 5, b: HexaPDF::Reference.new(1, 0),
372
- c: [HexaPDF::Reference.new(2, 0)],
373
- d: [HexaPDF::Reference.new(2, 0)]}))
374
- end
375
-
376
- it "recursively unwraps PDF objects" do
377
- assert_equal({a: 10}, @io_doc.unwrap(@io_doc.wrap({a: HexaPDF::Reference.new(1, 0)})))
378
- value = {a: HexaPDF::Object.new({b: HexaPDF::Object.new(10)})}
379
- assert_equal({a: {b: 10}}, @doc.unwrap(value))
380
- end
381
-
382
- it "fails to unwrap recursive structures" do
383
- obj1 = @doc.add({})
384
- obj2 = @doc.add({})
385
- obj1.value[2] = obj2
386
- obj2.value[1] = obj1
387
- assert_raises(HexaPDF::Error) { @doc.unwrap({a: obj1}) }
388
- end
389
- end
390
-
391
- describe "each" do
392
- it "iterates over the current objects" do
393
- assert_equal([10, 200, nil], @io_doc.each(only_current: true).sort.map(&:value))
394
- end
395
-
396
- it "iterates over all objects" do
397
- assert_equal([10, 200, 20, 30, nil], @io_doc.each(only_current: false).sort.map(&:value))
398
- end
399
-
400
- it "iterates over all loaded objects" do
401
- assert_equal(200, @io_doc.object(2).value)
402
- assert_equal([200], @io_doc.each(only_loaded: true).sort.map(&:value))
403
- end
404
-
405
- it "yields the revision as second argument if the block accepts exactly two arguments" do
406
- objs = [[10, 20, 30], [200, nil]]
407
- data = @io_doc.revisions.map.with_index {|rev, i| objs[i].map {|o| [o, rev] } }.reverse.flatten
408
- @io_doc.each(only_current: false) do |obj, rev|
409
- assert(data.shift == obj.value)
410
- assert_equal(data.shift, rev)
411
- end
412
- end
413
- end
414
-
415
- describe "encryption" do
416
- it "checks for encryption based on the existence of the trailer's /Encrypt dictionary" do
417
- refute(@doc.encrypted?)
418
- @doc.trailer[:Encrypt] = {Filter: :Standard}
419
- assert(@doc.encrypted?)
420
- end
421
-
422
- it "can set or delete a security handler via #encrypt" do
423
- @doc.encrypt
424
- refute_nil(@doc.security_handler)
425
- assert(@doc.encrypted?)
426
-
427
- @doc.encrypt(name: nil)
428
- assert_nil(@doc.security_handler)
429
- refute(@doc.encrypted?)
430
- end
431
-
432
- it "doesn't decrypt the document if document.auto_encrypt=false" do
433
- test_file = File.join(TEST_DATA_DIR, 'standard-security-handler', 'nopwd-arc4-40bit-V1.pdf')
434
- doc = HexaPDF::Document.new(io: StringIO.new(File.read(test_file)),
435
- config: {'document.auto_decrypt' => false})
436
- assert_kind_of(String, doc.trailer[:Info][:ModDate])
437
- handler = HexaPDF::Encryption::SecurityHandler.set_up_decryption(doc)
438
- assert_kind_of(Time, handler.decrypt(doc.trailer[:Info])[:ModDate])
439
- end
440
- end
441
-
442
- describe "validate" do
443
- before do
444
- @doc.validate # to create a valid document
445
- end
446
-
447
- it "validates indirect objects" do
448
- obj = @doc.add({Type: :Page, MediaBox: [1, 1, 1, 1], Parent: @doc.pages.root})
449
- refute(@doc.validate(auto_correct: false))
450
-
451
- called = false
452
- assert(@doc.validate {|_, _, o| assert_same(obj, o); called = true })
453
- assert(called)
454
- end
455
-
456
- it "validates the trailer object" do
457
- @doc.trailer[:ID] = :Symbol
458
- refute(@doc.validate {|_, _, obj| assert_same(@doc.trailer, obj) })
459
- end
460
-
461
- it "validates only loaded objects" do
462
- io = StringIO.new
463
- doc = HexaPDF::Document.new
464
- doc.pages.add.delete(:Resources)
465
- page = doc.pages.add
466
- page[:Annots] = [doc.add({Type: :Annot, Subtype: :Link, Rect: [0, 0, 1, 1], H: :Z})]
467
- doc.write(io, validate: false)
468
- doc = HexaPDF::Document.new(io: io)
469
- doc.pages[0] # force loading of the first page
470
-
471
- refute(doc.validate(auto_correct: false, only_loaded: true)) # bc of Resources
472
- assert(doc.validate(only_loaded: true))
473
- refute(doc.validate(auto_correct: false)) # bc of annot key H
474
- end
475
- end
476
-
477
- describe "write" do
478
- it "writes the document to a file" do
479
- begin
480
- file = Tempfile.new('hexapdf-write')
481
- file.close
482
- @io_doc.write(file.path)
483
- HexaPDF::Document.open(file.path) do |doc|
484
- assert_equal(200, doc.object(2).value)
485
- end
486
- ensure
487
- file.unlink
488
- end
489
- end
490
-
491
- it "writes the document to an IO object" do
492
- io = StringIO.new(''.b)
493
- @doc.write(io)
494
- refute(io.string.empty?)
495
- end
496
-
497
- it "writes the document incrementally" do
498
- io = StringIO.new
499
- @io_doc.write(io, incremental: true)
500
- assert_equal(@io.string, io.string[0, @io.string.length])
501
- end
502
-
503
- it "fails if the document is not valid" do
504
- @doc.trailer[:Size] = :Symbol
505
- assert_raises(HexaPDF::Error) { @doc.write(StringIO.new(''.b)) }
506
- end
507
-
508
- it "update the ID and the Info's ModDate field" do
509
- _, id1 = @doc.trailer.set_random_id
510
-
511
- @doc.write(StringIO.new(''.b), update_fields: false)
512
- assert_same(id1, @doc.trailer[:ID][1])
513
- refute(@doc.trailer.info.key?(:ModDate))
514
-
515
- @doc.write(StringIO.new(''.b))
516
- refute_same(id1, (id2 = @doc.trailer[:ID][1]))
517
- assert(@doc.trailer.info.key?(:ModDate))
518
-
519
- @doc.trailer.info[:Author] = 'Me'
520
- @doc.write(StringIO.new(''.b))
521
- refute_same(id2, @doc.trailer[:ID][1])
522
- assert(@doc.trailer.info.key?(:ModDate))
523
- assert(@doc.trailer.info.key?(:Author))
524
- end
525
-
526
- it "it doesn't optimize the file by default" do
527
- io = StringIO.new(''.b)
528
- @io_doc.write(io)
529
- doc = HexaPDF::Document.new(io: io)
530
- assert_equal(0, doc.each.count {|o| o.type == :ObjStm })
531
- end
532
-
533
- it "allows optimizing the file by using object streams" do
534
- io = StringIO.new(''.b)
535
- @io_doc.write(io, optimize: true)
536
- doc = HexaPDF::Document.new(io: io)
537
- assert_equal(2, doc.each.count {|o| o.type == :ObjStm })
538
- end
539
- end
540
-
541
- describe "version" do
542
- it "uses the file header version of a loaded document" do
543
- assert_equal('1.7', @io_doc.version)
544
- end
545
-
546
- it "uses the default version for a new document" do
547
- assert_equal('1.2', @doc.version)
548
- end
549
-
550
- it "uses the catalog's /Version entry if it points to a later version" do
551
- (@doc.trailer[:Root] ||= {})[:Version] = '1.4'
552
- assert_equal('1.4', @doc.version)
553
- end
554
-
555
- it "allows setting the version" do
556
- @doc.version = '1.4'
557
- assert_equal('1.4', @doc.version)
558
- end
559
-
560
- it "fails setting a version with an invalid format" do
561
- assert_raises(ArgumentError) { @doc.version = 'bla' }
562
- end
563
- end
564
-
565
- describe "task" do
566
- it "executes the given task with options" do
567
- @doc.config['task.map'][:test] = lambda do |doc, arg1:|
568
- assert_equal(doc, @doc)
569
- assert_equal(:arg1, arg1)
570
- end
571
- @doc.task(:test, arg1: :arg1)
572
- end
573
-
574
- it "executes the given task with a block" do
575
- @doc.config['task.map'][:test] = lambda do |doc, **, &block|
576
- assert_equal(doc, @doc)
577
- block.call('inside')
578
- end
579
- assert_equal(:done, @doc.task(:test) {|msg| assert_equal('inside', msg); :done })
580
- end
581
-
582
- it "fails if the given task is not available" do
583
- assert_raises(HexaPDF::Error) { @doc.task(:unknown) }
584
- end
585
- end
586
-
587
- describe "acro_form" do
588
- it "returns the main AcroForm object" do
589
- assert_nil(@doc.acro_form)
590
- @doc.catalog[:AcroForm] = 5
591
- assert_equal(5, @doc.acro_form)
592
- end
593
-
594
- it "create the AcroForm object if instructed" do
595
- assert_equal(:XXAcroForm, @doc.acro_form(create: true).type)
596
- end
597
- end
598
-
599
- describe "listener interface" do
600
- it "allows registering and dispatching messages" do
601
- args = []
602
- callable = lambda {|*a| args << [:callable, a] }
603
- @doc.register_listener(:something, callable)
604
- @doc.register_listener(:something) {|*a| args << [:block, a] }
605
- @doc.dispatch_message(:something, :arg)
606
- assert_equal([[:callable, [:arg]], [:block, [:arg]]], args)
607
- end
608
- end
609
-
610
- describe "caching interface" do
611
- it "allows setting and retrieving values" do
612
- assert_equal(:test, @doc.cache(:a, :b, :test) { :notused })
613
- assert_equal(:test, @doc.cache(:a, :b) { :other })
614
- assert_equal(:test, @doc.cache(:a, :b))
615
- assert_nil(@doc.cache(:a, :c, nil))
616
- assert_nil(@doc.cache(:a, :c) { :other })
617
- assert_nil(@doc.cache(:a, :c))
618
- assert(@doc.cached?(:a, :b))
619
- assert(@doc.cached?(:a, :c))
620
- end
621
-
622
- it "allows updating a value" do
623
- @doc.cache(:a, :b) { :test }
624
- assert_equal(:new, @doc.cache(:a, :b, update: true) { :new })
625
- end
626
-
627
- it "allows clearing cached values" do
628
- @doc.cache(:a, :b) { :c }
629
- @doc.cache(:b, :c) { :d }
630
- @doc.clear_cache(:a)
631
- refute(@doc.cached?(:a, :b))
632
- assert(@doc.cached?(:b, :c))
633
- @doc.clear_cache
634
- refute(@doc.cached?(:a, :c))
635
- end
636
-
637
- it "fails if no cached value exists and no block is given" do
638
- assert_raises(LocalJumpError) { @doc.cache(:a, :b) }
639
- end
640
- end
641
- end