gamba 2.0.1 → 2.1.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 +46 -1
- data/README.md +159 -30
- data/lib/gamba/annotations.rb +5 -0
- data/lib/gamba/barcodes/data_matrix.rb +204 -0
- data/lib/gamba/barcodes/linear.rb +182 -0
- data/lib/gamba/barcodes/qr_code.rb +339 -0
- data/lib/gamba/barcodes.rb +136 -0
- data/lib/gamba/combine.rb +13 -135
- data/lib/gamba/copier.rb +107 -0
- data/lib/gamba/document/internals.rb +5 -1
- data/lib/gamba/document.rb +33 -4
- data/lib/gamba/font.rb +7 -3
- data/lib/gamba/fonts/afm.rb +3 -2
- data/lib/gamba/fonts/ttf.rb +26 -20
- data/lib/gamba/images.rb +23 -1
- data/lib/gamba/imported_page.rb +137 -0
- data/lib/gamba/minitest.rb +35 -0
- data/lib/gamba/native/band.rb +56 -0
- data/lib/gamba/native/document.rb +122 -0
- data/lib/gamba/native/layout.rb +1063 -0
- data/lib/gamba/native/table.rb +189 -0
- data/lib/gamba/page_boxes.rb +68 -0
- data/lib/gamba/pdf/reader.rb +8 -2
- data/lib/gamba/pdf_a.rb +61 -20
- data/lib/gamba/pdf_check.rb +220 -0
- data/lib/gamba/railtie.rb +52 -0
- data/lib/gamba/rspec.rb +58 -0
- data/lib/gamba/table/cell/kinds.rb +45 -5
- data/lib/gamba/table/cell.rb +37 -0
- data/lib/gamba/table.rb +10 -0
- data/lib/gamba/tagging.rb +302 -0
- data/lib/gamba/testing.rb +79 -0
- data/lib/gamba/text/formatted/box.rb +5 -0
- data/lib/gamba/text/formatted/wrap.rb +1 -1
- data/lib/gamba/true_type/open_type_layout.rb +44 -17
- data/lib/gamba/true_type/simple_subsets.rb +11 -7
- data/lib/gamba/version.rb +1 -1
- data/lib/gamba.rb +18 -1
- data/lib/prawn/svg/document.rb +50 -16
- data/lib/prawn/svg/elements/image.rb +19 -4
- data/lib/prawn/svg/elements/text_component.rb +29 -26
- data/lib/prawn/svg/elements/use.rb +2 -2
- data/lib/prawn/svg/url_loader.rb +2 -1
- metadata +44 -5
|
@@ -17,33 +17,62 @@ module Gamba
|
|
|
17
17
|
@features = features.map(&:to_s)
|
|
18
18
|
@ligatures_by_first_glyph = read_ligatures
|
|
19
19
|
@pair_lookups = read_pair_lookups
|
|
20
|
+
@kerning_by_pair = {}
|
|
20
21
|
end
|
|
21
22
|
|
|
22
|
-
# Glyphs and the characters each stands for, ligatures applied: [[glyph, [code, …]], …]
|
|
23
|
+
# Glyphs and the characters each stands for, ligatures applied: [[glyph, code or [code, …]], …], a glyph
|
|
24
|
+
# standing for one character carrying its code alone, as unshaped text does.
|
|
23
25
|
def shape(codes)
|
|
24
|
-
clusters = codes.map { |code| [@file.glyph_by_code[code], [code]] }
|
|
25
|
-
return clusters if @ligatures_by_first_glyph.empty?
|
|
26
|
-
|
|
27
26
|
shaped = []
|
|
27
|
+
each_glyph(codes) { |glyph, index, length| shaped << [glyph, self.class.cluster_codes(codes, index, length)] }
|
|
28
|
+
shaped
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.cluster_codes(codes, index, length)
|
|
32
|
+
(length == 1) ? codes[index] : codes[index, length]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Each glyph, ligatures applied, with the index of its first character and how many it stands for. Text is
|
|
36
|
+
# measured word by word: this builds nothing for the glyphs of a word.
|
|
37
|
+
def each_glyph(codes)
|
|
38
|
+
glyph_by_code = @file.glyph_by_code
|
|
28
39
|
index = 0
|
|
29
|
-
while index <
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
end
|
|
40
|
+
while index < codes.size
|
|
41
|
+
glyph = glyph_by_code[codes[index]]
|
|
42
|
+
ligature = ligature_at(codes, index, glyph, glyph_by_code)
|
|
33
43
|
if ligature
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
index += components.size + 1
|
|
44
|
+
length = ligature[0].size + 1
|
|
45
|
+
yield ligature[1], index, length
|
|
37
46
|
else
|
|
38
|
-
|
|
39
|
-
index
|
|
47
|
+
length = 1
|
|
48
|
+
yield glyph, index, length
|
|
40
49
|
end
|
|
50
|
+
index += length
|
|
41
51
|
end
|
|
42
|
-
shaped
|
|
43
52
|
end
|
|
44
53
|
|
|
45
|
-
# The horizontal advance adjustment between two glyphs, in font units, or nil.
|
|
54
|
+
# The horizontal advance adjustment between two glyphs, in font units, or nil. Each pair is read from the
|
|
55
|
+
# font once: a document kerns the same pairs over and over.
|
|
46
56
|
def kerning(left, right)
|
|
57
|
+
pair = (left << 16) | right
|
|
58
|
+
adjustment = @kerning_by_pair.fetch(pair) { @kerning_by_pair[pair] = pair_adjustment(left, right) || false }
|
|
59
|
+
adjustment || nil
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
# The longest ligature starting with this glyph whose other components follow it: [components, glyph].
|
|
65
|
+
def ligature_at(codes, index, glyph, glyph_by_code)
|
|
66
|
+
@ligatures_by_first_glyph[glyph]&.find do |components, _ligature_glyph|
|
|
67
|
+
next false if index + components.size >= codes.size
|
|
68
|
+
|
|
69
|
+
matched = 0
|
|
70
|
+
matched += 1 while matched < components.size && glyph_by_code[codes[index + 1 + matched]] == components[matched]
|
|
71
|
+
matched == components.size
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def pair_adjustment(left, right)
|
|
47
76
|
@pair_lookups.each do |lookup|
|
|
48
77
|
adjustment = lookup.call(left, right)
|
|
49
78
|
return adjustment if adjustment
|
|
@@ -51,8 +80,6 @@ module Gamba
|
|
|
51
80
|
nil
|
|
52
81
|
end
|
|
53
82
|
|
|
54
|
-
private
|
|
55
|
-
|
|
56
83
|
def read_ligatures
|
|
57
84
|
table = @file.table("GSUB")
|
|
58
85
|
return {} unless table && @features.include?("liga")
|
|
@@ -14,6 +14,7 @@ module Gamba
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
SPACE = 32
|
|
17
|
+
SPACE_CLUSTER = [SPACE].freeze
|
|
17
18
|
FIRST_FREE_CODE = 33
|
|
18
19
|
|
|
19
20
|
def initialize(glyph_for_cluster)
|
|
@@ -33,16 +34,19 @@ module Gamba
|
|
|
33
34
|
# [[subset index, bytes], …] for clusters of characters, each cluster [glyph, codes].
|
|
34
35
|
def encode(clusters)
|
|
35
36
|
parts = []
|
|
36
|
-
clusters.each
|
|
37
|
-
if !parts.empty? && (codes == [SPACE] || codes == SPACE) && glyph == @subsets[0].glyph_by_code[SPACE]
|
|
38
|
-
parts.last[1] << SPACE
|
|
39
|
-
else
|
|
40
|
-
append(parts, *(@location_by_cluster[codes] ||= code_for([glyph, codes])))
|
|
41
|
-
end
|
|
42
|
-
end
|
|
37
|
+
clusters.each { |glyph, codes| append_cluster(parts, glyph, codes) }
|
|
43
38
|
parts
|
|
44
39
|
end
|
|
45
40
|
|
|
41
|
+
# Adds one cluster's code to parts: [[subset index, bytes], …].
|
|
42
|
+
def append_cluster(parts, glyph, codes)
|
|
43
|
+
if !parts.empty? && (codes == SPACE || codes == SPACE_CLUSTER) && glyph == @subsets[0].glyph_by_code[SPACE]
|
|
44
|
+
parts.last[1] << SPACE
|
|
45
|
+
else
|
|
46
|
+
append(parts, *(@location_by_cluster[codes] ||= code_for([glyph, codes])))
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
46
50
|
# The same for single characters, by code point: the common case, where a character already given its code
|
|
47
51
|
# costs a single hash access, and its glyph is only looked up the first time.
|
|
48
52
|
def encode_codepoints(codepoints, glyph_by_code)
|
data/lib/gamba/version.rb
CHANGED
data/lib/gamba.rb
CHANGED
|
@@ -55,6 +55,7 @@ require_relative "gamba/view"
|
|
|
55
55
|
require_relative "gamba/images"
|
|
56
56
|
require_relative "gamba/images/png_decoder"
|
|
57
57
|
require_relative "gamba/images/image"
|
|
58
|
+
require_relative "gamba/barcodes"
|
|
58
59
|
require_relative "gamba/repeater"
|
|
59
60
|
require_relative "gamba/grid"
|
|
60
61
|
require_relative "gamba/outline"
|
|
@@ -64,6 +65,7 @@ require_relative "gamba/table/cell"
|
|
|
64
65
|
require_relative "gamba/table/cell/kinds"
|
|
65
66
|
require_relative "gamba/security"
|
|
66
67
|
require_relative "gamba/pdf_a"
|
|
68
|
+
require_relative "gamba/tagging"
|
|
67
69
|
require_relative "gamba/pdf_a/srgb_profile"
|
|
68
70
|
require_relative "gamba/document/internals"
|
|
69
71
|
require_relative "gamba/document/bounding_box"
|
|
@@ -98,6 +100,19 @@ end
|
|
|
98
100
|
|
|
99
101
|
module Gamba
|
|
100
102
|
autoload :Combine, ::File.expand_path("gamba/combine", __dir__)
|
|
103
|
+
autoload :Copier, ::File.expand_path("gamba/copier", __dir__)
|
|
104
|
+
autoload :ImportedPage, ::File.expand_path("gamba/imported_page", __dir__)
|
|
105
|
+
autoload :PageBoxes, ::File.expand_path("gamba/page_boxes", __dir__)
|
|
106
|
+
autoload :Document, ::File.expand_path("gamba/native/document", __dir__)
|
|
107
|
+
autoload :Layout, ::File.expand_path("gamba/native/layout", __dir__)
|
|
108
|
+
|
|
109
|
+
# A document written with Gamba's own API: Gamba.document(page_size: "A4") { |document| document.text "Hello" }.
|
|
110
|
+
# See Gamba::Document::OPTIONS for the options; Prawn's API stays reachable through Gamba::Document#prawn.
|
|
111
|
+
def self.document(**options)
|
|
112
|
+
document = Document.new(**options)
|
|
113
|
+
yield document if block_given?
|
|
114
|
+
document
|
|
115
|
+
end
|
|
101
116
|
|
|
102
117
|
# The pages of other PDF files, one after the other in a new one:
|
|
103
118
|
# Gamba.combine([label, label], page_size: [288, 432]). See Gamba::Combine#initialize for the options.
|
|
@@ -108,7 +123,7 @@ module Gamba
|
|
|
108
123
|
# Loads what Gamba otherwise loads on first use, SVG support included: call it before a server forks its
|
|
109
124
|
# workers, so they share that memory instead of each loading its own copy.
|
|
110
125
|
def self.eager_load!
|
|
111
|
-
[TrueType::File, TrueType::Subset, Prawn::Fonts::TTF, Combine, PDF::Core::Reader]
|
|
126
|
+
[TrueType::File, TrueType::Subset, Prawn::Fonts::TTF, Combine, ImportedPage, Barcodes::QRCode, PDF::Core::Reader, Document]
|
|
112
127
|
require "prawn-svg"
|
|
113
128
|
end
|
|
114
129
|
end
|
|
@@ -122,3 +137,5 @@ end
|
|
|
122
137
|
|
|
123
138
|
Prawn.image_handler.register(Prawn::Images::JPG)
|
|
124
139
|
Prawn.image_handler.register(Prawn::Images::PNG)
|
|
140
|
+
|
|
141
|
+
require_relative "gamba/railtie" if defined?(Rails::Railtie)
|
data/lib/prawn/svg/document.rb
CHANGED
|
@@ -10,6 +10,8 @@ class Prawn::SVG::Document
|
|
|
10
10
|
MAXIMUM_ELEMENTS_THROUGH_USE = 20_000
|
|
11
11
|
# Elements inside one another: deeper, Ruby's stack runs out, and REXML resolves each namespace by its ancestors.
|
|
12
12
|
MAXIMUM_DEPTH = 256
|
|
13
|
+
# SVG images inside SVG images: over the web, an SVG can embed itself without end.
|
|
14
|
+
MAXIMUM_EMBEDDING_DEPTH = 16
|
|
13
15
|
|
|
14
16
|
class << self
|
|
15
17
|
attr_accessor :enable_web_requests_warned
|
|
@@ -26,19 +28,20 @@ class Prawn::SVG::Document
|
|
|
26
28
|
:elements_by_id, :gradients,
|
|
27
29
|
:element_styles,
|
|
28
30
|
:color_mode,
|
|
29
|
-
:external_svg_cache
|
|
31
|
+
:external_svg_cache,
|
|
32
|
+
:embedding_depth,
|
|
33
|
+
:raster_dimensions_by_data
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
# Gamba: embedder is the document whose <image> embeds this one, for the budgets they share.
|
|
36
|
+
def initialize(data, bounds, options, font_registry: nil, css_parser: CssParser::Parser.new, attribute_overrides: {}, embedder: nil)
|
|
32
37
|
begin
|
|
33
|
-
@root =
|
|
38
|
+
@root = self.class.parse(data) or raise_parse_error(data)
|
|
34
39
|
rescue REXML::ParseException => e
|
|
35
40
|
raise_parse_error(data, e.message)
|
|
36
|
-
rescue RuntimeError => e
|
|
37
|
-
# Gamba: REXML's entity expansion limits raise a bare RuntimeError.
|
|
38
|
-
raise InvalidSVGData, "The data supplied is not a valid SVG document: #{e.message}"
|
|
39
41
|
end
|
|
40
|
-
check_tree!(@root)
|
|
41
42
|
|
|
43
|
+
@embedder = embedder
|
|
44
|
+
@embedding_depth = embedder ? embedder.embedding_depth + 1 : 0
|
|
42
45
|
@warnings = []
|
|
43
46
|
@options = options
|
|
44
47
|
@elements_by_id = {}
|
|
@@ -48,6 +51,7 @@ class Prawn::SVG::Document
|
|
|
48
51
|
@depth = 0
|
|
49
52
|
@gradients = Prawn::SVG::Gradients.new(self)
|
|
50
53
|
@external_svg_cache = {}
|
|
54
|
+
@raster_dimensions_by_data = {}.compare_by_identity
|
|
51
55
|
@fallback_font_name = options.fetch(:fallback_font_name, DEFAULT_FALLBACK_FONT_NAME)
|
|
52
56
|
@font_registry = font_registry
|
|
53
57
|
@color_mode = load_color_mode
|
|
@@ -96,26 +100,54 @@ class Prawn::SVG::Document
|
|
|
96
100
|
def drawing_through_use(source)
|
|
97
101
|
raise Prawn::SVG::Elements::Base::SkipElementError, "use tag references an element that contains it" if @references_in_use.any? { _1.equal?(source) }
|
|
98
102
|
|
|
99
|
-
|
|
100
|
-
source.each_recursive { @elements_through_use += 1 }
|
|
101
|
-
raise Prawn::SVG::Elements::Base::SkipElementError, "use tags draw more than #{MAXIMUM_ELEMENTS_THROUGH_USE} elements" if @elements_through_use > MAXIMUM_ELEMENTS_THROUGH_USE
|
|
102
|
-
|
|
103
|
+
draw_again(self.class.element_count(source))
|
|
103
104
|
@references_in_use << source
|
|
104
105
|
yield
|
|
105
106
|
ensure
|
|
106
107
|
@references_in_use.pop if @references_in_use.last.equal?(source)
|
|
107
108
|
end
|
|
108
109
|
|
|
109
|
-
# Gamba:
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
# Gamba: elements drawn once more, counted against one budget for this document and the SVG images it embeds.
|
|
111
|
+
def draw_again(element_count)
|
|
112
|
+
return @embedder.draw_again(element_count) if @embedder
|
|
113
|
+
|
|
114
|
+
@elements_through_use += element_count
|
|
115
|
+
raise Prawn::SVG::Elements::Base::SkipElementError, "use tags and SVG images draw more than #{MAXIMUM_ELEMENTS_THROUGH_USE} elements" if @elements_through_use > MAXIMUM_ELEMENTS_THROUGH_USE
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def self.element_count(source)
|
|
119
|
+
count = 1
|
|
120
|
+
source.each_recursive { count += 1 }
|
|
121
|
+
count
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Gamba: the root of an SVG, checked before anything walks it: the document's own, and every SVG it loads with
|
|
125
|
+
# <use> or <image>. REXML's limits on entity expansion raise a bare RuntimeError.
|
|
126
|
+
def self.parse(data)
|
|
127
|
+
root = REXML::Document.new(data).root
|
|
128
|
+
check_tree!(root) if root
|
|
129
|
+
root
|
|
130
|
+
rescue REXML::ParseException
|
|
131
|
+
raise
|
|
132
|
+
rescue RuntimeError => e
|
|
133
|
+
raise InvalidSVGData, "The data supplied is not a valid SVG document: #{e.message}"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Gamba: walked without recursion. Texts and attributes expand their entities here, so that REXML's limits on
|
|
137
|
+
# expansion raise InvalidSVGData rather than a RuntimeError mid-render.
|
|
138
|
+
def self.check_tree!(root)
|
|
112
139
|
level = [root]
|
|
113
140
|
MAXIMUM_DEPTH.times do
|
|
114
|
-
level.each
|
|
141
|
+
level.each do |element|
|
|
142
|
+
element.texts.each(&:value)
|
|
143
|
+
element.attributes.each_attribute(&:value)
|
|
144
|
+
end
|
|
115
145
|
level = level.flat_map { _1.elements.to_a }
|
|
116
146
|
return if level.empty?
|
|
117
147
|
end
|
|
118
148
|
raise InvalidSVGData, "The SVG document nests elements deeper than #{MAXIMUM_DEPTH} levels"
|
|
149
|
+
rescue REXML::ParseException
|
|
150
|
+
raise
|
|
119
151
|
rescue RuntimeError => e
|
|
120
152
|
raise InvalidSVGData, "The data supplied is not a valid SVG document: #{e.message}"
|
|
121
153
|
end
|
|
@@ -199,10 +231,12 @@ class Prawn::SVG::Document
|
|
|
199
231
|
tempfile.write(data)
|
|
200
232
|
tempfile.close
|
|
201
233
|
@font_face_tempfiles << tempfile
|
|
234
|
+
# Gamba: read now, so that a damaged font is a warning like a missing one, not an error mid-render.
|
|
235
|
+
Gamba::TrueType::File.open(tempfile.path).glyph_by_code
|
|
202
236
|
|
|
203
237
|
font_registry.register_font_face(family, weight, style, stretch, tempfile.path)
|
|
204
238
|
true
|
|
205
|
-
rescue Prawn::SVG::UrlLoader::Error => e
|
|
239
|
+
rescue Prawn::SVG::UrlLoader::Error, Gamba::TrueType::Error => e
|
|
206
240
|
warnings << "Failed to load @font-face font from #{source[:url]}: #{e.message}"
|
|
207
241
|
false
|
|
208
242
|
end
|
|
@@ -82,10 +82,11 @@ class Prawn::SVG::Elements::Image < Prawn::SVG::Elements::Base
|
|
|
82
82
|
|
|
83
83
|
def process_image(data, width, height, preserve_aspect_ratio)
|
|
84
84
|
if (handler = find_image_handler(data))
|
|
85
|
-
|
|
86
|
-
ImageData.new([image.width.to_f, image.height.to_f], nil)
|
|
85
|
+
ImageData.new(raster_dimensions(handler, data), nil)
|
|
87
86
|
|
|
88
87
|
elsif potentially_svg?(data)
|
|
88
|
+
raise SkipElementError, "SVG images nested deeper than #{Prawn::SVG::Document::MAXIMUM_EMBEDDING_DEPTH} levels" if @document.embedding_depth >= Prawn::SVG::Document::MAXIMUM_EMBEDDING_DEPTH
|
|
89
|
+
|
|
89
90
|
attribute_overrides = {}
|
|
90
91
|
attribute_overrides["preserveAspectRatio"] = preserve_aspect_ratio if preserve_aspect_ratio
|
|
91
92
|
|
|
@@ -98,8 +99,10 @@ class Prawn::SVG::Elements::Image < Prawn::SVG::Elements::Base
|
|
|
98
99
|
document = Prawn::SVG::Document.new(
|
|
99
100
|
data, [width, height], {width:, height:, enable_web_requests: has_web_loader},
|
|
100
101
|
# Gamba: the parent's fonts, without which an embedded SVG holding text failed to render.
|
|
101
|
-
attribute_overrides:, font_registry: @document.font_registry
|
|
102
|
+
attribute_overrides:, font_registry: @document.font_registry, embedder: @document
|
|
102
103
|
)
|
|
104
|
+
# Gamba: drawn again for each <use> of it, and for each image of an image, which a few kilobytes can repeat.
|
|
105
|
+
@document.draw_again(Prawn::SVG::Document.element_count(document.root)) if state.inside_use || @document.embedding_depth.positive?
|
|
103
106
|
|
|
104
107
|
dimensions = [document.sizing.output_width, document.sizing.output_height]
|
|
105
108
|
ImageData.new(dimensions, document)
|
|
@@ -111,6 +114,18 @@ class Prawn::SVG::Elements::Image < Prawn::SVG::Elements::Base
|
|
|
111
114
|
raise_invalid_image_type
|
|
112
115
|
end
|
|
113
116
|
|
|
117
|
+
# Gamba: the image of a data: URL, which the loader keeps, is read once however many times <use> draws it.
|
|
118
|
+
def raster_dimensions(handler, data)
|
|
119
|
+
return read_raster_dimensions(handler, data) unless @url[0, 5].casecmp?("data:")
|
|
120
|
+
|
|
121
|
+
@document.raster_dimensions_by_data[data] ||= read_raster_dimensions(handler, data)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def read_raster_dimensions(handler, data)
|
|
125
|
+
image = handler.new(data)
|
|
126
|
+
[image.width.to_f, image.height.to_f]
|
|
127
|
+
end
|
|
128
|
+
|
|
114
129
|
def extract_fragment(url)
|
|
115
130
|
return [url, nil] if url.start_with?("data:")
|
|
116
131
|
|
|
@@ -149,7 +164,7 @@ class Prawn::SVG::Elements::Image < Prawn::SVG::Elements::Base
|
|
|
149
164
|
end
|
|
150
165
|
|
|
151
166
|
def find_view_element_attributes(data, fragment)
|
|
152
|
-
root =
|
|
167
|
+
root = Prawn::SVG::Document.parse(data)
|
|
153
168
|
return unless root
|
|
154
169
|
|
|
155
170
|
element = Prawn::SVG::Document.element_by_id(root, fragment)
|
|
@@ -27,20 +27,12 @@ module Prawn::SVG
|
|
|
27
27
|
|
|
28
28
|
@font, @fallback_fonts = select_fonts
|
|
29
29
|
|
|
30
|
-
@children =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
build_child(child)
|
|
37
|
-
when "textPath"
|
|
38
|
-
build_text_path(child)
|
|
39
|
-
else
|
|
40
|
-
warnings << "Unknown tag '#{child.name}' inside text tag; ignoring"
|
|
41
|
-
[]
|
|
42
|
-
end
|
|
43
|
-
end
|
|
30
|
+
@children = if name == "tref"
|
|
31
|
+
# Gamba: a <tref> draws its text again, as a <use> does: not inside itself, and within the same budget.
|
|
32
|
+
reference = find_referenced_element
|
|
33
|
+
reference ? document.drawing_through_use(reference.source) { build_children(reference.source.children) } : []
|
|
34
|
+
else
|
|
35
|
+
build_children(source.children)
|
|
44
36
|
end
|
|
45
37
|
end
|
|
46
38
|
|
|
@@ -158,9 +150,29 @@ module Prawn::SVG
|
|
|
158
150
|
Elements::TextNode.new(self, text, leading, trailing)
|
|
159
151
|
end
|
|
160
152
|
|
|
153
|
+
def build_children(nodes)
|
|
154
|
+
svg_text_children(nodes).flat_map do |child|
|
|
155
|
+
if child.node_type == :text
|
|
156
|
+
build_text_node(child)
|
|
157
|
+
else
|
|
158
|
+
case child.name
|
|
159
|
+
when "tspan", "tref"
|
|
160
|
+
build_child(child)
|
|
161
|
+
when "textPath"
|
|
162
|
+
build_text_path(child)
|
|
163
|
+
else
|
|
164
|
+
warnings << "Unknown tag '#{child.name}' inside text tag; ignoring"
|
|
165
|
+
[]
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
161
171
|
def build_child(child)
|
|
162
172
|
component = self.class.new(document, child, [], state.dup, self)
|
|
163
173
|
component.process
|
|
174
|
+
return [] unless component.children
|
|
175
|
+
|
|
164
176
|
component
|
|
165
177
|
end
|
|
166
178
|
|
|
@@ -172,8 +184,8 @@ module Prawn::SVG
|
|
|
172
184
|
component
|
|
173
185
|
end
|
|
174
186
|
|
|
175
|
-
def svg_text_children
|
|
176
|
-
|
|
187
|
+
def svg_text_children(nodes)
|
|
188
|
+
nodes.select do |child|
|
|
177
189
|
child.node_type == :text || (
|
|
178
190
|
child.node_type == :element &&
|
|
179
191
|
[SVG_NAMESPACE, ""].include?(child.namespace)
|
|
@@ -182,21 +194,12 @@ module Prawn::SVG
|
|
|
182
194
|
end
|
|
183
195
|
end
|
|
184
196
|
|
|
185
|
-
def text_children
|
|
186
|
-
if name == "tref"
|
|
187
|
-
reference = find_referenced_element
|
|
188
|
-
reference ? reference.source.children : []
|
|
189
|
-
else
|
|
190
|
-
source.children
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
|
|
194
197
|
def find_referenced_element
|
|
195
198
|
href = href_attribute
|
|
196
199
|
|
|
197
200
|
if href && href[0..0] == "#"
|
|
198
201
|
element = document.elements_by_id[href[1..]] # rubocop:disable Performance/ArraySemiInfiniteRangeSlice -- String
|
|
199
|
-
element if element
|
|
202
|
+
element if element&.name == "text"
|
|
200
203
|
end
|
|
201
204
|
end
|
|
202
205
|
|
|
@@ -101,8 +101,8 @@ class Prawn::SVG::Elements::Use < Prawn::SVG::Elements::Base
|
|
|
101
101
|
data = @document.url_loader.load(url)
|
|
102
102
|
|
|
103
103
|
root = begin
|
|
104
|
-
|
|
105
|
-
rescue REXML::ParseException
|
|
104
|
+
Prawn::SVG::Document.parse(data)
|
|
105
|
+
rescue REXML::ParseException, Prawn::SVG::Document::InvalidSVGData
|
|
106
106
|
raise SkipElementError, "use tag references external SVG at '#{url}' which could not be parsed"
|
|
107
107
|
end
|
|
108
108
|
|
data/lib/prawn/svg/url_loader.rb
CHANGED
|
@@ -29,7 +29,8 @@ class Prawn::SVG::UrlLoader
|
|
|
29
29
|
|
|
30
30
|
def perform_and_cache(url)
|
|
31
31
|
data = perform(url)
|
|
32
|
-
|
|
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
|
|
4
|
+
version: 2.1.0
|
|
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,10 @@ dependencies:
|
|
|
63
83
|
- - "<"
|
|
64
84
|
- !ruby/object:Gem::Version
|
|
65
85
|
version: '4'
|
|
66
|
-
description:
|
|
67
|
-
|
|
68
|
-
|
|
86
|
+
description: Gamba is a Ruby library that writes PDF files from stacks, rows, tables,
|
|
87
|
+
headers and footers it measures and places, tagged for PDF/UA. It also runs code
|
|
88
|
+
written for Prawn 2.5, prawn-table and prawn-svg unchanged, drawing the same pages
|
|
89
|
+
faster and in lighter files.
|
|
69
90
|
executables: []
|
|
70
91
|
extensions: []
|
|
71
92
|
extra_rdoc_files: []
|
|
@@ -94,7 +115,12 @@ files:
|
|
|
94
115
|
- data/fonts/ZapfDingbats.afm
|
|
95
116
|
- lib/gamba.rb
|
|
96
117
|
- lib/gamba/annotations.rb
|
|
118
|
+
- lib/gamba/barcodes.rb
|
|
119
|
+
- lib/gamba/barcodes/data_matrix.rb
|
|
120
|
+
- lib/gamba/barcodes/linear.rb
|
|
121
|
+
- lib/gamba/barcodes/qr_code.rb
|
|
97
122
|
- lib/gamba/combine.rb
|
|
123
|
+
- lib/gamba/copier.rb
|
|
98
124
|
- lib/gamba/document.rb
|
|
99
125
|
- lib/gamba/document/bounding_box.rb
|
|
100
126
|
- lib/gamba/document/column_box.rb
|
|
@@ -115,10 +141,17 @@ files:
|
|
|
115
141
|
- lib/gamba/images.rb
|
|
116
142
|
- lib/gamba/images/image.rb
|
|
117
143
|
- lib/gamba/images/png_decoder.rb
|
|
144
|
+
- lib/gamba/imported_page.rb
|
|
118
145
|
- lib/gamba/measurement_extensions.rb
|
|
119
146
|
- lib/gamba/measurements.rb
|
|
147
|
+
- lib/gamba/minitest.rb
|
|
148
|
+
- lib/gamba/native/band.rb
|
|
149
|
+
- lib/gamba/native/document.rb
|
|
150
|
+
- lib/gamba/native/layout.rb
|
|
151
|
+
- lib/gamba/native/table.rb
|
|
120
152
|
- lib/gamba/outline.rb
|
|
121
153
|
- lib/gamba/page.rb
|
|
154
|
+
- lib/gamba/page_boxes.rb
|
|
122
155
|
- lib/gamba/page_geometry.rb
|
|
123
156
|
- lib/gamba/pdf.rb
|
|
124
157
|
- lib/gamba/pdf/decryption.rb
|
|
@@ -128,13 +161,18 @@ files:
|
|
|
128
161
|
- lib/gamba/pdf/writer.rb
|
|
129
162
|
- lib/gamba/pdf_a.rb
|
|
130
163
|
- lib/gamba/pdf_a/srgb_profile.rb
|
|
164
|
+
- lib/gamba/pdf_check.rb
|
|
165
|
+
- lib/gamba/railtie.rb
|
|
131
166
|
- lib/gamba/repeater.rb
|
|
167
|
+
- lib/gamba/rspec.rb
|
|
132
168
|
- lib/gamba/security.rb
|
|
133
169
|
- lib/gamba/stamp.rb
|
|
134
170
|
- lib/gamba/table.rb
|
|
135
171
|
- lib/gamba/table/cell.rb
|
|
136
172
|
- lib/gamba/table/cell/kinds.rb
|
|
137
173
|
- lib/gamba/table/cells.rb
|
|
174
|
+
- lib/gamba/tagging.rb
|
|
175
|
+
- lib/gamba/testing.rb
|
|
138
176
|
- lib/gamba/text.rb
|
|
139
177
|
- lib/gamba/text/box.rb
|
|
140
178
|
- lib/gamba/text/formatted/arranger.rb
|
|
@@ -259,5 +297,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
259
297
|
requirements: []
|
|
260
298
|
rubygems_version: 4.0.20
|
|
261
299
|
specification_version: 4
|
|
262
|
-
summary:
|
|
300
|
+
summary: PDFs from layout you describe, tagged for screen readers; runs Prawn code
|
|
301
|
+
unchanged, faster
|
|
263
302
|
test_files: []
|