gamba 2.0.0 → 2.0.2

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.
@@ -94,6 +94,14 @@ module Prawn
94
94
 
95
95
  def issue_prawn_command(prawn, calls)
96
96
  calls.each do |call, arguments, kwarguments, children|
97
+ # Gamba: an infinite or NaN number, from a transform such as rotate(1e400), would be written into the page
98
+ # as NaN or Infinity, which no PDF reader parses: the call and what it holds are left out.
99
+ if non_finite?(arguments) || non_finite?(kwarguments)
100
+ warning = "#{call} left out: its arguments are not finite numbers"
101
+ document.warnings << warning unless document.warnings.include?(warning)
102
+ next
103
+ end
104
+
97
105
  skip = false
98
106
 
99
107
  rewrite_call_arguments(prawn, call, arguments, kwarguments, children) do
@@ -117,6 +125,15 @@ module Prawn
117
125
  end
118
126
  end
119
127
 
128
+ def non_finite?(value)
129
+ case value
130
+ when Float then !value.finite?
131
+ when Array then value.any? { non_finite?(_1) }
132
+ when Hash then value.each_value.any? { non_finite?(_1) }
133
+ else false
134
+ end
135
+ end
136
+
120
137
  def rewrite_call_arguments(prawn, call, arguments, kwarguments, children)
121
138
  case call
122
139
  when "svg:render"
@@ -223,13 +240,18 @@ module Prawn
223
240
  # Prawn's soft_mask hardcodes BBox to page.dimensions, which causes
224
241
  # Chrome and Firefox to clip mask content that extends beyond the page.
225
242
  # Temporarily override dimensions to use a large BBox.
243
+ # Gamba: a mask inside a mask finds the method defined already, and leaves it to the outer one to remove.
226
244
  def with_large_page_dimensions(prawn)
227
245
  page = prawn.state.page
246
+ return yield if page.singleton_class.method_defined?(:dimensions, false)
247
+
228
248
  large_bbox = [-10_000, -10_000, 10_000, 10_000]
229
249
  page.define_singleton_method(:dimensions) { large_bbox }
230
- yield
231
- ensure
232
- page.singleton_class.remove_method(:dimensions)
250
+ begin
251
+ yield
252
+ ensure
253
+ page.singleton_class.remove_method(:dimensions)
254
+ end
233
255
  end
234
256
 
235
257
  def inheritable_options
@@ -29,7 +29,8 @@ class Prawn::SVG::UrlLoader
29
29
 
30
30
  def perform_and_cache(url)
31
31
  data = perform(url)
32
- add_to_cache(url, data) if enable_cache
32
+ # Gamba: a data: URL decodes to the same bytes every time, and <use> can make a document load it thousands of times.
33
+ add_to_cache(url, data) if enable_cache || url[0, 5].casecmp?("data:")
33
34
  data
34
35
  end
35
36
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamba
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Level UP Solutions
@@ -9,6 +9,26 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: addressable
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 2.9.1
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '3'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: 2.9.1
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '3'
12
32
  - !ruby/object:Gem::Dependency
13
33
  name: css_parser
14
34
  requirement: !ruby/object:Gem::Requirement
@@ -63,9 +83,9 @@ dependencies:
63
83
  - - "<"
64
84
  - !ruby/object:Gem::Version
65
85
  version: '4'
66
- description: 'A drop-in replacement for prawn, prawn-table and prawn-svg: the same
67
- API and the same pages as Prawn 2.5, written faster, with fewer allocations and
68
- lighter files.'
86
+ description: 'Gamba is a Ruby library that writes PDF files. It is a faster rewrite
87
+ of Prawn 2.5, prawn-table and prawn-svg: code written for them runs unchanged and
88
+ draws the same pages, in lighter files.'
69
89
  executables: []
70
90
  extensions: []
71
91
  extra_rdoc_files: []
@@ -257,7 +277,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
257
277
  - !ruby/object:Gem::Version
258
278
  version: '0'
259
279
  requirements: []
260
- rubygems_version: 4.0.24
280
+ rubygems_version: 4.0.20
261
281
  specification_version: 4
262
- summary: 'Prawn''s API, rewritten for speed: same pages, lighter files'
282
+ summary: A faster rewrite of Prawn, prawn-table and prawn-svg that draws the same
283
+ pages
263
284
  test_files: []