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,269 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ #--
4
+ # This file is part of HexaPDF.
5
+ #
6
+ # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
+ # Copyright (C) 2016 Thomas Leitner
8
+ #
9
+ # HexaPDF is free software: you can redistribute it and/or modify it
10
+ # under the terms of the GNU Affero General Public License version 3 as
11
+ # published by the Free Software Foundation with the addition of the
12
+ # following permission added to Section 15 as permitted in Section 7(a):
13
+ # FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
14
+ # THOMAS LEITNER, THOMAS LEITNER DISCLAIMS THE WARRANTY OF NON
15
+ # INFRINGEMENT OF THIRD PARTY RIGHTS.
16
+ #
17
+ # HexaPDF is distributed in the hope that it will be useful, but WITHOUT
18
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
20
+ # License for more details.
21
+ #
22
+ # You should have received a copy of the GNU Affero General Public License
23
+ # along with HexaPDF. If not, see <http://www.gnu.org/licenses/>.
24
+ #
25
+ # The interactive user interfaces in modified source and object code
26
+ # versions of HexaPDF must display Appropriate Legal Notices, as required
27
+ # under Section 5 of the GNU Affero General Public License version 3.
28
+ #
29
+ # In accordance with Section 7(b) of the GNU Affero General Public
30
+ # License, a covered work must retain the producer line in every PDF that
31
+ # is created or manipulated using HexaPDF.
32
+ #++
33
+
34
+ require 'hexapdf/dictionary'
35
+
36
+ module HexaPDF
37
+ module Type
38
+
39
+ # Represents a node in the page tree of the PDF's document.
40
+ #
41
+ # The page tree is a tree structure containing page tree nodes for the root and intermediate
42
+ # nodes and page objects for the leaf nodes (see Page). The root node of the page tree is
43
+ # linked via the /Pages entry in the Catalog.
44
+ #
45
+ # All operations except #add_page on the page tree are rather expensive because page tree
46
+ # nodes and page objects can be mixed. This means that for finding a page at a specific index
47
+ # we have to go through all objects that come before it.
48
+ #
49
+ # Page indices are zero-based, not one-based. Therefore the first page has an index of 0!
50
+ #
51
+ # Since the page tree needs a certain structure it is not advised to directly modify page tree
52
+ # nodes. The validation feature can correct most problems but until the page tree is in order
53
+ # the methods may not work correctly!
54
+ #
55
+ # Newly created pages use the 'page.default_media_box' configuration option for the /MediaBox
56
+ # value. If an inherited /Resources dictionary does *not* exist, an empty one is created for
57
+ # the page.
58
+ #
59
+ # See: PDF1.7 s7.7.3.2, Page
60
+ class PageTreeNode < Dictionary
61
+
62
+ define_field :Type, type: Symbol, required: true, default: :Pages
63
+ define_field :Parent, type: Dictionary, indirect: true
64
+ define_field :Kids, type: Array, required: true, default: []
65
+ define_field :Count, type: Integer, required: true, default: 0
66
+
67
+ # Inheritable page fields
68
+ define_field :Resources, type: :XXResources
69
+ define_field :MediaBox, type: Rectangle
70
+ define_field :CropBox, type: Rectangle
71
+ define_field :Rotate, type: Integer
72
+
73
+
74
+ # Returns +true+ since page tree objects must always be indirect.
75
+ def must_be_indirect?
76
+ true
77
+ end
78
+
79
+ # Returns the number of pages under this page tree.
80
+ #
81
+ # *Note*: If this methods is not called on the root object of the page tree, the returned
82
+ # number is not the total number of pages in the document!
83
+ def page_count
84
+ self[:Count]
85
+ end
86
+
87
+ # Returns the page for the zero-based index or +nil+ if no such page exists.
88
+ #
89
+ # Negative indices count backwards from the end, i.e. -1 is the last page.
90
+ def page(index)
91
+ index = self[:Count] + index if index < 0
92
+ return nil if index < 0 || index >= self[:Count]
93
+
94
+ self[:Kids].each do |kid|
95
+ kid = document.deref(kid)
96
+ if kid.type == :Page
97
+ if index == 0
98
+ return kid
99
+ else
100
+ index -= 1
101
+ end
102
+ elsif index < kid[:Count]
103
+ return kid.page(index)
104
+ else
105
+ index -= kid[:Count]
106
+ end
107
+ end
108
+ end
109
+
110
+ # Inserts the page or a new empty page at the zero-based index and returns it.
111
+ #
112
+ # Negative indices count backwards from the end, i.e. -1 is the last page. When using
113
+ # negative indices, the page will be inserted after that element. So using an index of -1
114
+ # will insert the page after the last page.
115
+ #
116
+ # Must be called on the root of the page tree, otherwise the /Count entries are not
117
+ # correctly updated!
118
+ def insert_page(index, page = nil)
119
+ page ||= new_page
120
+ index = self[:Count] + index + 1 if index < 0
121
+
122
+ if index >= self[:Count]
123
+ self[:Kids] << page
124
+ page[:Parent] = self
125
+ page[:Resources] ||= {}
126
+ else
127
+ self[:Kids].each_with_index do |kid, kid_index|
128
+ kid = document.deref(kid)
129
+ if index == 0
130
+ self[:Kids].insert(kid_index, page)
131
+ page[:Parent] = self
132
+ break
133
+ elsif kid.type == :Page
134
+ index -= 1
135
+ elsif index <= kid[:Count]
136
+ kid.insert_page(index, page)
137
+ break
138
+ else
139
+ index -= kid[:Count]
140
+ end
141
+ end
142
+ end
143
+
144
+ self[:Count] += 1
145
+
146
+ page
147
+ end
148
+
149
+ # Adds the page or a new empty page at the end and returns it.
150
+ def add_page(page = nil)
151
+ insert_page(-1, page)
152
+ end
153
+
154
+ # Deletes the page at the position specified by the zero-based index and returns it. If an
155
+ # invalid index is specified, +nil+ is returned.
156
+ #
157
+ # Negative indices count backwards from the end, i.e. -1 is the last page.
158
+ #
159
+ # Must be called on the root of the page tree, otherwise the /Count entries are not
160
+ # correctly updated!
161
+ def delete_page(index)
162
+ index = self[:Count] + index if index < 0
163
+ return nil if index < 0 || index >= self[:Count]
164
+
165
+ page = nil
166
+ self[:Count] -= 1
167
+ self[:Kids].each_with_index do |kid, kid_index|
168
+ kid = document.deref(kid)
169
+ if kid.type == :Page && index == 0
170
+ page = self[:Kids].delete_at(kid_index)
171
+ document.delete(page)
172
+ break
173
+ elsif kid.type == :Page
174
+ index -= 1
175
+ elsif index < kid[:Count]
176
+ page = kid.delete_page(index)
177
+ if kid[:Count] == 0
178
+ self[:Kids].delete_at(kid_index)
179
+ document.delete(kid)
180
+ elsif kid[:Count] == 1
181
+ self[:Kids][kid_index] = kid[:Kids][0]
182
+ kid[:Kids][0][:Parent] = self
183
+ document.delete(kid)
184
+ end
185
+ break
186
+ else
187
+ index -= kid[:Count]
188
+ end
189
+ end
190
+
191
+ page
192
+ end
193
+
194
+ # :call-seq:
195
+ # pages.each_page {|page| block } -> pages
196
+ # pages.each_page -> Enumerator
197
+ #
198
+ # Iterates over all pages that are beneath this page tree node, from the first to the last
199
+ # page.
200
+ def each_page(&block)
201
+ return to_enum(__method__) unless block_given?
202
+
203
+ self[:Kids].each do |kid|
204
+ kid = document.deref(kid)
205
+ if kid.type == :Page
206
+ yield(kid)
207
+ else
208
+ kid.each_page(&block)
209
+ end
210
+ end
211
+
212
+ self
213
+ end
214
+
215
+ private
216
+
217
+ # Returns a new page object, correctly initialized using the document's configuration
218
+ # options.
219
+ def new_page
220
+ media_box = config['page.default_media_box']
221
+ media_box = Page::PAPER_SIZE[media_box].dup if Page::PAPER_SIZE.key?(media_box)
222
+ document.add(Type: :Page, MediaBox: media_box)
223
+ end
224
+
225
+ # Ensures that the /Count and /Parent fields of the whole page tree are set up correctly and
226
+ # that there is at least one page node. This is therefore only done for the root node of the
227
+ # page tree!
228
+ def perform_validation
229
+ super
230
+ return if key?(:Parent)
231
+
232
+ validate_node = lambda do |node|
233
+ count = 0
234
+ node[:Kids].reject! do |kid|
235
+ kid = document.deref(kid)
236
+ if !kid.kind_of?(HexaPDF::Object) || kid.null? ||
237
+ (kid.type != :Page && kid.type != :Pages)
238
+ yield("Invalid object in page tree node", true)
239
+ next true
240
+ elsif kid.type == :Page
241
+ count += 1
242
+ else
243
+ count += validate_node.call(kid)
244
+ end
245
+ if kid[:Parent] != node
246
+ yield("Field Parent of page tree node (#{kid.oid},#{kid.gen}) is invalid", true)
247
+ kid[:Parent] = node
248
+ end
249
+ false
250
+ end
251
+ if node[:Count] != count
252
+ yield("Field Count of page tree node (#{node.oid},#{node.gen}) is invalid", true)
253
+ node[:Count] = count
254
+ end
255
+ count
256
+ end
257
+
258
+ validate_node.call(self)
259
+
260
+ if self[:Count] == 0
261
+ yield("A PDF document needs at least one page", true)
262
+ add_page.validate {|msg, correctable| yield(msg, correctable)}
263
+ end
264
+ end
265
+
266
+ end
267
+
268
+ end
269
+ end
@@ -0,0 +1,212 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ #--
4
+ # This file is part of HexaPDF.
5
+ #
6
+ # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
+ # Copyright (C) 2016 Thomas Leitner
8
+ #
9
+ # HexaPDF is free software: you can redistribute it and/or modify it
10
+ # under the terms of the GNU Affero General Public License version 3 as
11
+ # published by the Free Software Foundation with the addition of the
12
+ # following permission added to Section 15 as permitted in Section 7(a):
13
+ # FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
14
+ # THOMAS LEITNER, THOMAS LEITNER DISCLAIMS THE WARRANTY OF NON
15
+ # INFRINGEMENT OF THIRD PARTY RIGHTS.
16
+ #
17
+ # HexaPDF is distributed in the hope that it will be useful, but WITHOUT
18
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
20
+ # License for more details.
21
+ #
22
+ # You should have received a copy of the GNU Affero General Public License
23
+ # along with HexaPDF. If not, see <http://www.gnu.org/licenses/>.
24
+ #
25
+ # The interactive user interfaces in modified source and object code
26
+ # versions of HexaPDF must display Appropriate Legal Notices, as required
27
+ # under Section 5 of the GNU Affero General Public License version 3.
28
+ #
29
+ # In accordance with Section 7(b) of the GNU Affero General Public
30
+ # License, a covered work must retain the producer line in every PDF that
31
+ # is created or manipulated using HexaPDF.
32
+ #++
33
+
34
+ require 'hexapdf/error'
35
+ require 'hexapdf/configuration'
36
+ require 'hexapdf/dictionary'
37
+ require 'hexapdf/content/color_space'
38
+
39
+ module HexaPDF
40
+ module Type
41
+
42
+ # Represents the resources needed by a content stream.
43
+ #
44
+ # See: PDF1.7 s7.8.3
45
+ class Resources < Dictionary
46
+
47
+ define_field :ExtGState, type: Dictionary
48
+ define_field :ColorSpace, type: Dictionary
49
+ define_field :Pattern, type: Dictionary
50
+ define_field :Shading, type: Dictionary, version: '1.3'
51
+ define_field :XObject, type: Dictionary
52
+ define_field :Font, type: Dictionary
53
+ define_field :ProcSet, type: Array
54
+ define_field :Properties, type: Dictionary, version: '1.2'
55
+
56
+ # Returns +:XXResources+.
57
+ def type
58
+ :XXResources
59
+ end
60
+
61
+ # Returns the color space stored under the given name.
62
+ #
63
+ # If the color space is not found, an error is raised.
64
+ #
65
+ # Note: The color spaces :DeviceGray, :DeviceRGB and :DeviceCMYK are returned without a
66
+ # lookup since they are fixed.
67
+ def color_space(name)
68
+ case name
69
+ when :DeviceRGB, :DeviceGray, :DeviceCMYK
70
+ GlobalConfiguration.constantize('color_space.map'.freeze, name).new
71
+ else
72
+ space_definition = self[:ColorSpace] && self[:ColorSpace][name]
73
+ if space_definition.nil?
74
+ raise HexaPDF::Error, "Color space '#{name}' not found in the resources"
75
+ elsif space_definition.kind_of?(Array)
76
+ space_definition.map! {|item| document.deref(item)}
77
+ space_family = space_definition[0]
78
+ else
79
+ space_family = space_definition
80
+ space_definition = [space_definition]
81
+ end
82
+
83
+ GlobalConfiguration.constantize('color_space.map'.freeze, space_family) do
84
+ HexaPDF::Content::ColorSpace::Universal
85
+ end.new(space_definition)
86
+ end
87
+ end
88
+
89
+ # Adds the color space to the resources and returns the name under which it is stored.
90
+ #
91
+ # If there already exists a color space with the same definition, it is reused. The device
92
+ # color spaces +:DeviceGray+, +:DeviceRGB+ and +:DeviceCMYK+ are never stored, their
93
+ # respective name is just returned.
94
+ def add_color_space(color_space)
95
+ family = color_space.family
96
+ return family if family == :DeviceRGB || family == :DeviceGray || family == :DeviceCMYK
97
+
98
+ definition = color_space.definition
99
+ self[:ColorSpace] = {} unless key?(:ColorSpace)
100
+ color_space_dict = self[:ColorSpace]
101
+
102
+ name, _value = color_space_dict.value.find do |_k, v|
103
+ v.map! {|item| document.deref(item)}
104
+ v == definition
105
+ end
106
+ unless name
107
+ name = create_resource_name(color_space_dict.value, 'CS')
108
+ color_space_dict[name] = definition
109
+ end
110
+ name
111
+ end
112
+
113
+ # Returns the XObject stored under the given name.
114
+ #
115
+ # If the XObject is not found, an error is raised.
116
+ def xobject(name)
117
+ object_getter(:XObject, name)
118
+ end
119
+
120
+ # Adds the XObject to the resources and returns the name under which it is stored.
121
+ #
122
+ # If there already exists a name for the given XObject, it is just returned.
123
+ def add_xobject(object)
124
+ object_setter(:XObject, 'XO'.freeze, object)
125
+ end
126
+
127
+ # Returns the graphics state parameter dictionary (see Type::GraphicsStateParameter) stored
128
+ # under the given name.
129
+ #
130
+ # If the dictionary is not found, an error is raised.
131
+ def ext_gstate(name)
132
+ object_getter(:ExtGState, name)
133
+ end
134
+
135
+ # Adds the graphics state parameter dictionary to the resources and returns the name under
136
+ # which it is stored.
137
+ #
138
+ # If there already exists a name for the given dictionary, it is just returned.
139
+ def add_ext_gstate(object)
140
+ object_setter(:ExtGState, 'GS'.freeze, object)
141
+ end
142
+
143
+ # Returns the font dictionary stored under the given name.
144
+ #
145
+ # If the dictionary is not found, an error is raised.
146
+ def font(name)
147
+ object_getter(:Font, name)
148
+ end
149
+
150
+ # Adds the font dictionary to the resources and returns the name under which it is stored.
151
+ #
152
+ # If there already exists a name for the given dictionary, it is just returned.
153
+ def add_font(object)
154
+ object_setter(:Font, 'F'.freeze, object)
155
+ end
156
+
157
+ private
158
+
159
+ # Helper method for returning an entry of a subdictionary.
160
+ def object_getter(dict_name, name)
161
+ obj = self[dict_name] && self[dict_name][name]
162
+ if obj.nil?
163
+ raise HexaPDF::Error, "No object called '#{name}' stored under /#{dict_name}"
164
+ end
165
+ obj
166
+ end
167
+
168
+ # Helper method for setting an entry of a subdictionary.
169
+ def object_setter(dict_name, prefix, object)
170
+ self[dict_name] = {} unless key?(dict_name)
171
+ dict = self[dict_name]
172
+ name, _value = dict.each.find {|_, dict_obj| dict_obj == object}
173
+ unless name
174
+ name = create_resource_name(dict.value, prefix)
175
+ dict[name] = object
176
+ end
177
+ name
178
+ end
179
+
180
+ # Returns a unique name that can be used to store a resource in the given hash.
181
+ def create_resource_name(hash, prefix)
182
+ n = hash.size + 1
183
+ while true
184
+ name = :"#{prefix}#{n}"
185
+ return name unless hash.key?(name)
186
+ n += 1
187
+ end
188
+ end
189
+
190
+ # Ensures that a valid procedure set is available.
191
+ def perform_validation
192
+ super
193
+ val = self[:ProcSet]
194
+ if !val
195
+ self[:ProcSet] = [:PDF, :Text, :ImageB, :ImageC, :ImageI]
196
+ else
197
+ val.reject! do |name|
198
+ case name
199
+ when :PDF, :Text, :ImageB, :ImageC, :ImageI
200
+ false
201
+ else
202
+ yield("Invalid page procedure set name /#{name}", true)
203
+ true
204
+ end
205
+ end
206
+ end
207
+ end
208
+
209
+ end
210
+
211
+ end
212
+ end
@@ -0,0 +1,128 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ #--
4
+ # This file is part of HexaPDF.
5
+ #
6
+ # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
+ # Copyright (C) 2016 Thomas Leitner
8
+ #
9
+ # HexaPDF is free software: you can redistribute it and/or modify it
10
+ # under the terms of the GNU Affero General Public License version 3 as
11
+ # published by the Free Software Foundation with the addition of the
12
+ # following permission added to Section 15 as permitted in Section 7(a):
13
+ # FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
14
+ # THOMAS LEITNER, THOMAS LEITNER DISCLAIMS THE WARRANTY OF NON
15
+ # INFRINGEMENT OF THIRD PARTY RIGHTS.
16
+ #
17
+ # HexaPDF is distributed in the hope that it will be useful, but WITHOUT
18
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
20
+ # License for more details.
21
+ #
22
+ # You should have received a copy of the GNU Affero General Public License
23
+ # along with HexaPDF. If not, see <http://www.gnu.org/licenses/>.
24
+ #
25
+ # The interactive user interfaces in modified source and object code
26
+ # versions of HexaPDF must display Appropriate Legal Notices, as required
27
+ # under Section 5 of the GNU Affero General Public License version 3.
28
+ #
29
+ # In accordance with Section 7(b) of the GNU Affero General Public
30
+ # License, a covered work must retain the producer line in every PDF that
31
+ # is created or manipulated using HexaPDF.
32
+ #++
33
+
34
+ require 'hexapdf/dictionary'
35
+ require 'digest/md5'
36
+
37
+ module HexaPDF
38
+ module Type
39
+
40
+ # Represents the PDF file trailer.
41
+ #
42
+ # The file trailer is the starting point for the PDF's object tree. It links to the Catalog
43
+ # (the main PDF document structure) and the Info dictionary and holds the information
44
+ # necessary for encrypting the PDF document.
45
+ #
46
+ # Since a PDF document can contain multiple revisions, each revision needs to have its own
47
+ # file trailer (see HexaPDF::Revision#trailer).
48
+ #
49
+ # When cross-reference streams are used the information that is normally stored in the file
50
+ # trailer is stored directly in the cross-reference stream dictionary. However, a
51
+ # HexaPDF::Revision object's trailer dictionary is always of this type. Only when a
52
+ # cross-reference stream is written is the trailer integrated into the stream's dictionary.
53
+ #
54
+ # See: PDF1.7 s7.5.5, s14.4
55
+ # XRefStream
56
+ class Trailer < Dictionary
57
+
58
+ define_field :Size, type: Integer, indirect: false # will be auto-set when written
59
+ define_field :Prev, type: Integer
60
+ define_field :Root, type: :Catalog, indirect: true
61
+ define_field :Encrypt, type: Dictionary
62
+ define_field :Info, type: :XXInfo, indirect: true
63
+ define_field :ID, type: Array
64
+ define_field :XRefStm, type: Integer, version: '1.5'
65
+
66
+ # Returns +:XXTrailer+.
67
+ def type
68
+ :XXTrailer
69
+ end
70
+
71
+ # Returns the document's Catalog (see Type::Catalog), creating it if needed.
72
+ def catalog
73
+ self[:Root] ||= document.add(Type: :Catalog)
74
+ end
75
+
76
+ # Returns the document's information dictionary (see Type::Info), creating it if needed.
77
+ def info
78
+ self[:Info] ||= document.add({}, type: :XXInfo)
79
+ end
80
+
81
+ # Sets the /ID field to an array of two copies of a random string and returns this array.
82
+ #
83
+ # See: PDF1.7 14.4
84
+ def set_random_id
85
+ value[:ID] = [Digest::MD5.digest(rand.to_s)] * 2
86
+ end
87
+
88
+ # Updates the second part of the /ID field (the first part should always be the same for a
89
+ # PDF file, the second part should change with each write).
90
+ def update_id
91
+ if !value[:ID]
92
+ set_random_id
93
+ else
94
+ value[:ID][1] = Digest::MD5.digest(rand.to_s)
95
+ end
96
+ end
97
+
98
+ private
99
+
100
+ # Validates the trailer.
101
+ def perform_validation
102
+ super
103
+ unless value[:ID]
104
+ msg = if value[:Encrypt]
105
+ "ID field is required when an Encrypt dictionary is present"
106
+ else
107
+ "ID field should always be set"
108
+ end
109
+ yield(msg, true)
110
+ set_random_id
111
+ end
112
+
113
+ unless value[:Root]
114
+ yield("A PDF document must have a Catalog dictionary", true)
115
+ value[:Root] = document.add(Type: :Catalog)
116
+ value[:Root].validate {|message, correctable| yield(message, correctable)}
117
+ end
118
+
119
+ if value[:Encrypt] && (!document.security_handler ||
120
+ !document.security_handler.encryption_key_valid?)
121
+ yield("Encryption key doesn't match encryption dictionary", false)
122
+ end
123
+ end
124
+
125
+ end
126
+
127
+ end
128
+ end
@@ -0,0 +1,73 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ #--
4
+ # This file is part of HexaPDF.
5
+ #
6
+ # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
+ # Copyright (C) 2016 Thomas Leitner
8
+ #
9
+ # HexaPDF is free software: you can redistribute it and/or modify it
10
+ # under the terms of the GNU Affero General Public License version 3 as
11
+ # published by the Free Software Foundation with the addition of the
12
+ # following permission added to Section 15 as permitted in Section 7(a):
13
+ # FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
14
+ # THOMAS LEITNER, THOMAS LEITNER DISCLAIMS THE WARRANTY OF NON
15
+ # INFRINGEMENT OF THIRD PARTY RIGHTS.
16
+ #
17
+ # HexaPDF is distributed in the hope that it will be useful, but WITHOUT
18
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
20
+ # License for more details.
21
+ #
22
+ # You should have received a copy of the GNU Affero General Public License
23
+ # along with HexaPDF. If not, see <http://www.gnu.org/licenses/>.
24
+ #
25
+ # The interactive user interfaces in modified source and object code
26
+ # versions of HexaPDF must display Appropriate Legal Notices, as required
27
+ # under Section 5 of the GNU Affero General Public License version 3.
28
+ #
29
+ # In accordance with Section 7(b) of the GNU Affero General Public
30
+ # License, a covered work must retain the producer line in every PDF that
31
+ # is created or manipulated using HexaPDF.
32
+ #++
33
+
34
+ require 'hexapdf/dictionary'
35
+
36
+ module HexaPDF
37
+ module Type
38
+
39
+ # Represents the PDF's viewer preferences dictionary which defines how a document should be
40
+ # presented on screen or in print.
41
+ #
42
+ # This dictionary is linked via the /ViewerPreferences entry from the Type::Catalog.
43
+ #
44
+ # See: PDF1.7 s12.2, Catalog
45
+ class ViewerPreferences < Dictionary
46
+
47
+ define_field :HideToolbar, type: Boolean, default: false
48
+ define_field :HideMenubar, type: Boolean, default: false
49
+ define_field :HideWindowUI, type: Boolean, default: false
50
+ define_field :FitWindow, type: Boolean, default: false
51
+ define_field :CenterWindow, type: Boolean, default: false
52
+ define_field :DisplayDocTitle, type: Boolean, default: false, version: '1.4'
53
+ define_field :NonFullScreenPageMode, type: Symbol, default: :UseNone
54
+ define_field :Direction, type: Symbol, default: :L2R, version: '1.3'
55
+ define_field :ViewArea, type: Symbol, default: :CropBox, version: '1.4'
56
+ define_field :ViewClip, type: Symbol, default: :CropBox, version: '1.4'
57
+ define_field :PrintArea, type: Symbol, default: :CropBox, version: '1.4'
58
+ define_field :PrintClip, type: Symbol, default: :CropBox, version: '1.4'
59
+ define_field :PrintScaling, type: Symbol, default: :AppDefault, version: '1.6'
60
+ define_field :Duplex, type: Symbol, version: '1.7'
61
+ define_field :PickTrayByPDFSize, type: Boolean, version: '1.7'
62
+ define_field :PrintPageRange, type: Array, version: '1.7'
63
+ define_field :NumCopies, type: Integer, version: '1.7'
64
+
65
+ # Returns +:XXViewerPreferences+.
66
+ def type
67
+ :XXViewerPreferences
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+ end