lib/prawn/svg/document.rb in prawn-svg-0.12.0.3 vs lib/prawn/svg/document.rb in prawn-svg-0.12.0.4
- old
+ new
@@ -4,31 +4,32 @@
begin
require 'css_parser'
CSS_PARSER_LOADED = true
rescue LoadError
CSS_PARSER_LOADED = false
- end
-
+ end
+
DEFAULT_WIDTH = 640
DEFAULT_HEIGHT = 480
-
+
# An +Array+ of warnings that occurred while parsing the SVG data.
attr_reader :warnings
# The scaling factor, as determined by the :width or :height options.
attr_accessor :scale
attr_reader :root,
:actual_width, :actual_height, :width, :height, :x_offset, :y_offset, :cache_images,
- :css_parser
-
+ :css_parser, :elements_by_id
+
def initialize(data, bounds, options)
@css_parser = CssParser::Parser.new if CSS_PARSER_LOADED
@root = REXML::Document.new(data).root
@warnings = []
@options = options
+ @elements_by_id = {}
@cache_images = options[:cache_images]
@actual_width, @actual_height = bounds # set this first so % width/heights can be used
if vb = @root.attributes['viewBox']
x1, y1, x2, y2 = vb.strip.split(/\s+/)
@@ -37,24 +38,24 @@
else
@x_offset, @y_offset = [0, 0]
@actual_width = points(@root.attributes['width'] || DEFAULT_WIDTH, :x)
@actual_height = points(@root.attributes['height'] || DEFAULT_HEIGHT, :y)
end
-
+
if @options[:width]
- @width = @options[:width]
+ @width = @options[:width]
@scale = @options[:width] / @actual_width.to_f
elsif @options[:height]
@height = @options[:height]
@scale = @options[:height] / @actual_height.to_f
else
@scale = 1
end
@width ||= @actual_width * @scale
- @height ||= @actual_height * @scale
+ @height ||= @actual_height * @scale
end
-
+
def x(value)
(points(value, :x) - @x_offset) * scale
end
def y(value)