root / trunk / web / dojo / dojox / gfx / svg_attach.js @ 12
History | View | Annotate | Download (4.77 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
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.svg");
|
||
9 | dojo.experimental("dojox.gfx.svg_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 | s=new dojox.gfx.Ellipse(_1);
|
||
23 | _3(s,dojox.gfx.defaultEllipse); |
||
24 | break;
|
||
25 | case dojox.gfx.Polyline.nodeType:
|
||
26 | s=new dojox.gfx.Polyline(_1);
|
||
27 | _3(s,dojox.gfx.defaultPolyline); |
||
28 | break;
|
||
29 | case dojox.gfx.Path.nodeType:
|
||
30 | s=new dojox.gfx.Path(_1);
|
||
31 | _3(s,dojox.gfx.defaultPath); |
||
32 | break;
|
||
33 | case dojox.gfx.Circle.nodeType:
|
||
34 | s=new dojox.gfx.Circle(_1);
|
||
35 | _3(s,dojox.gfx.defaultCircle); |
||
36 | break;
|
||
37 | case dojox.gfx.Line.nodeType:
|
||
38 | s=new dojox.gfx.Line(_1);
|
||
39 | _3(s,dojox.gfx.defaultLine); |
||
40 | break;
|
||
41 | case dojox.gfx.Image.nodeType:
|
||
42 | s=new dojox.gfx.Image(_1);
|
||
43 | _3(s,dojox.gfx.defaultImage); |
||
44 | break;
|
||
45 | case dojox.gfx.Text.nodeType:
|
||
46 | var t=_1.getElementsByTagName("textPath"); |
||
47 | if(t&&t.length){
|
||
48 | s=new dojox.gfx.TextPath(_1);
|
||
49 | _3(s,dojox.gfx.defaultPath); |
||
50 | _4(s); |
||
51 | }else{
|
||
52 | s=new dojox.gfx.Text(_1);
|
||
53 | _5(s); |
||
54 | } |
||
55 | _6(s); |
||
56 | break;
|
||
57 | default:
|
||
58 | return null; |
||
59 | } |
||
60 | if(!(s instanceof dojox.gfx.Image)){ |
||
61 | _7(s); |
||
62 | _8(s); |
||
63 | } |
||
64 | _9(s); |
||
65 | return s;
|
||
66 | }; |
||
67 | dojox.gfx.attachSurface=function(_a){ |
||
68 | var s=new dojox.gfx.Surface(); |
||
69 | s.rawNode=_a; |
||
70 | var _b=_a.getElementsByTagName("defs"); |
||
71 | if(_b.length==0){ |
||
72 | return null; |
||
73 | } |
||
74 | s.defNode=_b[0];
|
||
75 | return s;
|
||
76 | }; |
||
77 | var _7=function(_c){ |
||
78 | var _d=_c.rawNode.getAttribute("fill"); |
||
79 | if(_d=="none"){ |
||
80 | _c.fillStyle=null;
|
||
81 | return;
|
||
82 | } |
||
83 | var _e=null,_f=dojox.gfx.svg.getRef(_d); |
||
84 | if(_f){
|
||
85 | switch(_f.tagName.toLowerCase()){
|
||
86 | case "lineargradient": |
||
87 | _e=_10(dojox.gfx.defaultLinearGradient,_f); |
||
88 | dojo.forEach(["x1","y1","x2","y2"],function(x){ |
||
89 | _e[x]=_f.getAttribute(x); |
||
90 | }); |
||
91 | break;
|
||
92 | case "radialgradient": |
||
93 | _e=_10(dojox.gfx.defaultRadialGradient,_f); |
||
94 | dojo.forEach(["cx","cy","r"],function(x){ |
||
95 | _e[x]=_f.getAttribute(x); |
||
96 | }); |
||
97 | _e.cx=_f.getAttribute("cx");
|
||
98 | _e.cy=_f.getAttribute("cy");
|
||
99 | _e.r=_f.getAttribute("r");
|
||
100 | break;
|
||
101 | case "pattern": |
||
102 | _e=dojo.lang.shallowCopy(dojox.gfx.defaultPattern,true);
|
||
103 | dojo.forEach(["x","y","width","height"],function(x){ |
||
104 | _e[x]=_f.getAttribute(x); |
||
105 | }); |
||
106 | _e.src=_f.firstChild.getAttributeNS(dojox.gfx.svg.xmlns.xlink,"href");
|
||
107 | break;
|
||
108 | } |
||
109 | }else{
|
||
110 | _e=new dojo.Color(_d);
|
||
111 | var _11=_c.rawNode.getAttribute("fill-opacity"); |
||
112 | if(_11!=null){ |
||
113 | _e.a=_11; |
||
114 | } |
||
115 | } |
||
116 | _c.fillStyle=_e; |
||
117 | }; |
||
118 | var _10=function(_12,_13){ |
||
119 | var _14=dojo.clone(_12);
|
||
120 | _14.colors=[]; |
||
121 | for(var i=0;i<_13.childNodes.length;++i){ |
||
122 | _14.colors.push({offset:_13.childNodes[i].getAttribute("offset"),color:new dojo.Color(_13.childNodes[i].getAttribute("stop-color"))}); |
||
123 | } |
||
124 | return _14;
|
||
125 | }; |
||
126 | var _8=function(_15){ |
||
127 | var _16=_15.rawNode,_17=_16.getAttribute("stroke"); |
||
128 | if(_17==null||_17=="none"){ |
||
129 | _15.strokeStyle=null;
|
||
130 | return;
|
||
131 | } |
||
132 | var _18=_15.strokeStyle=dojo.clone(dojox.gfx.defaultStroke);
|
||
133 | var _19=new dojo.Color(_17); |
||
134 | if(_19){
|
||
135 | _18.color=_19; |
||
136 | _18.color.a=_16.getAttribute("stroke-opacity");
|
||
137 | _18.width=_16.getAttribute("stroke-width");
|
||
138 | _18.cap=_16.getAttribute("stroke-linecap");
|
||
139 | _18.join=_16.getAttribute("stroke-linejoin");
|
||
140 | if(_18.join=="miter"){ |
||
141 | _18.join=_16.getAttribute("stroke-miterlimit");
|
||
142 | } |
||
143 | _18.style=_16.getAttribute("dojoGfxStrokeStyle");
|
||
144 | } |
||
145 | }; |
||
146 | var _9=function(_1a){ |
||
147 | var _1b=_1a.rawNode.getAttribute("transform"); |
||
148 | if(_1b.match(/^matrix\(.+\)$/)){ |
||
149 | var t=_1b.slice(7,-1).split(","); |
||
150 | _1a.matrix=dojox.gfx.matrix.normalize({xx:parseFloat(t[0]),xy:parseFloat(t[2]),yx:parseFloat(t[1]),yy:parseFloat(t[3]),dx:parseFloat(t[4]),dy:parseFloat(t[5])}); |
||
151 | }else{
|
||
152 | _1a.matrix=null;
|
||
153 | } |
||
154 | }; |
||
155 | var _6=function(_1c){ |
||
156 | var _1d=_1c.fontStyle=dojo.clone(dojox.gfx.defaultFont),r=_1c.rawNode;
|
||
157 | _1d.style=r.getAttribute("font-style");
|
||
158 | _1d.variant=r.getAttribute("font-variant");
|
||
159 | _1d.weight=r.getAttribute("font-weight");
|
||
160 | _1d.size=r.getAttribute("font-size");
|
||
161 | _1d.family=r.getAttribute("font-family");
|
||
162 | }; |
||
163 | var _3=function(_1e,def){ |
||
164 | var _1f=_1e.shape=dojo.clone(def),r=_1e.rawNode;
|
||
165 | for(var i in _1f){ |
||
166 | _1f[i]=r.getAttribute(i); |
||
167 | } |
||
168 | }; |
||
169 | var _2=function(_20){ |
||
170 | _3(_20,dojox.gfx.defaultRect); |
||
171 | _20.shape.r=Math.min(_20.rawNode.getAttribute("rx"),_20.rawNode.getAttribute("ry")); |
||
172 | }; |
||
173 | var _5=function(_21){ |
||
174 | var _22=_21.shape=dojo.clone(dojox.gfx.defaultText),r=_21.rawNode;
|
||
175 | _22.x=r.getAttribute("x");
|
||
176 | _22.y=r.getAttribute("y");
|
||
177 | _22.align=r.getAttribute("text-anchor");
|
||
178 | _22.decoration=r.getAttribute("text-decoration");
|
||
179 | _22.rotated=parseFloat(r.getAttribute("rotate"))!=0; |
||
180 | _22.kerning=r.getAttribute("kerning")=="auto"; |
||
181 | _22.text=r.firstChild.nodeValue; |
||
182 | }; |
||
183 | var _4=function(_23){ |
||
184 | var _24=_23.shape=dojo.clone(dojox.gfx.defaultTextPath),r=_23.rawNode;
|
||
185 | _24.align=r.getAttribute("text-anchor");
|
||
186 | _24.decoration=r.getAttribute("text-decoration");
|
||
187 | _24.rotated=parseFloat(r.getAttribute("rotate"))!=0; |
||
188 | _24.kerning=r.getAttribute("kerning")=="auto"; |
||
189 | _24.text=r.firstChild.nodeValue; |
||
190 | }; |
||
191 | })(); |