in tapestry-framework/src/js/dojo-0.4.3-custom-4.1.6/src/gfx/svg.js [22:266]
dojo.lang.extend(dojo.gfx.Shape,{setFill:function(_2){
if(!_2){
this.fillStyle=null;
this.rawNode.setAttribute("fill","none");
this.rawNode.setAttribute("fill-opacity",0);
return this;
}
if(typeof (_2)=="object"&&"type" in _2){
switch(_2.type){
case "linear":
var f=dojo.gfx.makeParameters(dojo.gfx.defaultLinearGradient,_2);
var _4=this._setFillObject(f,"linearGradient");
dojo.lang.forEach(["x1","y1","x2","y2"],function(x){
_4.setAttribute(x,f[x].toFixed(8));
});
break;
case "radial":
var f=dojo.gfx.makeParameters(dojo.gfx.defaultRadialGradient,_2);
var _4=this._setFillObject(f,"radialGradient");
dojo.lang.forEach(["cx","cy","r"],function(x){
_4.setAttribute(x,f[x].toFixed(8));
});
break;
case "pattern":
var f=dojo.gfx.makeParameters(dojo.gfx.defaultPattern,_2);
var _7=this._setFillObject(f,"pattern");
dojo.lang.forEach(["x","y","width","height"],function(x){
_7.setAttribute(x,f[x].toFixed(8));
});
break;
}
return this;
}
var f=dojo.gfx.normalizeColor(_2);
this.fillStyle=f;
this.rawNode.setAttribute("fill",f.toCss());
this.rawNode.setAttribute("fill-opacity",f.a);
return this;
},setStroke:function(_9){
if(!_9){
this.strokeStyle=null;
this.rawNode.setAttribute("stroke","none");
this.rawNode.setAttribute("stroke-opacity",0);
return this;
}
this.strokeStyle=dojo.gfx.makeParameters(dojo.gfx.defaultStroke,_9);
this.strokeStyle.color=dojo.gfx.normalizeColor(this.strokeStyle.color);
var s=this.strokeStyle;
var rn=this.rawNode;
if(s){
rn.setAttribute("stroke",s.color.toCss());
rn.setAttribute("stroke-opacity",s.color.a);
rn.setAttribute("stroke-width",s.width);
rn.setAttribute("stroke-linecap",s.cap);
if(typeof (s.join)=="number"){
rn.setAttribute("stroke-linejoin","miter");
rn.setAttribute("stroke-miterlimit",s.join);
}else{
rn.setAttribute("stroke-linejoin",s.join);
}
}
return this;
},_setFillObject:function(f,_d){
var _e=this.rawNode.parentNode.getElementsByTagName("defs");
if(_e.length==0){
return this;
}
this.fillStyle=f;
var _f=_e[0];
var _10=this.rawNode.getAttribute("fill");
var ref=dojo.gfx.svg.getRef(_10);
if(ref){
_10=ref;
if(_10.tagName.toLowerCase()!=_d.toLowerCase()){
var id=_10.id;
_10.parentNode.removeChild(_10);
_10=document.createElementNS(dojo.svg.xmlns.svg,_d);
_10.setAttribute("id",id);
_f.appendChild(_10);
}else{
while(_10.childNodes.length){
_10.removeChild(_10.lastChild);
}
}
}else{
_10=document.createElementNS(dojo.svg.xmlns.svg,_d);
_10.setAttribute("id",dojo.dom.getUniqueId());
_f.appendChild(_10);
}
if(_d=="pattern"){
_10.setAttribute("patternUnits","userSpaceOnUse");
var img=document.createElementNS(dojo.svg.xmlns.svg,"image");
img.setAttribute("x",0);
img.setAttribute("y",0);
img.setAttribute("width",f.width.toFixed(8));
img.setAttribute("height",f.height.toFixed(8));
img.setAttributeNS(dojo.svg.xmlns.xlink,"href",f.src);
_10.appendChild(img);
}else{
_10.setAttribute("gradientUnits","userSpaceOnUse");
for(var i=0;i<f.colors.length;++i){
f.colors[i].color=dojo.gfx.normalizeColor(f.colors[i].color);
var t=document.createElementNS(dojo.svg.xmlns.svg,"stop");
t.setAttribute("offset",f.colors[i].offset.toFixed(8));
t.setAttribute("stop-color",f.colors[i].color.toCss());
_10.appendChild(t);
}
}
this.rawNode.setAttribute("fill","url(#"+_10.getAttribute("id")+")");
this.rawNode.removeAttribute("fill-opacity");
return _10;
},_applyTransform:function(){
var _16=this._getRealMatrix();
if(_16){
var tm=this.matrix;
this.rawNode.setAttribute("transform","matrix("+tm.xx.toFixed(8)+","+tm.yx.toFixed(8)+","+tm.xy.toFixed(8)+","+tm.yy.toFixed(8)+","+tm.dx.toFixed(8)+","+tm.dy.toFixed(8)+")");
}else{
this.rawNode.removeAttribute("transform");
}
return this;
},setRawNode:function(_18){
with(_18){
setAttribute("fill","none");
setAttribute("fill-opacity",0);
setAttribute("stroke","none");
setAttribute("stroke-opacity",0);
setAttribute("stroke-width",1);
setAttribute("stroke-linecap","butt");
setAttribute("stroke-linejoin","miter");
setAttribute("stroke-miterlimit",4);
}
this.rawNode=_18;
},moveToFront:function(){
this.rawNode.parentNode.appendChild(this.rawNode);
return this;
},moveToBack:function(){
this.rawNode.parentNode.insertBefore(this.rawNode,this.rawNode.parentNode.firstChild);
return this;
},setShape:function(_19){
this.shape=dojo.gfx.makeParameters(this.shape,_19);
for(var i in this.shape){
if(i!="type"){
this.rawNode.setAttribute(i,this.shape[i]);
}
}
return this;
},attachFill:function(_1b){
var _1c=null;
if(_1b){
var _1d=_1b.getAttribute("fill");
if(_1d=="none"){
return;
}
var ref=dojo.gfx.svg.getRef(_1d);
if(ref){
var _1f=ref;
switch(_1f.tagName.toLowerCase()){
case "lineargradient":
_1c=this._getGradient(dojo.gfx.defaultLinearGradient,_1f);
dojo.lang.forEach(["x1","y1","x2","y2"],function(x){
_1c[x]=_1f.getAttribute(x);
});
break;
case "radialgradient":
_1c=this._getGradient(dojo.gfx.defaultRadialGradient,_1f);
dojo.lang.forEach(["cx","cy","r"],function(x){
_1c[x]=_1f.getAttribute(x);
});
_1c.cx=_1f.getAttribute("cx");
_1c.cy=_1f.getAttribute("cy");
_1c.r=_1f.getAttribute("r");
break;
case "pattern":
_1c=dojo.lang.shallowCopy(dojo.gfx.defaultPattern,true);
dojo.lang.forEach(["x","y","width","height"],function(x){
_1c[x]=_1f.getAttribute(x);
});
_1c.src=_1f.firstChild.getAttributeNS(dojo.svg.xmlns.xlink,"href");
break;
}
}else{
_1c=new dojo.gfx.color.Color(_1d);
var _23=_1b.getAttribute("fill-opacity");
if(_23!=null){
_1c.a=_23;
}
}
}
return _1c;
},_getGradient:function(_24,_25){
var _26=dojo.lang.shallowCopy(_24,true);
_26.colors=[];
for(var i=0;i<_25.childNodes.length;++i){
_26.colors.push({offset:_25.childNodes[i].getAttribute("offset"),color:new dojo.gfx.color.Color(_25.childNodes[i].getAttribute("stop-color"))});
}
return _26;
},attachStroke:function(_28){
if(!_28){
return;
}
var _29=_28.getAttribute("stroke");
if(_29==null||_29=="none"){
return null;
}
var _2a=dojo.lang.shallowCopy(dojo.gfx.defaultStroke,true);
var _2b=new dojo.gfx.color.Color(_29);
if(_2b){
_2a.color=_2b;
_2a.color.a=_28.getAttribute("stroke-opacity");
_2a.width=_28.getAttribute("stroke-width");
_2a.cap=_28.getAttribute("stroke-linecap");
_2a.join=_28.getAttribute("stroke-linejoin");
if(_2a.join=="miter"){
_2a.join=_28.getAttribute("stroke-miterlimit");
}
}
return _2a;
},attachTransform:function(_2c){
var _2d=null;
if(_2c){
_2d=_2c.getAttribute("transform");
if(_2d.match(/^matrix\(.+\)$/)){
var t=_2d.slice(7,-1).split(",");
_2d=dojo.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])});
}
}
return _2d;
},attachShape:function(_2f){
var _30=null;
if(_2f){
_30=dojo.lang.shallowCopy(this.shape,true);
for(var i in _30){
_30[i]=_2f.getAttribute(i);
}
}
return _30;
},attach:function(_32){
if(_32){
this.rawNode=_32;
this.fillStyle=this.attachFill(_32);
this.strokeStyle=this.attachStroke(_32);
this.matrix=this.attachTransform(_32);
this.shape=this.attachShape(_32);
}
}});