hexapdf 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTERS +3 -0
- data/LICENSE +26 -0
- data/README.md +88 -0
- data/Rakefile +121 -0
- data/VERSION +1 -0
- data/agpl-3.0.txt +661 -0
- data/bin/hexapdf +6 -0
- data/data/hexapdf/afm/Courier-Bold.afm +342 -0
- data/data/hexapdf/afm/Courier-BoldOblique.afm +342 -0
- data/data/hexapdf/afm/Courier-Oblique.afm +342 -0
- data/data/hexapdf/afm/Courier.afm +342 -0
- data/data/hexapdf/afm/Helvetica-Bold.afm +2827 -0
- data/data/hexapdf/afm/Helvetica-BoldOblique.afm +2827 -0
- data/data/hexapdf/afm/Helvetica-Oblique.afm +3051 -0
- data/data/hexapdf/afm/Helvetica.afm +3051 -0
- data/data/hexapdf/afm/MustRead.html +1 -0
- data/data/hexapdf/afm/Symbol.afm +213 -0
- data/data/hexapdf/afm/Times-Bold.afm +2588 -0
- data/data/hexapdf/afm/Times-BoldItalic.afm +2384 -0
- data/data/hexapdf/afm/Times-Italic.afm +2667 -0
- data/data/hexapdf/afm/Times-Roman.afm +2419 -0
- data/data/hexapdf/afm/ZapfDingbats.afm +225 -0
- data/data/hexapdf/encoding/glyphlist.txt +4305 -0
- data/data/hexapdf/encoding/zapfdingbats.txt +225 -0
- data/examples/arc.rb +50 -0
- data/examples/graphics.rb +274 -0
- data/examples/hello_world.rb +16 -0
- data/examples/machupicchu.jpg +0 -0
- data/examples/merging.rb +24 -0
- data/examples/optimizing.rb +20 -0
- data/examples/show_char_bboxes.rb +55 -0
- data/examples/standard_pdf_fonts.rb +72 -0
- data/examples/truetype.rb +45 -0
- data/lib/hexapdf/cli/extract.rb +128 -0
- data/lib/hexapdf/cli/info.rb +121 -0
- data/lib/hexapdf/cli/inspect.rb +157 -0
- data/lib/hexapdf/cli/modify.rb +218 -0
- data/lib/hexapdf/cli.rb +121 -0
- data/lib/hexapdf/configuration.rb +392 -0
- data/lib/hexapdf/content/canvas.rb +1974 -0
- data/lib/hexapdf/content/color_space.rb +364 -0
- data/lib/hexapdf/content/graphic_object/arc.rb +267 -0
- data/lib/hexapdf/content/graphic_object/endpoint_arc.rb +208 -0
- data/lib/hexapdf/content/graphic_object/solid_arc.rb +173 -0
- data/lib/hexapdf/content/graphic_object.rb +81 -0
- data/lib/hexapdf/content/graphics_state.rb +579 -0
- data/lib/hexapdf/content/operator.rb +1072 -0
- data/lib/hexapdf/content/parser.rb +204 -0
- data/lib/hexapdf/content/processor.rb +451 -0
- data/lib/hexapdf/content/transformation_matrix.rb +172 -0
- data/lib/hexapdf/content.rb +47 -0
- data/lib/hexapdf/data_dir.rb +51 -0
- data/lib/hexapdf/dictionary.rb +303 -0
- data/lib/hexapdf/dictionary_fields.rb +382 -0
- data/lib/hexapdf/document.rb +589 -0
- data/lib/hexapdf/document_utils.rb +209 -0
- data/lib/hexapdf/encryption/aes.rb +206 -0
- data/lib/hexapdf/encryption/arc4.rb +93 -0
- data/lib/hexapdf/encryption/fast_aes.rb +79 -0
- data/lib/hexapdf/encryption/fast_arc4.rb +67 -0
- data/lib/hexapdf/encryption/identity.rb +63 -0
- data/lib/hexapdf/encryption/ruby_aes.rb +447 -0
- data/lib/hexapdf/encryption/ruby_arc4.rb +96 -0
- data/lib/hexapdf/encryption/security_handler.rb +494 -0
- data/lib/hexapdf/encryption/standard_security_handler.rb +616 -0
- data/lib/hexapdf/encryption.rb +94 -0
- data/lib/hexapdf/error.rb +73 -0
- data/lib/hexapdf/filter/ascii85_decode.rb +160 -0
- data/lib/hexapdf/filter/ascii_hex_decode.rb +87 -0
- data/lib/hexapdf/filter/dct_decode.rb +57 -0
- data/lib/hexapdf/filter/encryption.rb +59 -0
- data/lib/hexapdf/filter/flate_decode.rb +93 -0
- data/lib/hexapdf/filter/jpx_decode.rb +56 -0
- data/lib/hexapdf/filter/lzw_decode.rb +191 -0
- data/lib/hexapdf/filter/predictor.rb +266 -0
- data/lib/hexapdf/filter/run_length_decode.rb +108 -0
- data/lib/hexapdf/filter.rb +176 -0
- data/lib/hexapdf/font/cmap/parser.rb +146 -0
- data/lib/hexapdf/font/cmap/writer.rb +176 -0
- data/lib/hexapdf/font/cmap.rb +90 -0
- data/lib/hexapdf/font/encoding/base.rb +77 -0
- data/lib/hexapdf/font/encoding/difference_encoding.rb +64 -0
- data/lib/hexapdf/font/encoding/glyph_list.rb +150 -0
- data/lib/hexapdf/font/encoding/mac_expert_encoding.rb +221 -0
- data/lib/hexapdf/font/encoding/mac_roman_encoding.rb +265 -0
- data/lib/hexapdf/font/encoding/standard_encoding.rb +205 -0
- data/lib/hexapdf/font/encoding/symbol_encoding.rb +244 -0
- data/lib/hexapdf/font/encoding/win_ansi_encoding.rb +280 -0
- data/lib/hexapdf/font/encoding/zapf_dingbats_encoding.rb +250 -0
- data/lib/hexapdf/font/encoding.rb +68 -0
- data/lib/hexapdf/font/true_type/font.rb +179 -0
- data/lib/hexapdf/font/true_type/table/cmap.rb +103 -0
- data/lib/hexapdf/font/true_type/table/cmap_subtable.rb +384 -0
- data/lib/hexapdf/font/true_type/table/directory.rb +92 -0
- data/lib/hexapdf/font/true_type/table/glyf.rb +166 -0
- data/lib/hexapdf/font/true_type/table/head.rb +143 -0
- data/lib/hexapdf/font/true_type/table/hhea.rb +109 -0
- data/lib/hexapdf/font/true_type/table/hmtx.rb +79 -0
- data/lib/hexapdf/font/true_type/table/loca.rb +79 -0
- data/lib/hexapdf/font/true_type/table/maxp.rb +112 -0
- data/lib/hexapdf/font/true_type/table/name.rb +218 -0
- data/lib/hexapdf/font/true_type/table/os2.rb +200 -0
- data/lib/hexapdf/font/true_type/table/post.rb +230 -0
- data/lib/hexapdf/font/true_type/table.rb +155 -0
- data/lib/hexapdf/font/true_type.rb +48 -0
- data/lib/hexapdf/font/true_type_wrapper.rb +240 -0
- data/lib/hexapdf/font/type1/afm_parser.rb +230 -0
- data/lib/hexapdf/font/type1/character_metrics.rb +67 -0
- data/lib/hexapdf/font/type1/font.rb +123 -0
- data/lib/hexapdf/font/type1/font_metrics.rb +117 -0
- data/lib/hexapdf/font/type1/pfb_parser.rb +71 -0
- data/lib/hexapdf/font/type1.rb +52 -0
- data/lib/hexapdf/font/type1_wrapper.rb +193 -0
- data/lib/hexapdf/font_loader/from_configuration.rb +70 -0
- data/lib/hexapdf/font_loader/standard14.rb +98 -0
- data/lib/hexapdf/font_loader.rb +85 -0
- data/lib/hexapdf/font_utils.rb +89 -0
- data/lib/hexapdf/image_loader/jpeg.rb +166 -0
- data/lib/hexapdf/image_loader/pdf.rb +89 -0
- data/lib/hexapdf/image_loader/png.rb +410 -0
- data/lib/hexapdf/image_loader.rb +68 -0
- data/lib/hexapdf/importer.rb +139 -0
- data/lib/hexapdf/name_tree_node.rb +78 -0
- data/lib/hexapdf/number_tree_node.rb +67 -0
- data/lib/hexapdf/object.rb +363 -0
- data/lib/hexapdf/parser.rb +349 -0
- data/lib/hexapdf/rectangle.rb +99 -0
- data/lib/hexapdf/reference.rb +98 -0
- data/lib/hexapdf/revision.rb +206 -0
- data/lib/hexapdf/revisions.rb +194 -0
- data/lib/hexapdf/serializer.rb +326 -0
- data/lib/hexapdf/stream.rb +279 -0
- data/lib/hexapdf/task/dereference.rb +109 -0
- data/lib/hexapdf/task/optimize.rb +230 -0
- data/lib/hexapdf/task.rb +68 -0
- data/lib/hexapdf/tokenizer.rb +406 -0
- data/lib/hexapdf/type/catalog.rb +107 -0
- data/lib/hexapdf/type/embedded_file.rb +87 -0
- data/lib/hexapdf/type/file_specification.rb +232 -0
- data/lib/hexapdf/type/font.rb +81 -0
- data/lib/hexapdf/type/font_descriptor.rb +109 -0
- data/lib/hexapdf/type/font_simple.rb +190 -0
- data/lib/hexapdf/type/font_true_type.rb +47 -0
- data/lib/hexapdf/type/font_type1.rb +162 -0
- data/lib/hexapdf/type/form.rb +103 -0
- data/lib/hexapdf/type/graphics_state_parameter.rb +79 -0
- data/lib/hexapdf/type/image.rb +73 -0
- data/lib/hexapdf/type/info.rb +70 -0
- data/lib/hexapdf/type/names.rb +69 -0
- data/lib/hexapdf/type/object_stream.rb +224 -0
- data/lib/hexapdf/type/page.rb +355 -0
- data/lib/hexapdf/type/page_tree_node.rb +269 -0
- data/lib/hexapdf/type/resources.rb +212 -0
- data/lib/hexapdf/type/trailer.rb +128 -0
- data/lib/hexapdf/type/viewer_preferences.rb +73 -0
- data/lib/hexapdf/type/xref_stream.rb +204 -0
- data/lib/hexapdf/type.rb +67 -0
- data/lib/hexapdf/utils/bit_field.rb +87 -0
- data/lib/hexapdf/utils/bit_stream.rb +148 -0
- data/lib/hexapdf/utils/lru_cache.rb +65 -0
- data/lib/hexapdf/utils/math_helpers.rb +55 -0
- data/lib/hexapdf/utils/object_hash.rb +130 -0
- data/lib/hexapdf/utils/pdf_doc_encoding.rb +93 -0
- data/lib/hexapdf/utils/sorted_tree_node.rb +339 -0
- data/lib/hexapdf/version.rb +39 -0
- data/lib/hexapdf/writer.rb +199 -0
- data/lib/hexapdf/xref_section.rb +152 -0
- data/lib/hexapdf.rb +34 -0
- data/man/man1/hexapdf.1 +249 -0
- data/test/data/aes-test-vectors/CBCGFSbox-128-decrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCGFSbox-128-encrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCGFSbox-192-decrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCGFSbox-192-encrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCGFSbox-256-decrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCGFSbox-256-encrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCKeySbox-128-decrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCKeySbox-128-encrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCKeySbox-192-decrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCKeySbox-192-encrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCKeySbox-256-decrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCKeySbox-256-encrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCVarKey-128-decrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCVarKey-128-encrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCVarKey-192-decrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCVarKey-192-encrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCVarKey-256-decrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCVarKey-256-encrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCVarTxt-128-decrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCVarTxt-128-encrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCVarTxt-192-decrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCVarTxt-192-encrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCVarTxt-256-decrypt.data.gz +0 -0
- data/test/data/aes-test-vectors/CBCVarTxt-256-encrypt.data.gz +0 -0
- data/test/data/fonts/Ubuntu-Title.ttf +0 -0
- data/test/data/images/cmyk.jpg +0 -0
- data/test/data/images/fillbytes.jpg +0 -0
- data/test/data/images/gray.jpg +0 -0
- data/test/data/images/greyscale-1bit.png +0 -0
- data/test/data/images/greyscale-2bit.png +0 -0
- data/test/data/images/greyscale-4bit.png +0 -0
- data/test/data/images/greyscale-8bit.png +0 -0
- data/test/data/images/greyscale-alpha-8bit.png +0 -0
- data/test/data/images/greyscale-trns-8bit.png +0 -0
- data/test/data/images/greyscale-with-gamma1.0.png +0 -0
- data/test/data/images/greyscale-with-gamma1.5.png +0 -0
- data/test/data/images/indexed-1bit.png +0 -0
- data/test/data/images/indexed-2bit.png +0 -0
- data/test/data/images/indexed-4bit.png +0 -0
- data/test/data/images/indexed-8bit.png +0 -0
- data/test/data/images/indexed-alpha-4bit.png +0 -0
- data/test/data/images/indexed-alpha-8bit.png +0 -0
- data/test/data/images/rgb.jpg +0 -0
- data/test/data/images/truecolour-8bit.png +0 -0
- data/test/data/images/truecolour-alpha-8bit.png +0 -0
- data/test/data/images/truecolour-gama-chrm-8bit.png +0 -0
- data/test/data/images/truecolour-srgb-8bit.png +0 -0
- data/test/data/minimal.pdf +44 -0
- data/test/data/standard-security-handler/README +9 -0
- data/test/data/standard-security-handler/bothpwd-aes-128bit-V4.pdf +44 -0
- data/test/data/standard-security-handler/bothpwd-aes-256bit-V5.pdf +0 -0
- data/test/data/standard-security-handler/bothpwd-arc4-128bit-V2.pdf +43 -0
- data/test/data/standard-security-handler/bothpwd-arc4-128bit-V4.pdf +43 -0
- data/test/data/standard-security-handler/bothpwd-arc4-40bit-V1.pdf +0 -0
- data/test/data/standard-security-handler/nopwd-aes-128bit-V4.pdf +43 -0
- data/test/data/standard-security-handler/nopwd-aes-256bit-V5.pdf +0 -0
- data/test/data/standard-security-handler/nopwd-arc4-128bit-V2.pdf +43 -0
- data/test/data/standard-security-handler/nopwd-arc4-128bit-V4.pdf +43 -0
- data/test/data/standard-security-handler/nopwd-arc4-40bit-V1.pdf +43 -0
- data/test/data/standard-security-handler/ownerpwd-aes-128bit-V4.pdf +0 -0
- data/test/data/standard-security-handler/ownerpwd-aes-256bit-V5.pdf +43 -0
- data/test/data/standard-security-handler/ownerpwd-arc4-128bit-V2.pdf +43 -0
- data/test/data/standard-security-handler/ownerpwd-arc4-128bit-V4.pdf +43 -0
- data/test/data/standard-security-handler/ownerpwd-arc4-40bit-V1.pdf +43 -0
- data/test/data/standard-security-handler/userpwd-aes-128bit-V4.pdf +43 -0
- data/test/data/standard-security-handler/userpwd-aes-256bit-V5.pdf +43 -0
- data/test/data/standard-security-handler/userpwd-arc4-128bit-V2.pdf +0 -0
- data/test/data/standard-security-handler/userpwd-arc4-128bit-V4.pdf +0 -0
- data/test/data/standard-security-handler/userpwd-arc4-40bit-V1.pdf +43 -0
- data/test/hexapdf/common_tokenizer_tests.rb +204 -0
- data/test/hexapdf/content/common.rb +31 -0
- data/test/hexapdf/content/graphic_object/test_arc.rb +93 -0
- data/test/hexapdf/content/graphic_object/test_endpoint_arc.rb +91 -0
- data/test/hexapdf/content/graphic_object/test_solid_arc.rb +86 -0
- data/test/hexapdf/content/test_canvas.rb +1113 -0
- data/test/hexapdf/content/test_color_space.rb +97 -0
- data/test/hexapdf/content/test_graphics_state.rb +138 -0
- data/test/hexapdf/content/test_operator.rb +619 -0
- data/test/hexapdf/content/test_parser.rb +66 -0
- data/test/hexapdf/content/test_processor.rb +156 -0
- data/test/hexapdf/content/test_transformation_matrix.rb +64 -0
- data/test/hexapdf/encryption/common.rb +87 -0
- data/test/hexapdf/encryption/test_aes.rb +121 -0
- data/test/hexapdf/encryption/test_arc4.rb +39 -0
- data/test/hexapdf/encryption/test_fast_aes.rb +17 -0
- data/test/hexapdf/encryption/test_fast_arc4.rb +12 -0
- data/test/hexapdf/encryption/test_identity.rb +21 -0
- data/test/hexapdf/encryption/test_ruby_aes.rb +23 -0
- data/test/hexapdf/encryption/test_ruby_arc4.rb +20 -0
- data/test/hexapdf/encryption/test_security_handler.rb +356 -0
- data/test/hexapdf/encryption/test_standard_security_handler.rb +274 -0
- data/test/hexapdf/filter/common.rb +53 -0
- data/test/hexapdf/filter/test_ascii85_decode.rb +60 -0
- data/test/hexapdf/filter/test_ascii_hex_decode.rb +33 -0
- data/test/hexapdf/filter/test_encryption.rb +24 -0
- data/test/hexapdf/filter/test_flate_decode.rb +35 -0
- data/test/hexapdf/filter/test_lzw_decode.rb +52 -0
- data/test/hexapdf/filter/test_predictor.rb +183 -0
- data/test/hexapdf/filter/test_run_length_decode.rb +32 -0
- data/test/hexapdf/font/cmap/test_parser.rb +67 -0
- data/test/hexapdf/font/cmap/test_writer.rb +58 -0
- data/test/hexapdf/font/encoding/test_base.rb +35 -0
- data/test/hexapdf/font/encoding/test_difference_encoding.rb +21 -0
- data/test/hexapdf/font/encoding/test_glyph_list.rb +59 -0
- data/test/hexapdf/font/encoding/test_zapf_dingbats_encoding.rb +16 -0
- data/test/hexapdf/font/test_encoding.rb +27 -0
- data/test/hexapdf/font/test_true_type_wrapper.rb +110 -0
- data/test/hexapdf/font/test_type1_wrapper.rb +66 -0
- data/test/hexapdf/font/true_type/common.rb +19 -0
- data/test/hexapdf/font/true_type/table/test_cmap.rb +59 -0
- data/test/hexapdf/font/true_type/table/test_cmap_subtable.rb +133 -0
- data/test/hexapdf/font/true_type/table/test_directory.rb +35 -0
- data/test/hexapdf/font/true_type/table/test_glyf.rb +58 -0
- data/test/hexapdf/font/true_type/table/test_head.rb +76 -0
- data/test/hexapdf/font/true_type/table/test_hhea.rb +40 -0
- data/test/hexapdf/font/true_type/table/test_hmtx.rb +38 -0
- data/test/hexapdf/font/true_type/table/test_loca.rb +43 -0
- data/test/hexapdf/font/true_type/table/test_maxp.rb +62 -0
- data/test/hexapdf/font/true_type/table/test_name.rb +95 -0
- data/test/hexapdf/font/true_type/table/test_os2.rb +65 -0
- data/test/hexapdf/font/true_type/table/test_post.rb +89 -0
- data/test/hexapdf/font/true_type/test_font.rb +120 -0
- data/test/hexapdf/font/true_type/test_table.rb +41 -0
- data/test/hexapdf/font/type1/test_afm_parser.rb +51 -0
- data/test/hexapdf/font/type1/test_font.rb +68 -0
- data/test/hexapdf/font/type1/test_pfb_parser.rb +37 -0
- data/test/hexapdf/font_loader/test_from_configuration.rb +28 -0
- data/test/hexapdf/font_loader/test_standard14.rb +22 -0
- data/test/hexapdf/image_loader/test_jpeg.rb +83 -0
- data/test/hexapdf/image_loader/test_pdf.rb +47 -0
- data/test/hexapdf/image_loader/test_png.rb +258 -0
- data/test/hexapdf/task/test_dereference.rb +46 -0
- data/test/hexapdf/task/test_optimize.rb +137 -0
- data/test/hexapdf/test_configuration.rb +82 -0
- data/test/hexapdf/test_data_dir.rb +32 -0
- data/test/hexapdf/test_dictionary.rb +284 -0
- data/test/hexapdf/test_dictionary_fields.rb +185 -0
- data/test/hexapdf/test_document.rb +574 -0
- data/test/hexapdf/test_document_utils.rb +144 -0
- data/test/hexapdf/test_filter.rb +96 -0
- data/test/hexapdf/test_font_utils.rb +47 -0
- data/test/hexapdf/test_importer.rb +78 -0
- data/test/hexapdf/test_object.rb +177 -0
- data/test/hexapdf/test_parser.rb +394 -0
- data/test/hexapdf/test_rectangle.rb +36 -0
- data/test/hexapdf/test_reference.rb +41 -0
- data/test/hexapdf/test_revision.rb +139 -0
- data/test/hexapdf/test_revisions.rb +93 -0
- data/test/hexapdf/test_serializer.rb +169 -0
- data/test/hexapdf/test_stream.rb +262 -0
- data/test/hexapdf/test_tokenizer.rb +30 -0
- data/test/hexapdf/test_writer.rb +120 -0
- data/test/hexapdf/test_xref_section.rb +35 -0
- data/test/hexapdf/type/test_catalog.rb +30 -0
- data/test/hexapdf/type/test_embedded_file.rb +16 -0
- data/test/hexapdf/type/test_file_specification.rb +148 -0
- data/test/hexapdf/type/test_font.rb +35 -0
- data/test/hexapdf/type/test_font_descriptor.rb +51 -0
- data/test/hexapdf/type/test_font_simple.rb +190 -0
- data/test/hexapdf/type/test_font_type1.rb +128 -0
- data/test/hexapdf/type/test_form.rb +60 -0
- data/test/hexapdf/type/test_info.rb +14 -0
- data/test/hexapdf/type/test_names.rb +9 -0
- data/test/hexapdf/type/test_object_stream.rb +84 -0
- data/test/hexapdf/type/test_page.rb +260 -0
- data/test/hexapdf/type/test_page_tree_node.rb +255 -0
- data/test/hexapdf/type/test_resources.rb +167 -0
- data/test/hexapdf/type/test_trailer.rb +109 -0
- data/test/hexapdf/type/test_xref_stream.rb +131 -0
- data/test/hexapdf/utils/test_bit_field.rb +47 -0
- data/test/hexapdf/utils/test_lru_cache.rb +22 -0
- data/test/hexapdf/utils/test_object_hash.rb +115 -0
- data/test/hexapdf/utils/test_pdf_doc_encoding.rb +18 -0
- data/test/hexapdf/utils/test_sorted_tree_node.rb +232 -0
- data/test/test_helper.rb +56 -0
- metadata +427 -0
@@ -0,0 +1,232 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'hexapdf/document'
|
5
|
+
require 'hexapdf/name_tree_node'
|
6
|
+
require 'hexapdf/number_tree_node'
|
7
|
+
|
8
|
+
describe HexaPDF::Utils::SortedTreeNode do
|
9
|
+
before do
|
10
|
+
@doc = HexaPDF::Document.new
|
11
|
+
@root = @doc.add({}, type: HexaPDF::NameTreeNode)
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_multilevel_entries
|
15
|
+
@kid11 = @doc.add({Limits: ['c', 'f'], Names: ['c', 1, 'f', 1]}, type: HexaPDF::NameTreeNode)
|
16
|
+
@kid12 = @doc.add(Limits: ['i', 'm'], Names: ['i', 1, 'm', 1])
|
17
|
+
ref = HexaPDF::Reference.new(@kid11.oid, @kid11.gen)
|
18
|
+
@kid1 = @doc.add(Limits: ['c', 'm'], Kids: [ref, @kid12])
|
19
|
+
@kid21 = @doc.add({Limits: ['o', 'q'], Names: ['o', 1, 'q', 1]}, type: HexaPDF::NameTreeNode)
|
20
|
+
@kid221 = @doc.add({Limits: ['s', 'u'], Names: ['s', 1, 'u', 1]}, type: HexaPDF::NameTreeNode)
|
21
|
+
@kid22 = @doc.add({Limits: ['s', 'u'], Kids: [@kid221]}, type: HexaPDF::NameTreeNode)
|
22
|
+
@kid2 = @doc.add({Limits: ['o', 'u'], Kids: [@kid21, @kid22]}, type: HexaPDF::NameTreeNode)
|
23
|
+
@root[:Kids] = [@kid1, @kid2]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "must always be indirect" do
|
27
|
+
assert(@root.must_be_indirect?)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "add" do
|
31
|
+
it "works with the root node alone" do
|
32
|
+
@root.add_entry('c', 1)
|
33
|
+
@root.add_entry('a', 2)
|
34
|
+
@root.add_entry('e', 3)
|
35
|
+
assert_equal(['a', 2, 'c', 1, 'e', 3], @root[:Names])
|
36
|
+
refute(@root[:Limits])
|
37
|
+
end
|
38
|
+
|
39
|
+
it "replaces an existing entry if overwrite is true" do
|
40
|
+
assert(@root.add_entry('a', 2))
|
41
|
+
assert(@root.add_entry('a', 5))
|
42
|
+
assert_equal(['a', 5], @root[:Names])
|
43
|
+
end
|
44
|
+
|
45
|
+
it "doesn't replace an existing entry if overwrite is false" do
|
46
|
+
assert(@root.add_entry('a', 2))
|
47
|
+
refute(@root.add_entry('a', 5, overwrite: false))
|
48
|
+
assert_equal(['a', 2], @root[:Names])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "works with one level of intermediate nodes" do
|
52
|
+
kid1 = HexaPDF::NameTreeNode.new({Limits: ['m', 'm'], Names: ['m', 1]}, document: @doc)
|
53
|
+
kid2 = HexaPDF::NameTreeNode.new({Limits: ['t', 't'], Names: ['t', 1]}, document: @doc)
|
54
|
+
@root[:Kids] = [kid1, kid2]
|
55
|
+
@root.add_entry('c', 1)
|
56
|
+
@root.add_entry('d', 1)
|
57
|
+
@root.add_entry('p', 1)
|
58
|
+
@root.add_entry('r', 1)
|
59
|
+
@root.add_entry('u', 1)
|
60
|
+
assert_equal(['c', 'm'], kid1[:Limits])
|
61
|
+
assert_equal(['c', 1, 'd', 1, 'm', 1], kid1[:Names])
|
62
|
+
assert_equal(['p', 'u'], kid2[:Limits])
|
63
|
+
assert_equal(['p', 1, 'r', 1, 't', 1, 'u', 1], kid2[:Names])
|
64
|
+
end
|
65
|
+
|
66
|
+
it "works with multiple levels of intermediate nodes" do
|
67
|
+
add_multilevel_entries
|
68
|
+
@root.add_entry('a', 1)
|
69
|
+
@root.add_entry('e', 1)
|
70
|
+
@root.add_entry('g', 1)
|
71
|
+
@root.add_entry('j', 1)
|
72
|
+
@root.add_entry('n', 1)
|
73
|
+
@root.add_entry('p', 1)
|
74
|
+
@root.add_entry('r', 1)
|
75
|
+
@root.add_entry('v', 1)
|
76
|
+
assert_equal(['a', 'm'], @kid1[:Limits])
|
77
|
+
assert_equal(['a', 'f'], @kid11[:Limits])
|
78
|
+
assert_equal(['a', 1, 'c', 1, 'e', 1, 'f', 1], @kid11[:Names])
|
79
|
+
assert_equal(['g', 'm'], @kid12[:Limits])
|
80
|
+
assert_equal(['g', 1, 'i', 1, 'j', 1, 'm', 1], @kid12[:Names])
|
81
|
+
assert_equal(['n', 'v'], @kid2[:Limits])
|
82
|
+
assert_equal(['n', 'q'], @kid21[:Limits])
|
83
|
+
assert_equal(['n', 1, 'o', 1, 'p', 1, 'q', 1], @kid21[:Names])
|
84
|
+
assert_equal(['r', 'v'], @kid22[:Limits])
|
85
|
+
assert_equal(['r', 'v'], @kid221[:Limits])
|
86
|
+
assert_equal(['r', 1, 's', 1, 'u', 1, 'v', 1], @kid221[:Names])
|
87
|
+
end
|
88
|
+
|
89
|
+
it "splits nodes if needed" do
|
90
|
+
@doc.config['sorted_tree.max_leaf_node_size'] = 4
|
91
|
+
%w[a c e m k i g d b l j f h].each {|key| @root.add_entry(key, 1)}
|
92
|
+
refute(@root.value.key?(:Limits))
|
93
|
+
refute(@root.value.key?(:Names))
|
94
|
+
assert_equal(6, @root[:Kids].size)
|
95
|
+
assert_equal(['a', 1, 'b', 1], @root[:Kids][0][:Names])
|
96
|
+
assert_equal(['c', 1, 'd', 1], @root[:Kids][1][:Names])
|
97
|
+
assert_equal(['e', 1, 'f', 1], @root[:Kids][2][:Names])
|
98
|
+
assert_equal(['g', 1, 'h', 1, 'i', 1], @root[:Kids][3][:Names])
|
99
|
+
assert_equal(['j', 1, 'k', 1], @root[:Kids][4][:Names])
|
100
|
+
assert_equal(['l', 1, 'm', 1], @root[:Kids][5][:Names])
|
101
|
+
end
|
102
|
+
|
103
|
+
it "fails if not called on the root node" do
|
104
|
+
@root[:Limits] = ['a', 'c']
|
105
|
+
assert_raises(HexaPDF::Error) { @root.add_entry('b', 1) }
|
106
|
+
end
|
107
|
+
|
108
|
+
it "fails if the key is not a string" do
|
109
|
+
assert_raises(ArgumentError) { @root.add_entry(5, 1) }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "find" do
|
114
|
+
it "finds the correct entry" do
|
115
|
+
add_multilevel_entries
|
116
|
+
assert_equal(1, @root.find_entry('i'))
|
117
|
+
assert_equal(1, @root.find_entry('q'))
|
118
|
+
end
|
119
|
+
|
120
|
+
it "automatically dereferences the entry's value" do
|
121
|
+
add_multilevel_entries
|
122
|
+
obj = @doc.add(1)
|
123
|
+
@kid11[:Names][1] = HexaPDF::Reference.new(obj.oid, obj.gen)
|
124
|
+
assert_equal(obj, @root.find_entry('c'))
|
125
|
+
end
|
126
|
+
|
127
|
+
it "returns nil for non-existing entries" do
|
128
|
+
add_multilevel_entries
|
129
|
+
assert_nil(@root.find_entry('non'))
|
130
|
+
end
|
131
|
+
|
132
|
+
it "works when no entry exists" do
|
133
|
+
assert_nil(@root.find_entry('non'))
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "delete" do
|
138
|
+
it "works with only the root node" do
|
139
|
+
%w[a b c d e f g].each {|name| @root.add_entry(name, 1)}
|
140
|
+
%w[g b a unknown e d c].each {|name| @root.delete_entry(name)}
|
141
|
+
refute(@root.value.key?(:Kids))
|
142
|
+
refute(@root.value.key?(:Limits))
|
143
|
+
assert_equal(['f', 1], @root[:Names])
|
144
|
+
assert_equal(1, @root.delete_entry('f'))
|
145
|
+
end
|
146
|
+
|
147
|
+
it "works with multiple levels of intermediate nodes" do
|
148
|
+
add_multilevel_entries
|
149
|
+
%w[c f i m unknown o q s u].each {|name| @root.delete_entry(name)}
|
150
|
+
refute(@root.value.key?(:Names))
|
151
|
+
refute(@root.value.key?(:Limits))
|
152
|
+
assert(@root[:Kids].empty?)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "works on an uninitalized tree" do
|
156
|
+
assert_nil(@root.delete_entry('non'))
|
157
|
+
end
|
158
|
+
|
159
|
+
it "fails if not called on the root node" do
|
160
|
+
@root[:Limits] = ['a', 'c']
|
161
|
+
assert_raises(HexaPDF::Error) { @root.delete_entry('b') }
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "each" do
|
166
|
+
it "enumerates in the key-value pairs in sorted order" do
|
167
|
+
add_multilevel_entries
|
168
|
+
assert_equal(['c', 1, 'f', 1, 'i', 1, 'm', 1, 'o', 1, 'q', 1, 's', 1, 'u', 1],
|
169
|
+
@root.each_entry.to_a.flatten)
|
170
|
+
end
|
171
|
+
|
172
|
+
it "automatically dereferences the yielded values" do
|
173
|
+
add_multilevel_entries
|
174
|
+
obj = @doc.add(1)
|
175
|
+
@kid11[:Names][1] = HexaPDF::Reference.new(obj.oid, obj.gen)
|
176
|
+
assert_equal(['c', obj, 'f', 1], @kid11.each_entry.to_a.flatten)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "works on an uninitalized tree" do
|
180
|
+
assert_equal([], @root.each_entry.to_a)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "perform_validation" do
|
185
|
+
before do
|
186
|
+
add_multilevel_entries
|
187
|
+
end
|
188
|
+
|
189
|
+
it "checks that all kid objects are indirect objects" do
|
190
|
+
@root[:Kids][0] = HexaPDF::Reference.new(@kid1.oid, @kid1.gen)
|
191
|
+
assert(@root.validate)
|
192
|
+
|
193
|
+
@root[:Kids][0] = @kid1
|
194
|
+
@kid1.oid = 0
|
195
|
+
refute(@root.validate do |message, c|
|
196
|
+
assert_match(/must be indirect objects/, message)
|
197
|
+
refute(c)
|
198
|
+
end)
|
199
|
+
end
|
200
|
+
|
201
|
+
it "checks that leaf node containers have an even number of entries" do
|
202
|
+
@kid11[:Names].delete_at(0)
|
203
|
+
refute(@kid11.validate do |message, c|
|
204
|
+
assert_match(/odd number/, message)
|
205
|
+
refute(c)
|
206
|
+
end)
|
207
|
+
end
|
208
|
+
|
209
|
+
it "checks that the keys are of the correct type" do
|
210
|
+
@kid11[:Names][2] = 5
|
211
|
+
refute(@kid11.validate do |message, c|
|
212
|
+
assert_match(/must be a String object/, message)
|
213
|
+
refute(c)
|
214
|
+
end)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "checks that the keys are correctly sorted" do
|
218
|
+
@kid11[:Names][2] = 'a'
|
219
|
+
refute(@kid11.validate do |message, c|
|
220
|
+
assert_match(/not correctly sorted/, message)
|
221
|
+
refute(c)
|
222
|
+
end)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
it "works equally well with a NumberTreeNode" do
|
227
|
+
root = HexaPDF::NumberTreeNode.new({}, document: @doc)
|
228
|
+
root.add_entry(2, 1)
|
229
|
+
root.add_entry(1, 2)
|
230
|
+
assert_equal([1, 2, 2, 1], root[:Nums])
|
231
|
+
end
|
232
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start do
|
5
|
+
add_filter '/test/'
|
6
|
+
end
|
7
|
+
|
8
|
+
gem 'minitest'
|
9
|
+
require 'minitest/autorun'
|
10
|
+
require 'fiber'
|
11
|
+
require 'zlib'
|
12
|
+
|
13
|
+
|
14
|
+
TEST_DATA_DIR = File.join(__dir__, 'data')
|
15
|
+
MINIMAL_PDF = File.read(File.join(TEST_DATA_DIR, 'minimal.pdf')).freeze
|
16
|
+
|
17
|
+
module TestHelper
|
18
|
+
|
19
|
+
# Asserts that the method +name+ of +object+ gets invoked with the +expected_values+ when
|
20
|
+
# executing the block. +expected_values+ should contain arrays of arguments, one array for each
|
21
|
+
# invocation of the method.
|
22
|
+
def assert_method_invoked(object, name, *expected_values, check_block: false)
|
23
|
+
args = []
|
24
|
+
block = []
|
25
|
+
object.define_singleton_method(name) {|*la, &lb| args << la; block << lb}
|
26
|
+
yield
|
27
|
+
assert_equal(expected_values, args, "Incorrect arguments for #{object.class}##{name}")
|
28
|
+
block.each do |block_arg|
|
29
|
+
assert_kind_of(Proc, block_arg, "Missing block for #{object.class}##{name}") if check_block
|
30
|
+
end
|
31
|
+
ensure
|
32
|
+
object.singleton_class.send(:remove_method, name)
|
33
|
+
end
|
34
|
+
|
35
|
+
module_function
|
36
|
+
|
37
|
+
def feeder(string, len = string.length)
|
38
|
+
Fiber.new do
|
39
|
+
while string.length > 0
|
40
|
+
Fiber.yield string.slice!(0, len).force_encoding('BINARY')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def collector(source)
|
46
|
+
str = ''.force_encoding('BINARY')
|
47
|
+
while source.alive? && (data = source.resume)
|
48
|
+
str << data
|
49
|
+
end
|
50
|
+
str
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Minitest::Spec
|
55
|
+
include TestHelper
|
56
|
+
end
|