prawn-svg 0.21.0 → 0.22.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -0
  3. data/README.md +11 -4
  4. data/lib/prawn-svg.rb +9 -6
  5. data/lib/prawn/svg/attributes.rb +6 -0
  6. data/lib/prawn/svg/attributes/clip_path.rb +17 -0
  7. data/lib/prawn/svg/attributes/display.rb +5 -0
  8. data/lib/prawn/svg/attributes/font.rb +38 -0
  9. data/lib/prawn/svg/attributes/opacity.rb +15 -0
  10. data/lib/prawn/svg/attributes/stroke.rb +35 -0
  11. data/lib/prawn/svg/attributes/transform.rb +50 -0
  12. data/lib/prawn/svg/calculators/aspect_ratio.rb +1 -1
  13. data/lib/prawn/svg/calculators/document_sizing.rb +2 -2
  14. data/lib/prawn/svg/calculators/pixels.rb +1 -1
  15. data/lib/prawn/svg/color.rb +44 -14
  16. data/lib/prawn/svg/document.rb +6 -5
  17. data/lib/prawn/svg/elements.rb +33 -0
  18. data/lib/prawn/svg/elements/base.rb +228 -0
  19. data/lib/prawn/svg/elements/circle.rb +25 -0
  20. data/lib/prawn/svg/elements/container.rb +15 -0
  21. data/lib/prawn/svg/elements/ellipse.rb +23 -0
  22. data/lib/prawn/svg/elements/gradient.rb +117 -0
  23. data/lib/prawn/svg/elements/ignored.rb +5 -0
  24. data/lib/prawn/svg/elements/image.rb +85 -0
  25. data/lib/prawn/svg/elements/line.rb +16 -0
  26. data/lib/prawn/svg/elements/path.rb +405 -0
  27. data/lib/prawn/svg/elements/polygon.rb +17 -0
  28. data/lib/prawn/svg/elements/polyline.rb +22 -0
  29. data/lib/prawn/svg/elements/rect.rb +33 -0
  30. data/lib/prawn/svg/elements/root.rb +9 -0
  31. data/lib/prawn/svg/elements/style.rb +10 -0
  32. data/lib/prawn/svg/elements/text.rb +87 -0
  33. data/lib/prawn/svg/elements/use.rb +29 -0
  34. data/lib/prawn/svg/extension.rb +2 -2
  35. data/lib/prawn/svg/font.rb +3 -3
  36. data/lib/prawn/svg/interface.rb +12 -5
  37. data/lib/prawn/svg/url_loader.rb +1 -1
  38. data/lib/prawn/svg/version.rb +2 -2
  39. data/prawn-svg.gemspec +3 -3
  40. data/spec/integration_spec.rb +59 -2
  41. data/spec/prawn/svg/attributes/font_spec.rb +49 -0
  42. data/spec/prawn/svg/attributes/transform_spec.rb +56 -0
  43. data/spec/prawn/svg/calculators/aspect_ratio_spec.rb +2 -2
  44. data/spec/prawn/svg/calculators/document_sizing_spec.rb +3 -3
  45. data/spec/prawn/svg/color_spec.rb +36 -15
  46. data/spec/prawn/svg/document_spec.rb +4 -4
  47. data/spec/prawn/svg/elements/base_spec.rb +125 -0
  48. data/spec/prawn/svg/elements/gradient_spec.rb +61 -0
  49. data/spec/prawn/svg/elements/path_spec.rb +123 -0
  50. data/spec/prawn/svg/elements/style_spec.rb +23 -0
  51. data/spec/prawn/svg/{parser → elements}/text_spec.rb +7 -8
  52. data/spec/prawn/svg/font_spec.rb +12 -12
  53. data/spec/prawn/svg/interface_spec.rb +7 -7
  54. data/spec/prawn/svg/url_loader_spec.rb +2 -2
  55. data/spec/sample_svg/gradients.svg +40 -0
  56. data/spec/sample_svg/rect02.svg +8 -11
  57. data/spec/spec_helper.rb +1 -1
  58. metadata +46 -18
  59. data/lib/prawn/svg/element.rb +0 -304
  60. data/lib/prawn/svg/parser.rb +0 -268
  61. data/lib/prawn/svg/parser/image.rb +0 -81
  62. data/lib/prawn/svg/parser/path.rb +0 -392
  63. data/lib/prawn/svg/parser/text.rb +0 -80
  64. data/spec/prawn/svg/element_spec.rb +0 -127
  65. data/spec/prawn/svg/parser/path_spec.rb +0 -89
  66. data/spec/prawn/svg/parser_spec.rb +0 -55
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40c0c884ffef68848fa7314e085647ffc907a003
4
- data.tar.gz: 87341061bdfcb99e9cf8157cfb3c84f72ec3bb2b
3
+ metadata.gz: d93ba261ddc059e43122549f72a3e3daa676171f
4
+ data.tar.gz: d0497cb84295f9202f84c62b5db79f9d29608019
5
5
  SHA512:
6
- metadata.gz: 002745c7063d0013609343b4e383372058cde46835e240496f813855ea489287d6aad117ab98d89c3367e02d64a502deb038cdf00a7d9d381238e9d02f66149f
7
- data.tar.gz: ce3f448a22be98027ad0be5e154924839e080969cfeeb27322c57e017d249c767b4a073b2faed164a290d102cda0e18c80aa9665840385a6cbfc124714f76808
6
+ metadata.gz: acf2f6d51a5fda648bed5efd25ba85de91887867badccde3ce4d713cebddcc851280d524ba3006d7014651cd73ccf8c5a54185038a41dfa37612b522cb99ea17
7
+ data.tar.gz: 2dc23eac65fc5be3299015309d8e2f94d5598ba016f7776090f886fe9bd4551ae90bd129252428b65b617bf8472ca4adcf9cdc5760f3e5f3f635793415d09622
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.6
5
+ - 2.2.2
6
+
data/README.md CHANGED
@@ -1,12 +1,16 @@
1
1
  # prawn-svg
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/prawn-svg.svg)](https://badge.fury.io/rb/prawn-svg)
4
+ [![Build Status](https://travis-ci.org/mogest/prawn-svg.svg?branch=master)](https://travis-ci.org/mogest/prawn-svg)
5
+
3
6
  An SVG renderer for the Prawn PDF library.
4
7
 
5
8
  This will take an SVG file as input and render it into your PDF. Find out more about the Prawn PDF library at:
6
9
 
7
10
  http://wiki.github.com/sandal/prawn/
8
11
 
9
- prawn-svg is compatible with all versions of Prawn from 0.8.4 onwards, including the 1.x and 2.x series.
12
+ prawn-svg is compatible with all versions of Prawn from 0.11.1 onwards, including the 1.x and 2.x series.
13
+ The minimum Ruby version required is 2.0.0.
10
14
 
11
15
  ## Using prawn-svg
12
16
 
@@ -49,10 +53,13 @@ prawn-svg supports most but not all of the full SVG 1.1 specification. It curre
49
53
 
50
54
  - <tt>&lt;style&gt;</tt> plus <tt>id</tt>, <tt>class</tt> and <tt>style</tt> attributes (see CSS section below)
51
55
 
52
- - <tt>&lt;image&gt;</tt> with <tt>http:</tt>, <tt>https:</tt> and <tt>data:image/*;base64</tt> schemes
56
+ - <tt>&lt;image&gt;</tt> with <tt>http:</tt>, <tt>https:</tt> and <tt>data:image/\*;base64</tt> schemes
53
57
 
54
58
  - <tt>&lt;clipPath&gt;</tt>
55
59
 
60
+ - <tt>&lt;linearGradient&gt;</tt> but only with Prawn 2.0.4+. gradientTransform, spreadMethod and stop-opacity are
61
+ unimplemented.
62
+
56
63
  - attributes/styles: <tt>fill</tt>, <tt>stroke</tt>, <tt>stroke-width</tt>, <tt>stroke-linecap</tt>, <tt>stroke-dasharray</tt>, <tt>opacity</tt>, <tt>fill-opacity</tt>, <tt>stroke-opacity</tt>, <tt>transform</tt>, <tt>clip-path</tt>, <tt>display</tt>
57
64
 
58
65
  - the <tt>viewBox</tt> attribute on the <tt>&lt;svg&gt;</tt> tag
@@ -73,7 +80,7 @@ prawn-svg uses the css_parser gem to parse CSS <tt>&lt;style&gt;</tt> blocks. I
73
80
 
74
81
  ## Not supported
75
82
 
76
- prawn-svg does not support external <tt>url()</tt> references, measurements in <tt>en</tt> or <tt>em</tt>, sub-viewports, gradients/patterns or markers.
83
+ prawn-svg does not support external <tt>url()</tt> references, measurements in <tt>en</tt> or <tt>em</tt>, sub-viewports, radial gradients, patterns or markers.
77
84
 
78
85
  ## Configuration
79
86
 
@@ -83,7 +90,7 @@ By default, prawn-svg has a fonts path of <tt>["/Library/Fonts", "/System/Librar
83
90
  Mac OS X and Debian Linux users. You can add to the font path:
84
91
 
85
92
  ```ruby
86
- Prawn::Svg::Interface.font_path << "/my/font/directory"
93
+ Prawn::SVG::Interface.font_path << "/my/font/directory"
87
94
  ```
88
95
 
89
96
 
data/lib/prawn-svg.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'rexml/document'
2
+
1
3
  require 'prawn'
2
4
  require 'prawn/svg/version'
3
5
 
@@ -6,14 +8,15 @@ require 'prawn/svg/calculators/document_sizing'
6
8
  require 'prawn/svg/calculators/pixels'
7
9
  require 'prawn/svg/url_loader'
8
10
  require 'prawn/svg/color'
11
+ require 'prawn/svg/attributes'
12
+ require 'prawn/svg/elements'
9
13
  require 'prawn/svg/extension'
10
14
  require 'prawn/svg/interface'
11
15
  require 'prawn/svg/font'
12
16
  require 'prawn/svg/document'
13
- require 'prawn/svg/element'
14
- require 'prawn/svg/parser'
15
- require 'prawn/svg/parser/path'
16
- require 'prawn/svg/parser/text'
17
- require 'prawn/svg/parser/image'
18
17
 
19
- Prawn::Document.extensions << Prawn::Svg::Extension
18
+ module Prawn
19
+ Svg = SVG # backwards compatibility
20
+ end
21
+
22
+ Prawn::Document.extensions << Prawn::SVG::Extension
@@ -0,0 +1,6 @@
1
+ module Prawn::SVG::Attributes
2
+ end
3
+
4
+ %w(transform opacity clip_path stroke font display).each do |name|
5
+ require "prawn/svg/attributes/#{name}"
6
+ end
@@ -0,0 +1,17 @@
1
+ module Prawn::SVG::Attributes::ClipPath
2
+ def parse_clip_path_attribute_and_call
3
+ return unless clip_path = attributes['clip-path']
4
+
5
+ if (matches = clip_path.strip.match(/\Aurl\(#(.*)\)\z/)).nil?
6
+ document.warnings << "Only clip-path attributes with the form 'url(#xxx)' are supported"
7
+ elsif (clip_path_element = @document.elements_by_id[matches[1]]).nil?
8
+ document.warnings << "clip-path ID '#{matches[1]}' not defined"
9
+ elsif clip_path_element.source.name != "clipPath"
10
+ document.warnings << "clip-path ID '#{matches[1]}' does not point to a clipPath tag"
11
+ else
12
+ add_call_and_enter 'save_graphics_state'
13
+ add_calls_from_element clip_path_element
14
+ add_call "clip"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Prawn::SVG::Attributes::Display
2
+ def parse_display_attribute
3
+ @state[:display] = attributes['display'].strip if attributes['display']
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ module Prawn::SVG::Attributes::Font
2
+ def parse_font_attributes_and_call
3
+ if size = attributes['font-size']
4
+ @state[:font_size] = size.to_f
5
+ end
6
+ if weight = attributes['font-weight']
7
+ font_updated = true
8
+ @state[:font_weight] = Prawn::SVG::Font.weight_for_css_font_weight(weight)
9
+ end
10
+ if style = attributes['font-style']
11
+ font_updated = true
12
+ @state[:font_style] = style == 'italic' ? :italic : nil
13
+ end
14
+ if (family = attributes['font-family']) && family.strip != ""
15
+ font_updated = true
16
+ @state[:font_family] = family
17
+ end
18
+ if (anchor = attributes['text-anchor'])
19
+ @state[:text_anchor] = anchor
20
+ end
21
+
22
+ if @state[:font_family] && font_updated
23
+ usable_font_families = [@state[:font_family], document.fallback_font_name]
24
+
25
+ font_used = usable_font_families.compact.detect do |name|
26
+ if font = Prawn::SVG::Font.load(name, @state[:font_weight], @state[:font_style])
27
+ @state[:font_subfamily] = font.subfamily
28
+ add_call_and_enter 'font', font.name, :style => @state[:font_subfamily]
29
+ true
30
+ end
31
+ end
32
+
33
+ if font_used.nil?
34
+ warnings << "Font family '#{@state[:font_family]}' style '#{@state[:font_style] || 'normal'}' is not a known font, and the fallback font could not be found."
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ module Prawn::SVG::Attributes::Opacity
2
+ def parse_opacity_attributes_and_call
3
+ # We can't do nested opacities quite like the SVG requires, but this is close enough.
4
+ fill_opacity = stroke_opacity = clamp(attributes['opacity'].to_f, 0, 1) if attributes['opacity']
5
+ fill_opacity = clamp(attributes['fill-opacity'].to_f, 0, 1) if attributes['fill-opacity']
6
+ stroke_opacity = clamp(attributes['stroke-opacity'].to_f, 0, 1) if attributes['stroke-opacity']
7
+
8
+ if fill_opacity || stroke_opacity
9
+ state[:fill_opacity] = (state[:fill_opacity] || 1) * (fill_opacity || 1)
10
+ state[:stroke_opacity] = (state[:stroke_opacity] || 1) * (stroke_opacity || 1)
11
+
12
+ add_call_and_enter 'transparent', state[:fill_opacity], state[:stroke_opacity]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ module Prawn::SVG::Attributes::Stroke
2
+ CAP_STYLE_TRANSLATIONS = {"butt" => :butt, "round" => :round, "square" => :projecting_square}
3
+
4
+ def parse_stroke_attributes_and_call
5
+ if width = attributes['stroke-width']
6
+ add_call('line_width', distance(width))
7
+ end
8
+
9
+ if (linecap = attribute_value_as_keyword('stroke-linecap')) && linecap != 'inherit'
10
+ add_call('cap_style', CAP_STYLE_TRANSLATIONS.fetch(linecap, :butt))
11
+ end
12
+
13
+ if dasharray = attribute_value_as_keyword('stroke-dasharray')
14
+ case dasharray
15
+ when 'inherit'
16
+ # don't do anything
17
+ when 'none'
18
+ add_call('undash')
19
+ else
20
+ array = dasharray.split(Prawn::SVG::Elements::COMMA_WSP_REGEXP)
21
+ array *= 2 if array.length % 2 == 1
22
+ number_array = array.map {|value| distance(value)}
23
+
24
+ if number_array.any? {|number| number < 0}
25
+ @document.warnings << "stroke-dasharray cannot have negative numbers; treating as 'none'"
26
+ add_call('undash')
27
+ elsif number_array.inject(0) {|a, b| a + b} == 0
28
+ add_call('undash')
29
+ else
30
+ add_call('dash', number_array)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,50 @@
1
+ module Prawn::SVG::Attributes::Transform
2
+ def parse_transform_attribute_and_call
3
+ return unless transform = attributes['transform']
4
+
5
+ parse_css_method_calls(transform).each do |name, arguments|
6
+ case name
7
+ when 'translate'
8
+ x, y = arguments
9
+ add_call_and_enter name, distance(x.to_f, :x), -distance(y.to_f, :y)
10
+
11
+ when 'rotate'
12
+ r, x, y = arguments.collect {|a| a.to_f}
13
+ case arguments.length
14
+ when 1
15
+ add_call_and_enter name, -r, :origin => [0, y('0')]
16
+ when 3
17
+ add_call_and_enter name, -r, :origin => [x(x), y(y)]
18
+ else
19
+ warnings << "transform 'rotate' must have either one or three arguments"
20
+ end
21
+
22
+ when 'scale'
23
+ x_scale = arguments[0].to_f
24
+ y_scale = (arguments[1] || x_scale).to_f
25
+ add_call_and_enter "transformation_matrix", x_scale, 0, 0, y_scale, 0, 0
26
+
27
+ when 'matrix'
28
+ if arguments.length != 6
29
+ warnings << "transform 'matrix' must have six arguments"
30
+ else
31
+ a, b, c, d, e, f = arguments.collect {|argument| argument.to_f}
32
+ add_call_and_enter "transformation_matrix", a, -b, -c, d, distance(e, :x), -distance(f, :y)
33
+ end
34
+
35
+ else
36
+ warnings << "Unknown transformation '#{name}'; ignoring"
37
+ end
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def parse_css_method_calls(string)
44
+ string.scan(/\s*(\w+)\(([^)]+)\)\s*/).collect do |call|
45
+ name, argument_string = call
46
+ arguments = argument_string.strip.split(/\s*[,\s]\s*/)
47
+ [name, arguments]
48
+ end
49
+ end
50
+ end
@@ -1,4 +1,4 @@
1
- module Prawn::Svg::Calculators
1
+ module Prawn::SVG::Calculators
2
2
  class AspectRatio
3
3
  attr_reader :align, :defer
4
4
  attr_reader :width, :height, :x, :y
@@ -1,4 +1,4 @@
1
- module Prawn::Svg::Calculators
1
+ module Prawn::SVG::Calculators
2
2
  class DocumentSizing
3
3
  DEFAULT_WIDTH = 300
4
4
  DEFAULT_HEIGHT = 150
@@ -34,7 +34,7 @@ module Prawn::Svg::Calculators
34
34
  @output_height = Pixels.to_pixels(@document_height || @requested_height, container_height)
35
35
 
36
36
  if @view_box
37
- values = @view_box.strip.split(Prawn::Svg::Parser::COMMA_WSP_REGEXP)
37
+ values = @view_box.strip.split(Prawn::SVG::Elements::COMMA_WSP_REGEXP)
38
38
  @x_offset, @y_offset, @viewport_width, @viewport_height = values.map {|value| value.to_f}
39
39
  @x_offset = -@x_offset
40
40
 
@@ -1,4 +1,4 @@
1
- module Prawn::Svg::Calculators
1
+ module Prawn::SVG::Calculators
2
2
  class Pixels
3
3
  extend Prawn::Measurements
4
4
 
@@ -1,5 +1,17 @@
1
- class Prawn::Svg::Color
2
- UnresolvableURLWithNoFallbackError = Class.new(StandardError)
1
+ class Prawn::SVG::Color
2
+ class Hex
3
+ attr_reader :value
4
+
5
+ def initialize(value)
6
+ @value = value
7
+ end
8
+
9
+ def ==(other)
10
+ value == other.value
11
+ end
12
+ end
13
+
14
+ DEFAULT_COLOR = Hex.new("000000")
3
15
 
4
16
  HTML_COLORS = {
5
17
  'aliceblue' => 'f0f8ff',
@@ -153,34 +165,52 @@ class Prawn::Svg::Color
153
165
 
154
166
  RGB_VALUE_REGEXP = "\s*(-?[0-9.]+%?)\s*"
155
167
  RGB_REGEXP = /\Argb\(#{RGB_VALUE_REGEXP},#{RGB_VALUE_REGEXP},#{RGB_VALUE_REGEXP}\)\z/i
156
- URL_REGEXP = /\Aurl\([^)]*\)\z/i
168
+ URL_REGEXP = /\Aurl\(([^)]*)\)\z/i
157
169
 
158
- def self.color_to_hex(color_string)
170
+ def self.parse(color_string, gradients = nil)
159
171
  url_specified = false
160
172
 
161
- result = color_string.strip.scan(/([^(\s]+(\([^)]*\))?)/).detect do |color, *_|
173
+ components = color_string.to_s.strip.scan(/([^(\s]+(\([^)]*\))?)/)
174
+
175
+ result = components.map do |color, *_|
162
176
  if m = color.match(/\A#([0-9a-f])([0-9a-f])([0-9a-f])\z/i)
163
- break "#{m[1] * 2}#{m[2] * 2}#{m[3] * 2}"
177
+ Hex.new("#{m[1] * 2}#{m[2] * 2}#{m[3] * 2}")
178
+
164
179
  elsif color.match(/\A#[0-9a-f]{6}\z/i)
165
- break color[1..6]
180
+ Hex.new(color[1..6])
181
+
166
182
  elsif hex = HTML_COLORS[color.downcase]
167
- break hex
183
+ Hex.new(hex)
184
+
168
185
  elsif m = color.match(RGB_REGEXP)
169
- break (1..3).collect do |n|
186
+ hex = (1..3).collect do |n|
170
187
  value = m[n].to_f
171
188
  value *= 2.55 if m[n][-1..-1] == '%'
172
189
  "%02x" % clamp(value.round, 0, 255)
173
190
  end.join
174
- elsif color.match(URL_REGEXP)
191
+
192
+ Hex.new(hex)
193
+
194
+ elsif matches = color.match(URL_REGEXP)
175
195
  url_specified = true
176
- nil # we can't handle these so we find the next thing that matches
196
+ url = matches[1]
197
+ if url[0] == "#" && gradients && gradient = gradients[url[1..-1]]
198
+ gradient
199
+ end
177
200
  end
178
201
  end
179
202
 
180
- # http://www.w3.org/TR/SVG/painting.html section 11.2
181
- raise UnresolvableURLWithNoFallbackError if result.nil? && url_specified
203
+ # Generally, we default to black if the colour was unparseable.
204
+ # http://www.w3.org/TR/SVG/painting.html section 11.2 says if a URL was
205
+ # supplied without a fallback, that's an error.
206
+ result << DEFAULT_COLOR unless url_specified
207
+
208
+ result.compact
209
+ end
182
210
 
183
- result
211
+ def self.color_to_hex(color)
212
+ result = parse(color).detect {|result| result.is_a?(Hex)}
213
+ result.value if result
184
214
  end
185
215
 
186
216
  protected
@@ -1,4 +1,4 @@
1
- class Prawn::Svg::Document
1
+ class Prawn::SVG::Document
2
2
  begin
3
3
  require 'css_parser'
4
4
  CSS_PARSER_LOADED = true
@@ -15,7 +15,7 @@ class Prawn::Svg::Document
15
15
  attr_reader :root,
16
16
  :sizing,
17
17
  :cache_images, :fallback_font_name,
18
- :css_parser, :elements_by_id
18
+ :css_parser, :elements_by_id, :gradients
19
19
 
20
20
  def initialize(data, bounds, options)
21
21
  @css_parser = CssParser::Parser.new if CSS_PARSER_LOADED
@@ -24,10 +24,11 @@ class Prawn::Svg::Document
24
24
  @warnings = []
25
25
  @options = options
26
26
  @elements_by_id = {}
27
+ @gradients = {}
27
28
  @cache_images = options[:cache_images]
28
29
  @fallback_font_name = options.fetch(:fallback_font_name, DEFAULT_FALLBACK_FONT_NAME)
29
30
 
30
- @sizing = Prawn::Svg::Calculators::DocumentSizing.new(bounds, @root.attributes)
31
+ @sizing = Prawn::SVG::Calculators::DocumentSizing.new(bounds, @root.attributes)
31
32
  sizing.requested_width = options[:width]
32
33
  sizing.requested_height = options[:height]
33
34
  sizing.calculate
@@ -50,10 +51,10 @@ class Prawn::Svg::Document
50
51
  end
51
52
 
52
53
  def points(value, axis = nil)
53
- Prawn::Svg::Calculators::Pixels.to_pixels(value, @axis_to_size.fetch(axis, sizing.viewport_diagonal))
54
+ Prawn::SVG::Calculators::Pixels.to_pixels(value, @axis_to_size.fetch(axis, sizing.viewport_diagonal))
54
55
  end
55
56
 
56
57
  def url_loader
57
- @url_loader ||= Prawn::Svg::UrlLoader.new(:enable_cache => cache_images)
58
+ @url_loader ||= Prawn::SVG::UrlLoader.new(:enable_cache => cache_images)
58
59
  end
59
60
  end
@@ -0,0 +1,33 @@
1
+ module Prawn::SVG::Elements
2
+ COMMA_WSP_REGEXP = /(?:\s+,?\s*|,\s*)/
3
+ end
4
+
5
+ %w(base root container style text line polyline polygon circle ellipse rect path use image gradient ignored).each do |filename|
6
+ require "prawn/svg/elements/#{filename}"
7
+ end
8
+
9
+ module Prawn::SVG::Elements
10
+ TAG_CLASS_MAPPING = {
11
+ svg: Prawn::SVG::Elements::Container,
12
+ g: Prawn::SVG::Elements::Container,
13
+ symbol: Prawn::SVG::Elements::Container,
14
+ defs: Prawn::SVG::Elements::Container,
15
+ clipPath: Prawn::SVG::Elements::Container,
16
+ style: Prawn::SVG::Elements::Style,
17
+ text: Prawn::SVG::Elements::Text,
18
+ line: Prawn::SVG::Elements::Line,
19
+ polyline: Prawn::SVG::Elements::Polyline,
20
+ polygon: Prawn::SVG::Elements::Polygon,
21
+ circle: Prawn::SVG::Elements::Circle,
22
+ ellipse: Prawn::SVG::Elements::Ellipse,
23
+ rect: Prawn::SVG::Elements::Rect,
24
+ path: Prawn::SVG::Elements::Path,
25
+ use: Prawn::SVG::Elements::Use,
26
+ image: Prawn::SVG::Elements::Image,
27
+ linearGradient: Prawn::SVG::Elements::Gradient,
28
+ title: Prawn::SVG::Elements::Ignored,
29
+ desc: Prawn::SVG::Elements::Ignored,
30
+ metadata: Prawn::SVG::Elements::Ignored,
31
+ :"font-face" => Prawn::SVG::Elements::Ignored,
32
+ }
33
+ end