//>>built define("dojox/gfx/canvas",["./_base","dojo/_base/lang","dojo/_base/array","dojo/_base/declare","dojo/_base/window","dojo/dom-geometry","dojo/dom","./_base","./shape","./path","./arc","./matrix","./decompose"],function(g,_1,_2,_3,_4,_5,_6,_7,gs,_8,ga,m,_9){ var _a=g.canvas={}; var _b=null,mp=m.multiplyPoint,pi=Math.PI,_c=2*pi,_d=pi/2,_e=_1.extend; _a.Shape=_3("dojox.gfx.canvas.Shape",gs.Shape,{_render:function(_f){ _f.save(); this._renderTransform(_f); this._renderClip(_f); this._renderShape(_f); this._renderFill(_f,true); this._renderStroke(_f,true); _f.restore(); },_renderClip:function(ctx){ if(this.canvasClip){ this.canvasClip.render(ctx); ctx.clip(); } },_renderTransform:function(ctx){ if("canvasTransform" in this){ var t=this.canvasTransform; ctx.translate(t.dx,t.dy); ctx.rotate(t.angle2); ctx.scale(t.sx,t.sy); ctx.rotate(t.angle1); } },_renderShape:function(ctx){ },_renderFill:function(ctx,_10){ if("canvasFill" in this){ var fs=this.fillStyle; if("canvasFillImage" in this){ var w=fs.width,h=fs.height,iw=this.canvasFillImage.width,ih=this.canvasFillImage.height,sx=w==iw?1:w/iw,sy=h==ih?1:h/ih,s=Math.min(sx,sy),dx=(w-s*iw)/2,dy=(h-s*ih)/2; _b.width=w; _b.height=h; var _11=_b.getContext("2d"); _11.clearRect(0,0,w,h); _11.drawImage(this.canvasFillImage,0,0,iw,ih,dx,dy,s*iw,s*ih); this.canvasFill=ctx.createPattern(_b,"repeat"); delete this.canvasFillImage; } ctx.fillStyle=this.canvasFill; if(_10){ if(fs.type==="pattern"&&(fs.x!==0||fs.y!==0)){ ctx.translate(fs.x,fs.y); } ctx.fill(); } }else{ ctx.fillStyle="rgba(0,0,0,0.0)"; } },_renderStroke:function(ctx,_12){ var s=this.strokeStyle; if(s){ ctx.strokeStyle=s.color.toString(); ctx.lineWidth=s.width; ctx.lineCap=s.cap; if(typeof s.join=="number"){ ctx.lineJoin="miter"; ctx.miterLimit=s.join; }else{ ctx.lineJoin=s.join; } if(_12){ ctx.stroke(); } }else{ if(!_12){ ctx.strokeStyle="rgba(0,0,0,0.0)"; } } },getEventSource:function(){ return null; },connect:function(){ },disconnect:function(){ },canvasClip:null,setClip:function(_13){ this.inherited(arguments); var _14=_13?"width" in _13?"rect":"cx" in _13?"ellipse":"points" in _13?"polyline":"d" in _13?"path":null:null; if(_13&&!_14){ return this; } this.canvasClip=_13?_15(_14,_13):null; this.surface.makeDirty(); return this; }}); var _15=function(_16,_17){ switch(_16){ case "ellipse": return {canvasEllipse:_18(_17),render:function(ctx){ return _a.Ellipse.prototype._renderShape.call(this,ctx); }}; case "rect": return {shape:_1.delegate(_17,{r:0}),render:function(ctx){ return _a.Rect.prototype._renderShape.call(this,ctx); }}; case "path": return {canvasPath:_19(_17),render:function(ctx){ this.canvasPath._renderShape(ctx); }}; case "polyline": return {canvasPolyline:_17.points,render:function(ctx){ return _a.Polyline.prototype._renderShape.call(this,ctx); }}; } return null; }; var _19=function(geo){ var p=new dojox.gfx.canvas.Path(); p.canvasPath=[]; p._setPath(geo.d); return p; }; var _1a=function(_1b,_1c,_1d){ var old=_1b.prototype[_1c]; _1b.prototype[_1c]=_1d?function(){ this.surface.makeDirty(); old.apply(this,arguments); _1d.call(this); return this; }:function(){ this.surface.makeDirty(); return old.apply(this,arguments); }; }; _1a(_a.Shape,"setTransform",function(){ if(this.matrix){ this.canvasTransform=g.decompose(this.matrix); }else{ delete this.canvasTransform; } }); _1a(_a.Shape,"setFill",function(){ var fs=this.fillStyle,f; if(fs){ if(typeof (fs)=="object"&&"type" in fs){ var ctx=this.surface.rawNode.getContext("2d"); switch(fs.type){ case "linear": case "radial": f=fs.type=="linear"?ctx.createLinearGradient(fs.x1,fs.y1,fs.x2,fs.y2):ctx.createRadialGradient(fs.cx,fs.cy,0,fs.cx,fs.cy,fs.r); _2.forEach(fs.colors,function(_1e){ f.addColorStop(_1e.offset,g.normalizeColor(_1e.color).toString()); }); break; case "pattern": if(!_b){ _b=document.createElement("canvas"); } var img=new Image(); this.surface.downloadImage(img,fs.src); this.canvasFillImage=img; } }else{ f=fs.toString(); } this.canvasFill=f; }else{ delete this.canvasFill; } }); _1a(_a.Shape,"setStroke"); _1a(_a.Shape,"setShape"); _a.Group=_3("dojox.gfx.canvas.Group",_a.Shape,{constructor:function(){ gs.Container._init.call(this); },_render:function(ctx){ ctx.save(); this._renderTransform(ctx); this._renderClip(ctx); for(var i=0;i0){ ctx=this.surface.rawNode.getContext("2d"); ctx.save(); this._renderTransform(ctx); this._renderFill(ctx,false); this._renderStroke(ctx,false); if(this.canvasFont){ ctx.font=this.canvasFont; } w=ctx.measureText(s.text).width; ctx.restore(); } return w; },_render:function(ctx){ ctx.save(); this._renderTransform(ctx); this._renderFill(ctx,false); this._renderStroke(ctx,false); this._renderShape(ctx); ctx.restore(); },_renderShape:function(ctx){ var ta,s=this.shape; if(!s.text||s.text.length==0){ return; } ta=s.align==="middle"?"center":s.align; ctx.textAlign=ta; if(this.canvasFont){ ctx.font=this.canvasFont; } if(this.canvasFill){ ctx.fillText(s.text,s.x,s.y); } if(this.strokeStyle){ ctx.beginPath(); ctx.strokeText(s.text,s.x,s.y); ctx.closePath(); } }}); _1a(_a.Text,"setFont"); if(_4.global.CanvasRenderingContext2D){ var _20=_4.doc.createElement("canvas").getContext("2d"); if(_20&&typeof _20.fillText!="function"){ _a.Text.extend({getTextWidth:function(){ return 0; },_renderShape:function(){ }}); } } var _21={M:"_moveToA",m:"_moveToR",L:"_lineToA",l:"_lineToR",H:"_hLineToA",h:"_hLineToR",V:"_vLineToA",v:"_vLineToR",C:"_curveToA",c:"_curveToR",S:"_smoothCurveToA",s:"_smoothCurveToR",Q:"_qCurveToA",q:"_qCurveToR",T:"_qSmoothCurveToA",t:"_qSmoothCurveToR",A:"_arcTo",a:"_arcTo",Z:"_closePath",z:"_closePath"}; _a.Path=_3("dojox.gfx.canvas.Path",[_a.Shape,_8.Path],{constructor:function(){ this.lastControl={}; },setShape:function(){ this.canvasPath=[]; return this.inherited(arguments); },_updateWithSegment:function(_22){ var _23=_1.clone(this.last); this[_21[_22.action]](this.canvasPath,_22.action,_22.args); this.last=_23; this.inherited(arguments); },_renderShape:function(ctx){ var r=this.canvasPath; ctx.beginPath(); for(var i=0;i