svg command can now specify an ID
parent
a59a3a5790
commit
9784d928d1
|
|
@ -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 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.
|
# @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
|
# @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)
|
range = rangeify(range)
|
||||||
file = fileify(file)
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,14 @@ module Squib
|
||||||
cc.paint(alpha)
|
cc.paint(alpha)
|
||||||
end
|
end
|
||||||
|
|
||||||
def svg(file, x, y, width, height)
|
def svg(file, id, x, y, width, height)
|
||||||
svg = RSVG::Handle.new_from_file(file)
|
svg = RSVG::Handle.new_from_file(file)
|
||||||
width = svg.width if width == :native
|
width = svg.width if width == :native
|
||||||
height = svg.height if height == :native
|
height = svg.height if height == :native
|
||||||
tmp = Cairo::ImageSurface.new(width, height)
|
tmp = Cairo::ImageSurface.new(width, height)
|
||||||
tmp_cc = Cairo::Context.new(tmp)
|
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.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.set_source(tmp, x, y)
|
||||||
cairo_context.paint
|
cairo_context.paint
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue