Sha256: ef6dbf3de937b8d924a1780040b00e833659d1e18d36cc530fd77a2ecb064757

Contents?: true

Size: 875 Bytes

Versions: 1

Compression:

Stored size: 875 Bytes

Contents

require "gtk3"
require "rsvg2"

module Mireru
  module Widget
    class SVG < Gtk::DrawingArea
      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mireru-0.9.0 lib/mireru/widget/svg.rb