Mercurial > MadButterfly
comparison nodejs/svg.js @ 718:0cd59ce76e67
Refactor loadSVG as a class
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 15 Aug 2010 01:26:09 +0800 |
parents | b822b1912d67 |
children | 1b6856fda760 |
comparison
equal
deleted
inserted
replaced
717:b822b1912d67 | 718:0cd59ce76e67 |
---|---|
9 "black": [0, 0, 0], | 9 "black": [0, 0, 0], |
10 "red": [1, 0, 0] | 10 "red": [1, 0, 0] |
11 }; | 11 }; |
12 | 12 |
13 exports.loadSVG=function(mb_rt,root,filename) { | 13 exports.loadSVG=function(mb_rt,root,filename) { |
14 return new loadSVG(mb_rt, root, filename); | |
15 }; | |
16 | |
17 function loadSVG(mb_rt, root, filename) { | |
14 var doc = libxml.parseXmlFile(filename); | 18 var doc = libxml.parseXmlFile(filename); |
15 var nodes = doc.root().childNodes(); | 19 var nodes = doc.root().childNodes(); |
16 var coord = mb_rt.coord_new(root); | 20 var coord = mb_rt.coord_new(root); |
17 var k; | 21 var k; |
18 this.mb_rt = mb_rt; | 22 this.mb_rt = mb_rt; |
94 sys.puts("Unknown style: "+kv[0]); | 98 sys.puts("Unknown style: "+kv[0]); |
95 } | 99 } |
96 } | 100 } |
97 } | 101 } |
98 | 102 |
99 exports.parseTSpan=function(coord, n,style) | 103 loadSVG.prototype.parseTSpan=function(coord, n,style) |
100 { | 104 { |
101 var x = getInteger(n,'x'); | 105 var x = getInteger(n,'x'); |
102 var y = getInteger(n,'y'); | 106 var y = getInteger(n,'y'); |
103 var tcoord = this.mb_rt.coord_new(coord); | 107 var tcoord = this.mb_rt.coord_new(coord); |
104 var nodes = n.childNodes(); | 108 var nodes = n.childNodes(); |
119 } else { | 123 } else { |
120 } | 124 } |
121 } | 125 } |
122 } | 126 } |
123 | 127 |
124 exports._prepare_paint_color=function(color, alpha) { | 128 loadSVG.prototype._prepare_paint_color=function(color, alpha) { |
125 var paint; | 129 var paint; |
126 var c; | 130 var c; |
127 | 131 |
128 if (color[0]=='#') { | 132 if (color[0]=='#') { |
129 var r,g,b; | 133 var r,g,b; |
138 paint = this.mb_rt.paint_color_new(0,0,0,1); | 142 paint = this.mb_rt.paint_color_new(0,0,0,1); |
139 } | 143 } |
140 return paint; | 144 return paint; |
141 } | 145 } |
142 | 146 |
143 exports.parsePath=function(coord,id, n) | 147 loadSVG.prototype.parsePath=function(coord,id, n) |
144 { | 148 { |
145 var d = n.attr('d').value(); | 149 var d = n.attr('d').value(); |
146 var style = n.attr('style'); | 150 var style = n.attr('style'); |
147 var path = this.mb_rt.path_new(d); | 151 var path = this.mb_rt.path_new(d); |
148 var paint; | 152 var paint; |
196 black_paint.stroke(path); | 200 black_paint.stroke(path); |
197 } | 201 } |
198 coord.add_shape(path); | 202 coord.add_shape(path); |
199 } | 203 } |
200 | 204 |
201 exports.parseText=function(coord,id, n) | 205 loadSVG.prototype.parseText=function(coord,id, n) |
202 { | 206 { |
203 var x = getInteger(n,'x'); | 207 var x = getInteger(n,'x'); |
204 var y = getInteger(n,'y'); | 208 var y = getInteger(n,'y'); |
205 var tcoord = this.mb_rt.coord_new(coord); | 209 var tcoord = this.mb_rt.coord_new(coord); |
206 var style = new Object(); | 210 var style = new Object(); |
258 coord[4] = parseFloat(fields[3]); | 262 coord[4] = parseFloat(fields[3]); |
259 coord[5] = parseFloat(fields[5]); | 263 coord[5] = parseFloat(fields[5]); |
260 } | 264 } |
261 } | 265 } |
262 | 266 |
263 exports.parseRect=function(coord, id, n) | 267 loadSVG.prototype.parseRect=function(coord, id, n) |
264 { | 268 { |
265 var x = getInteger(n,'x'); | 269 var x = getInteger(n,'x'); |
266 var y = getInteger(n,'y'); | 270 var y = getInteger(n,'y'); |
267 var w = getInteger(n,'width'); | 271 var w = getInteger(n,'width'); |
268 var h = getInteger(n,'height'); | 272 var h = getInteger(n,'height'); |
306 sys.puts("rect x="+x+" y="+y+" w="+w+" h="+h); | 310 sys.puts("rect x="+x+" y="+y+" w="+w+" h="+h); |
307 paint.fill(rect); | 311 paint.fill(rect); |
308 coord.add_shape(rect); | 312 coord.add_shape(rect); |
309 } | 313 } |
310 | 314 |
311 exports.parseGroup=function(root, group_id, n) | 315 loadSVG.prototype.parseGroup=function(root, group_id, n) |
312 { | 316 { |
313 var k; | 317 var k; |
314 var nodes = n.childNodes(); | 318 var nodes = n.childNodes(); |
315 var coord = this.mb_rt.coord_new(root); | 319 var coord = this.mb_rt.coord_new(root); |
316 // Parse the transform and style here | 320 // Parse the transform and style here |
339 } | 343 } |
340 } | 344 } |
341 | 345 |
342 } | 346 } |
343 | 347 |
344 exports.parseImage=function(coord,id, n) | 348 loadSVG.prototype.parseImage=function(coord,id, n) |
345 { | 349 { |
346 sys.puts("---> image"); | 350 sys.puts("---> image"); |
347 var ref = n.attr('href').value(); | 351 var ref = n.attr('href').value(); |
348 | 352 |
349 if (ref == null) return; | 353 if (ref == null) return; |
379 var paint = this.mb_rt.paint_image_new(img_data); | 383 var paint = this.mb_rt.paint_image_new(img_data); |
380 paint.fill(img); | 384 paint.fill(img); |
381 coord.add_shape(img); | 385 coord.add_shape(img); |
382 } | 386 } |
383 | 387 |
384 exports.parseDefs=function(root,n) | 388 loadSVG.prototype.parseDefs=function(root,n) |
385 { | 389 { |
386 var k; | 390 var k; |
387 var nodes = n.childNodes(); | 391 var nodes = n.childNodes(); |
388 | 392 |
389 for(k in nodes) { | 393 for(k in nodes) { |