hexapdf 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -0
- data/lib/hexapdf/cli/command.rb +63 -63
- data/lib/hexapdf/cli/inspect.rb +1 -1
- data/lib/hexapdf/cli/modify.rb +0 -1
- data/lib/hexapdf/cli/optimize.rb +5 -5
- data/lib/hexapdf/configuration.rb +21 -0
- data/lib/hexapdf/content/graphics_state.rb +1 -1
- data/lib/hexapdf/digital_signature/signing/signed_data_creator.rb +1 -1
- data/lib/hexapdf/document/annotations.rb +115 -0
- data/lib/hexapdf/document.rb +28 -7
- data/lib/hexapdf/font/true_type_wrapper.rb +1 -0
- data/lib/hexapdf/font/type1_wrapper.rb +1 -0
- data/lib/hexapdf/type/acro_form/java_script_actions.rb +9 -2
- data/lib/hexapdf/type/acro_form/text_field.rb +9 -2
- data/lib/hexapdf/type/annotation.rb +59 -1
- data/lib/hexapdf/type/annotations/appearance_generator.rb +273 -0
- data/lib/hexapdf/type/annotations/border_styling.rb +160 -0
- data/lib/hexapdf/type/annotations/line.rb +521 -0
- data/lib/hexapdf/type/annotations/widget.rb +2 -96
- data/lib/hexapdf/type/annotations.rb +3 -0
- data/lib/hexapdf/type/form.rb +2 -2
- data/lib/hexapdf/version.rb +1 -1
- data/lib/hexapdf/writer.rb +0 -1
- data/lib/hexapdf/xref_section.rb +7 -4
- data/test/hexapdf/content/test_graphics_state.rb +2 -3
- data/test/hexapdf/content/test_operator.rb +4 -5
- data/test/hexapdf/digital_signature/test_cms_handler.rb +7 -8
- data/test/hexapdf/digital_signature/test_handler.rb +2 -3
- data/test/hexapdf/digital_signature/test_pkcs1_handler.rb +1 -2
- data/test/hexapdf/document/test_annotations.rb +33 -0
- data/test/hexapdf/font/test_true_type_wrapper.rb +7 -0
- data/test/hexapdf/font/test_type1_wrapper.rb +7 -0
- data/test/hexapdf/task/test_optimize.rb +1 -1
- data/test/hexapdf/test_document.rb +11 -3
- data/test/hexapdf/test_stream.rb +1 -2
- data/test/hexapdf/test_xref_section.rb +1 -1
- data/test/hexapdf/type/acro_form/test_java_script_actions.rb +21 -0
- data/test/hexapdf/type/acro_form/test_text_field.rb +7 -1
- data/test/hexapdf/type/annotations/test_appearance_generator.rb +398 -0
- data/test/hexapdf/type/annotations/test_border_styling.rb +114 -0
- data/test/hexapdf/type/annotations/test_line.rb +189 -0
- data/test/hexapdf/type/annotations/test_widget.rb +0 -81
- data/test/hexapdf/type/test_annotation.rb +55 -0
- data/test/hexapdf/type/test_form.rb +6 -0
- metadata +10 -2
@@ -69,87 +69,6 @@ describe HexaPDF::Type::Annotations::Widget do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
describe "border_style" do
|
73
|
-
before do
|
74
|
-
@widget[:MK] = {BC: [1, 0, 1]}
|
75
|
-
@color = HexaPDF::Content::ColorSpace.prenormalized_device_color([1, 0, 1])
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "getter" do
|
79
|
-
it "no /Border, /BS or /MK set" do
|
80
|
-
@widget.delete(:MK)
|
81
|
-
assert_equal([1, nil, :solid, 0, 0], @widget.border_style.to_a)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "no /Border, /BS but with /MK empty" do
|
85
|
-
@widget[:MK].delete(:BC)
|
86
|
-
assert_equal([1, nil, :solid, 0, 0], @widget.border_style.to_a)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "uses the color from /MK" do
|
90
|
-
assert_equal([1, @color, :solid, 0, 0], @widget.border_style.to_a)
|
91
|
-
@widget[:MK][:BC] = []
|
92
|
-
assert_equal([1, nil, :solid, 0, 0], @widget.border_style.to_a)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "uses the data from /Border" do
|
96
|
-
@widget[:Border] = [1, 2, 3, [1, 2]]
|
97
|
-
assert_equal([3, @color, [1, 2], 1, 2], @widget.border_style.to_a)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "uses the data from /BS, overriding /Border values" do
|
101
|
-
@widget[:Border] = [1, 2, 3, [1, 2]]
|
102
|
-
@widget[:BS] = {W: 5, S: :D, D: [5, 6]}
|
103
|
-
assert_equal([5, @color, [5, 6], 0, 0], @widget.border_style.to_a)
|
104
|
-
|
105
|
-
[[:S, :solid], [:D, [5, 6]], [:B, :beveled], [:I, :inset],
|
106
|
-
[:U, :underlined], [:Unknown, :solid]].each do |val, result|
|
107
|
-
@widget[:BS] = {S: val, D: [5, 6]}
|
108
|
-
assert_equal([1, @color, result, 0, 0], @widget.border_style.to_a)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe "setter" do
|
114
|
-
it "returns self" do
|
115
|
-
assert_equal(@widget, @widget.border_style(width: 1))
|
116
|
-
end
|
117
|
-
|
118
|
-
it "sets the color" do
|
119
|
-
@widget.border_style(color: [1.0, 51, 1.0])
|
120
|
-
assert_equal([1, 0.2, 1], @widget[:MK][:BC].value)
|
121
|
-
|
122
|
-
@widget.border_style(color: :transparent)
|
123
|
-
assert_equal([], @widget[:MK][:BC].value)
|
124
|
-
end
|
125
|
-
|
126
|
-
it "sets the width" do
|
127
|
-
@widget.border_style(width: 2)
|
128
|
-
assert_equal(2, @widget[:BS][:W])
|
129
|
-
end
|
130
|
-
|
131
|
-
it "sets the style" do
|
132
|
-
[[:solid, :S], [[5, 6], :D], [:beveled, :B], [:inset, :I], [:underlined, :U]].each do |val, r|
|
133
|
-
@widget.border_style(style: val)
|
134
|
-
assert_equal(r, @widget[:BS][:S])
|
135
|
-
assert_equal(val, @widget[:BS][:D].value) if r == :D
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
it "overrides all priorly set values" do
|
140
|
-
@widget.border_style(width: 3, style: :inset, color: [1])
|
141
|
-
@widget.border_style(width: 5)
|
142
|
-
border_style = @widget.border_style
|
143
|
-
assert_equal(:solid, border_style.style)
|
144
|
-
assert_equal([0], border_style.color.components)
|
145
|
-
end
|
146
|
-
|
147
|
-
it "raises an error for an unknown style" do
|
148
|
-
assert_raises(ArgumentError) { @widget.border_style(style: :unknown) }
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
72
|
describe "marker_style" do
|
154
73
|
before do
|
155
74
|
@chars = %w[4 l 8 u n H S]
|
@@ -113,6 +113,14 @@ describe HexaPDF::Type::Annotation do
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
+
describe "regenerate_appearance" do
|
117
|
+
it "regenerates the appearance using the data from the annotation object" do
|
118
|
+
@annot[:Subtype] = :Unknown
|
119
|
+
error = assert_raises(HexaPDF::Error) { @annot.regenerate_appearance }
|
120
|
+
assert_match(/Unknown.*not.*supported/, error.message)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
116
124
|
describe "flags" do
|
117
125
|
it "returns all flags" do
|
118
126
|
assert_equal([:invisible, :hidden, :no_view], @annot.flags)
|
@@ -139,6 +147,53 @@ describe HexaPDF::Type::Annotation do
|
|
139
147
|
end
|
140
148
|
end
|
141
149
|
|
150
|
+
describe "contents" do
|
151
|
+
it "returns the contents value" do
|
152
|
+
assert_nil(@annot.contents)
|
153
|
+
@annot[:Contents] = "test"
|
154
|
+
assert_equal("test", @annot.contents)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "sets the contents value" do
|
158
|
+
assert_same(@annot, @annot.contents("Test"))
|
159
|
+
assert_equal("Test", @annot[:Contents])
|
160
|
+
@annot.contents(nil)
|
161
|
+
assert_nil(@annot[:Contents])
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "opacity" do
|
166
|
+
it "returns the opacity values" do
|
167
|
+
opacity = @annot.opacity
|
168
|
+
assert_equal(1, opacity.fill_alpha)
|
169
|
+
assert_equal(1, opacity.stroke_alpha)
|
170
|
+
|
171
|
+
@annot[:CA] = 0.5
|
172
|
+
opacity = @annot.opacity
|
173
|
+
assert_equal(0.5, opacity.fill_alpha)
|
174
|
+
assert_equal(0.5, opacity.stroke_alpha)
|
175
|
+
|
176
|
+
@annot[:ca] = 0.3
|
177
|
+
opacity = @annot.opacity
|
178
|
+
assert_equal(0.3, opacity.fill_alpha)
|
179
|
+
assert_equal(0.5, opacity.stroke_alpha)
|
180
|
+
end
|
181
|
+
|
182
|
+
it "sets the opacity values" do
|
183
|
+
@annot.opacity(fill_alpha: 0.3)
|
184
|
+
refute(@annot.key?(:CA))
|
185
|
+
assert_equal(0.3, @annot[:ca])
|
186
|
+
|
187
|
+
@annot.opacity(stroke_alpha: 0.5)
|
188
|
+
assert_equal(0.3, @annot[:ca])
|
189
|
+
assert_equal(0.5, @annot[:CA])
|
190
|
+
|
191
|
+
@annot.opacity(stroke_alpha: 0.1, fill_alpha: 0.2)
|
192
|
+
assert_equal(0.1, @annot[:CA])
|
193
|
+
assert_equal(0.2, @annot[:ca])
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
142
197
|
describe "validation" do
|
143
198
|
it "makes sure that empty appearance stream dictionaries don't cause validation errors" do
|
144
199
|
assert(@annot.validate)
|
@@ -125,6 +125,12 @@ describe HexaPDF::Type::Form do
|
|
125
125
|
[:restore_graphics_state]])
|
126
126
|
end
|
127
127
|
|
128
|
+
it "doesn't move the origin if translate is false" do
|
129
|
+
@form[:BBox] = [-10, -5, 100, 300]
|
130
|
+
@form.canvas(translate: false).line_width = 5
|
131
|
+
assert_operators(@form, [[:set_line_width, [5]]])
|
132
|
+
end
|
133
|
+
|
128
134
|
it "fails if the form XObject already has data" do
|
129
135
|
@form.stream = '10 w'
|
130
136
|
assert_raises(HexaPDF::Error) { @form.canvas }
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hexapdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Leitner
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-02-10 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: cmdparse
|
@@ -371,6 +371,7 @@ files:
|
|
371
371
|
- lib/hexapdf/digital_signature/signing/timestamp_handler.rb
|
372
372
|
- lib/hexapdf/digital_signature/verification_result.rb
|
373
373
|
- lib/hexapdf/document.rb
|
374
|
+
- lib/hexapdf/document/annotations.rb
|
374
375
|
- lib/hexapdf/document/destinations.rb
|
375
376
|
- lib/hexapdf/document/files.rb
|
376
377
|
- lib/hexapdf/document/fonts.rb
|
@@ -507,6 +508,9 @@ files:
|
|
507
508
|
- lib/hexapdf/type/actions/uri.rb
|
508
509
|
- lib/hexapdf/type/annotation.rb
|
509
510
|
- lib/hexapdf/type/annotations.rb
|
511
|
+
- lib/hexapdf/type/annotations/appearance_generator.rb
|
512
|
+
- lib/hexapdf/type/annotations/border_styling.rb
|
513
|
+
- lib/hexapdf/type/annotations/line.rb
|
510
514
|
- lib/hexapdf/type/annotations/link.rb
|
511
515
|
- lib/hexapdf/type/annotations/markup_annotation.rb
|
512
516
|
- lib/hexapdf/type/annotations/text.rb
|
@@ -661,6 +665,7 @@ files:
|
|
661
665
|
- test/hexapdf/digital_signature/test_signatures.rb
|
662
666
|
- test/hexapdf/digital_signature/test_signing.rb
|
663
667
|
- test/hexapdf/digital_signature/test_verification_result.rb
|
668
|
+
- test/hexapdf/document/test_annotations.rb
|
664
669
|
- test/hexapdf/document/test_destinations.rb
|
665
670
|
- test/hexapdf/document/test_files.rb
|
666
671
|
- test/hexapdf/document/test_fonts.rb
|
@@ -785,6 +790,9 @@ files:
|
|
785
790
|
- test/hexapdf/type/actions/test_launch.rb
|
786
791
|
- test/hexapdf/type/actions/test_set_ocg_state.rb
|
787
792
|
- test/hexapdf/type/actions/test_uri.rb
|
793
|
+
- test/hexapdf/type/annotations/test_appearance_generator.rb
|
794
|
+
- test/hexapdf/type/annotations/test_border_styling.rb
|
795
|
+
- test/hexapdf/type/annotations/test_line.rb
|
788
796
|
- test/hexapdf/type/annotations/test_markup_annotation.rb
|
789
797
|
- test/hexapdf/type/annotations/test_text.rb
|
790
798
|
- test/hexapdf/type/annotations/test_widget.rb
|