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,82 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'test_helper'
4
+ require 'hexapdf/configuration'
5
+
6
+ describe HexaPDF::Configuration do
7
+ before do
8
+ @config = HexaPDF::Configuration.new
9
+ @config['test'] = :test
10
+ end
11
+
12
+ it "can create a config based on the default one with certain values overwritten" do
13
+ config = HexaPDF::Configuration.with_defaults('io.chunk_size' => 10)
14
+ assert_equal(10, config['io.chunk_size'])
15
+ assert_equal(:A4, config['page.default_media_box'])
16
+ end
17
+
18
+ it "can check the availabilty of an option" do
19
+ assert(@config.option?('test'))
20
+ end
21
+
22
+ it "can return the value for an option" do
23
+ assert_equal(:test, @config['test'])
24
+ end
25
+
26
+ it "can set the value for an option" do
27
+ @config['test'] = :other
28
+ assert_equal(:other, @config['test'])
29
+ end
30
+
31
+ it "can create a new config object by merging another one or a hash" do
32
+ @config['hash'] = {'test' => :test, 'other' => :other}
33
+ config = @config.merge('test' => :other)
34
+ assert_equal(:other, config['test'])
35
+
36
+ config['hash']['test'] = :other
37
+ config = @config.merge(config)
38
+ assert_equal(:other, config['hash']['test'])
39
+ assert_equal(:other, config['hash']['other'])
40
+ end
41
+
42
+ describe "constantize" do
43
+ it "returns a constant for an option with a string value" do
44
+ @config['test'] = 'HexaPDF'
45
+ assert_equal(HexaPDF, @config.constantize('test'))
46
+ end
47
+
48
+ it "returns a constant for an option with a constant as value" do
49
+ @config['test'] = HexaPDF
50
+ assert_equal(HexaPDF, @config.constantize('test'))
51
+ end
52
+
53
+ it "returns a constant for a nested option" do
54
+ @config['test'] = {'test' => 'HexaPDF', 'const' => HexaPDF}
55
+ assert_equal(HexaPDF, @config.constantize('test', 'test'))
56
+ assert_equal(HexaPDF, @config.constantize('test', 'const'))
57
+
58
+ @config['test'] = ['HexaPDF', HexaPDF]
59
+ assert_equal(HexaPDF, @config.constantize('test', 0))
60
+ assert_equal(HexaPDF, @config.constantize('test', 1))
61
+ end
62
+
63
+ it "returns nil for an unknown option" do
64
+ assert_nil(@config.constantize('unknown'))
65
+ end
66
+
67
+ it "returns nil for an unknown constant" do
68
+ @config['test'] = 'SomeUnknownConstant'
69
+ assert_nil(@config.constantize('test'))
70
+ end
71
+
72
+ it "returns nil for an unknown constant using a nested option" do
73
+ @config['test'] = {}
74
+ assert_nil(@config.constantize('test', 'test'))
75
+ assert_nil(@config.constantize('test', nil))
76
+ end
77
+
78
+ it "returns the result of the given block when no constant is found" do
79
+ assert_equal(:test, @config.constantize('unk') {|name| assert_equal('unk', name); :test})
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'test_helper'
4
+ require 'hexapdf/data_dir'
5
+
6
+ describe 'HexaPDF.data_dir' do
7
+ before do
8
+ @local = File.expand_path(File.join(__dir__, '..', '..', 'data', 'hexapdf'))
9
+ @global = File.expand_path(File.join(RbConfig::CONFIG["datadir"], "hexapdf"))
10
+ HexaPDF.remove_instance_variable(:@data_dir) if HexaPDF.instance_variable_defined?(:@data_dir)
11
+ end
12
+
13
+ after do
14
+ HexaPDF.remove_instance_variable(:@data_dir) if HexaPDF.instance_variable_defined?(:@data_dir)
15
+ end
16
+
17
+ it "returns the 'local' data directory by default, e.g. in case of gem installations" do
18
+ assert_equal(@local, HexaPDF.data_dir)
19
+ end
20
+
21
+ it "returns the global data directory if the local one isn't found" do
22
+ File.stub(:directory?, lambda {|path| path == @local ? false : true}) do
23
+ assert_equal(@global, HexaPDF.data_dir)
24
+ end
25
+ end
26
+
27
+ it "fails if no data directory is found" do
28
+ File.stub(:directory?, lambda {|_path| false}) do
29
+ assert_raises { HexaPDF.data_dir }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,284 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'test_helper'
4
+ require 'hexapdf/dictionary'
5
+ require 'hexapdf/reference'
6
+
7
+ describe HexaPDF::Dictionary do
8
+ def deref(obj)
9
+ if obj.kind_of?(HexaPDF::Reference)
10
+ HexaPDF::Object.new('deref', oid: obj.oid, gen: obj.gen)
11
+ else
12
+ obj
13
+ end
14
+ end
15
+
16
+ def add(obj)
17
+ HexaPDF::Object.new(obj, oid: 1)
18
+ end
19
+
20
+ def delete(_obj)
21
+ end
22
+
23
+ def wrap(obj, type:)
24
+ type.new(obj, document: self)
25
+ end
26
+
27
+ attr_accessor :version
28
+
29
+ before do
30
+ @version = '1.2'
31
+ @test_class = Class.new(HexaPDF::Dictionary)
32
+ @test_class.define_field(:Boolean, type: [TrueClass, FalseClass], default: false, version: '1.3')
33
+ @test_class.define_field(:Array, type: Array, required: true, default: [])
34
+ @test_class.define_field(:TestClass, type: @test_class, indirect: true)
35
+
36
+ @dict = @test_class.new({Array: [3, 4], Other: 5, Object: HexaPDF::Object.new(:obj)},
37
+ document: self)
38
+ end
39
+
40
+ describe "class methods" do
41
+ it "allows defining fields and retrieving their info" do
42
+ field = @test_class.field(:Boolean)
43
+ refute_nil(field)
44
+ assert_equal('1.3', field.version)
45
+ assert_equal(false, field.default)
46
+ refute(field.required?)
47
+
48
+ field = @test_class.field(:Array)
49
+ assert(field.required?)
50
+ assert_equal([], field.default)
51
+
52
+ assert(@test_class.field(:TestClass).indirect)
53
+ end
54
+
55
+ it "can retrieve fields from parent classes" do
56
+ @inherited_class = Class.new(@test_class)
57
+
58
+ assert(@inherited_class.field(:Boolean))
59
+ refute(@inherited_class.field(:Unknown))
60
+ end
61
+
62
+ it "can iterate over all fields" do
63
+ @inherited_class = Class.new(@test_class)
64
+ @inherited_class.define_field(:Inherited, type: [Array, Symbol])
65
+ assert_equal([:Boolean, :Array, :TestClass, :Inherited], @inherited_class.each_field.map {|k, _| k})
66
+ end
67
+
68
+ it "allows field access without subclassing" do
69
+ refute(HexaPDF::Dictionary.field(:Test))
70
+ assert_equal([], HexaPDF::Dictionary.each_field.to_a)
71
+ end
72
+ end
73
+
74
+ describe "after_data_change" do
75
+ it "fails if the value is not a hash" do
76
+ assert_raises(ArgumentError) { HexaPDF::Dictionary.new(:Name) }
77
+ end
78
+
79
+ it "sets the default value for a required field that has one" do
80
+ @test_class.define_field(:Type, type: Symbol, required: true, default: :MyType)
81
+ obj = @test_class.new(nil)
82
+ assert_equal(:MyType, obj.value[:Type])
83
+ end
84
+ end
85
+
86
+ describe "[]" do
87
+ it "allows retrieving set field values" do
88
+ assert_equal([3, 4], @dict[:Array])
89
+ assert_equal(5, @dict[:Other])
90
+ end
91
+
92
+ it "uses a default value if no value is set" do
93
+ assert_equal(false, @dict[:Boolean])
94
+ @dict.value[:Boolean] = true
95
+ assert_equal(true, @dict[:Boolean])
96
+ end
97
+
98
+ it "resolves references and stores the resolved object in place of the reference" do
99
+ @dict[:value] = HexaPDF::Reference.new(1, 0)
100
+ assert_equal('deref', @dict[:value])
101
+ assert_kind_of(HexaPDF::Object, @dict.value[:value])
102
+ end
103
+
104
+ it "wraps hash values in specific subclasses" do
105
+ @dict.value[:TestClass] = {Array: [1, 2]}
106
+ assert_kind_of(@test_class, @dict[:TestClass])
107
+ assert_equal([1, 2], @dict[:TestClass][:Array])
108
+
109
+ @dict.value[:TestClass] = HexaPDF::Object.new([1, 2])
110
+ refute_kind_of(@test_class, @dict[:TestClass])
111
+ assert_equal([1, 2], @dict[:TestClass])
112
+ end
113
+
114
+ it "fetches the value out of a HexaPDF::Object" do
115
+ assert_equal(:obj, @dict[:Object])
116
+ end
117
+
118
+ it "can convert data even if it is inside a HexaPDF::Object" do
119
+ @test_class.define_field(:Binary, type: HexaPDF::DictionaryFields::PDFByteString)
120
+ @dict[:Binary] = HexaPDF::Object.new('test')
121
+ result = @dict[:Binary]
122
+ assert_equal('test', result)
123
+ assert_equal(Encoding::BINARY, result.encoding)
124
+ assert_kind_of(HexaPDF::Object, @dict.value[:Binary])
125
+ assert_same(result, @dict.value[:Binary].value)
126
+ end
127
+ end
128
+
129
+ describe "[]=" do
130
+ it "directly stores the value if the stored value is no HexaPDF::Object" do
131
+ @dict[:Array] = [4, 5]
132
+ assert_equal([4, 5], @dict.value[:Array])
133
+
134
+ @dict[:NewValue] = 7
135
+ assert_equal(7, @dict.value[:NewValue])
136
+ end
137
+
138
+ it "stores the value inside the current value HexaPDF::Object but only if the given one is not such an object" do
139
+ @dict[:Object] = [4, 5]
140
+ assert_equal([4, 5], @dict.value[:Object].value)
141
+
142
+ @dict[:Object] = temp = HexaPDF::Object.new(:other)
143
+ assert_equal(temp, @dict.value[:Object])
144
+ end
145
+
146
+ it "doesn't store the value inside for subclasses of HexaPDF::Object" do
147
+ (@dict[:TestClass] ||= {})[:Array] = [4, 5]
148
+ assert_kind_of(@test_class, @dict[:TestClass])
149
+ @dict[:TestClass] = [4, 5]
150
+ assert_equal([4, 5], @dict[:TestClass])
151
+ end
152
+
153
+ it "doesn't store the value inside for HexaPDF::Reference objects" do
154
+ @dict[:Object] = HexaPDF::Object.new(:test)
155
+ assert_kind_of(HexaPDF::Object, @dict.value[:Object])
156
+ @dict[:Object] = HexaPDF::Reference.new(5, 0)
157
+ assert_kind_of(HexaPDF::Reference, @dict.value[:Object])
158
+ end
159
+
160
+ it "raises an error if the key is not a symbol object" do
161
+ assert_raises(ArgumentError) { @dict[5] = 6 }
162
+ end
163
+ end
164
+
165
+ describe "validate_fields" do
166
+ before do
167
+ @test_class.define_field(:Inherited, type: [Array, Symbol], required: true, indirect: false)
168
+ @obj = @test_class.new({Array: [], Inherited: :symbol}, document: self)
169
+ end
170
+
171
+ it "checks for the required fields w/wo auto_correct" do
172
+ assert(@obj.validate(auto_correct: false))
173
+ assert_equal({Array: [], Inherited: :symbol}, @obj.value)
174
+
175
+ @obj.value.delete(:Array)
176
+ refute(@obj.validate(auto_correct: false))
177
+ assert(@obj.validate(auto_correct: true))
178
+ assert_equal({Array: [], Inherited: :symbol}, @obj.value)
179
+
180
+ @obj.value.delete(:Inherited)
181
+ refute(@obj.validate(auto_correct: true))
182
+ end
183
+
184
+ it "updates the PDF version of the document if needed" do
185
+ @obj.validate
186
+ assert_equal('1.2', @version)
187
+
188
+ @obj[:Boolean] = true
189
+ refute(@obj.validate(auto_correct: false))
190
+ assert_equal('1.2', @version)
191
+ assert(@obj.validate(auto_correct: true))
192
+ assert_equal('1.3', @version)
193
+ end
194
+
195
+ it "checks for the correct type of a set field" do
196
+ @obj.value[:Inherited] = 'string'
197
+ refute(@obj.validate(auto_correct: false))
198
+
199
+ @obj.value[:Inherited] = HexaPDF::Object.new(:symbol)
200
+ assert(@obj.validate(auto_correct: false))
201
+
202
+ @obj.value[:Inherited] = Class.new(Array).new([5])
203
+ assert(@obj.validate(auto_correct: false))
204
+ end
205
+
206
+ it "checks whether a field needs to be indirect w/wo auto_correct" do
207
+ @obj.value[:Inherited] = HexaPDF::Object.new(:test, oid: 1)
208
+ refute(@obj.validate(auto_correct: false))
209
+ assert(@obj.validate(auto_correct: true))
210
+ assert_equal(:test, @obj.value[:Inherited])
211
+
212
+ @obj.value[:TestClass] = {Inherited: :symbol}
213
+ refute(@obj.validate(auto_correct: false))
214
+ assert(@obj.validate(auto_correct: true))
215
+ assert_equal(1, @obj.value[:TestClass].oid)
216
+
217
+ @obj.value[:TestClass] = HexaPDF::Object.new(Inherited: :symbol)
218
+ assert(@obj.validate(auto_correct: true))
219
+ assert_equal(1, @obj.value[:TestClass].oid)
220
+ end
221
+
222
+ it "validates values that are PDF objects" do
223
+ @obj.value[:TestClass] = @test_class.new(nil, document: self)
224
+ refute(@obj.validate)
225
+ @obj.value[:TestClass][:Inherited] = :symbol
226
+ assert(@obj.validate)
227
+ end
228
+
229
+ it "validates direct PDF objects nested in hashes" do
230
+ @obj[:TestClass] = {Inherited: :symbol, Nested: {Nested: {TestClass: @test_class.new(nil, document: self)}}}
231
+ refute(@obj.validate)
232
+ @obj[:TestClass][:Nested][:Nested][:TestClass][:Inherited] = :symbol
233
+ assert(@obj.validate)
234
+ end
235
+ end
236
+
237
+ describe "delete" do
238
+ it "deletes an entry from the underlying hash value and returns its value" do
239
+ assert_equal(5, @dict.delete(:Other))
240
+ refute(@dict.value.key?(:Other))
241
+ end
242
+
243
+ it "returns nil if no entry with the given name exists" do
244
+ assert_nil(@dict.delete(:SomethingUnknown))
245
+ end
246
+ end
247
+
248
+ describe "each" do
249
+ it "iterates over all name-value pairs in the dictionary" do
250
+ @dict[:TestClass] = {}
251
+ data = [:Array, [3, 4], :Other, 5, :Object, :obj, :TestClass, @dict[:TestClass]]
252
+ @dict.each do |name, value|
253
+ assert_equal(data.shift, name)
254
+ assert_equal(data.shift, value)
255
+ end
256
+ end
257
+ end
258
+
259
+ describe "to_hash" do
260
+ it "returns a shallow copy of the value" do
261
+ obj = @dict.to_hash
262
+ refute_equal(obj.object_id, @dict.value.object_id)
263
+ assert_equal(obj, @dict.value)
264
+ end
265
+ end
266
+
267
+ describe "type" do
268
+ it "returns the /Type entry" do
269
+ @dict[:Type] = :Test
270
+ assert_equal(:Test, @dict.type)
271
+ end
272
+
273
+ it "returns the value from Object#type if not /Type entry is present" do
274
+ assert_equal(:Unknown, @dict.type)
275
+ end
276
+ end
277
+
278
+ describe "empty?" do
279
+ it "returns true if the dictionary contains no entries" do
280
+ assert(HexaPDF::Dictionary.new({}).empty?)
281
+ refute(HexaPDF::Dictionary.new(x: 5).empty?)
282
+ end
283
+ end
284
+ end
@@ -0,0 +1,185 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'test_helper'
4
+ require 'hexapdf/dictionary_fields'
5
+ require 'hexapdf/dictionary'
6
+ require 'hexapdf/type'
7
+
8
+ describe HexaPDF::DictionaryFields do
9
+ include HexaPDF::DictionaryFields
10
+
11
+ describe "Field" do
12
+ before do
13
+ @field = self.class::Field.new([:Integer, Integer], true, 500, false, '1.2')
14
+ HexaPDF::GlobalConfiguration['object.type_map'][:Integer] = Integer
15
+ end
16
+
17
+ after do
18
+ HexaPDF::GlobalConfiguration['object.type_map'].delete(:Integer)
19
+ end
20
+
21
+ it "allows access to the basic field information" do
22
+ assert(@field.required?)
23
+ assert(@field.default?)
24
+ assert_equal(500, @field.default)
25
+ assert_equal(false, @field.indirect)
26
+ assert_equal('1.2', @field.version)
27
+ end
28
+
29
+ it "maps string types to constants" do
30
+ assert_equal([Integer], @field.type)
31
+ end
32
+
33
+ it "uses the additional types from a converter" do
34
+ @field = self.class::Field.new(self.class::PDFByteString)
35
+ assert_equal([self.class::PDFByteString, String], @field.type)
36
+ end
37
+
38
+ it "does not allow any conversion with the identity converter" do
39
+ x = '5'
40
+ refute(@field.convert?(x))
41
+ assert_same(x, @field.convert(x, self))
42
+ end
43
+
44
+ it "can check for a valid object" do
45
+ refute(@field.valid_object?('Test'))
46
+ assert(@field.valid_object?(5))
47
+ assert(@field.valid_object?(HexaPDF::Object.new(5)))
48
+ end
49
+ end
50
+
51
+ describe "DictionaryConverter" do
52
+ before do
53
+ @field = self.class::Field.new(Class.new(HexaPDF::Dictionary))
54
+ @doc = Minitest::Mock.new
55
+ end
56
+
57
+ it "additionally adds Hash as allowed type" do
58
+ assert(@field.type.include?(Hash))
59
+ end
60
+
61
+ it "allows conversion from a hash" do
62
+ assert(@field.convert?({}))
63
+ @doc.expect(:wrap, :data, [Hash, Hash])
64
+ @field.convert({Test: :value}, @doc)
65
+ @doc.verify
66
+ end
67
+
68
+ it "allows conversion from a Dictionary" do
69
+ assert(@field.convert?(HexaPDF::Dictionary.new({})))
70
+ @doc.expect(:wrap, :data, [HexaPDF::Dictionary, Hash])
71
+ @field.convert(HexaPDF::Dictionary.new(Test: :value), @doc)
72
+ @doc.verify
73
+ end
74
+ end
75
+
76
+ describe "StringConverter" do
77
+ before do
78
+ @field = self.class::Field.new(String)
79
+ end
80
+
81
+ it "allows conversion to UTF-8 string from binary" do
82
+ assert(@field.convert?('test'.b))
83
+
84
+ str = @field.convert("\xfe\xff\x00t\x00e\x00s\x00t".b, self)
85
+ assert_equal('test', str)
86
+ assert_equal(Encoding::UTF_8, str.encoding)
87
+ str = @field.convert("Testing\x9c\x92".b, self)
88
+ assert_equal("Testing\u0153\u2122", str)
89
+ assert_equal(Encoding::UTF_8, str.encoding)
90
+ end
91
+ end
92
+
93
+ describe "PDFByteStringConverter" do
94
+ before do
95
+ @field = self.class::Field.new(self.class::PDFByteString)
96
+ end
97
+
98
+ it "additionally adds String as allowed type if not already present" do
99
+ assert_equal([HexaPDF::Dictionary::PDFByteString, String], @field.type)
100
+ end
101
+
102
+ it "allows conversion to a binary string" do
103
+ assert(@field.convert?('test'))
104
+ refute(@field.convert?('test'.b))
105
+
106
+ str = @field.convert("test", self)
107
+ assert_equal('test', str)
108
+ assert_equal(Encoding::BINARY, str.encoding)
109
+ end
110
+ end
111
+
112
+ describe "DateConverter" do
113
+ before do
114
+ @field = self.class::Field.new(self.class::PDFDate)
115
+ end
116
+
117
+ it "additionally adds String/Time/Date/DateTime as allowed types" do
118
+ assert_equal([HexaPDF::Dictionary::PDFDate, String, Time, Date, DateTime], @field.type)
119
+ end
120
+
121
+ it "allows conversion to a Time object from a binary string" do
122
+ date = "D:199812231952-08'00".b
123
+ refute(@field.convert?('test'.b))
124
+ assert(@field.convert?(date))
125
+
126
+ [["D:1998", [1998, 01, 01, 00, 00, 00, "-00:00"]],
127
+ ["D:199812", [1998, 12, 01, 00, 00, 00, "-00:00"]],
128
+ ["D:19981223", [1998, 12, 23, 00, 00, 00, "-00:00"]],
129
+ ["D:1998122319", [1998, 12, 23, 19, 00, 00, "+00:00"]],
130
+ ["D:199812231952", [1998, 12, 23, 19, 52, 00, "+00:00"]],
131
+ ["D:19981223195210", [1998, 12, 23, 19, 52, 10, "+00:00"]],
132
+ ["D:19981223195210-08'00'", [1998, 12, 23, 19, 52, 10, "-08:00"]],
133
+ ["D:1998122319-08'00'", [1998, 12, 23, 19, 00, 00, "-08:00"]],
134
+ ["D:19981223-08'00'", [1998, 12, 23, 00, 00, 00, "-08:00"]],
135
+ ["D:199812-08'00'", [1998, 12, 01, 00, 00, 00, "-08:00"]],
136
+ ["D:1998-08'00'", [1998, 01, 01, 00, 00, 00, "-08:00"]],
137
+ ["D:19981223195210-08", [1998, 12, 23, 19, 52, 10, "-08:00"]], # non-standard bc missing '
138
+ ["D:19981223195210-08'00", [1998, 12, 23, 19, 52, 10, "-08:00"]], # non-standard bc missing '
139
+ ].each do |str, data|
140
+ obj = @field.convert(str, self)
141
+ assert_equal(Time.new(*data), obj, "date str used: #{str}")
142
+ end
143
+ end
144
+ end
145
+
146
+ describe "FileSpecificationConverter" do
147
+ before do
148
+ @field = self.class::Field.new(:Filespec)
149
+ end
150
+
151
+ it "additionally adds Hash and String as allowed types" do
152
+ assert(@field.type.include?(Hash))
153
+ assert(@field.type.include?(String))
154
+ end
155
+
156
+ it "allows conversion from a string" do
157
+ refute(@field.convert?({}))
158
+
159
+ @doc = Minitest::Mock.new
160
+ @doc.expect(:wrap, :data, [{F: 'test'}, {type: HexaPDF::Type::FileSpecification}])
161
+ @field.convert('test', @doc)
162
+ @doc.verify
163
+ end
164
+ end
165
+
166
+ describe "RectangleConverter" do
167
+ before do
168
+ @field = self.class::Field.new(HexaPDF::Rectangle)
169
+ end
170
+
171
+ it "additionally adds Array as allowed types" do
172
+ assert_equal([HexaPDF::Rectangle, Array], @field.type)
173
+ end
174
+
175
+ it "allows conversion to a Rectangle from an Array" do
176
+ assert(@field.convert?([5, 6]))
177
+ refute(@field.convert?(:name))
178
+
179
+ doc = Minitest::Mock.new
180
+ doc.expect(:wrap, :data, [[0, 1, 2, 3], type: HexaPDF::Rectangle])
181
+ @field.convert([0, 1, 2, 3], doc)
182
+ doc.verify
183
+ end
184
+ end
185
+ end