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,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'hexapdf/font/encoding'
|
5
|
+
|
6
|
+
describe HexaPDF::Font::Encoding do
|
7
|
+
describe "::for_name" do
|
8
|
+
it "returns nil if an unsupported encoding is given" do
|
9
|
+
assert_nil(HexaPDF::Font::Encoding.for_name(:some_unknown_encoding))
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns the requested encoding object" do
|
13
|
+
assert_kind_of(HexaPDF::Font::Encoding::WinAnsiEncoding,
|
14
|
+
HexaPDF::Font::Encoding.for_name(:WinAnsiEncoding))
|
15
|
+
assert_kind_of(HexaPDF::Font::Encoding::MacRomanEncoding,
|
16
|
+
HexaPDF::Font::Encoding.for_name(:MacRomanEncoding))
|
17
|
+
assert_kind_of(HexaPDF::Font::Encoding::StandardEncoding,
|
18
|
+
HexaPDF::Font::Encoding.for_name(:StandardEncoding))
|
19
|
+
assert_kind_of(HexaPDF::Font::Encoding::MacExpertEncoding,
|
20
|
+
HexaPDF::Font::Encoding.for_name(:MacExpertEncoding))
|
21
|
+
assert_kind_of(HexaPDF::Font::Encoding::SymbolEncoding,
|
22
|
+
HexaPDF::Font::Encoding.for_name(:SymbolEncoding))
|
23
|
+
assert_kind_of(HexaPDF::Font::Encoding::ZapfDingbatsEncoding,
|
24
|
+
HexaPDF::Font::Encoding.for_name(:ZapfDingbatsEncoding))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'hexapdf/font/true_type_wrapper'
|
5
|
+
require 'hexapdf/document'
|
6
|
+
|
7
|
+
describe HexaPDF::Font::TrueTypeWrapper do
|
8
|
+
before do
|
9
|
+
@doc = HexaPDF::Document.new
|
10
|
+
font_file = File.join(TEST_DATA_DIR, "fonts", "Ubuntu-Title.ttf")
|
11
|
+
@font = HexaPDF::Font::TrueType::Font.new(io: File.open(font_file))
|
12
|
+
@cmap = @font[:cmap].preferred_table
|
13
|
+
@font_wrapper = HexaPDF::Font::TrueTypeWrapper.new(@doc, @font)
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
@font.io.close
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "initialize" do
|
21
|
+
it "fails if the TrueType font has no Unicode cmap table" do
|
22
|
+
@font[:cmap].tables.clear
|
23
|
+
assert_raises(HexaPDF::Error) { HexaPDF::Font::TrueTypeWrapper.new(@doc, @font) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "decode_utf8" do
|
28
|
+
it "returns an array of glyph objects" do
|
29
|
+
assert_equal("Test",
|
30
|
+
@font_wrapper.decode_utf8("Test").map {|g| @cmap.gid_to_code(g.id)}.pack('U*'))
|
31
|
+
end
|
32
|
+
|
33
|
+
it "UTF-8 characters for which no glyph exists are mapped to the .notdef glyph" do
|
34
|
+
gotten = nil
|
35
|
+
@doc.config['font.on_missing_glyph'] = proc {|c| gotten = c; 0 }
|
36
|
+
assert_equal([0], @font_wrapper.decode_utf8("😁").map(&:id))
|
37
|
+
assert_equal(128513, gotten)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "glyph" do
|
42
|
+
it "returns the glyph object for the given id" do
|
43
|
+
glyph = @font_wrapper.glyph(3)
|
44
|
+
assert_equal(3, glyph.id)
|
45
|
+
assert_equal(338, glyph.width)
|
46
|
+
assert(glyph.space?)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "invokes font.on_missing_glyph for missing glyphs" do
|
50
|
+
assert_raises(HexaPDF::Error) { @font_wrapper.glyph(9999) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "encode" do
|
55
|
+
it "returns the PDF font dictionary and the encoded glyph" do
|
56
|
+
dict = @font_wrapper.dict
|
57
|
+
|
58
|
+
code = @font_wrapper.encode(@font_wrapper.glyph(3))
|
59
|
+
assert_equal([3].pack('n'), code)
|
60
|
+
glyph = @font_wrapper.decode_utf8('H').first
|
61
|
+
code = @font_wrapper.encode(glyph)
|
62
|
+
assert_equal([glyph.id].pack('n'), code)
|
63
|
+
|
64
|
+
@doc.dispatch_message(:complete_objects)
|
65
|
+
|
66
|
+
# Checking Type 0 font dictionary
|
67
|
+
assert_equal(:Font, dict[:Type])
|
68
|
+
assert_equal(:Type0, dict[:Subtype])
|
69
|
+
assert_equal(:'Identity-H', dict[:Encoding])
|
70
|
+
assert_equal(1, dict[:DescendantFonts].length)
|
71
|
+
assert_equal(dict[:BaseFont], dict[:DescendantFonts][0][:BaseFont])
|
72
|
+
assert_equal(HexaPDF::Font::CMap.create_to_unicode_cmap([[3, ' '.ord], [glyph.id, 'H'.ord]]),
|
73
|
+
dict[:ToUnicode].stream)
|
74
|
+
|
75
|
+
# Checking CIDFont dictionary
|
76
|
+
cidfont = dict[:DescendantFonts][0]
|
77
|
+
assert_equal(:Font, cidfont[:Type])
|
78
|
+
assert_equal(:CIDFontType2, cidfont[:Subtype])
|
79
|
+
assert_equal({Registry: "Adobe", Ordering: "Identity", Supplement: 0}, cidfont[:CIDSystemInfo])
|
80
|
+
assert_equal(:Identity, cidfont[:CIDToGIDMap])
|
81
|
+
assert_equal(@font_wrapper.glyph(3).width, cidfont[:DW])
|
82
|
+
assert_equal([glyph.id, [glyph.width]], cidfont[:W])
|
83
|
+
|
84
|
+
# Checking font descriptor
|
85
|
+
fd = cidfont[:FontDescriptor]
|
86
|
+
assert_equal(dict[:BaseFont], fd[:FontName])
|
87
|
+
assert(fd.flagged?(:symbolic))
|
88
|
+
assert(fd.key?(:FontFile2))
|
89
|
+
assert(fd.validate)
|
90
|
+
|
91
|
+
@cmap.stub(:[], nil) do
|
92
|
+
@font[:'OS/2'].typo_ascender = 1000
|
93
|
+
font_wrapper = HexaPDF::Font::TrueTypeWrapper.new(@doc, @font)
|
94
|
+
font_wrapper.encode(glyph)
|
95
|
+
fd = font_wrapper.dict[:DescendantFonts][0][:FontDescriptor]
|
96
|
+
assert_equal(800, fd[:CapHeight])
|
97
|
+
assert_equal(500, fd[:XHeight])
|
98
|
+
end
|
99
|
+
|
100
|
+
@font[:'OS/2'].version = 2
|
101
|
+
@font[:'OS/2'].x_height = 500 * @font[:head].units_per_em / 1000
|
102
|
+
@font[:'OS/2'].cap_height = 1000 * @font[:head].units_per_em / 1000
|
103
|
+
font_wrapper = HexaPDF::Font::TrueTypeWrapper.new(@doc, @font)
|
104
|
+
font_wrapper.encode(glyph)
|
105
|
+
fd = font_wrapper.dict[:DescendantFonts][0][:FontDescriptor]
|
106
|
+
assert_equal(1000, fd[:CapHeight])
|
107
|
+
assert_equal(500, fd[:XHeight])
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'hexapdf/font/type1_wrapper'
|
5
|
+
require 'hexapdf/document'
|
6
|
+
|
7
|
+
FONT_TIMES = HexaPDF::Font::Type1::Font.from_afm(File.join(HexaPDF.data_dir, 'afm', "Times-Roman.afm"))
|
8
|
+
FONT_SYMBOL = HexaPDF::Font::Type1::Font.from_afm(File.join(HexaPDF.data_dir, 'afm', "Symbol.afm"))
|
9
|
+
|
10
|
+
describe HexaPDF::Font::Type1Wrapper do
|
11
|
+
before do
|
12
|
+
@doc = HexaPDF::Document.new
|
13
|
+
@times_wrapper = HexaPDF::Font::Type1Wrapper.new(@doc, FONT_TIMES)
|
14
|
+
@symbol_wrapper = HexaPDF::Font::Type1Wrapper.new(@doc, FONT_SYMBOL)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "decode_utf8" do
|
18
|
+
it "returns an array of glyph objects" do
|
19
|
+
assert_equal([:T, :e, :s, :t], @times_wrapper.decode_utf8("Test").map(&:name))
|
20
|
+
end
|
21
|
+
|
22
|
+
it "UTF-8 characters for which no glyph name exist are mapped to themselves" do
|
23
|
+
gotten = nil
|
24
|
+
@doc.config['font.on_missing_glyph'] = proc {|c| gotten = c; :A }
|
25
|
+
assert_equal([:A], @times_wrapper.decode_utf8("😁").map(&:name))
|
26
|
+
assert_equal("😁", gotten)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "glyph" do
|
31
|
+
it "returns the glyph object for the given name" do
|
32
|
+
glyph = @times_wrapper.glyph(:A)
|
33
|
+
assert_equal(:A, glyph.name)
|
34
|
+
assert_equal(722, glyph.width)
|
35
|
+
refute(glyph.space?)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "invokes font.on_missing_glyph for missing glyphs" do
|
39
|
+
assert_raises(HexaPDF::Error) { @times_wrapper.glyph(:ffi) }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "encode" do
|
44
|
+
describe "uses WinAnsiEncoding as initial encoding for non-symbolic fonts" do
|
45
|
+
it "returns the PDF font dictionary using WinAnsiEncoding and encoded glyph" do
|
46
|
+
code = @times_wrapper.encode(@times_wrapper.glyph(:a))
|
47
|
+
@doc.dispatch_message(:complete_objects)
|
48
|
+
assert_equal("a", code)
|
49
|
+
assert_equal(:WinAnsiEncoding, @times_wrapper.dict[:Encoding])
|
50
|
+
end
|
51
|
+
|
52
|
+
it "fails if the encoding does not support the given glyph" do
|
53
|
+
assert_raises(HexaPDF::Error) { @times_wrapper.encode(@times_wrapper.glyph(:uring)) }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "uses an empty encoding as initial encoding for symbolic fonts" do
|
58
|
+
it "returns the PDF font dictionary and encoded glyph" do
|
59
|
+
code = @symbol_wrapper.encode(@symbol_wrapper.glyph(:plus))
|
60
|
+
@doc.dispatch_message(:complete_objects)
|
61
|
+
assert_equal("\x21", code)
|
62
|
+
assert_equal({Differences: [32, :space, :plus]}, @symbol_wrapper.dict[:Encoding])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'hexapdf/font/true_type/table'
|
4
|
+
|
5
|
+
module TestHelper
|
6
|
+
|
7
|
+
class TrueTypeTestTable < HexaPDF::Font::TrueType::Table
|
8
|
+
attr_reader :data
|
9
|
+
|
10
|
+
def parse_table
|
11
|
+
@data = io.read(directory_entry.length)
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_default
|
15
|
+
@data = 'default'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'stringio'
|
5
|
+
require 'hexapdf/font/true_type/table/cmap'
|
6
|
+
|
7
|
+
describe HexaPDF::Font::TrueType::Table::Cmap do
|
8
|
+
before do
|
9
|
+
f0 = [0, 262, 0].pack('n3') + (0..255).to_a.pack('C*')
|
10
|
+
data = [0, 3].pack('n2') << [[0, 1, 28],
|
11
|
+
[3, 1, 28 + f0.length],
|
12
|
+
[1, 0, 28],
|
13
|
+
].map {|a| a.pack('n2N')}.join('') << \
|
14
|
+
f0 << f0
|
15
|
+
io = StringIO.new(data)
|
16
|
+
config = @config = {}
|
17
|
+
@file = Object.new
|
18
|
+
@file.define_singleton_method(:io) { io }
|
19
|
+
@file.define_singleton_method(:config) { config }
|
20
|
+
@entry = HexaPDF::Font::TrueType::Table::Directory::Entry.new('cmap', 0, 0, io.length)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "initialize" do
|
24
|
+
it "reads the data from the associated file" do
|
25
|
+
table = HexaPDF::Font::TrueType::Table::Cmap.new(@file, @entry)
|
26
|
+
assert_equal(0, table.version)
|
27
|
+
assert_equal(3, table.tables.length)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "ignores unknown subtable when the config option is set to :ignore" do
|
31
|
+
@file.io.string = [0, 1].pack('n2') << [3, 1, 12].pack('n2N') << "\x00\x03"
|
32
|
+
table = HexaPDF::Font::TrueType::Table::Cmap.new(@file, @entry)
|
33
|
+
assert_equal(0, table.tables.length)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises an error when an unsupported subtable is found and the option is set to :raise" do
|
37
|
+
@file.io.string = [0, 1].pack('n2') << [3, 1, 12].pack('n2N') << "\x00\x03"
|
38
|
+
@file.config['font.true_type.cmap.unknown_format'] = :raise
|
39
|
+
assert_raises(HexaPDF::Error) { HexaPDF::Font::TrueType::Table::Cmap.new(@file, @entry) }
|
40
|
+
end
|
41
|
+
|
42
|
+
it "loads some default values if no entry is given" do
|
43
|
+
table = HexaPDF::Font::TrueType::Table::Cmap.new(@file)
|
44
|
+
assert_equal(0, table.version)
|
45
|
+
assert_equal([], table.tables)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "loads data from subtables with identical offsets only once" do
|
49
|
+
table = HexaPDF::Font::TrueType::Table::Cmap.new(@file, @entry)
|
50
|
+
assert_same(table.tables[0].gid_map, table.tables[2].gid_map)
|
51
|
+
refute_same(table.tables[0].gid_map, table.tables[1].gid_map)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns the preferred table" do
|
56
|
+
table = HexaPDF::Font::TrueType::Table::Cmap.new(@file, @entry)
|
57
|
+
assert_equal(table.tables[1], table.preferred_table)
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'stringio'
|
5
|
+
require 'hexapdf/font/true_type/table/cmap_subtable'
|
6
|
+
|
7
|
+
describe HexaPDF::Font::TrueType::Table::CmapSubtable do
|
8
|
+
before do
|
9
|
+
@klass = HexaPDF::Font::TrueType::Table::CmapSubtable
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "initialize" do
|
13
|
+
it "uses default values" do
|
14
|
+
t = @klass.new(3, 1)
|
15
|
+
assert_equal(3, t.platform_id)
|
16
|
+
assert_equal(1, t.encoding_id)
|
17
|
+
assert_nil(t.format)
|
18
|
+
assert_equal(0, t.language)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "unicode?" do
|
23
|
+
it "identifies (0,x), (3,1) and (3,10) as unicode" do
|
24
|
+
assert(@klass.new(0, 1).unicode?)
|
25
|
+
assert(@klass.new(0, 5).unicode?)
|
26
|
+
assert(@klass.new(3, 1).unicode?)
|
27
|
+
assert(@klass.new(3, 10).unicode?)
|
28
|
+
refute(@klass.new(1, 0).unicode?)
|
29
|
+
refute(@klass.new(3, 0).unicode?)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "inspect" do
|
34
|
+
it "can represent itself nicely" do
|
35
|
+
assert_equal("#<#{@klass.name} (3, 1, 0, nil)>", @klass.new(3, 1).inspect)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "parse" do
|
40
|
+
def table(data)
|
41
|
+
@klass.new(3, 1).tap {|obj| obj.parse(StringIO.new(data), 0)}
|
42
|
+
end
|
43
|
+
|
44
|
+
it "works for format 0" do
|
45
|
+
t = table([0, 262, 0].pack('n3') + [255].pack('C*') + (0..254).to_a.pack('C*'))
|
46
|
+
assert_equal(255, t[0])
|
47
|
+
assert_equal(233, t[234])
|
48
|
+
assert_nil(t[256])
|
49
|
+
|
50
|
+
assert_equal(0, t.gid_to_code(255))
|
51
|
+
assert_equal(234, t.gid_to_code(233))
|
52
|
+
end
|
53
|
+
|
54
|
+
it "works for format 2" do
|
55
|
+
f2 = ([0, 8] + [0] * 254).pack('n*') + \
|
56
|
+
[[0, 256, 0, 2 + 8], [0x33, 3, 5, 2 + 256 * 2]].map {|a| a.pack('n2s>n')}.join('') + \
|
57
|
+
((0..255).to_a + [35, 65534, 0]).pack('n*')
|
58
|
+
t = table([2, f2.length + 6, 0].pack('n3') << f2)
|
59
|
+
assert_nil(t[0x0132])
|
60
|
+
assert_equal(40, t[0x0133])
|
61
|
+
assert_equal(3, t[0x0134])
|
62
|
+
assert_nil(t[0x0135])
|
63
|
+
assert_nil(t[0x0136])
|
64
|
+
assert_equal(16, t[0x1036])
|
65
|
+
assert_nil(t[0xfffff])
|
66
|
+
|
67
|
+
assert_equal(0x0133, t.gid_to_code(40))
|
68
|
+
assert_equal(0x0134, t.gid_to_code(3))
|
69
|
+
assert_equal(16, t.gid_to_code(16))
|
70
|
+
end
|
71
|
+
|
72
|
+
it "works for format 4" do
|
73
|
+
f4 = [6, 8, 2, 4, 35, 134, 65535, 0, 30, 133, 65535, 100, 110, 120,
|
74
|
+
0, 6, 2, 65500, 0, 1].pack('n*')
|
75
|
+
t = table([4, f4.length + 6, 0].pack('n3') << f4)
|
76
|
+
assert_nil(t[25])
|
77
|
+
assert_equal(130, t[30])
|
78
|
+
assert_equal(133, t[33])
|
79
|
+
assert_equal(135, t[35])
|
80
|
+
assert_nil(t[36])
|
81
|
+
assert_nil(t[133])
|
82
|
+
assert_equal(111, t[134])
|
83
|
+
assert_equal(84, t[65535])
|
84
|
+
assert_nil(t[70000])
|
85
|
+
|
86
|
+
assert_equal(30, t.gid_to_code(130))
|
87
|
+
assert_equal(33, t.gid_to_code(133))
|
88
|
+
assert_equal(35, t.gid_to_code(135))
|
89
|
+
assert_equal(134, t.gid_to_code(111))
|
90
|
+
assert_equal(65535, t.gid_to_code(84))
|
91
|
+
end
|
92
|
+
|
93
|
+
it "works for format 6" do
|
94
|
+
t = table(([6, 30, 0, 1024, 10] + (1..10).to_a).pack('n*'))
|
95
|
+
assert_nil(t[0])
|
96
|
+
assert_equal(1, t[1024])
|
97
|
+
assert_equal(7, t[1030])
|
98
|
+
assert_equal(10, t[1033])
|
99
|
+
assert_nil(t[1034])
|
100
|
+
|
101
|
+
assert_equal(1033, t.gid_to_code(10))
|
102
|
+
end
|
103
|
+
|
104
|
+
it "works for format 10" do
|
105
|
+
t = table([10, 0].pack('n2') + [40, 0, 1024, 10].pack('N*') + (1..10).to_a.pack('n*'))
|
106
|
+
assert_nil(t[234])
|
107
|
+
assert_equal(1, t[1024])
|
108
|
+
assert_equal(7, t[1030])
|
109
|
+
assert_equal(10, t[1033])
|
110
|
+
assert_nil(t[1034])
|
111
|
+
|
112
|
+
assert_equal(1033, t.gid_to_code(10))
|
113
|
+
end
|
114
|
+
|
115
|
+
it "works for format 12" do
|
116
|
+
t = table([12, 0].pack('n2') + [40, 0, 2, 35, 38, 1000, 70000, 90000, 80000].pack('N*'))
|
117
|
+
assert_nil(t[30])
|
118
|
+
assert_equal(1000, t[35])
|
119
|
+
assert_equal(1003, t[38])
|
120
|
+
assert_equal(100_000, t[90_000])
|
121
|
+
assert_nil(t[90_001])
|
122
|
+
|
123
|
+
assert_equal(35, t.gid_to_code(1000))
|
124
|
+
assert_equal(38, t.gid_to_code(1003))
|
125
|
+
assert_equal(90_000, t.gid_to_code(100_000))
|
126
|
+
end
|
127
|
+
|
128
|
+
it "returns false if a format is not supported" do
|
129
|
+
refute(@klass.new(3, 1).parse(StringIO.new("\x00\x03".b), 0))
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'hexapdf/font/true_type/table/directory'
|
5
|
+
|
6
|
+
describe HexaPDF::Font::TrueType::Table::Directory do
|
7
|
+
before do
|
8
|
+
io = StringIO.new("TEST\x00\x01\x00\x00\x00\x00\x00\x00" \
|
9
|
+
"CUST----\x00\x00\x00\x1C\x00\x00\x00\x05ENTRY".b)
|
10
|
+
@file = Object.new
|
11
|
+
@file.define_singleton_method(:io) { io }
|
12
|
+
@self_entry = HexaPDF::Font::TrueType::Table::Directory::SELF_ENTRY
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has a dummy entry referring to itself" do
|
16
|
+
assert_equal(0, @self_entry.offset)
|
17
|
+
assert_equal(12, @self_entry.length)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "initialize" do
|
21
|
+
it "loads the table entries from the IO" do
|
22
|
+
dir = HexaPDF::Font::TrueType::Table::Directory.new(@file, @self_entry)
|
23
|
+
entry = dir.entry('CUST')
|
24
|
+
assert_equal('CUST', entry.tag)
|
25
|
+
assert_equal('----'.unpack('N').first, entry.checksum)
|
26
|
+
assert_equal(28, entry.offset)
|
27
|
+
assert_equal(5, entry.length)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "loads the default values if no entry is given" do
|
31
|
+
dir = HexaPDF::Font::TrueType::Table::Directory.new(@file)
|
32
|
+
assert_equal(0, dir.instance_eval { @tables }.length)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'stringio'
|
5
|
+
require 'hexapdf/font/true_type/table/glyf'
|
6
|
+
|
7
|
+
describe HexaPDF::Font::TrueType::Table::Glyf do
|
8
|
+
before do
|
9
|
+
@file = Object.new
|
10
|
+
loca = HexaPDF::Font::TrueType::Table::Loca.new(@file)
|
11
|
+
loca.offsets = [0, 0]
|
12
|
+
data = [1, -10, -20, 100, 150].pack('s>5')
|
13
|
+
loca.offsets << data.size
|
14
|
+
data << [-1, 10, 20, -100, -150].pack('s>5')
|
15
|
+
data << [0b00100000, 1, 20, 30].pack('n2C2')
|
16
|
+
data << [0b00101001, 2, 20, 30, 40].pack('n2n2n')
|
17
|
+
data << [0b01100001, 3, 20, 30, 40, 50].pack('n2n2n2')
|
18
|
+
data << [0b10100001, 4, 20, 30, 40, 50, 60, 70].pack('n2n2n4')
|
19
|
+
data << [0b00000000, 1, 20, 30].pack('n2C2')
|
20
|
+
loca.offsets << data.size
|
21
|
+
@file.define_singleton_method(:io) { @io ||= StringIO.new(data) }
|
22
|
+
@file.define_singleton_method(:[]) {|_arg| loca }
|
23
|
+
@entry = HexaPDF::Font::TrueType::Table::Directory::Entry.new('glyf', 0, 0, @file.io.length)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "initialize" do
|
27
|
+
it "reads the data from the associated file" do
|
28
|
+
table = HexaPDF::Font::TrueType::Table::Glyf.new(@file, @entry)
|
29
|
+
glyph = table[0]
|
30
|
+
refute(glyph.compound?)
|
31
|
+
assert_equal(0, glyph.number_of_contours)
|
32
|
+
|
33
|
+
glyph = table[1]
|
34
|
+
refute(glyph.compound?)
|
35
|
+
assert_equal(1, glyph.number_of_contours)
|
36
|
+
assert_equal(-10, glyph.x_min)
|
37
|
+
assert_equal(-20, glyph.y_min)
|
38
|
+
assert_equal(100, glyph.x_max)
|
39
|
+
assert_equal(150, glyph.y_max)
|
40
|
+
assert_same(glyph, table[1])
|
41
|
+
|
42
|
+
glyph = table[2]
|
43
|
+
assert(glyph.compound?)
|
44
|
+
assert_equal(-1, glyph.number_of_contours)
|
45
|
+
assert_equal(10, glyph.x_min)
|
46
|
+
assert_equal(20, glyph.y_min)
|
47
|
+
assert_equal(-100, glyph.x_max)
|
48
|
+
assert_equal(-150, glyph.y_max)
|
49
|
+
assert_equal([1, 2, 3, 4, 1], glyph.components)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "loads some default values if no entry is given" do
|
53
|
+
table = HexaPDF::Font::TrueType::Table::Glyf.new(@file)
|
54
|
+
assert_equal({}, table.glyphs)
|
55
|
+
assert_nil(table[0])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'stringio'
|
5
|
+
require 'hexapdf/font/true_type/table/head'
|
6
|
+
|
7
|
+
describe HexaPDF::Font::TrueType::Table::Head do
|
8
|
+
before do
|
9
|
+
data = [1, 0, 2, 6554, 0, 42, 0x5f0f, 0x3CF5, 3, 64].pack('n*')
|
10
|
+
@time = Time.new(2016, 05, 01)
|
11
|
+
data << ([(@time - HexaPDF::Font::TrueType::Table::TIME_EPOCH).to_i] * 2).pack('Q>*')
|
12
|
+
data << [-132, -152, 3423, 4231, 3, 9, -2, 0, 0].pack('s>4n2s>3')
|
13
|
+
io = StringIO.new(data)
|
14
|
+
@file = Object.new
|
15
|
+
@file.define_singleton_method(:io) { io }
|
16
|
+
@entry = HexaPDF::Font::TrueType::Table::Directory::Entry.new('head', 0, 0, io.length)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "initialize" do
|
20
|
+
it "reads the data from the associated file" do
|
21
|
+
table = HexaPDF::Font::TrueType::Table::Head.new(@file, @entry)
|
22
|
+
assert_equal('1.0', '%1.1f' % table.version)
|
23
|
+
assert_equal('2.1', '%1.1f' % table.font_revision)
|
24
|
+
assert_equal(42, table.checksum_adjustment)
|
25
|
+
assert_equal(3, table.flags)
|
26
|
+
assert_equal(64, table.units_per_em)
|
27
|
+
assert_equal(@time, table.created)
|
28
|
+
assert_equal(@time, table.modified)
|
29
|
+
assert_equal([-132, -152, 3423, 4231], table.bbox)
|
30
|
+
assert_equal(3, table.mac_style)
|
31
|
+
assert_equal(9, table.smallest_readable_size)
|
32
|
+
assert_equal(-2, table.font_direction_hint)
|
33
|
+
assert_equal(0, table.index_to_loc_format)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "loads some default values if no entry is given" do
|
37
|
+
table = HexaPDF::Font::TrueType::Table::Head.new(@file)
|
38
|
+
assert_equal(1.0, table.version.to_f)
|
39
|
+
assert_equal(1.0, table.font_revision.to_f)
|
40
|
+
assert_equal(0, table.checksum_adjustment)
|
41
|
+
assert_equal(0, table.flags)
|
42
|
+
assert_equal(64, table.units_per_em)
|
43
|
+
assert(Time.now - table.created < 2)
|
44
|
+
assert(Time.now - table.created < 2)
|
45
|
+
assert_equal([0, 0, 0, 0], table.bbox)
|
46
|
+
assert_equal(0, table.mac_style)
|
47
|
+
assert_equal(0, table.smallest_readable_size)
|
48
|
+
assert_equal(0, table.font_direction_hint)
|
49
|
+
assert_equal(0, table.index_to_loc_format)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "raises an error if the magic number is false when reading from a file" do
|
53
|
+
@file.io.string[12, 1] = '\x5e'
|
54
|
+
assert_raises(HexaPDF::Error) { HexaPDF::Font::TrueType::Table::Head.new(@file, @entry) }
|
55
|
+
end
|
56
|
+
|
57
|
+
it "raises an error if an invalid glyph format is specified when reading from a file" do
|
58
|
+
@file.io.string[-1] = '\x5e'
|
59
|
+
assert_raises(HexaPDF::Error) { HexaPDF::Font::TrueType::Table::Head.new(@file, @entry) }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "checksum_valid?" do
|
64
|
+
it "checks whether an entry's checksum is valid" do
|
65
|
+
@file.io.string = 254.chr * 12 + [0x5F0F3CF5].pack('N') + 254.chr * 36 + 0.chr * 4
|
66
|
+
@entry.checksum = (0xfefefefe * 11 + 0x5F0F3CF5) % 2**32
|
67
|
+
@entry.length = @file.io.string.length
|
68
|
+
table = HexaPDF::Font::TrueType::Table::Head.new(@file, @entry)
|
69
|
+
assert(table.checksum_valid?)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "raises an error if the checksum can't be verified because none is available" do
|
73
|
+
assert_raises(HexaPDF::Error) { HexaPDF::Font::TrueType::Table::Head.new(@file).checksum_valid? }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'stringio'
|
5
|
+
require 'hexapdf/font/true_type/table/hhea'
|
6
|
+
|
7
|
+
describe HexaPDF::Font::TrueType::Table::Hhea do
|
8
|
+
before do
|
9
|
+
data = [1, 0, 10, 11, 12, 100, 101, 102, 115, 1, 0, 0, 0, 0, 0, 0, 0, 10].pack('n2s>3ns>11n')
|
10
|
+
io = StringIO.new(data)
|
11
|
+
@file = Object.new
|
12
|
+
@file.define_singleton_method(:io) { io }
|
13
|
+
@entry = HexaPDF::Font::TrueType::Table::Directory::Entry.new('hhea', 0, 0, io.length)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "initialize" do
|
17
|
+
it "reads the data from the associated file" do
|
18
|
+
table = HexaPDF::Font::TrueType::Table::Hhea.new(@file, @entry)
|
19
|
+
assert_equal(1, table.version)
|
20
|
+
assert_equal(10, table.ascent)
|
21
|
+
assert_equal(11, table.descent)
|
22
|
+
assert_equal(12, table.line_gap)
|
23
|
+
assert_equal(100, table.advance_width_max)
|
24
|
+
assert_equal(101, table.min_left_side_bearing)
|
25
|
+
assert_equal(102, table.min_right_side_bearing)
|
26
|
+
assert_equal(115, table.x_max_extent)
|
27
|
+
assert_equal(1, table.caret_slope_rise)
|
28
|
+
assert_equal(0, table.caret_slope_run)
|
29
|
+
assert_equal(0, table.caret_offset)
|
30
|
+
assert_equal(10, table.num_of_long_hor_metrics)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "loads some default values if no entry is given" do
|
34
|
+
table = HexaPDF::Font::TrueType::Table::Hhea.new(@file)
|
35
|
+
assert_equal(1, table.version)
|
36
|
+
assert_equal(0, table.ascent)
|
37
|
+
assert_equal(0, table.descent)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'stringio'
|
5
|
+
require 'hexapdf/font/true_type/table/hhea'
|
6
|
+
require 'hexapdf/font/true_type/table/hmtx'
|
7
|
+
|
8
|
+
describe HexaPDF::Font::TrueType::Table::Hhea do
|
9
|
+
before do
|
10
|
+
data = [1, -2, 3, -4, 5, -6].pack('ns>ns>s>2')
|
11
|
+
io = StringIO.new(data)
|
12
|
+
@file = Object.new
|
13
|
+
@file.define_singleton_method(:io) { io }
|
14
|
+
hhea = HexaPDF::Font::TrueType::Table::Hhea.new(@file)
|
15
|
+
hhea.num_of_long_hor_metrics = 2
|
16
|
+
@file.define_singleton_method(:[]) {|_arg| hhea }
|
17
|
+
@entry = HexaPDF::Font::TrueType::Table::Directory::Entry.new('hmtx', 0, 0, io.length)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "initialize" do
|
21
|
+
it "reads the data from the associated file" do
|
22
|
+
table = HexaPDF::Font::TrueType::Table::Hmtx.new(@file, @entry)
|
23
|
+
assert_equal(1, table[0].advance_width)
|
24
|
+
assert_equal(-2, table[0].left_side_bearing)
|
25
|
+
assert_equal(3, table[1].advance_width)
|
26
|
+
assert_equal(-4, table[1].left_side_bearing)
|
27
|
+
assert_equal(3, table[2].advance_width)
|
28
|
+
assert_equal(5, table[2].left_side_bearing)
|
29
|
+
assert_equal(3, table[3].advance_width)
|
30
|
+
assert_equal(-6, table[3].left_side_bearing)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "loads some default values if no entry is given" do
|
34
|
+
table = HexaPDF::Font::TrueType::Table::Hmtx.new(@file)
|
35
|
+
assert_equal([], table.horizontal_metrics)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|