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