Mercurial > MadButterfly
diff nodejs/svg.js @ 914:e4474cac20da
Implement the page stack
author | wycc |
---|---|
date | Thu, 21 Oct 2010 23:56:55 +0800 |
parents | e86b4d56ddea |
children | 35b6a9411e26 |
line wrap: on
line diff
--- a/nodejs/svg.js Thu Oct 21 23:56:14 2010 +0800 +++ b/nodejs/svg.js Thu Oct 21 23:56:55 2010 +0800 @@ -32,12 +32,15 @@ return [r, g, b]; } -exports.loadSVG=function(mb_rt,root,filename) { - return new loadSVG(mb_rt, root, filename); -}; - +exports.loadSVG=loadSVG; function loadSVG(mb_rt, root, filename) { + this.pgstack=[]; + if (filename) + this.load(mb_rt,root,filename); +} + +loadSVG.prototype.load=function(mb_rt, root, filename) { var doc = libxml.parseXmlFile(filename); var _root = doc.root(); var nodes = _root.childNodes(); @@ -48,9 +51,13 @@ this.stop_ref={}; this.gradients={}; this.radials = {}; - root.center=new Object(); - root.center.x = 10000; - root.center.y = 10000; + coord.center=new Object(); + coord.center.x = 10000; + coord.center.y = 10000; + if (this.pgstack.length > 0) + this.pgstack[this.pgstack.length-1].hide(); + this.pgstack.push(coord); + if(_root.attr("width")) { k = _root.attr("width").value(); @@ -64,13 +71,21 @@ for(k in nodes) { var n = nodes[k].name(); if (n == "defs") { - this.parseDefs(root,nodes[k]); + this.parseDefs(coord,nodes[k]); } else if (n == "g") { - this.parseGroup(accu,root,'root_coord',nodes[k]); + this.parseGroup(accu,coord,'root_coord',nodes[k]); } } } +loadSVG.prototype.leaveSVG=function() +{ + var p = this.pgstack.pop(); + p.hide(); + if (this.pgstack.length > 0) + this.pgstack[this.pgstack.length-1].show(); +} + function make_mbnames(mb_rt, n, obj) { var mbname; var name;