root / trunk / web / dojo / dojox / gfx / _base.js @ 12
History | View | Annotate | Download (5.46 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 |
if(!dojo._hasResource["dojox.gfx._base"]){ |
9 |
dojo._hasResource["dojox.gfx._base"]=true; |
10 |
dojo.provide("dojox.gfx._base");
|
11 |
(function(){
|
12 |
var g=dojox.gfx,b=g._base;
|
13 |
g._hasClass=function(_1,_2){ |
14 |
var _3=_1.getAttribute("className"); |
15 |
return _3&&(" "+_3+" ").indexOf(" "+_2+" ")>=0; |
16 |
}; |
17 |
g._addClass=function(_4,_5){ |
18 |
var _6=_4.getAttribute("className")||""; |
19 |
if(!_6||(" "+_6+" ").indexOf(" "+_5+" ")<0){ |
20 |
_4.setAttribute("className",_6+(_6?" ":"")+_5); |
21 |
} |
22 |
}; |
23 |
g._removeClass=function(_7,_8){ |
24 |
var _9=_7.getAttribute("className"); |
25 |
if(_9){
|
26 |
_7.setAttribute("className",_9.replace(new RegExp("(^|\\s+)"+_8+"(\\s+|$)"),"$1$2")); |
27 |
} |
28 |
}; |
29 |
b._getFontMeasurements=function(){ |
30 |
var _a={"1em":0,"1ex":0,"100%":0,"12pt":0,"16px":0,"xx-small":0,"x-small":0,"small":0,"medium":0,"large":0,"x-large":0,"xx-large":0}; |
31 |
if(dojo.isIE){
|
32 |
dojo.doc.documentElement.style.fontSize="100%";
|
33 |
} |
34 |
var _b=dojo.doc.createElement("div"); |
35 |
var s=_b.style;
|
36 |
s.position="absolute";
|
37 |
s.left="-100px";
|
38 |
s.top="0px";
|
39 |
s.width="30px";
|
40 |
s.height="1000em";
|
41 |
s.borderWidth="0px";
|
42 |
s.margin="0px";
|
43 |
s.padding="0px";
|
44 |
s.outline="none";
|
45 |
s.lineHeight="1";
|
46 |
s.overflow="hidden";
|
47 |
dojo.body().appendChild(_b); |
48 |
for(var p in _a){ |
49 |
_b.style.fontSize=p; |
50 |
_a[p]=Math.round(_b.offsetHeight*12/16)*16/12/1000; |
51 |
} |
52 |
dojo.body().removeChild(_b); |
53 |
_b=null;
|
54 |
return _a;
|
55 |
}; |
56 |
var _c=null; |
57 |
b._getCachedFontMeasurements=function(_d){ |
58 |
if(_d||!_c){
|
59 |
_c=b._getFontMeasurements(); |
60 |
} |
61 |
return _c;
|
62 |
}; |
63 |
var _e=null,_f={}; |
64 |
b._getTextBox=function(_10,_11,_12){ |
65 |
var m,s,al=arguments.length; |
66 |
if(!_e){
|
67 |
m=_e=dojo.doc.createElement("div");
|
68 |
s=m.style; |
69 |
s.position="absolute";
|
70 |
s.left="-10000px";
|
71 |
s.top="0";
|
72 |
dojo.body().appendChild(m); |
73 |
}else{
|
74 |
m=_e; |
75 |
s=m.style; |
76 |
} |
77 |
m.className="";
|
78 |
s.borderWidth="0";
|
79 |
s.margin="0";
|
80 |
s.padding="0";
|
81 |
s.outline="0";
|
82 |
if(al>1&&_11){ |
83 |
for(var i in _11){ |
84 |
if(i in _f){ |
85 |
continue;
|
86 |
} |
87 |
s[i]=_11[i]; |
88 |
} |
89 |
} |
90 |
if(al>2&&_12){ |
91 |
m.className=_12; |
92 |
} |
93 |
m.innerHTML=_10; |
94 |
if(m["getBoundingClientRect"]){ |
95 |
var bcr=m.getBoundingClientRect();
|
96 |
return {l:bcr.left,t:bcr.top,w:bcr.width||(bcr.right-bcr.left),h:bcr.height||(bcr.bottom-bcr.top)}; |
97 |
}else{
|
98 |
return dojo.marginBox(m);
|
99 |
} |
100 |
}; |
101 |
var _13=0; |
102 |
b._getUniqueId=function(){ |
103 |
var id;
|
104 |
do{
|
105 |
id=dojo._scopeName+"Unique"+(++_13);
|
106 |
}while(dojo.byId(id));
|
107 |
return id;
|
108 |
}; |
109 |
})(); |
110 |
dojo.mixin(dojox.gfx,{defaultPath:{type:"path",path:""},defaultPolyline:{type:"polyline",points:[]},defaultRect:{type:"rect",x:0,y:0,width:100,height:100,r:0},defaultEllipse:{type:"ellipse",cx:0,cy:0,rx:200,ry:100},defaultCircle:{type:"circle",cx:0,cy:0,r:100},defaultLine:{type:"line",x1:0,y1:0,x2:100,y2:100},defaultImage:{type:"image",x:0,y:0,width:0,height:0,src:""},defaultText:{type:"text",x:0,y:0,text:"",align:"start",decoration:"none",rotated:false,kerning:true},defaultTextPath:{type:"textpath",text:"",align:"start",decoration:"none",rotated:false,kerning:true},defaultStroke:{type:"stroke",color:"black",style:"solid",width:1,cap:"butt",join:4},defaultLinearGradient:{type:"linear",x1:0,y1:0,x2:100,y2:100,colors:[{offset:0,color:"black"},{offset:1,color:"white"}]},defaultRadialGradient:{type:"radial",cx:0,cy:0,r:100,colors:[{offset:0,color:"black"},{offset:1,color:"white"}]},defaultPattern:{type:"pattern",x:0,y:0,width:0,height:0,src:""},defaultFont:{type:"font",style:"normal",variant:"normal",weight:"normal",size:"10pt",family:"serif"},getDefault:(function(){ |
111 |
var _14={};
|
112 |
return function(_15){ |
113 |
var t=_14[_15];
|
114 |
if(t){
|
115 |
return new t(); |
116 |
} |
117 |
t=_14[_15]=new Function;
|
118 |
t.prototype=dojox.gfx["default"+_15];
|
119 |
return new t(); |
120 |
}; |
121 |
})(),normalizeColor:function(_16){ |
122 |
return (_16 instanceof dojo.Color)?_16:new dojo.Color(_16); |
123 |
},normalizeParameters:function(_17,_18){ |
124 |
if(_18){
|
125 |
var _19={};
|
126 |
for(var x in _17){ |
127 |
if(x in _18&&!(x in _19)){ |
128 |
_17[x]=_18[x]; |
129 |
} |
130 |
} |
131 |
} |
132 |
return _17;
|
133 |
},makeParameters:function(_1a,_1b){ |
134 |
if(!_1b){
|
135 |
return dojo.delegate(_1a);
|
136 |
} |
137 |
var _1c={};
|
138 |
for(var i in _1a){ |
139 |
if(!(i in _1c)){ |
140 |
_1c[i]=dojo.clone((i in _1b)?_1b[i]:_1a[i]);
|
141 |
} |
142 |
} |
143 |
return _1c;
|
144 |
},formatNumber:function(x,_1d){ |
145 |
var val=x.toString();
|
146 |
if(val.indexOf("e")>=0){ |
147 |
val=x.toFixed(4);
|
148 |
}else{
|
149 |
var _1e=val.indexOf("."); |
150 |
if(_1e>=0&&val.length-_1e>5){ |
151 |
val=x.toFixed(4);
|
152 |
} |
153 |
} |
154 |
if(x<0){ |
155 |
return val;
|
156 |
} |
157 |
return _1d?" "+val:val; |
158 |
},makeFontString:function(_1f){ |
159 |
return _1f.style+" "+_1f.variant+" "+_1f.weight+" "+_1f.size+" "+_1f.family; |
160 |
},splitFontString:function(str){ |
161 |
var _20=dojox.gfx.getDefault("Font"); |
162 |
var t=str.split(/\s+/); |
163 |
do{
|
164 |
if(t.length<5){ |
165 |
break;
|
166 |
} |
167 |
_20.style=t[0];
|
168 |
_20.variant=t[1];
|
169 |
_20.weight=t[2];
|
170 |
var i=t[3].indexOf("/"); |
171 |
_20.size=i<0?t[3]:t[3].substring(0,i); |
172 |
var j=4; |
173 |
if(i<0){ |
174 |
if(t[4]=="/"){ |
175 |
j=6;
|
176 |
}else{
|
177 |
if(t[4].charAt(0)=="/"){ |
178 |
j=5;
|
179 |
} |
180 |
} |
181 |
} |
182 |
if(j<t.length){
|
183 |
_20.family=t.slice(j).join(" ");
|
184 |
} |
185 |
}while(false); |
186 |
return _20;
|
187 |
},cm_in_pt:72/2.54,mm_in_pt:7.2/2.54,px_in_pt:function(){ |
188 |
return dojox.gfx._base._getCachedFontMeasurements()["12pt"]/12; |
189 |
},pt2px:function(len){ |
190 |
return len*dojox.gfx.px_in_pt();
|
191 |
},px2pt:function(len){ |
192 |
return len/dojox.gfx.px_in_pt();
|
193 |
},normalizedLength:function(len){ |
194 |
if(len.length==0){ |
195 |
return 0; |
196 |
} |
197 |
if(len.length>2){ |
198 |
var _21=dojox.gfx.px_in_pt();
|
199 |
var val=parseFloat(len);
|
200 |
switch(len.slice(-2)){ |
201 |
case "px": |
202 |
return val;
|
203 |
case "pt": |
204 |
return val*_21;
|
205 |
case "in": |
206 |
return val*72*_21; |
207 |
case "pc": |
208 |
return val*12*_21; |
209 |
case "mm": |
210 |
return val*dojox.gfx.mm_in_pt*_21;
|
211 |
case "cm": |
212 |
return val*dojox.gfx.cm_in_pt*_21;
|
213 |
} |
214 |
} |
215 |
return parseFloat(len);
|
216 |
},pathVmlRegExp:/([A-Za-z]+)|(\d+(\.\d+)?)|(\.\d+)|(-\d+(\.\d+)?)|(-\.\d+)/g,pathSvgRegExp:/([A-Za-z])|(\d+(\.\d+)?)|(\.\d+)|(-\d+(\.\d+)?)|(-\.\d+)/g,equalSources:function(a,b){ |
217 |
return a&&b&&a==b;
|
218 |
}}); |
219 |
} |