Class: Gtk2SVG::Render
- Inherits:
-
DomRender
- Object
- DomRender
- Gtk2SVG::Render
- Defined in:
- lib/gtk2svg.rb
Instance Method Summary collapse
- #circle(e, attributes, raw_style) ⇒ Object
- #ellipse(e, attributes, raw_style) ⇒ Object
- #image(e, attributes, raw_style) ⇒ Object
- #line(e, attributes, raw_style) ⇒ Object
- #polygon(e, attributes, raw_style) ⇒ Object
- #polyline(e, attributes, raw_style) ⇒ Object
- #rect(e, attributes, raw_style) ⇒ Object
- #script(e, attributes, style) ⇒ Object
- #svg(e, attributes, raw_style) ⇒ Object
- #text(e, attributes, raw_style) ⇒ Object
Instance Method Details
#circle(e, attributes, raw_style) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gtk2svg.rb', line 18 def circle(e, attributes, raw_style) style = style_filter(attributes).merge(raw_style) h = attributes x, y= %i(cx cy).map{|x| h[x].to_i } radius = h[:r].to_i * 2 [:draw_arc, [x, y, radius, radius], style, render_all(e)] end |
#ellipse(e, attributes, raw_style) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gtk2svg.rb', line 30 def ellipse(e, attributes, raw_style) style = style_filter(attributes).merge(raw_style) h = attributes x, y= %i(cx cy).map{|x| h[x].to_i } width = h[:rx].to_i * 2 height = h[:ry].to_i * 2 [:draw_arc, [x, y, width, height], style, render_all(e)] end |
#image(e, attributes, raw_style) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gtk2svg.rb', line 51 def image(e, attributes, raw_style) style = style_filter(attributes).merge(raw_style) h = attributes x, y, width, height = %i(x y width height).map{|x| h[x] ? h[x].to_i : nil } src = h[:'xlink:href'] [:draw_image, [x, y, width, height], src, style, render_all(e)] end |
#line(e, attributes, raw_style) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/gtk2svg.rb', line 42 def line(e, attributes, raw_style) style = style_filter(attributes).merge(raw_style) x1, y1, x2, y2 = %i(x1 y1 x2 y2).map{|x| attributes[x].to_i } [:draw_line, [x1, y1, x2, y2], style, render_all(e)] end |
#polygon(e, attributes, raw_style) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/gtk2svg.rb', line 62 def polygon(e, attributes, raw_style) style = style_filter(attributes).merge(raw_style) points = attributes[:points].split(/\s+/). \ map {|x| x.split(/\s*,\s*/).map(&:to_i)} [:draw_polygon, points, style, render_all(e)] end |
#polyline(e, attributes, raw_style) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/gtk2svg.rb', line 71 def polyline(e, attributes, raw_style) style = style_filter(attributes).merge(raw_style) points = attributes[:points].split(/\s+/). \ map {|x| x.split(/\s*,\s*/).map(&:to_i)} [:draw_lines, points, style, render_all(e)] end |
#rect(e, attributes, raw_style) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/gtk2svg.rb', line 80 def rect(e, attributes, raw_style) style = style_filter(attributes).merge(raw_style) h = attributes x1, y1, width, height = %i(x y width height).map{|x| h[x].to_i } x2, y2, = x1 + width, y1 + height [:draw_rectangle, [x1, y1, x2, y2], style, render_all(e)] end |
#script(e, attributes, style) ⇒ Object
91 92 93 |
# File 'lib/gtk2svg.rb', line 91 def script(e, attributes, style) [:script] end |
#svg(e, attributes, raw_style) ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/gtk2svg.rb', line 95 def svg(e, attributes, raw_style) style = style_filter(attributes).merge(raw_style) # jr051216 style[:fill] = style.delete :'background-color' h = attributes width, height = %i(width height).map{|x| h[x].to_i } [:draw_rectangle, [0, 0, width, height], style, render_all(e)] end |
#text(e, attributes, raw_style) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/gtk2svg.rb', line 106 def text(e, attributes, raw_style) style = style_filter(attributes).merge(raw_style) style.merge!({font_size: '20'}) x, y = %i(x y).map{|x| attributes[x].to_i } [:draw_layout, [x, y], e.text, style, render_all(e)] end |