Mercurial > MadButterfly
annotate nodejs/svg.js @ 930:30cd14b11bc7
USe the graphics from the Max.
author | wycc |
---|---|
date | Sat, 06 Nov 2010 00:53:59 +0800 |
parents | 35b6a9411e26 |
children | a9abcdac0ae5 |
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 | |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
15 function parse_color(color) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
16 var r, g, b; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
17 var c; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
18 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
19 if (color[0] == "#") { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
20 r = parseInt(color.substring(1, 3), 16) / 255; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
21 g = parseInt(color.substring(3, 5), 16) / 255; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
22 b = parseInt(color.substring(5, 7), 16) / 255; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
23 } else if(_std_colors[color]) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
24 c = _std_colors[color]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
25 r = c[0]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
26 g = c[1]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
27 b = c[2]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
28 } else { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
29 r = g = b = 0; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
30 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
31 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
32 return [r, g, b]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
33 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
34 |
914 | 35 exports.loadSVG=loadSVG; |
784
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
783
diff
changeset
|
36 |
718
0cd59ce76e67
Refactor loadSVG as a class
Thinker K.F. Li <thinker@branda.to>
parents:
717
diff
changeset
|
37 function loadSVG(mb_rt, root, filename) { |
914 | 38 this.pgstack=[]; |
39 if (filename) | |
40 this.load(mb_rt,root,filename); | |
41 } | |
42 | |
43 loadSVG.prototype.load=function(mb_rt, root, filename) { | |
624 | 44 var doc = libxml.parseXmlFile(filename); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
45 var _root = doc.root(); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
46 var nodes = _root.childNodes(); |
624 | 47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 this.gradients={}; |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
53 this.radials = {}; |
914 | 54 coord.center=new Object(); |
55 coord.center.x = 10000; | |
56 coord.center.y = 10000; | |
57 if (this.pgstack.length > 0) | |
58 this.pgstack[this.pgstack.length-1].hide(); | |
59 this.pgstack.push(coord); | |
60 | |
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
|
61 |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
62 if(_root.attr("width")) { |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
63 k = _root.attr("width").value(); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
64 this.width = parseFloat(k); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
65 } |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
66 if(_root.attr("height")) { |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
67 k = _root.attr("height").value(); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
68 this.height = parseFloat(k); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
69 } |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
70 |
624 | 71 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
|
72 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
|
73 if (n == "defs") { |
914 | 74 this.parseDefs(coord,nodes[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
|
75 } else if (n == "g") { |
914 | 76 this.parseGroup(accu,coord,'root_coord',nodes[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
|
77 } |
624 | 78 } |
79 } | |
80 | |
914 | 81 loadSVG.prototype.leaveSVG=function() |
82 { | |
83 var p = this.pgstack.pop(); | |
84 p.hide(); | |
85 if (this.pgstack.length > 0) | |
86 this.pgstack[this.pgstack.length-1].show(); | |
87 } | |
88 | |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
89 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
|
90 var mbname; |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
91 var name; |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
92 |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
93 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
|
94 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
|
95 |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
96 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
|
97 if(mbname) { |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
98 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
|
99 mb_rt.mbnames[name] = obj; |
928
35b6a9411e26
Use inkscape:label to be the same way as the mbname. In this way, we can use the property editor to define name of the object.
wycc
parents:
914
diff
changeset
|
100 return; |
35b6a9411e26
Use inkscape:label to be the same way as the mbname. In this way, we can use the property editor to define name of the object.
wycc
parents:
914
diff
changeset
|
101 } |
35b6a9411e26
Use inkscape:label to be the same way as the mbname. In this way, we can use the property editor to define name of the object.
wycc
parents:
914
diff
changeset
|
102 mbname = n.attr("label"); |
35b6a9411e26
Use inkscape:label to be the same way as the mbname. In this way, we can use the property editor to define name of the object.
wycc
parents:
914
diff
changeset
|
103 if(mbname&&(mbname.value()!="")) { |
35b6a9411e26
Use inkscape:label to be the same way as the mbname. In this way, we can use the property editor to define name of the object.
wycc
parents:
914
diff
changeset
|
104 name = mbname.value(); |
35b6a9411e26
Use inkscape:label to be the same way as the mbname. In this way, we can use the property editor to define name of the object.
wycc
parents:
914
diff
changeset
|
105 mb_rt.mbnames[name] = obj; |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
106 } |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
107 } |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
108 |
624 | 109 function getInteger(n,name) |
110 { | |
111 if (n == null) return 0; | |
112 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
|
113 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
|
114 return parseInt(a.value()); |
624 | 115 } |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
116 |
631 | 117 function parsePointSize(s) |
118 { | |
119 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
|
120 var i; |
624 | 121 |
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
|
122 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
|
123 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
|
124 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
|
125 } |
a47431293043
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 return fs; |
631 | 127 |
128 } | |
129 | |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
130 function parse_style(node) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
131 var style_attr; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
132 var style; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
133 var parts, part; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
134 var kv, key, value; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
135 var content = {}; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
136 var i; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
137 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
138 style_attr = node.attr('style'); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
139 if(!style_attr) |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
140 return content; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
141 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
142 style = style_attr.value(); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
143 parts = style.split(';'); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
144 for(i = 0; i < parts.length; i++) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
145 part = parts[i].trim(); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
146 if(part) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
147 kv = part.split(':'); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
148 key = kv[0].trim(); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
149 value = kv[1].trim(); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
150 content[key] = value; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
151 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
152 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
153 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
154 return content; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
155 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
156 |
631 | 157 function parseColor(c) |
158 { | |
159 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
|
160 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
|
161 } |
631 | 162 } |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
163 |
631 | 164 function parseTextStyle(style,n) |
624 | 165 { |
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
|
166 var attr; |
625
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
167 if (n) { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
168 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
|
169 } 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
|
170 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
|
171 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
172 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
|
173 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
|
174 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
175 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
|
176 |
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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 } 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
|
182 } 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
|
183 } 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
|
184 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
|
185 } 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
|
186 } 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
|
187 } 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
|
188 } 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
|
189 } 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
|
190 } 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
|
191 } 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
|
192 } 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
|
193 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
|
194 } 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
|
195 } 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
|
196 } 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
|
197 } 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
|
198 } 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
|
199 } 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
|
200 } 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
|
201 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
|
202 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
203 } |
624 | 204 } |
732
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
720
diff
changeset
|
205 function tspan_set_text(text) |
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
720
diff
changeset
|
206 { |
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
|
207 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
|
208 } |
624 | 209 |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
210 function _parse_font_size(fn_sz_str) { |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
211 var pos; |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
212 |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
213 pos = fn_sz_str.search("px"); |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
214 if(pos >= 0) |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
215 fn_sz_str = fn_sz_str.substring(0, pos); |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
216 pos = fn_sz_str.search("pt"); |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
217 if(pos >= 0) |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
218 fn_sz_str = fn_sz_str.substring(0, pos); |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
219 |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
220 return parseFloat(fn_sz_str); |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
221 } |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
222 |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
223 loadSVG.prototype.parseTSpan = function(coord, n, pstyle) { |
624 | 224 var x = getInteger(n,'x'); |
225 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
|
226 var tcoord = this.mb_rt.coord_new(coord); |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
227 var style; |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
228 var family = "Courier"; |
902
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
229 var weight = 80; |
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
230 var slant = 0; |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
231 var sz = 10; |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
232 var face; |
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
|
233 var k; |
714 | 234 var obj = this.mb_rt.stext_new(n.text(),x,y); |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
235 |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
236 style = parse_style(n); |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
237 for(k in pstyle) { |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
238 if(k in style) |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
239 continue; |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
240 style[k] = pstyle[k]; |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
241 } |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
242 |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
243 if("font-family" in style) |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
244 family = style["font-family"]; |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
245 if("font-size" in style) |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
246 sz = _parse_font_size(style["font-size"]); |
902
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
247 if("font-weight" in style) { |
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
248 if(style["font-weight"] == "bold") |
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
249 weight = 200; |
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
250 } |
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
251 if("font-style" in style) { |
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
252 if(style["font-style"] == "oblique") |
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
253 slant = 110; |
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
254 } |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
255 |
902
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
256 face = this.mb_rt.font_face_query(family, slant, weight); |
899
ec94dd788332
set style for a text with computed text length
Thinker K.F. Li <thinker@codemud.net>
parents:
891
diff
changeset
|
257 obj.set_style([[n.text().length, face, sz]]); |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
258 |
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
|
259 tcoord.add_shape(obj); |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
260 tcoord.set_text = tspan_set_text; |
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
|
261 tcoord.text = obj; |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
262 |
882
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
263 this._set_paint_style(style, obj); |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
264 this._set_bbox(n, obj); |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
265 |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
266 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
|
267 }; |
624 | 268 |
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
|
269 loadSVG.prototype._prepare_paint_color = function(color, alpha) { |
706 | 270 var paint; |
713 | 271 var c; |
706 | 272 |
273 if (color[0]=='#') { | |
274 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
|
275 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
|
276 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
|
277 b = parseInt(color.substring(5,7),16)/255; |
714 | 278 paint = this.mb_rt.paint_color_new(r, g, b, alpha); |
713 | 279 } else if(_std_colors[color]) { |
280 c = _std_colors[color]; | |
714 | 281 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
|
282 } else if (color.substring(0,3) == 'url') { |
5723e5446b7c
Fix incorrect variable name
Thinker K.F. Li <thinker@codemud.net>
parents:
802
diff
changeset
|
283 var id = color.substring(5, color.length-1); |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
284 if(id in this.gradients) { |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
285 var gr = this.gradients[id]; |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
286 paint = this.mb_rt.paint_linear_new(gr[0],gr[1],gr[2],gr[3]); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
287 } else { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
288 var radial = this.radials[id]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
289 paint = this.mb_rt.paint_radial_new(radial[0], |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
290 radial[1], |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
291 radial[2]); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
292 } |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
293 paint.set_stops(this.stop_ref[id]); |
706 | 294 } else { |
714 | 295 paint = this.mb_rt.paint_color_new(0,0,0,1); |
706 | 296 } |
297 return paint; | |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
298 }; |
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
|
299 |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
300 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
|
301 { |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
302 return; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
303 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
|
304 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
|
305 var pair; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
306 var i; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
307 var minx,miny; |
759 | 308 |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
309 minx = 10000; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
310 miny = 10000; |
759 | 311 |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 switch(type) { |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
316 case 'm': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
317 case 'l': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
318 case 'a': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
319 case 'x': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
320 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
|
321 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
|
322 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
|
323 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
|
324 i++; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
325 } 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
|
326 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
|
327 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
|
328 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
|
329 } |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
330 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
331 case 'q': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
332 // Implement this latter |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
333 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
334 case 'c': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
335 // Implement this latter |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
336 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
337 case 's': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
338 // Implement this latter |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
339 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
340 case 'h': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
341 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
|
342 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
343 case 'v': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
344 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
|
345 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
346 default: |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
347 continue; |
759 | 348 } |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
349 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
|
350 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
|
351 } |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
352 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
|
353 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
|
354 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
|
355 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
|
356 }; |
759 | 357 |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
358 function _mul(m1, m2) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
359 var res = new Array(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
360 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
361 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
|
362 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
|
363 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
|
364 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
|
365 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
|
366 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
|
367 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
368 return res; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
369 } |
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 function _pnt_transform(x, y, matrix) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
372 var rx, ry; |
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 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
|
375 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
|
376 return new Array(rx, ry); |
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 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
379 function _shift_transform(x, y, matrix) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
380 var rx, ry; |
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 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
|
383 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
|
384 return new Array(rx, ry); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
385 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
386 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
387 function _transform_bbox(bbox, matrix) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
388 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
|
389 var x, y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
390 var pnt; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
391 var pnts = new Array(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
392 var i; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
393 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
394 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
|
395 pnts.push(pnt); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
396 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
|
397 pnts.push(pnt); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
398 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
|
399 pnts.push(pnt); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
400 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
|
401 pnts.push(pnt); |
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 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
|
404 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
|
405 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
|
406 pnt = pnts[i]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
407 if(pnt[0] < min_x) |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
408 min_x = pnt[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
409 if(pnt[1] < min_y) |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
410 min_y = pnt[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
411 if(pnt[0] > max_x) |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
412 max_x = pnt[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
413 if(pnt[1] > max_y) |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
414 max_y = pnt[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
415 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
416 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
417 bbox.x = min_x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
418 bbox.y = min_y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
419 bbox.width = max_x - min_x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
420 bbox.height = max_y - min_y; |
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 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
423 function _reverse(m1) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
424 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
|
425 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
|
426 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
427 rev[3] = -m[3] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
428 m[3] = 0; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
429 m[4] += rev[3] * m[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
430 m[5] += rev[3] * m[2]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
431 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
432 rev[1] = -m[1] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
433 rev[0] += rev[1] * rev[3]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
434 m[1] = 0; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
435 m[2] += rev[1] * m[5]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
436 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
437 rev[2] = -m[2]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
438 rev[5] = -m[5]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
439 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
440 rev[0] = rev[0] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
441 rev[1] = rev[1] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
442 rev[2] = rev[2] / m[0]; |
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 rev[3] = rev[3] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
445 rev[4] = rev[4] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
446 rev[5] = rev[5] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
447 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
448 return rev; |
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 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
451 var _bbox_proto = { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
452 _get_ac_saved_rev: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
453 var c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
454 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
455 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
456 if(c.type != "coord") |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
457 c = c.parent; // is a shape! |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
458 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
459 mtx = c._mbapp_saved_rev_mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
460 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
|
461 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
462 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
|
463 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
464 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
465 return mtx; |
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 _get_ac_mtx: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
469 var c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
470 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
471 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
472 if(c.type != "coord") |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
473 c = c.parent; // is a shape! |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
474 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
475 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
|
476 while(c.parent) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
477 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
478 mtx = _mul(c, 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 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
481 return mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
482 }, |
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 _saved_to_current: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
485 var r; |
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 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
|
488 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
489 return r; |
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 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
492 /*! \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
|
493 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
494 update: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
495 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
496 |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
497 this.x = this.orig.x; |
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
498 this.y = this.orig.y; |
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
499 this.width = this.orig.width; |
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
500 this.height = this.orig.height; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
501 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
502 mtx = this._saved_to_current(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
503 _transform_bbox(this, mtx); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
504 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
505 }; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
506 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
507 var _center_proto = { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
508 _get_ac_saved_rev: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
509 var c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
510 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
511 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
512 if(c.type != "coord") |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
513 c = c.parent; // is a shape! |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
514 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
515 mtx = c._mbapp_saved_rev_mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
516 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
|
517 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
518 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
|
519 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
520 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
521 return mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
522 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
523 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
524 _get_ac_mtx: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
525 var c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
526 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
527 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
528 if(c.type != "coord") |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
529 c = c.parent; // is a shape! |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
530 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
531 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
|
532 while(c.parent) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
533 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
534 mtx = _mul(c, mtx); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
535 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
536 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
537 return mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
538 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
539 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
540 _get_ac_rev: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
541 var c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
542 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
543 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
544 if(c.type != "coord") |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
545 c = c.parent; // is a shape! |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
546 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
547 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
|
548 while(c.parent) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
549 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
550 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
|
551 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
552 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
553 return mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
554 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
555 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
556 _saved_to_current: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
557 var r; |
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 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
|
560 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
561 return r; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
562 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
563 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
564 /*! \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
|
565 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
566 update: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
567 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
568 var xy; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
569 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
570 mtx = this._saved_to_current(); |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
571 xy = _pnt_transform(this.orig.x, this.orig.y, mtx); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
572 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
573 this._x = xy[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
574 this._y = xy[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
575 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
576 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
577 /*! \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
|
578 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
579 move: function(x, y) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
580 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
581 var xdiff = x - this._x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
582 var ydiff = y - this._y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
583 var shiftxy; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
584 var c; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
585 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
586 mtx = this._get_ac_rev(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
587 shiftxy = _shift_transform(xdiff, ydiff, mtx); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
588 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
589 c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
590 if(c.type != "coord") |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
591 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
592 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
593 c[2] += shiftxy[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
594 c[5] += shiftxy[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
595 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
596 this._x = x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
597 this._y = y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
598 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
599 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
600 /*! \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
|
601 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
602 move_pnt: function(pnt) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
603 this.move(pnt.x, pnt.y); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
604 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
605 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
606 /*! \brief Prevent user to modify value. |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
607 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
608 get x() { return this._x; }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
609 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
610 /*! \brief Prevent user to modify value. |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
611 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
612 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
|
613 |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
614 get rel() { |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
615 var rev; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
616 var xy; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
617 |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
618 rev = this._get_ac_rev(); |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
619 xy = _pnt_transform(this.orig.x, this.orig.y, rev); |
857
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
620 |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
621 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
|
622 }, |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
623 }; |
759 | 624 |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
625 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
|
626 var a; |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
627 var vstr; |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
807
diff
changeset
|
628 var bbox, center; |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
629 var orig; |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
630 |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
631 a = node.attr("bbox-x"); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
632 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
|
633 return 0; |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
634 |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
635 /* bbox.orig is initial values of bbox. The bbox is recomputed |
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
636 * according bbox.orig and current matrix. See bbox.update(). |
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
637 */ |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
807
diff
changeset
|
638 tgt.bbox = bbox = new Object(); |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
639 bbox.orig = orig = new Object(); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
640 bbox.owner = tgt; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
641 bbox.__proto__ = _bbox_proto; |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
642 vstr = a.value(); |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
643 orig.x = parseFloat(vstr); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
644 |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
645 a = node.attr("bbox-y"); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
646 vstr = a.value(); |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
647 orig.y = this.height - parseFloat(vstr); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
648 |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
649 a = node.attr("bbox-width"); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
650 vstr = a.value(); |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
651 orig.width = parseFloat(vstr); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
652 |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
653 a = node.attr("bbox-height"); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
654 vstr = a.value(); |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
655 orig.height = parseFloat(vstr); |
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
656 orig.y -= orig.height; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
657 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
658 bbox.update(); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
659 |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
660 /* center.orig is initial values of center. The center is |
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
661 * recomputed according center.orig and current matrix. See |
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
662 * center.update(). |
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
663 */ |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
807
diff
changeset
|
664 tgt.center = center = new Object(); |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
665 center.orig = orig = new Object(); |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
807
diff
changeset
|
666 |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
667 orig.x = bbox.orig.width / 2 + bbox.orig.x; |
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
668 orig.y = bbox.orig.height / 2 + bbox.orig.y; |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
669 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
|
670 if(a) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
671 vstr = a.value(); |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
672 orig.x += parseFloat(vstr); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
673 a = node.attr("transform-center-y"); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
674 vstr = a.value(); |
861
e69f551e4a37
Move initial values of bbox and center to bbox.orig and center.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
675 orig.y -= parseFloat(vstr); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
676 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
677 center.__proto__ = _center_proto; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
678 center.owner = tgt; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
679 center.update(); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
680 |
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
|
681 return 1; |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
682 } |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
683 |
882
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
684 loadSVG.prototype._set_paint_style = function(style, tgt) { |
706 | 685 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
|
686 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
|
687 var stroke_alpha = 1; |
877
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
688 var alpha = 1; |
717
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
689 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
|
690 var stroke_color; |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
691 var stroke_width = 1; |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
692 var i; |
706 | 693 |
877
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
694 if(style) { |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
695 if('opacity' in style) |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
696 alpha = parseFloat(style['opacity']); |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
697 if('fill' in style) |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
698 fill_color = style['fill']; |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
699 if('fill-opacity' in style) |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
700 fill_alpha = parseFloat(style['fill-opacity']); |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
701 if('stroke' in style) |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
702 stroke_color = style['stroke']; |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
703 if('stroke-width' in style) |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
704 stroke_width = parseFloat(style['stroke-width']); |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
705 if('stroke-opacity' in style) |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
706 stroke_alpha = parseFloat(style['stroke-opacity']); |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
707 if('display' in style && style['display'] == 'none') |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
708 return; |
717
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
709 } |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
710 |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
711 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
|
712 if(fill_color != "none") { |
714 | 713 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
|
714 paint.fill(tgt); |
706 | 715 } |
717
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
716 } |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
717 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
|
718 if(stroke_color != "none") { |
714 | 719 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
|
720 paint.stroke(tgt); |
706 | 721 } |
722 } | |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
723 |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
724 tgt.stroke_width = stroke_width; |
888
143ac14c3ce9
Set opacity for a path.
Thinker K.F. Li <thinker@codemud.net>
parents:
883
diff
changeset
|
725 |
143ac14c3ce9
Set opacity for a path.
Thinker K.F. Li <thinker@codemud.net>
parents:
883
diff
changeset
|
726 if(alpha < 1) |
143ac14c3ce9
Set opacity for a path.
Thinker K.F. Li <thinker@codemud.net>
parents:
883
diff
changeset
|
727 tgt.parent.opacity = alpha; |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
728 }; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
729 |
882
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
730 loadSVG.prototype._set_paint = function(node, tgt) { |
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
731 var style; |
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
732 |
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
733 style = parse_style(node); |
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
734 this._set_paint_style(style, tgt); |
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
735 }; |
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
736 |
880
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
737 function formalize_path_data(d) { |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
738 var posM, posm; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
739 var pos; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
740 var nums = "0123456789+-."; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
741 var rel = false; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
742 var cmd; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
743 |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
744 posM = d.search("M"); |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
745 posm = d.search("m"); |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
746 pos = posm < posM? posm: posM; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
747 if(pos == -1) |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
748 pos = posM == -1? posm: posM; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
749 if(pos == -1) |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
750 return d; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
751 |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
752 if(posm == pos) |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
753 rel = true; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
754 |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
755 pos = pos + 1; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
756 while(pos < d.length && " ,".search(d[pos]) >= 0) |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
757 pos++; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
758 while(pos < d.length && nums.search(d[pos]) >= 0) |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
759 pos++; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
760 while(pos < d.length && " ,".search(d[pos]) >= 0) |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
761 pos++; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
762 while(pos < d.length && nums.search(d[pos]) >= 0) |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
763 pos++; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
764 while(pos < d.length && " ,".search(d[pos]) >= 0) |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
765 pos++; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
766 if(nums.search(d[pos]) >= 0) { |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
767 if(rel) |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
768 cmd = "l"; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
769 else |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
770 cmd = "L"; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
771 d = d.substring(0, pos) + cmd + formalize_path_data(d.substring(pos)); |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
772 } |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
773 return d; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
774 } |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
775 |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
776 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
|
777 { |
880
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
778 var d = formalize_path_data(n.attr('d').value()); |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
779 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
|
780 var path = this.mb_rt.path_new(d); |
888
143ac14c3ce9
Set opacity for a path.
Thinker K.F. Li <thinker@codemud.net>
parents:
883
diff
changeset
|
781 var pcoord = this.mb_rt.coord_new(coord); |
880
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
782 |
888
143ac14c3ce9
Set opacity for a path.
Thinker K.F. Li <thinker@codemud.net>
parents:
883
diff
changeset
|
783 guessPathBoundingBox(pcoord,d); |
143ac14c3ce9
Set opacity for a path.
Thinker K.F. Li <thinker@codemud.net>
parents:
883
diff
changeset
|
784 pcoord.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
|
785 this._set_paint(n, path); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
786 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
|
787 |
888
143ac14c3ce9
Set opacity for a path.
Thinker K.F. Li <thinker@codemud.net>
parents:
883
diff
changeset
|
788 make_mbnames(this.mb_rt, n, pcoord); |
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
|
789 }; |
706 | 790 |
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
|
791 loadSVG.prototype.parseText=function(accu,coord,id, n) |
624 | 792 { |
793 var x = getInteger(n,'x'); | |
794 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
|
795 var tcoord = this.mb_rt.coord_new(coord); |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
796 var style; |
759 | 797 |
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
|
798 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
|
799 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
|
800 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
|
801 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
|
802 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
803 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
|
804 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
|
805 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
|
806 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
|
807 } |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
808 style = parse_style(n); |
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 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
|
810 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
|
811 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
|
812 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
|
813 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
|
814 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
|
815 } 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
|
816 } |
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
|
817 } |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
818 this._set_bbox(n, tcoord); |
624 | 819 |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
820 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
|
821 }; |
624 | 822 |
759 | 823 |
824 function multiply(s,d) { | |
825 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
|
826 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
|
827 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
|
828 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
|
829 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
|
830 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
|
831 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
|
832 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
|
833 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
|
834 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
|
835 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
|
836 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
|
837 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
|
838 }; |
759 | 839 |
624 | 840 function parseTransform(coord, s) |
841 { | |
842 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
|
843 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
|
844 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
|
845 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
|
846 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
|
847 } |
a47431293043
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 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
|
849 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
|
850 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
|
851 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
|
852 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
|
853 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
854 } |
a47431293043
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 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
|
856 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
|
857 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
|
858 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
|
859 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
|
860 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
|
861 } |
a47431293043
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 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
|
863 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
|
864 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
|
865 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
|
866 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
|
867 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
|
868 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
|
869 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
|
870 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
|
871 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
|
872 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
|
873 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
|
874 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
|
875 } |
624 | 876 } |
877 | |
759 | 878 loadSVG.prototype.parseRect=function(accu_matrix,coord, id, n) |
624 | 879 { |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
880 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
|
881 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
|
882 var rx,ry; |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
883 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
|
884 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
|
885 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
|
886 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
|
887 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
|
888 |
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
|
889 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
|
890 |
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
|
891 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
|
892 parseTransform(tcoord,trans.value()); |
759 | 893 |
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
|
894 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
|
895 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
|
896 this._set_paint(n, rect); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
897 this._set_bbox(n, tcoord); |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
787
diff
changeset
|
898 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
787
diff
changeset
|
899 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
|
900 }; |
a47431293043
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 |
a47431293043
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 // 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
|
903 // 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
|
904 // 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
|
905 // 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
|
906 // 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
|
907 // 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
|
908 // |
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
|
909 // 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
|
910 // 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
|
911 |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
912 function parseGroupStyle(style,n) |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
913 { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
914 var attr; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
915 if (n) { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
916 attr = n.attr('style'); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
917 } else { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
918 attr = null; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
919 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
920 if (attr == null) { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
921 return; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
922 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
923 var f = attr.value().split(';'); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
924 |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
925 for(i in f) { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
926 var kv = f[i].split(':'); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
927 if (kv[0] == 'opacity') { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
928 style.opacity = parseFloat(kv[1]); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
929 } else { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
930 sys.puts("Unknown style: "+kv[0]); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
931 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
932 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
933 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
934 |
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
|
935 loadSVG.prototype.parseGroup=function(accu_matrix,root, group_id, n) { |
624 | 936 var k; |
937 var nodes = n.childNodes(); | |
714 | 938 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
|
939 // 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
|
940 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
|
941 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
|
942 var style; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
943 |
759 | 944 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
|
945 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
|
946 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
|
947 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
|
948 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
|
949 } |
a47431293043
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 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
|
951 multiply(accu,coord); |
624 | 952 |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
953 style = {}; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
954 parseGroupStyle(style, n); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
955 if(style.opacity) { |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
956 sys.puts("opacity=" + style.opacity); |
830
2a73ff24c141
Use accessor to replace the method to setup the opacity
wycc
parents:
810
diff
changeset
|
957 coord.opacity=style.opacity; |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
958 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
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 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
|
961 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
|
962 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
|
963 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
|
964 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
|
965 id = attr.value(); |
624 | 966 } |
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
|
967 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
|
968 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
|
969 } 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
|
970 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
|
971 } 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
|
972 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
|
973 } 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
|
974 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
|
975 } 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
|
976 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
|
977 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
978 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
979 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
|
980 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
|
981 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
|
982 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
|
983 |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
984 this._set_bbox(n, coord); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
985 |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
986 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
|
987 }; |
624 | 988 |
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
|
989 loadSVG.prototype.parseImage=function(accu,coord,id, n) |
646 | 990 { |
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
|
991 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
|
992 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
|
993 var trans = n.attr('transform'); |
646 | 994 |
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
|
995 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
|
996 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
|
997 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
|
998 } 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
|
999 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
|
1000 } 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
|
1001 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
1002 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
|
1003 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
|
1004 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
|
1005 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
|
1006 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
|
1007 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
|
1008 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
|
1009 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
|
1010 } |
646 | 1011 |
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
|
1012 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
|
1013 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
|
1014 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
|
1015 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
|
1016 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
|
1017 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
|
1018 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
|
1019 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
|
1020 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
|
1021 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
|
1022 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
|
1023 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
|
1024 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
|
1025 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
|
1026 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
|
1027 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
|
1028 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
|
1029 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
|
1030 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
|
1031 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
|
1032 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
|
1033 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
|
1034 tcoord.add_shape(img); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
1035 |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
1036 this._set_bbox(n, img); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
1037 |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
1038 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
|
1039 }; |
624 | 1040 |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1041 function _parse_stops(n) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1042 var children; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1043 var child; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1044 var style; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1045 var color; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1046 var rgb; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1047 var opacity; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1048 var r, g, b, a; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1049 var offset_atr, offset; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1050 var stops = []; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1051 var i; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1052 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1053 children = n.childNodes(); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1054 for(i = 0; i < children.length; i++) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1055 child = children[i]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1056 if(child.name() == "stop") { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1057 style = parse_style(child); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1058 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1059 color = style["stop-color"]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1060 if(color) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1061 rgb = parse_color(color); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1062 r = rgb[0]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1063 g = rgb[1]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1064 b = rgb[2]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1065 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1066 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1067 opacity = style["stop-opacity"]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1068 if(opacity) |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1069 a = parseFloat(opacity); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1070 else |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1071 a = 1; |
876
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1072 |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1073 offset_attr = child.attr("offset"); |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1074 if(offset_attr) |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1075 offset = parseFloat(offset_attr.value()); |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1076 else |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1077 offset = 0; |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1078 |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1079 stops.push([offset, r, g, b, a]); |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1080 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1081 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1082 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1083 return stops; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1084 }; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1085 |
750 | 1086 loadSVG.prototype._MB_parseLinearGradient=function(root,n) |
1087 { | |
1088 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
|
1089 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
|
1090 var nodes = n.childNodes(); |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1091 var mtx = [1, 0, 0, 0, 1, 0]; |
750 | 1092 |
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
|
1093 if (id == null) return; |
876
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1094 id = id.value(); |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1095 |
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
|
1096 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
|
1097 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
|
1098 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
|
1099 var y2 = n.attr("y2"); |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1100 var xy; |
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
|
1101 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
|
1102 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
|
1103 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
|
1104 var r,g,b; |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1105 |
876
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1106 if(x1) |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1107 x1 = parseFloat(x1.value()); |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1108 if(x2) |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1109 x2 = parseFloat(x2.value()); |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1110 if(y1) |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1111 y1 = parseFloat(y1.value()); |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1112 if(y2) |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1113 y2 = parseFloat(y2.value()); |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1114 |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1115 stops = _parse_stops(n); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1116 |
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
|
1117 var href = n.attr('href'); |
876
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1118 if(href != null) { |
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
|
1119 href = href.value(); |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1120 var hrefid = href.substring(1); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1121 pstops = this.stop_ref[hrefid]; |
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
|
1122 stops = pstops.concat(stops); |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1123 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1124 var hrefgr = this.gradients[hrefid]; |
876
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1125 if(typeof x1 == "undefined") |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1126 x1 = hrefgr[0]; |
876
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1127 if(typeof y1 == "undefined") |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1128 y1 = hrefgr[1]; |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1129 if(typeof x2 == "undefined") |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1130 x2 = hrefgr[2]; |
876
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1131 if(typeof y2 == "undefined") |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1132 y2 = hrefgr[3]; |
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
|
1133 } |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1134 |
881
a17c4e231e54
Transform positions of radient paints.
Thinker K.F. Li <thinker@codemud.net>
parents:
880
diff
changeset
|
1135 if(n.attr("gradientTransform")) { |
a17c4e231e54
Transform positions of radient paints.
Thinker K.F. Li <thinker@codemud.net>
parents:
880
diff
changeset
|
1136 parseTransform(mtx, n.attr("gradientTransform").value()); |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1137 xy = _pnt_transform(x1, y1, mtx); |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1138 x1 = xy[0]; |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1139 y1 = xy[1]; |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1140 xy = _pnt_transform(x2, y2, mtx); |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1141 x2 = xy[0]; |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1142 y2 = xy[1]; |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1143 } |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1144 |
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
|
1145 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
|
1146 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
|
1147 }; |
750 | 1148 |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1149 loadSVG.prototype._MB_parseRadialGradient = function(root,n) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1150 var stops; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1151 var cx, cy; |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1152 var xy; |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1153 var mtx = [1, 0, 0, 0, 1, 0]; |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1154 var id; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1155 var href; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1156 var r; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1157 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1158 id = n.attr("id"); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1159 if(!id) |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1160 throw "Require an id"; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1161 id = id.value(); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1162 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1163 stops = _parse_stops(n); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1164 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1165 cx = n.attr("cx"); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1166 if(!cx) |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1167 throw "Miss cx attribute"; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1168 cy = n.attr("cy"); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1169 if(!cy) |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1170 throw "Miss cy attribute"; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1171 cx = parseFloat(cx.value()); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1172 cy = parseFloat(cy.value()); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1173 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1174 r = n.attr("r"); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1175 if(!r) |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1176 throw "Miss r attribute"; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1177 r = parseFloat(r.value()); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1178 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1179 href = n.attr("href"); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1180 if(href) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1181 href = href.value().substring(1); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1182 stops = this.stop_ref[href]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1183 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1184 |
881
a17c4e231e54
Transform positions of radient paints.
Thinker K.F. Li <thinker@codemud.net>
parents:
880
diff
changeset
|
1185 if(n.attr("gradientTransform")) { |
a17c4e231e54
Transform positions of radient paints.
Thinker K.F. Li <thinker@codemud.net>
parents:
880
diff
changeset
|
1186 parseTransform(mtx, n.attr("gradientTransform").value()); |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1187 xy = _pnt_transform(cx, cy, mtx); |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1188 cx = xy[0]; |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1189 cy = xy[1]; |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1190 } |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1191 |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1192 this.radials[id] = [cx, cy, r]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1193 this.stop_ref[id] = stops; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1194 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1195 |
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
|
1196 loadSVG.prototype.parseDefs=function(root,n) |
624 | 1197 { |
1198 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
|
1199 var nodes = n.childNodes(); |
624 | 1200 |
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
|
1201 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
|
1202 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
|
1203 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
|
1204 this._MB_parseLinearGradient(root,nodes[k]); |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1205 } else if(name == "radialGradient") { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1206 this._MB_parseRadialGradient(root,nodes[k]); |
624 | 1207 } |
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
|
1208 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
1209 }; |
624 | 1210 |
1211 |