root / trunk / web / dojo / dojox / gfx / vml_attach.js @ 12
History | View | Annotate | Download (6.96 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
dojo.require("dojox.gfx.vml");
|
9 |
dojo.experimental("dojox.gfx.vml_attach");
|
10 |
(function(){
|
11 |
dojox.gfx.attachNode=function(_1){ |
12 |
if(!_1){
|
13 |
return null; |
14 |
} |
15 |
var s=null; |
16 |
switch(_1.tagName.toLowerCase()){
|
17 |
case dojox.gfx.Rect.nodeType:
|
18 |
s=new dojox.gfx.Rect(_1);
|
19 |
_2(s); |
20 |
break;
|
21 |
case dojox.gfx.Ellipse.nodeType:
|
22 |
if(_1.style.width==_1.style.height){
|
23 |
s=new dojox.gfx.Circle(_1);
|
24 |
_3(s); |
25 |
}else{
|
26 |
s=new dojox.gfx.Ellipse(_1);
|
27 |
_4(s); |
28 |
} |
29 |
break;
|
30 |
case dojox.gfx.Path.nodeType:
|
31 |
switch(_1.getAttribute("dojoGfxType")){ |
32 |
case "line": |
33 |
s=new dojox.gfx.Line(_1);
|
34 |
_5(s); |
35 |
break;
|
36 |
case "polyline": |
37 |
s=new dojox.gfx.Polyline(_1);
|
38 |
_6(s); |
39 |
break;
|
40 |
case "path": |
41 |
s=new dojox.gfx.Path(_1);
|
42 |
_7(s); |
43 |
break;
|
44 |
case "text": |
45 |
s=new dojox.gfx.Text(_1);
|
46 |
_8(s); |
47 |
_9(s); |
48 |
_a(s); |
49 |
break;
|
50 |
case "textpath": |
51 |
s=new dojox.gfx.TextPath(_1);
|
52 |
_7(s); |
53 |
_8(s); |
54 |
_9(s); |
55 |
break;
|
56 |
} |
57 |
break;
|
58 |
case dojox.gfx.Image.nodeType:
|
59 |
switch(_1.getAttribute("dojoGfxType")){ |
60 |
case "image": |
61 |
s=new dojox.gfx.Image(_1);
|
62 |
_b(s); |
63 |
_c(s); |
64 |
break;
|
65 |
} |
66 |
break;
|
67 |
default:
|
68 |
return null; |
69 |
} |
70 |
if(!(s instanceof dojox.gfx.Image)){ |
71 |
_d(s); |
72 |
_e(s); |
73 |
if(!(s instanceof dojox.gfx.Text)){ |
74 |
_f(s); |
75 |
} |
76 |
} |
77 |
return s;
|
78 |
}; |
79 |
dojox.gfx.attachSurface=function(_10){ |
80 |
var s=new dojox.gfx.Surface(); |
81 |
s.clipNode=_10; |
82 |
var r=s.rawNode=_10.firstChild;
|
83 |
var b=r.firstChild;
|
84 |
if(!b||b.tagName!="rect"){ |
85 |
return null; |
86 |
} |
87 |
s.bgNode=r; |
88 |
return s;
|
89 |
}; |
90 |
var _d=function(_11){ |
91 |
var _12=null,r=_11.rawNode,fo=r.fill; |
92 |
if(fo.on&&fo.type=="gradient"){ |
93 |
var _12=dojo.clone(dojox.gfx.defaultLinearGradient),rad=dojox.gfx.matrix._degToRad(fo.angle);
|
94 |
_12.x2=Math.cos(rad); |
95 |
_12.y2=Math.sin(rad); |
96 |
_12.colors=[]; |
97 |
var _13=fo.colors.value.split(";"); |
98 |
for(var i=0;i<_13.length;++i){ |
99 |
var t=_13[i].match(/\S+/g); |
100 |
if(!t||t.length!=2){ |
101 |
continue;
|
102 |
} |
103 |
_12.colors.push({offset:dojox.gfx.vml._parseFloat(t[0]),color:new dojo.Color(t[1])}); |
104 |
} |
105 |
}else{
|
106 |
if(fo.on&&fo.type=="gradientradial"){ |
107 |
var _12=dojo.clone(dojox.gfx.defaultRadialGradient),w=parseFloat(r.style.width),h=parseFloat(r.style.height);
|
108 |
_12.cx=isNaN(w)?0:fo.focusposition.x*w;
|
109 |
_12.cy=isNaN(h)?0:fo.focusposition.y*h;
|
110 |
_12.r=isNaN(w)?1:w/2; |
111 |
_12.colors=[]; |
112 |
var _13=fo.colors.value.split(";"); |
113 |
for(var i=_13.length-1;i>=0;--i){ |
114 |
var t=_13[i].match(/\S+/g); |
115 |
if(!t||t.length!=2){ |
116 |
continue;
|
117 |
} |
118 |
_12.colors.push({offset:dojox.gfx.vml._parseFloat(t[0]),color:new dojo.Color(t[1])}); |
119 |
} |
120 |
}else{
|
121 |
if(fo.on&&fo.type=="tile"){ |
122 |
var _12=dojo.clone(dojox.gfx.defaultPattern);
|
123 |
_12.width=dojox.gfx.pt2px(fo.size.x); |
124 |
_12.height=dojox.gfx.pt2px(fo.size.y); |
125 |
_12.x=fo.origin.x*_12.width; |
126 |
_12.y=fo.origin.y*_12.height; |
127 |
_12.src=fo.src; |
128 |
}else{
|
129 |
if(fo.on&&r.fillcolor){
|
130 |
_12=new dojo.Color(r.fillcolor+""); |
131 |
_12.a=fo.opacity; |
132 |
} |
133 |
} |
134 |
} |
135 |
} |
136 |
_11.fillStyle=_12; |
137 |
}; |
138 |
var _e=function(_14){ |
139 |
var r=_14.rawNode;
|
140 |
if(!r.stroked){
|
141 |
_14.strokeStyle=null;
|
142 |
return;
|
143 |
} |
144 |
var _15=_14.strokeStyle=dojo.clone(dojox.gfx.defaultStroke),rs=r.stroke;
|
145 |
_15.color=new dojo.Color(r.strokecolor.value);
|
146 |
_15.width=dojox.gfx.normalizedLength(r.strokeweight+"");
|
147 |
_15.color.a=rs.opacity; |
148 |
_15.cap=this._translate(this._capMapReversed,rs.endcap); |
149 |
_15.join=rs.joinstyle=="miter"?rs.miterlimit:rs.joinstyle;
|
150 |
_15.style=rs.dashstyle; |
151 |
}; |
152 |
var _f=function(_16){ |
153 |
var s=_16.rawNode.skew,sm=s.matrix,so=s.offset;
|
154 |
_16.matrix=dojox.gfx.matrix.normalize({xx:sm.xtox,xy:sm.ytox,yx:sm.xtoy,yy:sm.ytoy,dx:dojox.gfx.pt2px(so.x),dy:dojox.gfx.pt2px(so.y)}); |
155 |
}; |
156 |
var _17=function(_18){ |
157 |
_18.bgNode=_18.rawNode.firstChild; |
158 |
}; |
159 |
var _2=function(_19){ |
160 |
var r=_19.rawNode,_1a=r.outerHTML.match(/arcsize = \"(\d*\.?\d+[%f]?)\"/)[1],_1b=r.style,_1c=parseFloat(_1b.width),_1d=parseFloat(_1b.height); |
161 |
_1a=(_1a.indexOf("%")>=0)?parseFloat(_1a)/100:dojox.gfx.vml._parseFloat(_1a); |
162 |
_19.shape=dojox.gfx.makeParameters(dojox.gfx.defaultRect,{x:parseInt(_1b.left),y:parseInt(_1b.top),width:_1c,height:_1d,r:Math.min(_1c,_1d)*_1a}); |
163 |
}; |
164 |
var _4=function(_1e){ |
165 |
var _1f=_1e.rawNode.style,rx=parseInt(_1f.width)/2,ry=parseInt(_1f.height)/2; |
166 |
_1e.shape=dojox.gfx.makeParameters(dojox.gfx.defaultEllipse,{cx:parseInt(_1f.left)+rx,cy:parseInt(_1f.top)+ry,rx:rx,ry:ry}); |
167 |
}; |
168 |
var _3=function(_20){ |
169 |
var _21=_20.rawNode.style,r=parseInt(_21.width)/2; |
170 |
_20.shape=dojox.gfx.makeParameters(dojox.gfx.defaultCircle,{cx:parseInt(_21.left)+r,cy:parseInt(_21.top)+r,r:r}); |
171 |
}; |
172 |
var _5=function(_22){ |
173 |
var _23=_22.shape=dojo.clone(dojox.gfx.defaultLine),p=_22.rawNode.path.v.match(dojox.gfx.pathVmlRegExp);
|
174 |
do{
|
175 |
if(p.length<7||p[0]!="m"||p[3]!="l"||p[6]!="e"){ |
176 |
break;
|
177 |
} |
178 |
_23.x1=parseInt(p[1]);
|
179 |
_23.y1=parseInt(p[2]);
|
180 |
_23.x2=parseInt(p[4]);
|
181 |
_23.y2=parseInt(p[5]);
|
182 |
}while(false); |
183 |
}; |
184 |
var _6=function(_24){ |
185 |
var _25=_24.shape=dojo.clone(dojox.gfx.defaultPolyline),p=_24.rawNode.path.v.match(dojox.gfx.pathVmlRegExp);
|
186 |
do{
|
187 |
if(p.length<3||p[0]!="m"){ |
188 |
break;
|
189 |
} |
190 |
var x=parseInt(p[0]),y=parseInt(p[1]); |
191 |
if(isNaN(x)||isNaN(y)){
|
192 |
break;
|
193 |
} |
194 |
_25.points.push({x:x,y:y}); |
195 |
if(p.length<6||p[3]!="l"){ |
196 |
break;
|
197 |
} |
198 |
for(var i=4;i<p.length;i+=2){ |
199 |
x=parseInt(p[i]); |
200 |
y=parseInt(p[i+1]);
|
201 |
if(isNaN(x)||isNaN(y)){
|
202 |
break;
|
203 |
} |
204 |
_25.points.push({x:x,y:y}); |
205 |
} |
206 |
}while(false); |
207 |
}; |
208 |
var _b=function(_26){ |
209 |
_26.shape=dojo.clone(dojox.gfx.defaultImage); |
210 |
_26.shape.src=_26.rawNode.firstChild.src; |
211 |
}; |
212 |
var _c=function(_27){ |
213 |
var m=_27.rawNode.filters["DXImageTransform.Microsoft.Matrix"]; |
214 |
_27.matrix=dojox.gfx.matrix.normalize({xx:m.M11,xy:m.M12,yx:m.M21,yy:m.M22,dx:m.Dx,dy:m.Dy}); |
215 |
}; |
216 |
var _8=function(_28){ |
217 |
var _29=_28.shape=dojo.clone(dojox.gfx.defaultText),r=_28.rawNode,p=r.path.v.match(dojox.gfx.pathVmlRegExp);
|
218 |
do{
|
219 |
if(!p||p.length!=7){ |
220 |
break;
|
221 |
} |
222 |
var c=r.childNodes,i=0; |
223 |
for(;i<c.length&&c[i].tagName!="textpath";++i){ |
224 |
} |
225 |
if(i>=c.length){
|
226 |
break;
|
227 |
} |
228 |
var s=c[i].style;
|
229 |
_29.text=c[i].string; |
230 |
switch(s["v-text-align"]){ |
231 |
case "left": |
232 |
_29.x=parseInt(p[1]);
|
233 |
_29.align="start";
|
234 |
break;
|
235 |
case "center": |
236 |
_29.x=(parseInt(p[1])+parseInt(p[4]))/2; |
237 |
_29.align="middle";
|
238 |
break;
|
239 |
case "right": |
240 |
_29.x=parseInt(p[4]);
|
241 |
_29.align="end";
|
242 |
break;
|
243 |
} |
244 |
_29.y=parseInt(p[2]);
|
245 |
_29.decoration=s["text-decoration"];
|
246 |
_29.rotated=s["v-rotate-letters"].toLowerCase() in dojox.gfx.vml._bool; |
247 |
_29.kerning=s["v-text-kern"].toLowerCase() in dojox.gfx.vml._bool; |
248 |
return;
|
249 |
}while(false); |
250 |
_28.shape=null;
|
251 |
}; |
252 |
var _9=function(_2a){ |
253 |
var _2b=_2a.fontStyle=dojo.clone(dojox.gfx.defaultFont),c=_2a.rawNode.childNodes,i=0; |
254 |
for(;i<c.length&&c[i].tagName=="textpath";++i){ |
255 |
} |
256 |
if(i>=c.length){
|
257 |
_2a.fontStyle=null;
|
258 |
return;
|
259 |
} |
260 |
var s=c[i].style;
|
261 |
_2b.style=s.fontstyle; |
262 |
_2b.variant=s.fontvariant; |
263 |
_2b.weight=s.fontweight; |
264 |
_2b.size=s.fontsize; |
265 |
_2b.family=s.fontfamily; |
266 |
}; |
267 |
var _a=function(_2c){ |
268 |
_f(_2c); |
269 |
var _2d=_2c.matrix,fs=_2c.fontStyle;
|
270 |
if(_2d&&fs){
|
271 |
_2c.matrix=dojox.gfx.matrix.multiply(_2d,{dy:dojox.gfx.normalizedLength(fs.size)*0.35}); |
272 |
} |
273 |
}; |
274 |
var _7=function(_2e){ |
275 |
var _2f=_2e.shape=dojo.clone(dojox.gfx.defaultPath),p=_2e.rawNode.path.v.match(dojox.gfx.pathVmlRegExp),t=[],_30=false,map=dojox.gfx.Path._pathVmlToSvgMap; |
276 |
for(var i=0;i<p.length;++p){ |
277 |
var s=p[i];
|
278 |
if(s in map){ |
279 |
_30=false;
|
280 |
t.push(map[s]); |
281 |
}else{
|
282 |
if(!_30){
|
283 |
var n=parseInt(s);
|
284 |
if(isNaN(n)){
|
285 |
_30=true;
|
286 |
}else{
|
287 |
t.push(n); |
288 |
} |
289 |
} |
290 |
} |
291 |
} |
292 |
var l=t.length;
|
293 |
if(l>=4&&t[l-1]==""&&t[l-2]==0&&t[l-3]==0&&t[l-4]=="l"){ |
294 |
t.splice(l-4,4); |
295 |
} |
296 |
if(l){
|
297 |
_2f.path=t.join(" ");
|
298 |
} |
299 |
}; |
300 |
})(); |