Experimenting with creating an SVG app using the Gtk2SVG gem

#!/usr/bin/env ruby

# file: draw3.rb

require 'gtk2svg'

s =<<SVG
<svg width="400" height="110">
  <rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)" />
  <rect x="100" y="100" width="100" height="100" style="fill:rgb(255,0,0);stroke-width:3;stroke:rgb(0,0,0)" />
</svg>
SVG

a = Gtk2SVG::Render.new(s).to_a

area = Gtk::DrawingArea.new

area.signal_connect("expose_event") do

  drawing = Gtk2SVG::DrawingInstructions.new area
  drawing.render a

end

Gtk::Window.new.add(area).show_all
Gtk.main

The above example creates a GTK2 application which can parse and render SVG. Below is a screenshot of the application.

Screenshot of the SVG rendered in a GTK2 application

Resources