hexapdf 0.17.1 → 0.17.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1024 -0
- data/LICENSE +29 -0
- data/README.md +129 -0
- data/Rakefile +109 -0
- data/agpl-3.0.txt +661 -0
- data/examples/001-hello_world.rb +16 -0
- data/examples/002-graphics.rb +275 -0
- data/examples/003-arcs.rb +50 -0
- data/examples/004-optimizing.rb +23 -0
- data/examples/005-merging.rb +27 -0
- data/examples/006-standard_pdf_fonts.rb +73 -0
- data/examples/007-truetype.rb +42 -0
- data/examples/008-show_char_bboxes.rb +55 -0
- data/examples/009-text_layouter_alignment.rb +47 -0
- data/examples/010-text_layouter_inline_boxes.rb +64 -0
- data/examples/011-text_layouter_line_wrapping.rb +57 -0
- data/examples/012-text_layouter_styling.rb +122 -0
- data/examples/013-text_layouter_shapes.rb +176 -0
- data/examples/014-text_in_polygon.rb +60 -0
- data/examples/015-boxes.rb +76 -0
- data/examples/016-frame_automatic_box_placement.rb +90 -0
- data/examples/017-frame_text_flow.rb +60 -0
- data/examples/018-composer.rb +44 -0
- data/examples/019-acro_form.rb +88 -0
- data/examples/emoji-smile.png +0 -0
- data/examples/emoji-wink.png +0 -0
- data/examples/machupicchu.jpg +0 -0
- data/lib/hexapdf/content/graphic_object/endpoint_arc.rb +66 -0
- data/lib/hexapdf/content/graphic_object/geom2d.rb +13 -0
- data/lib/hexapdf/version.rb +1 -1
- 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/images/ycck.jpg +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 +236 -0
- data/test/hexapdf/content/common.rb +39 -0
- data/test/hexapdf/content/graphic_object/test_arc.rb +102 -0
- data/test/hexapdf/content/graphic_object/test_endpoint_arc.rb +90 -0
- data/test/hexapdf/content/graphic_object/test_geom2d.rb +79 -0
- data/test/hexapdf/content/graphic_object/test_solid_arc.rb +86 -0
- data/test/hexapdf/content/test_canvas.rb +1279 -0
- data/test/hexapdf/content/test_color_space.rb +176 -0
- data/test/hexapdf/content/test_graphics_state.rb +151 -0
- data/test/hexapdf/content/test_operator.rb +619 -0
- data/test/hexapdf/content/test_parser.rb +99 -0
- data/test/hexapdf/content/test_processor.rb +163 -0
- data/test/hexapdf/content/test_transformation_matrix.rb +64 -0
- data/test/hexapdf/document/test_files.rb +72 -0
- data/test/hexapdf/document/test_fonts.rb +60 -0
- data/test/hexapdf/document/test_images.rb +72 -0
- data/test/hexapdf/document/test_pages.rb +130 -0
- data/test/hexapdf/encryption/common.rb +87 -0
- data/test/hexapdf/encryption/test_aes.rb +129 -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 +380 -0
- data/test/hexapdf/encryption/test_standard_security_handler.rb +322 -0
- data/test/hexapdf/filter/common.rb +53 -0
- data/test/hexapdf/filter/test_ascii85_decode.rb +59 -0
- data/test/hexapdf/filter/test_ascii_hex_decode.rb +38 -0
- data/test/hexapdf/filter/test_crypt.rb +21 -0
- data/test/hexapdf/filter/test_encryption.rb +24 -0
- data/test/hexapdf/filter/test_flate_decode.rb +44 -0
- data/test/hexapdf/filter/test_lzw_decode.rb +52 -0
- data/test/hexapdf/filter/test_predictor.rb +219 -0
- data/test/hexapdf/filter/test_run_length_decode.rb +32 -0
- data/test/hexapdf/font/cmap/test_parser.rb +102 -0
- data/test/hexapdf/font/cmap/test_writer.rb +66 -0
- data/test/hexapdf/font/encoding/test_base.rb +45 -0
- data/test/hexapdf/font/encoding/test_difference_encoding.rb +29 -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_cmap.rb +104 -0
- data/test/hexapdf/font/test_encoding.rb +27 -0
- data/test/hexapdf/font/test_invalid_glyph.rb +34 -0
- data/test/hexapdf/font/test_true_type_wrapper.rb +186 -0
- data/test/hexapdf/font/test_type1_wrapper.rb +107 -0
- data/test/hexapdf/font/true_type/common.rb +17 -0
- data/test/hexapdf/font/true_type/table/common.rb +27 -0
- data/test/hexapdf/font/true_type/table/test_cmap.rb +47 -0
- data/test/hexapdf/font/true_type/table/test_cmap_subtable.rb +141 -0
- data/test/hexapdf/font/true_type/table/test_directory.rb +30 -0
- data/test/hexapdf/font/true_type/table/test_glyf.rb +58 -0
- data/test/hexapdf/font/true_type/table/test_head.rb +56 -0
- data/test/hexapdf/font/true_type/table/test_hhea.rb +26 -0
- data/test/hexapdf/font/true_type/table/test_hmtx.rb +30 -0
- data/test/hexapdf/font/true_type/table/test_kern.rb +61 -0
- data/test/hexapdf/font/true_type/table/test_loca.rb +33 -0
- data/test/hexapdf/font/true_type/table/test_maxp.rb +50 -0
- data/test/hexapdf/font/true_type/table/test_name.rb +76 -0
- data/test/hexapdf/font/true_type/table/test_os2.rb +55 -0
- data/test/hexapdf/font/true_type/table/test_post.rb +78 -0
- data/test/hexapdf/font/true_type/test_builder.rb +42 -0
- data/test/hexapdf/font/true_type/test_font.rb +116 -0
- data/test/hexapdf/font/true_type/test_optimizer.rb +26 -0
- data/test/hexapdf/font/true_type/test_subsetter.rb +73 -0
- data/test/hexapdf/font/true_type/test_table.rb +48 -0
- data/test/hexapdf/font/type1/common.rb +6 -0
- data/test/hexapdf/font/type1/test_afm_parser.rb +65 -0
- data/test/hexapdf/font/type1/test_font.rb +104 -0
- data/test/hexapdf/font/type1/test_font_metrics.rb +22 -0
- data/test/hexapdf/font/type1/test_pfb_parser.rb +37 -0
- data/test/hexapdf/font_loader/test_from_configuration.rb +43 -0
- data/test/hexapdf/font_loader/test_from_file.rb +36 -0
- data/test/hexapdf/font_loader/test_standard14.rb +33 -0
- data/test/hexapdf/image_loader/test_jpeg.rb +93 -0
- data/test/hexapdf/image_loader/test_pdf.rb +47 -0
- data/test/hexapdf/image_loader/test_png.rb +259 -0
- data/test/hexapdf/layout/test_box.rb +154 -0
- data/test/hexapdf/layout/test_frame.rb +350 -0
- data/test/hexapdf/layout/test_image_box.rb +73 -0
- data/test/hexapdf/layout/test_inline_box.rb +71 -0
- data/test/hexapdf/layout/test_line.rb +206 -0
- data/test/hexapdf/layout/test_style.rb +790 -0
- data/test/hexapdf/layout/test_text_box.rb +140 -0
- data/test/hexapdf/layout/test_text_fragment.rb +375 -0
- data/test/hexapdf/layout/test_text_layouter.rb +758 -0
- data/test/hexapdf/layout/test_text_shaper.rb +62 -0
- data/test/hexapdf/layout/test_width_from_polygon.rb +109 -0
- data/test/hexapdf/task/test_dereference.rb +51 -0
- data/test/hexapdf/task/test_optimize.rb +162 -0
- data/test/hexapdf/test_composer.rb +258 -0
- data/test/hexapdf/test_configuration.rb +93 -0
- data/test/hexapdf/test_data_dir.rb +32 -0
- data/test/hexapdf/test_dictionary.rb +340 -0
- data/test/hexapdf/test_dictionary_fields.rb +269 -0
- data/test/hexapdf/test_document.rb +641 -0
- data/test/hexapdf/test_filter.rb +100 -0
- data/test/hexapdf/test_importer.rb +106 -0
- data/test/hexapdf/test_object.rb +258 -0
- data/test/hexapdf/test_parser.rb +645 -0
- data/test/hexapdf/test_pdf_array.rb +169 -0
- data/test/hexapdf/test_rectangle.rb +73 -0
- data/test/hexapdf/test_reference.rb +50 -0
- data/test/hexapdf/test_revision.rb +188 -0
- data/test/hexapdf/test_revisions.rb +196 -0
- data/test/hexapdf/test_serializer.rb +195 -0
- data/test/hexapdf/test_stream.rb +274 -0
- data/test/hexapdf/test_tokenizer.rb +80 -0
- data/test/hexapdf/test_type.rb +18 -0
- data/test/hexapdf/test_writer.rb +140 -0
- data/test/hexapdf/test_xref_section.rb +61 -0
- data/test/hexapdf/type/acro_form/test_appearance_generator.rb +795 -0
- data/test/hexapdf/type/acro_form/test_button_field.rb +308 -0
- data/test/hexapdf/type/acro_form/test_choice_field.rb +220 -0
- data/test/hexapdf/type/acro_form/test_field.rb +259 -0
- data/test/hexapdf/type/acro_form/test_form.rb +357 -0
- data/test/hexapdf/type/acro_form/test_signature_field.rb +38 -0
- data/test/hexapdf/type/acro_form/test_text_field.rb +201 -0
- data/test/hexapdf/type/acro_form/test_variable_text_field.rb +88 -0
- data/test/hexapdf/type/actions/test_launch.rb +24 -0
- data/test/hexapdf/type/actions/test_uri.rb +23 -0
- data/test/hexapdf/type/annotations/test_markup_annotation.rb +22 -0
- data/test/hexapdf/type/annotations/test_text.rb +34 -0
- data/test/hexapdf/type/annotations/test_widget.rb +225 -0
- data/test/hexapdf/type/test_annotation.rb +97 -0
- data/test/hexapdf/type/test_catalog.rb +48 -0
- data/test/hexapdf/type/test_cid_font.rb +61 -0
- data/test/hexapdf/type/test_file_specification.rb +141 -0
- data/test/hexapdf/type/test_font.rb +67 -0
- data/test/hexapdf/type/test_font_descriptor.rb +61 -0
- data/test/hexapdf/type/test_font_simple.rb +176 -0
- data/test/hexapdf/type/test_font_true_type.rb +31 -0
- data/test/hexapdf/type/test_font_type0.rb +120 -0
- data/test/hexapdf/type/test_font_type1.rb +142 -0
- data/test/hexapdf/type/test_font_type3.rb +26 -0
- data/test/hexapdf/type/test_form.rb +120 -0
- data/test/hexapdf/type/test_image.rb +261 -0
- data/test/hexapdf/type/test_info.rb +9 -0
- data/test/hexapdf/type/test_object_stream.rb +117 -0
- data/test/hexapdf/type/test_page.rb +598 -0
- data/test/hexapdf/type/test_page_tree_node.rb +315 -0
- data/test/hexapdf/type/test_resources.rb +209 -0
- data/test/hexapdf/type/test_trailer.rb +116 -0
- data/test/hexapdf/type/test_xref_stream.rb +143 -0
- data/test/hexapdf/utils/test_bit_field.rb +63 -0
- data/test/hexapdf/utils/test_bit_stream.rb +69 -0
- data/test/hexapdf/utils/test_graphics_helpers.rb +37 -0
- data/test/hexapdf/utils/test_lru_cache.rb +22 -0
- data/test/hexapdf/utils/test_object_hash.rb +120 -0
- data/test/hexapdf/utils/test_pdf_doc_encoding.rb +18 -0
- data/test/hexapdf/utils/test_sorted_tree_node.rb +239 -0
- data/test/test_helper.rb +58 -0
- metadata +263 -3
@@ -0,0 +1,176 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'hexapdf/content/color_space'
|
5
|
+
|
6
|
+
module CommonColorSpaceTests
|
7
|
+
extend Minitest::Spec::DSL
|
8
|
+
|
9
|
+
it "the color object returns the correct color space" do
|
10
|
+
assert_equal(@color_space, @color.color_space)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "the color space class accepts the color space definition as argument to ::new" do
|
14
|
+
assert_equal(1, @color_space.class.method(:new).arity.abs)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "the color space responds to :default_color" do
|
18
|
+
assert(@color_space.respond_to?(:default_color))
|
19
|
+
assert_equal(0, @color_space.method(:default_color).arity)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "the color space responds to :color" do
|
23
|
+
assert(@color_space.respond_to?(:color))
|
24
|
+
end
|
25
|
+
|
26
|
+
it "the color space returns the correct color space family" do
|
27
|
+
assert_equal(@color_space_family, @color_space.family)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "the color space returns the correct color space definition" do
|
31
|
+
assert_equal(@color_space_definition, @color_space.definition)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "the color responds to :components" do
|
35
|
+
assert(@color.respond_to?(:components))
|
36
|
+
end
|
37
|
+
|
38
|
+
it "the color responds to :color_space" do
|
39
|
+
assert(@color.respond_to?(:color_space))
|
40
|
+
end
|
41
|
+
|
42
|
+
it "the colors are comparable" do
|
43
|
+
refute_equal(@color, @other_color)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "the components are returned in the correct order" do
|
47
|
+
assert_equal(@components, @color_space.color(*@components).components)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "normalizes the colors when using the #color method" do
|
51
|
+
return unless defined?(@colors)
|
52
|
+
assert_equal(@components, @color_space.color(*@colors).components)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "doesn't normalize the colors when using the #prenormalized_color method" do
|
56
|
+
return unless defined?(@colors)
|
57
|
+
assert_equal(@colors, @color_space.prenormalized_color(*@colors).components)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe HexaPDF::Content::ColorSpace do
|
63
|
+
before do
|
64
|
+
@class = HexaPDF::Content::ColorSpace
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "self.device_color_from_specification" do
|
68
|
+
it "works for gray values" do
|
69
|
+
assert_equal([0.2], @class.device_color_from_specification(51).components)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "works for RGB values" do
|
73
|
+
assert_equal([0.2, 1, 0], @class.device_color_from_specification(51, 255, 0).components)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "works for RGB values given as full hex string" do
|
77
|
+
assert_equal([0.2, 1, 0], @class.device_color_from_specification("33FF00").components)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "works for RGB values given as half hex string" do
|
81
|
+
assert_equal([0.2, 1, 0], @class.device_color_from_specification("3F0").components)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "works for RGB values given as color names" do
|
85
|
+
assert_equal([0, 0, 1], @class.device_color_from_specification("blue").components)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "works for CMYK values" do
|
89
|
+
assert_equal([0.51, 0.9, 1, 0.5],
|
90
|
+
@class.device_color_from_specification(51, 90, 100, 50).components)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "works when an array is given" do
|
94
|
+
assert_equal([0.2], @class.device_color_from_specification([51]).components)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "raises an error if an invalid color string is given" do
|
98
|
+
assert_raises(ArgumentError) { @class.device_color_from_specification("unknown") }
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it "returns a device color object for prenormalized color values" do
|
103
|
+
assert_equal([5, 6, 7], @class.prenormalized_device_color([5, 6, 7]).components)
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "self.for_components" do
|
107
|
+
it "returns the correct device color space name" do
|
108
|
+
assert_equal(:DeviceGray, @class.for_components([1]))
|
109
|
+
assert_equal(:DeviceRGB, @class.for_components([1, 2, 3]))
|
110
|
+
assert_equal(:DeviceCMYK, @class.for_components([1, 2, 3, 4]))
|
111
|
+
end
|
112
|
+
|
113
|
+
it "fails if an array with an invalid length is passed" do
|
114
|
+
assert_raises(ArgumentError) { @class.for_components([]) }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe HexaPDF::Content::ColorSpace::Universal do
|
120
|
+
include CommonColorSpaceTests
|
121
|
+
|
122
|
+
before do
|
123
|
+
@color_space = HexaPDF::Content::ColorSpace::Universal.new([:test, :value])
|
124
|
+
@color_space_family = :test
|
125
|
+
@color_space_definition = [:test, :value]
|
126
|
+
@color = @color_space.default_color
|
127
|
+
@other_color = @color_space.color(128, 5, 6, 7, 8)
|
128
|
+
@components = [5, 6, 7, 8]
|
129
|
+
end
|
130
|
+
|
131
|
+
it "can be compared to another universal color space" do
|
132
|
+
other = HexaPDF::Content::ColorSpace::Universal.new([:other])
|
133
|
+
same = HexaPDF::Content::ColorSpace::Universal.new([:test, :value])
|
134
|
+
assert_equal(same, @color_space)
|
135
|
+
refute_equal(other, @color_space)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe HexaPDF::Content::ColorSpace::DeviceRGB do
|
140
|
+
include CommonColorSpaceTests
|
141
|
+
|
142
|
+
before do
|
143
|
+
@color_space = HexaPDF::Content::ColorSpace::DeviceRGB.new
|
144
|
+
@color_space_family = @color_space_definition = :DeviceRGB
|
145
|
+
@color = @color_space.default_color
|
146
|
+
@other_color = @color_space.color(128, 0, 0)
|
147
|
+
@colors = [128, 0, 255]
|
148
|
+
@components = @colors.map {|c| c.to_f / 255 }
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe HexaPDF::Content::ColorSpace::DeviceCMYK do
|
153
|
+
include CommonColorSpaceTests
|
154
|
+
|
155
|
+
before do
|
156
|
+
@color_space = HexaPDF::Content::ColorSpace::DeviceCMYK.new
|
157
|
+
@color_space_family = @color_space_definition = :DeviceCMYK
|
158
|
+
@color = @color_space.default_color
|
159
|
+
@other_color = @color_space.color(128, 0, 0, 128)
|
160
|
+
@colors = [0, 20, 40, 80]
|
161
|
+
@components = [0.0, 0.2, 0.4, 0.8]
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe HexaPDF::Content::ColorSpace::DeviceGray do
|
166
|
+
include CommonColorSpaceTests
|
167
|
+
|
168
|
+
before do
|
169
|
+
@color_space = HexaPDF::Content::ColorSpace::DeviceGray.new
|
170
|
+
@color_space_family = @color_space_definition = :DeviceGray
|
171
|
+
@color = @color_space.default_color
|
172
|
+
@other_color = @color_space.color(128)
|
173
|
+
@colors = [128]
|
174
|
+
@components = [128.0 / 255]
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'hexapdf/content/graphics_state'
|
5
|
+
|
6
|
+
# Dummy class used as wrapper so that constant lookup works correctly
|
7
|
+
class GraphicsStateWrapper < Minitest::Spec
|
8
|
+
|
9
|
+
include HexaPDF::Content
|
10
|
+
|
11
|
+
describe NamedValue do
|
12
|
+
before do
|
13
|
+
@val = NamedValue.new(:round, 1)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "freezes a new object on creation" do
|
17
|
+
assert(@val.frozen?)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can be compared to name, value or NamedValue objects" do
|
21
|
+
assert_equal(@val, :round)
|
22
|
+
assert_equal(@val, 1)
|
23
|
+
assert_equal(@val, @val)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns the value when operands are requested" do
|
27
|
+
assert_equal(@val.value, @val.to_operands)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe LineCapStyle do
|
32
|
+
it "can normalize a style argument" do
|
33
|
+
[[:BUTT_CAP, :butt, 0], [:ROUND_CAP, :round, 1],
|
34
|
+
[:PROJECTING_SQUARE_CAP, :projecting_square, 2]].each do |const_name, name, value|
|
35
|
+
const = LineCapStyle.const_get(const_name)
|
36
|
+
assert_equal(const, LineCapStyle.normalize(name))
|
37
|
+
assert_equal(const, LineCapStyle.normalize(value))
|
38
|
+
assert_equal(const, LineCapStyle.normalize(const))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "fails when trying to normalize an invalid argument" do
|
43
|
+
assert_raises(ArgumentError) { LineCapStyle.normalize(:invalid) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe LineJoinStyle do
|
48
|
+
it "can normalize a style argument" do
|
49
|
+
[[:MITER_JOIN, :miter, 0], [:ROUND_JOIN, :round, 1],
|
50
|
+
[:BEVEL_JOIN, :bevel, 2]].each do |const_name, name, value|
|
51
|
+
const = LineJoinStyle.const_get(const_name)
|
52
|
+
assert_equal(const, LineJoinStyle.normalize(name))
|
53
|
+
assert_equal(const, LineJoinStyle.normalize(value))
|
54
|
+
assert_equal(const, LineJoinStyle.normalize(const))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "fails when trying to normalize an invalid argument" do
|
59
|
+
assert_raises(ArgumentError) { LineJoinStyle.normalize(:invalid) }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe RenderingIntent do
|
64
|
+
it "can normalize an intent argument" do
|
65
|
+
assert_equal(RenderingIntent::ABSOLUTE_COLORIMETRIC,
|
66
|
+
RenderingIntent.normalize(:AbsoluteColorimetric))
|
67
|
+
assert_equal(RenderingIntent::RELATIVE_COLORIMETRIC,
|
68
|
+
RenderingIntent.normalize(:RelativeColorimetric))
|
69
|
+
assert_equal(RenderingIntent::PERCEPTUAL,
|
70
|
+
RenderingIntent.normalize(:Perceptual))
|
71
|
+
assert_equal(RenderingIntent::SATURATION,
|
72
|
+
RenderingIntent.normalize(:Saturation))
|
73
|
+
end
|
74
|
+
|
75
|
+
it "fails when trying to normalize an invalid argument" do
|
76
|
+
assert_raises(ArgumentError) { RenderingIntent.normalize(:invalid) }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe LineDashPattern do
|
81
|
+
it "returns a normalized line dash pattern from various values" do
|
82
|
+
assert_equal([[], 0], LineDashPattern.normalize(0).to_operands)
|
83
|
+
assert_equal([[5], 0], LineDashPattern.normalize(5).to_operands)
|
84
|
+
assert_equal([[5, 3], 2], LineDashPattern.normalize([5, 3], 2).to_operands)
|
85
|
+
assert_equal([[5], 1], LineDashPattern.normalize(LineDashPattern.normalize(5, 1)).to_operands)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "fails on normalization if an invalid array argument is provided" do
|
89
|
+
assert_raises(ArgumentError) { LineDashPattern.normalize(:bla) }
|
90
|
+
end
|
91
|
+
|
92
|
+
it "fails on initialization if the phase is negative" do
|
93
|
+
assert_raises(ArgumentError) { LineDashPattern.new([], -1) }
|
94
|
+
end
|
95
|
+
|
96
|
+
it "fails on initialization if all the dash array values are zero " do
|
97
|
+
assert_raises(ArgumentError) { LineDashPattern.new([0, 0], 0) }
|
98
|
+
end
|
99
|
+
|
100
|
+
it "fails on initialization if a dash array value is negative" do
|
101
|
+
assert_raises(ArgumentError) { LineDashPattern.new([-2, 0], 0) }
|
102
|
+
end
|
103
|
+
|
104
|
+
it "can be compared to another line dash pattern object" do
|
105
|
+
assert_equal(LineDashPattern.new([2, 3], 0),
|
106
|
+
LineDashPattern.new([2, 3], 0))
|
107
|
+
refute_equal(LineDashPattern.new([2, 3], 0),
|
108
|
+
LineDashPattern.new([2, 3], 1))
|
109
|
+
refute_equal(LineDashPattern.new([2, 3], 0),
|
110
|
+
LineDashPattern.new([2, 2], 0))
|
111
|
+
end
|
112
|
+
|
113
|
+
it "returns the operands needed for the line dash pattern operator" do
|
114
|
+
assert_equal([[2, 3], 0], LineDashPattern.new([2, 3], 0).to_operands)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe TextRenderingMode do
|
119
|
+
it "can normalize a style argument" do
|
120
|
+
[[:FILL, 0], [:STROKE, 1], [:FILL_STROKE, 2], [:INVISIBLE, 3], [:FILL_CLIP, 4],
|
121
|
+
[:STROKE_CLIP, 5], [:FILL_STROKE_CLIP, 6], [:CLIP, 7]].each do |const_name, value|
|
122
|
+
const = TextRenderingMode.const_get(const_name)
|
123
|
+
assert_equal(const, TextRenderingMode.normalize(const_name.to_s.downcase.intern))
|
124
|
+
assert_equal(const, TextRenderingMode.normalize(value))
|
125
|
+
assert_equal(const, TextRenderingMode.normalize(const))
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it "fails when trying to normalize an invalid argument" do
|
130
|
+
assert_raises(ArgumentError) { TextRenderingMode.normalize(:invalid) }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe GraphicsState do
|
135
|
+
before do
|
136
|
+
@gs = GraphicsState.new
|
137
|
+
end
|
138
|
+
|
139
|
+
it "allows saving and restoring the graphics state" do
|
140
|
+
@gs.save
|
141
|
+
@gs.line_width = 10
|
142
|
+
@gs.restore
|
143
|
+
assert_equal(1, @gs.line_width)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "fails when restoring the graphics state if the stack is empty" do
|
147
|
+
assert_raises(HexaPDF::Error) { @gs.restore }
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|