if(window.Shodo==null){Shodo={};Shodo.Font=function(a,b,c,d,e,f,g,h,i){this.isIE=(window.G_vmlCanvasManager!=null);this.useVML=true;if(this.isIE&&((b==null)||(b.Family==null)||(b.Size==null))){alert("Invalid or unspecified font description.");return null}this.xparentpixel=i;this.mycanvas=g;this.Positions=c;if(this.Positions[0]<0){this.Positions[0]=0}this.Widths=d;this.CharSet=f;this.TextImage=h;this.fontname=a;this.fontheight=e;this.fontdesc=b||{};if(this.isIE){if(this.fontdesc.Color==null){this.fontdesc.Color='black'}this.fontdesc.IEOpacity=(this.fontdesc.Opacity!=null)?Math.round(100*this.fontdesc.Opacity):100}};Shodo.Font.prototype={drawAbove:function(a,x,y,b,c){if(b==null){b=0}var d=this.getBounds(a,0,0,c,0);x-=((d[2]-d[0])>>1);y-=((d[3]-d[1])+b);return this.drawString(a,x,y,c,'center')},drawAlignedTo:function(a,x,y,b,c){var d=this.getBounds(a,0,0,b,0);var e=(d[3]-d[1])>>1;var f=d[2]-d[0];var g=d[3]-d[1];c=c%360;if(c<0){c=360+c}if(c>270){c=c-360}if((c<=90)&&(c>=-90)){return this.drawString(a,x,y,b,'left',c)}if(c<=180){d=this.getBounds(a,x,y-e,b,c);return this.drawString(a,d[0],d[3],b,'right',c-180)}d=this.getBounds(a,x,y,b,c);return this.drawString(a,d[0]+e,d[1],b,'left',c-180)},drawBelow:function(a,x,y,b,c){if(b==null){b=0}var d=this.getBounds(a,0,0,c,0);x-=((d[2]-d[0])>>1);y+=b+1;return this.drawString(a,x,y,c,'center')},drawLeftOf:function(a,x,y,b,c){if(b==null){b=0}var d=this.getBounds(a,0,0,c,0);x-=((d[2]-d[0])+b);y-=((d[3]-d[1])>>1);return this.drawString(a,x,y,c,'right')},drawRightOf:function(a,x,y,b,c){if(b==null){b=0}var d=this.getBounds(a,0,0,c,0);x+=b;y-=((d[3]-d[1])>>1);return this.drawString(a,x,y,c,'left')},drawString:function(a,x,y,b,c,d){if(this.isIE&&this.useVML){return((d==null)||(d==0))?this._vml_drawTextBox(a,x,y,b,c):this._vml_drawString(a,x,y,b,c,d)}a=""+a;if(c==null){c='left'}y=Math.round(y);var e=Math.round(x);if(b==null){b=4}var f=a.split("\n");var g=[];var h=this.getBounds(a,x,y,b,0);if(h==null){return null}var k=h[2]-h[0]+1;var l;var m;var n=this.fontheight;this.mycanvas.save();this.mycanvas.translate(h[0],h[1]);if((d!=null)&&(d!=0)){this.mycanvas.rotate((Math.PI/180)*d)}else{d=0}var o=[];var i;var j=0;y=0;for(i=0;i<f.length;i++){var s=f[i].split('');x=0;m=0;for(j=0;j<s.length;j++){l=this.CharSet.indexOf(s[j]);if(l<0){return null}m+=this.Widths[l];o.push(l)}o.push(-2);g[i]=(c=='right')?[(h[2]-h[0])-m+1,y]:(c=='center')?[(((h[2]-h[0])-m+1)>>1),y]:[0,y];y+=n+b}var p=g[0][0];var q=g[0][1];if((this.xparentpixel!=null)&&(d!=0)){this.mycanvas.drawImage(this.xparentpixel,0,0,1,1,p,q,1,1)}j=0;for(i=0;i<o.length;i++){l=o[i];if(l==-2){j++;if(j==g.length){break}p=g[j][0];q=g[j][1];continue}if(this.Positions[l]>=0){this.mycanvas.drawImage(this.TextImage,this.Positions[l],0,this.Widths[l],n,p,q,this.Widths[l],n)}p+=this.Widths[l]}this.mycanvas.restore();return this},getBounds:function(a,x,y,b,c){if(b==null){b=4}a=""+a;var d=a.split("\n");var e=0;var i,j,pos,width=0;var f=0;var g=this.fontheight;for(i=0;i<d.length;i++){var s=d[i].split('');f+=g+b;for(j=0;j<s.length;j++){pos=this.CharSet.indexOf(s[j]);if(pos<0){return null}width+=this.Widths[pos]}if(e<width){e=width}width=0}f-=b;if(c==null){c=0}c=c%360;if(c==0){var h=[x,y,x+e-1,y+f-1];return[x,y,x+e-1,y+f-1]}var k,xp_rt,yp_top,yp_bot;var l;if(c>0){if(c<=90){l=(Math.PI/180)*c;k=x-(f*Math.sin(l));xp_rt=x+(e*Math.cos(l));yp_top=y;yp_bot=y+(f*Math.cos(l))+(e*Math.sin(l))}else if(c<=180){l=(Math.PI/180)*(c-90);k=x-(e*Math.sin(l))-(f*Math.cos(l));xp_rt=x;yp_top=y-(f*Math.sin(l));yp_bot=y+(e*Math.cos(l))}else if(c<=270){l=(Math.PI/180)*(c-180);var m=f*Math.sin(l);var n=e*Math.cos(l);k=x-n;xp_rt=x+m;yp_top=y-(e*Math.sin(l))-(f*Math.cos(l));yp_bot=y}else{l=(Math.PI/180)*(360-c);k=x-(f*Math.sin(l));xp_rt=x+(e*Math.cos(l));yp_top=y-(f*Math.sin(l))-(e*Math.sin(l));yp_bot=y}}else{if(c>-90){l=(Math.PI/180)*(-c);k=x;xp_rt=x+(e*Math.sin(l))+(f*Math.sin(l));yp_top=y-(e*Math.sin(l));yp_bot=y+(f*Math.cos(l))}else if(c>-180){l=(Math.PI/180)*(c+180);k=x-(e*Math.cos(l));xp_rt=x+(f*Math.sin(l));yp_top=y-(e*Math.sin(l))+(f*Math.cos(l));yp_bot=y}else if(c>-270){l=(Math.PI/180)*(c+270);k=x-(e*Math.sin(l))-(f*Math.sin(l));xp_rt=x;yp_top=y-(f*Math.sin(l));yp_bot=y+(width*Math.cos(l))}else{l=(Math.PI/180)*(c+360);k=x-(f*Math.sin(l));xp_rt=x+(e*Math.cos(l));yp_top=y;yp_bot=y+(f*Math.sin(l))+(e*Math.sin(l))}}return[Math.round(k),Math.round(yp_top),Math.round(xp_rt),Math.round(yp_bot)]},getHeight:function(){return this.fontheight},disableVML:function(){this.useVML=false},enableVML:function(){this.useVML=true},_vml_drawTextBox:function(a,x,y,b,c){var d=this.getBounds(a,x,y,b,0);var w=d[2]-d[0]+1;var h=d[3]-d[1];a=""+a;if(a.match(/\n/)){a.replace(/\n/,"<br/>")}var e=['<v:rect style="position:absolute; top=',y,'; left=',x,'; width=',w,'; height=',h,'">','<v:textbox style="font: ',(this.fontdesc.Style||"normal"),' ',(this.fontdesc.Weight||"normal"),' ',this.fontdesc.Size,'px ',this.fontdesc.Family,'; text-align: ',(c||'left'),'; color: ',this.fontdesc.Color,'; filter: alpha(opacity=',this.fontdesc.IEOpacity,');">',a,'</v:textbox> </v:rect>'].join("");var f=this.mycanvas.getElement();f.insertAdjacentHTML("beforeEnd",e);return this},_vml_drawString:function(a,x,y,b,c,d){var e=this.getBounds(a,x,y,b,d);if(d==null){d=0}var f=((d==90)||(d==270)||(d==-90)||(d==-270))?e[0]+((e[2]-e[0])>>1):e[0];var g=((d==90)||(d==270)||(d==-90)||(d==-270))?e[0]+((e[2]-e[0])>>1):e[2];var h=(d==0)?e[3]:((d==90)||(d==-270))?e[1]:((d==-90)||(d==270))?e[3]:(((d>0)&&(d<90))||((d>180)&&(d<270))||((d>-359.9)&&(d<-270))||((d<-90)&&(d>-180)))?e[1]:e[3];var i=(d==0)?h:((d==90)||(d==-270))?e[3]:((d==-90)||(d==270))?e[1]:(((d>0)&&(d<90))||((d>180)&&(d<270))||((d>-359.9)&&(d<-270))||((d<-90)&&(d>-180)))?e[3]:e[1];if(h==i){h-=(this.fontdesc.Size>>1);i-=(this.fontdesc.Size>>1);i+=0.08}if(f==g){g+=0.08}var j=Math.round(0.6*this.fontdesc.Size);var k=['<g_vml_:line from="',f,' ',h,'" to="',g,' ',i,'">','<g_vml_:fill on="True" color="',this.fontdesc.Color,'" opacity="',this.fontdesc.IEOpacity,'%" />','<g_vml_:path textpathok="True"/>','<g_vml_:textpath on="True" string="',a,'" style="font: ',(this.fontdesc.Style||"normal"),' normal ',(this.fontdesc.Weight||"normal"),' ',j,'pt ',this.fontdesc.Family+';"/>','</g_vml_:line>'].join("");var l=this.mycanvas.getElement();l.insertAdjacentHTML("beforeEnd",k);return this}};Shodo.Foundry=function(a,b,c,d,e,f){this.xparentpixel=null;this.mycanvas=a;this.imgcount=0;this.fonts=(b!=null)?b:{};this.isIE=(window.G_vmlCanvasManager!=null);this.useVML=(f!=null)?f:true;if(!JSON){alert("No JSON parser available.\nSee http://yuiblog.com/blog/2007/04/10/json-and-browser-security/");return null}this.initFonts(c,d,e)};Shodo.Foundry.prototype={addFont:function(a,b,c,d,e,f,g,h,i,j,k){var l={};l.Family=a;l.Size=b;l.Color=c;l.Opacity=d;l.Weight=null;l.Style=null;return this.addNamedFont(this.canonical(a,b,c,d),l,e,f,g,h,i,j,k)},addFontsFromJSON:function(a,b,c){var d=(a instanceof String)?JSON.parse(a):a;var e=[];if(d==null){alert("Invalid JSON received!");return null}var f;for(f in d){this.fonts[f]=this.addNamedFont(f,d[f].Description,d[f].CharSet,d[f].Positions,d[f].Widths,d[f].Height,(this.isIE||(d[f].DataURL==null)?d[f].ImageURL:d[f].DataURL),b,c);e.push(f)}return e},addNamedFont:function(b,c,d,e,f,g,h,i,j){this.fonts[b]={};var k=new Image();k.foundry=this;k.font=b;this.fonts[b].Font=new Shodo.Font(b,c,e,f,g,d,this.mycanvas,k,this.xparentpixel);this.fonts[b].Font.onload=i;this.fonts[b].Font.foundry=this;this.fonts[b].Font.appCtxt=j;if(this.isIE){if(this.useVML){this.fonts[b].Font.enableVML()}else{this.fonts[b].Font.disableVML()}}k.onload=function(){var a=this.foundry.getFontByName(this.font);if(a.onload!=null){a.onload()}this.foundry=null;this.font=null;a.foundry=null;a.appCtxt=null};if(this.fontpath!=null){h.replace(/^.+\//,this.fontpath)}k.src=h;return this.fonts[b]},canonical:function(a,b,c,d){if(c.length==7){c+=""+((d==null)?'ff':d.toString(16).toLowerCase())}return[a.replace(/\W+/g,'_').toLowerCase(),b,c.substr(1).toLowerCase()].join('_')},getFont:function(a,b,c,d){return this.fonts[this.canonical(a,b,c,d)].Font},getFontByName:function(a){return this.fonts[a].Font},initFonts:function(a,b,c){if(a!=null){if(a.substr(a.length-1)!='/'){a+='/'}this.fontpath=a}var d;for(d in this.fonts){this.imgcount++}this.onload=c;this.appCtxt=b;if((this.xparentpixel==null)&&navigator.userAgent.match(/Firefox/)&&(this.mycanvas.mozDrawText==null)){this.imgcount++;this.xparentpixel=new Image();this.xparentpixel.foundry=this;this.xparentpixel.onload=function(){this.foundry.isLoadDone();this.foundry=null};this.xparentpixel.src="data:image/gif;base64,R0lGODlhAQABAJH/AP///wAAAP///wAAACH/C0FET0JFOklSMS4wAt7tACH5BAEAAAIALAAAAAABAAEAAAICVAEAOw=="}for(d in this.fonts){this.fonts[d]=this.addNamedFont(d,this.fonts[d].Description,this.fonts[d].CharSet,this.fonts[d].Positions,this.fonts[d].Widths,this.fonts[d].Height,(this.isIE||(this.fonts[d].DataURL==null)?this.fonts[d].ImageURL:this.fonts[d].DataURL),function(){this.foundry.isLoadDone()})}return this},isLoadDone:function(){this.imgcount--;if((this.imgcount==0)&&(this.onload!=null)){this.onload();this.appCtxt=null;this.onload=null}},setFontPath:function(a){if(a.substr(a.length-1)!='/'){a+='/'}this.fontpath=a},disableVML:function(){this.useVML=false},enableVML:function(){this.useVML=true},disableVMLForAll:function(){if(this.isIE){this.useVML=false;for(var a in this.fonts){this.fonts[a].Font.disableVML()}}},enableVMLForAll:function(){if(this.isIE){this.useVML=true;for(var a in this.fonts){this.fonts[a].Font.enableVML()}}}}}