Browse Source

svg command can now specify an ID

dev
Andy Meneely 12 years ago
parent
commit
9784d928d1
  1. 4
      lib/squib/api/image.rb
  2. 4
      lib/squib/graphics/image.rb

4
lib/squib/api/image.rb

@ -27,10 +27,10 @@ module Squib
# @param width: the pixel width that the image should scale to. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document.
# @param height: the pixel width that the image should scale to. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document.
# @api public
def svg(range: :all, file: nil, x: 0, y: 0, width: :native, height: :native)
def svg(range: :all, file: nil, id: nil, x: 0, y: 0, width: :native, height: :native)
range = rangeify(range)
file = fileify(file)
range.each{ |i| @cards[i].svg(file, x, y, width, height) }
range.each{ |i| @cards[i].svg(file, id, x, y, width, height) }
end
end

4
lib/squib/graphics/image.rb

@ -8,14 +8,14 @@ module Squib
cc.paint(alpha)
end
def svg(file, x, y, width, height)
def svg(file, id, x, y, width, height)
svg = RSVG::Handle.new_from_file(file)
width = svg.width if width == :native
height = svg.height if height == :native
tmp = Cairo::ImageSurface.new(width, height)
tmp_cc = Cairo::Context.new(tmp)
tmp_cc.scale(width.to_f / svg.width.to_f, height.to_f / svg.height.to_f)
tmp_cc.render_rsvg_handle(svg)
tmp_cc.render_rsvg_handle(svg, id)
cairo_context.set_source(tmp, x, y)
cairo_context.paint
end

Loading…
Cancel
Save