hexapdf 0.29.0 → 0.31.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 +45 -0
- data/lib/hexapdf/cli/command.rb +16 -1
- data/lib/hexapdf/cli/info.rb +9 -1
- data/lib/hexapdf/cli/inspect.rb +2 -2
- data/lib/hexapdf/composer.rb +76 -28
- data/lib/hexapdf/configuration.rb +17 -4
- data/lib/hexapdf/dictionary_fields.rb +7 -2
- data/lib/hexapdf/document/pages.rb +31 -18
- data/lib/hexapdf/document.rb +8 -1
- data/lib/hexapdf/encryption/standard_security_handler.rb +2 -2
- data/lib/hexapdf/filter/flate_decode.rb +20 -8
- data/lib/hexapdf/layout/page_style.rb +144 -0
- data/lib/hexapdf/layout.rb +1 -0
- data/lib/hexapdf/task/optimize.rb +8 -6
- data/lib/hexapdf/type/font_simple.rb +14 -2
- data/lib/hexapdf/type/object_stream.rb +7 -2
- data/lib/hexapdf/type/outline.rb +1 -1
- data/lib/hexapdf/type/outline_item.rb +1 -1
- data/lib/hexapdf/type/page.rb +29 -8
- data/lib/hexapdf/type/xref_stream.rb +11 -4
- data/lib/hexapdf/version.rb +1 -1
- data/lib/hexapdf/writer.rb +1 -1
- data/test/hexapdf/document/test_pages.rb +25 -0
- data/test/hexapdf/encryption/test_standard_security_handler.rb +2 -2
- data/test/hexapdf/filter/test_flate_decode.rb +19 -5
- data/test/hexapdf/layout/test_page_style.rb +70 -0
- data/test/hexapdf/task/test_optimize.rb +11 -9
- data/test/hexapdf/test_composer.rb +35 -10
- data/test/hexapdf/test_dictionary_fields.rb +9 -4
- data/test/hexapdf/test_writer.rb +8 -8
- data/test/hexapdf/type/test_font_simple.rb +18 -6
- data/test/hexapdf/type/test_object_stream.rb +16 -7
- data/test/hexapdf/type/test_outline.rb +3 -1
- data/test/hexapdf/type/test_outline_item.rb +3 -1
- data/test/hexapdf/type/test_page.rb +42 -11
- data/test/hexapdf/type/test_xref_stream.rb +6 -1
- metadata +4 -2
@@ -123,12 +123,21 @@ describe HexaPDF::Type::ObjectStream do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
126
|
+
describe "perform_validation" do
|
127
|
+
it "fails validation if gen != 0" do
|
128
|
+
assert(@obj.validate(auto_correct: false))
|
129
|
+
@obj.gen = 1
|
130
|
+
refute(@obj.validate(auto_correct: false) do |msg, correctable|
|
131
|
+
assert_match(/invalid generation/, msg)
|
132
|
+
refute(correctable)
|
133
|
+
end)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "sets the /N and /First entries to dummy values so that validation works" do
|
137
|
+
@obj = HexaPDF::Type::ObjectStream.new({}, oid: 1, document: @doc)
|
138
|
+
assert(@obj.validate(auto_correct: false))
|
139
|
+
assert_equal(0, @obj[:N])
|
140
|
+
assert_equal(0, @obj[:First])
|
141
|
+
end
|
133
142
|
end
|
134
143
|
end
|
@@ -30,11 +30,12 @@ describe HexaPDF::Type::Outline do
|
|
30
30
|
|
31
31
|
describe "perform_validation" do
|
32
32
|
before do
|
33
|
-
5.times { @outline.add_item("Test1") }
|
33
|
+
@outline_items = 5.times.map { @outline.add_item("Test1") }
|
34
34
|
end
|
35
35
|
|
36
36
|
it "fixes a missing /First entry" do
|
37
37
|
@outline.delete(:First)
|
38
|
+
@outline_items[0][:Prev] = HexaPDF::Reference.new(100)
|
38
39
|
called = false
|
39
40
|
@outline.validate do |msg, correctable, _|
|
40
41
|
called = true
|
@@ -46,6 +47,7 @@ describe HexaPDF::Type::Outline do
|
|
46
47
|
|
47
48
|
it "fixes a missing /Last entry" do
|
48
49
|
@outline.delete(:Last)
|
50
|
+
@outline_items[4][:Next] = HexaPDF::Reference.new(100)
|
49
51
|
called = false
|
50
52
|
@outline.validate do |msg, correctable, _|
|
51
53
|
called = true
|
@@ -276,12 +276,13 @@ describe HexaPDF::Type::OutlineItem do
|
|
276
276
|
|
277
277
|
describe "perform_validation" do
|
278
278
|
before do
|
279
|
-
5.times { @item.add_item("Test1") }
|
279
|
+
@outline_items = 5.times.map { @item.add_item("Test1") }
|
280
280
|
@item[:Parent] = @doc.add({})
|
281
281
|
end
|
282
282
|
|
283
283
|
it "fixes a missing /First entry" do
|
284
284
|
@item.delete(:First)
|
285
|
+
@outline_items[0][:Prev] = HexaPDF::Reference.new(100)
|
285
286
|
called = false
|
286
287
|
@item.validate do |msg, correctable, _|
|
287
288
|
called = true
|
@@ -293,6 +294,7 @@ describe HexaPDF::Type::OutlineItem do
|
|
293
294
|
|
294
295
|
it "fixes a missing /Last entry" do
|
295
296
|
@item.delete(:Last)
|
297
|
+
@outline_items[4][:Next] = HexaPDF::Reference.new(100)
|
296
298
|
called = false
|
297
299
|
@item.validate do |msg, correctable, _|
|
298
300
|
called = true
|
@@ -19,9 +19,21 @@ describe HexaPDF::Type::Page do
|
|
19
19
|
assert_equal([0, 0, 842, 595], HexaPDF::Type::Page.media_box(:A4, orientation: :landscape))
|
20
20
|
end
|
21
21
|
|
22
|
+
it "works with a paper size array" do
|
23
|
+
assert_equal([0, 0, 842, 595], HexaPDF::Type::Page.media_box([0, 0, 842, 595]))
|
24
|
+
end
|
25
|
+
|
22
26
|
it "fails if the paper size is unknown" do
|
23
27
|
assert_raises(HexaPDF::Error) { HexaPDF::Type::Page.media_box(:Unknown) }
|
24
28
|
end
|
29
|
+
|
30
|
+
it "fails if the array doesn't contain four numbers" do
|
31
|
+
assert_raises(HexaPDF::Error) { HexaPDF::Type::Page.media_box([0, 1, 2]) }
|
32
|
+
end
|
33
|
+
|
34
|
+
it "fails if the array doesn't contain only numbers" do
|
35
|
+
assert_raises(HexaPDF::Error) { HexaPDF::Type::Page.media_box([0, 1, 2, 'a']) }
|
36
|
+
end
|
25
37
|
end
|
26
38
|
|
27
39
|
# Asserts that the page's contents contains the operators.
|
@@ -70,22 +82,41 @@ describe HexaPDF::Type::Page do
|
|
70
82
|
end
|
71
83
|
end
|
72
84
|
|
73
|
-
describe "
|
85
|
+
describe "perform_validation" do
|
74
86
|
it "only does validation if the page is in the document's page tree" do
|
75
87
|
page = @doc.add({Type: :Page})
|
88
|
+
assert(page.validate(auto_correct: false))
|
89
|
+
page[:Parent] = @doc.add({Type: :Pages, Kids: [page], Count: 1})
|
90
|
+
assert(page.validate(auto_correct: false))
|
91
|
+
@doc.pages.add(page)
|
92
|
+
refute(page.validate(auto_correct: false))
|
93
|
+
end
|
94
|
+
|
95
|
+
it "validates that the required inheritable field /Resources is set" do
|
96
|
+
page = @doc.pages.add
|
97
|
+
page.delete(:Resources)
|
98
|
+
refute(page.validate(auto_correct: false))
|
76
99
|
assert(page.validate)
|
77
|
-
|
78
|
-
assert(page.validate)
|
79
|
-
page[:Parent] = @doc.catalog.pages
|
80
|
-
refute(page.validate)
|
100
|
+
assert_kind_of(HexaPDF::Dictionary, page[:Resources])
|
81
101
|
end
|
82
102
|
|
83
|
-
it "
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
103
|
+
it "validates that the required inheritable field /MediaBox is set" do
|
104
|
+
page1 = @doc.pages.add(:Letter)
|
105
|
+
page2 = @doc.pages.add(:Letter)
|
106
|
+
page3 = @doc.pages.add(:Letter)
|
107
|
+
|
108
|
+
[page1, page2, page3].each do |page|
|
109
|
+
page.delete(:MediaBox)
|
110
|
+
refute(page.validate(auto_correct: false))
|
111
|
+
assert(page.validate)
|
112
|
+
assert_equal([0, 0, 612, 792], page[:MediaBox])
|
113
|
+
end
|
114
|
+
|
115
|
+
page2.delete(:MediaBox)
|
116
|
+
page1[:MediaBox] = [0, 0, 1, 1]
|
117
|
+
refute(page2.validate(auto_correct: false))
|
118
|
+
assert(page2.validate)
|
119
|
+
assert_equal([0, 0, 595, 842], page2[:MediaBox])
|
89
120
|
end
|
90
121
|
end
|
91
122
|
|
@@ -6,9 +6,10 @@ require 'hexapdf/type/xref_stream'
|
|
6
6
|
describe HexaPDF::Type::XRefStream do
|
7
7
|
before do
|
8
8
|
@doc = Object.new
|
9
|
+
@doc.instance_variable_set(:@version, '1.5')
|
9
10
|
def (@doc).deref(obj); obj; end
|
10
11
|
def (@doc).wrap(obj, **); obj; end
|
11
|
-
@obj = HexaPDF::Type::XRefStream.new({}, oid: 1, document: @doc)
|
12
|
+
@obj = HexaPDF::Type::XRefStream.new({}, oid: 1, document: @doc, stream: '')
|
12
13
|
end
|
13
14
|
|
14
15
|
describe "xref_section" do
|
@@ -141,4 +142,8 @@ describe HexaPDF::Type::XRefStream do
|
|
141
142
|
assert_raises(HexaPDF::Error) { @obj.update_with_xref_section_and_trailer(@section, {}) }
|
142
143
|
end
|
143
144
|
end
|
145
|
+
|
146
|
+
it "sets /Size and /W to dummy values to make validation work" do
|
147
|
+
assert(@obj.validate(auto_correct: false))
|
148
|
+
end
|
144
149
|
end
|
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.31.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: 2023-
|
11
|
+
date: 2023-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cmdparse
|
@@ -428,6 +428,7 @@ files:
|
|
428
428
|
- lib/hexapdf/layout/line.rb
|
429
429
|
- lib/hexapdf/layout/list_box.rb
|
430
430
|
- lib/hexapdf/layout/numeric_refinements.rb
|
431
|
+
- lib/hexapdf/layout/page_style.rb
|
431
432
|
- lib/hexapdf/layout/style.rb
|
432
433
|
- lib/hexapdf/layout/text_box.rb
|
433
434
|
- lib/hexapdf/layout/text_fragment.rb
|
@@ -679,6 +680,7 @@ files:
|
|
679
680
|
- test/hexapdf/layout/test_inline_box.rb
|
680
681
|
- test/hexapdf/layout/test_line.rb
|
681
682
|
- test/hexapdf/layout/test_list_box.rb
|
683
|
+
- test/hexapdf/layout/test_page_style.rb
|
682
684
|
- test/hexapdf/layout/test_style.rb
|
683
685
|
- test/hexapdf/layout/test_text_box.rb
|
684
686
|
- test/hexapdf/layout/test_text_fragment.rb
|