class Gtk2SVG::DrawingInstructions
Attributes
area[RW]
Public Class Methods
new(area=nil, window=nil, debug: false)
click to toggle source
# File lib/gtk2svg.rb, line 115 def initialize(area=nil, window=nil, debug: false) @area, @window, @debug = area, window, debug end
Public Instance Methods
draw_arc(args)
click to toggle source
# File lib/gtk2svg.rb, line 121 def draw_arc(args) dimensions, style = args x, y, width, height = dimensions gc = gc_ini(fill: style[:fill] || :none) @area.window.draw_arc(gc, 1, x, y, width, height, 0, 64 * 360) end
draw_image(args)
click to toggle source
# File lib/gtk2svg.rb, line 131 def draw_image(args) dimensions, src, style = args x, y, width, height = dimensions gc = gc_ini(fill: style[:fill] || :none) if File.exists? src then img = GdkPixbuf::Pixbuf.new(file: src) x ||= 0 y ||= 0 width ||= img.width height ||= img.height @area.window.draw_pixbuf(gc, img, 0, 0, x, y, width, height, Gdk::RGB::DITHER_NONE, 0, 0) end end
draw_layout(args)
click to toggle source
# File lib/gtk2svg.rb, line 198 def draw_layout(args) coords, text, style = args x, y = coords layout = Pango::Layout.new(Gdk::Pango.context) layout.font_description = Pango::FontDescription.\ new('Sans ' + style[:'font-size']) layout.text = text.strip gc = gc_ini(fill: style[:fill] || :none) @area.window.draw_layout(gc, x, y, layout) end
draw_line(args)
click to toggle source
# File lib/gtk2svg.rb, line 152 def draw_line(args) coords, style = args x1, y1, x2, y2 = coords gc = gc_ini(stroke: style[:stroke] || :none) gc.set_line_attributes(style[:'stroke-width'].to_i, Gdk::GC::LINE_SOLID, \ Gdk::GC::CAP_NOT_LAST, Gdk::GC::JOIN_MITER) @area.window.draw_line(gc, x1, y1, x2, y2) end
draw_lines(args)
click to toggle source
# File lib/gtk2svg.rb, line 175 def draw_lines(args) points, style = args gc = gc_ini(fill: style[:fill] || :none, stroke: style[:stroke] || :none) gc.set_line_attributes(style[:'stroke-width'].to_i, Gdk::GC::LINE_SOLID, \ Gdk::GC::CAP_NOT_LAST, Gdk::GC::JOIN_MITER) @area.window.draw_lines(gc, points) end
draw_polygon(args)
click to toggle source
# File lib/gtk2svg.rb, line 164 def draw_polygon(args) points, style = args gc = gc_ini(fill: style[:fill] || :none, stroke: style[:stroke] || :none) gc.set_line_attributes(style[:'stroke-width'].to_i, Gdk::GC::LINE_SOLID, \ Gdk::GC::CAP_NOT_LAST, Gdk::GC::JOIN_MITER) @area.window.draw_polygon(gc, 1, points) end
draw_rectangle(args)
click to toggle source
# File lib/gtk2svg.rb, line 186 def draw_rectangle(args) puts 'inside draw_rectangle' if @debug coords, style, e = args x1, y1, x2, y2 = coords gc = gc_ini(fill: style[:fill] || :none) @area.window.draw_rectangle(gc, 1, x1, y1, x2, y2) end
render(a)
click to toggle source
# File lib/gtk2svg.rb, line 217 def render(a) if @debug then puts 'inside gtk2svg render '.info puts 'a: ' + a.inspect end method(a[0]).call(args=a[1..2]) puts 'after method' if @debug return unless a[3].any? draw a[3] end
script(args)
click to toggle source
# File lib/gtk2svg.rb, line 231 def script(args) end
window(args)
click to toggle source
# File lib/gtk2svg.rb, line 214 def window(args) end
Private Instance Methods
draw(a)
click to toggle source
# File lib/gtk2svg.rb, line 237 def draw(a) a.each do |rawx| x, *remaining = rawx if x.is_a? Symbol then method(x).call(args=remaining) elsif x.is_a? String then draw remaining elsif x.is_a? Array draw remaining else method(x).call(remaining.take 2) end end end
gc_ini(fill: nil, stroke: nil)
click to toggle source
# File lib/gtk2svg.rb, line 276 def gc_ini(fill: nil, stroke: nil) gc = Gdk::GC.new(@area.window) colour = fill || stroke unless colour == :none or colour == 'none' gc.set_foreground(set_colour(colour)) end gc end
set_colour(c)
click to toggle source
# File lib/gtk2svg.rb, line 257 def set_colour(c) colour = case c when /^rgb/ regex = /rgb\((\d{1,3}), *(\d{1,3}), *(\d{1,3})\)$/ r, g, b = c.match(regex).captures.map {|x| x.to_i * 257} colour = Gdk::Color.new(r, g, b) when /^#/ Gdk::Color.parse(c) else Gdk::Color.parse(c) end colormap = Gdk::Colormap.system colormap.alloc_color(colour, false, true) colour end