hexapdf 0.46.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +342 -16
- data/LICENSE +1 -1
- data/README.md +9 -8
- data/examples/009-text_layouter_alignment.rb +4 -0
- data/examples/010-text_layouter_inline_boxes.rb +4 -0
- data/examples/011-text_layouter_line_wrapping.rb +4 -0
- data/examples/012-text_layouter_styling.rb +9 -4
- data/examples/013-text_layouter_shapes.rb +5 -0
- data/examples/015-boxes.rb +3 -0
- data/examples/016-frame_automatic_box_placement.rb +3 -0
- data/examples/017-frame_text_flow.rb +3 -0
- data/examples/022-outline.rb +5 -1
- data/examples/{028-frame_mask_mode.rb → 028-composer_mask_mode.rb} +3 -3
- data/lib/hexapdf/cli/batch.rb +1 -1
- data/lib/hexapdf/cli/command.rb +65 -65
- data/lib/hexapdf/cli/debug_info.rb +98 -0
- data/lib/hexapdf/cli/files.rb +1 -1
- data/lib/hexapdf/cli/fonts.rb +1 -1
- data/lib/hexapdf/cli/form.rb +11 -6
- data/lib/hexapdf/cli/image2pdf.rb +1 -1
- data/lib/hexapdf/cli/images.rb +19 -4
- data/lib/hexapdf/cli/info.rb +1 -1
- data/lib/hexapdf/cli/inspect.rb +24 -8
- data/lib/hexapdf/cli/merge.rb +1 -1
- data/lib/hexapdf/cli/modify.rb +1 -2
- data/lib/hexapdf/cli/optimize.rb +6 -6
- data/lib/hexapdf/cli/split.rb +1 -1
- data/lib/hexapdf/cli/usage.rb +1 -1
- data/lib/hexapdf/cli/watermark.rb +1 -1
- data/lib/hexapdf/cli.rb +20 -2
- data/lib/hexapdf/composer.rb +22 -1
- data/lib/hexapdf/configuration.rb +56 -1
- data/lib/hexapdf/content/canvas.rb +1 -1
- data/lib/hexapdf/content/canvas_composer.rb +1 -1
- data/lib/hexapdf/content/color_space.rb +1 -1
- data/lib/hexapdf/content/graphic_object/arc.rb +1 -1
- data/lib/hexapdf/content/graphic_object/endpoint_arc.rb +1 -1
- data/lib/hexapdf/content/graphic_object/geom2d.rb +1 -1
- data/lib/hexapdf/content/graphic_object/solid_arc.rb +1 -1
- data/lib/hexapdf/content/graphic_object.rb +1 -1
- data/lib/hexapdf/content/graphics_state.rb +2 -2
- data/lib/hexapdf/content/operator.rb +1 -1
- data/lib/hexapdf/content/parser.rb +22 -23
- data/lib/hexapdf/content/processor.rb +1 -1
- data/lib/hexapdf/content/transformation_matrix.rb +1 -1
- data/lib/hexapdf/content.rb +1 -1
- data/lib/hexapdf/data_dir.rb +1 -1
- data/lib/hexapdf/dictionary.rb +8 -2
- data/lib/hexapdf/dictionary_fields.rb +2 -2
- data/lib/hexapdf/digital_signature/cms_handler.rb +19 -2
- data/lib/hexapdf/digital_signature/handler.rb +1 -1
- data/lib/hexapdf/digital_signature/pkcs1_handler.rb +1 -1
- data/lib/hexapdf/digital_signature/signature.rb +2 -2
- data/lib/hexapdf/digital_signature/signatures.rb +1 -1
- data/lib/hexapdf/digital_signature/signing/default_handler.rb +3 -3
- data/lib/hexapdf/digital_signature/signing/signed_data_creator.rb +2 -2
- data/lib/hexapdf/digital_signature/signing/timestamp_handler.rb +25 -5
- data/lib/hexapdf/digital_signature/signing.rb +1 -1
- data/lib/hexapdf/digital_signature/verification_result.rb +1 -1
- data/lib/hexapdf/digital_signature.rb +1 -1
- data/lib/hexapdf/document/annotations.rb +220 -0
- data/lib/hexapdf/document/destinations.rb +1 -1
- data/lib/hexapdf/document/files.rb +1 -1
- data/lib/hexapdf/document/fonts.rb +1 -1
- data/lib/hexapdf/document/images.rb +1 -1
- data/lib/hexapdf/document/layout.rb +95 -16
- data/lib/hexapdf/document/metadata.rb +11 -4
- data/lib/hexapdf/document/pages.rb +1 -1
- data/lib/hexapdf/document.rb +52 -9
- data/lib/hexapdf/encryption/aes.rb +1 -1
- data/lib/hexapdf/encryption/arc4.rb +3 -3
- data/lib/hexapdf/encryption/fast_aes.rb +1 -1
- data/lib/hexapdf/encryption/fast_arc4.rb +1 -1
- data/lib/hexapdf/encryption/identity.rb +1 -1
- data/lib/hexapdf/encryption/ruby_aes.rb +1 -1
- data/lib/hexapdf/encryption/ruby_arc4.rb +1 -1
- data/lib/hexapdf/encryption/security_handler.rb +4 -2
- data/lib/hexapdf/encryption/standard_security_handler.rb +40 -29
- data/lib/hexapdf/encryption.rb +1 -1
- data/lib/hexapdf/error.rb +12 -4
- data/lib/hexapdf/filter/ascii85_decode.rb +1 -1
- data/lib/hexapdf/filter/ascii_hex_decode.rb +1 -1
- data/lib/hexapdf/filter/crypt.rb +1 -1
- data/lib/hexapdf/filter/encryption.rb +1 -1
- data/lib/hexapdf/filter/flate_decode.rb +1 -1
- data/lib/hexapdf/filter/lzw_decode.rb +1 -1
- data/lib/hexapdf/filter/pass_through.rb +1 -1
- data/lib/hexapdf/filter/predictor.rb +1 -1
- data/lib/hexapdf/filter/run_length_decode.rb +1 -1
- data/lib/hexapdf/filter.rb +1 -1
- data/lib/hexapdf/font/cmap/parser.rb +1 -1
- data/lib/hexapdf/font/cmap/writer.rb +59 -5
- data/lib/hexapdf/font/cmap.rb +18 -7
- data/lib/hexapdf/font/encoding/base.rb +28 -1
- data/lib/hexapdf/font/encoding/difference_encoding.rb +1 -1
- data/lib/hexapdf/font/encoding/glyph_list.rb +1 -1
- data/lib/hexapdf/font/encoding/mac_expert_encoding.rb +1 -1
- data/lib/hexapdf/font/encoding/mac_roman_encoding.rb +1 -1
- data/lib/hexapdf/font/encoding/standard_encoding.rb +1 -1
- data/lib/hexapdf/font/encoding/symbol_encoding.rb +1 -1
- data/lib/hexapdf/font/encoding/win_ansi_encoding.rb +1 -1
- data/lib/hexapdf/font/encoding/zapf_dingbats_encoding.rb +1 -1
- data/lib/hexapdf/font/encoding.rb +1 -1
- data/lib/hexapdf/font/invalid_glyph.rb +1 -1
- data/lib/hexapdf/font/true_type/builder.rb +1 -1
- data/lib/hexapdf/font/true_type/font.rb +1 -1
- data/lib/hexapdf/font/true_type/optimizer.rb +1 -1
- data/lib/hexapdf/font/true_type/subsetter.rb +1 -1
- data/lib/hexapdf/font/true_type/table/cmap.rb +1 -1
- data/lib/hexapdf/font/true_type/table/cmap_subtable.rb +1 -1
- data/lib/hexapdf/font/true_type/table/directory.rb +1 -1
- data/lib/hexapdf/font/true_type/table/glyf.rb +1 -1
- data/lib/hexapdf/font/true_type/table/head.rb +1 -1
- data/lib/hexapdf/font/true_type/table/hhea.rb +1 -1
- data/lib/hexapdf/font/true_type/table/hmtx.rb +1 -1
- data/lib/hexapdf/font/true_type/table/kern.rb +1 -1
- data/lib/hexapdf/font/true_type/table/loca.rb +1 -1
- data/lib/hexapdf/font/true_type/table/maxp.rb +1 -1
- data/lib/hexapdf/font/true_type/table/name.rb +1 -1
- data/lib/hexapdf/font/true_type/table/os2.rb +1 -1
- data/lib/hexapdf/font/true_type/table/post.rb +1 -1
- data/lib/hexapdf/font/true_type/table.rb +7 -2
- data/lib/hexapdf/font/true_type.rb +1 -1
- data/lib/hexapdf/font/true_type_wrapper.rb +51 -16
- data/lib/hexapdf/font/type1/afm_parser.rb +1 -1
- data/lib/hexapdf/font/type1/character_metrics.rb +1 -1
- data/lib/hexapdf/font/type1/font.rb +1 -1
- data/lib/hexapdf/font/type1/font_metrics.rb +1 -1
- data/lib/hexapdf/font/type1/pfb_parser.rb +1 -1
- data/lib/hexapdf/font/type1.rb +1 -1
- data/lib/hexapdf/font/type1_wrapper.rb +3 -4
- data/lib/hexapdf/font_loader/from_configuration.rb +1 -1
- data/lib/hexapdf/font_loader/from_file.rb +1 -1
- data/lib/hexapdf/font_loader/standard14.rb +1 -1
- data/lib/hexapdf/font_loader/variant_from_name.rb +1 -1
- data/lib/hexapdf/font_loader.rb +1 -1
- data/lib/hexapdf/image_loader/jpeg.rb +1 -1
- data/lib/hexapdf/image_loader/pdf.rb +1 -1
- data/lib/hexapdf/image_loader/png.rb +1 -1
- data/lib/hexapdf/image_loader.rb +1 -1
- data/lib/hexapdf/importer.rb +2 -2
- data/lib/hexapdf/layout/box.rb +6 -1
- data/lib/hexapdf/layout/box_fitter.rb +1 -1
- data/lib/hexapdf/layout/column_box.rb +1 -1
- data/lib/hexapdf/layout/container_box.rb +64 -29
- data/lib/hexapdf/layout/frame.rb +1 -1
- data/lib/hexapdf/layout/image_box.rb +1 -1
- data/lib/hexapdf/layout/inline_box.rb +1 -1
- data/lib/hexapdf/layout/line.rb +1 -1
- data/lib/hexapdf/layout/list_box.rb +1 -1
- data/lib/hexapdf/layout/numeric_refinements.rb +1 -1
- data/lib/hexapdf/layout/page_style.rb +1 -1
- data/lib/hexapdf/layout/style.rb +133 -22
- data/lib/hexapdf/layout/table_box.rb +86 -14
- data/lib/hexapdf/layout/text_box.rb +1 -1
- data/lib/hexapdf/layout/text_fragment.rb +13 -2
- data/lib/hexapdf/layout/text_layouter.rb +1 -1
- data/lib/hexapdf/layout/text_shaper.rb +1 -1
- data/lib/hexapdf/layout/width_from_polygon.rb +1 -1
- data/lib/hexapdf/layout.rb +1 -1
- data/lib/hexapdf/name_tree_node.rb +1 -1
- data/lib/hexapdf/number_tree_node.rb +1 -1
- data/lib/hexapdf/object.rb +4 -4
- data/lib/hexapdf/parser.rb +36 -7
- data/lib/hexapdf/pdf_array.rb +26 -4
- data/lib/hexapdf/rectangle.rb +1 -1
- data/lib/hexapdf/reference.rb +2 -2
- data/lib/hexapdf/revision.rb +7 -3
- data/lib/hexapdf/revisions.rb +1 -1
- data/lib/hexapdf/serializer.rb +8 -8
- data/lib/hexapdf/stream.rb +1 -1
- data/lib/hexapdf/task/dereference.rb +1 -1
- data/lib/hexapdf/task/merge_acro_form.rb +164 -0
- data/lib/hexapdf/task/optimize.rb +5 -5
- data/lib/hexapdf/task/pdfa.rb +1 -1
- data/lib/hexapdf/task.rb +2 -1
- data/lib/hexapdf/test_utils.rb +3 -2
- data/lib/hexapdf/tokenizer.rb +52 -44
- data/lib/hexapdf/type/acro_form/appearance_generator.rb +66 -13
- data/lib/hexapdf/type/acro_form/button_field.rb +1 -1
- data/lib/hexapdf/type/acro_form/choice_field.rb +1 -1
- data/lib/hexapdf/type/acro_form/field.rb +6 -2
- data/lib/hexapdf/type/acro_form/form.rb +23 -32
- data/lib/hexapdf/type/acro_form/java_script_actions.rb +10 -3
- data/lib/hexapdf/type/acro_form/signature_field.rb +19 -8
- data/lib/hexapdf/type/acro_form/text_field.rb +10 -3
- data/lib/hexapdf/type/acro_form/variable_text_field.rb +13 -5
- data/lib/hexapdf/type/acro_form.rb +1 -1
- data/lib/hexapdf/type/action.rb +1 -1
- data/lib/hexapdf/type/actions/go_to.rb +2 -1
- data/lib/hexapdf/type/actions/go_to_r.rb +2 -1
- data/lib/hexapdf/type/actions/launch.rb +6 -2
- data/lib/hexapdf/type/actions/set_ocg_state.rb +1 -1
- data/lib/hexapdf/type/actions/uri.rb +1 -1
- data/lib/hexapdf/type/actions.rb +1 -1
- data/lib/hexapdf/type/annotation.rb +78 -3
- data/lib/hexapdf/type/annotations/appearance_generator.rb +426 -0
- data/lib/hexapdf/type/annotations/border_effect.rb +99 -0
- data/lib/hexapdf/type/annotations/border_styling.rb +160 -0
- data/lib/hexapdf/type/annotations/circle.rb +65 -0
- data/lib/hexapdf/type/annotations/interior_color.rb +84 -0
- data/lib/hexapdf/type/annotations/line.rb +334 -0
- data/lib/hexapdf/type/annotations/line_ending_styling.rb +208 -0
- data/lib/hexapdf/type/annotations/link.rb +1 -1
- data/lib/hexapdf/type/annotations/markup_annotation.rb +15 -3
- data/lib/hexapdf/type/annotations/polygon.rb +64 -0
- data/lib/hexapdf/type/annotations/polygon_polyline.rb +109 -0
- data/lib/hexapdf/type/annotations/polyline.rb +64 -0
- data/lib/hexapdf/type/annotations/square.rb +65 -0
- data/lib/hexapdf/type/annotations/square_circle.rb +77 -0
- data/lib/hexapdf/type/annotations/text.rb +1 -1
- data/lib/hexapdf/type/annotations/widget.rb +56 -118
- data/lib/hexapdf/type/annotations.rb +13 -1
- data/lib/hexapdf/type/catalog.rb +5 -2
- data/lib/hexapdf/type/cid_font.rb +6 -3
- data/lib/hexapdf/type/cmap.rb +58 -0
- data/lib/hexapdf/type/embedded_file.rb +1 -1
- data/lib/hexapdf/type/file_specification.rb +18 -15
- data/lib/hexapdf/type/font.rb +1 -1
- data/lib/hexapdf/type/font_descriptor.rb +5 -4
- data/lib/hexapdf/type/font_simple.rb +4 -2
- data/lib/hexapdf/type/font_true_type.rb +3 -1
- data/lib/hexapdf/type/font_type0.rb +2 -2
- data/lib/hexapdf/type/font_type1.rb +19 -1
- data/lib/hexapdf/type/font_type3.rb +1 -2
- data/lib/hexapdf/type/form.rb +8 -5
- data/lib/hexapdf/type/graphics_state_parameter.rb +8 -5
- data/lib/hexapdf/type/icon_fit.rb +1 -1
- data/lib/hexapdf/type/image.rb +9 -5
- data/lib/hexapdf/type/info.rb +3 -3
- data/lib/hexapdf/type/mark_information.rb +3 -3
- data/lib/hexapdf/type/marked_content_reference.rb +59 -0
- data/lib/hexapdf/type/measure.rb +57 -0
- data/lib/hexapdf/type/metadata.rb +1 -1
- data/lib/hexapdf/type/names.rb +1 -1
- data/lib/hexapdf/type/namespace.rb +57 -0
- data/lib/hexapdf/type/object_reference.rb +57 -0
- data/lib/hexapdf/type/object_stream.rb +1 -1
- data/lib/hexapdf/type/optional_content_configuration.rb +2 -2
- data/lib/hexapdf/type/optional_content_group.rb +1 -1
- data/lib/hexapdf/type/optional_content_membership.rb +2 -2
- data/lib/hexapdf/type/optional_content_properties.rb +1 -1
- data/lib/hexapdf/type/outline.rb +1 -1
- data/lib/hexapdf/type/outline_item.rb +1 -1
- data/lib/hexapdf/type/output_intent.rb +1 -1
- data/lib/hexapdf/type/page.rb +6 -4
- data/lib/hexapdf/type/page_label.rb +1 -1
- data/lib/hexapdf/type/page_tree_node.rb +1 -1
- data/lib/hexapdf/type/resources.rb +13 -9
- data/lib/hexapdf/type/struct_elem.rb +72 -0
- data/lib/hexapdf/type/struct_tree_root.rb +64 -0
- data/lib/hexapdf/type/trailer.rb +1 -1
- data/lib/hexapdf/type/viewer_preferences.rb +5 -4
- data/lib/hexapdf/type/xref_stream.rb +1 -1
- data/lib/hexapdf/type.rb +8 -1
- data/lib/hexapdf/utils/bit_field.rb +1 -1
- data/lib/hexapdf/utils/bit_stream.rb +1 -1
- data/lib/hexapdf/utils/graphics_helpers.rb +1 -1
- data/lib/hexapdf/utils/lru_cache.rb +1 -1
- data/lib/hexapdf/utils/math_helpers.rb +1 -1
- data/lib/hexapdf/utils/object_hash.rb +1 -1
- data/lib/hexapdf/utils/pdf_doc_encoding.rb +1 -1
- data/lib/hexapdf/utils/sorted_tree_node.rb +17 -4
- data/lib/hexapdf/utils.rb +1 -1
- data/lib/hexapdf/version.rb +2 -2
- data/lib/hexapdf/writer.rb +3 -2
- data/lib/hexapdf/xref_section.rb +25 -6
- data/lib/hexapdf.rb +1 -1
- data/test/data/standard-security-handler/bothpwd-aes-256bit-V5-R5.pdf +43 -0
- data/test/data/standard-security-handler/nopwd-aes-256bit-V5-R5.pdf +44 -0
- data/test/data/standard-security-handler/ownerpwd-aes-256bit-V5-R5.pdf +43 -0
- data/test/data/standard-security-handler/userpwd-aes-256bit-V5-R5.pdf +0 -0
- data/test/hexapdf/common_tokenizer_tests.rb +7 -7
- data/test/hexapdf/content/test_graphics_state.rb +2 -3
- data/test/hexapdf/content/test_operator.rb +4 -5
- data/test/hexapdf/digital_signature/common.rb +6 -1
- data/test/hexapdf/digital_signature/signing/test_default_handler.rb +6 -1
- data/test/hexapdf/digital_signature/signing/test_timestamp_handler.rb +12 -0
- data/test/hexapdf/digital_signature/test_cms_handler.rb +25 -15
- data/test/hexapdf/digital_signature/test_handler.rb +2 -3
- data/test/hexapdf/digital_signature/test_pkcs1_handler.rb +1 -2
- data/test/hexapdf/digital_signature/test_signature.rb +7 -0
- data/test/hexapdf/digital_signature/test_signatures.rb +12 -7
- data/test/hexapdf/document/test_annotations.rb +75 -0
- data/test/hexapdf/document/test_layout.rb +38 -10
- data/test/hexapdf/document/test_metadata.rb +13 -1
- data/test/hexapdf/encryption/common.rb +1 -1
- data/test/hexapdf/encryption/test_aes.rb +1 -1
- data/test/hexapdf/encryption/test_arc4.rb +2 -2
- data/test/hexapdf/encryption/test_security_handler.rb +8 -6
- data/test/hexapdf/encryption/test_standard_security_handler.rb +7 -3
- data/test/hexapdf/filter/test_ascii85_decode.rb +1 -1
- data/test/hexapdf/filter/test_ascii_hex_decode.rb +1 -1
- data/test/hexapdf/filter/test_flate_decode.rb +2 -3
- data/test/hexapdf/font/cmap/test_writer.rb +73 -16
- data/test/hexapdf/font/encoding/test_base.rb +20 -0
- data/test/hexapdf/font/encoding/test_glyph_list.rb +1 -1
- data/test/hexapdf/font/test_true_type_wrapper.rb +31 -5
- data/test/hexapdf/font/test_type1_wrapper.rb +8 -1
- data/test/hexapdf/font/true_type/test_table.rb +12 -0
- data/test/hexapdf/layout/test_box.rb +8 -2
- data/test/hexapdf/layout/test_container_box.rb +34 -6
- data/test/hexapdf/layout/test_list_box.rb +7 -7
- data/test/hexapdf/layout/test_page_style.rb +1 -1
- data/test/hexapdf/layout/test_style.rb +46 -12
- data/test/hexapdf/layout/test_table_box.rb +66 -16
- data/test/hexapdf/layout/test_text_box.rb +0 -6
- data/test/hexapdf/layout/test_text_fragment.rb +3 -3
- data/test/hexapdf/layout/test_text_layouter.rb +4 -2
- data/test/hexapdf/task/test_merge_acro_form.rb +104 -0
- data/test/hexapdf/task/test_optimize.rb +3 -1
- data/test/hexapdf/test_composer.rb +15 -0
- data/test/hexapdf/test_dictionary.rb +15 -0
- data/test/hexapdf/test_dictionary_fields.rb +1 -0
- data/test/hexapdf/test_document.rb +26 -8
- data/test/hexapdf/test_filter.rb +1 -1
- data/test/hexapdf/test_importer.rb +7 -0
- data/test/hexapdf/test_object.rb +1 -1
- data/test/hexapdf/test_parser.rb +87 -18
- data/test/hexapdf/test_pdf_array.rb +36 -3
- data/test/hexapdf/test_revision.rb +27 -6
- data/test/hexapdf/test_revisions.rb +1 -1
- data/test/hexapdf/test_serializer.rb +4 -4
- data/test/hexapdf/test_stream.rb +1 -2
- data/test/hexapdf/test_tokenizer.rb +1 -1
- data/test/hexapdf/test_writer.rb +22 -8
- data/test/hexapdf/test_xref_section.rb +15 -0
- data/test/hexapdf/type/acro_form/test_appearance_generator.rb +118 -26
- data/test/hexapdf/type/acro_form/test_button_field.rb +7 -6
- data/test/hexapdf/type/acro_form/test_field.rb +10 -0
- data/test/hexapdf/type/acro_form/test_form.rb +32 -9
- data/test/hexapdf/type/acro_form/test_java_script_actions.rb +21 -0
- data/test/hexapdf/type/acro_form/test_signature_field.rb +3 -1
- data/test/hexapdf/type/acro_form/test_text_field.rb +7 -1
- data/test/hexapdf/type/acro_form/test_variable_text_field.rb +14 -1
- data/test/hexapdf/type/actions/test_launch.rb +6 -2
- data/test/hexapdf/type/annotations/test_appearance_generator.rb +608 -0
- data/test/hexapdf/type/annotations/test_border_effect.rb +59 -0
- data/test/hexapdf/type/annotations/test_border_styling.rb +114 -0
- data/test/hexapdf/type/annotations/test_interior_color.rb +37 -0
- data/test/hexapdf/type/annotations/test_line.rb +144 -0
- data/test/hexapdf/type/annotations/test_line_ending_styling.rb +42 -0
- data/test/hexapdf/type/annotations/test_polygon_polyline.rb +29 -0
- data/test/hexapdf/type/annotations/test_widget.rb +47 -81
- data/test/hexapdf/type/test_annotation.rb +58 -0
- data/test/hexapdf/type/test_font_type1.rb +20 -1
- data/test/hexapdf/type/test_form.rb +7 -1
- data/test/hexapdf/type/test_image.rb +1 -1
- data/test/hexapdf/type/test_page.rb +7 -1
- data/test/hexapdf/type/test_page_tree_node.rb +2 -2
- data/test/hexapdf/type/test_resources.rb +3 -1
- data/test/hexapdf/utils/test_sorted_tree_node.rb +18 -7
- data/test/test_helper.rb +7 -0
- metadata +69 -9
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
require 'hexapdf/document'
|
|
5
|
+
|
|
6
|
+
describe HexaPDF::Type::Annotations::AppearanceGenerator do
|
|
7
|
+
before do
|
|
8
|
+
@doc = HexaPDF::Document.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "create" do
|
|
12
|
+
it "fails for unsupported annotation types" do
|
|
13
|
+
annot = @doc.add({Type: :Annot, Subtype: :Unknown})
|
|
14
|
+
error = assert_raises(HexaPDF::Error) do
|
|
15
|
+
HexaPDF::Type::Annotations::AppearanceGenerator.new(annot).create_appearance
|
|
16
|
+
end
|
|
17
|
+
assert_match(/Unknown.*not yet supported/, error.message)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "line" do
|
|
22
|
+
before do
|
|
23
|
+
@line = @doc.add({Type: :Annot, Subtype: :Line, L: [100, 100, 200, 100], C: [0]})
|
|
24
|
+
@generator = HexaPDF::Type::Annotations::AppearanceGenerator.new(@line)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "sets the print flag and unsets the hidden flag" do
|
|
28
|
+
@line.flag(:hidden)
|
|
29
|
+
@generator.create_appearance
|
|
30
|
+
assert(@line.flagged?(:print))
|
|
31
|
+
refute(@line.flagged?(:hidden))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "creates a simple line" do
|
|
35
|
+
@generator.create_appearance
|
|
36
|
+
assert_equal([96, 96, 204, 104], @line[:Rect])
|
|
37
|
+
assert_equal([96, 96, 204, 104], @line.appearance[:BBox])
|
|
38
|
+
assert_operators(@line.appearance.stream,
|
|
39
|
+
[[:concatenate_matrix, [1.0, 0.0, -0.0, 1.0, 100, 100]],
|
|
40
|
+
[:move_to, [0, 0]],
|
|
41
|
+
[:line_to, [100.0, 0]],
|
|
42
|
+
[:stroke_path]])
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "creates a rotated line" do
|
|
46
|
+
@line.line(100, 100, 50, 150)
|
|
47
|
+
@generator.create_appearance
|
|
48
|
+
assert_equal([46, 96, 104, 154], @line[:Rect])
|
|
49
|
+
assert_operators(@line.appearance.stream,
|
|
50
|
+
[[:concatenate_matrix, [-0.707107, 0.707107, -0.707107, -0.707107, 100, 100]],
|
|
51
|
+
[:move_to, [0, 0]],
|
|
52
|
+
[:line_to, [70.710678, 0]],
|
|
53
|
+
[:stroke_path]])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "stroke color" do
|
|
57
|
+
it "uses the specified border color for stroking operations" do
|
|
58
|
+
@line.border_style(color: "red")
|
|
59
|
+
@generator.create_appearance
|
|
60
|
+
assert_operators(@line.appearance.stream,
|
|
61
|
+
[:set_device_rgb_stroking_color, [1, 0, 0]], range: 0)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "works with a transparent border" do
|
|
65
|
+
@line.border_style(color: :transparent, width: 1)
|
|
66
|
+
@generator.create_appearance
|
|
67
|
+
assert_operators(@line.appearance.stream, [:end_path], range: 3)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "uses the specified interior color for non-stroking operations" do
|
|
72
|
+
@line.interior_color("red")
|
|
73
|
+
@generator.create_appearance
|
|
74
|
+
assert_operators(@line.appearance.stream,
|
|
75
|
+
[:set_device_rgb_non_stroking_color, [1, 0, 0]], range: 0)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "sets the specified border line width" do
|
|
79
|
+
@line.border_style(width: 2)
|
|
80
|
+
@generator.create_appearance
|
|
81
|
+
assert_operators(@line.appearance.stream,
|
|
82
|
+
[:set_line_width, [2]], range: 0)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "sets the specified line dash pattern if it is an array" do
|
|
86
|
+
@line.border_style(style: [5, 2])
|
|
87
|
+
@generator.create_appearance
|
|
88
|
+
assert_operators(@line.appearance.stream,
|
|
89
|
+
[:set_line_dash_pattern, [[5, 2], 0]], range: 0)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
describe "leader lines" do
|
|
93
|
+
it "works for positive leader line length values" do
|
|
94
|
+
@line.leader_line_length(10)
|
|
95
|
+
@generator.create_appearance
|
|
96
|
+
assert_operators(@line.appearance.stream,
|
|
97
|
+
[[:concatenate_matrix, [1.0, 0.0, -0.0, 1.0, 100, 100]],
|
|
98
|
+
[:move_to, [0, 0]],
|
|
99
|
+
[:line_to, [0, 10]],
|
|
100
|
+
[:move_to, [100, 0]],
|
|
101
|
+
[:line_to, [100, 10]],
|
|
102
|
+
[:move_to, [0, 10]],
|
|
103
|
+
[:line_to, [100.0, 10]],
|
|
104
|
+
[:stroke_path]])
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "works for negative leader line length values" do
|
|
108
|
+
@line.leader_line_length(-10)
|
|
109
|
+
@generator.create_appearance
|
|
110
|
+
assert_operators(@line.appearance.stream,
|
|
111
|
+
[[:concatenate_matrix, [1.0, 0.0, -0.0, 1.0, 100, 100]],
|
|
112
|
+
[:move_to, [0, 0]],
|
|
113
|
+
[:line_to, [0, -10]],
|
|
114
|
+
[:move_to, [100, 0]],
|
|
115
|
+
[:line_to, [100, -10]],
|
|
116
|
+
[:move_to, [0, -10]],
|
|
117
|
+
[:line_to, [100.0, -10]],
|
|
118
|
+
[:stroke_path]])
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "works when using an offset and a positive leader line length" do
|
|
122
|
+
@line.leader_line_length(10)
|
|
123
|
+
@line.leader_line_offset(5)
|
|
124
|
+
@generator.create_appearance
|
|
125
|
+
assert_operators(@line.appearance.stream,
|
|
126
|
+
[[:concatenate_matrix, [1.0, 0.0, -0.0, 1.0, 100, 100]],
|
|
127
|
+
[:move_to, [0, 5]],
|
|
128
|
+
[:line_to, [0, 15]],
|
|
129
|
+
[:move_to, [100, 5]],
|
|
130
|
+
[:line_to, [100, 15]],
|
|
131
|
+
[:move_to, [0, 15]],
|
|
132
|
+
[:line_to, [100.0, 15]],
|
|
133
|
+
[:stroke_path]])
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "works when using an offset and a negative leader line length" do
|
|
137
|
+
@line.leader_line_length(-10)
|
|
138
|
+
@line.leader_line_offset(5)
|
|
139
|
+
@generator.create_appearance
|
|
140
|
+
assert_operators(@line.appearance.stream,
|
|
141
|
+
[[:concatenate_matrix, [1.0, 0.0, -0.0, 1.0, 100, 100]],
|
|
142
|
+
[:move_to, [0, -5]],
|
|
143
|
+
[:line_to, [0, -15]],
|
|
144
|
+
[:move_to, [100, -5]],
|
|
145
|
+
[:line_to, [100, -15]],
|
|
146
|
+
[:move_to, [0, -15]],
|
|
147
|
+
[:line_to, [100.0, -15]],
|
|
148
|
+
[:stroke_path]])
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "works when using leader line extensions" do
|
|
152
|
+
@line.leader_line_length(10)
|
|
153
|
+
@line.leader_line_extension_length(5)
|
|
154
|
+
@generator.create_appearance
|
|
155
|
+
assert_operators(@line.appearance.stream,
|
|
156
|
+
[[:concatenate_matrix, [1.0, 0.0, -0.0, 1.0, 100, 100]],
|
|
157
|
+
[:move_to, [0, 0]],
|
|
158
|
+
[:line_to, [0, 15]],
|
|
159
|
+
[:move_to, [100, 0]],
|
|
160
|
+
[:line_to, [100, 15]],
|
|
161
|
+
[:move_to, [0, 10]],
|
|
162
|
+
[:line_to, [100.0, 10]],
|
|
163
|
+
[:stroke_path]])
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
describe "line ending styles" do
|
|
168
|
+
before do
|
|
169
|
+
@line.border_style(width: 2)
|
|
170
|
+
@line.interior_color("red")
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it "works correctly for a transparent border" do
|
|
174
|
+
@line.line_ending_style(start_style: :square, end_style: :square)
|
|
175
|
+
@line.border_style(color: :transparent)
|
|
176
|
+
@generator.create_appearance
|
|
177
|
+
assert_operators(@line.appearance.stream,
|
|
178
|
+
[[:append_rectangle, [-3, -3, 6, 6]],
|
|
179
|
+
[:fill_path_non_zero],
|
|
180
|
+
[:append_rectangle, [97, -3, 6, 6]],
|
|
181
|
+
[:fill_path_non_zero]], range: 5..-1)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it "works for a square" do
|
|
185
|
+
@line.line_ending_style(start_style: :square, end_style: :square)
|
|
186
|
+
@generator.create_appearance
|
|
187
|
+
assert_operators(@line.appearance.stream,
|
|
188
|
+
[[:append_rectangle, [-6, -6, 12, 12]],
|
|
189
|
+
[:fill_and_stroke_path_non_zero],
|
|
190
|
+
[:append_rectangle, [94, -6, 12, 12]],
|
|
191
|
+
[:fill_and_stroke_path_non_zero]], range: 6..-1)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
it "works for a circle" do
|
|
195
|
+
@line.line_ending_style(start_style: :circle, end_style: :circle)
|
|
196
|
+
@generator.create_appearance
|
|
197
|
+
assert_operators(@line.appearance.stream,
|
|
198
|
+
[[:move_to, [6.0, 0.0]],
|
|
199
|
+
[:curve_to, [6.0, 2.140933, 4.854102, 4.125686, 3.0, 5.196152]],
|
|
200
|
+
[:curve_to, [1.145898, 6.266619, -1.145898, 6.266619, -3.0, 5.196152]],
|
|
201
|
+
[:curve_to, [-4.854102, 4.125686, -6.0, 2.140933, -6.0, 0.0]],
|
|
202
|
+
[:curve_to, [-6.0, -2.140933, -4.854102, -4.125686, -3.0, -5.196152]],
|
|
203
|
+
[:curve_to, [-1.145898, -6.266619, 1.145898, -6.266619, 3.0, -5.196152]],
|
|
204
|
+
[:curve_to, [4.854102, -4.125686, 6.0, -2.140933, 6.0, -0.0]],
|
|
205
|
+
[:close_subpath],
|
|
206
|
+
[:fill_and_stroke_path_non_zero],
|
|
207
|
+
[:move_to, [106.0, 0.0]],
|
|
208
|
+
[:curve_to, [106.0, 2.140933, 104.854102, 4.125686, 103.0, 5.196152]],
|
|
209
|
+
[:curve_to, [101.145898, 6.266619, 98.854102, 6.266619, 97.0, 5.196152]],
|
|
210
|
+
[:curve_to, [95.145898, 4.125686, 94.0, 2.140933, 94.0, 0.0]],
|
|
211
|
+
[:curve_to, [94.0, -2.140933, 95.145898, -4.125686, 97.0, -5.196152]],
|
|
212
|
+
[:curve_to, [98.854102, -6.266619, 101.145898, -6.266619, 103.0, -5.196152]],
|
|
213
|
+
[:curve_to, [104.854102, -4.125686, 106.0, -2.140933, 106.0, -0.0]],
|
|
214
|
+
[:close_subpath],
|
|
215
|
+
[:fill_and_stroke_path_non_zero]], range: 6..-1)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
it "works for a diamond" do
|
|
219
|
+
@line.line_ending_style(start_style: :diamond, end_style: :diamond)
|
|
220
|
+
@generator.create_appearance
|
|
221
|
+
assert_operators(@line.appearance.stream,
|
|
222
|
+
[[:move_to, [6, 0]],
|
|
223
|
+
[:line_to, [0, 6]],
|
|
224
|
+
[:line_to, [-6, 0]],
|
|
225
|
+
[:line_to, [0, -6]],
|
|
226
|
+
[:close_subpath],
|
|
227
|
+
[:fill_and_stroke_path_non_zero],
|
|
228
|
+
[:move_to, [106.0, 0]],
|
|
229
|
+
[:line_to, [100.0, 6]],
|
|
230
|
+
[:line_to, [94.0, 0]],
|
|
231
|
+
[:line_to, [100.0, -6]],
|
|
232
|
+
[:close_subpath],
|
|
233
|
+
[:fill_and_stroke_path_non_zero]], range: 6..-1)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
it "works for open and closed as well as reversed open and closed arrows" do
|
|
237
|
+
dx = 15.588457
|
|
238
|
+
[:open_arrow, :closed_arrow, :ropen_arrow, :rclosed_arrow].each do |style|
|
|
239
|
+
@line.line_ending_style(start_style: style, end_style: style)
|
|
240
|
+
@generator.create_appearance
|
|
241
|
+
used_dx = (style == :ropen_arrow || style == :rclosed_arrow ? -dx : dx)
|
|
242
|
+
ops = [[:move_to, [used_dx, 9.0]],
|
|
243
|
+
[:line_to, [0, 0]],
|
|
244
|
+
[:line_to, [used_dx, -9.0]],
|
|
245
|
+
[:move_to, [100 - used_dx, -9.0]],
|
|
246
|
+
[:line_to, [100.0, 0]],
|
|
247
|
+
[:line_to, [100 - used_dx, 9.0]]]
|
|
248
|
+
if style == :closed_arrow || style == :rclosed_arrow
|
|
249
|
+
ops.insert(3, [:close_subpath], [:fill_and_stroke_path_non_zero])
|
|
250
|
+
ops.insert(-1, [:close_subpath], [:fill_and_stroke_path_non_zero])
|
|
251
|
+
else
|
|
252
|
+
ops.insert(3, [:stroke_path])
|
|
253
|
+
ops.insert(-1, [:stroke_path])
|
|
254
|
+
end
|
|
255
|
+
assert_operators(@line.appearance.stream, ops, range: 6..-1)
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it "works for butt" do
|
|
260
|
+
@line.line_ending_style(start_style: :butt, end_style: :butt)
|
|
261
|
+
@generator.create_appearance
|
|
262
|
+
assert_operators(@line.appearance.stream,
|
|
263
|
+
[[:move_to, [0, 6]],
|
|
264
|
+
[:line_to, [0, -6]],
|
|
265
|
+
[:stroke_path],
|
|
266
|
+
[:move_to, [100.0, 6]],
|
|
267
|
+
[:line_to, [100.0, -6]],
|
|
268
|
+
[:stroke_path]], range: 6..-1)
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
it "works for slash" do
|
|
272
|
+
@line.line_ending_style(start_style: :slash, end_style: :slash)
|
|
273
|
+
@generator.create_appearance
|
|
274
|
+
assert_operators(@line.appearance.stream,
|
|
275
|
+
[[:move_to, [3, 5.196152]],
|
|
276
|
+
[:line_to, [-3, -5.196152]],
|
|
277
|
+
[:stroke_path],
|
|
278
|
+
[:move_to, [103.0, 5.196152]],
|
|
279
|
+
[:line_to, [97.0, -5.196152]],
|
|
280
|
+
[:stroke_path]], range: 6..-1)
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
describe "caption" do
|
|
285
|
+
before do
|
|
286
|
+
@line.captioned(true)
|
|
287
|
+
@line.contents("Test")
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
it "adjusts the annotation's /Rect entry" do
|
|
291
|
+
@line.contents("This is some eeeeextra long text")
|
|
292
|
+
@generator.create_appearance
|
|
293
|
+
assert_equal([80.2225, 91.83749999999999, 219.7775, 108.1625], @line[:Rect])
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
it "puts the caption inline" do
|
|
297
|
+
@generator.create_appearance
|
|
298
|
+
assert_operators(@line.appearance.stream,
|
|
299
|
+
[[:move_to, [0, 0]],
|
|
300
|
+
[:line_to, [40.2475, 0]],
|
|
301
|
+
[:move_to, [59.7525, 0]],
|
|
302
|
+
[:line_to, [100, 0]],
|
|
303
|
+
[:stroke_path],
|
|
304
|
+
[:save_graphics_state],
|
|
305
|
+
[:set_font_and_size, [:F1, 9]],
|
|
306
|
+
[:begin_text],
|
|
307
|
+
[:move_text, [41.2475, -2.2995]],
|
|
308
|
+
[:show_text, ["Test"]],
|
|
309
|
+
[:end_text]], range: 1..-2)
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
it "puts the caption inline with an offset" do
|
|
313
|
+
@line.caption_offset(20, 5)
|
|
314
|
+
@generator.create_appearance
|
|
315
|
+
assert_operators(@line.appearance.stream,
|
|
316
|
+
[[:move_to, [0, 0]],
|
|
317
|
+
[:line_to, [60.2475, 0]],
|
|
318
|
+
[:move_to, [79.7525, 0]],
|
|
319
|
+
[:line_to, [100, 0]],
|
|
320
|
+
[:stroke_path],
|
|
321
|
+
[:save_graphics_state],
|
|
322
|
+
[:set_font_and_size, [:F1, 9]],
|
|
323
|
+
[:begin_text],
|
|
324
|
+
[:move_text, [61.2475, 2.7005]],
|
|
325
|
+
[:show_text, ["Test"]],
|
|
326
|
+
[:end_text]], range: 1..-2)
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
it "handles too long inline captions" do
|
|
330
|
+
@line.contents('This inline text is so long that no line is shown')
|
|
331
|
+
@generator.create_appearance
|
|
332
|
+
assert_operators(@line.appearance.stream,
|
|
333
|
+
[[:move_to, [0, 0]],
|
|
334
|
+
[:line_to, [0, 0]],
|
|
335
|
+
[:move_to, [100, 0]],
|
|
336
|
+
[:line_to, [100, 0]],
|
|
337
|
+
[:stroke_path],
|
|
338
|
+
[:save_graphics_state],
|
|
339
|
+
[:set_font_and_size, [:F1, 9]],
|
|
340
|
+
[:begin_text],
|
|
341
|
+
[:move_text, [-41.0395, -2.2995]],
|
|
342
|
+
[:show_text, ["This inline text is so long that no line is shown"]],
|
|
343
|
+
[:end_text]], range: 1..-2)
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
it "puts the caption on top of the line" do
|
|
347
|
+
@line.caption_position(:top)
|
|
348
|
+
@generator.create_appearance
|
|
349
|
+
assert_operators(@line.appearance.stream,
|
|
350
|
+
[[:move_to, [0, 0]],
|
|
351
|
+
[:line_to, [100, 0]],
|
|
352
|
+
[:stroke_path],
|
|
353
|
+
[:save_graphics_state],
|
|
354
|
+
[:set_font_and_size, [:F1, 9]],
|
|
355
|
+
[:begin_text],
|
|
356
|
+
[:move_text, [41.2475, 3.863]],
|
|
357
|
+
[:show_text, ["Test"]],
|
|
358
|
+
[:end_text]], range: 1..-2)
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
it "puts the caption on top of the line" do
|
|
362
|
+
@line.caption_position(:top)
|
|
363
|
+
@line.caption_offset(-20, -5)
|
|
364
|
+
@generator.create_appearance
|
|
365
|
+
assert_operators(@line.appearance.stream,
|
|
366
|
+
[[:move_to, [0, 0]],
|
|
367
|
+
[:line_to, [100, 0]],
|
|
368
|
+
[:stroke_path],
|
|
369
|
+
[:save_graphics_state],
|
|
370
|
+
[:set_font_and_size, [:F1, 9]],
|
|
371
|
+
[:begin_text],
|
|
372
|
+
[:move_text, [21.2475, -1.137]],
|
|
373
|
+
[:show_text, ["Test"]],
|
|
374
|
+
[:end_text]], range: 1..-2)
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
it "handles text with line breaks" do
|
|
378
|
+
@line.contents("This inline text\ris long")
|
|
379
|
+
@generator.create_appearance
|
|
380
|
+
assert_operators(@line.appearance.stream,
|
|
381
|
+
[[:move_to, [0, 0]],
|
|
382
|
+
[:line_to, [20.2405, 0]],
|
|
383
|
+
[:move_to, [79.7595, 0]],
|
|
384
|
+
[:line_to, [100, 0]],
|
|
385
|
+
[:stroke_path],
|
|
386
|
+
[:save_graphics_state],
|
|
387
|
+
[:set_leading, [10.40625]],
|
|
388
|
+
[:set_font_and_size, [:F1, 9]],
|
|
389
|
+
[:begin_text],
|
|
390
|
+
[:move_text, [21.2405, 2.903625]],
|
|
391
|
+
[:show_text, ["This inline text"]],
|
|
392
|
+
[:move_text_next_line],
|
|
393
|
+
[:show_text, ["is long"]],
|
|
394
|
+
[:end_text]], range: 1..-2)
|
|
395
|
+
end
|
|
396
|
+
end
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
describe "square/circle" do
|
|
400
|
+
before do
|
|
401
|
+
@square = @doc.add({Type: :Annot, Subtype: :Square, Rect: [100, 100, 200, 150], C: [0],
|
|
402
|
+
BS: {W: 2}})
|
|
403
|
+
@generator = HexaPDF::Type::Annotations::AppearanceGenerator.new(@square)
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
it "sets the print flag and unsets the hidden flag" do
|
|
407
|
+
@square.flag(:hidden)
|
|
408
|
+
@generator.create_appearance
|
|
409
|
+
assert(@square.flagged?(:print))
|
|
410
|
+
refute(@square.flagged?(:hidden))
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
it "creates the /RD entry if it doesn't exist and adjusts the /Rect" do
|
|
414
|
+
@generator.create_appearance
|
|
415
|
+
assert_equal([99, 99, 201, 151], @square[:Rect])
|
|
416
|
+
assert_equal([0, 0, 102, 52], @square.appearance[:BBox])
|
|
417
|
+
assert_operators(@square.appearance.stream,
|
|
418
|
+
[[:set_line_width, [2]],
|
|
419
|
+
[:append_rectangle, [1, 1, 100, 50]],
|
|
420
|
+
[:stroke_path]])
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
it "uses an existing /RD entry" do
|
|
424
|
+
@square[:RD] = [2, 4, 6, 8]
|
|
425
|
+
@generator.create_appearance
|
|
426
|
+
assert_equal([100, 100, 200, 150], @square[:Rect])
|
|
427
|
+
assert_equal([0, 0, 100, 50], @square.appearance[:BBox])
|
|
428
|
+
assert_operators(@square.appearance.stream,
|
|
429
|
+
[[:set_line_width, [2]],
|
|
430
|
+
[:append_rectangle, [3, 9, 90, 36]],
|
|
431
|
+
[:stroke_path]])
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
it "can apply just a fill color without a stroke color" do
|
|
435
|
+
@square.delete(:C)
|
|
436
|
+
@square.interior_color(255, 0, 0)
|
|
437
|
+
@generator.create_appearance
|
|
438
|
+
assert_operators(@square.appearance.stream,
|
|
439
|
+
[[:set_device_rgb_non_stroking_color, [1, 0, 0]],
|
|
440
|
+
[:set_line_width, [2]],
|
|
441
|
+
[:append_rectangle, [1, 1, 100, 50]],
|
|
442
|
+
[:fill_path_non_zero]])
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
it "applies all set styling options" do
|
|
446
|
+
@square.border_style(color: [255, 0, 0], width: 10, style: [2, 1])
|
|
447
|
+
@square.interior_color(0, 255, 0)
|
|
448
|
+
@square.opacity(fill_alpha: 0.5, stroke_alpha: 0.5)
|
|
449
|
+
@generator.create_appearance
|
|
450
|
+
assert_operators(@square.appearance.stream,
|
|
451
|
+
[[:set_graphics_state_parameters, [:GS1]],
|
|
452
|
+
[:set_device_rgb_stroking_color, [1, 0, 0]],
|
|
453
|
+
[:set_device_rgb_non_stroking_color, [0, 1, 0]],
|
|
454
|
+
[:set_line_width, [10]],
|
|
455
|
+
[:set_line_dash_pattern, [[2, 1], 0]],
|
|
456
|
+
[:append_rectangle, [5, 5, 100, 50]],
|
|
457
|
+
[:fill_and_stroke_path_non_zero]])
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
it "doesn't draw anything if neither stroke nor fill color is set" do
|
|
461
|
+
@square.delete(:C)
|
|
462
|
+
@generator.create_appearance
|
|
463
|
+
assert_operators(@square.appearance.stream, [])
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
it "draws an ellipse" do
|
|
467
|
+
@square[:Subtype] = :Circle
|
|
468
|
+
@generator.create_appearance
|
|
469
|
+
assert_operators(@square.appearance.stream,
|
|
470
|
+
[[:set_line_width, [2]],
|
|
471
|
+
[:move_to, [101.0, 26.0]],
|
|
472
|
+
[:curve_to, [101.0, 34.920552, 91.45085, 43.190359, 76.0, 47.650635]],
|
|
473
|
+
[:curve_to, [60.54915, 52.110911, 41.45085, 52.110911, 26.0, 47.650635]],
|
|
474
|
+
[:curve_to, [10.54915, 43.190359, 1.0, 34.920552, 1.0, 26.0]],
|
|
475
|
+
[:curve_to, [1.0, 17.079448, 10.54915, 8.809641, 26.0, 4.349365]],
|
|
476
|
+
[:curve_to, [41.45085, -0.110911, 60.54915, -0.110911, 76.0, 4.349365]],
|
|
477
|
+
[:curve_to, [91.45085, 8.809641, 101.0, 17.079448, 101.0, 26.0]],
|
|
478
|
+
[:close_subpath],
|
|
479
|
+
[:stroke_path]])
|
|
480
|
+
end
|
|
481
|
+
end
|
|
482
|
+
|
|
483
|
+
describe "polygon/polyline" do
|
|
484
|
+
before do
|
|
485
|
+
@polyline = @doc.add({Type: :Annot, Subtype: :PolyLine, C: [0],
|
|
486
|
+
Vertices: [100, 100, 200, 150, 210, 80]})
|
|
487
|
+
@generator = HexaPDF::Type::Annotations::AppearanceGenerator.new(@polyline)
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
it "sets the print flag and unsets the hidden flag" do
|
|
491
|
+
@polyline.flag(:hidden)
|
|
492
|
+
@generator.create_appearance
|
|
493
|
+
assert(@polyline.flagged?(:print))
|
|
494
|
+
refute(@polyline.flagged?(:hidden))
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
it "creates a simple polyline" do
|
|
498
|
+
@generator.create_appearance
|
|
499
|
+
assert_equal([96, 76, 214, 154], @polyline[:Rect])
|
|
500
|
+
assert_equal([96, 76, 214, 154], @polyline.appearance[:BBox])
|
|
501
|
+
assert_operators(@polyline.appearance.stream,
|
|
502
|
+
[[:move_to, [100, 100]],
|
|
503
|
+
[:line_to, [200, 150]],
|
|
504
|
+
[:line_to, [210, 80]],
|
|
505
|
+
[:stroke_path]])
|
|
506
|
+
end
|
|
507
|
+
|
|
508
|
+
it "creates a simple polygon" do
|
|
509
|
+
@polyline[:Subtype] = :Polygon
|
|
510
|
+
@generator.create_appearance
|
|
511
|
+
assert_operators(@polyline.appearance.stream,
|
|
512
|
+
[[:move_to, [100, 100]],
|
|
513
|
+
[:line_to, [200, 150]],
|
|
514
|
+
[:line_to, [210, 80]],
|
|
515
|
+
[:close_subpath],
|
|
516
|
+
[:stroke_path]])
|
|
517
|
+
end
|
|
518
|
+
|
|
519
|
+
describe "stroke color" do
|
|
520
|
+
it "uses the specified border color for stroking operations" do
|
|
521
|
+
@polyline.border_style(color: "red")
|
|
522
|
+
@generator.create_appearance
|
|
523
|
+
assert_operators(@polyline.appearance.stream,
|
|
524
|
+
[:set_device_rgb_stroking_color, [1, 0, 0]], range: 0)
|
|
525
|
+
assert_operators(@polyline.appearance.stream,
|
|
526
|
+
[:stroke_path], range: 4)
|
|
527
|
+
end
|
|
528
|
+
|
|
529
|
+
it "works with a transparent border" do
|
|
530
|
+
@polyline.border_style(color: :transparent)
|
|
531
|
+
@generator.create_appearance
|
|
532
|
+
assert_operators(@polyline.appearance.stream, [:end_path], range: 3)
|
|
533
|
+
end
|
|
534
|
+
end
|
|
535
|
+
|
|
536
|
+
describe "interior color" do
|
|
537
|
+
it "uses the specified interior color for non-stroking operations" do
|
|
538
|
+
@polyline[:Subtype] = :Polygon
|
|
539
|
+
@polyline.border_style(color: :transparent)
|
|
540
|
+
@polyline.interior_color("red")
|
|
541
|
+
@generator.create_appearance
|
|
542
|
+
assert_operators(@polyline.appearance.stream,
|
|
543
|
+
[:set_device_rgb_non_stroking_color, [1, 0, 0]], range: 0)
|
|
544
|
+
assert_operators(@polyline.appearance.stream,
|
|
545
|
+
[:fill_path_non_zero], range: 5)
|
|
546
|
+
end
|
|
547
|
+
|
|
548
|
+
it "works together with the stroke color" do
|
|
549
|
+
@polyline[:Subtype] = :Polygon
|
|
550
|
+
@polyline.interior_color("red")
|
|
551
|
+
@generator.create_appearance
|
|
552
|
+
assert_operators(@polyline.appearance.stream,
|
|
553
|
+
[:set_device_rgb_non_stroking_color, [1, 0, 0]], range: 0)
|
|
554
|
+
assert_operators(@polyline.appearance.stream,
|
|
555
|
+
[:fill_and_stroke_path_non_zero], range: 5)
|
|
556
|
+
end
|
|
557
|
+
|
|
558
|
+
it "works if neither interior nor border color is used" do
|
|
559
|
+
@polyline[:Subtype] = :Polygon
|
|
560
|
+
@polyline.interior_color(:transparent)
|
|
561
|
+
@polyline.border_style(color: :transparent)
|
|
562
|
+
@generator.create_appearance
|
|
563
|
+
assert_operators(@polyline.appearance.stream,
|
|
564
|
+
[:end_path], range: 4)
|
|
565
|
+
end
|
|
566
|
+
end
|
|
567
|
+
|
|
568
|
+
it "sets the specified border line width" do
|
|
569
|
+
@polyline.border_style(width: 4)
|
|
570
|
+
@generator.create_appearance
|
|
571
|
+
assert_operators(@polyline.appearance.stream,
|
|
572
|
+
[:set_line_width, [4]], range: 0)
|
|
573
|
+
end
|
|
574
|
+
|
|
575
|
+
it "sets the specified line dash pattern if it is an array" do
|
|
576
|
+
@polyline.border_style(style: [5, 2])
|
|
577
|
+
@generator.create_appearance
|
|
578
|
+
assert_operators(@polyline.appearance.stream,
|
|
579
|
+
[:set_line_dash_pattern, [[5, 2], 0]], range: 0)
|
|
580
|
+
end
|
|
581
|
+
|
|
582
|
+
it "sets the specified opacity" do
|
|
583
|
+
@polyline.opacity(fill_alpha: 0.5, stroke_alpha: 0.5)
|
|
584
|
+
@generator.create_appearance
|
|
585
|
+
assert_operators(@polyline.appearance.stream,
|
|
586
|
+
[:set_graphics_state_parameters, [:GS1]], range: 0)
|
|
587
|
+
end
|
|
588
|
+
|
|
589
|
+
it "draws the specified line ending style" do
|
|
590
|
+
@polyline.line_ending_style(start_style: :open_arrow, end_style: :rclosed_arrow)
|
|
591
|
+
@polyline.border_style(width: 2)
|
|
592
|
+
@polyline.interior_color("red")
|
|
593
|
+
@generator.create_appearance
|
|
594
|
+
assert_equal([86, 52, 238, 158], @polyline[:Rect])
|
|
595
|
+
assert_equal([86, 52, 238, 158], @polyline.appearance[:BBox])
|
|
596
|
+
assert_operators(@polyline.appearance.stream,
|
|
597
|
+
[[:move_to, [109.917818, 115.021215]],
|
|
598
|
+
[:line_to, [100, 100]],
|
|
599
|
+
[:line_to, [117.967662, 98.921525]],
|
|
600
|
+
[:stroke_path],
|
|
601
|
+
[:move_to, [221.114086, 94.158993]],
|
|
602
|
+
[:line_to, [210, 80]],
|
|
603
|
+
[:line_to, [203.294995, 96.704578]],
|
|
604
|
+
[:close_subpath],
|
|
605
|
+
[:fill_and_stroke_path_non_zero]], range: 6..-1)
|
|
606
|
+
end
|
|
607
|
+
end
|
|
608
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
require 'hexapdf/document'
|
|
5
|
+
require 'hexapdf/type/annotations/border_effect'
|
|
6
|
+
|
|
7
|
+
describe HexaPDF::Type::Annotations::BorderEffect do
|
|
8
|
+
class TestAnnot < HexaPDF::Type::Annotation
|
|
9
|
+
define_field :BE, type: :XXBorderEffect
|
|
10
|
+
include HexaPDF::Type::Annotations::BorderEffect
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
before do
|
|
14
|
+
@doc = HexaPDF::Document.new
|
|
15
|
+
@annot = @doc.wrap({Type: :Annot}, type: TestAnnot)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "border_effect" do
|
|
19
|
+
it "returns :none if no border effect is set" do
|
|
20
|
+
assert_equal(:none, @annot.border_effect)
|
|
21
|
+
@annot[:BE] = {}
|
|
22
|
+
assert_equal(:none, @annot.border_effect)
|
|
23
|
+
@annot[:BE] = {S: :S}
|
|
24
|
+
assert_equal(:none, @annot.border_effect)
|
|
25
|
+
@annot[:BE] = {S: :K}
|
|
26
|
+
assert_equal(:none, @annot.border_effect)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "returns cloud(y|ier|iest) if /S is /C and depending on /I" do
|
|
30
|
+
@annot[:BE] = {S: :C}
|
|
31
|
+
assert_equal(:cloudy, @annot.border_effect)
|
|
32
|
+
@annot[:BE][:I] = 0
|
|
33
|
+
assert_equal(:cloudy, @annot.border_effect)
|
|
34
|
+
@annot[:BE][:I] = 1
|
|
35
|
+
assert_equal(:cloudier, @annot.border_effect)
|
|
36
|
+
@annot[:BE][:I] = 2
|
|
37
|
+
assert_equal(:cloudiest, @annot.border_effect)
|
|
38
|
+
@annot[:BE][:I] = 3
|
|
39
|
+
assert_equal(:cloudy, @annot.border_effect)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "sets the /BE entry appropriately" do
|
|
43
|
+
@annot.border_effect(:none)
|
|
44
|
+
refute(@annot.key?(:BE))
|
|
45
|
+
@annot.border_effect(nil)
|
|
46
|
+
refute(@annot.key?(:BE))
|
|
47
|
+
@annot.border_effect(:cloudy)
|
|
48
|
+
assert_equal({S: :C, I: 0}, @annot[:BE])
|
|
49
|
+
@annot.border_effect(:cloudier)
|
|
50
|
+
assert_equal({S: :C, I: 1}, @annot[:BE])
|
|
51
|
+
@annot.border_effect(:cloudiest)
|
|
52
|
+
assert_equal({S: :C, I: 2}, @annot[:BE])
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "raises an error if the given type is unknown" do
|
|
56
|
+
assert_raises(ArgumentError) { @annot.border_effect(:unknown) }
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|