hexapdf 0.11.6 → 0.11.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60a5bf5332e0ebf949653852c2f77a7a78861b120bf0c5eed30ee6591cd0736e
4
- data.tar.gz: 79c8495ffcf48c4d81180ab9aa39e5ee12386f0a015ccef2460e453a879609d3
3
+ metadata.gz: 569e36409af92892e51daffa031686bc87db46bc846933ddb9f47c415fccfd3f
4
+ data.tar.gz: 88ad0152b80467b2f7936e2431b24091b8fa799b51094efcbfb467af04fb468e
5
5
  SHA512:
6
- metadata.gz: ded53b4977a8caafc8811b80f42fd0e137fed0af84072ee864a30f02ac729d5327f85840c2f7eb21426a5f3beee8caa6b2d40f91e0521180f161db8ccad86a48
7
- data.tar.gz: c1f7c2fb6e6fd2eacef1d11421768844471d0b048bf0eb36558f6a0a6426eed3438db1309aa17e3cd4e7a1e973affab946b52073c10ad7a37e0d9c3ce46cf3b8
6
+ metadata.gz: d49c7ae6f7bb2d17cf3124a10043b50d451e832f64fbf9cd6d852e00d00a6eb0fb47fedb624f97629404f5509b6126d4fdf04265164416adbb2020075b0dafd9
7
+ data.tar.gz: 2fa2a590c07c7e286ab4b57bd110618bab7b3e4f6bfbb00906c1df53e3314f23536644652ba6a143802ca2bc331bd8f1ffa58ee4fbda884ae020c9b517b7f652
@@ -1,3 +1,12 @@
1
+ ## 0.11.7 - 2020-06-10
2
+
3
+ ### Fixed
4
+
5
+ * Deletion of object streams in [HexaPDF::Task::Optimize] to avoid accessing
6
+ then invalid object streams
7
+ * [HexaPDF::Task::Optimize] to work correctly when deleting object streams and
8
+ generating xref streams
9
+
1
10
  ## 0.11.6 - 2020-05-27
2
11
 
3
12
  ### Fixed
@@ -127,13 +127,18 @@ module HexaPDF
127
127
  when :delete
128
128
  doc.revisions.each_with_index do |rev, rev_index|
129
129
  xref_stream = false
130
+ objects_to_delete = []
130
131
  rev.each do |obj|
131
- if obj.type == :ObjStm || (obj.type == :XRef && xref_streams == :delete)
132
- rev.delete(obj)
132
+ if obj.type == :ObjStm
133
+ objects_to_delete << obj
134
+ elsif obj.type == :XRef
135
+ xref_stream = true
136
+ objects_to_delete << obj if xref_streams == :delete
133
137
  else
134
138
  delete_fields_with_defaults(obj)
135
139
  end
136
140
  end
141
+ objects_to_delete.each {|obj| rev.delete(obj) }
137
142
  if xref_streams == :generate && !xref_stream
138
143
  doc.add({Type: :XRef}, revision: rev_index)
139
144
  end
@@ -143,11 +148,12 @@ module HexaPDF
143
148
  xref_stream = false
144
149
  count = 0
145
150
  objstms = [doc.wrap({Type: :ObjStm})]
151
+ old_objstms = []
146
152
  rev.each do |obj|
147
153
  if obj.type == :XRef
148
154
  xref_stream = true
149
155
  elsif obj.type == :ObjStm
150
- rev.delete(obj)
156
+ old_objstms << obj
151
157
  end
152
158
  delete_fields_with_defaults(obj)
153
159
 
@@ -160,6 +166,7 @@ module HexaPDF
160
166
  count = 0
161
167
  end
162
168
  end
169
+ old_objstms.each {|objstm| rev.delete(objstm) }
163
170
  objstms.each {|objstm| doc.add(objstm, revision: rev_index) }
164
171
  doc.add({Type: :XRef}, revision: rev_index) unless xref_stream
165
172
  end
@@ -37,6 +37,6 @@
37
37
  module HexaPDF
38
38
 
39
39
  # The version of HexaPDF.
40
- VERSION = '0.11.6'
40
+ VERSION = '0.11.7'
41
41
 
42
42
  end
@@ -7,13 +7,15 @@ require 'hexapdf/task/optimize'
7
7
  describe HexaPDF::Task::Optimize do
8
8
  class TestType < HexaPDF::Dictionary
9
9
 
10
+ define_type :Test
10
11
  define_field :Optional, type: Symbol, default: :Optional
11
12
 
12
13
  end
13
14
 
14
15
  before do
16
+ HexaPDF::GlobalConfiguration['object.type_map'][:Test] = TestType
15
17
  @doc = HexaPDF::Document.new
16
- @obj1 = @doc.add(@doc.wrap({Optional: :Optional}, type: TestType))
18
+ @obj1 = @doc.add({Type: :Test, Optional: :Optional})
17
19
  @doc.trailer[:Test] = @doc.wrap(@obj1)
18
20
  @doc.revisions.add
19
21
  @obj2 = @doc.add({Type: :UsedEntry})
@@ -22,6 +24,10 @@ describe HexaPDF::Task::Optimize do
22
24
  @obj1[:Test] = @doc.wrap(@obj4, type: TestType)
23
25
  end
24
26
 
27
+ after do
28
+ HexaPDF::GlobalConfiguration['object.type_map'].delete(:Test)
29
+ end
30
+
25
31
  def assert_objstms_generated
26
32
  assert(@doc.revisions.all? {|rev| rev.any? {|obj| obj.type == :ObjStm } })
27
33
  assert(@doc.revisions.all? {|rev| rev.any? {|obj| obj.type == :XRef } })
@@ -40,7 +46,7 @@ describe HexaPDF::Task::Optimize do
40
46
  end
41
47
 
42
48
  def assert_default_deleted
43
- refute(@obj1.value.key?(:Optional))
49
+ refute(@doc.object(1).key?(:Optional))
44
50
  end
45
51
 
46
52
  describe "compact" do
@@ -84,21 +90,29 @@ describe HexaPDF::Task::Optimize do
84
90
  end
85
91
 
86
92
  describe "object_streams" do
87
- it "generates object streams" do
93
+ def reload_document_with_objstm_from_io
94
+ io = StringIO.new
88
95
  objstm = @doc.add({Type: :ObjStm})
89
- xref = @doc.add({Type: :XRef})
96
+ @doc.add({Type: :XRef})
97
+ objstm.add_object(@doc.add({Type: :Test}))
98
+ @doc.write(io)
99
+ io.rewind
100
+ @doc = HexaPDF::Document.new(io: io)
101
+ end
102
+
103
+ it "generates object streams" do
90
104
  210.times { @doc.add(5) }
105
+ objstm = @doc.add({Type: :ObjStm})
106
+ reload_document_with_objstm_from_io
91
107
  @doc.task(:optimize, object_streams: :generate)
92
108
  assert_objstms_generated
93
109
  assert_default_deleted
94
110
  assert_nil(@doc.object(objstm).value)
95
- assert(3, @doc.revisions.current.find_all {|obj| obj.type == :ObjStm }.size)
96
- assert([xref], @doc.revisions.current.find_all {|obj| obj.type == :XRef })
111
+ assert_equal(2, @doc.revisions.current.find_all {|obj| obj.type == :ObjStm }.size)
97
112
  end
98
113
 
99
114
  it "deletes object and xref streams" do
100
- @doc.add({Type: :ObjStm})
101
- @doc.add({Type: :XRef})
115
+ reload_document_with_objstm_from_io
102
116
  @doc.task(:optimize, object_streams: :delete, xref_streams: :delete)
103
117
  assert_no_objstms
104
118
  assert_no_xrefstms
@@ -107,9 +121,11 @@ describe HexaPDF::Task::Optimize do
107
121
 
108
122
  it "deletes object and generates xref streams" do
109
123
  @doc.add({Type: :ObjStm})
124
+ xref = @doc.add({Type: :XRef})
110
125
  @doc.task(:optimize, object_streams: :delete, xref_streams: :generate)
111
126
  assert_no_objstms
112
127
  assert_xrefstms_generated
128
+ assert_equal([xref], @doc.revisions.current.find_all {|obj| obj.type == :XRef })
113
129
  assert_default_deleted
114
130
  end
115
131
  end
@@ -40,7 +40,7 @@ describe HexaPDF::Writer do
40
40
  219
41
41
  %%EOF
42
42
  3 0 obj
43
- <</Producer(HexaPDF version 0.11.6)>>
43
+ <</Producer(HexaPDF version 0.11.7)>>
44
44
  endobj
45
45
  xref
46
46
  3 1
@@ -72,7 +72,7 @@ describe HexaPDF::Writer do
72
72
  141
73
73
  %%EOF
74
74
  6 0 obj
75
- <</Producer(HexaPDF version 0.11.6)>>
75
+ <</Producer(HexaPDF version 0.11.7)>>
76
76
  endobj
77
77
  2 0 obj
78
78
  <</Length 10>>stream
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.11.6
4
+ version: 0.11.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Leitner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-27 00:00:00.000000000 Z
11
+ date: 2020-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmdparse