Class: Mireru::Widget::SVG
- Inherits:
-
Gtk::DrawingArea
- Object
- Gtk::DrawingArea
- Mireru::Widget::SVG
- Defined in:
- lib/mireru/widget/svg.rb
Instance Method Summary collapse
-
#initialize(file) ⇒ SVG
constructor
A new instance of SVG.
Constructor Details
#initialize(file) ⇒ SVG
Returns a new instance of SVG.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mireru/widget/svg.rb', line 23 def initialize(file) super() handle = RSVG::Handle.new_from_file(file) width, height = handle.dimensions.to_a signal_connect("draw") do |, event| context = .window.create_cairo_context window_width = .allocated_width window_height = .allocated_height width_scale = window_width.to_f / width height_scale = window_height.to_f / height scale = [width_scale, height_scale].min begin context.scale(scale, scale) rescue => e $stderr.puts("#{e.class}: #{e.}") $stderr.puts(e.backtrace) end context.render_rsvg_handle(handle) true end end |