hexapdf 0.24.1 → 0.24.2

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: 9d7da895c4baff0d0e5114a6c423f3f6ca3de02004807d7f5a81c19e404edff1
4
- data.tar.gz: 89c6dd4709077bf6c6ccb710addeccfdf23a4a75d37dda4357f36c25d5f8865d
3
+ metadata.gz: d651940209b634c4f8c95924479f46dca2b49a458b731cd6bfba5ad95151c70d
4
+ data.tar.gz: aebe4ea9b21414b68483557f0f4cda0ea02ba17ae39bd58166c0864890c56691
5
5
  SHA512:
6
- metadata.gz: f5400d99a41fec977ba734bf487af5ce847bdea1f762a0f2df98b45f20952ee4059b08b75ff76ddb3e87db2191f1f7d18b01d9c1d8911b44fbdfc54ea2faa478
7
- data.tar.gz: f70679b7844a27d2da4f208900309b1820c39174923ab7d0645edbeddaa60455bd359a6e355c254e8764de013078d199846ec5ac443de3d39dd1abc4ad93c890
6
+ metadata.gz: 6d5fc26a440b93e140ae1cf761b969c9cb8c7b708db52674b3b8f785babfd4552f6682b536cae682570309d3f4b40fc8d26e8a9c933de271b7cd347a49334c07
7
+ data.tar.gz: 61b7303d84de7bd0851e6f60de62e8e25a5c772ad97837c2ab03962f220a06caae03cb05c668b233eb8fc0273e3232a9be6965d31ad9add1bf6c9ee979cb828e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 0.24.2 - 2022-08-31
2
+
3
+ ### Fixed
4
+
5
+ * [HexaPDF::Importer] to detect loops in a fully-loaded document
6
+ * HexaPDF::Type::PageTreeNode#perform_validation to only do the validation for
7
+ the document's root page tree node
8
+ * HexaPDF::Type::Page#perform_validation to only do the validation if the page
9
+ is part of the document's page tree
10
+ * Box layouting to take small floating point differences into account
11
+
12
+
1
13
  ## 0.24.1 - 2022-08-11
2
14
 
3
15
  ### Added
data/Rakefile CHANGED
@@ -47,7 +47,7 @@ namespace :dev do
47
47
  end
48
48
 
49
49
  task :test_all do
50
- versions = `rbenv versions --bare | grep -i 2.[67]\\\\\\|3.`.split("\n")
50
+ versions = `rbenv versions --bare | grep -i ^2.[67]\\\\\\|^3.`.split("\n")
51
51
  versions.each do |version|
52
52
  sh "eval \"$(rbenv init -)\"; rbenv shell #{version} && ruby -v && rake test"
53
53
  end
@@ -117,6 +117,8 @@ module HexaPDF
117
117
  when HexaPDF::Object
118
118
  if object.type == :Catalog || object.type == :Pages
119
119
  @mapper[object.data] = nil
120
+ elsif (mapped_object = @mapper[object.data]) && !mapped_object.null?
121
+ mapped_object
120
122
  else
121
123
  obj = object.dup
122
124
  @mapper[object.data] = NullableWeakRef.new(obj)
@@ -34,6 +34,7 @@
34
34
  # commercial licenses are available at <https://gettalong.at/hexapdf/>.
35
35
  #++
36
36
  require 'hexapdf/layout/style'
37
+ require 'geom2d/utils'
37
38
 
38
39
  module HexaPDF
39
40
  module Layout
@@ -76,6 +77,8 @@ module HexaPDF
76
77
  # which should just draw the content.
77
78
  class Box
78
79
 
80
+ include Geom2D::Utils
81
+
79
82
  # Creates a new Box object, using the provided block as drawing block (see ::new).
80
83
  #
81
84
  # If +content_box+ is +true+, the width and height are taken to mean the content width and
@@ -183,7 +186,9 @@ module HexaPDF
183
186
  def split(available_width, available_height, frame)
184
187
  if @fit_successful
185
188
  [self, nil]
186
- elsif (style.position != :flow && (@width > available_width || @height > available_height)) ||
189
+ elsif (style.position != :flow &&
190
+ (float_compare(@width, available_width) > 0 ||
191
+ float_compare(@height, available_height) > 0)) ||
187
192
  content_height == 0 || content_width == 0
188
193
  [nil, self]
189
194
  else
@@ -98,7 +98,8 @@ module HexaPDF
98
98
  @height = image_height * ratio + rh
99
99
  end
100
100
 
101
- @width <= available_width && @height <= available_height
101
+ @fit_successful = float_compare(@width, available_width) <= 0 &&
102
+ float_compare(@height, available_height) <= 0
102
103
  end
103
104
 
104
105
  private
@@ -564,6 +564,11 @@ module HexaPDF
564
564
 
565
565
  # Ensures that the required inheritable fields are set.
566
566
  def perform_validation(&block)
567
+ root_node = document.catalog.pages
568
+ parent_node = self[:Parent]
569
+ parent_node = parent_node[:Parent] while parent_node && parent_node != root_node
570
+ return unless parent_node
571
+
567
572
  super
568
573
  REQUIRED_INHERITABLE_FIELDS.each do |name|
569
574
  next if self[name]
@@ -265,7 +265,7 @@ module HexaPDF
265
265
  # page tree!
266
266
  def perform_validation(&block)
267
267
  super
268
- return if key?(:Parent)
268
+ return unless document.catalog[:Pages] == self
269
269
 
270
270
  validate_node = lambda do |node|
271
271
  count = 0
@@ -37,6 +37,6 @@
37
37
  module HexaPDF
38
38
 
39
39
  # The version of HexaPDF.
40
- VERSION = '0.24.1'
40
+ VERSION = '0.24.2'
41
41
 
42
42
  end
@@ -26,6 +26,7 @@ describe HexaPDF::Importer do
26
26
  @obj = @source.add({hash: @hash, array: ["one", "two"],
27
27
  ref: HexaPDF::Reference.new(obj.oid, obj.gen),
28
28
  others: [:symbol, 5, 5.5, nil, true, false]})
29
+ @obj[:MySelf] = @obj
29
30
  @source.pages.add
30
31
  @source.pages.root[:Rotate] = 90
31
32
  @dest = HexaPDF::Document.new
@@ -40,7 +40,7 @@ describe HexaPDF::Writer do
40
40
  219
41
41
  %%EOF
42
42
  3 0 obj
43
- <</Producer(HexaPDF version 0.24.1)>>
43
+ <</Producer(HexaPDF version 0.24.2)>>
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.24.1)>>
75
+ <</Producer(HexaPDF version 0.24.2)>>
76
76
  endobj
77
77
  2 0 obj
78
78
  <</Length 10>>stream
@@ -206,7 +206,7 @@ describe HexaPDF::Writer do
206
206
  <</Type/Page/MediaBox[0 0 595 842]/Parent 2 0 R/Resources<<>>>>
207
207
  endobj
208
208
  5 0 obj
209
- <</Producer(HexaPDF version 0.24.0)>>
209
+ <</Producer(HexaPDF version 0.24.2)>>
210
210
  endobj
211
211
  4 0 obj
212
212
  <</Root 1 0 R/Info 5 0 R/Size 6/Type/XRef/W[1 1 2]/Index[0 6]/Filter/FlateDecode/DecodeParms<</Columns 4/Predictor 12>>/Length 33>>stream
@@ -71,8 +71,17 @@ describe HexaPDF::Type::Page do
71
71
  end
72
72
 
73
73
  describe "validation" do
74
+ it "only does validation if the page is in the document's page tree" do
75
+ page = @doc.add({Type: :Page})
76
+ assert(page.validate)
77
+ page[:Parent] = @doc.add({Type: :Pages, Kids: [page]})
78
+ assert(page.validate)
79
+ page[:Parent] = @doc.catalog.pages
80
+ refute(page.validate)
81
+ end
82
+
74
83
  it "fails if a required inheritable field is not set" do
75
- root = @doc.add({Type: :Pages})
84
+ root = @doc.catalog[:Pages] = @doc.add({Type: :Pages})
76
85
  page = @doc.add({Type: :Page, Parent: root})
77
86
  message = ''
78
87
  refute(page.validate {|m, _| message = m })
@@ -7,7 +7,7 @@ require 'hexapdf/type/page_tree_node'
7
7
  describe HexaPDF::Type::PageTreeNode do
8
8
  before do
9
9
  @doc = HexaPDF::Document.new
10
- @root = @doc.add({Type: :Pages})
10
+ @root = @doc.catalog[:Pages] = @doc.add({Type: :Pages})
11
11
  end
12
12
 
13
13
  # Defines the following page tree:
@@ -283,6 +283,12 @@ describe HexaPDF::Type::PageTreeNode do
283
283
  end
284
284
 
285
285
  describe "validation" do
286
+ it "only does validation on the document's root node" do
287
+ @doc.catalog.delete(:Pages)
288
+ assert(@root.validate)
289
+ assert_equal(0, @root.page_count)
290
+ end
291
+
286
292
  it "corrects faulty /Count entries" do
287
293
  define_multilevel_page_tree
288
294
  root_count = @root.page_count
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.24.1
4
+ version: 0.24.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Leitner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-11 00:00:00.000000000 Z
11
+ date: 2022-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmdparse