hexapdf 0.15.8 → 0.17.1

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 +10 -1
  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 +11 -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 +30 -4
  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 -954
  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,794 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require 'test_helper'
4
- require_relative '../../content/common'
5
- require 'hexapdf/document'
6
- require 'hexapdf/type/acro_form/appearance_generator'
7
-
8
- describe HexaPDF::Type::AcroForm::AppearanceGenerator do
9
- before do
10
- @doc = HexaPDF::Document.new
11
- @page = @doc.pages.add
12
- @form = @doc.acro_form(create: true)
13
- end
14
-
15
- describe "create_appearances" do
16
- before do
17
- @field = @doc.add({FT: :Btn}, type: :XXAcroFormField, subtype: :Btn)
18
- @widget = @doc.wrap({Parent: @field, Type: :Annot, Subtype: :Widget})
19
- @generator = HexaPDF::Type::AcroForm::AppearanceGenerator.new(@widget)
20
- end
21
-
22
- it "fails for unsupported button fields" do
23
- @field.flag(:push_button)
24
- @generator = HexaPDF::Type::AcroForm::AppearanceGenerator.new(@widget)
25
- assert_raises(HexaPDF::Error) { @generator.create_appearances }
26
- end
27
-
28
- it "fails for unsupported field types" do
29
- @field[:FT] = :Unknown
30
- assert_raises(HexaPDF::Error) { @generator.create_appearances }
31
- end
32
- end
33
-
34
- describe "background color and border" do
35
- before do
36
- @field = @doc.add({FT: :Btn}, type: :XXAcroFormField, subtype: :Btn)
37
- @widget = @field.create_widget(@page, defaults: false, Rect: [0, 0, 10, 20])
38
- @xform = @doc.add({Type: :XObject, Subtype: :Form, BBox: @widget[:Rect]})
39
- @generator = HexaPDF::Type::AcroForm::AppearanceGenerator.new(@widget)
40
- end
41
-
42
- def execute(circular = false)
43
- @generator.send(:apply_background_and_border, @widget.border_style, @xform.canvas,
44
- circular: circular)
45
- end
46
-
47
- it "applies no background color or border if none is set" do
48
- execute
49
- assert_operators(@xform.stream, [])
50
- end
51
-
52
- it "applies a background color if one set" do
53
- @widget.background_color(0.5)
54
- execute
55
- execute(true)
56
- assert_operators(@xform.stream,
57
- [[:save_graphics_state],
58
- [:set_device_gray_non_stroking_color, [0.5]],
59
- [:append_rectangle, [0, 0, 10, 20]],
60
- [:fill_path_non_zero], [:restore_graphics_state],
61
-
62
- [:save_graphics_state],
63
- [:set_device_gray_non_stroking_color, [0.5]],
64
- [:move_to, [10.0, 10.0]],
65
- [:curve_to, [10.0, 11.78411, 9.045085, 13.438072, 7.5, 14.330127]],
66
- [:curve_to, [5.954915, 15.222182, 4.045085, 15.222182, 2.5, 14.330127]],
67
- [:curve_to, [0.954915, 13.438072, 0.0, 11.78411, 0.0, 10.0]],
68
- [:curve_to, [-0.0, 8.21589, 0.954915, 6.561928, 2.5, 5.669873]],
69
- [:curve_to, [4.045085, 4.777818, 5.954915, 4.777818, 7.5, 5.669873]],
70
- [:curve_to, [9.045085, 6.561928, 10.0, 8.21589, 10.0, 10.0]],
71
- [:close_subpath], [:fill_path_non_zero], [:restore_graphics_state]])
72
- end
73
-
74
- it "sets the border color and width correctly" do
75
- @widget.border_style(color: 0.5, width: 4)
76
- execute
77
- execute(true)
78
- assert_operators(@xform.stream,
79
- [[:save_graphics_state],
80
- [:set_device_gray_stroking_color, [0.5]],
81
- [:set_line_width, [4]],
82
- [:append_rectangle, [2, 2, 6, 16]],
83
- [:stroke_path], [:restore_graphics_state],
84
-
85
- [:save_graphics_state],
86
- [:set_device_gray_stroking_color, [0.5]],
87
- [:set_line_width, [4]],
88
- [:move_to, [8.0, 10.0]],
89
- [:curve_to, [8.0, 11.070466, 7.427051, 12.062843, 6.5, 12.598076]],
90
- [:curve_to, [5.572949, 13.133309, 4.427051, 13.133309, 3.5, 12.598076]],
91
- [:curve_to, [2.572949, 12.062843, 2.0, 11.070466, 2.0, 10.0]],
92
- [:curve_to, [2.0, 8.929534, 2.572949, 7.937157, 3.5, 7.401924]],
93
- [:curve_to, [4.427051, 6.866691, 5.572949, 6.866691, 6.5, 7.401924]],
94
- [:curve_to, [7.427051, 7.937157, 8.0, 8.929534, 8.0, 10.0]],
95
- [:close_subpath], [:stroke_path], [:restore_graphics_state]])
96
- end
97
-
98
- it "handles the case of an underlined border" do
99
- @widget.border_style(style: :underlined, width: 2)
100
- execute
101
- execute(true)
102
- assert_operators(@xform.stream,
103
- [[:save_graphics_state],
104
- [:set_line_width, [2]],
105
- [:move_to, [1, 1]], [:line_to, [9.0, 1]],
106
- [:stroke_path], [:restore_graphics_state],
107
-
108
- [:save_graphics_state],
109
- [:set_line_width, [2]],
110
- [:move_to, [1.0, 10.0]],
111
- [:curve_to, [1.0, 8.572712, 1.763932, 7.249543, 3.0, 6.535898]],
112
- [:curve_to, [4.236068, 5.822254, 5.763932, 5.822254, 7.0, 6.535898]],
113
- [:curve_to, [8.236068, 7.249543, 9.0, 8.572712, 9.0, 10.0]],
114
- [:stroke_path], [:restore_graphics_state]])
115
- end
116
-
117
- it "handles the special case of a comb field" do
118
- @field = @doc.add({FT: :Tx, MaxLen: 4}, type: :XXAcroFormField, subtype: :Tx)
119
- @field.initialize_as_comb_text_field
120
- @widget = @field.create_widget(@page, Rect: [0, 0, 10, 20])
121
- @xform = @doc.add({Type: :XObject, Subtype: :Form, BBox: @widget[:Rect]})
122
- @generator = HexaPDF::Type::AcroForm::AppearanceGenerator.new(@widget)
123
- @widget.border_style(width: 2)
124
- execute
125
- assert_operators(@xform.stream,
126
- [[:save_graphics_state],
127
- [:set_line_width, [2]],
128
- [:append_rectangle, [1, 1, 8, 18]],
129
- [:move_to, [2.5, 2]], [:line_to, [2.5, 20.0]],
130
- [:move_to, [5.0, 2]], [:line_to, [5.0, 20.0]],
131
- [:move_to, [7.5, 2]], [:line_to, [7.5, 20.0]],
132
- [:stroke_path], [:restore_graphics_state]])
133
- end
134
- end
135
-
136
- describe "draw_marker" do
137
- before do
138
- @field = @doc.add({FT: :Btn}, type: :XXAcroFormField, subtype: :Btn)
139
- @widget = @field.create_widget(@page, defaults: false, Rect: [0, 0, 10, 20])
140
- @xform = @doc.add({Type: :XObject, Subtype: :Form, BBox: @widget[:Rect]})
141
- @generator = HexaPDF::Type::AcroForm::AppearanceGenerator.new(@widget)
142
- end
143
-
144
- def execute
145
- @generator.send(:draw_marker, @xform.canvas, @widget[:Rect], @widget.border_style.width,
146
- @widget.marker_style)
147
- end
148
-
149
- it "handles the marker :circle specially for radio button widgets" do
150
- @field.initialize_as_radio_button
151
- @widget.marker_style(style: :circle, color: 0.5)
152
- execute
153
- assert_operators(@xform.stream,
154
- [[:set_device_gray_non_stroking_color, [0.5]],
155
- [:move_to, [7.0, 10.0]],
156
- [:curve_to, [7.0, 10.713644, 6.618034, 11.375229, 6.0, 11.732051]],
157
- [:curve_to, [5.381966, 12.088873, 4.618034, 12.088873, 4.0, 11.732051]],
158
- [:curve_to, [3.381966, 11.375229, 3.0, 10.713644, 3.0, 10.0]],
159
- [:curve_to, [3.0, 9.286356, 3.381966, 8.624771, 4.0, 8.267949]],
160
- [:curve_to, [4.618034, 7.911127, 5.381966, 7.911127, 6.0, 8.267949]],
161
- [:curve_to, [6.618034, 8.624771, 7.0, 9.286356, 7.0, 10.0]],
162
- [:close_subpath],
163
- [:fill_path_non_zero]])
164
- end
165
-
166
- it "handles the marker :cross specially" do
167
- @widget.marker_style(style: :cross, color: 0.5)
168
- execute
169
- assert_operators(@xform.stream,
170
- [[:set_device_gray_stroking_color, [0.5]],
171
- [:move_to, [1, 1]], [:line_to, [9, 19]],
172
- [:move_to, [1, 19]], [:line_to, [9, 1]],
173
- [:stroke_path]])
174
- end
175
-
176
- describe "handles the normal markers by drawing them using the ZapfDingbats font" do
177
- it "works with font auto-sizing" do
178
- @widget.marker_style(style: :check, color: 0.5, size: 0)
179
- execute
180
- assert_operators(@xform.stream,
181
- [[:set_font_and_size, [:F1, 8]],
182
- [:set_device_gray_non_stroking_color, [0.5]],
183
- [:begin_text],
184
- [:set_text_matrix, [1, 0, 0, 1, 1.616, 7.236]],
185
- [:show_text, ["4"]],
186
- [:end_text]])
187
- end
188
-
189
- it "works with a fixed font size" do
190
- @widget.marker_style(style: :check, color: 0.5, size: 5)
191
- execute
192
- assert_operators(@xform.stream,
193
- [[:set_font_and_size, [:F1, 5]],
194
- [:set_device_gray_non_stroking_color, [0.5]],
195
- [:begin_text],
196
- [:set_text_matrix, [1, 0, 0, 1, 2.885, 8.2725]],
197
- [:show_text, ["4"]],
198
- [:end_text]])
199
- end
200
- end
201
- end
202
-
203
- describe "button fields" do
204
- before do
205
- @field = @doc.add({FT: :Btn}, type: :XXAcroFormField, subtype: :Btn)
206
- end
207
-
208
- describe "check box" do
209
- before do
210
- @widget = @field.create_widget(@page, Rect: [0, 0, 0, 0])
211
- @generator = HexaPDF::Type::AcroForm::AppearanceGenerator.new(@widget)
212
- @field.field_value = :Off
213
- end
214
-
215
- it "updates the widgets' /AS entry to point to the selected appearance" do
216
- @generator.create_appearances
217
- assert_equal(@field[:V], @widget[:AS])
218
- end
219
-
220
- it "set the print flag on the widgets" do
221
- @generator.create_appearances
222
- assert(@widget.flagged?(:print))
223
- end
224
-
225
- it "adjusts the /Rect if width is zero" do
226
- @generator.create_appearances
227
- assert_equal(12, @widget[:Rect].width)
228
- end
229
-
230
- it "adjusts the /Rect if height is zero" do
231
- @generator.create_appearances
232
- assert_equal(12, @widget[:Rect].height)
233
- end
234
-
235
- it "creates the needed appearance streams" do
236
- @generator.create_appearances
237
- assert_equal(:XObject, @widget[:AP][:N][:Off].type)
238
- assert_equal(:XObject, @widget[:AP][:N][:Yes].type)
239
- end
240
-
241
- it "creates the /Off appearance stream" do
242
- @generator.create_appearances
243
- assert_operators(@widget[:AP][:N][:Off].stream,
244
- [[:save_graphics_state],
245
- [:set_device_gray_non_stroking_color, [1.0]],
246
- [:append_rectangle, [0, 0, 12, 12]],
247
- [:fill_path_non_zero],
248
- [:append_rectangle, [0.5, 0.5, 11, 11]],
249
- [:stroke_path], [:restore_graphics_state]])
250
- end
251
-
252
- it "creates the /Yes appearance stream" do
253
- @generator.create_appearances
254
- assert_operators(@widget[:AP][:N][:Yes].stream,
255
- [[:save_graphics_state],
256
- [:set_device_gray_non_stroking_color, [1.0]],
257
- [:append_rectangle, [0, 0, 12, 12]],
258
- [:fill_path_non_zero],
259
- [:append_rectangle, [0.5, 0.5, 11, 11]],
260
- [:stroke_path], [:restore_graphics_state],
261
-
262
- [:save_graphics_state],
263
- [:set_font_and_size, [:F1, 10]],
264
- [:begin_text],
265
- [:set_text_matrix, [1, 0, 0, 1, 1.77, 2.545]],
266
- [:show_text, ["4"]],
267
- [:end_text],
268
- [:restore_graphics_state]])
269
- end
270
-
271
- it "fails if the appearance dictionaries are not set up" do
272
- @widget[:AP][:N].delete(:Off)
273
- assert_raises(HexaPDF::Error) { @generator.create_appearances }
274
- end
275
- end
276
-
277
- describe "radio button" do
278
- before do
279
- @field.initialize_as_radio_button
280
- @widget = @field.create_widget(@page, Rect: [0, 0, 0, 0], value: :radio)
281
- @generator = HexaPDF::Type::AcroForm::AppearanceGenerator.new(@widget)
282
- end
283
-
284
- it "updates the widgets' /AS entry to point to the selected appearance" do
285
- @field.field_value = :radio
286
- @generator.create_appearances
287
- assert_equal(@field[:V], @widget[:AS])
288
-
289
- @field.create_widget(@page, value: :other)
290
- @field.field_value = :other
291
- @generator.create_appearances
292
- assert_equal(:Off, @widget[:AS])
293
- end
294
-
295
- it "set the print flag on the widgets" do
296
- @generator.create_appearances
297
- assert(@widget.flagged?(:print))
298
- end
299
-
300
- it "adjusts the /Rect if width is zero" do
301
- @generator.create_appearances
302
- assert_equal(12, @widget[:Rect].width)
303
- end
304
-
305
- it "adjusts the /Rect if height is zero" do
306
- @generator.create_appearances
307
- assert_equal(12, @widget[:Rect].height)
308
- end
309
-
310
- it "creates the needed appearance streams" do
311
- @generator.create_appearances
312
- assert_equal(:XObject, @widget[:AP][:N][:Off].type)
313
- assert_equal(:XObject, @widget[:AP][:N][:radio].type)
314
- end
315
-
316
- it "creates the /Off appearance stream" do
317
- @widget.marker_style(style: :cross)
318
- @generator.create_appearances
319
- assert_operators(@widget[:AP][:N][:Off].stream,
320
- [[:save_graphics_state],
321
- [:set_device_gray_non_stroking_color, [1.0]],
322
- [:append_rectangle, [0, 0, 12, 12]],
323
- [:fill_path_non_zero],
324
- [:append_rectangle, [0.5, 0.5, 11, 11]],
325
- [:stroke_path], [:restore_graphics_state]])
326
- end
327
-
328
- it "creates the appearance stream according to the set value" do
329
- @widget.marker_style(style: :check)
330
- @generator.create_appearances
331
- assert_operators(@widget[:AP][:N][:radio].stream,
332
- [[:save_graphics_state],
333
- [:set_device_gray_non_stroking_color, [1.0]],
334
- [:append_rectangle, [0, 0, 12, 12]],
335
- [:fill_path_non_zero],
336
- [:append_rectangle, [0.5, 0.5, 11, 11]],
337
- [:stroke_path], [:restore_graphics_state],
338
-
339
- [:save_graphics_state],
340
- [:set_font_and_size, [:F1, 10]],
341
- [:begin_text],
342
- [:set_text_matrix, [1, 0, 0, 1, 1.77, 2.545]],
343
- [:show_text, ["4"]],
344
- [:end_text],
345
- [:restore_graphics_state]])
346
- end
347
-
348
- it "fails if the appearance dictionaries are not set up" do
349
- @widget[:AP][:N].delete(:radio)
350
- assert_raises(HexaPDF::Error) { @generator.create_appearances }
351
- end
352
- end
353
- end
354
-
355
- describe "text fields" do
356
- before do
357
- @form.set_default_appearance_string
358
- @field = @doc.add({FT: :Tx}, type: :XXAcroFormField, subtype: :Tx)
359
- @widget = @field.create_widget(@page, Rect: [0, 0, 0, 0])
360
- @generator = HexaPDF::Type::AcroForm::AppearanceGenerator.new(@widget)
361
- end
362
-
363
- it "updates the widgets to use the :N appearance stream" do
364
- @generator.create_appearances
365
- assert_equal(:N, @widget[:AS])
366
- end
367
-
368
- it "set the print flag on the widgets" do
369
- @generator.create_appearances
370
- assert(@widget.flagged?(:print))
371
- end
372
-
373
- describe "it adjusts the :Rect when necessary" do
374
- before do
375
- @widget.border_style(width: 3)
376
- end
377
-
378
- it "uses a default width if the width is zero" do
379
- @generator.create_appearances
380
- assert_equal(@doc.config['acro_form.text_field.default_width'], @widget[:Rect].width)
381
- end
382
-
383
- it "uses the font size of the /DA if non-zero as basis for the height if it is zero" do
384
- @field.set_default_appearance_string(font_size: 10)
385
- @generator.create_appearances
386
- assert_equal(15.25, @widget[:Rect].height)
387
- end
388
-
389
- it "uses a default font size as basis for the height if it and the set font size are zero" do
390
- assert_equal(0, @field.parse_default_appearance_string[1])
391
- @generator.create_appearances
392
- assert_equal(15.25, @widget[:Rect].height)
393
- end
394
- end
395
-
396
- it "adds an appropriate form XObject" do
397
- @generator.create_appearances
398
- form = @widget[:AP][:N]
399
- assert_equal(:XObject, form.type)
400
- assert_equal(:Form, form[:Subtype])
401
- assert_equal([0, 0, @widget[:Rect].width, @widget[:Rect].height], form[:BBox])
402
- assert_equal(@doc.acro_form.default_resources[:Font][:F1], form[:Resources][:Font][:F1])
403
- end
404
-
405
- it "re-uses the existing form XObject" do
406
- @field[:V] = 'test'
407
- @generator.create_appearances
408
- form = @widget[:AP][:N]
409
- form[:key] = :value
410
- form.delete(:Subtype)
411
- @widget[:AP][:N] = @doc.wrap(form, type: HexaPDF::Dictionary)
412
-
413
- @field[:V] = 'test1'
414
- @generator.create_appearances
415
- assert_equal(form, @widget[:AP][:N])
416
- refute(form.key?(:key))
417
- assert_match(/test1/, form.contents)
418
- end
419
-
420
- describe "font size calculation" do
421
- before do
422
- @widget[:Rect].height = 20
423
- @widget[:Rect].width = 100
424
- @field.field_value = ''
425
- end
426
-
427
- it "uses the non-zero font size" do
428
- @field.set_default_appearance_string(font_size: 10)
429
- @generator.create_appearances
430
- assert_operators(@widget[:AP][:N].stream,
431
- [:set_font_and_size, [:F1, 10]],
432
- range: 5)
433
- end
434
-
435
- it "calculates the font size based on the rectangle height and border width" do
436
- @generator.create_appearances
437
- assert_operators(@widget[:AP][:N].stream,
438
- [:set_font_and_size, [:F1, 12.923875]],
439
- range: 5)
440
- @widget.border_style(width: 2, color: :transparent)
441
- @generator.create_appearances
442
- assert_operators(@widget[:AP][:N].stream,
443
- [:set_font_and_size, [:F1, 11.487889]],
444
- range: 5)
445
- end
446
-
447
- it " in case of mulitline auto-sizing" do
448
- @field.initialize_as_multiline_text_field
449
- @field[:V] = 'a'
450
- @field.set_default_appearance_string(font_size: 0)
451
- @generator.create_appearances
452
- assert_operators(@widget[:AP][:N].stream,
453
- [:set_font_and_size, [:F1, 12]],
454
- range: 6)
455
- end
456
- end
457
-
458
- describe "single line text fields" do
459
- describe "quadding e.g. text alignment" do
460
- before do
461
- @field.field_value = 'Test'
462
- @field.set_default_appearance_string(font_size: 10)
463
- @widget[:Rect].height = 20
464
- end
465
-
466
- it "works for left aligned text" do
467
- @field.text_alignment(:left)
468
- @generator.create_appearances
469
- assert_operators(@widget[:AP][:N].stream,
470
- [:set_text_matrix, [1, 0, 0, 1, 2, 6.41]],
471
- range: 7)
472
- end
473
-
474
- it "works for right aligned text" do
475
- @field.text_alignment(:right)
476
- @generator.create_appearances
477
- assert_operators(@widget[:AP][:N].stream,
478
- [:set_text_matrix, [1, 0, 0, 1, 78.55, 6.41]],
479
- range: 7)
480
- end
481
-
482
- it "works for center aligned text" do
483
- @field.text_alignment(:center)
484
- @generator.create_appearances
485
- assert_operators(@widget[:AP][:N].stream,
486
- [:set_text_matrix, [1, 0, 0, 1, 40.275, 6.41]],
487
- range: 7)
488
- end
489
-
490
- it "vertically aligns to the font descender if the text is too high" do
491
- @widget[:Rect].height = 5
492
- @generator.create_appearances
493
- assert_operators(@widget[:AP][:N].stream,
494
- [:set_text_matrix, [1, 0, 0, 1, 2, 3.07]],
495
- range: 7)
496
- end
497
- end
498
-
499
- it "creates the /N appearance stream according to the set string" do
500
- @field.field_value = 'Text'
501
- @generator.create_appearances
502
- assert_operators(@widget[:AP][:N].stream,
503
- [[:begin_marked_content, [:Tx]],
504
- [:save_graphics_state],
505
- [:append_rectangle, [1, 1, 98, 9.25]],
506
- [:clip_path_non_zero],
507
- [:end_path],
508
- [:set_font_and_size, [:F1, 6.641436]],
509
- [:begin_text],
510
- [:set_text_matrix, [1, 0, 0, 1, 2, 3.240724]],
511
- [:show_text, ["Text"]],
512
- [:end_text],
513
- [:restore_graphics_state],
514
- [:end_marked_content]])
515
- end
516
- end
517
-
518
- describe "multiline text fields" do
519
- before do
520
- @field.set_default_appearance_string(font_size: 10)
521
- @field.initialize_as_multiline_text_field
522
- @widget[:Rect].height = 30
523
- @widget[:Rect].width = 100
524
- end
525
-
526
- describe "quadding e.g. text alignment" do
527
- before do
528
- @field[:V] = "Test\nValue"
529
- end
530
-
531
- it "works for left aligned text" do
532
- @field.text_alignment(:left)
533
- @generator.create_appearances
534
- assert_operators(@widget[:AP][:N].stream,
535
- [:set_text_matrix, [1, 0, 0, 1, 2, 16.195]],
536
- range: 9)
537
- end
538
-
539
- it "works for right aligned text" do
540
- @field.text_alignment(:right)
541
- @generator.create_appearances
542
- assert_operators(@widget[:AP][:N].stream,
543
- [:set_text_matrix, [1, 0, 0, 1, 78.55, 16.195]],
544
- range: 9)
545
- end
546
-
547
- it "works for center aligned text" do
548
- @field.text_alignment(:center)
549
- @generator.create_appearances
550
- assert_operators(@widget[:AP][:N].stream,
551
- [:set_text_matrix, [1, 0, 0, 1, 40.275, 16.195]],
552
- range: 9)
553
- end
554
- end
555
-
556
- it "creates the /N appearance stream according to the set string" do
557
- @field.field_value = "Test\nValue"
558
- @generator.create_appearances
559
- assert_operators(@widget[:AP][:N].stream,
560
- [[:begin_marked_content, [:Tx]],
561
- [:save_graphics_state],
562
- [:append_rectangle, [1, 1, 98, 28]],
563
- [:clip_path_non_zero],
564
- [:end_path],
565
- [:save_graphics_state],
566
- [:set_leading, [11.5625]],
567
- [:set_font_and_size, [:F1, 10]],
568
- [:begin_text],
569
- [:set_text_matrix, [1, 0, 0, 1, 2, 16.195]],
570
- [:show_text, ['Test']],
571
- [:move_text_next_line],
572
- [:show_text, ['Value']],
573
- [:end_text],
574
- [:restore_graphics_state],
575
- [:restore_graphics_state],
576
- [:end_marked_content]])
577
-
578
- @field.field_value = "Test\nTest\nTest"
579
- @field.set_default_appearance_string(font_size: 0)
580
- @generator.create_appearances
581
- assert_operators(@widget[:AP][:N].stream,
582
- [[:begin_marked_content, [:Tx]],
583
- [:save_graphics_state],
584
- [:append_rectangle, [1, 1, 98, 28]],
585
- [:clip_path_non_zero],
586
- [:end_path],
587
- [:save_graphics_state],
588
- [:set_leading, [9.25]],
589
- [:set_font_and_size, [:F1, 8]],
590
- [:begin_text],
591
- [:set_text_matrix, [1, 0, 0, 1, 2, 18.556]],
592
- [:show_text, ['Test']],
593
- [:move_text_next_line],
594
- [:show_text, ['Test']],
595
- [:move_text_next_line],
596
- [:show_text, ['Test']],
597
- [:end_text],
598
- [:restore_graphics_state],
599
- [:restore_graphics_state],
600
- [:end_marked_content]],
601
- )
602
- end
603
- end
604
-
605
- describe "comb text fields" do
606
- before do
607
- @field.set_default_appearance_string(font_size: 10)
608
- @field.initialize_as_comb_text_field
609
- @field[:MaxLen] = 10
610
- @widget[:Rect].height = 20
611
- @widget[:Rect].width = 100
612
- end
613
-
614
- describe "quadding e.g. text alignment" do
615
- before do
616
- @field[:V] = 'Test'
617
- end
618
-
619
- it "works for left aligned text" do
620
- @field.text_alignment(:left)
621
- @generator.create_appearances
622
- assert_operators(@widget[:AP][:N].stream,
623
- [:set_text_matrix, [1, 0, 0, 1, 2.945, 6.41]],
624
- range: 7)
625
- end
626
-
627
- it "works for right aligned text" do
628
- @field.text_alignment(:right)
629
- @generator.create_appearances
630
- assert_operators(@widget[:AP][:N].stream,
631
- [:set_text_matrix, [1, 0, 0, 1, 62.945, 6.41]],
632
- range: 7)
633
- end
634
-
635
- it "works for center aligned text" do
636
- @field.text_alignment(:center)
637
- @generator.create_appearances
638
- assert_operators(@widget[:AP][:N].stream,
639
- [:set_text_matrix, [1, 0, 0, 1, 32.945, 6.41]],
640
- range: 7)
641
- end
642
-
643
- it "handles centering like Adobe, e.g. shift left, when text cannot be completely centered" do
644
- @field.field_value = 'Hello'
645
- @field.text_alignment(:center)
646
- @generator.create_appearances
647
- assert_operators(@widget[:AP][:N].stream,
648
- [:set_text_matrix, [1, 0, 0, 1, 22.39, 6.41]],
649
- range: 7)
650
- end
651
- end
652
-
653
- it "creates the /N appearance stream according to the set string" do
654
- @field.field_value = 'Text'
655
- @generator.create_appearances
656
- assert_operators(@widget[:AP][:N].stream,
657
- [[:begin_marked_content, [:Tx]],
658
- [:save_graphics_state],
659
- [:append_rectangle, [1, 1, 98, 18]],
660
- [:clip_path_non_zero],
661
- [:end_path],
662
- [:set_font_and_size, [:F1, 10]],
663
- [:begin_text],
664
- [:set_text_matrix, [1, 0, 0, 1, 2.945, 6.41]],
665
- [:show_text_with_positioning, [['T', -416.5, 'e', -472, 'x', -611, 't']]],
666
- [:end_text],
667
- [:restore_graphics_state],
668
- [:end_marked_content]])
669
- end
670
-
671
- it "fails if the /MaxLen key is not set" do
672
- @field.delete(:MaxLen)
673
- @field[:V] = 't'
674
- assert_raises(HexaPDF::Error) { @generator.create_appearances }
675
- end
676
- end
677
-
678
- describe "choice fields" do
679
- it "works for combo boxes by using the text appearance method" do
680
- @form.set_default_appearance_string
681
- field = @doc.add({FT: :Ch}, type: :XXAcroFormField, subtype: :Ch)
682
- field.initialize_as_combo_box
683
- field.flag(:edit)
684
- field.field_value = 'Test'
685
- widget = field.create_widget(@page, Rect: [0, 0, 0, 0])
686
- generator = HexaPDF::Type::AcroForm::AppearanceGenerator.new(widget)
687
- generator.create_appearances
688
- assert_kind_of(HexaPDF::Type::Form, widget[:AP][:N])
689
- end
690
-
691
- describe "list boxes" do
692
- before do
693
- @field = @doc.add({FT: :Ch}, type: :XXAcroFormField, subtype: :Ch)
694
- @field.initialize_as_list_box
695
- @field.flag(:multi_select)
696
- @field.option_items = ['a', 'b', 'c']
697
- @widget = @field.create_widget(@page, Rect: [0, 0, 90, 36])
698
- @generator = HexaPDF::Type::AcroForm::AppearanceGenerator.new(@widget)
699
- end
700
-
701
- it "uses a fixed font size for list box items if auto-sizing is used" do
702
- @field.set_default_appearance_string(font_size: 0)
703
- @generator.create_appearances
704
- assert_operators(@widget[:AP][:N].stream,
705
- [:set_font_and_size, [:F1, 12]],
706
- range: 8)
707
- end
708
-
709
- it "uses the set values instead of the ones from /I if in conflict" do
710
- @field[:I] = [0, 1]
711
- @field[:V] = ['b']
712
- @generator.create_appearances
713
- assert_operators(@widget[:AP][:N].stream,
714
- [[:set_device_rgb_non_stroking_color, [0.6, 0.756863, 0.854902]],
715
- [:append_rectangle, [1, 7.25, 88, 13.875]],
716
- [:fill_path_non_zero]],
717
- range: 5..7)
718
- end
719
-
720
- it "creates the /N appearance stream" do
721
- @field[:I] = [1, 2]
722
- @field[:V] = ['b', 'c']
723
- @generator.create_appearances
724
- assert_operators(@widget[:AP][:N].stream,
725
- [[:begin_marked_content, [:Tx]],
726
- [:save_graphics_state],
727
- [:append_rectangle, [1, 1, 88, 34]],
728
- [:clip_path_non_zero], [:end_path],
729
- [:set_device_rgb_non_stroking_color, [0.6, 0.756863, 0.854902]],
730
- [:append_rectangle, [1, 7.25, 88, 13.875]],
731
- [:append_rectangle, [1, -6.625, 88, 13.875]],
732
- [:fill_path_non_zero],
733
- [:save_graphics_state],
734
- [:set_leading, [13.875]],
735
- [:set_font_and_size, [:F1, 12]],
736
- [:set_device_gray_non_stroking_color, [0.0]],
737
- [:begin_text],
738
- [:set_text_matrix, [1, 0, 0, 1, 2, 23.609]],
739
- [:show_text, ["a"]],
740
- [:move_text_next_line],
741
- [:show_text, ["b"]],
742
- [:end_text],
743
- [:restore_graphics_state], [:restore_graphics_state],
744
- [:end_marked_content]])
745
- end
746
- end
747
- end
748
-
749
- describe "font resolution in case the referenced font is not usable" do
750
- before do
751
- @doc.config['acro_form.fallback_font'] = ['Times', {variant: :italic}]
752
- @field[:V] = 'Test'
753
- end
754
-
755
- it "uses the fallback font if the font is not usable" do
756
- def (@form.default_resources.font(:F1)).font_wrapper; nil; end
757
- @generator.create_appearances
758
- assert_equal(:'Times-Italic', @widget[:AP][:N][:Resources][:Font][:F2][:BaseFont])
759
- end
760
-
761
- it "uses the fallback font if the font is not found" do
762
- @form.default_resources[:Font].delete(:F1)
763
- @generator.create_appearances
764
- assert_equal(:'Times-Italic', @widget[:AP][:N][:Resources][:Font][:F1][:BaseFont])
765
- end
766
-
767
- it "respects a simple fallback font name" do
768
- @doc.config['acro_form.fallback_font'] = 'Times'
769
- @form.default_resources[:Font].delete(:F1)
770
- @generator.create_appearances
771
- assert_equal(:'Times-Roman', @widget[:AP][:N][:Resources][:Font][:F1][:BaseFont])
772
- end
773
-
774
- it "respects a fallback font callable object" do
775
- field = @field
776
- @doc.config['acro_form.fallback_font'] = proc do |field_arg, font_arg|
777
- assert_same(field.data, field_arg.data)
778
- assert_nil(font_arg)
779
- 'Times'
780
- end
781
- @form.default_resources[:Font].delete(:F1)
782
- @generator.create_appearances
783
- assert_equal(:'Times-Roman', @widget[:AP][:N][:Resources][:Font][:F1][:BaseFont])
784
- end
785
-
786
- it "fails if fallback fonts are disabled" do
787
- @doc.config['acro_form.fallback_font'] = nil
788
- @form.default_resources[:Font].delete(:F1)
789
- msg = assert_raises(HexaPDF::Error) { @generator.create_appearances }
790
- assert_match(/Font.*not usable/, msg.message)
791
- end
792
- end
793
- end
794
- end