Mercurial > MadButterfly
diff nodejs/svg.js @ 978:78312b44f48c
Implement Scene API.
author | wycc |
---|---|
date | Sat, 20 Nov 2010 20:04:31 +0800 |
parents | a9abcdac0ae5 |
children | 593a418ed8bf |
line wrap: on
line diff
--- a/nodejs/svg.js Sat Nov 20 15:46:03 2010 +0800 +++ b/nodejs/svg.js Sat Nov 20 20:04:31 2010 +0800 @@ -72,12 +72,16 @@ var n = nodes[k].name(); if (n == "defs") { this.parseDefs(coord,nodes[k]); + } else if (n == "metadata") { + this.parseMetadata(coord,nodes[k]); } else if (n == "g") { this.parseGroup(accu,coord,'root_coord',nodes[k]); } } } + + loadSVG.prototype.leaveSVG=function() { var p = this.pgstack.pop(); @@ -104,6 +108,12 @@ name = mbname.value(); mb_rt.mbnames[name] = obj; } + try { + var gname = n.attr('id').value(); + sys.puts(gname); + mb_rt.mbnames[gname] = obj; + } catch(e) { + } } function getInteger(n,name) @@ -1117,7 +1127,8 @@ href = href.value(); var hrefid = href.substring(1); pstops = this.stop_ref[hrefid]; - stops = pstops.concat(stops); + if (pstops) + stops = pstops.concat(stops); var hrefgr = this.gradients[hrefid]; if(typeof x1 == "undefined") @@ -1191,6 +1202,44 @@ this.stop_ref[id] = stops; } +loadSVG.prototype.parseScenes=function(coord,node) { + var nodes = node.childNodes(); + + for(k in nodes) { + var name = nodes[k].name(); + if (name == 'scene') { + var node = nodes[k]; + + scene = new Object(); + scene.start = parseInt(node.attr('start').value()); + try { + scene.end = parseInt(node.attr('end').value()); + } catch(e) { + scene.end = scene.start; + } + scene.ref = node.attr('ref').value(); + + try { + this.scenenames[node.attr('name').value()] = scene.start; + } catch(e) { + } + this.scenes.push(scene); + } + } +} + +loadSVG.prototype.parseMetadata=function(coord,node) { + var nodes = node.childNodes(); + + for(k in nodes) { + var name = nodes[k].name(); + if (name == 'scenes') { + this.scenes=[]; + this.scenenames={}; + this.parseScenes(coord,nodes[k]); + } + } +} loadSVG.prototype.parseDefs=function(root,n) { var k;