Adding SVG support
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user