hexapdf 0.45.0 → 0.46.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +87 -47
  3. data/examples/019-acro_form.rb +5 -0
  4. data/lib/hexapdf/cli/inspect.rb +5 -0
  5. data/lib/hexapdf/composer.rb +1 -1
  6. data/lib/hexapdf/configuration.rb +8 -0
  7. data/lib/hexapdf/digital_signature/cms_handler.rb +31 -3
  8. data/lib/hexapdf/digital_signature/signing/default_handler.rb +9 -1
  9. data/lib/hexapdf/digital_signature/signing/signed_data_creator.rb +5 -1
  10. data/lib/hexapdf/document/layout.rb +48 -27
  11. data/lib/hexapdf/document.rb +24 -2
  12. data/lib/hexapdf/importer.rb +15 -5
  13. data/lib/hexapdf/layout/box.rb +25 -28
  14. data/lib/hexapdf/layout/frame.rb +1 -1
  15. data/lib/hexapdf/layout/inline_box.rb +17 -23
  16. data/lib/hexapdf/layout/list_box.rb +24 -29
  17. data/lib/hexapdf/layout/page_style.rb +23 -16
  18. data/lib/hexapdf/layout/style.rb +2 -2
  19. data/lib/hexapdf/layout/text_box.rb +2 -6
  20. data/lib/hexapdf/parser.rb +5 -1
  21. data/lib/hexapdf/revisions.rb +1 -1
  22. data/lib/hexapdf/stream.rb +3 -3
  23. data/lib/hexapdf/tokenizer.rb +3 -2
  24. data/lib/hexapdf/type/acro_form/button_field.rb +2 -0
  25. data/lib/hexapdf/type/acro_form/choice_field.rb +2 -0
  26. data/lib/hexapdf/type/acro_form/field.rb +8 -0
  27. data/lib/hexapdf/type/acro_form/form.rb +2 -1
  28. data/lib/hexapdf/type/acro_form/text_field.rb +2 -0
  29. data/lib/hexapdf/version.rb +1 -1
  30. data/test/hexapdf/digital_signature/common.rb +66 -84
  31. data/test/hexapdf/digital_signature/signing/test_default_handler.rb +7 -0
  32. data/test/hexapdf/digital_signature/signing/test_signed_data_creator.rb +9 -0
  33. data/test/hexapdf/digital_signature/test_cms_handler.rb +41 -1
  34. data/test/hexapdf/digital_signature/test_handler.rb +2 -1
  35. data/test/hexapdf/document/test_layout.rb +28 -5
  36. data/test/hexapdf/layout/test_box.rb +12 -5
  37. data/test/hexapdf/layout/test_frame.rb +12 -2
  38. data/test/hexapdf/layout/test_inline_box.rb +17 -28
  39. data/test/hexapdf/layout/test_list_box.rb +5 -5
  40. data/test/hexapdf/layout/test_page_style.rb +7 -2
  41. data/test/hexapdf/layout/test_text_box.rb +3 -9
  42. data/test/hexapdf/layout/test_text_layouter.rb +0 -3
  43. data/test/hexapdf/test_document.rb +27 -0
  44. data/test/hexapdf/test_importer.rb +17 -0
  45. data/test/hexapdf/test_revisions.rb +54 -41
  46. data/test/hexapdf/type/acro_form/test_form.rb +9 -0
  47. metadata +2 -2
@@ -357,46 +357,59 @@ describe HexaPDF::Revisions do
357
357
  end
358
358
  end
359
359
 
360
- it "merges the two revisions of a linearized PDF into one" do
361
- io = StringIO.new(<<~EOF)
362
- %PDF-1.2
363
- 5 0 obj
364
- <</Linearized 1>>
365
- endobj
366
- xref
367
- 5 1
368
- 0000000009 00000 n
369
- trailer
370
- <</ID[(a)(b)]/Info 1 0 R/Root 2 0 R/Size 6/Prev 394>>
371
- %
372
- 1 0 obj
373
- <</ModDate(D:20221205233910+01'00')/Producer(HexaPDF version 0.27.0)>>
374
- endobj
375
- 2 0 obj
376
- <</Type/Catalog/Pages 3 0 R>>
377
- endobj
378
- 3 0 obj
379
- <</Type/Pages/Kids[4 0 R]/Count 1>>
380
- endobj
381
- 4 0 obj
382
- <</Type/Page/MediaBox[0 0 595 842]/Parent 3 0 R/Resources<<>>>>
383
- endobj
384
- xref
385
- 0 5
386
- 0000000000 65535 f
387
- 0000000133 00000 n
388
- 0000000219 00000 n
389
- 0000000264 00000 n
390
- 0000000315 00000 n
391
- trailer
392
- <</ID[(a)(b)]/Info 1 0 R/Root 2 0 R/Size 5>>
393
- startxref
394
- 41
395
- %%EOF
396
- EOF
397
- doc = HexaPDF::Document.new(io: io, config: {'parser.try_xref_reconstruction' => false})
398
- assert(doc.revisions.parser.linearized?)
399
- assert_equal(1, doc.revisions.count)
400
- assert_same(5, doc.revisions.current.xref_section.max_oid)
360
+ describe "linearzied PDFs" do
361
+ before do
362
+ @io = StringIO.new(<<~EOF)
363
+ %PDF-1.2
364
+ 5 0 obj
365
+ <</Linearized 1>>
366
+ endobj
367
+ xref
368
+ 5 1
369
+ 0000000009 00000 n
370
+ trailer
371
+ <</ID[(a)(b)]/Info 1 0 R/Root 2 0 R/Size 6/Prev 394>>
372
+ %
373
+ 1 0 obj
374
+ <</ModDate(D:20221205233910+01'00')/Producer(HexaPDF version 0.27.0)>>
375
+ endobj
376
+ 2 0 obj
377
+ <</Type/Catalog/Pages 3 0 R>>
378
+ endobj
379
+ 3 0 obj
380
+ <</Type/Pages/Kids[4 0 R]/Count 1>>
381
+ endobj
382
+ 4 0 obj
383
+ <</Type/Page/MediaBox[0 0 595 842]/Parent 3 0 R/Resources<<>>>>
384
+ endobj
385
+ xref
386
+ 0 5
387
+ 0000000000 65535 f
388
+ 0000000133 00000 n
389
+ 0000000219 00000 n
390
+ 0000000264 00000 n
391
+ 0000000315 00000 n
392
+ trailer
393
+ <</ID[(a)(b)]/Info 1 0 R/Root 2 0 R/Size 5>>
394
+ startxref
395
+ 41
396
+ %%EOF
397
+ EOF
398
+ end
399
+
400
+ it "merges the two revisions of a linearized PDF into one" do
401
+ doc = HexaPDF::Document.new(io: @io, config: {'parser.try_xref_reconstruction' => false})
402
+ assert(doc.revisions.parser.linearized?)
403
+ assert_equal(1, doc.revisions.count)
404
+ assert_same(5, doc.revisions.current.xref_section.max_oid)
405
+ end
406
+
407
+ it "works for a fake linearized PDF where the first xref section isn't actually used" do
408
+ @io.string[-9..-1] = "394\n%%EOF\n"
409
+ doc = HexaPDF::Document.new(io: @io, config: {'parser.try_xref_reconstruction' => false})
410
+ assert(doc.revisions.parser.linearized?)
411
+ assert_equal(1, doc.revisions.count)
412
+ assert_same(4, doc.revisions.current.xref_section.max_oid)
413
+ end
401
414
  end
402
415
  end
@@ -274,6 +274,15 @@ describe HexaPDF::Type::AcroForm::Form do
274
274
  assert(obj.null?)
275
275
  end
276
276
 
277
+ it "deletes a field with an embedded widget annotation" do
278
+ widget = @field.create_widget(@doc.pages.add, Rect: [0, 0, 0, 0])
279
+ assert_equal(widget, @field)
280
+ refute(@doc.pages[0][:Annots].empty?)
281
+ @acro_form.delete_field(@field)
282
+ assert(@doc.pages[0][:Annots].empty?)
283
+ assert(@field.null?)
284
+ end
285
+
277
286
  it "deletes all widget annotations from the document and the annotation array" do
278
287
  widget1 = @field.create_widget(@doc.pages.add, Rect: [0, 0, 0, 0])
279
288
  widget2 = @field.create_widget(@doc.pages.add, Rect: [0, 0, 0, 0])
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.45.0
4
+ version: 0.46.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-06-18 00:00:00.000000000 Z
11
+ date: 2024-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmdparse