Class: Mireru::Widget::SVG

Inherits:
Gtk::DrawingArea
  • Object
show all
Defined in:
lib/mireru/widget/svg.rb

Instance Method Summary collapse

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 |widget, event|
    context = widget.window.create_cairo_context
    window_width = widget.allocated_width
    window_height = widget.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.message}")
      $stderr.puts(e.backtrace)
    end
    context.render_rsvg_handle(handle)
    true
  end
end