/*
 jsPDF ( ${buildDate} ${commitID} )
Copyright (c) 2010 James Hall, https://github.com/MrRio/jsPDF
Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
MIT license.
 
        -----------------------------------------------------------------------------------------------
        JavaScript PubSub library
        2012 (c) ddotsenko@willowsystems.com
        based on Peter Higgins (dante@dojotoolkit.org)
        Loosely based on Dojo publish/subscribe API, limited in scope. Rewritten blindly.
        Original is (c) Dojo Foundation 2004-2010. Released under either AFL or new BSD, see:
        http://dojofoundation.org/license for more information.
        -----------------------------------------------------------------------------------------------
*/
var jsPDF=function(){function E(d,m,e){d="undefined"===typeof d?"p":d.toString().toLowerCase();"undefined"===typeof m&&(m="mm");"undefined"===typeof e&&(e="a4");var l=e.toString().toLowerCase(),t=[],s=0,j={a3:[841.89,1190.55],a4:[595.28,841.89],a5:[420.94,595.28],letter:[612,792],legal:[612,1008]},B="0 g",q=0,N=[],y=2,I=!1,G=[],p={},v={},J=16,w,k,z,c,u={title:"",subject:"",author:"",keywords:"",creator:""},O=0,P=0,n={},C=new U(n);if("pt"==m)c=1;else if("mm"==m)c=72/25.4;else if("cm"==m)c=72/2.54;
else if("in"==m)c=72;else throw"Invalid unit: "+m;if(l in j)k=j[l][1]/c,z=j[l][0]/c;else try{k=e[1],z=e[0]}catch(X){throw"Invalid format: "+e;}if("p"===d||"portrait"===d)d="p",z>k&&(d=z,z=k,k=d);else if("l"===d||"landscape"===d)d="l",k>z&&(d=z,z=k,k=d);else throw"Invalid orientation: "+d;var f=function(a){return a.toFixed(2)},r=function(a){return a.toFixed(3)},H=function(a){var i=a.toFixed(0);return 10>a?"0"+i:i},b=function(a){I?N[q].push(a):(t.push(a),s+=a.length+1)},F=function(){y++;G[y]=s;b(y+
" 0 obj");return y},S=function(a){b("stream");b(a);b("endstream")},T=function(){q++;I=!0;N[q]=[];b(f(0.200025*c)+" w");b("0 G");0!==O&&b(O.toString(10)+" J");0!==P&&b(P.toString(10)+" j");C.publish("addPage",{pageNumber:q})},Q=function(a,i){var b;void 0===a&&(a=p[w].fontName);void 0===i&&(i=p[w].fontStyle);try{b=v[a][i]}catch(h){b=void 0}if(!b)throw Error("Unable to look up font label for font '"+a+"', '"+i+"'. Refer to getFontList() for available fonts.");return b},R=function(){I=!1;t=[];G=[];b("%PDF-1.3");
var a=z*c,i=k*c,g,h;for(g=1;g<=q;g++)F(),b("<</Type /Page"),b("/Parent 1 0 R"),b("/Resources 2 0 R"),b("/Contents "+(y+1)+" 0 R>>"),b("endobj"),h=N[g].join("\n"),F(),b("<</Length "+h.length+">>"),S(h),b("endobj");G[1]=s;b("1 0 obj");b("<</Type /Pages");g="/Kids [";for(h=0;h<q;h++)g+=3+2*h+" 0 R ";b(g+"]");b("/Count "+q);b("/MediaBox [0 0 "+f(a)+" "+f(i)+"]");b(">>");b("endobj");for(var x in p)p.hasOwnProperty(x)&&(a=p[x],a.objectNumber=F(),b("<</BaseFont/"+a.PostScriptName+"/Type/Font"),"string"===
typeof a.encoding&&b("/Encoding/"+a.encoding),b("/Subtype/Type1>>"),b("endobj"));C.publish("putResources");G[2]=s;b("2 0 obj");b("<<");b("/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]");b("/Font <<");for(var d in p)p.hasOwnProperty(d)&&b("/"+d+" "+p[d].objectNumber+" 0 R");b(">>");b("/XObject <<");C.publish("putXobjectDict");b(">>");b(">>");b("endobj");F();b("<<");b("/Producer (jsPDF 20120619)");u.title&&b("/Title ("+D(u.title)+")");u.subject&&b("/Subject ("+D(u.subject)+")");u.author&&b("/Author ("+
D(u.author)+")");u.keywords&&b("/Keywords ("+D(u.keywords)+")");u.creator&&b("/Creator ("+D(u.creator)+")");x=new Date;b("/CreationDate (D:"+[x.getFullYear(),H(x.getMonth()+1),H(x.getDate()),H(x.getHours()),H(x.getMinutes()),H(x.getSeconds())].join("")+")");b(">>");b("endobj");F();b("<<");b("/Type /Catalog");b("/Pages 1 0 R");b("/OpenAction [3 0 R /FitH null]");b("/PageLayout /OneColumn");b(">>");b("endobj");x=s;b("xref");b("0 "+(y+1));b("0000000000 65535 f ");for(d=1;d<=y;d++)a=G[d].toFixed(0),a=
10>a.length?Array(11-a.length).join("0")+a:a,b(a+" 00000 n ");b("trailer");b("<<");b("/Size "+(y+1));b("/Root "+y+" 0 R");b("/Info "+(y-1)+" 0 R");b(">>");b("startxref");b(x);b("%%EOF");I=!0;return t.join("\n")},D=function(a,b){var g;g=a;var h=b,c,d;void 0===h&&(h={});c=h.sourceEncoding?c:"Unicode";var f=h.outputEncoding,e,m,k;if((h.autoencode||f)&&p[w].metadata&&p[w].metadata[c]&&p[w].metadata[c].encoding)if(c=p[w].metadata[c].encoding,!f&&p[w].encoding&&(f=p[w].encoding),!f&&c.codePages&&(f=c.codePages[0]),
"string"===typeof f&&(f=c[f]),f){m=!1;e=[];c=0;for(d=g.length;c<d;c++)(k=f[g.charCodeAt(c)])?e.push(String.fromCharCode(k)):e.push(g[c]),e[c].charCodeAt(0)>>8&&(m=!0);g=e.join("")}for(c=g.length;void 0===m&&0!==c;)g.charCodeAt(c-1)>>8&&(m=!0),c--;if(m){e=h.noBOM?[]:[254,255];c=0;for(d=g.length;c<d;c++){k=g.charCodeAt(c);h=k>>8;if(h>>8)throw Error("Character at position "+c.toString(10)+" of string '"+g+"' exceeds 16bits. Cannot be encoded into UCS-2 BE");e.push(h);e.push(k-(h<<8))}g=String.fromCharCode.apply(void 0,
e)}return g.replace(/\\/g,"\\\\").replace(/\(/g,"\\(").replace(/\)/g,"\\)")},K=function(a){var b="S";if("F"===a)b="f";else if("FD"===a||"DF"===a)b="B";return b};n.internal={pdfEscape:D,getStyle:K,getFont:function(){return p[Q.apply(n,arguments)]},getFontSize:function(){return J},btoa:L,write:function(a,c,g,h){b(1===arguments.length?arguments[0]:Array.prototype.join.call(arguments," "))},getCoordinateString:function(a){return f(a*c)},getVerticalCoordinateString:function(a){return f((k-a)*c)},collections:{},
newObject:F,putStream:S,events:C,scaleFactor:c,pageSize:{width:z,height:k}};n.addPage=function(){T();return this};n.text=function(a,i,g,h){var d,e;"number"===typeof a&&(d=a,e=i,a=g,i=d,g=e);"string"===typeof a&&a.match(/[\n\r]/)&&(a=a.split(/\r\n|\r|\n/g));"undefined"===typeof h?h={noBOM:!0,autoencode:!0}:(void 0===h.noBOM&&(h.noBOM=!0),void 0===h.autoencode&&(h.autoencode=!0));if("string"===typeof a)h=D(a,h);else if(a instanceof Array){a=a.concat();for(d=a.length-1;-1!==d;d--)a[d]=D(a[d],h);h=a.join(") Tj\nT* (")}else throw Error('Type of text must be string or Array. "'+
a+'" is not recognized.');b("BT\n/"+w+" "+J+" Tf\n"+J+" TL\n"+B+"\n"+f(i*c)+" "+f((k-g)*c)+" Td\n("+h+") Tj\nET");return this};n.line=function(a,i,g,h){b(f(a*c)+" "+f((k-i)*c)+" m "+f(g*c)+" "+f((k-h)*c)+" l S");return this};n.lines=function(a,i,g,h,d){var f,e;"number"===typeof a&&(f=a,e=i,a=g,i=f,g=e);d=K(d);h=void 0===h?[1,1]:h;b(r(i*c)+" "+r((k-g)*c)+" m ");f=h[0];h=h[1];e=0;for(var m=a.length,j,l,n,q,p=g;e<m;e++)g=a[e],2===g.length?(i=g[0]*f+i,p=g[1]*h+p,b(r(i*c)+" "+r((k-p)*c)+" l")):(j=g[0]*
f+i,l=g[1]*h+p,n=g[2]*f+i,q=g[3]*h+p,i=g[4]*f+i,p=g[5]*h+p,b(r(j*c)+" "+r((k-l)*c)+" "+r(n*c)+" "+r((k-q)*c)+" "+r(i*c)+" "+r((k-p)*c)+" c"));b(d);return this};n.rect=function(a,i,g,d,e){e=K(e);b([f(a*c),f((k-i)*c),f(g*c),f(-d*c),"re",e].join(" "));return this};n.triangle=function(a,b,c,d,e,f,m){this.lines([[c-a,d-b],[e-c,f-d],[a-e,b-f]],a,b,[1,1],m);return this};n.ellipse=function(a,i,d,e,m){var m=K(m),j=4/3*(Math.SQRT2-1)*d,l=4/3*(Math.SQRT2-1)*e;b([f((a+d)*c),f((k-i)*c),"m",f((a+d)*c),f((k-(i-
l))*c),f((a+j)*c),f((k-(i-e))*c),f(a*c),f((k-(i-e))*c),"c"].join(" "));b([f((a-j)*c),f((k-(i-e))*c),f((a-d)*c),f((k-(i-l))*c),f((a-d)*c),f((k-i)*c),"c"].join(" "));b([f((a-d)*c),f((k-(i+l))*c),f((a-j)*c),f((k-(i+e))*c),f(a*c),f((k-(i+e))*c),"c"].join(" "));b([f((a+j)*c),f((k-(i+e))*c),f((a+d)*c),f((k-(i+l))*c),f((a+d)*c),f((k-i)*c),"c",m].join(" "));return this};n.circle=function(a,b,c,d){return this.ellipse(a,b,c,c,d)};n.setProperties=function(a){for(var b in u)u.hasOwnProperty(b)&&a[b]&&(u[b]=a[b]);
return this};n.addImage=function(){return this};n.setFontSize=function(a){J=a;return this};n.setFont=function(a,b){w=Q(a,b);return this};n.setFontStyle=n.setFontType=function(a){w=Q(void 0,a);return this};n.getFontList=function(){var a={},b,c,d;for(b in v)if(v.hasOwnProperty(b))for(c in a[b]=d=[],v[b])v[b].hasOwnProperty(c)&&d.push(c);return a};n.setLineWidth=function(a){b((a*c).toFixed(2)+" w");return this};n.setDrawColor=function(a,c,d){a=0===a&&0===c&&0===d||"undefined"===typeof c?r(a/255)+" G":
[r(a/255),r(c/255),r(d/255),"RG"].join(" ");b(a);return this};n.setFillColor=function(a,c,d){a=0===a&&0===c&&0===d||"undefined"===typeof c?r(a/255)+" g":[r(a/255),r(c/255),r(d/255),"rg"].join(" ");b(a);return this};n.setTextColor=function(a,b,c){B=0===a&&0===b&&0===c||"undefined"===typeof b?r(a/255)+" g":[r(a/255),r(b/255),r(c/255),"rg"].join(" ");return this};n.CapJoinStyles={"0":0,butt:0,but:0,bevel:0,1:1,round:1,rounded:1,circle:1,2:2,projecting:2,project:2,square:2,milter:2};n.setLineCap=function(a){var c=
this.CapJoinStyles[a];if(void 0===c)throw Error("Line cap style of '"+a+"' is not recognized. See or extend .CapJoinStyles property for valid styles");O=c;b(c.toString(10)+" J");return this};n.setLineJoin=function(a){var c=this.CapJoinStyles[a];if(void 0===c)throw Error("Line join style of '"+a+"' is not recognized. See or extend .CapJoinStyles property for valid styles");P=c;b(c.toString(10)+" j");return this};n.output=function(a){switch(a){case void 0:return R();case "datauristring":case "dataurlstring":return"data:application/pdf;base64,"+
L(R());case "datauri":case "dataurl":document.location.href="data:application/pdf;base64,"+L(R());break;default:throw Error('Output type "'+a+'" is not supported.');}};for(var A in E.API)if(E.API.hasOwnProperty(A))if("events"===A&&E.API.events.length){d=C;m=E.API.events;l=e=void 0;for(j=m.length-1;-1!==j;j--)e=m[j][0],l=m[j][1],d.subscribe.apply(d,[e].concat("function"===typeof l?[l]:l))}else n[A]=E.API[A];A=[["Helvetica","helvetica","normal"],["Helvetica-Bold","helvetica","bold"],["Helvetica-Oblique",
"helvetica","italic"],["Helvetica-BoldOblique","helvetica","bolditalic"],["Courier","courier","normal"],["Courier-Bold","courier","bold"],["Courier-Oblique","courier","italic"],["Courier-BoldOblique","courier","bolditalic"],["Times-Roman","times","normal"],["Times-Bold","times","bold"],["Times-Italic","times","italic"],["Times-BoldItalic","times","bolditalic"]];d=0;for(m=A.length;d<m;d++){var j=A[d][0],M=A[d][1],l=A[d][2],e="F"+(V(p)+1).toString(10),j=p[e]={id:e,PostScriptName:j,fontName:M,fontStyle:l,
encoding:"StandardEncoding",metadata:{}},W=e;void 0===v[M]&&(v[M]={});v[M][l]=W;C.publish("addFont",j);l=e;e=A[d][0].split("-");j=e[0];e=e[1]||"";void 0===v[j]&&(v[j]={});v[j][e]=l}C.publish("addFonts",{fonts:p,dictionary:v});w="F1";T();C.publish("initialized");return n}if("undefined"===typeof L)var L=function(d){var m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".split(""),e,l,t,s,j=0,B=0,q="",q=[];do e=d.charCodeAt(j++),l=d.charCodeAt(j++),t=d.charCodeAt(j++),s=e<<16|l<<8|
t,e=s>>18&63,l=s>>12&63,t=s>>6&63,s&=63,q[B++]=m[e]+m[l]+m[t]+m[s];while(j<d.length);q=q.join("");d=d.length%3;return(d?q.slice(0,d-3):q)+"===".slice(d||3)};var V="function"===typeof Object.keys?function(d){return Object.keys(d).length}:function(d){var m=0,e;for(e in d)d.hasOwnProperty(e)&&m++;return m},U=function(d){this.topics={};this.context=d;this.publish=function(d,e){if(this.topics[d]){var l=this.topics[d],e=Array.prototype.slice.call(arguments,1),t=[],s,j,B,q;j=0;for(B=l.length;j<B;j++)q=l[j],
s=q[0],q[1]&&(q[0]=function(){},t.push(j)),s.apply(this.context,e);j=0;for(B=t.length;j<B;j++)l.splice(t[j],1)}};this.subscribe=function(d,e,l){this.topics[d]?this.topics[d].push([e,l]):this.topics[d]=[[e,l]];return{topic:d,callback:e}};this.unsubscribe=function(d){if(this.topics[d.topic])for(var e=this.topics[d.topic],l=0,t=e.length;l<t;l++)e[l][0]===d.callback&&e.splice(l,1)}};E.API={events:[]};return E}();
