hexapdf 0.35.0 → 0.35.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85a526812bcfbeae9fbe103513c3fac73ac2d736b2ac965305c8c1164fc976b7
4
- data.tar.gz: f999566105d0ac42c5037bf642256fd6c9a0c515bffb2329ef32456009b46dbd
3
+ metadata.gz: 4a7769176f4b753c876ecfb95a6cd2a954249388a7da9e308fbd8c25ba071c9b
4
+ data.tar.gz: f39b081ab1408fd08a3dff88f8aa3417283e98478b3e9fad60a692afb16e92c1
5
5
  SHA512:
6
- metadata.gz: 77d31b7c95a8ffd8c1189b062aac8dd7adc75a78ca3f1d8c91033401a1311b446a387c8c1b52932d5573d7721b5a6d4210433ac44d500fa3389dd17daf1be865
7
- data.tar.gz: 686e6e041a2723a54f1ff5acf0e46c9f7231b4ee5220f4dfe127579549c28c093f28c60ba4470d4be9fba0ccad0202905a57132f1e64596412308ab49b3ab1ed
6
+ metadata.gz: 21fcdbd57cdcf436edd1de50f0268d05573b92b70edd1eafeb00af0414eed3cbaa8f107ac1310419a29a113dc5a33ec991fa49a4fa0b47edea1bd2eb7afb0768
7
+ data.tar.gz: 0c6732024ebd325a4216fe8e4a2fdc69d51365b873ec53c926a9a1e575730cdb6d5f45eea5cd211c1cb2a21afd16cb75f3a1782411a2971eed7afe2f61708dfd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## 0.35.1 - 2024-01-11
2
+
3
+ ### Added
4
+
5
+ * [HexaPDF::Utils] module functions for float comparisons and using them instead
6
+ of the geom2d ones
7
+
8
+ ### Changed
9
+
10
+ * Pre-defined paper sizes of the ISO A, B and C series to be more precise
11
+
12
+ ### Fixed
13
+
14
+ * [HexaPDF::Layout::Box#fit] to use float comparison
15
+ * [HexaPDF::Type::IconFit] to use correct superclass
16
+
17
+
1
18
  ## 0.35.0 - 2024-01-06
2
19
 
3
20
  ### Added
@@ -384,7 +384,8 @@ module HexaPDF
384
384
  # composer.lorem_ipsum(sentences: 1, margin: [0, 0, 5])
385
385
  # composer.list(item_spacing: 2) do |list|
386
386
  # composer.document.config['layout.boxes.map'].each do |name, klass|
387
- # list.formatted_text([{text: name.to_s, fill_color: "hp-blue-dark"}, "\n#{klass}"])
387
+ # list.formatted_text([{text: name.to_s, fill_color: "hp-blue-dark"}, "\n#{klass}"],
388
+ # font_size: 8)
388
389
  # end
389
390
  # end
390
391
  #
@@ -118,7 +118,7 @@ module HexaPDF
118
118
  # composer.list(item_spacing: 2) do |list|
119
119
  # composer.document.config['layout.boxes.map'].each do |name, klass|
120
120
  # list.formatted_text([{text: name.to_s, fill_color: "hp-blue-dark"},
121
- # {text: "\n#{klass}", font_size: 7}])
121
+ # {text: "\n#{klass}"}, font_size: 7])
122
122
  # end
123
123
  # end
124
124
  # end
@@ -62,8 +62,7 @@ module HexaPDF
62
62
  # https://web.archive.org/web/20160310153722/https://www.w3.org/TR/SVG/implnote.html).
63
63
  class EndpointArc
64
64
 
65
- EPSILON = 1e-10 # :nodoc:
66
-
65
+ include Utils
67
66
  include Utils::MathHelpers
68
67
 
69
68
  # Creates and configures a new endpoint arc object.
@@ -283,7 +282,7 @@ module HexaPDF
283
282
 
284
283
  # F.6.5.2
285
284
  sqrt = (rxs * rys - rxs * y1ps - rys * x1ps) / (rxs * y1ps + rys * x1ps)
286
- sqrt = 0 if sqrt.abs < EPSILON
285
+ sqrt = 0 if sqrt.abs < Utils::EPSILON
287
286
  sqrt = Math.sqrt(sqrt)
288
287
  sqrt *= -1 unless @large_arc == @clockwise
289
288
  cxp = sqrt * rx * y1p / ry
@@ -303,11 +302,6 @@ module HexaPDF
303
302
  inclination: @inclination, clockwise: @clockwise, max_curves: @max_curves}
304
303
  end
305
304
 
306
- # Compares two float numbers if they are within a certain delta.
307
- def float_equal(a, b)
308
- (a - b).abs < EPSILON
309
- end
310
-
311
305
  # Computes the angle in degrees between the x-axis and the vector.
312
306
  def compute_angle_to_x_axis(vx, vy)
313
307
  (vy < 0 ? -1 : 1) * rad_to_deg(Math.acos(vx / Math.sqrt(vx**2 + vy**2)))
@@ -53,6 +53,7 @@ require 'hexapdf/image_loader'
53
53
  require 'hexapdf/font_loader'
54
54
  require 'hexapdf/layout'
55
55
  require 'hexapdf/digital_signature'
56
+ require 'hexapdf/utils'
56
57
 
57
58
  begin
58
59
  require 'hexapdf/cext'
@@ -84,7 +84,7 @@ module HexaPDF
84
84
  # which should just draw the content.
85
85
  class Box
86
86
 
87
- include Geom2D::Utils
87
+ include HexaPDF::Utils
88
88
 
89
89
  # Creates a new Box object, using the provided block as drawing block (see ::new).
90
90
  #
@@ -194,7 +194,8 @@ module HexaPDF
194
194
  def fit(available_width, available_height, _frame)
195
195
  @width = (@initial_width > 0 ? @initial_width : available_width)
196
196
  @height = (@initial_height > 0 ? @initial_height : available_height)
197
- @fit_successful = (@width <= available_width && @height <= available_height)
197
+ @fit_successful = (float_compare(@width, available_width) <= 0 &&
198
+ float_compare(@height, available_height) <= 0)
198
199
  end
199
200
 
200
201
  # Tries to split the box into two, the first of which needs to fit into the current region of
@@ -86,7 +86,7 @@ module HexaPDF
86
86
  # It is also possible to provide a different initial shape on initialization.
87
87
  class Frame
88
88
 
89
- include Geom2D::Utils
89
+ include HexaPDF::Utils
90
90
 
91
91
  # Stores the result of fitting a box in a Frame.
92
92
  class FitResult
@@ -42,7 +42,7 @@ module HexaPDF
42
42
  # Utility class for generating width specifications for TextLayouter#fit from polygons.
43
43
  class WidthFromPolygon
44
44
 
45
- include Geom2D::Utils
45
+ include HexaPDF::Utils
46
46
 
47
47
  # Creates a new object for the given polygon (or polygon set) and immediately prepares it so
48
48
  # that #call can be used.
@@ -34,7 +34,7 @@
34
34
  # commercial licenses are available at <https://gettalong.at/hexapdf/>.
35
35
  #++
36
36
 
37
- require 'hexapdf/type/annotation'
37
+ require 'hexapdf/dictionary'
38
38
 
39
39
  module HexaPDF
40
40
  module Type
@@ -43,7 +43,7 @@ module HexaPDF
43
43
  # rectangle.
44
44
  #
45
45
  # See: PDF2.0 s12.7.8.3.2
46
- class IconFit < Annotation
46
+ class IconFit < Dictionary
47
47
 
48
48
  define_type :XXIconFit
49
49
 
@@ -62,41 +62,41 @@ module HexaPDF
62
62
  # * ISO sizes: A0x4, A0x2, A0-A10, B0-B10, C0-C10
63
63
  # * Letter, Legal, Ledger, Tabloid, Executive
64
64
  PAPER_SIZE = {
65
- A0x4: [0, 0, 4768, 6741].freeze,
66
- A0x2: [0, 0, 3370, 4768].freeze,
67
- A0: [0, 0, 2384, 3370].freeze,
68
- A1: [0, 0, 1684, 2384].freeze,
69
- A2: [0, 0, 1191, 1684].freeze,
70
- A3: [0, 0, 842, 1191].freeze,
71
- A4: [0, 0, 595, 842].freeze,
72
- A5: [0, 0, 420, 595].freeze,
73
- A6: [0, 0, 298, 420].freeze,
74
- A7: [0, 0, 210, 298].freeze,
75
- A8: [0, 0, 147, 210].freeze,
76
- A9: [0, 0, 105, 147].freeze,
77
- A10: [0, 0, 74, 105].freeze,
78
- B0: [0, 0, 2835, 4008].freeze,
79
- B1: [0, 0, 2004, 2835].freeze,
80
- B2: [0, 0, 1417, 2004].freeze,
81
- B3: [0, 0, 1001, 1417].freeze,
82
- B4: [0, 0, 709, 1001].freeze,
83
- B5: [0, 0, 499, 709].freeze,
84
- B6: [0, 0, 354, 499].freeze,
85
- B7: [0, 0, 249, 354].freeze,
86
- B8: [0, 0, 176, 249].freeze,
87
- B9: [0, 0, 125, 176].freeze,
88
- B10: [0, 0, 88, 125].freeze,
89
- C0: [0, 0, 2599, 3677].freeze,
90
- C1: [0, 0, 1837, 2599].freeze,
91
- C2: [0, 0, 1298, 1837].freeze,
92
- C3: [0, 0, 918, 1298].freeze,
93
- C4: [0, 0, 649, 918].freeze,
94
- C5: [0, 0, 459, 649].freeze,
95
- C6: [0, 0, 323, 459].freeze,
96
- C7: [0, 0, 230, 323].freeze,
97
- C8: [0, 0, 162, 230].freeze,
98
- C9: [0, 0, 113, 162].freeze,
99
- C10: [0, 0, 79, 113].freeze,
65
+ A0x4: [0, 0, 4767.874016, 6740.787402].freeze,
66
+ A0x2: [0, 0, 3370.393701, 4767.874016].freeze,
67
+ A0: [0, 0, 2383.937008, 3370.393701].freeze,
68
+ A1: [0, 0, 1683.779528, 2383.937008].freeze,
69
+ A2: [0, 0, 1190.551181, 1683.779528].freeze,
70
+ A3: [0, 0, 841.889764, 1190.551181].freeze,
71
+ A4: [0, 0, 595.275591, 841.889764].freeze,
72
+ A5: [0, 0, 419.527559, 595.275591].freeze,
73
+ A6: [0, 0, 297.637795, 419.527559].freeze,
74
+ A7: [0, 0, 209.76378, 297.637795].freeze,
75
+ A8: [0, 0, 147.401575, 209.76378].freeze,
76
+ A9: [0, 0, 104.88189, 147.401575].freeze,
77
+ A10: [0, 0, 73.700787, 104.88189].freeze,
78
+ B0: [0, 0, 2834.645669, 4008.188976].freeze,
79
+ B1: [0, 0, 2004.094488, 2834.645669].freeze,
80
+ B2: [0, 0, 1417.322835, 2004.094488].freeze,
81
+ B3: [0, 0, 1000.629921, 1417.322835].freeze,
82
+ B4: [0, 0, 708.661417, 1000.629921].freeze,
83
+ B5: [0, 0, 498.897638, 708.661417].freeze,
84
+ B6: [0, 0, 354.330709, 498.897638].freeze,
85
+ B7: [0, 0, 249.448819, 354.330709].freeze,
86
+ B8: [0, 0, 175.748031, 249.448819].freeze,
87
+ B9: [0, 0, 124.724409, 175.748031].freeze,
88
+ B10: [0, 0, 87.874016, 124.724409].freeze,
89
+ C0: [0, 0, 2599.370079, 3676.535433].freeze,
90
+ C1: [0, 0, 1836.850394, 2599.370079].freeze,
91
+ C2: [0, 0, 1298.267717, 1836.850394].freeze,
92
+ C3: [0, 0, 918.425197, 1298.267717].freeze,
93
+ C4: [0, 0, 649.133858, 918.425197].freeze,
94
+ C5: [0, 0, 459.212598, 649.133858].freeze,
95
+ C6: [0, 0, 323.149606, 459.212598].freeze,
96
+ C7: [0, 0, 229.606299, 323.149606].freeze,
97
+ C8: [0, 0, 161.574803, 229.606299].freeze,
98
+ C9: [0, 0, 113.385827, 161.574803].freeze,
99
+ C10: [0, 0, 79.370079, 113.385827].freeze,
100
100
  Letter: [0, 0, 612, 792].freeze,
101
101
  Legal: [0, 0, 612, 1008].freeze,
102
102
  Ledger: [0, 0, 792, 1224].freeze,
@@ -0,0 +1,66 @@
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
+ #
3
+ #--
4
+ # This file is part of HexaPDF.
5
+ #
6
+ # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
+ # Copyright (C) 2014-2023 Thomas Leitner
8
+ #
9
+ # HexaPDF is free software: you can redistribute it and/or modify it
10
+ # under the terms of the GNU Affero General Public License version 3 as
11
+ # published by the Free Software Foundation with the addition of the
12
+ # following permission added to Section 15 as permitted in Section 7(a):
13
+ # FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
14
+ # THOMAS LEITNER, THOMAS LEITNER DISCLAIMS THE WARRANTY OF NON
15
+ # INFRINGEMENT OF THIRD PARTY RIGHTS.
16
+ #
17
+ # HexaPDF is distributed in the hope that it will be useful, but WITHOUT
18
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
20
+ # License for more details.
21
+ #
22
+ # You should have received a copy of the GNU Affero General Public License
23
+ # along with HexaPDF. If not, see <http://www.gnu.org/licenses/>.
24
+ #
25
+ # The interactive user interfaces in modified source and object code
26
+ # versions of HexaPDF must display Appropriate Legal Notices, as required
27
+ # under Section 5 of the GNU Affero General Public License version 3.
28
+ #
29
+ # In accordance with Section 7(b) of the GNU Affero General Public
30
+ # License, a covered work must retain the producer line in every PDF that
31
+ # is created or manipulated using HexaPDF.
32
+ #
33
+ # If the GNU Affero General Public License doesn't fit your need,
34
+ # commercial licenses are available at <https://gettalong.at/hexapdf/>.
35
+ #++
36
+
37
+ require 'geom2d/utils'
38
+
39
+ module HexaPDF
40
+ module Utils
41
+
42
+ # The precision with which to compare floating point numbers.
43
+ #
44
+ # This is chosen with respect to precision that is used for serializing floating point numbers.
45
+ EPSILON = 1e-6
46
+
47
+ # Best effort of setting Geom2D's precision to the one used by HexaPDF.
48
+ ::Geom2D::Utils.precision = EPSILON
49
+
50
+ module_function
51
+
52
+ private
53
+
54
+ # Compares two floats whether they are equal using the FLOAT_EPSILON precision.
55
+ def float_equal(a, b)
56
+ (a - b).abs < EPSILON
57
+ end
58
+
59
+ # Compares two floats like the <=> operator but using the FLOAT_EPSILON precision for detecting
60
+ # whether they are equal.
61
+ def float_compare(a, b)
62
+ (a - b).abs < EPSILON ? 0 : a <=> b
63
+ end
64
+
65
+ end
66
+ end
@@ -37,6 +37,6 @@
37
37
  module HexaPDF
38
38
 
39
39
  # The version of HexaPDF.
40
- VERSION = '0.35.0'
40
+ VERSION = '0.35.1'
41
41
 
42
42
  end
@@ -39,7 +39,7 @@ describe HexaPDF::Content::CanvasComposer do
39
39
  @composer.draw_box(create_box)
40
40
  assert_operators(@composer.canvas.contents,
41
41
  [[:save_graphics_state],
42
- [:concatenate_matrix, [1, 0, 0, 1, 0, 742]],
42
+ [:concatenate_matrix, [1, 0, 0, 1, 0, 741.889764]],
43
43
  [:restore_graphics_state],
44
44
  [:save_graphics_state],
45
45
  [:concatenate_matrix, [1, 0, 0, 1, 0, 0]],
@@ -58,10 +58,10 @@ describe HexaPDF::Content::CanvasComposer do
58
58
  [:concatenate_matrix, [1, 0, 0, 1, 0, 0]],
59
59
  [:restore_graphics_state],
60
60
  [:save_graphics_state],
61
- [:concatenate_matrix, [1, 0, 0, 1, 400, 742]],
61
+ [:concatenate_matrix, [1, 0, 0, 1, 400, 741.889764]],
62
62
  [:restore_graphics_state],
63
63
  [:save_graphics_state],
64
- [:concatenate_matrix, [1, 0, 0, 1, 400, 642]],
64
+ [:concatenate_matrix, [1, 0, 0, 1, 400, 641.889764]],
65
65
  [:restore_graphics_state]])
66
66
  end
67
67
 
@@ -70,10 +70,10 @@ describe HexaPDF::Content::CanvasComposer do
70
70
  @composer.draw_box(create_box(width: 400, height: 100))
71
71
  assert_operators(@composer.canvas.contents,
72
72
  [[:save_graphics_state],
73
- [:concatenate_matrix, [1, 0, 0, 1, 0, 742]],
73
+ [:concatenate_matrix, [1, 0, 0, 1, 0, 741.889764]],
74
74
  [:restore_graphics_state],
75
75
  [:save_graphics_state],
76
- [:concatenate_matrix, [1, 0, 0, 1, 0, 642]],
76
+ [:concatenate_matrix, [1, 0, 0, 1, 0, 641.889764]],
77
77
  [:restore_graphics_state]])
78
78
  end
79
79
 
@@ -17,20 +17,20 @@ describe HexaPDF::Document::Pages do
17
17
  describe "create" do
18
18
  it "uses the defaults from the configuration for missing arguments" do
19
19
  page = @doc.pages.create
20
- assert_equal([0, 0, 595, 842], page.box(:media).value)
20
+ assert_equal([0, 0, 595.275591, 841.889764], page.box(:media).value)
21
21
  end
22
22
 
23
23
  it "allows specifying a reference to a predefined page size" do
24
24
  page = @doc.pages.create(media_box: :A3)
25
- assert_equal([0, 0, 842, 1191], page.box(:media).value)
25
+ assert_equal([0, 0, 841.889764, 1190.551181], page.box(:media).value)
26
26
  end
27
27
 
28
28
  it "allows specifying the orientation for a predefined page size" do
29
29
  page = @doc.pages.create(media_box: :A4, orientation: :landscape)
30
- assert_equal([0, 0, 842, 595], page.box(:media).value)
30
+ assert_equal([0, 0, 841.889764, 595.275591], page.box(:media).value)
31
31
 
32
32
  page = @doc.pages.create(orientation: :landscape)
33
- assert_equal([0, 0, 842, 595], page.box(:media).value)
33
+ assert_equal([0, 0, 841.889764, 595.275591], page.box(:media).value)
34
34
  end
35
35
 
36
36
  it "allows using a media box array" do
@@ -54,7 +54,7 @@ describe HexaPDF::Document::Pages do
54
54
  it "adds a new empty page with the given page format" do
55
55
  page = @doc.pages.add(:A4, orientation: :landscape)
56
56
  assert_same(page, @doc.pages[0])
57
- assert_equal([0, 0, 842, 595], @doc.pages[0].box(:media).value)
57
+ assert_equal([0, 0, 841.889764, 595.275591], @doc.pages[0].box(:media).value)
58
58
  end
59
59
 
60
60
  it "adds the given page to the end" do
@@ -95,6 +95,13 @@ describe HexaPDF::Layout::Box do
95
95
  assert_equal(100, box.height)
96
96
  end
97
97
 
98
+ it "uses float comparison" do
99
+ box = create_box(width: 50.0000002, height: 49.9999996)
100
+ assert(box.fit(50, 50, @frame))
101
+ assert_equal(50.0000002, box.width)
102
+ assert_equal(49.9999996, box.height)
103
+ end
104
+
98
105
  it "returns false if the box doesn't fit" do
99
106
  box = create_box(width: 101)
100
107
  refute(box.fit(100, 100, @frame))
@@ -192,19 +192,19 @@ describe HexaPDF::Layout::ColumnBox do
192
192
  end
193
193
 
194
194
  it "takes a different final location into account" do
195
- box = create_box(children: @fixed_size_boxes[0, 2])
195
+ box = create_box(children: @fixed_size_boxes[0, 2], style: {padding: [2, 4, 6, 8]})
196
196
  box.fit(100, 100, @frame)
197
197
  box.draw(@canvas, 20, 10)
198
198
  operators = [
199
199
  [:save_graphics_state],
200
- [:concatenate_matrix, [1, 0, 0, 1, 20, -80]],
200
+ [:concatenate_matrix, [1, 0, 0, 1, 20, -72]],
201
201
  [:save_graphics_state],
202
- [:concatenate_matrix, [1, 0, 0, 1, 0, 90]],
202
+ [:concatenate_matrix, [1, 0, 0, 1, 8, 88]],
203
203
  [:move_to, [0, 0]],
204
204
  [:end_path],
205
205
  [:restore_graphics_state],
206
206
  [:save_graphics_state],
207
- [:concatenate_matrix, [1, 0, 0, 1, 55, 90]],
207
+ [:concatenate_matrix, [1, 0, 0, 1, 57, 88]],
208
208
  [:move_to, [0, 0]],
209
209
  [:end_path],
210
210
  [:restore_graphics_state],
@@ -35,7 +35,7 @@ describe HexaPDF::Layout::PageStyle do
35
35
  istyle.next_style = :other
36
36
  end
37
37
  page = style.create_page(@doc)
38
- assert_equal([0, 0, 595, 842], page.box(:media))
38
+ assert_equal([0, 0, 595.275591, 841.889764], page.box(:media))
39
39
  assert_equal("0 0 10 10 re\nS\n", page.contents)
40
40
  assert_equal(:frame, style.frame)
41
41
  assert_equal(:other, style.next_style)
@@ -54,8 +54,8 @@ describe HexaPDF::Layout::PageStyle do
54
54
  assert_kind_of(HexaPDF::Layout::Frame, style.frame)
55
55
  assert_equal(36, style.frame.left)
56
56
  assert_equal(36, style.frame.bottom)
57
- assert_equal(523, style.frame.width)
58
- assert_equal(770, style.frame.height)
57
+ assert_equal(523.275591, style.frame.width)
58
+ assert_equal(769.889764, style.frame.height)
59
59
  end
60
60
  end
61
61
 
@@ -65,7 +65,7 @@ describe HexaPDF::Layout::PageStyle do
65
65
  frame = style.create_frame(style.create_page(doc), [15, 10])
66
66
  assert_equal(10, frame.left)
67
67
  assert_equal(15, frame.bottom)
68
- assert_equal(575, frame.width)
69
- assert_equal(812, frame.height)
68
+ assert_equal(575.275591, frame.width)
69
+ assert_equal(811.889764, frame.height)
70
70
  end
71
71
  end
@@ -16,8 +16,8 @@ describe HexaPDF::Composer do
16
16
  assert_kind_of(HexaPDF::Type::Page, @composer.page)
17
17
  assert_equal(36, @composer.frame.left)
18
18
  assert_equal(36, @composer.frame.bottom)
19
- assert_equal(523, @composer.frame.width)
20
- assert_equal(770, @composer.frame.height)
19
+ assert_equal(523.275591, @composer.frame.width)
20
+ assert_equal(769.889764, @composer.frame.height)
21
21
  assert_kind_of(HexaPDF::Layout::Style, @composer.style(:base))
22
22
  end
23
23
 
@@ -28,15 +28,15 @@ describe HexaPDF::Composer do
28
28
 
29
29
  it "allows the customization of the page orientation" do
30
30
  composer = HexaPDF::Composer.new(page_orientation: :landscape)
31
- assert_equal([0, 0, 842, 595], composer.page.box.value)
31
+ assert_equal([0, 0, 841.889764, 595.275591], composer.page.box.value)
32
32
  end
33
33
 
34
34
  it "allows the customization of the margin" do
35
35
  composer = HexaPDF::Composer.new(margin: [100, 80, 60, 40])
36
36
  assert_equal(40, composer.frame.left)
37
37
  assert_equal(60, composer.frame.bottom)
38
- assert_equal(475, composer.frame.width)
39
- assert_equal(682, composer.frame.height)
38
+ assert_in_delta(475.275591, composer.frame.width)
39
+ assert_equal(681.889764, composer.frame.height)
40
40
  end
41
41
 
42
42
  it "allows skipping the initial page creation" do
@@ -107,7 +107,7 @@ describe HexaPDF::Composer do
107
107
  end
108
108
 
109
109
  it "returns the current y-position" do
110
- assert_equal(806, @composer.y)
110
+ assert_equal(805.889764, @composer.y)
111
111
  end
112
112
 
113
113
  describe "style" do
@@ -203,7 +203,7 @@ describe HexaPDF::Composer do
203
203
  @composer.draw_box(create_box)
204
204
  assert_operators(@composer.canvas.contents,
205
205
  [[:save_graphics_state],
206
- [:concatenate_matrix, [1, 0, 0, 1, 36, 706]],
206
+ [:concatenate_matrix, [1, 0, 0, 1, 36, 705.889764]],
207
207
  [:restore_graphics_state],
208
208
  [:save_graphics_state],
209
209
  [:concatenate_matrix, [1, 0, 0, 1, 36, 36]],
@@ -232,14 +232,14 @@ describe HexaPDF::Composer do
232
232
  @composer.draw_box(box)
233
233
  assert_operators(first_page_contents,
234
234
  [[:save_graphics_state],
235
- [:concatenate_matrix, [1, 0, 0, 1, 36, 406]],
235
+ [:concatenate_matrix, [1, 0, 0, 1, 36, 405.889764]],
236
236
  [:restore_graphics_state],
237
237
  [:save_graphics_state],
238
- [:concatenate_matrix, [1, 0, 0, 1, 36, 6]],
238
+ [:concatenate_matrix, [1, 0, 0, 1, 36, 5.889764]],
239
239
  [:restore_graphics_state]])
240
240
  assert_operators(@composer.canvas.contents,
241
241
  [[:save_graphics_state],
242
- [:concatenate_matrix, [1, 0, 0, 1, 36, 706]],
242
+ [:concatenate_matrix, [1, 0, 0, 1, 36, 705.889764]],
243
243
  [:restore_graphics_state]])
244
244
  end
245
245
 
@@ -252,14 +252,14 @@ describe HexaPDF::Composer do
252
252
  @composer.draw_box(box)
253
253
  assert_operators(first_page_contents,
254
254
  [[:save_graphics_state],
255
- [:concatenate_matrix, [1, 0, 0, 1, 36, 406]],
255
+ [:concatenate_matrix, [1, 0, 0, 1, 36, 405.889764]],
256
256
  [:restore_graphics_state],
257
257
  [:save_graphics_state],
258
- [:concatenate_matrix, [1, 0, 0, 1, 36, 306]],
258
+ [:concatenate_matrix, [1, 0, 0, 1, 36, 305.889764]],
259
259
  [:restore_graphics_state]])
260
260
  assert_operators(@composer.canvas.contents,
261
261
  [[:save_graphics_state],
262
- [:concatenate_matrix, [1, 0, 0, 1, 36, 406]],
262
+ [:concatenate_matrix, [1, 0, 0, 1, 36, 405.889764]],
263
263
  [:restore_graphics_state]])
264
264
  end
265
265
 
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'test_helper'
4
+ require 'hexapdf/utils.rb'
5
+
6
+ describe HexaPDF::Utils do
7
+ include HexaPDF::Utils
8
+
9
+ it "checks floats for equality with a certain precision" do
10
+ assert(float_equal(1.0, 1))
11
+ assert(float_equal(1.0, 1.0000003))
12
+ end
13
+
14
+ it "compares floats like the <=> operator" do
15
+ assert_equal(0, float_compare(1.0, 1))
16
+ assert_equal(0, float_compare(1.0, 1.0000003))
17
+ assert_equal(-1, float_compare(1.0, 1.03))
18
+ assert_equal(1, float_compare(1.0, 0.9997))
19
+ end
20
+ 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.35.0)>>
43
+ <</Producer(HexaPDF version 0.35.1)>>
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.35.0)>>
75
+ <</Producer(HexaPDF version 0.35.1)>>
76
76
  endobj
77
77
  2 0 obj
78
78
  <</Length 10>>stream
@@ -214,7 +214,7 @@ describe HexaPDF::Writer do
214
214
  <</Type/Page/MediaBox[0 0 595 842]/Parent 2 0 R/Resources<<>>>>
215
215
  endobj
216
216
  5 0 obj
217
- <</Producer(HexaPDF version 0.35.0)>>
217
+ <</Producer(HexaPDF version 0.35.1)>>
218
218
  endobj
219
219
  4 0 obj
220
220
  <</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
@@ -12,11 +12,11 @@ describe HexaPDF::Type::Page do
12
12
 
13
13
  describe "::media_box" do
14
14
  it "returns the media box for a given paper size" do
15
- assert_equal([0, 0, 595, 842], HexaPDF::Type::Page.media_box(:A4))
15
+ assert_equal([0, 0, 595.275591, 841.889764], HexaPDF::Type::Page.media_box(:A4))
16
16
  end
17
17
 
18
18
  it "respects the orientation key" do
19
- assert_equal([0, 0, 842, 595], HexaPDF::Type::Page.media_box(:A4, orientation: :landscape))
19
+ assert_equal([0, 0, 841.889764, 595.275591], HexaPDF::Type::Page.media_box(:A4, orientation: :landscape))
20
20
  end
21
21
 
22
22
  it "works with a paper size array" do
@@ -116,7 +116,7 @@ describe HexaPDF::Type::Page do
116
116
  page1[:MediaBox] = [0, 0, 1, 1]
117
117
  refute(page2.validate(auto_correct: false))
118
118
  assert(page2.validate)
119
- assert_equal([0, 0, 595, 842], page2[:MediaBox])
119
+ assert_equal([0, 0, 595.275591, 841.889764], page2[:MediaBox])
120
120
  end
121
121
  end
122
122
 
@@ -89,7 +89,7 @@ describe HexaPDF::Type::PageTreeNode do
89
89
  assert_equal(:Page, page[:Type])
90
90
  assert_equal(@root, page[:Parent])
91
91
  assert_kind_of(HexaPDF::Rectangle, page[:MediaBox])
92
- assert_equal([0, 0, 842, 595], page[:MediaBox].value)
92
+ assert_equal([0, 0, 841.889764, 595.275591], page[:MediaBox].value)
93
93
  assert_equal({}, page[:Resources].value)
94
94
  refute(@root.value.key?(:Parent))
95
95
  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.35.0
4
+ version: 0.35.1
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-01-06 00:00:00.000000000 Z
11
+ date: 2024-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmdparse
@@ -519,6 +519,7 @@ files:
519
519
  - lib/hexapdf/type/trailer.rb
520
520
  - lib/hexapdf/type/viewer_preferences.rb
521
521
  - lib/hexapdf/type/xref_stream.rb
522
+ - lib/hexapdf/utils.rb
522
523
  - lib/hexapdf/utils/bit_field.rb
523
524
  - lib/hexapdf/utils/bit_stream.rb
524
525
  - lib/hexapdf/utils/graphics_helpers.rb
@@ -728,6 +729,7 @@ files:
728
729
  - test/hexapdf/test_stream.rb
729
730
  - test/hexapdf/test_tokenizer.rb
730
731
  - test/hexapdf/test_type.rb
732
+ - test/hexapdf/test_utils.rb
731
733
  - test/hexapdf/test_writer.rb
732
734
  - test/hexapdf/test_xref_section.rb
733
735
  - test/hexapdf/type/acro_form/test_appearance_generator.rb