Adding SVG support

This commit is contained in:
Andy Meneely
2014-07-17 10:55:20 -04:00
parent d7c8941620
commit 3f4e001e63
6 changed files with 112 additions and 1 deletions
+7 -1
View File
@@ -1,11 +1,17 @@
module Squib
class Deck
def png(range=:all, file: nil, x: 0, y: 0)
def png(range: :all, file: nil, x: 0, y: 0)
range = rangeify(range)
file = fileify(file)
range.each{ |i| @cards[i].png(file, x, y) }
end
def svg(range: :all, file: nil, x: 0, y: 0)
range = rangeify(range)
file = fileify(file)
range.each{ |i| @cards[i].svg(file, x, y) }
end
end
end
+3
View File
@@ -27,6 +27,9 @@ module Squib
def rangeify (range)
range = 0..(@cards.size-1) if range == :all
range = range..range if range.is_a? Integer
if range.max > (@cards.size-1)
raise "#{range} is outside of deck range of 0..#{@card.size-1}"
end
return range
end
+10
View File
@@ -8,5 +8,15 @@ module Squib
cc.paint
end
def svg(file, x, y)
require 'rsvg2'
svg = RSVG::Handle.new_from_file(file)
tmp = Cairo::ImageSurface.new(svg.width, svg.height)
tmp_cc = Cairo::Context.new(tmp)
tmp_cc.render_rsvg_handle(svg, width: 400, height: 400)
cairo_context.set_source(tmp, x, y)
cairo_context.paint
end
end
end