Mercurial > MadButterfly
annotate nodejs/svg.js @ 1447:b916bb0dc7ca
Add setFrameRate
author | wycc |
---|---|
date | Mon, 11 Apr 2011 20:25:44 +0800 |
parents | 167873cd35c5 |
children |
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 |
1390 | 35 function loadSVG (mb_rt, root, filename) { |
914 | 36 this.pgstack=[]; |
37 if (filename) | |
38 this.load(mb_rt,root,filename); | |
39 } | |
40 | |
41 loadSVG.prototype.load=function(mb_rt, root, filename) { | |
624 | 42 var doc = libxml.parseXmlFile(filename); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
43 var _root = doc.root(); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
44 var nodes = _root.childNodes(); |
624 | 45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 this.gradients={}; |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
51 this.radials = {}; |
1376 | 52 this._groupMap={}; |
914 | 53 coord.center=new Object(); |
54 coord.center.x = 10000; | |
55 coord.center.y = 10000; | |
56 if (this.pgstack.length > 0) | |
57 this.pgstack[this.pgstack.length-1].hide(); | |
58 this.pgstack.push(coord); | |
1400
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
59 this.mb_rt.mbnames={}; |
914 | 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]); |
978 | 75 } else if (n == "metadata") { |
76 this.parseMetadata(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 } else if (n == "g") { |
914 | 78 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
|
79 } |
624 | 80 } |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
81 |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
82 this.sortScene(); |
624 | 83 } |
84 | |
978 | 85 |
86 | |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
87 loadSVG.prototype.sortScene=function() |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
88 { |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
89 for(i=0;i<this.scenes.length;i++) { |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
90 sys.puts(this._groupMap[this.scenes[i].ref]); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
91 sys.puts(this._groupMap[this.scenes[i].ref].layer); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
92 this.scenes[i].layer = this._groupMap[this.scenes[i].ref].layer; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
93 } |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
94 this.scenes.sort(function(a,b) { |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
95 if (a.layer > b.layer) return 1; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
96 if (a.layer < b.layer) return -1; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
97 if (a.start > b.start) return 1; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
98 if (a.start < b.start) return -1; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
99 return 0; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
100 }); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
101 sys.puts("scenes"); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
102 for(i=0;i<this.scenes.length;i++) { |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
103 var s = this.scenes[i]; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
104 sys.puts(s.layer+": start="+s.start+" end="+s.end+" ref="+s.ref); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
105 } |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
106 |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
107 } |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
108 |
914 | 109 loadSVG.prototype.leaveSVG=function() |
110 { | |
111 var p = this.pgstack.pop(); | |
112 p.hide(); | |
113 if (this.pgstack.length > 0) | |
114 this.pgstack[this.pgstack.length-1].show(); | |
115 } | |
116 | |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
117 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
|
118 var mbname; |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
119 var name; |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
120 |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
121 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
|
122 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
|
123 |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
124 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
|
125 if(mbname) { |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
126 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
|
127 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
|
128 } |
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
|
129 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
|
130 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
|
131 name = mbname.value(); |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
132 sys.puts("defone object "+ name); |
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
|
133 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
|
134 } |
978 | 135 try { |
136 var gname = n.attr('id').value(); | |
1378 | 137 sys.puts("defone object "+ gname); |
978 | 138 mb_rt.mbnames[gname] = obj; |
139 } catch(e) { | |
140 } | |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
141 } |
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
142 |
624 | 143 function getInteger(n,name) |
144 { | |
145 if (n == null) return 0; | |
146 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
|
147 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
|
148 return parseInt(a.value()); |
624 | 149 } |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
150 |
631 | 151 function parsePointSize(s) |
152 { | |
153 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
|
154 var i; |
624 | 155 |
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
|
156 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
|
157 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
|
158 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
|
159 } |
a47431293043
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 fs; |
631 | 161 |
162 } | |
163 | |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
164 function parse_style(node) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
165 var style_attr; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
166 var style; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
167 var parts, part; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
168 var kv, key, value; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
169 var content = {}; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
170 var i; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
171 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
172 style_attr = node.attr('style'); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
173 if(!style_attr) |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
174 return content; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
175 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
176 style = style_attr.value(); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
177 parts = style.split(';'); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
178 for(i = 0; i < parts.length; i++) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
179 part = parts[i].trim(); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
180 if(part) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
181 kv = part.split(':'); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
182 key = kv[0].trim(); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
183 value = kv[1].trim(); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
184 content[key] = value; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
185 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
186 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
187 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
188 return content; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
189 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
190 |
631 | 191 function parseColor(c) |
192 { | |
193 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
|
194 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
|
195 } |
631 | 196 } |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
197 |
631 | 198 function parseTextStyle(style,n) |
624 | 199 { |
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
|
200 var attr; |
625
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
201 if (n) { |
9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents:
624
diff
changeset
|
202 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
|
203 } 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
|
204 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
|
205 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
206 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
|
207 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
|
208 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
209 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
|
210 |
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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 } 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
|
216 } 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
|
217 } 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
|
218 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
|
219 } 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
|
220 } 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
|
221 } 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
|
222 } 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
|
223 } 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
|
224 } 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
|
225 } 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
|
226 } 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
|
227 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
|
228 } 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
|
229 } 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
|
230 } 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
|
231 } 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
|
232 } 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
|
233 } 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
|
234 } 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
|
235 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
|
236 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
237 } |
624 | 238 } |
732
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
720
diff
changeset
|
239 function tspan_set_text(text) |
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
720
diff
changeset
|
240 { |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
241 sys.puts("kkkkk "+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
|
242 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
|
243 } |
624 | 244 |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
245 function _parse_font_size(fn_sz_str) { |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
246 var pos; |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
247 |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
248 pos = fn_sz_str.search("px"); |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
249 if(pos >= 0) |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
250 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
|
251 pos = fn_sz_str.search("pt"); |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
252 if(pos >= 0) |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
253 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
|
254 |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
255 return parseFloat(fn_sz_str); |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
256 } |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
257 |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
258 loadSVG.prototype.parseTSpan = function(coord, n, pstyle) { |
624 | 259 var x = getInteger(n,'x'); |
260 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
|
261 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
|
262 var style; |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
263 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
|
264 var weight = 80; |
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
265 var slant = 0; |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
266 var sz = 10; |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
267 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
|
268 var k; |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
269 if (x == 0) x = coord.text_x; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
270 if (y == 0) y = coord.text_y; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
271 var obj = this.mb_rt.stext_new(n.text().trim(),x,y); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
272 sys.puts("get text "+n.text().trim() +"at "+x+","+y); |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
273 |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
274 tcoord.node = n; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
275 n.coord = tcoord; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
276 this._check_duplicate_src(n,tcoord); |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
277 style = parse_style(n); |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
278 for(k in pstyle) { |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
279 if(k in style) |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
280 continue; |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
281 style[k] = pstyle[k]; |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
282 } |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
283 |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
284 if("font-family" in style) |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
285 family = style["font-family"]; |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
286 if("font-size" in style) |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
287 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
|
288 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
|
289 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
|
290 weight = 200; |
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
291 } |
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
292 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
|
293 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
|
294 slant = 110; |
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
295 } |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
296 |
902
e86b4d56ddea
Parse font-style and font-weight of SVG text
Thinker K.F. Li <thinker@codemud.net>
parents:
899
diff
changeset
|
297 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
|
298 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
|
299 |
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
|
300 tcoord.add_shape(obj); |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
301 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
|
302 tcoord.text = obj; |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
303 |
882
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
304 this._set_paint_style(style, obj); |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
305 this._set_bbox(n, obj); |
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
306 |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
307 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
|
308 }; |
624 | 309 |
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
|
310 loadSVG.prototype._prepare_paint_color = function(color, alpha) { |
706 | 311 var paint; |
713 | 312 var c; |
706 | 313 |
314 if (color[0]=='#') { | |
315 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
|
316 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
|
317 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
|
318 b = parseInt(color.substring(5,7),16)/255; |
714 | 319 paint = this.mb_rt.paint_color_new(r, g, b, alpha); |
713 | 320 } else if(_std_colors[color]) { |
321 c = _std_colors[color]; | |
714 | 322 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
|
323 } else if (color.substring(0,3) == 'url') { |
5723e5446b7c
Fix incorrect variable name
Thinker K.F. Li <thinker@codemud.net>
parents:
802
diff
changeset
|
324 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
|
325 if(id in this.gradients) { |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
326 var gr = this.gradients[id]; |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
327 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
|
328 } else { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
329 var radial = this.radials[id]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
330 paint = this.mb_rt.paint_radial_new(radial[0], |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
331 radial[1], |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
332 radial[2]); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
333 } |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
334 paint.set_stops(this.stop_ref[id]); |
706 | 335 } else { |
714 | 336 paint = this.mb_rt.paint_color_new(0,0,0,1); |
706 | 337 } |
338 return paint; | |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
339 }; |
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
|
340 |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
341 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
|
342 { |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
343 return; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
344 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
|
345 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
|
346 var pair; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
347 var i; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
348 var minx,miny; |
759 | 349 |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
350 minx = 10000; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
351 miny = 10000; |
759 | 352 |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
353 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
|
354 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
|
355 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
|
356 switch(type) { |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
357 case 'm': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
358 case 'l': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
359 case 'a': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
360 case 'x': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
361 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
|
362 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
|
363 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
|
364 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
|
365 i++; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
366 } 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
|
367 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
|
368 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
|
369 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
|
370 } |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
371 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
372 case 'q': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
373 // Implement this latter |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
374 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
375 case 'c': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
376 // Implement this latter |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
377 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
378 case 's': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
379 // Implement this latter |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
380 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
381 case 'h': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
382 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
|
383 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
384 case 'v': |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
385 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
|
386 break; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
387 default: |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
388 continue; |
759 | 389 } |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
390 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
|
391 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
|
392 } |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
393 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
|
394 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
|
395 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
|
396 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
|
397 }; |
759 | 398 |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
399 function _mul(m1, m2) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
400 var res = new Array(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
401 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
402 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
|
403 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
|
404 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
|
405 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
|
406 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
|
407 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
|
408 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
409 return res; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
410 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
411 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
412 function _pnt_transform(x, y, matrix) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
413 var rx, ry; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
414 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
415 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
|
416 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
|
417 return new Array(rx, ry); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
418 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
419 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
420 function _shift_transform(x, y, matrix) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
421 var rx, ry; |
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 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
|
424 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
|
425 return new Array(rx, ry); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
426 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
427 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
428 function _transform_bbox(bbox, matrix) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
429 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
|
430 var x, y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
431 var pnt; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
432 var pnts = new Array(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
433 var i; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
434 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
435 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
|
436 pnts.push(pnt); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
437 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
|
438 pnts.push(pnt); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
439 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
|
440 pnts.push(pnt); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
441 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
|
442 pnts.push(pnt); |
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 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
|
445 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
|
446 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
|
447 pnt = pnts[i]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
448 if(pnt[0] < min_x) |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
449 min_x = pnt[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
450 if(pnt[1] < min_y) |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
451 min_y = pnt[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
452 if(pnt[0] > max_x) |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
453 max_x = pnt[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
454 if(pnt[1] > max_y) |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
455 max_y = pnt[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
456 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
457 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
458 bbox.x = min_x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
459 bbox.y = min_y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
460 bbox.width = max_x - min_x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
461 bbox.height = max_y - min_y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
462 } |
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 function _reverse(m1) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
465 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
|
466 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
|
467 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
468 rev[3] = -m[3] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
469 m[3] = 0; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
470 m[4] += rev[3] * m[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
471 m[5] += rev[3] * m[2]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
472 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
473 rev[1] = -m[1] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
474 rev[0] += rev[1] * rev[3]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
475 m[1] = 0; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
476 m[2] += rev[1] * m[5]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
477 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
478 rev[2] = -m[2]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
479 rev[5] = -m[5]; |
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 rev[0] = rev[0] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
482 rev[1] = rev[1] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
483 rev[2] = rev[2] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
484 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
485 rev[3] = rev[3] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
486 rev[4] = rev[4] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
487 rev[5] = rev[5] / m[4]; |
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 rev; |
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 var _bbox_proto = { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
493 _get_ac_saved_rev: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
494 var c = this.owner; |
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 |
936
a9abcdac0ae5
Fix issue of moving lightbar of testsvg.js.
Thinker K.F. Li <thinker@codemud.net>
parents:
928
diff
changeset
|
497 c = c.parent; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
498 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
499 mtx = c._mbapp_saved_rev_mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
500 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
|
501 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
502 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
|
503 } |
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 return mtx; |
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 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
508 _get_ac_mtx: 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 |
936
a9abcdac0ae5
Fix issue of moving lightbar of testsvg.js.
Thinker K.F. Li <thinker@codemud.net>
parents:
928
diff
changeset
|
512 c = c.parent; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
513 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
514 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
|
515 while(c.parent) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
516 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
517 mtx = _mul(c, mtx); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
518 } |
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 return mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
521 }, |
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 _saved_to_current: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
524 var r; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
525 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
526 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
|
527 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
528 return r; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
529 }, |
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 /*! \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
|
532 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
533 update: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
534 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
535 |
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
|
536 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
|
537 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
|
538 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
|
539 this.height = this.orig.height; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
540 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
541 mtx = this._saved_to_current(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
542 _transform_bbox(this, 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 }; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
545 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
546 var _center_proto = { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
547 _get_ac_saved_rev: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
548 var c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
549 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
550 |
936
a9abcdac0ae5
Fix issue of moving lightbar of testsvg.js.
Thinker K.F. Li <thinker@codemud.net>
parents:
928
diff
changeset
|
551 c = c.parent; |
854
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 mtx = c._mbapp_saved_rev_mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
554 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
|
555 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
556 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
|
557 } |
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 return mtx; |
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 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
562 _get_ac_mtx: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
563 var c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
564 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
565 |
936
a9abcdac0ae5
Fix issue of moving lightbar of testsvg.js.
Thinker K.F. Li <thinker@codemud.net>
parents:
928
diff
changeset
|
566 c = c.parent; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
567 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
568 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
|
569 while(c.parent) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
570 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
571 mtx = _mul(c, mtx); |
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 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
574 return mtx; |
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 _get_ac_rev: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
578 var c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
579 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
580 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
581 if(c.type != "coord") |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
582 c = c.parent; // is a shape! |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
583 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
584 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
|
585 while(c.parent) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
586 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
587 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
|
588 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
589 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
590 return mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
591 }, |
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 _saved_to_current: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
594 var r; |
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 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
|
597 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
598 return r; |
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 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
601 /*! \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
|
602 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
603 update: function() { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
604 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
605 var xy; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
606 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
607 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
|
608 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
|
609 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
610 this._x = xy[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
611 this._y = xy[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
612 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
613 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
614 /*! \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
|
615 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
616 move: function(x, y) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
617 var mtx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
618 var xdiff = x - this._x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
619 var ydiff = y - this._y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
620 var shiftxy; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
621 var c; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
622 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
623 mtx = this._get_ac_rev(); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
624 shiftxy = _shift_transform(xdiff, ydiff, mtx); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
625 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
626 c = this.owner; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
627 if(c.type != "coord") |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
628 c = c.parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
629 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
630 c[2] += shiftxy[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
631 c[5] += shiftxy[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
632 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
633 this._x = x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
634 this._y = y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
635 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
636 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
637 /*! \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
|
638 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
639 move_pnt: function(pnt) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
640 this.move(pnt.x, pnt.y); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
641 }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
642 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
643 /*! \brief Prevent user to modify value. |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
644 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
645 get x() { return this._x; }, |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
646 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
647 /*! \brief Prevent user to modify value. |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
648 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
649 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
|
650 |
936
a9abcdac0ae5
Fix issue of moving lightbar of testsvg.js.
Thinker K.F. Li <thinker@codemud.net>
parents:
928
diff
changeset
|
651 /*! \brief Center position in the relative space defined by parent. |
a9abcdac0ae5
Fix issue of moving lightbar of testsvg.js.
Thinker K.F. Li <thinker@codemud.net>
parents:
928
diff
changeset
|
652 */ |
857
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
653 get rel() { |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
654 var rev; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
655 var xy; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
656 |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
657 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
|
658 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
|
659 |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
660 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
|
661 }, |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
662 }; |
759 | 663 |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
664 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
|
665 var a; |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
666 var vstr; |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
807
diff
changeset
|
667 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
|
668 var orig; |
1398
6fa4a53c3fca
Use clone_from_subtree to generate content for the svg:use.
wycc
parents:
1395
diff
changeset
|
669 |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
670 a = node.attr("bbox-x"); |
1395
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
671 if(!a) { |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
672 sys.puts("No bbox: "+node); |
1395
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
673 tgt.center = new Object(); |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
674 tgt.center.x=0; |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
675 tgt.center.y=0; |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
676 tgt.center.rel = new Object(); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
677 tgt.center.rel.x=0; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
678 tgt.center.rel.y=0; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
679 tgt.bbox = new Object(); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
680 tgt.center.__proto__ = _center_proto; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
681 tgt.center.owner = tgt; |
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
|
682 return 0; |
1395
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
683 } |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
684 |
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
|
685 /* 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
|
686 * 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
|
687 */ |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
807
diff
changeset
|
688 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
|
689 bbox.orig = orig = new Object(); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
690 bbox.owner = tgt; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
691 bbox.__proto__ = _bbox_proto; |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
692 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
|
693 orig.x = parseFloat(vstr); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
694 |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
695 a = node.attr("bbox-y"); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
696 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
|
697 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
|
698 |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
699 a = node.attr("bbox-width"); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
700 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
|
701 orig.width = parseFloat(vstr); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
702 |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
703 a = node.attr("bbox-height"); |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
704 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
|
705 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
|
706 orig.y -= orig.height; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
707 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
708 bbox.update(); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
709 |
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
|
710 /* 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
|
711 * 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
|
712 * 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
|
713 */ |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
807
diff
changeset
|
714 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
|
715 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
|
716 |
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
|
717 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
|
718 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
|
719 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
|
720 if(a) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
721 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
|
722 orig.x += parseFloat(vstr); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
723 a = node.attr("transform-center-y"); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
724 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
|
725 orig.y -= parseFloat(vstr); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
726 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
727 center.__proto__ = _center_proto; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
728 center.owner = tgt; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
729 center.update(); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
730 |
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
|
731 return 1; |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
732 } |
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
733 |
882
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
734 loadSVG.prototype._set_paint_style = function(style, tgt) { |
706 | 735 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
|
736 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
|
737 var stroke_alpha = 1; |
877
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
738 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
|
739 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
|
740 var stroke_color; |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
741 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
|
742 var i; |
706 | 743 |
877
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
744 if(style) { |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
745 if('opacity' in style) |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
746 alpha = parseFloat(style['opacity']); |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
747 if('fill' in style) |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
748 fill_color = style['fill']; |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
749 if('fill-opacity' in style) |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
750 fill_alpha = parseFloat(style['fill-opacity']); |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
751 if('stroke' in style) |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
752 stroke_color = style['stroke']; |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
753 if('stroke-width' in style) |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
754 stroke_width = parseFloat(style['stroke-width']); |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
755 if('stroke-opacity' in style) |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
756 stroke_alpha = parseFloat(style['stroke-opacity']); |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
757 if('display' in style && style['display'] == 'none') |
deadcca6e213
Refactory loadSVG._set_paint()
Thinker K.F. Li <thinker@codemud.net>
parents:
876
diff
changeset
|
758 return; |
717
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
759 } |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
760 |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
761 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
|
762 if(fill_color != "none") { |
714 | 763 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
|
764 paint.fill(tgt); |
706 | 765 } |
717
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
766 } |
b822b1912d67
Paint with black for unspecified, not "none", fill and stroke.
Thinker K.F. Li <thinker@branda.to>
parents:
714
diff
changeset
|
767 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
|
768 if(stroke_color != "none") { |
714 | 769 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
|
770 paint.stroke(tgt); |
706 | 771 } |
772 } | |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
773 |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
774 tgt.stroke_width = stroke_width; |
888
143ac14c3ce9
Set opacity for a path.
Thinker K.F. Li <thinker@codemud.net>
parents:
883
diff
changeset
|
775 |
143ac14c3ce9
Set opacity for a path.
Thinker K.F. Li <thinker@codemud.net>
parents:
883
diff
changeset
|
776 if(alpha < 1) |
143ac14c3ce9
Set opacity for a path.
Thinker K.F. Li <thinker@codemud.net>
parents:
883
diff
changeset
|
777 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
|
778 }; |
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
779 |
882
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
780 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
|
781 var style; |
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
782 |
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
783 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
|
784 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
|
785 }; |
d9d55bb50679
Parse color and stroke width of tspan object correctly.
Thinker K.F. Li <thinker@codemud.net>
parents:
881
diff
changeset
|
786 |
880
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
787 function formalize_path_data(d) { |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
788 var posM, posm; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
789 var pos; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
790 var nums = "0123456789+-."; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
791 var rel = false; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
792 var cmd; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
793 |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
794 posM = d.search("M"); |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
795 posm = d.search("m"); |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
796 pos = posm < posM? posm: posM; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
797 if(pos == -1) |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
798 pos = posM == -1? posm: posM; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
799 if(pos == -1) |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
800 return d; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
801 |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
802 if(posm == pos) |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
803 rel = true; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
804 |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
805 pos = pos + 1; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
806 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
|
807 pos++; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
808 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
|
809 pos++; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
810 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
|
811 pos++; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
812 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
|
813 pos++; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
814 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
|
815 pos++; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
816 if(nums.search(d[pos]) >= 0) { |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
817 if(rel) |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
818 cmd = "l"; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
819 else |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
820 cmd = "L"; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
821 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
|
822 } |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
823 return d; |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
824 } |
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
825 |
785
b6d9c42019d1
Refactor color parsing and fix bug of parsing path
Thinker K.F. Li <thinker@codemud.net>
parents:
784
diff
changeset
|
826 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
|
827 { |
880
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
828 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
|
829 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
|
830 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
|
831 var pcoord = this.mb_rt.coord_new(coord); |
1378 | 832 pcoord.node = n; |
833 n.coord = pcoord; | |
834 this._check_duplicate_src(n,pcoord); | |
880
ac3e8492ad74
Formalize path data for MadButterfly.
Thinker K.F. Li <thinker@codemud.net>
parents:
879
diff
changeset
|
835 |
1395
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
836 //guessPathBoundingBox(pcoord,d); |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
837 var trans = n.attr('transform'); |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
838 if (trans) |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
839 parseTransform(pcoord,trans.value()); |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
840 else { |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
841 pcoord.sx = 1; |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
842 pcoord.sy = 1; |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
843 pcoord.r = 0; |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
844 pcoord.tx = 0; |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
845 pcoord.ty = 0; |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
846 } |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
847 |
888
143ac14c3ce9
Set opacity for a path.
Thinker K.F. Li <thinker@codemud.net>
parents:
883
diff
changeset
|
848 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
|
849 this._set_paint(n, path); |
1395
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
850 this._set_bbox(n, pcoord); |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
851 |
888
143ac14c3ce9
Set opacity for a path.
Thinker K.F. Li <thinker@codemud.net>
parents:
883
diff
changeset
|
852 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
|
853 }; |
706 | 854 |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
855 loadSVG.prototype.parseFlowRegion=function(coord, n,style) |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
856 { |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
857 var nodes = n.childNodes(); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
858 |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
859 var k; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
860 |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
861 for(k in nodes) { |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
862 var c= nodes[k].name(); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
863 if (c == "rect") { |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
864 // We support rectangle only for now. The x,y,w,h are extrcated and use by the flowPara latter. |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
865 coord.text_x = getInteger(nodes[k],'x'); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
866 coord.text_y = getInteger(nodes[k],'y'); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
867 coord.text_w = getInteger(nodes[k],'width'); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
868 coord.text_h = getInteger(nodes[k],'height'); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
869 } |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
870 } |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
871 } |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
872 loadSVG.prototype.parseFlowRoot=function(accu,coord, id, n) { |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
873 var nodes = n.childNodes(); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
874 var tcoord = this.mb_rt.coord_new(coord); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
875 var trans = n.attr('transform'); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
876 |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
877 |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
878 |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
879 tcoord.node = n; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
880 n.coord = tcoord; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
881 this._check_duplicate_src(n,tcoord); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
882 |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
883 if (trans) |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
884 parseTransform(tcoord,trans.value()); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
885 else { |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
886 tcoord.sx = 1; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
887 tcoord.sy = 1; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
888 tcoord.r = 0; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
889 tcoord.tx = 0; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
890 tcoord.ty = 0; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
891 } |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
892 style = parse_style(n); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
893 var nodes = n.childNodes(); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
894 var k; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
895 for(k in nodes) { |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
896 var c= nodes[k].name(); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
897 if (c == "flowRegion") { |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
898 this.parseFlowRegion(tcoord,nodes[k],style); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
899 } else if (c == "flowPara") { |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
900 this.parseTSpan(tcoord,nodes[k],style); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
901 } else if (c == "flowDiv") { |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
902 } |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
903 } |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
904 var nx = coord[0]*tcoord.text_x+coord[1]*tcoord.text_y+coord[2]; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
905 if (coord.center.x > nx) |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
906 coord.center.x = nx; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
907 var ny = coord[3]*tcoord.text_x+coord[4]*tcoord.text_y+coord[5]; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
908 if (coord.center.y > ny) |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
909 coord.center.y = ny; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
910 this._set_bbox(n, tcoord); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
911 |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
912 make_mbnames(this.mb_rt, n, tcoord); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
913 } |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
914 |
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
|
915 loadSVG.prototype.parseText=function(accu,coord,id, n) |
624 | 916 { |
1400
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
917 var nodes = n.childNodes(); |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
918 if (nodes == "") return; |
624 | 919 var x = getInteger(n,'x'); |
920 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
|
921 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
|
922 var style; |
759 | 923 |
1378 | 924 tcoord.node = n; |
925 n.coord = tcoord; | |
926 this._check_duplicate_src(n,tcoord); | |
927 | |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
928 tcoord.sx = 1; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
929 tcoord.sy = 1; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
930 tcoord.r = 0; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
931 tcoord.tx = 0; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
932 tcoord.ty = 0; |
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
|
933 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
|
934 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
|
935 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
|
936 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
|
937 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
938 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
|
939 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
|
940 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
|
941 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
|
942 } |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
943 |
879
44f46d6873be
Set paint for tspan correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
878
diff
changeset
|
944 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
|
945 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
|
946 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
|
947 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
|
948 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
|
949 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
|
950 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
|
951 } 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
|
952 } |
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
|
953 } |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
954 this._set_bbox(n, tcoord); |
624 | 955 |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
956 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
|
957 }; |
624 | 958 |
759 | 959 |
960 function multiply(s,d) { | |
961 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
|
962 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
|
963 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
|
964 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
|
965 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
|
966 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
|
967 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
|
968 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
|
969 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
|
970 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
|
971 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
|
972 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
|
973 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
|
974 }; |
759 | 975 |
624 | 976 function parseTransform(coord, s) |
977 { | |
978 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
|
979 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
|
980 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
|
981 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
|
982 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
|
983 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
984 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
|
985 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
|
986 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
|
987 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
|
988 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
|
989 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
990 } |
a47431293043
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 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
|
992 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
|
993 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
|
994 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
|
995 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
|
996 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
|
997 } |
a47431293043
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 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
|
999 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
|
1000 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
|
1001 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
|
1002 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
|
1003 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
|
1004 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
|
1005 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
|
1006 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
|
1007 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
|
1008 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
|
1009 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
|
1010 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
|
1011 } |
1400
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1012 generateAffineParameters(coord); |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1013 } |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1014 function generateAffineParameters(coord) |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1015 { |
1378 | 1016 if (coord[0]*coord[4] == coord[1]*coord[3]) { |
1017 sys.puts("Singular affine matrix\n"); | |
1018 coord.sx = 1; | |
1019 coord.sy = 1; | |
1020 coord.r = 0; | |
1021 coord.tx = 0; | |
1022 coord.ty = 0; | |
1023 return; | |
1024 } | |
1025 A = coord[0]; | |
1026 B = coord[3]; | |
1027 C = coord[1]; | |
1028 D = coord[4]; | |
1029 E = coord[2]; | |
1030 F = coord[5]; | |
1031 sx = Math.sqrt(A*A+B*B); | |
1032 A = A / sx; | |
1033 B = B / sx; | |
1034 shear = A*C+B*D; | |
1035 C = C - A*shear; | |
1036 D = D - B*shear; | |
1037 sy = Math.sqrt(C*C+D*D); | |
1038 C = C / sy; | |
1039 D = D / sy; | |
1040 r = A*D - B*C; | |
1041 if (r == -1) { | |
1042 shear = - shear; | |
1043 sy = -sy; | |
1044 } | |
1045 R = Math.atan2(-B,A); | |
1046 coord.sx = sx; | |
1047 coord.sy = sy; | |
1048 coord.r = R; | |
1049 coord.tx = E; | |
1050 coord.ty = F; | |
624 | 1051 } |
1052 | |
759 | 1053 loadSVG.prototype.parseRect=function(accu_matrix,coord, id, n) |
624 | 1054 { |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
1055 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
|
1056 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
|
1057 var rx,ry; |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
1058 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
|
1059 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
|
1060 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
|
1061 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
|
1062 var tcoord = this.mb_rt.coord_new(coord); |
1378 | 1063 tcoord.node = n; |
1064 n.coord = tcoord; | |
1065 this._check_duplicate_src(n,tcoord); | |
703
3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
wycc
parents:
647
diff
changeset
|
1066 |
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
|
1067 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
|
1068 |
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
|
1069 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
|
1070 parseTransform(tcoord,trans.value()); |
1378 | 1071 else { |
1072 tcoord.sx = 1; | |
1073 tcoord.sy = 1; | |
1074 tcoord.r = 0; | |
1075 tcoord.tx = 0; | |
1076 tcoord.ty = 0; | |
1077 } | |
1381
9a585df24e52
Consider the width and height attribute for the rect elements. The inkscape will change the width and height directly without using transform when we resize the rectangle.
wycc
parents:
1378
diff
changeset
|
1078 |
9a585df24e52
Consider the width and height attribute for the rect elements. The inkscape will change the width and height directly without using transform when we resize the rectangle.
wycc
parents:
1378
diff
changeset
|
1079 tcoord.tx += x; |
9a585df24e52
Consider the width and height attribute for the rect elements. The inkscape will change the width and height directly without using transform when we resize the rectangle.
wycc
parents:
1378
diff
changeset
|
1080 tcoord.ty += y; |
9a585df24e52
Consider the width and height attribute for the rect elements. The inkscape will change the width and height directly without using transform when we resize the rectangle.
wycc
parents:
1378
diff
changeset
|
1081 attr = n.attr('duplicate-src'); |
9a585df24e52
Consider the width and height attribute for the rect elements. The inkscape will change the width and height directly without using transform when we resize the rectangle.
wycc
parents:
1378
diff
changeset
|
1082 if (attr) { |
9a585df24e52
Consider the width and height attribute for the rect elements. The inkscape will change the width and height directly without using transform when we resize the rectangle.
wycc
parents:
1378
diff
changeset
|
1083 var id = attr.value(); |
1425
13e126941bdd
The scribbo may set the duplicated-src to itself. We work around it here. However, we should modify the scribbo to fix it.
wycc
parents:
1408
diff
changeset
|
1084 var src = this.mb_rt.mbnames[id]; |
13e126941bdd
The scribbo may set the duplicated-src to itself. We work around it here. However, we should modify the scribbo to fix it.
wycc
parents:
1408
diff
changeset
|
1085 if (src != null) { |
13e126941bdd
The scribbo may set the duplicated-src to itself. We work around it here. However, we should modify the scribbo to fix it.
wycc
parents:
1408
diff
changeset
|
1086 var orign = src.node; |
13e126941bdd
The scribbo may set the duplicated-src to itself. We work around it here. However, we should modify the scribbo to fix it.
wycc
parents:
1408
diff
changeset
|
1087 sys.puts("xxxxxxxxxxxxxx"); |
1422 | 1088 var nw = getInteger(orign,'width'); |
1089 var nh = getInteger(orign,'height'); | |
1090 tcoord.sx *= w/nw; | |
1091 tcoord.sy *= h/nh; | |
1092 } | |
1381
9a585df24e52
Consider the width and height attribute for the rect elements. The inkscape will change the width and height directly without using transform when we resize the rectangle.
wycc
parents:
1378
diff
changeset
|
1093 } |
1378 | 1094 |
1095 | |
759 | 1096 |
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
|
1097 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
|
1098 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
|
1099 this._set_paint(n, rect); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
1100 this._set_bbox(n, tcoord); |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
787
diff
changeset
|
1101 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
787
diff
changeset
|
1102 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
|
1103 }; |
a47431293043
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 |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
1105 // 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
|
1106 // 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
|
1107 // 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
|
1108 // 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
|
1109 // 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
|
1110 // 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
|
1111 // |
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
|
1112 // 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
|
1113 // 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
|
1114 |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1115 function parseGroupStyle(style,n) |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1116 { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1117 var attr; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1118 if (n) { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1119 attr = n.attr('style'); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1120 } else { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1121 attr = null; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1122 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1123 if (attr == null) { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1124 return; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1125 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1126 var f = attr.value().split(';'); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1127 |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1128 for(i in f) { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1129 var kv = f[i].split(':'); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1130 if (kv[0] == 'opacity') { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1131 style.opacity = parseFloat(kv[1]); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1132 } else { |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1133 sys.puts("Unknown style: "+kv[0]); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1134 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1135 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1136 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1137 |
1376 | 1138 loadSVG.prototype.duplicateGroup=function(id,root) { |
1139 n = this._groupMap[id]; | |
1140 var m = [1,0,0,1,0,0] | |
1141 this.parseGroup(m,root,id, n) | |
1142 } | |
1143 | |
1408
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1144 function getName(n) |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1145 { |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1146 var attr = n.attr('mbname'); |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1147 var name; |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1148 |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1149 if (attr) { |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1150 name = attr.value(); |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1151 if (name != '') return name; |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1152 } |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1153 attr = n.attr('label'); |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1154 |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1155 if (attr) { |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1156 name = attr.value(); |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1157 if (name != '') return name; |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1158 } |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1159 attr = n.attr('id'); |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1160 |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1161 if (attr) { |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1162 name = attr.value(); |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1163 if (name != '') return name; |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1164 } |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1165 |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1166 return ''; |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1167 |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1168 } |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1169 |
1378 | 1170 loadSVG.prototype._check_duplicate_src=function(n,coord) { |
1408
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1171 var id = getName(n); |
1400
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1172 if (id) { |
1408
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1173 coord.id = id; |
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1174 coord.refid = id; |
1400
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1175 } else { |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1176 coord.id = "NA"; |
1408
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1177 coord.refid ="NA"; |
1400
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1178 } |
1395
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
1179 if (n.name()=="use") { |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
1180 n.coord.isuse = true |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
1181 } else { |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
1182 n.coord.isuse = false; |
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
1183 } |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
1184 |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
1185 // A workaround, should be removed. |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
1186 var attr = n.attr('saved_id'); |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
1187 if (attr) return; |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
1188 |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
1189 attr = n.attr('duplicate-src'); |
1400
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1190 if (attr == null) { |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1191 sys.puts("no duplicated" + n); |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1192 return; |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1193 } |
1378 | 1194 var id = attr.value(); |
1195 try { | |
1400
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1196 if (this.mb_rt.mbnames[id].target) { |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1197 sys.puts("duplicated"); |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1198 } |
1378 | 1199 this.mb_rt.mbnames[id].target = coord; |
1408
c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
wycc
parents:
1400
diff
changeset
|
1200 coord.refid = this.mb_rt.mbnames[id].id; |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
1201 sys.puts("set the refid of "+id+" to be "+coord.refid); |
1378 | 1202 } catch(e) { |
1203 sys.puts("id "+id+" is not defined"); | |
1204 } | |
1205 } | |
1206 | |
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
|
1207 loadSVG.prototype.parseGroup=function(accu_matrix,root, group_id, n) { |
1381
9a585df24e52
Consider the width and height attribute for the rect elements. The inkscape will change the width and height directly without using transform when we resize the rectangle.
wycc
parents:
1378
diff
changeset
|
1208 var label = n.attr('label'); |
9a585df24e52
Consider the width and height attribute for the rect elements. The inkscape will change the width and height directly without using transform when we resize the rectangle.
wycc
parents:
1378
diff
changeset
|
1209 if (label && label.value()=='dup') return; |
624 | 1210 var k; |
1211 var nodes = n.childNodes(); | |
714 | 1212 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
|
1213 // 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
|
1214 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
|
1215 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
|
1216 var style; |
1381
9a585df24e52
Consider the width and height attribute for the rect elements. The inkscape will change the width and height directly without using transform when we resize the rectangle.
wycc
parents:
1378
diff
changeset
|
1217 |
1378 | 1218 n.coord = coord; |
1219 coord.node = n; | |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
1220 n.layer = root.id; |
1378 | 1221 this._check_duplicate_src(n,coord); |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1222 |
759 | 1223 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
|
1224 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
|
1225 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
|
1226 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
|
1227 parseTransform(coord, trans.value()); |
1378 | 1228 } else { |
1229 coord.sx = 1; | |
1230 coord.sy = 1; | |
1231 coord.r = 0; | |
1232 coord.tx = 0; | |
1233 coord.ty = 0; | |
1234 } | |
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
|
1235 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
|
1236 multiply(accu,coord); |
624 | 1237 |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1238 style = {}; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1239 parseGroupStyle(style, n); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1240 if(style.opacity) { |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1241 sys.puts("opacity=" + style.opacity); |
830
2a73ff24c141
Use accessor to replace the method to setup the opacity
wycc
parents:
810
diff
changeset
|
1242 coord.opacity=style.opacity; |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
808
diff
changeset
|
1243 } |
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
|
1244 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
|
1245 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
|
1246 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
|
1247 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
|
1248 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
|
1249 id = attr.value(); |
624 | 1250 } |
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
|
1251 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
|
1252 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
|
1253 } 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
|
1254 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
|
1255 } 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
|
1256 this.parseText(accu,coord, id, nodes[k]); |
1435
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
1257 } else if (c == "flowRoot") { |
b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
wycc
parents:
1425
diff
changeset
|
1258 this.parseFlowRoot(accu, coord, id, 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
|
1259 } 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
|
1260 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
|
1261 } 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
|
1262 this.parseImage(accu_matrix,coord, id, nodes[k]); |
1378 | 1263 } else if (c == "use") { |
1264 this.parseUse(accu_matrix,coord, id, 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
|
1265 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
1266 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
1267 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
|
1268 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
|
1269 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
|
1270 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
|
1271 |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
1272 this._set_bbox(n, coord); |
1378 | 1273 // Set the group map only it is not defined before. The group might be |
1274 // redefined by the svg:use tag | |
1385
2ebb07ee455e
Fix the issue that we put the wrong entry for the groupMap for svg:g element.
wycc
parents:
1384
diff
changeset
|
1275 if (this._groupMap[group_id]==undefined) |
2ebb07ee455e
Fix the issue that we put the wrong entry for the groupMap for svg:g element.
wycc
parents:
1384
diff
changeset
|
1276 this._groupMap[group_id] = n; |
1378 | 1277 |
1278 make_mbnames(this.mb_rt, n, coord); | |
1279 return coord; | |
1280 }; | |
1281 | |
1282 loadSVG.prototype.parseUse=function(accu_matrix,root, use_id, n) { | |
1283 var k; | |
1284 var nodes; | |
1398
6fa4a53c3fca
Use clone_from_subtree to generate content for the svg:use.
wycc
parents:
1395
diff
changeset
|
1285 var coord; |
1378 | 1286 // Parse the transform and style here |
1287 var trans = n.attr('transform'); | |
1288 var accu=[1,0,0,0,1,0]; | |
1289 var style; | |
1398
6fa4a53c3fca
Use clone_from_subtree to generate content for the svg:use.
wycc
parents:
1395
diff
changeset
|
1290 var attr = n.attr('duplicate-src'); |
6fa4a53c3fca
Use clone_from_subtree to generate content for the svg:use.
wycc
parents:
1395
diff
changeset
|
1291 if (attr) { |
6fa4a53c3fca
Use clone_from_subtree to generate content for the svg:use.
wycc
parents:
1395
diff
changeset
|
1292 var src = this.mb_rt.mbnames[attr.value()]; |
6fa4a53c3fca
Use clone_from_subtree to generate content for the svg:use.
wycc
parents:
1395
diff
changeset
|
1293 coord = root.clone_from_subtree(src); |
1400
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1294 coord[0] = src[0]; |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1295 coord[1] = src[1]; |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1296 coord[2] = src[2]; |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1297 coord[3] = src[3]; |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1298 coord[4] = src[4]; |
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1299 coord[5] = src[5]; |
1398
6fa4a53c3fca
Use clone_from_subtree to generate content for the svg:use.
wycc
parents:
1395
diff
changeset
|
1300 } else { |
6fa4a53c3fca
Use clone_from_subtree to generate content for the svg:use.
wycc
parents:
1395
diff
changeset
|
1301 coord = this.mb_rt.coord_new(root); |
6fa4a53c3fca
Use clone_from_subtree to generate content for the svg:use.
wycc
parents:
1395
diff
changeset
|
1302 } |
1378 | 1303 n.coord = coord; |
1304 coord.node = n; | |
1305 this._check_duplicate_src(n,coord); | |
1306 | |
1307 coord.center= new Object(); | |
1308 coord.center.x = 10000; | |
1309 coord.center.y = 10000; | |
1310 if (trans!=null) { | |
1311 parseTransform(coord, trans.value()); | |
1312 } else { | |
1400
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1313 generateAffineParameters(coord); |
1378 | 1314 } |
1315 multiply(accu,accu_matrix); | |
1316 multiply(accu,coord); | |
1317 | |
1318 style = {}; | |
1319 parseGroupStyle(style, n); | |
1320 if(style.opacity) { | |
1321 sys.puts("opacity=" + style.opacity); | |
1322 coord.opacity=style.opacity; | |
1323 } | |
1395
a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
wycc
parents:
1392
diff
changeset
|
1324 |
1378 | 1325 if (root.center.x > coord.center.x) |
1326 root.center.x = coord.center.x; | |
1327 if (root.center.y > coord.center.y) | |
1328 root.center.y = coord.center.y; | |
1329 this._set_bbox(n, coord); | |
1376 | 1330 this._groupMap[n.name()] = n; |
1400
18215e577fe0
clone the affine matrix ofwhen we use clone_from_subtree. This function will not copy the affine matrix at all. We need to do it manually.
wycc
parents:
1398
diff
changeset
|
1331 |
719
1b6856fda760
Collect mbnames and mapping to object through mb_rt.mbnames
Thinker K.F. Li <thinker@branda.to>
parents:
718
diff
changeset
|
1332 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
|
1333 }; |
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
|
1334 loadSVG.prototype.parseImage=function(accu,coord,id, n) |
646 | 1335 { |
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
|
1336 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
|
1337 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
|
1338 var trans = n.attr('transform'); |
1378 | 1339 n.coord = tcoord; |
1340 tcoord.node = n; | |
1341 this._check_duplicate_src(n,tcoord); | |
646 | 1342 |
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
|
1343 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
|
1344 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
|
1345 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
|
1346 } 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
|
1347 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
|
1348 } 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
|
1349 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
1350 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
|
1351 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
|
1352 var x,y,nx,ny; |
1384
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1353 tcoord.center= new Object(); |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1354 tcoord.center.x = 10000; |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1355 tcoord.center.y = 10000; |
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
|
1356 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
|
1357 parseTransform(coord, trans.value()); |
1384
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1358 } else { |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1359 tcoord.sx = 1; |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1360 tcoord.sy = 1; |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1361 tcoord.r = 0; |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1362 tcoord.tx = 0; |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1363 tcoord.ty = 0; |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1364 } |
646 | 1365 |
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
|
1366 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
|
1367 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
|
1368 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
|
1369 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
|
1370 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
|
1371 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
|
1372 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
|
1373 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
|
1374 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
|
1375 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
|
1376 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
|
1377 y = parseFloat(y.value()); |
1384
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1378 tcoord.tx += x; |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1379 tcoord.ty += y; |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1380 attr = n.attr('duplicate-src'); |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1381 if (attr) { |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1382 var id = attr.value(); |
1392
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1390
diff
changeset
|
1383 var origcoord = this.mb_rt.mbnames[id]; |
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1390
diff
changeset
|
1384 if (origcoord==null) { |
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1390
diff
changeset
|
1385 sys.puts("Unknown reference "+id); |
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1390
diff
changeset
|
1386 } else { |
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1390
diff
changeset
|
1387 var orign = origcoord.node; |
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1390
diff
changeset
|
1388 var nw = getInteger(orign,'width'); |
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1390
diff
changeset
|
1389 var nh = getInteger(orign,'height'); |
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1390
diff
changeset
|
1390 tcoord.sx *= w/nw; |
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1390
diff
changeset
|
1391 tcoord.sy *= h/nh; |
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1390
diff
changeset
|
1392 } |
1384
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1393 } |
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
|
1394 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
|
1395 ny = tcoord[3]*x+tcoord[4]*y+tcoord[5]; |
1384
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1396 if (tcoord.center.x > nx) |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1397 tcoord.center.x = nx; |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1398 if (tcoord.center.y > ny) |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1399 tcoord.center.y = ny; |
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
|
1400 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
|
1401 var img_data = ldr.load(ref); |
1384
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1402 try { |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1403 var paint = this.mb_rt.paint_image_new(img_data); |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1404 paint.fill(img); |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1405 } catch(e) { |
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1406 sys.puts(e); |
1385
2ebb07ee455e
Fix the issue that we put the wrong entry for the groupMap for svg:g element.
wycc
parents:
1384
diff
changeset
|
1407 sys.puts("--Can not load image "+ref); |
1384
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1408 } |
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
|
1409 tcoord.add_shape(img); |
787
0899dcac441c
Set bounding box attributes for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
785
diff
changeset
|
1410 |
1384
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1411 this._set_bbox(n, tcoord); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
852
diff
changeset
|
1412 |
1384
98ea7146cef3
Fix the parseImage to setup the transform attributes correctly.
wycc
parents:
1381
diff
changeset
|
1413 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
|
1414 }; |
624 | 1415 |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1416 function _parse_stops(n) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1417 var children; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1418 var child; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1419 var style; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1420 var color; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1421 var rgb; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1422 var opacity; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1423 var r, g, b, a; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1424 var offset_atr, offset; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1425 var stops = []; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1426 var i; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1427 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1428 children = n.childNodes(); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1429 for(i = 0; i < children.length; i++) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1430 child = children[i]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1431 if(child.name() == "stop") { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1432 style = parse_style(child); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1433 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1434 color = style["stop-color"]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1435 if(color) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1436 rgb = parse_color(color); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1437 r = rgb[0]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1438 g = rgb[1]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1439 b = rgb[2]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1440 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1441 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1442 opacity = style["stop-opacity"]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1443 if(opacity) |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1444 a = parseFloat(opacity); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1445 else |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1446 a = 1; |
876
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1447 |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1448 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
|
1449 if(offset_attr) |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1450 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
|
1451 else |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1452 offset = 0; |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1453 |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1454 stops.push([offset, r, g, b, a]); |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1455 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1456 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1457 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1458 return stops; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1459 }; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1460 |
750 | 1461 loadSVG.prototype._MB_parseLinearGradient=function(root,n) |
1462 { | |
1463 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
|
1464 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
|
1465 var nodes = n.childNodes(); |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1466 var mtx = [1, 0, 0, 0, 1, 0]; |
750 | 1467 |
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
|
1468 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
|
1469 id = id.value(); |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1470 |
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
|
1471 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
|
1472 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
|
1473 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
|
1474 var y2 = n.attr("y2"); |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1475 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
|
1476 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
|
1477 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
|
1478 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
|
1479 var r,g,b; |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1480 |
876
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1481 if(x1) |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1482 x1 = parseFloat(x1.value()); |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1483 if(x2) |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1484 x2 = parseFloat(x2.value()); |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1485 if(y1) |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1486 y1 = parseFloat(y1.value()); |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1487 if(y2) |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1488 y2 = parseFloat(y2.value()); |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1489 |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1490 stops = _parse_stops(n); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1491 |
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
|
1492 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
|
1493 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
|
1494 href = href.value(); |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1495 var hrefid = href.substring(1); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1496 pstops = this.stop_ref[hrefid]; |
978 | 1497 if (pstops) |
1498 stops = pstops.concat(stops); | |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1499 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1500 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
|
1501 if(typeof x1 == "undefined") |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1502 x1 = hrefgr[0]; |
876
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1503 if(typeof y1 == "undefined") |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1504 y1 = hrefgr[1]; |
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1505 if(typeof x2 == "undefined") |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1506 x2 = hrefgr[2]; |
876
e6936110c48f
Fix bug of parsing linear and radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
875
diff
changeset
|
1507 if(typeof y2 == "undefined") |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1508 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
|
1509 } |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1510 |
881
a17c4e231e54
Transform positions of radient paints.
Thinker K.F. Li <thinker@codemud.net>
parents:
880
diff
changeset
|
1511 if(n.attr("gradientTransform")) { |
a17c4e231e54
Transform positions of radient paints.
Thinker K.F. Li <thinker@codemud.net>
parents:
880
diff
changeset
|
1512 parseTransform(mtx, n.attr("gradientTransform").value()); |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1513 xy = _pnt_transform(x1, y1, mtx); |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1514 x1 = xy[0]; |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1515 y1 = xy[1]; |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1516 xy = _pnt_transform(x2, y2, mtx); |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1517 x2 = xy[0]; |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1518 y2 = xy[1]; |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1519 } |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1520 |
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
|
1521 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
|
1522 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
|
1523 }; |
750 | 1524 |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1525 loadSVG.prototype._MB_parseRadialGradient = function(root,n) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1526 var stops; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1527 var cx, cy; |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1528 var xy; |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1529 var mtx = [1, 0, 0, 0, 1, 0]; |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1530 var id; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1531 var href; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1532 var r; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1533 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1534 id = n.attr("id"); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1535 if(!id) |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1536 throw "Require an id"; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1537 id = id.value(); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1538 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1539 stops = _parse_stops(n); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1540 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1541 cx = n.attr("cx"); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1542 if(!cx) |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1543 throw "Miss cx attribute"; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1544 cy = n.attr("cy"); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1545 if(!cy) |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1546 throw "Miss cy attribute"; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1547 cx = parseFloat(cx.value()); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1548 cy = parseFloat(cy.value()); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1549 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1550 r = n.attr("r"); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1551 if(!r) |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1552 throw "Miss r attribute"; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1553 r = parseFloat(r.value()); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1554 |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1555 href = n.attr("href"); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1556 if(href) { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1557 href = href.value().substring(1); |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1558 stops = this.stop_ref[href]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1559 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1560 |
881
a17c4e231e54
Transform positions of radient paints.
Thinker K.F. Li <thinker@codemud.net>
parents:
880
diff
changeset
|
1561 if(n.attr("gradientTransform")) { |
a17c4e231e54
Transform positions of radient paints.
Thinker K.F. Li <thinker@codemud.net>
parents:
880
diff
changeset
|
1562 parseTransform(mtx, n.attr("gradientTransform").value()); |
878
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1563 xy = _pnt_transform(cx, cy, mtx); |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1564 cx = xy[0]; |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1565 cy = xy[1]; |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1566 } |
818e5bed913d
Handle stroke-width and gradientTransform
Thinker K.F. Li <thinker@codemud.net>
parents:
877
diff
changeset
|
1567 |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1568 this.radials[id] = [cx, cy, r]; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1569 this.stop_ref[id] = stops; |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1570 } |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1571 |
978 | 1572 loadSVG.prototype.parseScenes=function(coord,node) { |
1573 var nodes = node.childNodes(); | |
1574 | |
1575 for(k in nodes) { | |
1576 var name = nodes[k].name(); | |
1577 if (name == 'scene') { | |
1578 var node = nodes[k]; | |
1579 | |
1580 scene = new Object(); | |
1581 scene.start = parseInt(node.attr('start').value()); | |
1582 try { | |
1583 scene.end = parseInt(node.attr('end').value()); | |
1584 } catch(e) { | |
1585 scene.end = scene.start; | |
1586 } | |
1587 scene.ref = node.attr('ref').value(); | |
1376 | 1588 try { |
1589 scene.type = node.attr('type').value(); | |
1590 } catch(e) { | |
1591 scene.type='normal'; | |
1592 } | |
978 | 1593 |
1594 try { | |
1595 this.scenenames[node.attr('name').value()] = scene.start; | |
1596 } catch(e) { | |
1597 } | |
1598 this.scenes.push(scene); | |
1599 } | |
1600 } | |
1601 } | |
1602 | |
1376 | 1603 loadSVG.prototype.parseComponents=function(coord,node) { |
1604 | |
1605 var nodes = node.childNodes(); | |
1606 | |
1607 for(k in nodes) { | |
1608 var name = nodes[k].name(); | |
1609 if (name == 'component') { | |
1610 // Parse the component here | |
1611 } | |
1612 } | |
1613 } | |
1614 | |
978 | 1615 loadSVG.prototype.parseMetadata=function(coord,node) { |
1616 var nodes = node.childNodes(); | |
1617 | |
1618 for(k in nodes) { | |
1619 var name = nodes[k].name(); | |
1620 if (name == 'scenes') { | |
1621 this.scenes=[]; | |
1622 this.scenenames={}; | |
1623 this.parseScenes(coord,nodes[k]); | |
1376 | 1624 } else if (name == "components") { |
1625 this.parseComponents(coord,nodes[k]); | |
978 | 1626 } |
1627 } | |
1628 } | |
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
|
1629 loadSVG.prototype.parseDefs=function(root,n) |
624 | 1630 { |
1631 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
|
1632 var nodes = n.childNodes(); |
624 | 1633 |
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
|
1634 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
|
1635 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
|
1636 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
|
1637 this._MB_parseLinearGradient(root,nodes[k]); |
875
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1638 } else if(name == "radialGradient") { |
5d7c3c681851
Parse radial gradient
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
1639 this._MB_parseRadialGradient(root,nodes[k]); |
624 | 1640 } |
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
|
1641 } |
a47431293043
Re-indent ts=8 to make editor and cat seeing the same thing
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
1642 }; |
624 | 1643 |
1644 | |
1390 | 1645 exports.loadSVG = loadSVG; |