r2dsvg 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ace8319852e656e2f92b8277bf237679fd0607f475d8d3cf8202eaed8ed583d7
4
- data.tar.gz: 55fa2c0ee725a5fd8c22ebac07d0d8cf0f54598c9934e2152ff6245a1386d85e
3
+ metadata.gz: 8296973a57c753bc725b879e70c9479f439a50feb5d7b5330be4694f54b5605e
4
+ data.tar.gz: 2ef0ea5d588963e2e429817ae0e044f258e3f2af08b8dca29171998595357ae8
5
5
  SHA512:
6
- metadata.gz: ba05b63001637286b4d9adfbab2f8e3b39871b74933e513785e0fda4b860fcd6695952d56c01d2a0272566f9b6a59869219d74f531c9820ea05642e3026110e8
7
- data.tar.gz: c39b551a7b759b376844352e0c8150c76c5a7b9d064a9e89d007f82b0e6e9589d44e5d561043de4a226bfa9ff427d9d32c7a3b720de80b7ef729fca38b049bca
6
+ metadata.gz: 55f66186da14d03535b3c1c5a201e8aa9f2c8c331ec5c7df5b13269e3357a0bd083ddebcaeeb3a9b21beed39a13d65638074f324dec8abd5b434a71bf23af335
7
+ data.tar.gz: ea0e41cfb9a3751f53692ba1890f433ba80cfbc39698ccd500b9a58cd99bff9d31885671831664a5707ad6bd1c3feaae9e67cb96b8dbfec3191d36bf49c4e0e3
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/r2dsvg.rb CHANGED
@@ -9,6 +9,14 @@ require 'svgle'
9
9
  require 'ruby2d' # experimental gem depends upon simple2d binaries
10
10
  require 'dom_render'
11
11
 
12
+ DEFAULT_CSS = <<CSS
13
+
14
+ svg {background-color: white}
15
+ rect {fill: yellow}
16
+ line, polyline {stroke: green; stroke-width: 3}
17
+ text {fill: red, size: 20}
18
+
19
+ CSS
12
20
 
13
21
 
14
22
  class R2dSvg
@@ -16,6 +24,21 @@ class R2dSvg
16
24
  using ColouredText
17
25
 
18
26
  class Render < DomRender
27
+
28
+ def audio(e, attributes, raw_style)
29
+
30
+ puts 'inside audio attributes: ' + attributes.inspect if @debug
31
+ style = style_filter(attributes).merge(raw_style)
32
+ h = attributes
33
+
34
+ sources = e.xpath('source').map do |x|
35
+ h = x.attributes.to_h
36
+ h.delete :style
37
+ h
38
+ end
39
+
40
+ [:embed_audio, sources ]
41
+ end
19
42
 
20
43
  def rect(e, attributes, raw_style)
21
44
 
@@ -28,6 +51,10 @@ class R2dSvg
28
51
 
29
52
  [:draw_rectangle, [x1, y1, x2, y2], style, render_all(e)]
30
53
  end
54
+
55
+ def script(e, attributes, style)
56
+ [:script]
57
+ end
31
58
 
32
59
  def svg(e, attributes, raw_style)
33
60
 
@@ -38,6 +65,16 @@ class R2dSvg
38
65
 
39
66
  [:draw_rectangle, [0, 0, width, height], style, render_all(e)]
40
67
  end
68
+
69
+ def text(e, attributes, raw_style)
70
+
71
+ style = style_filter(attributes).merge(raw_style)
72
+ style.merge!({font_size: '20'})
73
+
74
+ x, y = %i(x y).map{|x| attributes[x].to_i }
75
+
76
+ [:draw_text, [x, y], e.text, style, render_all(e)]
77
+ end
41
78
 
42
79
  private
43
80
 
@@ -83,6 +120,51 @@ class R2dSvg
83
120
 
84
121
  end
85
122
 
123
+ def draw_text(args)
124
+
125
+ coords, text, style = args
126
+
127
+ x, y = coords
128
+
129
+ if @debug then
130
+ puts 'inside draw_text'.info
131
+ puts ('style: ' + style.inspect).debug
132
+ end
133
+
134
+ @window.add Text.new(
135
+ text,
136
+ x: x, y: y,
137
+ #font: 'vera.ttf',
138
+ size: style[:font_size].to_i,
139
+ color: style[:color],
140
+ z: style[:"z-index"].to_i
141
+ )
142
+
143
+ end
144
+
145
+ # Ruby 2D supports a number of popular audio formats, including WAV,
146
+ # MP3, Ogg Vorbis, and FLAC.
147
+
148
+ def embed_audio(args)
149
+
150
+ sources, _ = args
151
+
152
+ if @debug then
153
+ puts 'sources: ' + sources.inspect if @debug
154
+ puts 'inside embed_audio'.info
155
+ end
156
+
157
+ audio = sources.find do |source|
158
+ File.exists? source[:src]
159
+ end
160
+
161
+ return unless audio
162
+
163
+ file = File.exists? audio[:src]? audio[:src] : nil
164
+ @window.add = Sound.new(file)
165
+
166
+ end
167
+
86
168
  def window(args)
87
169
  end
88
170
 
@@ -91,6 +173,9 @@ class R2dSvg
91
173
  draw a[3]
92
174
  end
93
175
 
176
+ def script(args)
177
+
178
+ end
94
179
 
95
180
  private
96
181
 
@@ -127,9 +212,27 @@ class R2dSvg
127
212
  puts ('instructions: ' + instructions.inspect).debug if @debug
128
213
 
129
214
  @width, @height = %i(width height).map{|x| doc.root.attributes[x].to_i }
130
- window.set title: title, width: @width, height: @height
131
-
215
+ window.set title: title, width: @width, height: @height
216
+
217
+ def doc.element_by_id(id)
218
+ self.root.element("//*[@id='#{id}']")
219
+ end
220
+
221
+ doc.root.xpath('//script').each {|x| eval x.text.unescape }
222
+
132
223
  drawing.render instructions
224
+
225
+ window.on :mouse_move do |event|
226
+
227
+ @doc.root.xpath('//*[@onmousemove]').each do |x|
228
+
229
+ eval x.onmousemove() if x.hotspot? event.x, event.y
230
+
231
+ end
232
+
233
+ end
234
+
235
+ @doc = doc
133
236
  window.show
134
237
  end
135
238
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r2dsvg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file