Class: R2dEngine::Render
- Inherits:
-
DomRender
- Object
- DomRender
- R2dEngine::Render
- Defined in:
- lib/r2dsvg/r2dsvg_module.rb
Instance Method Summary collapse
- #audio(e, attributes) ⇒ Object
- #circle(e, attributes) ⇒ Object
-
#ellipse(e, attributes) ⇒ Object
not yet implemented.
- #g(e, attributes) ⇒ Object
- #image(e, attributes) ⇒ Object
- #line(e, attributes) ⇒ Object
- #polygon(e, attributes) ⇒ Object
- #polyline(e, attributes) ⇒ Object
- #rect(e, attributes) ⇒ Object
- #svg(e, attributes) ⇒ Object
- #text(e, attributes) ⇒ Object
Instance Method Details
#audio(e, attributes) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 63 def audio(e, attributes) puts 'inside audio attributes: ' + attributes.inspect if @debug h = attributes sources = e.xpath('source').map do |x| h = x.attributes.to_h h.delete :style h end [:embed_audio, sources, e] end |
#circle(e, attributes) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 78 def circle(e, attributes) h = attributes x, y, radius= %i(cx cy r).map{|x| h[x].to_i } fill = h[:fill] [:draw_circle, [x, y], radius, fill, attributes, render_all(e)] end |
#ellipse(e, attributes) ⇒ Object
not yet implemented
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 93 def ellipse(e, attributes) 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], attributes, render_all(e)] end |
#g(e, attributes) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 104 def g(e, attributes) puts 'inside rect attributes: ' + attributes.inspect if @debug 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], attributes, e, render_all(e)] end |
#image(e, attributes) ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 127 def image(e, attributes) 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, attributes, e, render_all(e)] end |
#line(e, attributes) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 118 def line(e, attributes) x1, y1, x2, y2 = %i(x1 y1 x2 y2).map{|x| attributes[x].to_i } [:draw_line, [x1, y1, x2, y2], attributes, render_all(e)] end |
#polygon(e, attributes) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 137 def polygon(e, attributes) points = attributes[:points].split(/\s+/). \ map {|x| x.split(/\s*,\s*/).map(&:to_i)} [:draw_polygon, points, attributes, e, render_all(e)] end |
#polyline(e, attributes) ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 146 def polyline(e, attributes) points = attributes[:points].split(/\s+/). \ map {|x| x.split(/\s*,\s*/).map(&:to_i)} [:draw_lines, points, attributes, render_all(e)] end |
#rect(e, attributes) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 154 def rect(e, attributes) puts 'inside rect attributes: ' + attributes.inspect if @debug 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], attributes, e, render_all(e)] end |
#svg(e, attributes) ⇒ Object
168 169 170 171 172 173 174 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 168 def svg(e, attributes) h = attributes width, height = %i(width height).map{|x| h[x].to_i } [:draw_rectangle, [0, 0, width, height], attributes, render_all(e)] end |
#text(e, attributes) ⇒ Object
176 177 178 179 180 181 182 183 184 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 176 def text(e, attributes) attributes.merge!({font_size: '20'}) x, y = %i(x y).map{|x| attributes[x].to_i } [:draw_text, [x, y], e.text, attributes, e, render_all(e)] end |