Mercurial > MadButterfly
comparison nodejs/svg.js @ 719:1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 15 Aug 2010 01:41:10 +0800 |
parents | 0cd59ce76e67 |
children | 9c5abb4e114b |
comparison
equal
deleted
inserted
replaced
718:0cd59ce76e67 | 719:1b6856fda760 |
---|---|
29 this.parseGroup(root,'root_coord',nodes[k]); | 29 this.parseGroup(root,'root_coord',nodes[k]); |
30 } | 30 } |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 function make_mbnames(mb_rt, n, obj) { | |
35 var mbname; | |
36 var name; | |
37 | |
38 if(!mb_rt.mbnames) | |
39 mb_rt.mbnames = {}; | |
40 | |
41 mbname = n.attr("mbname"); | |
42 if(mbname) { | |
43 name = mbname.value(); | |
44 mb_rt.mbnames[name] = obj; | |
45 } | |
46 } | |
47 | |
34 function getInteger(n,name) | 48 function getInteger(n,name) |
35 { | 49 { |
36 if (n == null) return 0; | 50 if (n == null) return 0; |
37 var a = n.attr(name); | 51 var a = n.attr(name); |
38 if (a==null) return 0; | 52 if (a==null) return 0; |
39 return parseInt(a.value()); | 53 return parseInt(a.value()); |
40 } | 54 } |
55 | |
41 function parsePointSize(s) | 56 function parsePointSize(s) |
42 { | 57 { |
43 var fs=0; | 58 var fs=0; |
44 var i; | 59 var i; |
45 | 60 |
49 } | 64 } |
50 return fs; | 65 return fs; |
51 | 66 |
52 } | 67 } |
53 | 68 |
54 | |
55 function parseColor(c) | 69 function parseColor(c) |
56 { | 70 { |
57 if (c[0] == '#') { | 71 if (c[0] == '#') { |
58 return parseInt(c.substring(1,3),16)<<16 | parseInt(c.substring(3,5),16)<<8 | parseInt(c.substring(5,7),16); | 72 return parseInt(c.substring(1,3),16)<<16 | parseInt(c.substring(3,5),16)<<8 | parseInt(c.substring(5,7),16); |
59 } | 73 } |
60 } | 74 } |
75 | |
61 function parseTextStyle(style,n) | 76 function parseTextStyle(style,n) |
62 { | 77 { |
63 var attr; | 78 var attr; |
64 if (n) { | 79 if (n) { |
65 attr = n.attr('style'); | 80 attr = n.attr('style'); |
121 if (name == "tspan") { | 136 if (name == "tspan") { |
122 this.parseTSpan(tcoord,nodes[k]); | 137 this.parseTSpan(tcoord,nodes[k]); |
123 } else { | 138 } else { |
124 } | 139 } |
125 } | 140 } |
141 make_mbnames(this.mb_rt, n, tcoord); | |
126 } | 142 } |
127 | 143 |
128 loadSVG.prototype._prepare_paint_color=function(color, alpha) { | 144 loadSVG.prototype._prepare_paint_color=function(color, alpha) { |
129 var paint; | 145 var paint; |
130 var c; | 146 var c; |
198 } | 214 } |
199 } else { | 215 } else { |
200 black_paint.stroke(path); | 216 black_paint.stroke(path); |
201 } | 217 } |
202 coord.add_shape(path); | 218 coord.add_shape(path); |
219 | |
220 make_mbnames(this.mb_rt, n, path); | |
203 } | 221 } |
204 | 222 |
205 loadSVG.prototype.parseText=function(coord,id, n) | 223 loadSVG.prototype.parseText=function(coord,id, n) |
206 { | 224 { |
207 var x = getInteger(n,'x'); | 225 var x = getInteger(n,'x'); |
219 this.parseTSpan(tcoord,nodes[k],style); | 237 this.parseTSpan(tcoord,nodes[k],style); |
220 } else { | 238 } else { |
221 } | 239 } |
222 } | 240 } |
223 | 241 |
224 | 242 make_mbnames(this.mb_rt, n, tcoord); |
225 } | 243 } |
226 | 244 |
227 function parseTransform(coord, s) | 245 function parseTransform(coord, s) |
228 { | 246 { |
229 var off = s.indexOf('translate'); | 247 var off = s.indexOf('translate'); |
322 if (trans!=null) { | 340 if (trans!=null) { |
323 parseTransform(coord, trans.value()); | 341 parseTransform(coord, trans.value()); |
324 } | 342 } |
325 | 343 |
326 for(k in nodes) { | 344 for(k in nodes) { |
327 var n = nodes[k].name(); | 345 var c = nodes[k].name(); |
328 var attr = nodes[k].attr('id'); | 346 var attr = nodes[k].attr('id'); |
329 var id; | 347 var id; |
330 if (attr) { | 348 if (attr) { |
331 id = attr.value(); | 349 id = attr.value(); |
332 } | 350 } |
333 if (n == "g") { | 351 if (c == "g") { |
334 this.parseGroup(coord, id, nodes[k]); | 352 this.parseGroup(coord, id, nodes[k]); |
335 } else if (n == "path") { | 353 } else if (c == "path") { |
336 this.parsePath(coord, id, nodes[k]); | 354 this.parsePath(coord, id, nodes[k]); |
337 } else if (n == "text") { | 355 } else if (c == "text") { |
338 this.parseText(coord, id, nodes[k]); | 356 this.parseText(coord, id, nodes[k]); |
339 } else if (n == "rect") { | 357 } else if (c == "rect") { |
340 this.parseRect(coord, id, nodes[k]); | 358 this.parseRect(coord, id, nodes[k]); |
341 } else if (n == "image") { | 359 } else if (c == "image") { |
342 this.parseImage(coord, id, nodes[k]); | 360 this.parseImage(coord, id, nodes[k]); |
343 } | 361 } |
344 } | 362 } |
345 | 363 |
364 make_mbnames(this.mb_rt, n, coord); | |
346 } | 365 } |
347 | 366 |
348 loadSVG.prototype.parseImage=function(coord,id, n) | 367 loadSVG.prototype.parseImage=function(coord,id, n) |
349 { | 368 { |
350 sys.puts("---> image"); | 369 sys.puts("---> image"); |
381 var img_data = ldr.load(ref); | 400 var img_data = ldr.load(ref); |
382 sys.puts(img_data); | 401 sys.puts(img_data); |
383 var paint = this.mb_rt.paint_image_new(img_data); | 402 var paint = this.mb_rt.paint_image_new(img_data); |
384 paint.fill(img); | 403 paint.fill(img); |
385 coord.add_shape(img); | 404 coord.add_shape(img); |
405 make_mbnames(this.mb_rt, n, img); | |
386 } | 406 } |
387 | 407 |
388 loadSVG.prototype.parseDefs=function(root,n) | 408 loadSVG.prototype.parseDefs=function(root,n) |
389 { | 409 { |
390 var k; | 410 var k; |