Sha256: 09f29587f8ba7f30464e665378028f5a39151c341f076e91bdf78c020bcbd481
Contents?: true
Size: 1.62 KB
Versions: 3
Compression:
Stored size: 1.62 KB
Contents
require "rsvg2" require "rabbit/image/base" module Rabbit module ImageManipulable class SVG < Base unshift_loader(self) class << self def match?(filename) File.open(filename) do |f| /<svg|<!DOCTYPE\s+svg/ =~ f.read(200) end end end def draw(canvas, x, y, params={}) if @handle default_params = { :width => width, :height => height, } canvas.draw_rsvg_handle(@handle, x, y, default_params.merge(params)) else super end end def pixbuf @pixbuf ||= to_pixbuf(width, height) end private def update_size @handle = nil rsvg_environment do |name| if RSVG::Handle.respond_to?(:new_from_file) @handle = RSVG::Handle.new_from_file(name) dim = @handle.dimensions @width = dim.width @height = dim.height else @pixbuf = RSVG.pixbuf_from_file(name) @width = @pixbuf.width @height = @pixbuf.height end end end def filename File.expand_path(@filename) end def rsvg_environment dir = File.dirname(filename) name = File.basename(filename) Dir.chdir(dir) do yield(name) end end def to_pixbuf(w=nil, h=nil) rsvg_environment do |name| if w or h RSVG.pixbuf_from_file_at_size(name, w || width, h || height) else RSVG.pixbuf_from_file(name) end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rabbit-2.1.9 | lib/rabbit/image/svg.rb |
rabbit-2.1.8 | lib/rabbit/image/svg.rb |
rabbit-2.1.7 | lib/rabbit/image/svg.rb |