forked from ineedfat/pdfjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdfJS-0.0.1.min.js
1 lines (1 loc) · 24 KB
/
pdfJS-0.0.1.min.js
1
(function(t){"use strict";var e="0.0.1";Object.create||(Object.create=function(t){function e(){}if(arguments.length>1)throw Error("Object.create implementation only accepts the first parameter.");return e.prototype=t,new e});var i=function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t.prototype[i]=e[i])},o={translate:function(t,e){this.push("1 0 0 1 "+parseFloat(t).toFixed(2)+" "+parseFloat(e).toFixed(2)+" cm")},scale:function(t,e){this.push(parseFloat(t).toFixed(2)+" 0 0 "+parseFloat(e).toFixed(2)+" 0 0 cm")},rotate:function(t){var e=Math.cos(t).toFixed(2),i=Math.sin(t).toFixed(2);this.push(e+" "+i+" -"+i+" "+e+" 0 0 cm")},skew:function(t,e){this.push("1 "+Math.tan(t).toFixed(2)+" "+Math.tan(e).toFixed(2)+" 1 0 0 cm")},lineWidth:function(t){this.push(parseFloat(t).toFixed(2)+" w")},lineCap:function(t){this.push(t+" J")},lineJoin:function(t){this.push(t+" j")},miterLimit:function(t){this.push(t+" M")},dashPattern:function(t,e){this.push(t+" "+e+" d")},renderingIntent:function(t){this.push(t+" ri")},strokeAdjustment:function(){},pushState:function(){this.push("q")},popState:function(){this.push("Q")},moveTo:function(){if(2!=arguments.length)throw"Invalid new path parameters";var t=Array.prototype.slice.call(arguments);this.push(t.join(" ")+" m")},lineTo:function(){if(2!=arguments.length)throw"Invalid straight line parameters";var t=Array.prototype.slice.call(arguments);this.push(t.join(" ")+" l")},bezierCurve:function(){var t=Array.prototype.slice.call(arguments);switch(arguments.length){case 4:this.push(t.join(" ")+" v");break;case 5:this.push(t.slice(0,4).join(" ")+" y");break;case 6:this.push(t.join(" ")+" c");break;default:throw"Invalid bezier curve parameters"}},close:function(){this.push("h")},paintPath:function(t){t?this.push(t):this.push("B")},strokePath:function(){this.push("S")},fillPath:function(){this.push("F")},endPath:function(){this.push("n")},clip:function(t){this.push("W"+(t?" *":""))},rect:function(){if(4!=arguments.length)throw"Invalid rectangle parameters";var t=Array.prototype.slice.call(arguments);this.push(t.join(" ")+" re")},fillColor:function(){switch(arguments.length){case 1:"DeviceGray"!==this.activeFillCS&&(this.push("/DeviceGray cs"),this.activeFillCS="DeviceGray");break;case 3:"DeviceRGB"!==this.activeFillCS&&(this.push("/DeviceRGB cs"),this.activeFillCS="DeviceRGB");break;default:throw"Invalid color values"}var t=Array.prototype.slice.call(arguments);this.push(t.join(" ")+" sc")},strokeColor:function(){switch(arguments.length){case 1:"DeviceGray"!==this.activeStrokeCS&&(this.push("/DeviceGray CS"),this.activeStrokeCS="DeviceGray");break;case 3:"DeviceRGB"!==this.activeStrokeCS&&(this.push("/DeviceRGB CS"),this.activeStrokeCS="DeviceRGB");default:throw"Invalid color values"}var t=Array.prototype.slice.call(arguments);this.push(t.join(" ")+" SC")},addImage:function(t,e,i,o,r){return 0==o&&(o=r*t.width/t.height),0==r&&(r=o*t.height/t.width),this.push("q"),this.push(o.toFixed(2)+" 0 0 "+r.toFixed(2)+" "+e.toFixed(2)+" "+i.toFixed(2)+" cm"),this.push("/"+t.name+" Do"),this.push("Q"),this},addSvg:function(t,e,i,o,r){o||r||(o=r=1),this.pushState(),this.push(o.toFixed(2)+" 0 0 "+-1*r.toFixed(2)+" "+e.toFixed(2)+" "+(i+this.doc.settings.dimension[1]).toFixed(2)+" cm"),this.push.apply(this,t.content),this.popState()}},r={beginText:function(t,e,i){this.push("BT"),this.fontStyle(t,e,i)},endText:function(){this.push("ET"),this.activeFont=void 0},textPosition:function(t,e){this.push(t+" "+e+" Td")},charSpace:function(t){this.push(t+" Tc")},wordSpace:function(t){this.push(t+" Tw")},scaleText:function(t){this.push(t+" Tz")},leading:function(t){this.push(t+" TL")},fontSize:function(t){this.push("/"+this.activeFont.description.key+" "+t+" Tf"),this.activeFontSize=t},fontStyle:function(t,e,i){this.activeFont=this.doc.resObj.getFont(t,e)||this.doc.resObj.fontObjs[0];var o=this.activeFont.description.key;this.push("/"+o+" "+(i||this.activeFontSize)+" Tf"),i&&(this.activeFontSize=i)},renderMode:function(){this.push(render+" Tr")},rise:function(t){this.push(t+" Ts")},print:function(t,e,i){1===arguments.length?this.push("("+this.activeFont.charactersEncode(O(t))+") Tj"):this.push(e+" "+i+" ("+this.activeFont.charactersEncode(O(t))+') "')},println:function(t){this.push("T*"),t&&this.print(t)},showArrayText:function(t){var e;for(e=0,len=t.length;len>I;e++)temp=t[e],"string"==typeof temp&&(t[e]="("+temp+")");this.push(t.join(" ")+" TJ")}},s=function(t,e){this.objectNumber=t,this.generationNumber=e,this.body=[]};s.prototype={out:function(){var t=[];return t.push(this.objectNumber+" "+this.generationNumber+" obj"),t=t.concat(this.body),t.push("endobj"),t.join("\n")},body:[],objectNumber:0,generationNumber:0};var n=function(t,e,i,o,r,n,a,h){var u=this;s.call(this,i,o),this.pageOptions=e,this.parent=t,this.contentStreams=r,this.currentStream=this.contentStreams[0],this.repeatableStreams=n,this.templateStreams=a,this.reservedObjectNums=[],this.doc=h,this.data={pageNum:0,pageTotal:function(){return u.doc.pageCount}}};n.prototype=Object.create(s.prototype,{out:{value:function(){this.body=[];var t,e,i,o=[];for(t=0,e=this.templateStreams.length;e>t;t++)this.reservedObjectNums[t]||(this.reservedObjectNums[t]=++this.doc.objectNumber),o.push(this.templateStreams[t].out(this.reservedObjectNums[t],0,this));if(this.body.push("<< /Type /Page"),this.body.push(x(this.pageOptions)),this.body.push("/Parent "+this.parent.objectNumber+" "+this.parent.generationNumber+" R"),this.body.push("/Contents "),this.contentStreams.length){for(this.body.push("["),t=0;i=this.contentStreams[t];t++)this.body.push(i.objectNumber+" "+i.generationNumber+" R");for(t=0;i=this.repeatableStreams[t];t++)this.body.push(i.objectNumber+" "+i.generationNumber+" R");for(t=0;i=this.reservedObjectNums[t];t++)this.body.push(i+" "+0+" R");this.body.push("]")}if(this.body.push(">>"),o.push(s.prototype.out.apply(this,arguments)),this.contentStreams.length)for(t=0;i=this.contentStreams[t];t++)o.push(i.out());return o.join("\n")}},setStream:{value:function(t){if(t>=this.contentStreams.length)throw"Invalid stream index";return this.currentStream=this.contentStreams[t],this}}});var a=function(t,e,i,o){s.call(this,e,i),this.parent=t,this.kids=[],this.options=o};a.prototype=Object.create(s.prototype,{out:{value:function(){this.body=[];var t,e;for(this.body.push("<< /Type /Pages",F(this.options),"/Kids ["),t=0;e=this.kids[t];t++)this.body.push(e.objectNumber+" "+e.generationNumber+" R");return this.body.push("]"),this.body.push("/Count "+h(this)),this.parent&&this.body.push("/Parent "+this.parent.objectNumber+" "+this.parent.generationNumber+" R"),this.body.push(">>"),s.prototype.out.apply(this,arguments)}}});var h=function(t){var e,i,o=0;for(e=0;i=t.kids[e];e++)i instanceof n?o++:o+=h(i);return o},u=function(t,e,i){s.call(this,t,e),this.content=[],this.dictionary={},this.doc=i,this.activeFont=void 0,this.activeFontSize=14,this.activeFillCS=void 0,this.activeStrokeCS=void 0},c=function(t){var e,i=[];for(e in t)t.hasOwnProperty(e)&&i.push("/"+e+" "+t[e]);return i.join("\n")};u.prototype=Object.create(s.prototype,{out:{value:function(){this.body=[];var t=c(this.dictionary),e=this.content;return this instanceof l||(e=["q"].concat(this.content),e.push("Q")),this.body.push("<< /Length "+e.join("\n").length),t&&this.body.push(t),this.body.push(">>"),this.body.push("stream"),this.body=this.body.concat(e),this.body.push("endstream"),s.prototype.out.apply(this,arguments)}},push:{value:function(){return Array.prototype.push.apply(this.content,arguments),this}}}),i(u,r),i(u,o);var p=function(t,e,i){s.call(this,e,i),this.description=t};p.codePages={WinAnsiEncoding:{338:140,339:156,352:138,353:154,376:159,381:142,382:158,402:131,710:136,732:152,8211:150,8212:151,8216:145,8217:146,8218:130,8220:147,8221:148,8222:132,8224:134,8225:135,8226:149,8230:133,8240:137,8249:139,8250:155,8364:128,8482:153}},p.prototype=Object.create(s.prototype,{out:{value:function(){return this.body=[],this.body.push("<< /Type /Font"),this.body.push("/Subtype /Type1"),this.body.push("/BaseFont /"+this.description.postScriptName),"string"==typeof this.description.encoding&&this.body.push("/Encoding /"+this.description.encoding),this.body.push(">>"),s.prototype.out.apply(this,arguments)}},charactersEncode:{value:function(t){var e,i,o,r,s,n,a=[],h=this.description.encoding;if("string"==typeof h&&(h=p.codePages[h]),!h)return t;for(e=0,i=t.length;i>e;e++)o=t.charCodeAt(e),o>>8&&(r=!0),o=h[o],o?a.push(String.fromCharCode(o)):a.push(t[e]);if(r){var u=[];for(e=0,i=a.length;i>e;e++){if(o=text.charCodeAt(e),s=o>>8,n=o-s,s>>8)throw"Character exceeds 16bits: "+text[e];u.push(s,n)}return String.fromCharCode.apply(null,u)}return a.join("")}}});var l=function(t,e,i,o,r,s,n,a){u.call(this,t,e),this.width=i,this.height=o,this.colorSpace=r||B.deviceRGB,this.bpc=s||8,this.filter=n,this.name="Im1",this.options=a||{}};l.prototype=Object.create(u.prototype,{out:{value:function(){return this.dictionary.Type="/XObject",this.dictionary.Subtype="/Image",this.dictionary.Width=this.width,this.dictionary.Height=this.height,this.dictionary.ColorSpace="/"+this.colorSpace,this.dictionary.BitsPerComponent=this.bpc,this.filter&&(this.dictionary.Filter="/"+this.filter),u.prototype.out.apply(this,arguments)}}});var d=function(t){this.templateContent=[],u.call(this,0,0,t)};d.prototype=Object.create(u.prototype,{out:{value:function(t,e,i){var o,r,s=this.templateContent.join("\n");if(this.objectNumber=t,this.generationNumber=e,i.data)for(var n in i.data)i.data.hasOwnProperty(n)&&(o=RegExp("{{"+n+"}}","g"),r=i.data[n],s=s.replace(o,r));return this.content=[s],u.prototype.out.apply(this,arguments)}},push:{value:function(){return Array.prototype.push.apply(this.templateContent,arguments),this}}});var b="1.3",f=function(t,e){var i=this;if(this.pageCount=0,this.repeatableElements=[],this.templateStreams=[],this.activeAsync=0,this.objectNumber=0,this.currentPage=null,this.settings={dimension:B.paperFormat.letter,documentProperties:{title:"",subject:"",author:"",keywords:"",creator:""}},i.settings.dimension="string"==typeof t?B.paperFormat[t.toLowerCase()].slice():t.slice().splice(0,2),"landscape"===e.toLowerCase()){var o=i.settings.dimension[0];i.settings.dimension[0]=i.settings.dimension[1],i.settings.dimension[1]=o}this.resObj=new C(++this.objectNumber,0),this.rootNode=new a(null,++i.objectNumber,0,{mediabox:[0,0,this.settings.dimension[0],this.settings.dimension[1]],resources:this.resObj}),this.currentNode=this.rootNode,this.infoObj=S(this.settings,this.newObj()),this.catalogObj=j(this.rootNode,this.newObj()),this.addStandardFonts()};f.prototype={objNumber:function(t){return t&&(this.objectNumber=value),t},page:function(t){return t&&(this.objectNumber=value),t},newObj:function(){return new s(++this.objectNumber,0)},newStream:function(){return new u(++this.objectNumber,0,this)},addPage:function(t,e,i){return this.pageCount++,this.currentPage=new n(this.currentNode,i||{mediabox:[0,0,e||this.settings.dimension[0],t||this.settings.dimension[1]]},++this.objectNumber,0,[this.newStream()],this.repeatableElements.slice(),this.templateStreams.slice(),this),this.currentPage.data.pageNum=this.pageCount,this.currentNode.kids.push(this.currentPage),this.currentPage},output:function(t){var e=N([g(this.rootNode),y(this.resObj.fontObjs),y(this.resObj.imageXObjects),y(this.repeatableElements),this.resObj.out(),this.infoObj.out(),this.catalogObj.out()]).join("\n"),i=v(e,this.catalogObj,this.infoObj);switch(t){case"datauristring":case"dataurlstring":return"data:application/pdf;base64,"+btoa(i);case"datauri":case"dataurl":document.location.href="data:application/pdf;base64,"+btoa(i);break;case"dataurlnewwindow":window.open("data:application/pdf;base64,"+btoa(i));break;default:return i}},outputAsync:function(t,e){var i=this,o=window.setInterval(function(){0===i.activeAsync&&(window.clearInterval(o),e(i.output(t)))},50)},addFont:function(t,e,i,o){var r="F"+(this.resObj.fontObjs.length+1).toString(10),s={key:r,postScriptName:t,fontName:e,fontStyle:i,encoding:o,metadata:{}};return this.resObj.fontObjs.push(new p(s,++this.objectNumber,0)),r},addStandardFonts:function(){for(var t="helvetica",e="times",i="courier",o="normal",r="bold",s="italic",n="bolditalic",a="StandardEncoding",h=[["Helvetica",t,o],["Helvetica-Bold",t,r],["Helvetica-Oblique",t,s],["Helvetica-BoldOblique",t,n],["Courier",i,o],["Courier-Bold",i,r],["Courier-Oblique",i,s],["Courier-BoldOblique",i,n],["Times-Roman",e,o],["Times-Bold",e,r],["Times-Italic",e,s],["Times-BoldItalic",e,n],["Symbol","symbol",o],["ZapfDingbats","zapfdingbats",o]],u=0,c=h.length;c>u;u++)this.addFont(h[u][0],h[u][1],h[u][2],a);return this},addRepeatableElement:function(){var t=this.newStream();return this.repeatableElements.push(t),t},addRepeatableTemplate:function(){var t=new d(this);return this.templateStreams.push(t),t}};var m=function(t){if("string"!=typeof t)throw"getOffsets expects a string input";var e,i,o,r,s=[],n=/\d+(?=\sobj)/,a=/^\d+/;for(e=t.match(/\d+\s\d+\sobj/gim),i=0;o=e[i];i++)r=RegExp("[^\\d]"+o.replace(/\s+/g,"\\s+")),s.push({objNum:parseInt(a.exec(o)),genNum:parseInt(n.exec(o)),offset:t.search(r)});return s},g=function(t){var e,i,o=[t.out()];for(e=0;i=t.kids[e];e++)i instanceof a?o.push(g(i)):o.push(i.out());return o.join("\n")},y=function(t){var e,i,o=[];for(e=0;i=t[e];e++)o.push(i.out());return o.join("\n")},v=function(t,e,i){var o,r=["%PDF-"+b,t],s=r.join("\n"),n=s.length,a=m(s),h=a.length;for(a=a.sort(function(t,e){return t.objNum-e.objNum}),r.push("xref"),r.push("0 "+(h+1)),r.push("0000000000 65535 f "),o=0;h>o;o++)r.push(E(a[o].offset)+" 00000 n ");return r.push("trailer"),r.push("<<"),r.push("/Size "+(h+1)),r.push("/Root "+e.objectNumber+" 0 R"),r.push("/Info "+i.objectNumber+" 0 R"),r.push(">>"),r.push("startxref"),r.push(n),r.push("%%EOF"),r.join("\n")},j=function(t,e){return e.body=[],e.body.push("<<"),e.body.push("/Type /Catalog"),e.body.push("/Pages "+t.objectNumber+" "+t.generationNumber+" R"),e.body.push("/PageLayout /OneColumn"),e.body.push(">>"),e},S=function(t,i){i.body=[],i.body.push("<<"),i.body.push("/Producer (PDFjs "+e+")"),t.documentProperties.title&&i.body.push("/Title ("+pdfEscape(t.documentProperties.title)+")"),t.documentProperties.subject&&i.body.push("/Subject ("+pdfEscape(t.documentProperties.subject)+")"),t.documentProperties.author&&i.body.push("/Author ("+pdfEscape(t.documentProperties.author)+")"),t.documentProperties.keywords&&i.body.push("/Keywords ("+pdfEscape(t.documentProperties.keywords)+")"),t.documentProperties.creator&&i.body.push("/Creator ("+pdfEscape(t.documentProperties.creator)+")");var o=new Date;return i.body.push("/CreationDate (D:"+[o.getFullYear(),R(o.getMonth()+1),R(o.getDate()),R(o.getHours()),R(o.getMinutes()),R(o.getSeconds())].join("")+")"),i.body.push(">>"),i},C=function(t,e){s.call(this,t,e),this.fontObjs=[],this.imageXObjects=[]},w=function(t,e){var i,o,r=[];for(i=0,o=t.length;o>i;i++)r.push("/"+e+(i+1).toString(10)+" "+t[i].objectNumber+" "+t[i].generationNumber+" R");return r.join("\n")};C.prototype=Object.create(s.prototype,{out:{value:function(){this.body=[],this.body.push("<<"),this.body.push("/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]"),this.body.push("/Font <<"),this.body.push(w(this.fontObjs,"F")),this.body.push(">>");var t=w(this.imageXObjects,"Im");return t&&(this.body.push("/XObject <<"),this.body.push(t),this.body.push(">>")),this.body.push(">>"),s.prototype.out.apply(this,arguments)}},getFont:{value:function(t,e){if("string"==typeof t)for(var i,o=0;i=this.fontObjs[o];o++){if(i.description.key.toLowerCase()===t.toLowerCase())return i;if("string"==typeof e&&i.description.fontName.toLowerCase()===t.toLowerCase()&&i.description.fontStyle.toLowerCase()===e.toLowerCase())return i}return void 0}}});var x=function(t){var e,i=[];for(var o in t)if(t.hasOwnProperty(o))switch(e=t[o],o.toLowerCase()){case"resources":if(e instanceof C)i.push("/Resources "+e.objectNumber+" "+e.generationNumber+" R");else{if("string"!=typeof e)throw"Invalid Resources!";i.push(e)}break;case"mediabox":A(e)&&i.push("/MediaBox ["+e.join(" ")+"]");break;case"cropbox":A(e)&&i.push("/CropBox ["+e.join(" ")+"]");break;case"bleedbox":A(e)&&i.push("/BleedBox ["+e.join(" ")+"]");break;case"trimbox":A(e)&&i.push("/TrimBox ["+e.join(" ")+"]");break;case"artbox":A(e)&&i.push("/ArtBox ["+e.join(" ")+"]");break;case"rotate":"number"==typeof e&&0===e%90&&i.push("/Rotate "+e);break;case"thumb":break;case"b":break;case"dur":break;case"Trans":break;case"Annots":break;case"AA":break;case"PieceInfo":break;case"LastModified":break;case"StructParents":break;case"ID":break;case"PZ":break;case"SeparationInfo":}return i.join("\n")},F=function(t){var e,i=[];for(var o in t)if(t.hasOwnProperty(o))switch(e=t[o],o.toLowerCase()){case"resources":if(e instanceof C)i.push("/Resources "+e.objectNumber+" "+e.generationNumber+" R");else{if("string"!=typeof e)throw"Invalid Resources!";i.push(e)}break;case"mediabox":A(e)&&i.push("/MediaBox ["+e.join(" ")+"]");break;case"cropbox":A(e)&&i.push("/CropBox ["+e.join(" ")+"]");break;case"rotate":"number"==typeof e&&0===e%90&&i.push("/Rotate "+e)}return i.join("\n")},k=/((\(|\)|\\))/gi,O=function(t){return t.replace(k,"\\$1")},N=function(t){var e,i,o,r=[];for(e=0,i=t.length;i>e;e++)o=t[e],o&&r.push(o);return r},P=/function (.{1,})\(/,T=function(t){var e=P.exec(""+t.constructor);return e&&e.length>1?e[1]:""},A=function(t){if(!t||"object"!=typeof t||4!==t.length)return console.warn("Invalid Rect"),!1;for(var e=0;4>e;e++)if("number"!=typeof t[e])return console.warn("Invalid Rect"),!1;return!0},R=function(t){var e=t.toFixed(0);return 10>t?"0"+e:e},E=function(t){var e=t.toFixed(0);return 10>e.length?Array(11-e.length).join("0")+e:e},B={paperFormat:{a3:[841.89,1190.55],a4:[595.28,841.89],a5:[420.94,595.28],letter:[612,792],legal:[612,1008]},lineCapStyle:{buttCap:0,roundCap:1,projectinSquareCap:2},lineJoinStyle:{miterJoin:0,roundJoin:1,bevelJoin:2},renderingIntentOption:{absoluteColorimetric:"AbsoluteColorimetric",relativeColorimetric:"RelativeColorimetric",saturation:"Saturation",perceptual:"Perceptual"},pathPaintingOption:{bigS:"S",smallS:"s",smallF:"f",fStar:"f*",bigB:"B",bigBStar:"B*",smallB:"b",smallBStar:"b*",n:"n"},colorSpace:{deviceGray:"DeviceGray",deviceRGB:"DeviceRGB",deviceCMYK:"DeviceCMYK"},textMode:{fillText:0,strokeText:1,fillStrokeText:2,invisibleText:3,fillClipText:4,strokeClipText:5,fillStrokeClipText:6,clipText:7}};f.prototype.newImage=function(t,e,i){var o=new l(++this.objectNumber,0,0,0,B.colorSpace.deviceRGB,8,"DCTDecode");return G.call(this,t,o,i||this.resObj,e,this),o};var G=function(t){if(t instanceof HTMLImageElement)L.apply(this,[t].concat(Array.prototype.slice.call(arguments,1,3)));else if("string"==typeof t)D.apply(this,[t].concat(Array.prototype.slice.call(arguments,1)));else{if(!(t instanceof HTMLCanvasElement))throw"Invalid Image Type";z.apply(this,[t].concat(Array.prototype.slice.call(arguments,1,3)))}},D=function(t,e,i,o,r){var s=new Image;s.onload=function(){r.activeAsync--,L.call(this,s,e,i)},o&&(s.crossOrigin="anonymous"),r.activeAsync++,s.src=t},L=function(t){var e=document.createElement("canvas");e.width=t.width,e.height=t.height;var i=e.getContext("2d");if(!i)throw"addImage requires canvas to be supported by browser.";i.drawImage(t,0,0,e.width,e.height),z.apply(this,[e].concat(Array.prototype.slice.call(arguments,1)))},z=function(t,e,i){var o=t.toDataURL("image/jpeg"),r=M(o,"jpeg");e.content.push(r.data),e.name="Im"+(i.imageXObjects.length+1),e.width=r.width,e.height=r.height,i.imageXObjects.push(e)},M=function(t,e){var i,o={width:0,height:0,data:""};e=e.toLowerCase(),"data:image/jpeg;base64,"===t.substring(0,23)&&(t=atob(t.replace("data:image/jpeg;base64,","")),e="jpeg");try{"jpeg"!=e&&e||(i=J(t),o.width=i[0],o.height=i[1])}catch(r){console.log("Image is not JPEG")}return o.data=t,o},J=function(t){var e,i;if(255===!t.charCodeAt(0)||216===!t.charCodeAt(1)||255===!t.charCodeAt(2)||224===!t.charCodeAt(3)||!t.charCodeAt(6)==="J".charCodeAt(0)||!t.charCodeAt(7)==="F".charCodeAt(0)||!t.charCodeAt(8)==="I".charCodeAt(0)||!t.charCodeAt(9)==="F".charCodeAt(0)||0===!t.charCodeAt(10))throw Error("getJpegSize requires a binary jpeg file");for(var o=256*t.charCodeAt(4)+t.charCodeAt(5),r=4,s=t.length;s>r;){if(r+=o,255!==t.charCodeAt(r))throw Error("getJpegSize could not find the size of the image");if(192===t.charCodeAt(r+1))return i=256*t.charCodeAt(r+5)+t.charCodeAt(r+6),e=256*t.charCodeAt(r+7)+t.charCodeAt(r+8),[e,i];r+=2,o=256*t.charCodeAt(r)+t.charCodeAt(r+1)}},q=function(t){this.content=[],t&&this.setSvg(t)};q.helpers={sanitizePath:function(t){var e=t.replace(/\s{2,}/gm," ");return e=e.replace(/([A-Za-z])(?=\d)/gm,"$1 ")},drawPath:function(t){var e,i,o,r=this,s=q.helpers.sanitizePath(t).split(" "),n={},a={},h=function(t,e,i,o,s,h){t=parseFloat(t),e=parseFloat(e),i=parseFloat(i),o=parseFloat(o),s=parseFloat(s).toFixed(2),h=parseFloat(h).toFixed(2);var u,c,p,l;u=(2*i/3+t/3).toFixed(2),c=(2*o/3+e/3).toFixed(2),p=(2*i/3+s/3).toFixed(2),l=(2*o/3+h/3).toFixed(2),r.bezierCurve(u,c,p,l,s,h),n={x:s,y:h},a={x:i,y:o}},u=function(t,e){return{x:2*e.x-t.x,y:2*e.y-t.y}};for(i=0,o=s.length;o>i;i++)switch(e=s[i],"T"!==e&&"Q"!==e&&"t"!==e&&"q"!==e&&(a={}),e){case"M":for(;parseFloat(s[i+1]);)n.x=s[++i],n.y=s[++i],this.moveTo(n.x,n.y);break;case"L":for(;parseFloat(s[i+1]);)n.x=s[++i],n.y=s[++i],this.lineTo(n.x,n.y);break;case"H":for(;parseFloat(s[i+1]);)n.x=s[++i],this.lineTo(n.x,0);break;case"V":for(;parseFloat(s[i+1]);)n.y=s[++i],this.lineTo(0,n.y);break;case"C":for(;parseFloat(s[i+1]);)this.bezierCurve(s[++i],s[++i],s[++i],s[++i],n.x=s[++i],n.y=s[++i]);break;case"S":for(;parseFloat(s[i+1]);)this.bezierCurve(s[++i],s[++i],n.x=s[++i],n.y=s[++i]);break;case"Q":for(;parseFloat(s[i+1]);)h(n.x,n.y,s[++i],s[++i],s[++i],s[++i]);break;case"T":for(var c;parseFloat(s[i+1]);)a.x||a.y?c=u(a,n):(c={},c.x=n.x,c.y=n.y),h(n.x,n.y,c.x,c.y,s[++i],s[++i]);break;case"A":i+=4,console.error("Path Not Supported");break;case"Z":this.close();break;default:throw"Invalid Path String!"}},setGenericOpitons:function(t,e){switch(t){case"stroke-width":this.lineWidth(e);break;case"stroke":"none"!==e.toLowerCase()&&this.strokeColor(0);break;case"fill":"none"!==e.toLowerCase()&&this.fillColor(0)}},paintSvg:function(t,e){var i=t.fill,o=t.stroke,r=i?"none"===i.value.toLowerCase():!1,s=o?"none"===o.value.toLowerCase():!1;i&&o&&!r&&!s?this.paintPath():i&&!r?this.paintPath("f"):o&&!s?this.paintPath("s"):!e||i||o||this.paintPath()}};var V={SVGSVGElement:"skip",SVGCircleElement:function(t){var e,i,o=t.attributes,r=parseInt(o.r.value).toFixed(2),s=o.cx?parseInt(o.cx.value).toFixed(2):0,n=o.cy?parseInt(o.cy.value).toFixed(2):0,a=(.5522422*r).toFixed(2);for(this.translate(s,n),this.moveTo(0,-1*r),this.bezierCurve(a,-1*r,r,-1*a,r,0),this.bezierCurve(r,a,a,r,0,r),this.bezierCurve(-1*a,r,-1*r,a,-1*r,0),this.bezierCurve(-1*r,-1*a,-1*a,-1*r,0,-1*r),e=0;i=o[e];e++)q.helpers.setGenericOpitons.call(this,i.name.toLowerCase(),i.value),console.log(i.name+" = "+i.value);q.helpers.paintSvg.call(this,o)},SVGPathElement:function(t){var e,i,o,r=t.attributes;for(e=0;i=r[e];e++){switch(o=i.name.toLowerCase(),q.helpers.setGenericOpitons.call(this,o,i.value),o){case"d":q.helpers.drawPath.call(this,i.value)}console.log(i.name+" = "+i.value)}q.helpers.paintSvg.call(this,r,!0)}},H=function(t){console.log(t);var e=V[T(t)];e||console.error("Not Supported SVGElement: "+T(t)),"skip"!==e&&(this.pushState(),e.call(this,t),this.popState());for(var i,o=0;i=t.childNodes[o];o++)i instanceof SVGElement&&H.call(this,i)};q.prototype={setSvg:function(t){if(!(t instanceof SVGSVGElement))throw"Element is not an SVGSVGElement";H.call(this,t)},push:function(){return Array.prototype.push.apply(this.content,arguments),this}},i(q,r),i(q,o);var X={doc:function(t,e,i){var o=new f(t,e,i);return{objNum:function(){o.objNumber.apply(o,arguments)},currentPage:function(){return o.page.apply(o,arguments)},createObj:function(){return o.newObj.apply(o,arguments)},createStream:function(){return o.newStream.apply(o,arguments)},addPage:function(){return o.addPage.apply(o,arguments)},addRepeatableElement:function(){return o.addRepeatableElement.apply(o,arguments)},addRepeatableTemplate:function(){return o.addRepeatableTemplate.apply(o,arguments)},root:function(){return o.rootNode.apply(o,arguments)},output:function(){return o.output.apply(o,arguments)},outputAsync:function(){return o.outputAsync.apply(o,arguments)},addFont:function(){return o.addFont.apply(o,arguments)},newImage:function(){return o.newImage.apply(o,arguments)}}},svg:q,obj:s,pageTreeNode:a,utils:B};t.pdfJS=X})(window);