SVG scaling is now supported!

This commit is contained in:
Andy Meneely
2014-07-22 14:54:09 -04:00
parent b021e9aca3
commit c2ec7947df
5 changed files with 35 additions and 16 deletions
+6 -3
View File
@@ -8,11 +8,14 @@ module Squib
cc.paint(alpha)
end
def svg(file, x, y)
require 'rsvg2'
def svg(file, x, y, width, height)
svg = RSVG::Handle.new_from_file(file)
tmp = Cairo::ImageSurface.new(svg.width, svg.height)
width = svg.width if width == :native
height = svg.height if height == :native
puts "Width and height #{width} #{height}, svg was #{svg.width} #{svg.height}"
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)
cairo_context.set_source(tmp, x, y)
cairo_context.paint