class Rabbit::ImageManipulable::SVG

Public Class Methods

match?(filename) click to toggle source
# File lib/rabbit/image/svg.rb, line 13
def match?(filename)
  File.open(filename) do |f|
    begin
      /<svg|<!DOCTYPE\s+svg/ =~ f.read(200)
    rescue EncodingError
      false
    end
  end
end

Public Instance Methods

draw(canvas, x, y, params={}) click to toggle source
Calls superclass method Rabbit::ImageManipulable::Base#draw
# File lib/rabbit/image/svg.rb, line 24
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
pixbuf() click to toggle source
# File lib/rabbit/image/svg.rb, line 36
def pixbuf
  @pixbuf ||= to_pixbuf(width, height)
end

Private Instance Methods

filename() click to toggle source
# File lib/rabbit/image/svg.rb, line 57
def filename
  File.expand_path(@filename)
end
rsvg_environment() { |name| ... } click to toggle source
# File lib/rabbit/image/svg.rb, line 61
def rsvg_environment
  dir = File.dirname(filename)
  name = File.basename(filename)
  Dir.chdir(dir) do
    yield(name)
  end
end
to_pixbuf(w=nil, h=nil) click to toggle source
# File lib/rabbit/image/svg.rb, line 69
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
update_size() click to toggle source
# File lib/rabbit/image/svg.rb, line 41
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