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,96 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'hexapdf/filter'
|
5
|
+
require 'stringio'
|
6
|
+
require 'tempfile'
|
7
|
+
|
8
|
+
describe HexaPDF::Filter do
|
9
|
+
before do
|
10
|
+
@obj = HexaPDF::Filter
|
11
|
+
@str = ''
|
12
|
+
40.times { @str << [rand(2**32)].pack('N') }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "source_from_string" do
|
16
|
+
it "doesn't modify the given string" do
|
17
|
+
str = @str.dup
|
18
|
+
@obj.source_from_string(@str).resume.slice!(0, 10)
|
19
|
+
assert_equal(str, @str)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns the whole string" do
|
23
|
+
assert_equal(@str, collector(@obj.source_from_string(@str)))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "source_from_io" do
|
28
|
+
before do
|
29
|
+
@io = StringIO.new(@str.dup)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "converts an IO into a source via #source_from_io" do
|
33
|
+
assert_equal(@str, collector(@obj.source_from_io(@io)))
|
34
|
+
|
35
|
+
assert_equal(@str, collector(@obj.source_from_io(@io, pos: -10)))
|
36
|
+
assert_equal(@str[10..-1], collector(@obj.source_from_io(@io, pos: 10)))
|
37
|
+
assert_equal("", collector(@obj.source_from_io(@io, pos: 200)))
|
38
|
+
|
39
|
+
assert_equal("", collector(@obj.source_from_io(@io, length: 0)))
|
40
|
+
assert_equal(@str[0...100], collector(@obj.source_from_io(@io, length: 100)))
|
41
|
+
assert_equal(@str, collector(@obj.source_from_io(@io, length: -15)))
|
42
|
+
assert_equal(100, @obj.source_from_io(@io, length: 100).length)
|
43
|
+
|
44
|
+
assert_equal(@str, collector(@obj.source_from_io(@io, chunk_size: -15)))
|
45
|
+
assert_equal(@str, collector(@obj.source_from_io(@io, chunk_size: 0)))
|
46
|
+
assert_equal(@str, collector(@obj.source_from_io(@io, chunk_size: 100)))
|
47
|
+
assert_equal(@str, collector(@obj.source_from_io(@io, chunk_size: 200)))
|
48
|
+
|
49
|
+
assert_equal(@str[0...20], collector(@obj.source_from_io(@io, length: 20, chunk_size: 100)))
|
50
|
+
assert_equal(@str[20...40], collector(@obj.source_from_io(@io, pos: 20, length: 20, chunk_size: 100)))
|
51
|
+
assert_equal(@str[20...40], collector(@obj.source_from_io(@io, pos: 20, length: 20, chunk_size: 5)))
|
52
|
+
end
|
53
|
+
|
54
|
+
it "fails if not all requested bytes could be read" do
|
55
|
+
assert_raises(HexaPDF::FilterError) do
|
56
|
+
collector(@obj.source_from_io(@io, length: 200))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "source_from_file" do
|
62
|
+
before do
|
63
|
+
@file = Tempfile.new('hexapdf-filter')
|
64
|
+
@file.write(@str)
|
65
|
+
@file.close
|
66
|
+
end
|
67
|
+
|
68
|
+
after do
|
69
|
+
@file.unlink
|
70
|
+
end
|
71
|
+
|
72
|
+
it "converts the file into a source fiber" do
|
73
|
+
assert_equal(@str, collector(@obj.source_from_file(@file.path)))
|
74
|
+
assert_equal(@file.size, @obj.source_from_file(@file.path).length)
|
75
|
+
|
76
|
+
assert_equal(@str[100..-1], collector(@obj.source_from_file(@file.path, pos: 100)))
|
77
|
+
assert_equal(@str[100..-1].length, @obj.source_from_file(@file.path, pos: 100).length)
|
78
|
+
|
79
|
+
assert_equal(@str[50...100], collector(@obj.source_from_file(@file.path, pos: 50, length: 50)))
|
80
|
+
assert_equal(50, @obj.source_from_file(@file.path, length: 50).length)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "fails if more bytes are requested than stored in the file" do
|
84
|
+
assert_raises(HexaPDF::FilterError) do
|
85
|
+
collector(@obj.source_from_file(@file.path, length: 200))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it "collects the binary string from a source via #string_from_source" do
|
91
|
+
source = @obj.source_from_io(StringIO.new(@str), chunk_size: 50)
|
92
|
+
result = @obj.string_from_source(source)
|
93
|
+
assert_equal(@str, result)
|
94
|
+
assert_equal(Encoding::BINARY, result.encoding)
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'hexapdf/font_utils'
|
5
|
+
require 'hexapdf/document'
|
6
|
+
|
7
|
+
describe HexaPDF::FontUtils do
|
8
|
+
before do
|
9
|
+
@doc = HexaPDF::Document.new
|
10
|
+
@doc.config['font_loader'] = []
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "load" do
|
14
|
+
before do
|
15
|
+
@doc.config['font_loader'] << lambda do |doc, name, **options|
|
16
|
+
assert_equal(@doc, doc)
|
17
|
+
if name == :TestFont
|
18
|
+
x = Object.new
|
19
|
+
x.define_singleton_method(:name) do
|
20
|
+
options[:variant] == :bold ? :BoldFont : :NormalFont
|
21
|
+
end
|
22
|
+
x
|
23
|
+
else
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "loads the specified font" do
|
30
|
+
assert_equal(:NormalFont, @doc.fonts.load(:TestFont).name)
|
31
|
+
assert_equal(:BoldFont, @doc.fonts.load(:TestFont, variant: :bold).name)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "caches loaded fonts" do
|
35
|
+
assert_same(@doc.fonts.load(:TestFont), @doc.fonts.load(:TestFont))
|
36
|
+
end
|
37
|
+
|
38
|
+
it "fails if the requested font is not found" do
|
39
|
+
assert_raises(HexaPDF::Error) { @doc.fonts.load("Unknown") }
|
40
|
+
end
|
41
|
+
|
42
|
+
it "raises an error if a font loader cannot be correctly retrieved" do
|
43
|
+
@doc.config['font_loader'][0] = 'UnknownFontLoader'
|
44
|
+
assert_raises(HexaPDF::Error) { @doc.fonts.load(:Other) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'hexapdf/importer'
|
5
|
+
require 'hexapdf/document'
|
6
|
+
|
7
|
+
describe HexaPDF::Importer do
|
8
|
+
before do
|
9
|
+
@source = HexaPDF::Document.new
|
10
|
+
obj = @source.add("test")
|
11
|
+
@obj = @source.add(hash: {key: "value"}, array: ["one", "two"],
|
12
|
+
ref: HexaPDF::Reference.new(obj.oid, obj.gen),
|
13
|
+
others: [:symbol, 5, 5.5, nil, true, false])
|
14
|
+
@source.pages.add_page
|
15
|
+
@source.pages[:Rotate] = 90
|
16
|
+
@dest = HexaPDF::Document.new
|
17
|
+
@importer = HexaPDF::Importer.for(source: @source, destination: @dest)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "::for" do
|
21
|
+
it "caches the importer" do
|
22
|
+
assert_same(@importer, HexaPDF::Importer.for(source: @source, destination: @dest))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "import" do
|
27
|
+
it "imports an object only once" do
|
28
|
+
obj = @importer.import(@obj)
|
29
|
+
assert_same(obj, @importer.import(@obj))
|
30
|
+
assert_equal(2, @dest.each.to_a.size)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "re-imports an object that was imported but then deleted" do
|
34
|
+
obj = @importer.import(@obj)
|
35
|
+
@dest.delete(obj)
|
36
|
+
refute_same(obj, @importer.import(@obj))
|
37
|
+
end
|
38
|
+
|
39
|
+
it "can import a direct object" do
|
40
|
+
obj = @importer.import(key: @obj)
|
41
|
+
assert(@dest.object?(obj[:key]))
|
42
|
+
end
|
43
|
+
|
44
|
+
it "copies the data of the imported objects" do
|
45
|
+
data = {key: @obj, str: "str"}
|
46
|
+
obj = @importer.import(data)
|
47
|
+
obj[:str].upcase!
|
48
|
+
obj[:key][:hash][:key].upcase!
|
49
|
+
obj[:key][:hash][:data] = :value
|
50
|
+
obj[:key][:array].unshift
|
51
|
+
obj[:key][:array][0].upcase!
|
52
|
+
|
53
|
+
assert_equal("str", data[:str])
|
54
|
+
assert_equal("value", @obj[:hash][:key])
|
55
|
+
assert_equal(["one", "two"], @obj[:array])
|
56
|
+
end
|
57
|
+
|
58
|
+
it "does not import objects of type Catalog or Pages" do
|
59
|
+
@obj[:catalog] = @source.catalog
|
60
|
+
@obj[:pages] = @source.pages
|
61
|
+
obj = @importer.import(@obj)
|
62
|
+
|
63
|
+
assert_nil(obj[:catalog])
|
64
|
+
assert_nil(obj[:pages])
|
65
|
+
end
|
66
|
+
|
67
|
+
it "imports Page objects correctly by copying the inherited values" do
|
68
|
+
page = @importer.import(@source.pages.page(0))
|
69
|
+
assert_equal(90, page[:Rotate])
|
70
|
+
end
|
71
|
+
|
72
|
+
it "raise an error if the given object doesn't belong to the source document" do
|
73
|
+
other_doc = HexaPDF::Document.new
|
74
|
+
other_obj = other_doc.add("test")
|
75
|
+
assert_raises(HexaPDF::Error) { @importer.import(other_obj) }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'hexapdf/object'
|
5
|
+
require 'hexapdf/reference'
|
6
|
+
|
7
|
+
describe HexaPDF::Object do
|
8
|
+
describe "class.deep_copy" do
|
9
|
+
it "handles not-duplicatable classes" do
|
10
|
+
assert_equal(5, HexaPDF::Object.deep_copy(5))
|
11
|
+
assert_equal(5.5, HexaPDF::Object.deep_copy(5.5))
|
12
|
+
assert_equal(nil, HexaPDF::Object.deep_copy(nil))
|
13
|
+
assert_equal(true, HexaPDF::Object.deep_copy(true))
|
14
|
+
assert_equal(false, HexaPDF::Object.deep_copy(false))
|
15
|
+
assert_equal(:Name, HexaPDF::Object.deep_copy(:Name))
|
16
|
+
end
|
17
|
+
|
18
|
+
it "handles general, duplicatable classes" do
|
19
|
+
x = "test"
|
20
|
+
assert_equal("test", HexaPDF::Object.deep_copy(x))
|
21
|
+
refute_same(x, HexaPDF::Object.deep_copy(x))
|
22
|
+
end
|
23
|
+
|
24
|
+
it "handles arrays" do
|
25
|
+
x = [5, 6, [1, 2, 3]]
|
26
|
+
y = HexaPDF::Object.deep_copy(x)
|
27
|
+
x[2][0] = 4
|
28
|
+
assert_equal([5, 6, [1, 2, 3]], y)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "handles hashes" do
|
32
|
+
x = {a: 5, b: 6, c: {a: 1, b: 2}}
|
33
|
+
y = HexaPDF::Object.deep_copy(x)
|
34
|
+
x[:c][:a] = 4
|
35
|
+
assert_equal({a: 5, b: 6, c: {a: 1, b: 2}}, y)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "handles PDF references" do
|
39
|
+
x = HexaPDF::Reference.new(1, 2)
|
40
|
+
assert_same(x, HexaPDF::Object.deep_copy(x))
|
41
|
+
end
|
42
|
+
|
43
|
+
it "handles PDF objects" do
|
44
|
+
x = HexaPDF::Object.new("test")
|
45
|
+
assert_equal("test", HexaPDF::Object.deep_copy(x))
|
46
|
+
x.oid = 1
|
47
|
+
assert_same(x, HexaPDF::Object.deep_copy(x))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "initialize" do
|
52
|
+
it "uses a simple value as is" do
|
53
|
+
obj = HexaPDF::Object.new(5)
|
54
|
+
assert_equal(5, obj.value)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "reuses the data object of a HexaPDF::Object" do
|
58
|
+
obj = HexaPDF::Object.new(5)
|
59
|
+
assert_same(obj.data, HexaPDF::Object.new(obj).data)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "uses a provided PDFData structure" do
|
63
|
+
obj = HexaPDF::PDFData.new(5)
|
64
|
+
assert_equal(obj, HexaPDF::Object.new(obj).data)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "getters and setters" do
|
69
|
+
before do
|
70
|
+
@obj = HexaPDF::Object.new(5)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "can get/set oid" do
|
74
|
+
@obj.oid = 7
|
75
|
+
assert_equal(7, @obj.oid)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "can get/set gen" do
|
79
|
+
@obj.gen = 7
|
80
|
+
assert_equal(7, @obj.gen)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "can get/set the value" do
|
84
|
+
@obj.value = :test
|
85
|
+
assert_equal(:test, @obj.value)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "null?" do
|
90
|
+
it "works for nil values" do
|
91
|
+
assert(HexaPDF::Object.new(nil).null?)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "validate" do
|
96
|
+
it "invokes perform_validation correctly via #validate" do
|
97
|
+
obj = HexaPDF::Object.new(5)
|
98
|
+
invoked = {}
|
99
|
+
obj.define_singleton_method(:perform_validation) do |&block|
|
100
|
+
invoked[:method] = true
|
101
|
+
block.call("error", true)
|
102
|
+
end
|
103
|
+
assert(obj.validate {|*a| invoked[:block] = a})
|
104
|
+
assert_equal([:method, :block], invoked.keys)
|
105
|
+
assert_equal(["error", true], invoked[:block])
|
106
|
+
|
107
|
+
refute(obj.validate(auto_correct: false))
|
108
|
+
end
|
109
|
+
|
110
|
+
it "stops validating on an uncorrectable problem" do
|
111
|
+
obj = HexaPDF::Object.new(5)
|
112
|
+
invoked = {}
|
113
|
+
obj.define_singleton_method(:perform_validation) do |&block|
|
114
|
+
invoked[:before] = true
|
115
|
+
block.call("error", false)
|
116
|
+
invoked[:after] = true
|
117
|
+
end
|
118
|
+
refute(obj.validate {|*a| invoked[:block] = a})
|
119
|
+
refute(invoked.key?(:after))
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it "can represent itself during inspection" do
|
124
|
+
obj = HexaPDF::Object.new(5, oid: 5)
|
125
|
+
assert_match(/\[5, 0\].*value=5/, obj.inspect)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "can be compared to another object" do
|
129
|
+
obj = HexaPDF::Object.new(5, oid: 5)
|
130
|
+
|
131
|
+
assert_equal(obj, HexaPDF::Object.new(obj))
|
132
|
+
refute_equal(obj, HexaPDF::Object.new(5, oid: 5))
|
133
|
+
refute_equal(obj, HexaPDF::Object.new(6, oid: 5))
|
134
|
+
refute_equal(obj, HexaPDF::Object.new(5, oid: 1))
|
135
|
+
refute_equal(obj, HexaPDF::Object.new(5, oid: 5, gen: 1))
|
136
|
+
end
|
137
|
+
|
138
|
+
it "works correctly as hash key, is interchangable in this regard with Reference objects" do
|
139
|
+
hash = {}
|
140
|
+
hash[HexaPDF::Reference.new(1)] = :one
|
141
|
+
hash[HexaPDF::Object.new(:val, oid: 2)] = :two
|
142
|
+
assert_equal(:one, hash[HexaPDF::Reference.new(1, 0)])
|
143
|
+
assert_equal(:one, hash[HexaPDF::Object.new(:data, oid: 1)])
|
144
|
+
assert_equal(:two, hash[HexaPDF::Reference.new(2)])
|
145
|
+
assert_equal(:two, hash[HexaPDF::Object.new(:data, oid: 2)])
|
146
|
+
end
|
147
|
+
|
148
|
+
it "can be sorted together with Reference objects" do
|
149
|
+
a = HexaPDF::Object.new(:data, oid: 1)
|
150
|
+
b = HexaPDF::Object.new(:data, oid: 1, gen: 1)
|
151
|
+
c = HexaPDF::Reference.new(5, 7)
|
152
|
+
assert_equal([a, b, c], [b, c, a].sort)
|
153
|
+
end
|
154
|
+
|
155
|
+
describe "deep_copy" do
|
156
|
+
it "creates an independent object" do
|
157
|
+
obj = HexaPDF::Object.new(a: "mystring", b: HexaPDF::Reference.new(1, 0), c: 5)
|
158
|
+
copy = obj.deep_copy
|
159
|
+
refute_equal(copy, obj)
|
160
|
+
assert_equal(copy.value, obj.value)
|
161
|
+
refute_same(copy.value[:a], obj.value[:a])
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
it "validates that the object is indirect if it must be indirect" do
|
166
|
+
doc = Object.new
|
167
|
+
def doc.add(obj) obj.oid = 1 end
|
168
|
+
obj = HexaPDF::Object.new(6, document: doc)
|
169
|
+
|
170
|
+
obj.validate
|
171
|
+
assert_equal(0, obj.oid)
|
172
|
+
|
173
|
+
obj.must_be_indirect = true
|
174
|
+
obj.validate
|
175
|
+
assert_equal(1, obj.oid)
|
176
|
+
end
|
177
|
+
end
|