//>>built
define("dojox/gfx/VectorText","dojo/_base/lang dojo/_base/declare dojo/_base/array dojo/_base/loader dojo/_base/xhr ./_base dojox/xml/DomParser dojox/html/metrics ./matrix".split(" "),function(z,L,q,Q,M,k,N,O,G){var P=function(a){var c;M.get({url:a,sync:!0,load:function(b){c=b}});return c};z.getObject("dojox.gfx.VectorText",!0);z.mixin(k,{vectorFontFitting:{NONE:0,FLOW:1,FIT:2},defaultVectorText:{type:"vectortext",x:0,y:0,width:null,height:null,text:"",align:"start",decoration:"none",fitting:0,leading:1.5},
defaultVectorFont:{type:"vectorfont",size:"10pt",family:null},_vectorFontCache:{},_svgFontCache:{},getVectorFont:function(a){return k._vectorFontCache[a]?k._vectorFontCache[a]:new k.VectorFont(a)}});return L("dojox.gfx.VectorFont",null,{_entityRe:/&(quot|apos|lt|gt|amp|#x[^;]+|#\d+);/g,_decodeEntitySequence:function(a){if(a.match(this._entityRe)){for(var c={amp:"\x26",apos:"'",quot:'"',lt:"\x3c",gt:"\x3e"},b,d="";null!==(b=this._entityRe.exec(a));)d="x"==b[1].charAt(1)?d+String.fromCharCode(parseInt(b[1].slice(2),
16)):isNaN(parseInt(b[1].slice(1),10))?d+(c[b[1]]||""):d+String.fromCharCode(parseInt(b[1].slice(1),10));return d}},_parse:function(a,c){var b=k._svgFontCache[c]||N.parse(a),d=b.documentElement.byName("font")[0],e=b.documentElement.byName("font-face")[0],g=parseFloat(e.getAttribute("units-per-em")||1E3,10),h={x:parseFloat(d.getAttribute("horiz-adv-x"),10),y:parseFloat(d.getAttribute("vert-adv-y")||0,10)};h.y||(h.y=g);d={horiz:{x:parseFloat(d.getAttribute("horiz-origin-x")||0,10),y:parseFloat(d.getAttribute("horiz-origin-y")||
0,10)},vert:{x:parseFloat(d.getAttribute("vert-origin-x")||0,10),y:parseFloat(d.getAttribute("vert-origin-y")||0,10)}};var f=e.getAttribute("font-family"),l=e.getAttribute("font-style")||"all",p=e.getAttribute("font-variant")||"normal",H=e.getAttribute("font-weight")||"all",t=e.getAttribute("font-stretch")||"normal",w=e.getAttribute("unicode-range")||"U+0-10FFFF";e.getAttribute("panose-1");e.getAttribute("cap-height");var D=parseFloat(e.getAttribute("ascent")||g-d.vert.y,10),E=parseFloat(e.getAttribute("descent")||
d.vert.y,10),u={},n=f;e.byName("font-face-name")[0]&&(n=e.byName("font-face-name")[0].getAttribute("name"));if(!k._vectorFontCache[n]){q.forEach(["alphabetic","ideographic","mathematical","hanging"],function(m){var v=e.getAttribute(m);null!==v&&(u[m]=parseFloat(v,10))});var A=parseFloat(b.documentElement.byName("missing-glyph")[0].getAttribute("horiz-adv-x")||h.x,10),x={},B={},I=b.documentElement.byName("glyph");q.forEach(I,function(m){var v=m.getAttribute("unicode"),C=m.getAttribute("glyph-name"),
r=parseFloat(m.getAttribute("horiz-adv-x")||h.x,10);m=m.getAttribute("d");v.match(this._entityRe)&&(v=this._decodeEntitySequence(v));r={code:v,name:C,xAdvance:r,path:m};x[v]=r;B[C]=r},this);I=b.documentElement.byName("hkern");q.forEach(I,function(m,v){var C=-parseInt(m.getAttribute("k"),10),r=m.getAttribute("u1"),J=m.getAttribute("g1"),F=m.getAttribute("u2"),K=m.getAttribute("g2"),y;r?(r=this._decodeEntitySequence(r),x[r]&&(y=x[r])):B[J]&&(y=B[J]);y&&(y.kern||(y.kern={}),F?(F=this._decodeEntitySequence(F),
y.kern[F]={x:C}):B[K]&&(y.kern[B[K].code]={x:C}))},this);z.mixin(this,{family:f,name:n,style:l,variant:p,weight:H,stretch:t,range:w,viewbox:{width:g,height:g},origin:d,advance:z.mixin(h,{missing:{x:A,y:A}}),ascent:D,descent:E,baseline:u,glyphs:x});k._vectorFontCache[n]=this;k._vectorFontCache[c]=this;n==f||k._vectorFontCache[f]||(k._vectorFontCache[f]=this);k._svgFontCache[c]||(k._svgFontCache[c]=b)}},_clean:function(){var a=this.name,c=this.family;q.forEach("family name style variant weight stretch range viewbox origin advance ascent descent baseline glyphs".split(" "),
function(b){try{delete this[b]}catch(d){}},this);k._vectorFontCache[a]&&delete k._vectorFontCache[a];k._vectorFontCache[c]&&delete k._vectorFontCache[c];return this},constructor:function(a){this._defaultLeading=1.5;void 0!==a&&this.load(a)},load:function(a){this.onLoadBegin(a.toString());this._parse(k._svgFontCache[a.toString()]||P(a.toString()),a.toString());this.onLoad(this);return this},initialized:function(){return null!==this.glyphs},_round:function(a){return Math.round(1E3*a)/1E3},_leading:function(a){return this.viewbox.height*
(a||this._defaultLeading)},_normalize:function(a){return a.replace(/\s+/g,String.fromCharCode(32))},_getWidth:function(a){var c=0,b=0,d=null;q.forEach(a,function(e,g){b=e.xAdvance;a[g]&&e.kern&&e.kern[a[g].code]&&(b+=e.kern[a[g].code].x);c+=b;d=e});d&&" "==d.code&&(c-=d.xAdvance);return this._round(c)},_getLongestLine:function(a){var c=0,b=0;q.forEach(a,function(d,e){var g=Math.max(c,this._getWidth(d));g>c&&(c=g,b=e)},this);return{width:c,index:b,line:a[b]}},_trim:function(a){var c=function(b){b.length&&
(" "==b[b.length-1].code&&b.splice(b.length-1,1),b.length&&" "==b[0].code&&b.splice(0,1))};z.isArray(a[0])?q.forEach(a,c):c(a);return a},_split:function(a,c){var b=this._getWidth(a);b=Math.floor(b/c);for(var d=[],e=0,g=[],h=!1,f=0,l=a.length;f<l;f++){" "==a[f].code&&(h=!0);e+=a[f].xAdvance;f+1<l&&a[f].kern&&a[f].kern[a[f+1].code]&&(e+=a[f].kern[a[f+1].code].x);if(e>=b){for(e=a[f];h&&" "!=e.code&&0<=f;)e=g.pop(),f--;d.push(g);g=[];e=0;h=!1}g.push(a[f])}g.length&&d.push(g);return this._trim(d)},_getSizeFactor:function(a){a+=
"";var c=O.getCachedFontMeasurements(),b=this.viewbox.height,d=c["1em"];d=parseFloat(a,10);if(-1<a.indexOf("em"))return this._round(c["1em"]*d/b);if(-1<a.indexOf("ex"))return this._round(c["1ex"]*d/b);if(-1<a.indexOf("pt"))return this._round(c["12pt"]/12*d/b);if(-1<a.indexOf("px"))return this._round(c["16px"]/16*d/b);if(-1<a.indexOf("%"))return this._round(d/100*c["1em"]/b);d=c[a]||c.medium;return this._round(d/b)},_getFitFactor:function(a,c,b,d){if(b){var e=this._getLongestLine(a).width;return this._round(Math.min(c/
e,b/(a.length*this.viewbox.height*d-(this.viewbox.height*d-this.viewbox.height))))}return this._round(c/this._getWidth(a))},_getBestFit:function(a,c,b,d){for(var e=32,g=0,h=e;0<e;){var f=this._getFitFactor(this._split(a,e),c,b,d);f>g&&(g=f,h=e);e--}return{scale:g,lines:this._split(a,h)}},_getBestFlow:function(a,c,b){for(var d=[],e=0,g=[],h=!1,f=0,l=a.length;f<l;f++){" "==a[f].code&&(h=!0);var p=a[f].xAdvance;f+1<l&&a[f].kern&&a[f].kern[a[f+1].code]&&(p+=a[f].kern[a[f+1].code].x);e+=b*p;if(e>=c){for(e=
a[f];h&&" "!=e.code&&0<=f;)e=g.pop(),f--;d.push(g);g=[];e=0;h=!1}g.push(a[f])}g.length&&d.push(g);return this._trim(d)},getWidth:function(a,c){return this._getWidth(q.map(this._normalize(a).split(""),function(b){return this.glyphs[b]||{xAdvance:this.advance.missing.x}},this))*(c||1)},getLineHeight:function(a){return this.viewbox.height*(a||1)},getCenterline:function(a){return this.viewbox.height/2*(a||1)},getBaseline:function(a){return(a||1)*(this.viewbox.height+this.descent)},draw:function(a,c,b,
d,e){if(!this.initialized())throw Error("dojox.gfx.VectorFont.draw(): we have not been initialized yet.");var g=a.createGroup();(c.x||c.y)&&a.applyTransform({dx:c.x||0,dy:c.y||0});var h=q.map(this._normalize(c.text).split(""),function(x){return this.glyphs[x]||{path:null,xAdvance:this.advance.missing.x}},this);a=b.size;var f=c.fitting,l=c.width,p=c.height;b=c.align;c=c.leading||this._defaultLeading;!f||(f!=k.vectorFontFitting.FLOW||l)&&(f!=k.vectorFontFitting.FIT||l&&p)||(f=k.vectorFontFitting.NONE);
switch(f){case k.vectorFontFitting.FIT:h=this._getBestFit(h,l,p,c);a=h.scale;h=h.lines;break;case k.vectorFontFitting.FLOW:a=this._getSizeFactor(a);h=this._getBestFlow(h,l,a);break;default:a=this._getSizeFactor(a),h=[h]}h=q.filter(h,function(x){return 0<x.length});l=0;f=this._getLongestLine(h).width;p=0;for(var H=h.length;p<H;p++){for(var t=0,w=h[p],D=this._getWidth(w),E=g.createGroup(),u=0;u<w.length;u++){var n=w[u];if(null!==n.path){var A=E.createPath(n.path).setFill(d);e&&A.setStroke(e);A.setTransform([G.flipY,
G.translate(t,-this.viewbox.height-this.descent)])}t+=n.xAdvance;u+1<w.length&&n.kern&&n.kern[w[u+1].code]&&(t+=n.kern[w[u+1].code].x)}t=0;"middle"==b?t=f/2-D/2:"end"==b&&(t=f-D);E.setTransform({dx:t,dy:l});l+=this.viewbox.height*c}g.setTransform(G.scale(a));return g},onLoadBegin:function(a){},onLoad:function(a){}})});