comparison nodejs/svg.js @ 914:e4474cac20da

Implement the page stack
author wycc
date Thu, 21 Oct 2010 23:56:55 +0800
parents e86b4d56ddea
children 35b6a9411e26
comparison
equal deleted inserted replaced
913:85b647f5aeff 914:e4474cac20da
30 } 30 }
31 31
32 return [r, g, b]; 32 return [r, g, b];
33 } 33 }
34 34
35 exports.loadSVG=function(mb_rt,root,filename) { 35 exports.loadSVG=loadSVG;
36 return new loadSVG(mb_rt, root, filename);
37 };
38
39 36
40 function loadSVG(mb_rt, root, filename) { 37 function loadSVG(mb_rt, root, filename) {
38 this.pgstack=[];
39 if (filename)
40 this.load(mb_rt,root,filename);
41 }
42
43 loadSVG.prototype.load=function(mb_rt, root, filename) {
41 var doc = libxml.parseXmlFile(filename); 44 var doc = libxml.parseXmlFile(filename);
42 var _root = doc.root(); 45 var _root = doc.root();
43 var nodes = _root.childNodes(); 46 var nodes = _root.childNodes();
44 var coord = mb_rt.coord_new(root); 47 var coord = mb_rt.coord_new(root);
45 var k; 48 var k;
46 var accu=[1,0,0,0,1,0]; 49 var accu=[1,0,0,0,1,0];
47 this.mb_rt = mb_rt; 50 this.mb_rt = mb_rt;
48 this.stop_ref={}; 51 this.stop_ref={};
49 this.gradients={}; 52 this.gradients={};
50 this.radials = {}; 53 this.radials = {};
51 root.center=new Object(); 54 coord.center=new Object();
52 root.center.x = 10000; 55 coord.center.x = 10000;
53 root.center.y = 10000; 56 coord.center.y = 10000;
57 if (this.pgstack.length > 0)
58 this.pgstack[this.pgstack.length-1].hide();
59 this.pgstack.push(coord);
60
54 61
55 if(_root.attr("width")) { 62 if(_root.attr("width")) {
56 k = _root.attr("width").value(); 63 k = _root.attr("width").value();
57 this.width = parseFloat(k); 64 this.width = parseFloat(k);
58 } 65 }
62 } 69 }
63 70
64 for(k in nodes) { 71 for(k in nodes) {
65 var n = nodes[k].name(); 72 var n = nodes[k].name();
66 if (n == "defs") { 73 if (n == "defs") {
67 this.parseDefs(root,nodes[k]); 74 this.parseDefs(coord,nodes[k]);
68 } else if (n == "g") { 75 } else if (n == "g") {
69 this.parseGroup(accu,root,'root_coord',nodes[k]); 76 this.parseGroup(accu,coord,'root_coord',nodes[k]);
70 } 77 }
71 } 78 }
79 }
80
81 loadSVG.prototype.leaveSVG=function()
82 {
83 var p = this.pgstack.pop();
84 p.hide();
85 if (this.pgstack.length > 0)
86 this.pgstack[this.pgstack.length-1].show();
72 } 87 }
73 88
74 function make_mbnames(mb_rt, n, obj) { 89 function make_mbnames(mb_rt, n, obj) {
75 var mbname; 90 var mbname;
76 var name; 91 var name;