Mercurial > MadButterfly
annotate nodejs/svg.js @ 857:ea1e88c40548 abs_n_rel_center
Make scale work on center of an object
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 20 Sep 2010 22:43:44 +0800 |
parents | eff2f580b536 |
children | e69f551e4a37 |
rev | line source |
---|---|
807
5723e5446b7c
Fix incorrect variable name
Thinker K.F. Li <thinker@codemud.net>
parents:
802
diff
changeset
|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
624 | 3 var libxml = require('libxmljs'); |
4 var sys=require('sys'); | |
5 var mbfly = require("mbfly"); | |
646 | 6 var ldr = mbfly.img_ldr_new("."); |
714 | 7 |
624 | 8 |
713 | 9 var _std_colors = { |
10 "white": [1, 1, 1], | |
11 "black": [0, 0, 0], | |
12 "red": [1, 0, 0] | |
13 }; | |
14 | |
714 | 15 exports.loadSVG=function(mb_rt,root,filename) { |
718
0cd59ce76e67
Refactor loadSVG as a class
Thinker K.F. Li <thinker@branda.to>
parents:
717
diff
changeset
|
16 return new loadSVG(mb_rt, root, filename); |
0cd59ce76e67
Refactor loadSVG as a class
Thinker K.F. Li <thinker@branda.to>
parents:
717
diff
changeset
|
17 }; |
0cd59ce76e67
Refactor loadSVG as a class
Thinker K.F. Li <thinker@branda.to>
parents:
717
diff
changeset
|
18 |
784
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
783
diff
changeset
|
19 |
718
0cd59ce76e67
Refactor loadSVG as a class
Thinker K.F. Li <thinker@branda.to>
parents:
717
diff
changeset
|
20 function loadSVG(mb_rt, root, filename) { |
624 | 21 var doc = libxml.parseXmlFile(filename); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
22 var _root = doc.root(); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
23 var nodes = _root.childNodes(); |
624 | 24 var coord = mb_rt.coord_new(root); |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
25 var k; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
26 var accu=[1,0,0,0,1,0]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
27 this.mb_rt = mb_rt; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
28 this.stop_ref={}; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
29 this.gradients={}; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
30 root.center=new Object(); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
31 root.center.x = 10000; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
32 root.center.y = 10000; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
33 |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
34 if(_root.attr("width")) { |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
35 k = _root.attr("width").value(); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
36 this.width = parseFloat(k); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
37 } |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
38 if(_root.attr("height")) { |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
39 k = _root.attr("height").value(); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
40 this.height = parseFloat(k); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
41 } |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
42 |
624 | 43 for(k in nodes) { |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
44 var n = nodes[k].name(); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
45 if (n == "defs") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
46 this.parseDefs(root,nodes[k]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
47 } else if (n == "g") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
48 this.parseGroup(accu,root,'root_coord',nodes[k]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
49 } |
624 | 50 } |
51 } | |
52 | |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
53 function make_mbnames(mb_rt, n, obj) { |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
54 var mbname; |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
55 var name; |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
56 |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
57 if(!mb_rt.mbnames) |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
58 mb_rt.mbnames = {}; |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
59 |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
60 mbname = n.attr("mbname"); |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
61 if(mbname) { |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
62 name = mbname.value(); |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
63 mb_rt.mbnames[name] = obj; |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
64 } |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
65 } |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
66 |
624 | 67 function getInteger(n,name) |
68 { | |
69 if (n == null) return 0; | |
70 var a = n.attr(name); | |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
71 if (a==null) return 0; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
72 return parseInt(a.value()); |
624 | 73 } |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
74 |
631 | 75 function parsePointSize(s) |
76 { | |
77 var fs=0; | |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
78 var i; |
624 | 79 |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
80 for(i=0;i<s.length;i++) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
81 if (s[i]<'0' || s[i] > '9') break; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
82 fs = fs*10 + (s[i]-'0'); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
83 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
84 return fs; |
631 | 85 |
86 } | |
87 | |
88 function parseColor(c) | |
89 { | |
90 if (c[0] == '#') { | |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
91 return parseInt(c.substring(1,3),16)<<16 | parseInt(c.substring(3,5),16)<<8 | parseInt(c.substring(5,7),16); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
92 } |
631 | 93 } |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
94 |
631 | 95 function parseTextStyle(style,n) |
624 | 96 { |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
97 var attr; |
625
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
98 if (n) { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
99 attr = n.attr('style'); |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
100 } else { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
101 attr = null; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
102 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
103 if (attr == null) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
104 return; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
105 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
106 var f = attr.value().split(';'); |
625
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
107 |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
108 for(i in f) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
109 var kv = f[i].split(':'); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
110 if (kv[0] == 'font-size') { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
111 style.fs = parsePointSize(kv[1]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
112 } else if (kv[0] == "font-style") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
113 } else if (kv[0] == "font-weight") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
114 } else if (kv[0] == "fill") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
115 style.color = parseColor(kv[1]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
116 } else if (kv[0] == "fill-opacity") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
117 } else if (kv[0] == "stroke-opacity") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
118 } else if (kv[0] == "stroke") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
119 } else if (kv[0] == "stroke-width") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
120 } else if (kv[0] == "stroke-linecap") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
121 } else if (kv[0] == "stroke-linejoin") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
122 } else if (kv[0] == "stroke-lineopacity") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
123 } else if (kv[0] == "font-family") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
124 style.family = kv[1]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
125 } else if (kv[0] == "font-stretch") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
126 } else if (kv[0] == "font-variant") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
127 } else if (kv[0] == "text-anchor") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
128 } else if (kv[0] == "text-align") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
129 } else if (kv[0] == "writing-mode") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
130 } else if (kv[0] == "line-height") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
131 } else { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
132 sys.puts("Unknown style: "+kv[0]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
133 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
134 } |
624 | 135 } |
732
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
720
diff
changeset
|
136 function tspan_set_text(text) |
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
720
diff
changeset
|
137 { |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
138 this.text.set_text(text); |
732
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
720
diff
changeset
|
139 } |
624 | 140 |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
141 loadSVG.prototype.parseTSpan = function(coord, n,style) { |
624 | 142 var x = getInteger(n,'x'); |
143 var y = getInteger(n,'y'); | |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
144 var tcoord = this.mb_rt.coord_new(coord); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
145 var nodes = n.childNodes(); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
146 var k; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
147 |
714 | 148 var obj = this.mb_rt.stext_new(n.text(),x,y); |
631 | 149 parseTextStyle(style,n); |
714 | 150 style.paint = this.mb_rt.paint_color_new(1,1,1,1); |
151 style.face=this.mb_rt.font_face_query(style.family, 2, 100); | |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
152 obj.set_style([[20,style.face,style.fs]]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
153 style.paint.fill(obj); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
154 tcoord.add_shape(obj); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
155 for(k in nodes) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
156 var name = nodes[k].name(); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
157 if (name == "tspan") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
158 this.parseTSpan(tcoord,nodes[k]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
159 } else { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
160 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
161 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
162 tcoord.set_text=tspan_set_text; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
163 tcoord.text = obj; |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
164 make_mbnames(this.mb_rt, n, tcoord); |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
165 }; |
624 | 166 |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
167 loadSVG.prototype._prepare_paint_color = function(color, alpha) { |
706 | 168 var paint; |
713 | 169 var c; |
706 | 170 |
171 if (color[0]=='#') { | |
172 var r,g,b; | |
717
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
173 r = parseInt(color.substring(1,3),16)/255; |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
174 g = parseInt(color.substring(3,5),16)/255; |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
175 b = parseInt(color.substring(5,7),16)/255; |
714 | 176 paint = this.mb_rt.paint_color_new(r, g, b, alpha); |
713 | 177 } else if(_std_colors[color]) { |
178 c = _std_colors[color]; | |
714 | 179 paint = this.mb_rt.paint_color_new(c[0], c[1], c[2], alpha); |
807
5723e5446b7c
Fix incorrect variable name
Thinker K.F. Li <thinker@codemud.net>
parents:
802
diff
changeset
|
180 } else if (color.substring(0,3) == 'url') { |
5723e5446b7c
Fix incorrect variable name
Thinker K.F. Li <thinker@codemud.net>
parents:
802
diff
changeset
|
181 var id = color.substring(5, color.length-1); |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
182 var gr = this.gradients[id]; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
183 paint = this.mb_rt.paint_linear_new(gr[0],gr[1],gr[2],gr[3]); |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
184 paint.set_stops(this.stop_ref[id]); |
706 | 185 } else { |
714 | 186 paint = this.mb_rt.paint_color_new(0,0,0,1); |
706 | 187 } |
188 return paint; | |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
189 }; |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
190 |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
191 function guessPathBoundingBox(coord,d) |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
192 { |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
193 return; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
194 var items = d.split(' '); |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
195 var len = items.length; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
196 var pair; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
197 var i; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
198 var minx,miny; |
759 | 199 |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
200 minx = 10000; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
201 miny = 10000; |
759 | 202 |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
203 for(i=0;i<len;i++) { |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
204 var type = items[i].toLowerCase(); |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
205 x = minx;y = miny; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
206 switch(type) { |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
207 case 'm': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
208 case 'l': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
209 case 'a': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
210 case 'x': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
211 pair = items[i+1].split(','); |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
212 if (pair.length==2) { |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
213 x = parseFloat(pair[0]); |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
214 y = parseFloat(pair[1]); |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
215 i++; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
216 } else { |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
217 x = parseFloat(items[i+1]); |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
218 y = parseFloat(items[i+2]); |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
219 i+=2; |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
220 } |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
221 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
222 case 'q': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
223 // Implement this latter |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
224 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
225 case 'c': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
226 // Implement this latter |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
227 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
228 case 's': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
229 // Implement this latter |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
230 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
231 case 'h': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
232 x = parseFloat(items[i+1]); |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
233 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
234 case 'v': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
235 y = parseFloat(items[i+1]); |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
236 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
237 default: |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
238 continue; |
759 | 239 } |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
240 if (x < minx) minx = x; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
241 if (y < miny) miny = y; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
242 } |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
243 if (coord.center.x > minx) |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
244 coord.center.x = minx; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
245 if (coord.center.y > miny) |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
246 coord.center.y = miny; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
247 }; |
759 | 248 |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
249 function _mul(m1, m2) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
250 var res = new Array(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
251 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
252 res.push(m1[0] * m2[0] + m1[1] * m2[3]); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
253 res.push(m1[0] * m2[1] + m1[1] * m2[4]); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
254 res.push(m1[0] * m2[2] + m1[1] * m2[5] + m1[2]); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
255 res.push(m1[3] * m2[0] + m1[4] * m2[3]); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
256 res.push(m1[3] * m2[1] + m1[4] * m2[4]); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
257 res.push(m1[3] * m2[2] + m1[4] * m2[5] + m1[5]); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
258 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
259 return res; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
260 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
261 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
262 function _pnt_transform(x, y, matrix) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
263 var rx, ry; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
264 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
265 rx = x * matrix[0] + y * matrix[1] + matrix[2]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
266 ry = x * matrix[3] + y * matrix[4] + matrix[5]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
267 return new Array(rx, ry); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
268 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
269 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
270 function _shift_transform(x, y, matrix) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
271 var rx, ry; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
272 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
273 rx = x * matrix[0] + y * matrix[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
274 ry = x * matrix[3] + y * matrix[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
275 return new Array(rx, ry); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
276 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
277 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
278 function _transform_bbox(bbox, matrix) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
279 var min_x, min_y, max_x, max_y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
280 var x, y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
281 var pnt; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
282 var pnts = new Array(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
283 var i; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
284 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
285 pnt = _pnt_transform(bbox.x, bbox.y, matrix); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
286 pnts.push(pnt); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
287 pnt = _pnt_transform(bbox.x + bbox.width, bbox.y, matrix); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
288 pnts.push(pnt); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
289 pnt = _pnt_transform(bbox.x, bbox.y + bbox.height, matrix); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
290 pnts.push(pnt); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
291 pnt = _pnt_transform(bbox.x + bbox.width, bbox.y + bbox.height, matrix); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
292 pnts.push(pnt); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
293 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
294 min_x = max_x = pnts[0][0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
295 min_y = max_y = pnts[0][1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
296 for(i = 1; i < pnts.length; i++) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
297 pnt = pnts[i]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
298 if(pnt[0] < min_x) |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
299 min_x = pnt[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
300 if(pnt[1] < min_y) |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
301 min_y = pnt[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
302 if(pnt[0] > max_x) |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
303 max_x = pnt[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
304 if(pnt[1] > max_y) |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
305 max_y = pnt[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
306 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
307 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
308 bbox.x = min_x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
309 bbox.y = min_y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
310 bbox.width = max_x - min_x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
311 bbox.height = max_y - min_y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
312 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
313 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
314 function _reverse(m1) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
315 var rev = new Array(1, 0, 0, 0, 1, 0); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
316 var m = new Array(m1[0], m1[1], m1[2], m1[3], m1[4], m1[5]); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
317 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
318 rev[3] = -m[3] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
319 m[3] = 0; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
320 m[4] += rev[3] * m[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
321 m[5] += rev[3] * m[2]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
322 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
323 rev[1] = -m[1] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
324 rev[0] += rev[1] * rev[3]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
325 m[1] = 0; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
326 m[2] += rev[1] * m[5]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
327 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
328 rev[2] = -m[2]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
329 rev[5] = -m[5]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
330 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
331 rev[0] = rev[0] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
332 rev[1] = rev[1] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
333 rev[2] = rev[2] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
334 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
335 rev[3] = rev[3] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
336 rev[4] = rev[4] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
337 rev[5] = rev[5] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
338 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
339 return rev; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
340 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
341 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
342 var _bbox_proto = { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
343 _get_ac_saved_rev: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
344 var c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
345 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
346 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
347 if(c.type != "coord") |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
348 c = c.parent; // is a shape! |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
349 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
350 mtx = c._mbapp_saved_rev_mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
351 while(c.parent && typeof c.parent != "undefined") { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
352 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
353 mtx = _mul(mtx, c._mbapp_saved_rev_mtx); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
354 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
355 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
356 return mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
357 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
358 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
359 _get_ac_mtx: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
360 var c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
361 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
362 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
363 if(c.type != "coord") |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
364 c = c.parent; // is a shape! |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
365 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
366 mtx = [c[0], c[1], c[2], c[3], c[4], c[5]]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
367 while(c.parent) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
368 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
369 mtx = _mul(c, mtx); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
370 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
371 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
372 return mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
373 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
374 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
375 _saved_to_current: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
376 var r; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
377 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
378 r = _mul(this._get_ac_mtx(), this._get_ac_saved_rev()); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
379 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
380 return r; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
381 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
382 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
383 /*! \brief Update x, y, width, and height of the bbox. |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
384 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
385 update: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
386 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
387 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
388 this.x = this._svg_saved_x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
389 this.y = this._svg_saved_y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
390 this.width = this._svg_saved_width; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
391 this.height = this._svg_saved_height; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
392 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
393 mtx = this._saved_to_current(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
394 _transform_bbox(this, mtx); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
395 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
396 }; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
397 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
398 var _center_proto = { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
399 _get_ac_saved_rev: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
400 var c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
401 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
402 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
403 if(c.type != "coord") |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
404 c = c.parent; // is a shape! |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
405 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
406 mtx = c._mbapp_saved_rev_mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
407 while(c.parent && typeof c.parent != "undefined") { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
408 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
409 mtx = _mul(mtx, c._mbapp_saved_rev_mtx); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
410 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
411 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
412 return mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
413 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
414 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
415 _get_ac_mtx: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
416 var c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
417 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
418 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
419 if(c.type != "coord") |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
420 c = c.parent; // is a shape! |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
421 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
422 mtx = [c[0], c[1], c[2], c[3], c[4], c[5]]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
423 while(c.parent) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
424 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
425 mtx = _mul(c, mtx); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
426 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
427 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
428 return mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
429 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
430 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
431 _get_ac_rev: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
432 var c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
433 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
434 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
435 if(c.type != "coord") |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
436 c = c.parent; // is a shape! |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
437 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
438 mtx = _reverse([c[0], c[1], c[2], c[3], c[4], c[5]]); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
439 while(c.parent) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
440 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
441 mtx = _mul(mtx, _reverse([c[0], c[1], c[2], c[3], c[4], c[5]])); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
442 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
443 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
444 return mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
445 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
446 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
447 _saved_to_current: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
448 var r; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
449 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
450 r = _mul(this._get_ac_mtx(), this._get_ac_saved_rev()); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
451 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
452 return r; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
453 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
454 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
455 /*! \brief Update x, y of center point of an object. |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
456 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
457 update: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
458 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
459 var xy; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
460 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
461 mtx = this._saved_to_current(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
462 xy = _pnt_transform(this._svg_saved_x, this._svg_saved_y, mtx); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
463 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
464 this._x = xy[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
465 this._y = xy[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
466 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
467 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
468 /*! \brief Move owner object to make center at (x, y). |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
469 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
470 move: function(x, y) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
471 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
472 var xdiff = x - this._x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
473 var ydiff = y - this._y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
474 var shiftxy; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
475 var c; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
476 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
477 mtx = this._get_ac_rev(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
478 shiftxy = _shift_transform(xdiff, ydiff, mtx); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
479 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
480 c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
481 if(c.type != "coord") |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
482 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
483 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
484 c[2] += shiftxy[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
485 c[5] += shiftxy[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
486 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
487 this._x = x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
488 this._y = y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
489 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
490 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
491 /*! \brief Move owner object to make center at position specified by pnt. |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
492 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
493 move_pnt: function(pnt) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
494 this.move(pnt.x, pnt.y); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
495 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
496 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
497 /*! \brief Prevent user to modify value. |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
498 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
499 get x() { return this._x; }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
500 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
501 /*! \brief Prevent user to modify value. |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
502 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
503 get y() { return this._y; }, |
857
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
504 |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
505 get rel() { |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
506 var rev; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
507 var xy; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
508 |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
509 rev = this._get_ac_rev(); |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
510 xy = _pnt_transform(this._svg_saved_x, this._svg_saved_y, rev); |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
511 |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
512 return {x: xy[0], y: xy[1]}; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
513 }, |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
514 }; |
759 | 515 |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
516 loadSVG.prototype._set_bbox = function(node, tgt) { |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
517 var a; |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
518 var vstr; |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
807
diff
changeset
|
519 var bbox, center; |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
520 |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
521 a = node.attr("bbox-x"); |
847 | 522 sys.puts("a="+a); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
523 if(!a) |
842
76fe4afce640
The inkscape:bbox is defined as the global coordinate system. However, the center.x and center.y must be the coordiante system of the parent group of the SVG entity. Therefore, we need to do coordinate transformation from the global coordination system to the local coordination system.
wycc
parents:
830
diff
changeset
|
524 return 0; |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
525 |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
807
diff
changeset
|
526 tgt.bbox = bbox = new Object(); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
527 bbox.owner = tgt; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
528 bbox.__proto__ = _bbox_proto; |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
529 vstr = a.value(); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
530 bbox._svg_saved_x = parseFloat(vstr); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
531 |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
532 a = node.attr("bbox-y"); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
533 vstr = a.value(); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
534 bbox._svg_saved_y = this.height - parseFloat(vstr); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
535 |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
536 a = node.attr("bbox-width"); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
537 vstr = a.value(); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
538 bbox._svg_saved_width = parseFloat(vstr); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
539 |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
540 a = node.attr("bbox-height"); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
541 vstr = a.value(); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
542 bbox._svg_saved_height = parseFloat(vstr); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
543 bbox._svg_saved_y -= bbox._svg_saved_height; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
544 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
545 bbox.update(); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
546 |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
807
diff
changeset
|
547 tgt.center = center = new Object(); |
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
807
diff
changeset
|
548 |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
549 center._svg_saved_x = bbox._svg_saved_width / 2 + bbox._svg_saved_x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
550 center._svg_saved_y = bbox._svg_saved_height / 2 + bbox._svg_saved_y; |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
551 a = node.attr("transform-center-x"); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
552 if(a) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
553 vstr = a.value(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
554 center._svg_saved_x += parseFloat(vstr); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
555 a = node.attr("transform-center-y"); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
556 vstr = a.value(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
557 center._svg_saved_y -= parseFloat(vstr); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
558 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
559 center.__proto__ = _center_proto; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
560 center.owner = tgt; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
561 center.update(); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
562 |
842
76fe4afce640
The inkscape:bbox is defined as the global coordinate system. However, the center.x and center.y must be the coordiante system of the parent group of the SVG entity. Therefore, we need to do coordinate transformation from the global coordination system to the local coordination system.
wycc
parents:
830
diff
changeset
|
563 return 1; |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
564 } |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
565 |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
566 loadSVG.prototype._set_paint = function(node, tgt) { |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
567 var style = node.attr('style'); |
706 | 568 var paint; |
717
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
569 var fill_alpha = 1; |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
570 var stroke_alpha = 1; |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
571 var fill_color; |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
572 var stroke_color; |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
573 var black_paint; |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
574 var i; |
706 | 575 |
717
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
576 if(style != null) { |
706 | 577 var items = style.value().split(';'); |
578 var alpha; | |
579 | |
580 for(i in items) { | |
581 var f = items[i].split(':'); | |
582 if (f[0] == 'opacity') { | |
583 alpha = f[1]; | |
584 } else if (f[0] == 'fill') { | |
717
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
585 fill_color = f[1]; |
706 | 586 } else if (f[0] == 'fill-opacity') { |
587 fill_alpha = parseFloat(f[1]); | |
588 } else if (f[0] == 'stroke') { | |
717
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
589 stroke_color = f[1]; |
706 | 590 } else if (f[0] == 'stroke-width') { |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
591 tgt.stroke_width = parseFloat(f[1]); |
706 | 592 } else if (f[0] == 'stroke-opacity') { |
593 stroke_alpha = parseFloat(f[1]); | |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
594 } else if (f[0] == 'display') { |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
595 if(f[1] == 'none') |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
596 return; |
706 | 597 } |
598 } | |
599 | |
717
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
600 } |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
601 |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
602 if(!fill_color || !stroke_color) |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
603 black_paint = this.mb_rt.paint_color_new(0, 0, 0, 1); |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
604 |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
605 if(fill_color) { |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
606 if(fill_color != "none") { |
714 | 607 paint = this._prepare_paint_color(fill_color, fill_alpha); |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
608 paint.fill(tgt); |
706 | 609 } |
717
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
610 } else { |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
611 black_paint.fill(tgt); |
717
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
612 } |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
613 if(stroke_color) { |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
614 if(stroke_color != "none") { |
714 | 615 paint = this._prepare_paint_color(stroke_color, stroke_alpha); |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
616 paint.stroke(tgt); |
706 | 617 } |
717
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
618 } else { |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
619 black_paint.stroke(tgt); |
706 | 620 } |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
621 }; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
622 |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
623 loadSVG.prototype.parsePath=function(accu, coord,id, n) |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
624 { |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
625 var d = n.attr('d').value(); |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
626 var style = n.attr('style'); |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
627 var path = this.mb_rt.path_new(d); |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
628 |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
629 guessPathBoundingBox(coord,d); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
630 coord.add_shape(path); |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
631 this._set_paint(n, path); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
632 this._set_bbox(n, path); |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
633 |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
634 make_mbnames(this.mb_rt, n, path); |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
635 }; |
706 | 636 |
776
77b561bb7929
Implement new algorithm to calculate the origin of the SVG elemnts so that we can implement object resize without changing the position of the object.
wycc
parents:
759
diff
changeset
|
637 loadSVG.prototype.parseText=function(accu,coord,id, n) |
624 | 638 { |
639 var x = getInteger(n,'x'); | |
640 var y = getInteger(n,'y'); | |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
641 var tcoord = this.mb_rt.coord_new(coord); |
631 | 642 var style = new Object(); |
759 | 643 |
776
77b561bb7929
Implement new algorithm to calculate the origin of the SVG elemnts so that we can implement object resize without changing the position of the object.
wycc
parents:
759
diff
changeset
|
644 if (n.attr('x')) { |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
645 var nx = coord[0]*x+coord[1]*y+coord[2]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
646 if (coord.center.x > nx) |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
647 coord.center.x = nx; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
648 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
649 if (n.attr('y')) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
650 var ny = coord[3]*x+coord[4]*y+coord[5]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
651 if (coord.center.y > ny) |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
652 coord.center.y = ny; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
653 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
654 style.fs = 20; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
655 style.family = 'courier'; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
656 parseTextStyle(style,n); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
657 var nodes = n.childNodes(); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
658 var k; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
659 for(k in nodes) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
660 var c= nodes[k].name(); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
661 if (c == "tspan") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
662 this.parseTSpan(tcoord,nodes[k],style); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
663 } else { |
776
77b561bb7929
Implement new algorithm to calculate the origin of the SVG elemnts so that we can implement object resize without changing the position of the object.
wycc
parents:
759
diff
changeset
|
664 } |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
665 } |
847 | 666 sys.puts(y); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
667 this._set_bbox(n, tcoord); |
624 | 668 |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
669 make_mbnames(this.mb_rt, n, tcoord); |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
670 }; |
624 | 671 |
759 | 672 |
673 function multiply(s,d) { | |
674 var m=[]; | |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
675 m[0] = s[0]*d[0]+s[1]*d[3]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
676 m[1] = s[0]*d[1]+s[1]*d[4]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
677 m[2] = s[0]*d[2]+s[1]*d[5]+s[2]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
678 m[3] = s[3]*d[0]+s[4]*d[3]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
679 m[4] = s[3]*d[1]+s[4]*d[4]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
680 m[5] = s[3]*d[2]+s[4]*d[5]+s[5]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
681 s[0] = m[0]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
682 s[1] = m[1]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
683 s[2] = m[2]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
684 s[3] = m[3]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
685 s[4] = m[4]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
686 s[5] = m[5]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
687 }; |
759 | 688 |
624 | 689 function parseTransform(coord, s) |
690 { | |
691 var off = s.indexOf('translate'); | |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
692 if (off != -1) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
693 var ss = s.substring(off+9); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
694 for(i=0;i<ss.length;i++) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
695 if (ss[i] == '(') break; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
696 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
697 ss = ss.substring(i+1); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
698 for(i=0;i<ss.length;i++) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
699 if (ss[i] == ')') { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
700 ss = ss.substring(0,i); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
701 break; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
702 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
703 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
704 var f = ss.split(','); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
705 var x,y; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
706 x = parseFloat(f[0]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
707 y = parseFloat(f[1]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
708 coord[2] += x; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
709 coord[5] += y; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
710 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
711 off = s.indexOf('matrix'); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
712 if (off != -1) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
713 var end = s.indexOf(')'); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
714 var m = s.substring(7,end); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
715 var fields = m.split(','); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
716 var newm=[]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
717 newm[0] = parseFloat(fields[0]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
718 newm[1] = parseFloat(fields[2]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
719 newm[2] = parseFloat(fields[4]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
720 newm[3] = parseFloat(fields[1]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
721 newm[4] = parseFloat(fields[3]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
722 newm[5] = parseFloat(fields[5]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
723 multiply(coord,newm); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
724 } |
624 | 725 } |
726 | |
759 | 727 loadSVG.prototype.parseRect=function(accu_matrix,coord, id, n) |
624 | 728 { |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
729 var x = getInteger(n,'x'); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
730 var y = getInteger(n,'y'); |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
731 var rx,ry; |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
732 var w = getInteger(n,'width'); |
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
733 var h = getInteger(n,'height'); |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
734 var trans = n.attr('transform'); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
735 var paint; |
776
77b561bb7929
Implement new algorithm to calculate the origin of the SVG elemnts so that we can implement object resize without changing the position of the object.
wycc
parents:
759
diff
changeset
|
736 var tcoord = this.mb_rt.coord_new(coord); |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
737 |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
738 var style = n.attr('style'); |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
739 |
842
76fe4afce640
The inkscape:bbox is defined as the global coordinate system. However, the center.x and center.y must be the coordiante system of the parent group of the SVG entity. Therefore, we need to do coordinate transformation from the global coordination system to the local coordination system.
wycc
parents:
830
diff
changeset
|
740 if (trans) |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
741 parseTransform(tcoord,trans.value()); |
759 | 742 |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
743 var rect = this.mb_rt.rect_new(x,y,w,h,10, 10); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
744 tcoord.add_shape(rect); |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
745 this._set_paint(n, rect); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
746 this._set_bbox(n, tcoord); |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
787
diff
changeset
|
747 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
787
diff
changeset
|
748 make_mbnames(this.mb_rt, n, tcoord); |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
749 }; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
750 |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
751 // When we parse a group, we need to calculate the origin of the group |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
752 // so that we can resize the group without changing its origin point. |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
753 // This must be done recursively. For text/rect/image, we can get its |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
754 // origin point directly by using the (x,y) and apply their |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
755 // transformation matrix. For group, we need to send the acculumated |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
756 // matrix so that each group can get their origin correctly. |
776
77b561bb7929
Implement new algorithm to calculate the origin of the SVG elemnts so that we can implement object resize without changing the position of the object.
wycc
parents:
759
diff
changeset
|
757 // |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
758 // Each element must be responsible to calculate its absolute origin |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
759 // point and update the origin of its parent. |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
760 |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
761 function parseGroupStyle(style,n) |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
762 { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
763 var attr; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
764 if (n) { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
765 attr = n.attr('style'); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
766 } else { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
767 attr = null; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
768 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
769 if (attr == null) { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
770 return; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
771 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
772 var f = attr.value().split(';'); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
773 |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
774 for(i in f) { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
775 var kv = f[i].split(':'); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
776 if (kv[0] == 'opacity') { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
777 style.opacity = parseFloat(kv[1]); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
778 } else { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
779 sys.puts("Unknown style: "+kv[0]); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
780 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
781 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
782 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
783 |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
784 loadSVG.prototype.parseGroup=function(accu_matrix,root, group_id, n) { |
624 | 785 var k; |
786 var nodes = n.childNodes(); | |
714 | 787 var coord = this.mb_rt.coord_new(root); |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
788 // Parse the transform and style here |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
789 var trans = n.attr('transform'); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
790 var accu=[1,0,0,0,1,0]; |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
791 var style; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
792 |
759 | 793 coord.center= new Object(); |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
794 coord.center.x = 10000; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
795 coord.center.y = 10000; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
796 if (trans!=null) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
797 parseTransform(coord, trans.value()); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
798 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
799 multiply(accu,accu_matrix); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
800 multiply(accu,coord); |
624 | 801 |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
802 style = {}; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
803 parseGroupStyle(style, n); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
804 if(style.opacity) { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
805 sys.puts(style.opacity); |
830
2a73ff24c141
Use accessor to replace the method to setup the opacity
wycc
parents:
810
diff
changeset
|
806 coord.opacity=style.opacity; |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
807 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
808 |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
809 for(k in nodes) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
810 var c = nodes[k].name(); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
811 var attr = nodes[k].attr('id'); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
812 var id; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
813 if (attr) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
814 id = attr.value(); |
624 | 815 } |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
816 if (c == "g") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
817 this.parseGroup(accu,coord, id, nodes[k]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
818 } else if (c == "path") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
819 this.parsePath(accu,coord, id, nodes[k]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
820 } else if (c == "text") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
821 this.parseText(accu,coord, id, nodes[k]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
822 } else if (c == "rect") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
823 this.parseRect(accu_matrix,coord, id, nodes[k]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
824 } else if (c == "image") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
825 this.parseImage(accu_matrix,coord, id, nodes[k]); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
826 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
827 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
828 if (root.center.x > coord.center.x) |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
829 root.center.x = coord.center.x; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
830 if (root.center.y > coord.center.y) |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
831 root.center.y = coord.center.y; |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
832 |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
833 this._set_bbox(n, coord); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
834 |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
835 make_mbnames(this.mb_rt, n, coord); |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
836 }; |
624 | 837 |
776
77b561bb7929
Implement new algorithm to calculate the origin of the SVG elemnts so that we can implement object resize without changing the position of the object.
wycc
parents:
759
diff
changeset
|
838 loadSVG.prototype.parseImage=function(accu,coord,id, n) |
646 | 839 { |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
840 var ref = n.attr('href').value(); |
776
77b561bb7929
Implement new algorithm to calculate the origin of the SVG elemnts so that we can implement object resize without changing the position of the object.
wycc
parents:
759
diff
changeset
|
841 var tcoord = this.mb_rt.coord_new(coord); |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
842 var trans = n.attr('transform'); |
646 | 843 |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
844 if (ref == null) return; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
845 if (ref.substr(0,7) == "file://") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
846 ref = ref.substring(7); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
847 } else if (ref.substr(0,5)=="file:") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
848 ref = ref.substring(5); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
849 } else { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
850 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
851 var w; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
852 var h; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
853 var x,y,nx,ny; |
776
77b561bb7929
Implement new algorithm to calculate the origin of the SVG elemnts so that we can implement object resize without changing the position of the object.
wycc
parents:
759
diff
changeset
|
854 coord.center= new Object(); |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
855 coord.center.x = 10000; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
856 coord.center.y = 10000; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
857 if (trans!=null) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
858 parseTransform(coord, trans.value()); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
859 } |
646 | 860 |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
861 w = n.attr("width"); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
862 if (w == null) return; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
863 w = parseFloat(w.value()); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
864 h = n.attr("height"); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
865 if (h == null) return; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
866 h = parseFloat(h.value()); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
867 x = n.attr("x"); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
868 if (x == null) return; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
869 x = parseFloat(x.value()); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
870 y = n.attr("y"); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
871 if (y == null) return; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
872 y = parseFloat(y.value()); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
873 nx = tcoord[0]*x+tcoord[1]*y+tcoord[2]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
874 ny = tcoord[3]*x+tcoord[4]*y+tcoord[5]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
875 if (coord.center.x > nx) |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
876 coord.center.x = nx; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
877 if (coord.center.y > ny) |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
878 coord.center.y = ny; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
879 var img = this.mb_rt.image_new(x,y,w,h); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
880 var img_data = ldr.load(ref); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
881 var paint = this.mb_rt.paint_image_new(img_data); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
882 paint.fill(img); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
883 tcoord.add_shape(img); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
884 |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
885 this._set_bbox(n, img); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
886 |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
887 make_mbnames(this.mb_rt, n, img); |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
888 }; |
624 | 889 |
750 | 890 loadSVG.prototype._MB_parseLinearGradient=function(root,n) |
891 { | |
892 var id = n.attr('id'); | |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
893 var k; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
894 var nodes = n.childNodes(); |
750 | 895 |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
896 if (id == null) return; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
897 var x1 = n.attr("x1"); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
898 var y1 = n.attr("y1"); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
899 var x2 = n.attr("x2"); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
900 var y2 = n.attr("y2"); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
901 var gr; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
902 var color, opacity; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
903 var stops; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
904 var r,g,b; |
750 | 905 stops=[]; |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
906 for(k in nodes) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
907 var ss = nodes[k]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
908 if (ss.name()=="stop") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
909 var style = ss.attr("style").value(); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
910 var items = style.split(';'); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
911 var off = parseInt(ss.attr('offset').value()); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
912 color = 'black'; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
913 opacity = 1; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
914 for (i in items) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
915 it = items[i]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
916 var f = it.split(':'); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
917 k = f[0]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
918 v = f[1]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
919 if (k == 'stop-color') { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
920 color = v.substring(1); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
921 if (v == 'white') { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
922 r = 1; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
923 g = 1; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
924 b = 1; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
925 } else if (v == 'black') { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
926 r = 0; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
927 g = 0; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
928 b = 0; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
929 } else { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
930 r = parseInt(color.substring(0,2),16)/255.0; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
931 g = parseInt(color.substring(2,4),16)/255.0; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
932 b = parseInt(color.substring(4,6),16)/255.0; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
933 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
934 } else if (k=='stop-opacity') { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
935 opacity = parseFloat(v); |
750 | 936 } |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
937 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
938 stops.push([off, r,g,b,opacity]); |
750 | 939 } |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
940 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
941 var href = n.attr('href'); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
942 if (href != null) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
943 href = href.value(); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
944 pstops = this.stop_ref[href.substring(1)]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
945 stops = pstops.concat(stops); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
946 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
947 id = id.value(); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
948 this.stop_ref[id] = stops; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
949 if (x1) |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
950 x1 = parseFloat(x1.value()); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
951 if (x2) |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
952 x2 = parseFloat(x2.value()); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
953 if (y1) |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
954 y1 = parseFloat(y1.value()); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
955 if (y2) |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
956 y2 = parseFloat(y2.value()); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
957 this.gradients[id] = [x1,y1,x2,y2]; |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
958 }; |
750 | 959 |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
960 loadSVG.prototype.parseDefs=function(root,n) |
624 | 961 { |
962 var k; | |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
963 var nodes = n.childNodes(); |
624 | 964 |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
965 for(k in nodes) { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
966 var name = nodes[k].name(); |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
967 if (name == "linearGradient") { |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
968 this._MB_parseLinearGradient(root,nodes[k]); |
624 | 969 } |
783
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
970 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
971 }; |
624 | 972 |
973 |