Mercurial > MadButterfly
annotate nodejs/svg.js @ 709:920c9e6e4214
Make code clear
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 13 Aug 2010 17:51:21 +0800 |
parents | ac9c20db953e |
children | c93381320d6e |
rev | line source |
---|---|
624 | 1 var libxml = require('libxmljs'); |
2 var sys=require('sys'); | |
3 var mbfly = require("mbfly"); | |
4 var mb_rt = new mbfly.mb_rt(":0.0", 720,480); | |
646 | 5 var ldr = mbfly.img_ldr_new("."); |
709 | 6 var background = mb_rt.rect_new(0, 0, 720, 480, 0, 0); |
7 var paint = mb_rt.paint_color_new(1, 1, 1, 1); | |
8 paint.fill(background); | |
9 mb_rt.root.add_shape(background); | |
624 | 10 |
11 function MB_loadSVG(mb_rt,root,filename) { | |
12 var doc = libxml.parseXmlFile(filename); | |
13 var nodes = doc.root().childNodes(); | |
14 var coord = mb_rt.coord_new(root); | |
15 var k; | |
16 | |
17 for(k in nodes) { | |
18 var n = nodes[k].name(); | |
19 if (n == "defs") { | |
20 _MB_parseDefs(root,nodes[k]); | |
21 } else if (n == "g") { | |
22 _MB_parseGroup(root,'root_coord',nodes[k]); | |
23 } | |
24 } | |
25 } | |
26 | |
27 function getInteger(n,name) | |
28 { | |
29 if (n == null) return 0; | |
30 var a = n.attr(name); | |
31 if (a==null) return 0; | |
32 return parseInt(a.value()); | |
33 } | |
631 | 34 function parsePointSize(s) |
35 { | |
36 var fs=0; | |
37 var i; | |
624 | 38 |
631 | 39 for(i=0;i<s.length;i++) { |
40 if (s[i]<'0' || s[i] > '9') break; | |
41 fs = fs*10 + (s[i]-'0'); | |
42 } | |
43 return fs; | |
44 | |
45 } | |
46 | |
47 | |
48 function parseColor(c) | |
49 { | |
50 if (c[0] == '#') { | |
51 return parseInt(c.substring(1,3),16)<<16 | parseInt(c.substring(3,5),16)<<8 | parseInt(c.substring(5,7),16); | |
52 } | |
53 } | |
54 function parseTextStyle(style,n) | |
624 | 55 { |
625
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
56 var attr; |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
57 if (n) { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
58 attr = n.attr('style'); |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
59 } else { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
60 attr = null; |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
61 } |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
62 if (attr == null) { |
631 | 63 return; |
625
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
64 } |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
65 var f = attr.value().split(';'); |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
66 |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
67 for(i in f) { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
68 var kv = f[i].split(':'); |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
69 if (kv[0] == 'font-size') { |
631 | 70 style.fs = parsePointSize(kv[1]); |
625
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
71 } else if (kv[0] == "font-style") { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
72 } else if (kv[0] == "font-weight") { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
73 } else if (kv[0] == "fill") { |
631 | 74 style.color = parseColor(kv[1]); |
625
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
75 } else if (kv[0] == "fill-opacity") { |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
76 } else if (kv[0] == "stroke-opacity") { |
625
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
77 } else if (kv[0] == "stroke") { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
78 } else if (kv[0] == "stroke-width") { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
79 } else if (kv[0] == "stroke-linecap") { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
80 } else if (kv[0] == "stroke-linejoin") { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
81 } else if (kv[0] == "stroke-lineopacity") { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
82 } else if (kv[0] == "font-family") { |
631 | 83 style.family = kv[1]; |
625
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
84 } else if (kv[0] == "font-stretch") { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
85 } else if (kv[0] == "font-variant") { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
86 } else if (kv[0] == "text-anchor") { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
87 } else if (kv[0] == "text-align") { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
88 } else if (kv[0] == "writing-mode") { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
89 } else if (kv[0] == "line-height") { |
632 | 90 } else { |
625
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
91 sys.puts("Unknown style: "+kv[0]); |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
92 } |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
93 } |
624 | 94 } |
95 | |
631 | 96 function _MB_parseTSpan(coord, n,style) |
624 | 97 { |
98 var x = getInteger(n,'x'); | |
99 var y = getInteger(n,'y'); | |
100 var tcoord = mb_rt.coord_new(coord); | |
101 var nodes = n.childNodes(); | |
102 var k; | |
103 | |
104 sys.puts(n.text()); | |
105 var obj = mb_rt.stext_new(n.text(),x,y); | |
631 | 106 parseTextStyle(style,n); |
107 style.paint = mb_rt.paint_color_new(1,1,1,1); | |
108 style.face=mb_rt.font_face_query(style.family, 2, 100); | |
109 obj.set_style([[20,style.face,style.fs]]); | |
110 style.paint.fill(obj); | |
624 | 111 tcoord.add_shape(obj); |
112 for(k in nodes) { | |
113 var name = nodes[k].name(); | |
114 if (name == "tspan") { | |
115 _MB_parseTSpan(tcoord,nodes[k]); | |
116 } else { | |
117 } | |
118 } | |
119 } | |
120 | |
706 | 121 function _prepare_paint_color(color, alpha) { |
122 var paint; | |
123 | |
124 if (color[0]=='#') { | |
125 var r,g,b; | |
126 r = parseInt(color.substring(1,3),16)/256; | |
127 g = parseInt(color.substring(3,5),16)/256; | |
128 b = parseInt(color.substring(5,7),16)/256; | |
129 paint = mb_rt.paint_color_new(r, g, b, alpha); | |
130 } else { | |
131 paint = mb_rt.paint_color_new(0,0,0,1); | |
132 } | |
133 return paint; | |
134 } | |
135 | |
136 function _MB_parsePath(coord,id, n) | |
137 { | |
138 var d = n.attr('d').value(); | |
139 var style = n.attr('style'); | |
140 var path = mb_rt.path_new(d); | |
141 var paint; | |
142 | |
143 if (style==null) { | |
144 paint = mb_rt.paint_color_new(0,0,0,0.1); | |
145 paint.stroke(path); | |
146 } else { | |
147 var items = style.value().split(';'); | |
148 var fill_alpha = 1; | |
149 var stroke_alpha = 1; | |
150 var fill_color; | |
151 var stroke_color; | |
152 var alpha; | |
153 | |
154 for(i in items) { | |
155 sys.puts(items[i]); | |
156 var f = items[i].split(':'); | |
157 if (f[0] == 'opacity') { | |
158 alpha = f[1]; | |
159 } else if (f[0] == 'fill') { | |
160 if(f[1] != "none") | |
161 fill_color = f[1]; | |
162 } else if (f[0] == 'fill-opacity') { | |
163 fill_alpha = parseFloat(f[1]); | |
164 } else if (f[0] == 'stroke') { | |
165 if(f[1] != "none") | |
166 stroke_color = f[1]; | |
167 } else if (f[0] == 'stroke-width') { | |
168 path.stroke_width = parseFloat(f[1]); | |
169 } else if (f[0] == 'stroke-opacity') { | |
170 stroke_alpha = parseFloat(f[1]); | |
171 } | |
172 } | |
173 | |
174 if(fill_color) { | |
175 paint = _prepare_paint_color(fill_color, fill_alpha); | |
176 paint.fill(path); | |
177 } | |
178 if(stroke_color) { | |
179 paint = _prepare_paint_color(stroke_color, stroke_alpha); | |
180 paint.stroke(path); | |
181 } | |
182 | |
183 } | |
184 coord.add_shape(path); | |
185 } | |
186 | |
624 | 187 function _MB_parseText(coord,id, n) |
188 { | |
189 var x = getInteger(n,'x'); | |
190 var y = getInteger(n,'y'); | |
191 var tcoord = mb_rt.coord_new(coord); | |
631 | 192 var style = new Object(); |
193 style.fs = 20; | |
194 style.family = 'courier'; | |
195 parseTextStyle(style,n); | |
624 | 196 var nodes = n.childNodes(); |
197 var k; | |
198 for(k in nodes) { | |
199 var n = nodes[k].name(); | |
200 if (n == "tspan") { | |
631 | 201 _MB_parseTSpan(tcoord,nodes[k],style); |
624 | 202 } else { |
203 } | |
204 } | |
205 | |
206 | |
207 } | |
208 | |
209 function parseTransform(coord, s) | |
210 { | |
211 var off = s.indexOf('translate'); | |
212 if (off != -1) { | |
213 var ss = s.substring(off+9); | |
214 for(i=0;i<ss.length;i++) { | |
215 if (ss[i] == '(') break; | |
216 } | |
217 ss = ss.substring(i+1); | |
218 for(i=0;i<ss.length;i++) { | |
219 if (ss[i] == ')') { | |
220 ss = ss.substring(0,i); | |
221 break; | |
222 } | |
223 } | |
224 var f = ss.split(','); | |
225 var x,y; | |
706 | 226 x = parseFloat(f[0]); |
227 y = parseFloat(f[1]); | |
228 coord[0] = 1; | |
229 coord[1] = 0; | |
230 coord[2] = x; | |
231 coord[3] = 0; | |
232 coord[4] = 1; | |
624 | 233 coord[5] = y; |
234 } | |
235 off = s.indexOf('matrix'); | |
236 if (off != -1) { | |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
237 var end = s.indexOf(')'); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
238 var m = s.substring(7,end); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
239 var fields = m.split(','); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
240 coord[0] = parseFloat(fields[0]); |
706 | 241 coord[1] = parseFloat(fields[2]); |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
242 coord[2] = parseFloat(fields[4]); |
706 | 243 coord[3] = parseFloat(fields[1]); |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
244 coord[4] = parseFloat(fields[3]); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
245 coord[5] = parseFloat(fields[5]); |
624 | 246 } |
247 } | |
248 | |
249 function _MB_parseRect(coord, id, n) | |
250 { | |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
251 var x = getInteger(n,'x'); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
252 var y = getInteger(n,'y'); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
253 var w = getInteger(n,'width'); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
254 var h = getInteger(n,'height'); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
255 var paint; |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
256 |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
257 var style = n.attr('style'); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
258 |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
259 if (style==null) { |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
260 paint = mb_rt.paint_color_new(0,0,0,0.1); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
261 } else { |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
262 var items = style.value().split(';'); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
263 var fill = ''; |
708
ac9c20db953e
Default alpha of a tag is '1'
Thinker K.F. Li <thinker@branda.to>
parents:
706
diff
changeset
|
264 var alpha = 1; |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
265 for(i in items) { |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
266 sys.puts(items[i]); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
267 var f = items[i].split(':'); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
268 if (f[0] == 'opacity') { |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
269 alpha = f[1]; |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
270 } else if (f[0] == 'fill') { |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
271 fill = f[1]; |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
272 } else if (f[0] == 'fill-opacity') { |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
273 } else if (f[0] == 'stroke') { |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
274 } else if (f[0] == 'stroken-width') { |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
275 } else if (f[0] == 'stroke-opacity') { |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
276 } |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
277 } |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
278 sys.puts("fill="+fill); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
279 if (fill[0]=='#') { |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
280 var r,g,b; |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
281 r = parseInt(fill.substring(1,3),16)/256; |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
282 g = parseInt(fill.substring(3,5),16)/256; |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
283 b = parseInt(fill.substring(5,7),16)/256; |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
284 sys.puts("r="+r+" g="+g+" b="+b+" a="+alpha); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
285 |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
286 paint = mb_rt.paint_color_new(r,g,b,parseFloat(alpha)); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
287 } else { |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
288 paint = mb_rt.paint_color_new(0,0,0,1); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
289 } |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
290 } |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
291 var rect = mb_rt.rect_new(x,y,w,h,10, 10); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
292 sys.puts("rect x="+x+" y="+y+" w="+w+" h="+h); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
293 paint.fill(rect); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
294 coord.add_shape(rect); |
624 | 295 } |
296 | |
297 function _MB_parseGroup(root, group_id, n) | |
298 { | |
299 var k; | |
300 var nodes = n.childNodes(); | |
301 var coord = mb_rt.coord_new(root); | |
302 // Parse the transform and style here | |
303 var trans = n.attr('transform'); | |
304 if (trans!=null) { | |
305 parseTransform(coord, trans.value()); | |
306 } | |
307 | |
308 for(k in nodes) { | |
309 var n = nodes[k].name(); | |
310 var attr = nodes[k].attr('id'); | |
311 var id; | |
312 if (attr) { | |
313 id = attr.value(); | |
314 } | |
315 if (n == "g") { | |
316 _MB_parseGroup(coord, id, nodes[k]); | |
706 | 317 } else if (n == "path") { |
318 _MB_parsePath(coord, id, nodes[k]); | |
624 | 319 } else if (n == "text") { |
320 _MB_parseText(coord, id, nodes[k]); | |
321 } else if (n == "rect") { | |
322 _MB_parseRect(coord, id, nodes[k]); | |
646 | 323 } else if (n == "image") { |
324 _MB_parseImage(coord, id, nodes[k]); | |
624 | 325 } |
326 } | |
327 | |
328 } | |
329 | |
646 | 330 function _MB_parseImage(coord,id, n) |
331 { | |
332 sys.puts("---> image"); | |
333 var ref = n.attr('href').value(); | |
334 | |
335 if (ref == null) return; | |
336 sys.puts(ref); | |
647 | 337 if (ref.substr(0,7) == "file://") { |
338 ref = ref.substring(7); | |
339 } else if (ref.substr(0,5)=="file:") { | |
340 ref = ref.substring(5); | |
341 } else { | |
646 | 342 return; |
343 } | |
344 sys.puts("Load image "+ref); | |
345 var w; | |
346 var h; | |
347 var x,y; | |
348 | |
349 w = n.attr("width"); | |
350 if (w == null) return; | |
351 w = parseInt(w.value()); | |
352 h = n.attr("height"); | |
353 if (h == null) return; | |
354 h = parseInt(h.value()); | |
355 x = n.attr("x"); | |
356 if (x == null) return; | |
357 x = parseInt(x.value()); | |
358 y = n.attr("y"); | |
359 if (y == null) return; | |
360 y = parseInt(y.value()); | |
361 sys.puts("x="+x+",y="+y+",w="+w+",h="+h); | |
362 var img = mb_rt.image_new(x,y,w,h); | |
363 var img_data = ldr.load(ref); | |
364 sys.puts(img_data); | |
365 var paint = mb_rt.paint_image_new(img_data); | |
366 paint.fill(img); | |
367 coord.add_shape(img); | |
368 } | |
624 | 369 |
370 function _MB_parseDefs(root,n) | |
371 { | |
372 var k; | |
373 var nodes = n.childNodes(); | |
374 | |
375 for(k in nodes) { | |
376 var name = nodes[k].name(); | |
377 if (name == "linearGradient") { | |
378 //_MB_parseLinearGradient(root,nodes[k]); | |
379 } | |
380 } | |
381 } | |
382 | |
383 | |
384 MB_loadSVG(mb_rt,mb_rt.root,"test.svg"); | |
385 mb_rt.redraw_all(); | |
704
d950487bd9f9
Flush mb_rt, immediately, after redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
703
diff
changeset
|
386 mb_rt.flush(); |