/* Copyright (c) 2004-2006, The Dojo Foundation All Rights Reserved. Licensed under the Academic Free License version 2.1 or above OR the modified BSD license. For more information on Dojo licensing, see: http://dojotoolkit.org/community/licensing.shtml */ dojo.provide("dojo.gfx.svg"); dojo.require("dojo.lang.declare"); dojo.require("dojo.svg"); dojo.require("dojo.gfx.color"); dojo.require("dojo.gfx.common"); dojo.require("dojo.gfx.shape"); dojo.require("dojo.gfx.path"); dojo.require("dojo.experimental"); dojo.experimental("dojo.gfx.svg"); dojo.gfx.svg.getRef=function(_1){ if(!_1||_1=="none"){ return null; } if(_1.match(/^url\(#.+\)$/)){ return dojo.byId(_1.slice(5,-1)); } if(dojo.render.html.opera&&_1.match(/^#dj_unique_.+$/)){ return dojo.byId(_1.slice(1)); } return null; }; 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