hexapdf 0.39.1 → 0.41.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 +59 -0
- data/examples/019-acro_form.rb +12 -23
- data/examples/027-composer_optional_content.rb +1 -1
- data/examples/030-pdfa.rb +6 -6
- data/examples/031-acro_form_java_script.rb +101 -0
- data/lib/hexapdf/cli/command.rb +11 -0
- data/lib/hexapdf/cli/form.rb +38 -9
- data/lib/hexapdf/cli/info.rb +4 -0
- data/lib/hexapdf/configuration.rb +10 -0
- data/lib/hexapdf/content/canvas.rb +2 -0
- data/lib/hexapdf/document/layout.rb +8 -1
- data/lib/hexapdf/encryption/aes.rb +13 -6
- data/lib/hexapdf/encryption/security_handler.rb +6 -4
- data/lib/hexapdf/font/cmap/parser.rb +1 -5
- data/lib/hexapdf/font/cmap.rb +22 -3
- data/lib/hexapdf/font_loader/from_configuration.rb +1 -1
- data/lib/hexapdf/font_loader/variant_from_name.rb +72 -0
- data/lib/hexapdf/font_loader.rb +1 -0
- data/lib/hexapdf/layout/list_box.rb +40 -33
- data/lib/hexapdf/layout/style.rb +25 -23
- data/lib/hexapdf/layout/text_box.rb +3 -3
- data/lib/hexapdf/type/acro_form/appearance_generator.rb +11 -76
- data/lib/hexapdf/type/acro_form/field.rb +14 -0
- data/lib/hexapdf/type/acro_form/form.rb +25 -8
- data/lib/hexapdf/type/acro_form/java_script_actions.rb +498 -0
- data/lib/hexapdf/type/acro_form/text_field.rb +78 -0
- data/lib/hexapdf/type/acro_form.rb +1 -0
- data/lib/hexapdf/type/annotations/widget.rb +1 -1
- data/lib/hexapdf/version.rb +1 -1
- data/test/hexapdf/encryption/test_aes.rb +18 -8
- data/test/hexapdf/encryption/test_security_handler.rb +17 -0
- data/test/hexapdf/encryption/test_standard_security_handler.rb +1 -1
- data/test/hexapdf/font/cmap/test_parser.rb +5 -3
- data/test/hexapdf/font/test_cmap.rb +8 -0
- data/test/hexapdf/font_loader/test_from_configuration.rb +4 -0
- data/test/hexapdf/font_loader/test_variant_from_name.rb +34 -0
- data/test/hexapdf/layout/test_list_box.rb +30 -1
- data/test/hexapdf/layout/test_style.rb +1 -1
- data/test/hexapdf/layout/test_text_box.rb +4 -4
- data/test/hexapdf/type/acro_form/test_appearance_generator.rb +31 -47
- data/test/hexapdf/type/acro_form/test_field.rb +11 -0
- data/test/hexapdf/type/acro_form/test_form.rb +33 -0
- data/test/hexapdf/type/acro_form/test_java_script_actions.rb +226 -0
- data/test/hexapdf/type/acro_form/test_text_field.rb +44 -0
- metadata +7 -2
@@ -124,6 +124,10 @@ describe HexaPDF::Type::AcroForm::TextField do
|
|
124
124
|
assert_raises(HexaPDF::Error) { @field.field_value = 'test' }
|
125
125
|
end
|
126
126
|
|
127
|
+
it "fails if the provided value is not a string" do
|
128
|
+
assert_raises(HexaPDF::Error) { @field.field_value = 10 }
|
129
|
+
end
|
130
|
+
|
127
131
|
it "fails if the value exceeds the length set by /MaxLen" do
|
128
132
|
@field[:MaxLen] = 5
|
129
133
|
assert_raises(HexaPDF::Error) { @field.field_value = 'testdf' }
|
@@ -197,6 +201,46 @@ describe HexaPDF::Type::AcroForm::TextField do
|
|
197
201
|
end
|
198
202
|
end
|
199
203
|
|
204
|
+
describe "set_format_action" do
|
205
|
+
it "applies the number format" do
|
206
|
+
@doc.acro_form(create: true)
|
207
|
+
@field.set_format_action(:number, decimals: 0)
|
208
|
+
assert(@field.key?(:AA))
|
209
|
+
assert(@field[:AA].key?(:F))
|
210
|
+
assert_equal('AFNumber_Format(0, 0, 0, 0, "", true);', @field[:AA][:F][:JS])
|
211
|
+
end
|
212
|
+
|
213
|
+
it "fails if an unknown format action is specified" do
|
214
|
+
assert_raises(ArgumentError) { @field.set_format_action(:unknown) }
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
describe "set_calculate_action" do
|
219
|
+
before do
|
220
|
+
@form = @doc.acro_form(create: true)
|
221
|
+
@form.create_text_field('text1')
|
222
|
+
@form.create_text_field('text2')
|
223
|
+
end
|
224
|
+
|
225
|
+
it "sets the calculate action using AFSimple_Calculate" do
|
226
|
+
@field.set_calculate_action(:sum, fields: ['text1', @form.field_by_name('text2')])
|
227
|
+
assert(@field.key?(:AA))
|
228
|
+
assert(@field[:AA].key?(:C))
|
229
|
+
assert_equal('AFSimple_Calculate("SUM", ["text1","text2"]);', @field[:AA][:C][:JS])
|
230
|
+
assert_equal([@field], @form[:CO].value)
|
231
|
+
end
|
232
|
+
|
233
|
+
it "sets the simplified field notation calculate action" do
|
234
|
+
@field.set_calculate_action(:sfn, fields: "text1")
|
235
|
+
assert_equal('/** BVCALC text1 EVCALC **/ event.value = AFMakeNumber(getField("text1").value)',
|
236
|
+
@field[:AA][:C][:JS])
|
237
|
+
end
|
238
|
+
|
239
|
+
it "fails if an unknown calculate action is specified" do
|
240
|
+
assert_raises(ArgumentError) { @field.set_calculate_action(:unknown) }
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
200
244
|
describe "validation" do
|
201
245
|
it "checks the value of the /FT field" do
|
202
246
|
@field.delete(:FT)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hexapdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.41.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Leitner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cmdparse
|
@@ -306,6 +306,7 @@ files:
|
|
306
306
|
- examples/028-frame_mask_mode.rb
|
307
307
|
- examples/029-composer_fallback_fonts.rb
|
308
308
|
- examples/030-pdfa.rb
|
309
|
+
- examples/031-acro_form_java_script.rb
|
309
310
|
- examples/emoji-smile.png
|
310
311
|
- examples/emoji-wink.png
|
311
312
|
- examples/machupicchu.jpg
|
@@ -429,6 +430,7 @@ files:
|
|
429
430
|
- lib/hexapdf/font_loader/from_configuration.rb
|
430
431
|
- lib/hexapdf/font_loader/from_file.rb
|
431
432
|
- lib/hexapdf/font_loader/standard14.rb
|
433
|
+
- lib/hexapdf/font_loader/variant_from_name.rb
|
432
434
|
- lib/hexapdf/image_loader.rb
|
433
435
|
- lib/hexapdf/image_loader/jpeg.rb
|
434
436
|
- lib/hexapdf/image_loader/pdf.rb
|
@@ -477,6 +479,7 @@ files:
|
|
477
479
|
- lib/hexapdf/type/acro_form/choice_field.rb
|
478
480
|
- lib/hexapdf/type/acro_form/field.rb
|
479
481
|
- lib/hexapdf/type/acro_form/form.rb
|
482
|
+
- lib/hexapdf/type/acro_form/java_script_actions.rb
|
480
483
|
- lib/hexapdf/type/acro_form/signature_field.rb
|
481
484
|
- lib/hexapdf/type/acro_form/text_field.rb
|
482
485
|
- lib/hexapdf/type/acro_form/variable_text_field.rb
|
@@ -698,6 +701,7 @@ files:
|
|
698
701
|
- test/hexapdf/font_loader/test_from_configuration.rb
|
699
702
|
- test/hexapdf/font_loader/test_from_file.rb
|
700
703
|
- test/hexapdf/font_loader/test_standard14.rb
|
704
|
+
- test/hexapdf/font_loader/test_variant_from_name.rb
|
701
705
|
- test/hexapdf/image_loader/test_jpeg.rb
|
702
706
|
- test/hexapdf/image_loader/test_pdf.rb
|
703
707
|
- test/hexapdf/image_loader/test_png.rb
|
@@ -748,6 +752,7 @@ files:
|
|
748
752
|
- test/hexapdf/type/acro_form/test_choice_field.rb
|
749
753
|
- test/hexapdf/type/acro_form/test_field.rb
|
750
754
|
- test/hexapdf/type/acro_form/test_form.rb
|
755
|
+
- test/hexapdf/type/acro_form/test_java_script_actions.rb
|
751
756
|
- test/hexapdf/type/acro_form/test_signature_field.rb
|
752
757
|
- test/hexapdf/type/acro_form/test_text_field.rb
|
753
758
|
- test/hexapdf/type/acro_form/test_variable_text_field.rb
|