Sophie

Sophie

distrib > * > 2009.0 > i586 > by-pkgid > ca1febf5d4b1482f8741ccde48d1e3ba > files > 9

ruby-rsvg2-0.17.0-1mdv2009.0.i586.rpm

#!/usr/bin/env ruby

require 'gtk2'
require 'rsvg2'

unless RSVG.cairo_available?
  puts "this sample needs RSVG with cairo support"
  exit(-1)
end

unless Gdk.cairo_available?
  puts "this sample needs GDK with cairo support"
  exit(-1)
end

if ARGV.size != 1
  puts "usage: #{$0} input.svg"
  exit(-1)
end

input = ARGV.shift

handle = RSVG::Handle.new_from_file(input)
width, height = handle.dimensions.to_a

window = Gtk::Window.new
window.set_default_size(width, height)
area = Gtk::DrawingArea.new

window.signal_connect("destroy") do
  Gtk.main_quit
end

area.signal_connect("expose_event") do |widget, event|
  context = widget.window.create_cairo_context
  window_width, window_height = widget.window.size
  context.scale(window_width.to_f / width, window_height.to_f / height)
  context.render_rsvg_handle(handle)
end

window.add(area)
window.show_all

Gtk.main