From b3ccdf139d0e8e8a13190e898849c2b2b3233f50 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Wed, 17 Aug 2022 12:00:53 +0100 Subject: [PATCH 1/2] Remove replicated helper function ga - was defined twice, which might conflict with some JS compilers --- src/libs/WebPDecoder.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libs/WebPDecoder.js b/src/libs/WebPDecoder.js index b918f4016..4834a2855 100644 --- a/src/libs/WebPDecoder.js +++ b/src/libs/WebPDecoder.js @@ -3177,9 +3177,6 @@ function WebPDecoder(imageData) { Ga(a, b, c, d, e); d[e + 3] = 255; } - function ga(a, b) { - return 0 > a ? 0 : a > b ? b : a; - } function la(a, b, c) { self[a] = function(a, e, f, g, h, k, l, m, n) { for (var d = m + (n & -2) * c; m != d; ) From 0e60ee85afa9e229cedae10ebacdc0b1a757894e Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Wed, 17 Aug 2022 12:04:15 +0100 Subject: [PATCH 2/2] Replicate changes to dist files --- dist/jspdf.debug.js | 119 +- dist/jspdf.min.js | 18 +- dist/jspdf.node.debug.js | 107 +- dist/jspdf.node.min.js | 16 +- dist/jspdf.worker.debug.js | 25539 +++++++++++++++++++++++++++++++++++ dist/jspdf.worker.min.js | 351 + 6 files changed, 26035 insertions(+), 115 deletions(-) create mode 100644 dist/jspdf.worker.debug.js create mode 100644 dist/jspdf.worker.min.js diff --git a/dist/jspdf.debug.js b/dist/jspdf.debug.js index 2a0469727..fbd966ff2 100644 --- a/dist/jspdf.debug.js +++ b/dist/jspdf.debug.js @@ -6,8 +6,8 @@ /** @license * * jsPDF - PDF Document creation from JavaScript - * Version 2.1.1 Built on 2019-10-11T08:56:17.234Z - * CommitID 0dd01f177e + * Version 1.5.3 Built on 2022-08-17T11:03:43.941Z + * CommitID b3ccdf139d * * Copyright (c) 2010-2018 James Hall , https://github.com/MrRio/jsPDF * 2015-2018 yWorks GmbH, http://www.yworks.com @@ -37,17 +37,13 @@ */ function _typeof(obj) { - if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { - _typeof = function (obj) { - return typeof obj; - }; - } else { - _typeof = function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }; - } + "@babel/helpers - typeof"; - return _typeof(obj); + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }, _typeof(obj); } /** @@ -1420,6 +1416,10 @@ */ var Matrix = function Matrix(sx, shy, shx, sy, tx, ty) { + if (!(this instanceof Matrix)) { + return new Matrix(sx, shy, shx, sy, tx, ty); + } + var _matrix = []; /** * @name sx @@ -1827,8 +1827,13 @@ */ - API.ShadingPattern = function (type, coords, colors, gState, matrix) { - advancedApiModeTrap("ShadingPattern"); // see putPattern() for information how they are realized + API.ShadingPattern = function ShadingPattern(type, coords, colors, gState, matrix) { + advancedApiModeTrap("ShadingPattern"); + + if (!(this instanceof ShadingPattern)) { + return new ShadingPattern(type, coords, colors, gState, matrix); + } // see putPattern() for information how they are realized + this.type = type === "axial" ? 2 : 3; this.coords = coords; @@ -1851,8 +1856,13 @@ */ - API.TilingPattern = function (boundingBox, xStep, yStep, gState, matrix) { + API.TilingPattern = function TilingPattern(boundingBox, xStep, yStep, gState, matrix) { advancedApiModeTrap("TilingPattern"); + + if (!(this instanceof TilingPattern)) { + return new TilingPattern(boundingBox, xStep, yStep, gState, matrix); + } + this.boundingBox = boundingBox; this.xStep = xStep; this.yStep = yStep; @@ -2627,8 +2637,8 @@ for (var patternKey in patterns) { if (patterns.hasOwnProperty(patternKey) && patterns[patternKey] instanceof API.TilingPattern && patterns[patternKey].objectNumber >= 0 && patterns[patternKey].objectNumber < objectOid // prevent cyclic dependencies ) { - out("/" + patternKey + " " + patterns[patternKey].objectNumber + " 0 R"); - } + out("/" + patternKey + " " + patterns[patternKey].objectNumber + " 0 R"); + } } events.publish("putTilingPatternDict"); @@ -3480,7 +3490,7 @@ * * @memberof jsPDF# * @name setPage - * @param {number} page Switch the active page to the page number specified. + * @param {number} page Switch the active page to the page number specified (indexed starting at 1). * @example * doc = jsPDF() * doc.addPage() @@ -3877,7 +3887,6 @@ var lang = options.lang; - //renderingMode var renderingMode = -1; @@ -5500,7 +5509,10 @@ */ - API.GState = function (parameters) { + API.GState = function GState(parameters) { + if (!(this instanceof GState)) { + return new GState(parameters); + } /** * @name GState#opacity * @type {any} @@ -5510,6 +5522,8 @@ * @name GState#stroke-opacity * @type {any} */ + + var supported = "opacity,stroke-opacity".split(","); for (var p in parameters) { @@ -5935,8 +5949,7 @@ * @instance * @param {string} filename The filename including extension. * @param {Object} options An Object with additional options, possible options: 'returnPromise'. - * @returns {jsPDF} jsPDF-instance - */ + * @returns {jsPDF} jsPDF-instance */ API.save = function (filename, options) { @@ -6146,7 +6159,7 @@ * @memberof jsPDF# */ - jsPDF.version = '2.1.1'; + jsPDF.version = '1.5.3'; if (typeof define === "function" && define.amd) { define(function () { @@ -8994,9 +9007,6 @@ globalObj["AcroForm"] = { Appearance: AcroFormAppearance }; - } else { - // eslint-disable-next-line no-console - console.warn("AcroForm-Classes are not populated into global-namespace, because the class-Names exist already. This avoids conflicts with the already used framework."); } jsPDFAPI.AcroFormChoiceField = AcroFormChoiceField; @@ -11125,7 +11135,7 @@ * @param {Integer} [y] top-position for top-left corner of table * @param {Object[]} [data] An array of objects containing key-value pairs corresponding to a row of data. * @param {String[]} [headers] Omit or null to auto-generate headers at a performance cost - * @param {Object} [config.printHeaders] True to print column headers at the top of every page + * @param {Object} [config.printHeaders] True to print column headers at the top of every page * @param {Object} [config.autoSize] True to dynamically set the column widths to match the widest cell value * @param {Object} [config.margins] margin values for left, top, bottom, and width * @param {Object} [config.fontSize] Integer fontSize to use (optional) @@ -11289,10 +11299,16 @@ var padding = this.internal.__cell__.padding; var fontSize = this.internal.__cell__.table_font_size; var scaleFactor = this.internal.scaleFactor; - return Object.keys(model).map(function (value) { - return _typeof(value) === "object" ? value.text : value; - }).map(function (value) { - return this.splitTextToSize(value, columnWidths[value] - padding - padding); + return Object.keys(model).map(function (key) { + return [key, model[key]]; + }).map(function (item) { + var key = item[0]; + var value = item[1]; + return _typeof(value) === "object" ? [key, value.text] : [key, value]; + }).map(function (item) { + var key = item[0]; + var value = item[1]; + return this.splitTextToSize(value, columnWidths[key] - padding - padding); }, this).map(function (value) { return this.getLineHeightFactor() * value.length * fontSize / scaleFactor + padding + padding; }, this).reduce(function (pv, cv) { @@ -13828,7 +13844,8 @@ x: 0, y: 0, html2canvas: {}, - jsPDF: {} + jsPDF: {}, + backgroundColor: "transparent" } }; /* ----- FROM / TO ----- */ @@ -13925,7 +13942,7 @@ right: 0, top: 0, margin: "auto", - backgroundColor: "white" + backgroundColor: this.opt.backgroundColor }; // Set the overlay to hidden (could be changed in the future to provide a print preview). var source = cloneNode(this.prop.src, this.opt.html2canvas.javascriptEnabled); @@ -14972,13 +14989,13 @@ * Color Allowed Interpretation Type Bit Depths - 0 1,2,4,8,16 Each pixel is a grayscale sample. - 2 8,16 Each pixel is an R,G,B triple. - 3 1,2,4,8 Each pixel is a palette index; + 0 1,2,4,8,16 Each pixel is a grayscale sample. + 2 8,16 Each pixel is an R,G,B triple. + 3 1,2,4,8 Each pixel is a palette index; a PLTE chunk must appear. - 4 8,16 Each pixel is a grayscale sample, + 4 8,16 Each pixel is a grayscale sample, followed by an alpha sample. - 6 8,16 Each pixel is an R,G,B triple, + 6 8,16 Each pixel is an R,G,B triple, followed by an alpha sample. */ @@ -15823,6 +15840,8 @@ } else { if (doKerning && _typeof(kerning[char_code]) === "object" && !isNaN(parseInt(kerning[char_code][prior_char_code], 10))) { kerningValue = kerning[char_code][prior_char_code] / kerningFractionOf; + } else { + kerningValue = 0; } output.push((widths[char_code] || default_char_width) / widthsFractionOf + kerningValue); @@ -16555,10 +16574,10 @@ } // if only one is set, that value is set as max and SVG // is scaled proportionately. else if (w) { - scale = [w / svgw, w / svgw]; - } else if (h) { - scale = [h / svgh, h / svgh]; - } + scale = [w / svgw, w / svgw]; + } else if (h) { + scale = [h / svgh, h / svgh]; + } } var i, @@ -19055,13 +19074,13 @@ utf8.push(0xe0 | charcode >> 12, 0x80 | charcode >> 6 & 0x3f, 0x80 | charcode & 0x3f); } // surrogate pair else { - i++; // UTF-16 encodes 0x10000-0x10FFFF by - // subtracting 0x10000 and splitting the - // 20 bits of 0x0-0xFFFFF into two halves + i++; // UTF-16 encodes 0x10000-0x10FFFF by + // subtracting 0x10000 and splitting the + // 20 bits of 0x0-0xFFFFF into two halves - charcode = 0x10000 + ((charcode & 0x3ff) << 10 | str.charCodeAt(i) & 0x3ff); - utf8.push(0xf0 | charcode >> 18, 0x80 | charcode >> 12 & 0x3f, 0x80 | charcode >> 6 & 0x3f, 0x80 | charcode & 0x3f); - } + charcode = 0x10000 + ((charcode & 0x3ff) << 10 | str.charCodeAt(i) & 0x3ff); + utf8.push(0xf0 | charcode >> 18, 0x80 | charcode >> 12 & 0x3f, 0x80 | charcode >> 6 & 0x3f, 0x80 | charcode & 0x3f); + } } return utf8; @@ -25461,10 +25480,6 @@ d[e + 3] = 255; } - function ga(a, b) { - return 0 > a ? 0 : a > b ? b : a; - } - function la(a, b, c) { self[a] = function (a, e, f, g, h, k, l, m, n) { for (var d = m + (n & -2) * c; m != d;) { diff --git a/dist/jspdf.min.js b/dist/jspdf.min.js index 0f53a8fb3..cf20d6715 100644 --- a/dist/jspdf.min.js +++ b/dist/jspdf.min.js @@ -2,8 +2,8 @@ /** @license * * jsPDF - PDF Document creation from JavaScript - * Version 2.1.1 Built on 2019-10-11T08:56:17.234Z - * CommitID 0dd01f177e + * Version 1.5.3 Built on 2022-08-17T11:03:43.941Z + * CommitID b3ccdf139d * * Copyright (c) 2010-2018 James Hall , https://github.com/MrRio/jsPDF * 2015-2018 yWorks GmbH, http://www.yworks.com @@ -30,14 +30,14 @@ * Contributor(s): * siefkenj, ahwolf, rickygu, Midnith, saintclair, eaparango, * kim3er, mfo, alnorth, Flamenco - */function on(t){return(on="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}!function(t){if("object"!==on(t.console)){t.console={};for(var e,n,r=t.console,i=function(){},a=["memory"],o="assert,clear,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn".split(",");e=a.pop();)r[e]||(r[e]={});for(;n=o.pop();)r[n]||(r[n]=i)}var s,u,l,c,h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function f(){}void 0===t.btoa&&(t.btoa=function(t){var e,n,r,i,a,o=0,s=0,u="",l=[];if(!t)return t;for(;e=(a=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,n=a>>12&63,r=a>>6&63,i=63&a,l[s++]=h.charAt(e)+h.charAt(n)+h.charAt(r)+h.charAt(i),o>16&255,n=o>>8&255,r=255&o,l[u++]=64==i?String.fromCharCode(e):64==a?String.fromCharCode(e,n):String.fromCharCode(e,n,r),s>>0,r=new Array(n),i=1>>0,i=0;if(2<=arguments.length)e=arguments[1];else{for(;i>>0,i=0;if(2<=arguments.length)e=arguments[1];else{for(;i>>0,i=0;i>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var r=arguments[1],i=0;i>18&63,n=a>>12&63,r=a>>6&63,i=63&a,l[s++]=h.charAt(e)+h.charAt(n)+h.charAt(r)+h.charAt(i),o>16&255,n=o>>8&255,r=255&o,l[u++]=64==i?String.fromCharCode(e):64==a?String.fromCharCode(e,n):String.fromCharCode(e,n,r),s>>0,r=new Array(n),i=1>>0,i=0;if(2<=arguments.length)e=arguments[1];else{for(;i>>0,i=0;if(2<=arguments.length)e=arguments[1];else{for(;i>>0,i=0;i>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var r=arguments[1],i=0;it[u+1].offset;)u++;var c=t[u].offset,h=(n-c)/(t[u+1].offset-c),f=t[u].color,d=t[u+1].color;s+=B(Math.round((1-h)*f[0]+h*d[0]).toString(16))+B(Math.round((1-h)*f[1]+h*d[1]).toString(16))+B(Math.round((1-h)*f[2]+h*d[2]).toString(16))}return s.trim()}(t.colors,e),i=[];i.push({key:"FunctionType",value:"0"}),i.push({key:"Domain",value:"[0.0 1.0]"}),i.push({key:"Size",value:"["+e+"]"}),i.push({key:"BitsPerSample",value:"8"}),i.push({key:"Range",value:"[0.0 1.0 0.0 1.0 0.0 1.0]"}),i.push({key:"Decode",value:"[0.0 1.0 0.0 1.0 0.0 1.0]"}),ee({data:r,additionalKeyValues:i,alreadyAppliedFilters:["/ASCIIHexDecode"]}),st("endobj"),t.objectNumber=Gt(),st("<< /ShadingType "+t.type),st("/ColorSpace /DeviceRGB");var a="/Coords ["+at(parseFloat(t.coords[0]))+" "+at(parseFloat(t.coords[1]))+" ";2===t.type?a+=at(parseFloat(t.coords[2]))+" "+at(parseFloat(t.coords[3])):a+=at(parseFloat(t.coords[2]))+" "+at(parseFloat(t.coords[3]))+" "+at(parseFloat(t.coords[4]))+" "+at(parseFloat(t.coords[5])),st(a+="]"),t.matrix&&st("/Matrix ["+t.matrix.toString()+"]"),st("/Function "+n+" 0 R"),st("/Extend [true true]"),st(">>"),st("endobj")}function Mt(t,e){var n=Yt(),r=Gt();e.push({resourcesOid:n,objectOid:r}),t.objectNumber=r;var i=[];i.push({key:"Type",value:"/Pattern"}),i.push({key:"PatternType",value:"1"}),i.push({key:"PaintType",value:"1"}),i.push({key:"TilingType",value:"1"}),i.push({key:"BBox",value:"["+t.boundingBox.map(at).join(" ")+"]"}),i.push({key:"XStep",value:at(t.xStep)}),i.push({key:"YStep",value:at(t.yStep)}),i.push({key:"Resources",value:n+" 0 R"}),t.matrix&&i.push({key:"Matrix",value:"["+t.matrix.toString()+"]"}),ee({data:t.stream,additionalKeyValues:i}),st("endobj")}function Tt(t){for(var e in t.objectNumber=Gt(),st("<<"),t)switch(e){case"opacity":st("/ca "+x(t[e]));break;case"stroke-opacity":st("/CA "+x(t[e]))}st(">>"),st("endobj")}function qt(t){Jt(t.resourcesOid,!0),st("<<"),st("/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]"),function(){for(var t in st("/Font <<"),pt)!pt.hasOwnProperty(t)||(!1===c||!0===c&&et.hasOwnProperty(t))&&st("/"+t+" "+pt[t].objectNumber+" 0 R");st(">>")}(),function(){if(0>")}}(),function(t){if(0>")}}(t.objectOid),function(){if(0>")}}(),function(){for(var t in st("/XObject <<"),St)St.hasOwnProperty(t)&&0<=St[t].objectNumber&&st("/"+t+" "+St[t].objectNumber+" 0 R");At.publish("putXobjectDict"),st(">>")}(),st(">>"),st("endobj")}function Rt(){var t=[];!function(){for(var t in pt)!pt.hasOwnProperty(t)||(!1===c||!0===c&&et.hasOwnProperty(t))&&(n=pt[t],At.publish("putFont",{font:n,out:st,newObject:Gt,putStream:ee,pdfEscapeWithNeededParanthesis:e}),!0!==n.isAlreadyPutted&&(n.objectNumber=Gt(),st("<<"),st("/Type /Font"),st("/BaseFont /"+e(n.postScriptName)),st("/Subtype /Type1"),"string"==typeof n.encoding&&st("/Encoding /"+n.encoding),st("/FirstChar 32"),st("/LastChar 255"),st(">>"),st("endobj")));function e(t,e){return-1!==t.indexOf(" ")?"("+ie(t,e)+")":ie(t,e)}var n}(),function(){var t;for(t in yt)yt.hasOwnProperty(t)&&Tt(yt[t])}(),function(){for(var t in St)St.hasOwnProperty(t)&&Ot(St[t])}(),function(t){var e;for(e in bt)bt.hasOwnProperty(e)&&(bt[e]instanceof h.ShadingPattern?Et(bt[e]):bt[e]instanceof h.TilingPattern&&Mt(bt[e],t))}(t),At.publish("putResources"),t.forEach(qt),qt({resourcesOid:Zt,objectOid:Number.MAX_SAFE_INTEGER}),At.publish("postPutResources")}function Dt(t){gt[t.fontName]=gt[t.fontName]||{},gt[t.fontName][t.fontStyle]=t.id}function Ut(t,e,n,r,i){var a={id:"F"+(Object.keys(pt).length+1).toString(10),postScriptName:t,fontName:e,fontStyle:n,encoding:r,isStandardFont:i||!1,metadata:{}};return At.publish("addFont",{font:a,instance:this}),pt[a.id]=a,Dt(a),a.id}function zt(t,e){var n,r,i;switch(a=e||a,"string"==typeof t&&(n=g(t.toLowerCase()),Array.isArray(n)&&(r=n[0],i=n[1])),Array.isArray(t)&&(r=t[0]*tt,i=t[1]*tt),isNaN(r)&&(r=o[0],i=o[1]),(14400>16&255,r=u>>8&255,i=255&u}if(void 0===r||void 0===a&&n===r&&r===i)if("string"==typeof n)e=n+" "+o[0];else switch(t.precision){case 2:e=x(n/255)+" "+o[0];break;case 3:default:e=N(n/255)+" "+o[0]}else if(void 0===a||"object"===on(a)){if(a&&!isNaN(a.a)&&0===a.a)return e=["1.","1.","1.",o[1]].join(" ");if("string"==typeof n)e=[n,r,i,o[1]].join(" ");else switch(t.precision){case 2:e=[x(n/255),x(r/255),x(i/255),o[1]].join(" ");break;default:case 3:e=[N(n/255),N(r/255),N(i/255),o[1]].join(" ")}}else if("string"==typeof n)e=[n,r,i,a,o[2]].join(" ");else switch(t.precision){case 2:e=[x(n),x(r),x(i),x(a),o[2]].join(" ");break;case 3:default:e=[N(n),N(r),N(i),N(a),o[2]].join(" ")}return e},te=h.__private__.getFilters=function(){return i},ee=h.__private__.putStream=function(t){var e=(t=t||{}).data||"",n=t.filters||te(),r=t.alreadyAppliedFilters||[],i=t.addLength1||!1,a=e.length,o={};!0===n&&(n=["FlateEncode"]);var s=t.additionalKeyValues||[],u=(o=void 0!==ln.API.processDataByFilters?ln.API.processDataByFilters(e,n):{data:e,reverseChain:[]}).reverseChain+(Array.isArray(r)?r.join(" "):r.toString());if(0!==o.data.length&&(s.push({key:"Length",value:o.data.length}),!0===i&&s.push({key:"Length1",value:a})),0!=u.length)if(u.split("/").length-1==1)s.push({key:"Filter",value:u});else{s.push({key:"Filter",value:"["+u+"]"});for(var l=0;l>"),0!==o.data.length&&(st("stream"),st(o.data),st("endstream"))},ne=h.__private__.putPage=function(t){var e=t.number,n=t.data,r=t.objId,i=t.contentsObjId;Jt(r,!0),st("<>"),st("endobj");var a=n.join("\n");return rt===nt&&(a+="\nQ"),Jt(i,!0),ee({data:a,filters:te()}),st("endobj"),r},re=h.__private__.putPages=function(){var t,e,n=[];for(t=1;t<=Nt;t++)Lt[t].objId=Yt(),Lt[t].contentsObjId=Yt();for(t=1;t<=Nt;t++)n.push(ne({number:t,data:R[t],objId:Lt[t].objId,contentsObjId:Lt[t].contentsObjId,mediaBox:Lt[t].mediaBox,cropBox:Lt[t].cropBox,bleedBox:Lt[t].bleedBox,trimBox:Lt[t].trimBox,artBox:Lt[t].artBox,userUnit:Lt[t].userUnit,rootDictionaryObjId:Kt,resourceDictionaryObjId:Zt}));Jt(Kt,!0),st("<>"),st("endobj"),At.publish("postPutPages")},ie=h.__private__.pdfEscape=h.pdfEscape=function(t,e){return function(t,e){var n,r,i,a,o,s,u,l,c;if(i=(e=e||{}).sourceEncoding||"Unicode",o=e.outputEncoding,(e.autoencode||o)&&pt[ct].metadata&&pt[ct].metadata[i]&&pt[ct].metadata[i].encoding&&(a=pt[ct].metadata[i].encoding,!o&&pt[ct].encoding&&(o=pt[ct].encoding),!o&&a.codePages&&(o=a.codePages[0]),"string"==typeof o&&(o=a[o]),o)){for(u=!1,s=[],n=0,r=t.length;n>8&&(u=!0);t=s.join("")}for(n=t.length;void 0===u&&0!==n;)t.charCodeAt(n-1)>>8&&(u=!0),n--;if(!u)return t;for(s=e.noBOM?[]:[254,255],n=0,r=t.length;n>8)>>8)throw new Error("Character at position "+n+" of string '"+t+"' exceeds 16bits. Cannot be encoded into UCS-2 BE");s.push(c),s.push(l-(c<<8))}return String.fromCharCode.apply(void 0,s)}(t,e).replace(/\\/g,"\\\\").replace(/\(/g,"\\(").replace(/\)/g,"\\)")},ae=h.__private__.beginPage=function(t){R[++Nt]=[],Lt[Nt]={objId:0,contentsObjId:0,userUnit:Number(s),artBox:null,bleedBox:null,cropBox:null,trimBox:null,mediaBox:{bottomLeftX:0,bottomLeftY:0,topRightX:Number(t[0]),topRightY:Number(t[1])}},oe(Nt),z(R[I])},oe=function(t){0>"),st("endobj")},le=h.__private__.putCatalog=function(t){var e=(t=t||{}).rootDictionaryObjId||Kt;switch(Gt(),st("<<"),st("/Type /Catalog"),st("/Pages "+e+" 0 R"),G||(G="fullwidth"),G){case"fullwidth":st("/OpenAction [3 0 R /FitH null]");break;case"fullheight":st("/OpenAction [3 0 R /FitV null]");break;case"fullpage":st("/OpenAction [3 0 R /Fit]");break;case"original":st("/OpenAction [3 0 R /XYZ null null 1]");break;default:var n=""+G;"%"===n.substr(n.length-1)&&(G=parseInt(G)/100),"number"==typeof G&&st("/OpenAction [3 0 R /XYZ null null "+x(G)+"]")}switch(K||(K="continuous"),K){case"continuous":st("/PageLayout /OneColumn");break;case"single":st("/PageLayout /SinglePage");break;case"two":case"twoleft":st("/PageLayout /TwoColumnLeft");break;case"tworight":st("/PageLayout /TwoColumnRight")}J&&st("/PageMode /"+J),At.publish("putCatalog"),st(">>"),st("endobj")},ce=h.__private__.putTrailer=function(){st("trailer"),st("<<"),st("/Size "+(O+1)),st("/Root "+O+" 0 R"),st("/Info "+(O-1)+" 0 R"),st("/ID [ <"+A+"> <"+A+"> ]"),st(">>")},he=h.__private__.putHeader=function(){st("%PDF-"+f),st("%ºß¬à")},fe=h.__private__.putXRef=function(){var t="0000000000";st("xref"),st("0 "+(O+1)),st("0000000000 65535 f");for(var e=1;e<=O;e++){"function"==typeof E[e]?st((t+E[e]()).slice(-10)+" 00000 n"):void 0!==E[e]?st((t+E[e]).slice(-10)+" 00000 n"):st("0000000000 00000 n")}},de=h.__private__.buildDocument=function(){T=O=0,M=[],E=[],q=[],Kt=Yt(),Zt=Yt(),z(M),At.publish("buildDocument"),he(),re(),function(){At.publish("putAdditionalObjects");for(var t=0;t<\/script>"; + var nW = global.open(); + + if (nW !== null) { + nW.document.write(htmlForNewWindow); + } + + return nW; + } else { + throw new Error("The option pdfobjectnewwindow just works in a browser-environment."); + } + + case "pdfjsnewwindow": + if (Object.prototype.toString.call(global) === "[object Window]") { + var pdfJsUrl = options.pdfJsUrl || "examples/PDF.js/web/viewer.html"; + var htmlForPDFjsNewWindow = "" + "" + '' + ""; + var dataURLNewWindow = global.open(); + + if (dataURLNewWindow !== null) { + dataURLNewWindow.document.write(htmlForDataURLNewWindow); + } + + if (dataURLNewWindow || typeof safari === "undefined") { return dataURLNewWindow; } + } else { + throw new Error("The option dataurlnewwindow just works in a browser-environment."); + } + + break; + + case "datauri": + case "dataurl": + return global.document.location.href = this.output("datauristring", options); + + default: + return null; + } + }); + /** + * Used to see if a supplied hotfix was requested when the pdf instance was created. + * @param {string} hotfixName - The name of the hotfix to check. + * @returns {boolean} + */ + + var hasHotfix = function hasHotfix(hotfixName) { + return Array.isArray(hotfixes) === true && hotfixes.indexOf(hotfixName) > -1; + }; + + switch (unit) { + case "pt": + scaleFactor = 1; + break; + + case "mm": + scaleFactor = 72 / 25.4; + break; + + case "cm": + scaleFactor = 72 / 2.54; + break; + + case "in": + scaleFactor = 72; + break; + + case "px": + if (hasHotfix("px_scaling") == true) { + scaleFactor = 72 / 96; + } else { + scaleFactor = 96 / 72; + } + + break; + + case "pc": + scaleFactor = 12; + break; + + case "em": + scaleFactor = 12; + break; + + case "ex": + scaleFactor = 6; + break; + + default: + throw new Error("Invalid unit: " + unit); + } + + setCreationDate(); + setFileId(); //--------------------------------------- + // Public API + + var getPageInfo = API.__private__.getPageInfo = API.getPageInfo = function (pageNumberOneBased) { + if (isNaN(pageNumberOneBased) || pageNumberOneBased % 1 !== 0) { + throw new Error("Invalid argument passed to jsPDF.getPageInfo"); + } + + var objId = pagesContext[pageNumberOneBased].objId; + return { + objId: objId, + pageNumber: pageNumberOneBased, + pageContext: pagesContext[pageNumberOneBased] + }; + }; + + var getPageInfoByObjId = API.__private__.getPageInfoByObjId = function (objId) { + if (isNaN(objId) || objId % 1 !== 0) { + throw new Error("Invalid argument passed to jsPDF.getPageInfoByObjId"); + } + + for (var pageNumber in pagesContext) { + if (pagesContext[pageNumber].objId === objId) { + break; + } + } + + return getPageInfo(pageNumber); + }; + + var getCurrentPageInfo = API.__private__.getCurrentPageInfo = API.getCurrentPageInfo = function () { + return { + objId: pagesContext[currentPage].objId, + pageNumber: currentPage, + pageContext: pagesContext[currentPage] + }; + }; + /** + * Adds (and transfers the focus to) new page to the PDF document. + * @param format {String/Array} The format of the new page. Can be:
  • a0 - a10
  • b0 - b10
  • c0 - c10
  • dl
  • letter
  • government-letter
  • legal
  • junior-legal
  • ledger
  • tabloid
  • credit-card

+ * Default is "a4". If you want to use your own format just pass instead of one of the above predefined formats the size as an number-array, e.g. [595.28, 841.89] + * @param orientation {string} Orientation of the new page. Possible values are "portrait" or "landscape" (or shortcuts "p" (Default), "l"). + * @function + * @instance + * @returns {jsPDF} + * + * @memberof jsPDF# + * @name addPage + */ + + + API.addPage = function () { + _addPage.apply(this, arguments); + + return this; + }; + /** + * Adds (and transfers the focus to) new page to the PDF document. + * @function + * @instance + * @returns {jsPDF} + * + * @memberof jsPDF# + * @name setPage + * @param {number} page Switch the active page to the page number specified (indexed starting at 1). + * @example + * doc = jsPDF() + * doc.addPage() + * doc.addPage() + * doc.text('I am on page 3', 10, 10) + * doc.setPage(1) + * doc.text('I am on page 1', 10, 10) + */ + + + API.setPage = function () { + _setPage.apply(this, arguments); + + setOutputDestination.call(this, pages[currentPage]); + return this; + }; + /** + * @name insertPage + * @memberof jsPDF# + * + * @function + * @instance + * @param {Object} beforePage + * @returns {jsPDF} + */ + + + API.insertPage = function (beforePage) { + this.addPage(); + this.movePage(currentPage, beforePage); + return this; + }; + /** + * @name movePage + * @memberof jsPDF# + * @function + * @instance + * @param {number} targetPage + * @param {number} beforePage + * @returns {jsPDF} + */ + + + API.movePage = function (targetPage, beforePage) { + var tmpPages, tmpPagesContext; + + if (targetPage > beforePage) { + tmpPages = pages[targetPage]; + tmpPagesContext = pagesContext[targetPage]; + + for (var i = targetPage; i > beforePage; i--) { + pages[i] = pages[i - 1]; + pagesContext[i] = pagesContext[i - 1]; + } + + pages[beforePage] = tmpPages; + pagesContext[beforePage] = tmpPagesContext; + this.setPage(beforePage); + } else if (targetPage < beforePage) { + tmpPages = pages[targetPage]; + tmpPagesContext = pagesContext[targetPage]; + + for (var j = targetPage; j < beforePage; j++) { + pages[j] = pages[j + 1]; + pagesContext[j] = pagesContext[j + 1]; + } + + pages[beforePage] = tmpPages; + pagesContext[beforePage] = tmpPagesContext; + this.setPage(beforePage); + } + + return this; + }; + /** + * Deletes a page from the PDF. + * @name deletePage + * @memberof jsPDF# + * @function + * @param {number} targetPage + * @instance + * @returns {jsPDF} + */ + + + API.deletePage = function () { + _deletePage.apply(this, arguments); + + return this; + }; + /** + * Adds text to page. Supports adding multiline text when 'text' argument is an Array of Strings. + * + * @function + * @instance + * @param {String|Array} text String or array of strings to be added to the page. Each line is shifted one line down per font, spacing settings declared before this call. + * @param {number} x Coordinate (in units declared at inception of PDF document) against left edge of the page. + * @param {number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page. + * @param {Object} [options] - Collection of settings signaling how the text must be encoded. + * @param {string} [options.align=left] - The alignment of the text, possible values: left, center, right, justify. + * @param {string} [options.baseline=alphabetic] - Sets text baseline used when drawing the text, possible values: alphabetic, ideographic, bottom, top, middle, hanging + * @param {string} [options.angle=0] - Rotate the text clockwise or counterclockwise. Expects the angle in degree. + * @param {string} [options.rotationDirection=1] - Direction of the rotation. 0 = clockwise, 1 = counterclockwise. + * @param {string} [options.charSpace=0] - The space between each letter. + * @param {string} [options.lineHeightFactor=1.15] - The lineheight of each line. + * @param {string} [options.flags] - Flags for to8bitStream. + * @param {string} [options.flags.noBOM=true] - Don't add BOM to Unicode-text. + * @param {string} [options.flags.autoencode=true] - Autoencode the Text. + * @param {string} [options.maxWidth=0] - Split the text by given width, 0 = no split. + * @param {string} [options.renderingMode=fill] - Set how the text should be rendered, possible values: fill, stroke, fillThenStroke, invisible, fillAndAddForClipping, strokeAndAddPathForClipping, fillThenStrokeAndAddToPathForClipping, addToPathForClipping. + * @param {boolean} [options.isInputVisual] - Option for the BidiEngine + * @param {boolean} [options.isOutputVisual] - Option for the BidiEngine + * @param {boolean} [options.isInputRtl] - Option for the BidiEngine + * @param {boolean} [options.isOutputRtl] - Option for the BidiEngine + * @param {boolean} [options.isSymmetricSwapping] - Option for the BidiEngine + * @param {number|Matrix} transform If transform is a number the text will be rotated by this value around the anchor set by x and y. + * + * If it is a Matrix, this matrix gets directly applied to the text, which allows shearing + * effects etc.; the x and y offsets are then applied AFTER the coordinate system has been established by this + * matrix. This means passing a rotation matrix that is equivalent to some rotation angle will in general yield a + * DIFFERENT result. A matrix is only allowed in "advanced" API mode. + * @returns {jsPDF} + * @memberof jsPDF# + * @name text + */ + + + API.__private__.text = API.text = function (text, x, y, options, transform) { + /* + * Inserts something like this into PDF + * BT + * /F1 16 Tf % Font name + size + * 16 TL % How many units down for next line in multiline text + * 0 g % color + * 28.35 813.54 Td % position + * (line one) Tj + * T* (line two) Tj + * T* (line three) Tj + * ET + */ + options = options || {}; + var scope = options.scope || this; + var payload, da, angle, align, charSpace, maxWidth, flags; // Pre-August-2012 the order of arguments was function(x, y, text, flags) + // in effort to make all calls have similar signature like + // function(data, coordinates... , miscellaneous) + // this method had its args flipped. + // code below allows backward compatibility with old arg order. + + if (typeof text === "number" && typeof x === "number" && (typeof y === "string" || Array.isArray(y))) { + var tmp = y; + y = x; + x = text; + text = tmp; + } + + var transformationMatrix; + + if (arguments[3] instanceof Matrix === false) { + flags = arguments[3]; + angle = arguments[4]; + align = arguments[5]; + + if (_typeof(flags) !== "object" || flags === null) { + if (typeof angle === "string") { + align = angle; + angle = null; + } + + if (typeof flags === "string") { + align = flags; + flags = null; + } + + if (typeof flags === "number") { + angle = flags; + flags = null; + } + + options = { + flags: flags, + angle: angle, + align: align + }; + } + } else { + advancedApiModeTrap("The transform parameter of text() with a Matrix value"); + transformationMatrix = transform; + } + + if (isNaN(x) || isNaN(y) || typeof text === "undefined" || text === null) { + throw new Error("Invalid arguments passed to jsPDF.text"); + } + + if (text.length === 0) { + return scope; + } + + var xtra = ""; + var isHex = false; + var lineHeight = typeof options.lineHeightFactor === "number" ? options.lineHeightFactor : lineHeightFactor; + var scaleFactor = scope.internal.scaleFactor; + + function ESC(s) { + s = s.split("\t").join(Array(options.TabLen || 9).join(" ")); + return pdfEscape(s, flags); + } + + function transformTextToSpecialArray(text) { + //we don't want to destroy original text array, so cloning it + var sa = text.concat(); + var da = []; + var len = sa.length; + var curDa; //we do array.join('text that must not be PDFescaped") + //thus, pdfEscape each component separately + + while (len--) { + curDa = sa.shift(); + + if (typeof curDa === "string") { + da.push(curDa); + } else { + if (Array.isArray(text) && (curDa.length === 1 || curDa[1] === undefined && curDa[2] === undefined)) { + da.push(curDa[0]); + } else { + da.push([curDa[0], curDa[1], curDa[2]]); + } + } + } + + return da; + } + + function processTextByFunction(text, processingFunction) { + var result; + + if (typeof text === "string") { + result = processingFunction(text)[0]; + } else if (Array.isArray(text)) { + //we don't want to destroy original text array, so cloning it + var sa = text.concat(); + var da = []; + var len = sa.length; + var curDa; + var tmpResult; //we do array.join('text that must not be PDFescaped") + //thus, pdfEscape each component separately + + while (len--) { + curDa = sa.shift(); + + if (typeof curDa === "string") { + da.push(processingFunction(curDa)[0]); + } else if (Array.isArray(curDa) && typeof curDa[0] === "string") { + tmpResult = processingFunction(curDa[0], curDa[1], curDa[2]); + da.push([tmpResult[0], tmpResult[1], tmpResult[2]]); + } + } + + result = da; + } + + return result; + } //Check if text is of type String + + + var textIsOfTypeString = false; + var tmpTextIsOfTypeString = true; + + if (typeof text === "string") { + textIsOfTypeString = true; + } else if (Array.isArray(text)) { + //we don't want to destroy original text array, so cloning it + var sa = text.concat(); + da = []; + var len = sa.length; + var curDa; //we do array.join('text that must not be PDFescaped") + //thus, pdfEscape each component separately + + while (len--) { + curDa = sa.shift(); + + if (typeof curDa !== "string" || Array.isArray(curDa) && typeof curDa[0] !== "string") { + tmpTextIsOfTypeString = false; + } + } + + textIsOfTypeString = tmpTextIsOfTypeString; + } + + if (textIsOfTypeString === false) { + throw new Error('Type of text must be string or Array. "' + text + '" is not recognized.'); + } //If there are any newlines in text, we assume + //the user wanted to print multiple lines, so break the + //text up into an array. If the text is already an array, + //we assume the user knows what they are doing. + //Convert text into an array anyway to simplify + //later code. + + + if (typeof text === "string") { + if (text.match(/[\r?\n]/)) { + text = text.split(/\r\n|\r|\n/g); + } else { + text = [text]; + } + } //baseline + + + var height = activeFontSize / scope.internal.scaleFactor; + var descent = height * (lineHeightFactor - 1); + + switch (options.baseline) { + case "bottom": + y -= descent; + break; + + case "top": + y += height - descent; + break; + + case "hanging": + y += height - 2 * descent; + break; + + case "middle": + y += height / 2 - descent; + break; + + case "ideographic": + case "alphabetic": + default: + // do nothing, everything is fine + break; + } //multiline + + + maxWidth = options.maxWidth || 0; + + if (maxWidth > 0) { + if (typeof text === "string") { + text = scope.splitTextToSize(text, maxWidth); + } else if (Object.prototype.toString.call(text) === "[object Array]") { + text = scope.splitTextToSize(text.join(" "), maxWidth); + } + } //creating Payload-Object to make text byRef + + + payload = { + text: text, + x: x, + y: y, + options: options, + mutex: { + pdfEscape: pdfEscape, + activeFontKey: activeFontKey, + fonts: fonts, + activeFontSize: activeFontSize + } + }; + events.publish("preProcessText", payload); + text = payload.text; + options = payload.options; //angle + + angle = options.angle; + + if (transformationMatrix instanceof Matrix === false && angle && typeof angle === "number") { + angle *= Math.PI / 180; + + if (options.rotationDirection === 0) { + angle = -angle; + } + + if (apiMode === ApiMode.ADVANCED) { + angle = -angle; + } + + var c = Math.cos(angle); + var s = Math.sin(angle); + transformationMatrix = new Matrix(c, s, -s, c, 0, 0); + } else if (angle && angle instanceof Matrix) { + transformationMatrix = angle; + } + + if (apiMode === ApiMode.ADVANCED && !transformationMatrix) { + transformationMatrix = identityMatrix; + } //charSpace + + + charSpace = options.charSpace || activeCharSpace; + + if (typeof charSpace !== "undefined") { + xtra += hpf(scale(charSpace)) + " Tc\n"; + this.setCharSpace(this.getCharSpace() || 0); + } //lang + + + var lang = options.lang; + + + var renderingMode = -1; + var parmRenderingMode = typeof options.renderingMode !== "undefined" ? options.renderingMode : options.stroke; + var pageContext = scope.internal.getCurrentPageInfo().pageContext; + + switch (parmRenderingMode) { + case 0: + case false: + case "fill": + renderingMode = 0; + break; + + case 1: + case true: + case "stroke": + renderingMode = 1; + break; + + case 2: + case "fillThenStroke": + renderingMode = 2; + break; + + case 3: + case "invisible": + renderingMode = 3; + break; + + case 4: + case "fillAndAddForClipping": + renderingMode = 4; + break; + + case 5: + case "strokeAndAddPathForClipping": + renderingMode = 5; + break; + + case 6: + case "fillThenStrokeAndAddToPathForClipping": + renderingMode = 6; + break; + + case 7: + case "addToPathForClipping": + renderingMode = 7; + break; + } + + var usedRenderingMode = typeof pageContext.usedRenderingMode !== "undefined" ? pageContext.usedRenderingMode : -1; //if the coder wrote it explicitly to use a specific + //renderingMode, then use it + + if (renderingMode !== -1) { + xtra += renderingMode + " Tr\n"; //otherwise check if we used the rendering Mode already + //if so then set the rendering Mode... + } else if (usedRenderingMode !== -1) { + xtra += "0 Tr\n"; + } + + if (renderingMode !== -1) { + pageContext.usedRenderingMode = renderingMode; + } //align + + + align = options.align || "left"; + var leading = activeFontSize * lineHeight; + var pageWidth = scope.internal.pageSize.getWidth(); + var activeFont = fonts[activeFontKey]; + charSpace = options.charSpace || activeCharSpace; + maxWidth = options.maxWidth || 0; + var lineWidths; + flags = {}; + var wordSpacingPerLine = []; + + if (Object.prototype.toString.call(text) === "[object Array]") { + da = transformTextToSpecialArray(text); + var newY; + + if (align !== "left") { + lineWidths = da.map(function (v) { + return scope.getStringUnitWidth(v, { + font: activeFont, + charSpace: charSpace, + fontSize: activeFontSize, + doKerning: false + }) * activeFontSize / scaleFactor; + }); + } //The first line uses the "main" Td setting, + //and the subsequent lines are offset by the + //previous line's x coordinate. + + + var prevWidth = 0; + var newX; + + if (align === "right") { + //The passed in x coordinate defines the + //rightmost point of the text. + x -= lineWidths[0]; + text = []; + len = da.length; + + for (var i = 0; i < len; i++) { + if (i === 0) { + newX = getHorizontalCoordinate(x); + newY = getVerticalCoordinate(y); + } else { + newX = scale(prevWidth - lineWidths[i]); + newY = -leading; + } + + text.push([da[i], newX, newY]); + prevWidth = lineWidths[i]; + } + } else if (align === "center") { + //The passed in x coordinate defines + //the center point. + x -= lineWidths[0] / 2; + text = []; + len = da.length; + + for (var j = 0; j < len; j++) { + if (j === 0) { + newX = getHorizontalCoordinate(x); + newY = getVerticalCoordinate(y); + } else { + newX = scale((prevWidth - lineWidths[j]) / 2); + newY = -leading; + } + + text.push([da[j], newX, newY]); + prevWidth = lineWidths[j]; + } + } else if (align === "left") { + text = []; + len = da.length; + + for (var h = 0; h < len; h++) { + text.push(da[h]); + } + } else if (align === "justify") { + text = []; + len = da.length; + maxWidth = maxWidth !== 0 ? maxWidth : pageWidth; + + for (var l = 0; l < len; l++) { + newY = l === 0 ? getVerticalCoordinate(y) : -leading; + newX = l === 0 ? getHorizontalCoordinate(x) : 0; + + if (l < len - 1) { + wordSpacingPerLine.push(hpf(scale((maxWidth - lineWidths[l]) / (da[l].split(" ").length - 1)))); + } + + text.push([da[l], newX, newY]); + } + } else { + throw new Error('Unrecognized alignment option, use "left", "center", "right" or "justify".'); + } + } //R2L + + + var doReversing = typeof options.R2L === "boolean" ? options.R2L : R2L; + + if (doReversing === true) { + text = processTextByFunction(text, function (text, posX, posY) { + return [text.split("").reverse().join(""), posX, posY]; + }); + } //creating Payload-Object to make text byRef + + + payload = { + text: text, + x: x, + y: y, + options: options, + mutex: { + pdfEscape: pdfEscape, + activeFontKey: activeFontKey, + fonts: fonts, + activeFontSize: activeFontSize + } + }; + events.publish("postProcessText", payload); + text = payload.text; + isHex = payload.mutex.isHex || false; //Escaping + + var activeFontEncoding = fonts[activeFontKey].encoding; + + if (activeFontEncoding === "WinAnsiEncoding" || activeFontEncoding === "StandardEncoding") { + text = processTextByFunction(text, function (text, posX, posY) { + return [ESC(text), posX, posY]; + }); + } + + da = transformTextToSpecialArray(text); + text = []; + var STRING = 0; + var ARRAY = 1; + var variant = Array.isArray(da[0]) ? ARRAY : STRING; + var posX; + var posY; + var content; + var wordSpacing = ""; + + var generatePosition = function generatePosition(parmPosX, parmPosY, parmTransformationMatrix) { + var position = ""; + + if (parmTransformationMatrix instanceof Matrix) { + // It is kind of more intuitive to apply a plain rotation around the text anchor set by x and y + // but when the user supplies an arbitrary transformation matrix, the x and y offsets should be applied + // in the coordinate system established by this matrix + if (typeof options.angle === "number") { + parmTransformationMatrix = matrixMult(parmTransformationMatrix, new Matrix(1, 0, 0, 1, parmPosX, parmPosY)); + } else { + parmTransformationMatrix = matrixMult(new Matrix(1, 0, 0, 1, parmPosX, parmPosY), parmTransformationMatrix); + } + + if (apiMode === ApiMode.ADVANCED) { + parmTransformationMatrix = matrixMult(new Matrix(1, 0, 0, -1, 0, 0), parmTransformationMatrix); + } + + position = parmTransformationMatrix.join(" ") + " Tm\n"; + } else { + position = hpf(parmPosX) + " " + hpf(parmPosY) + " Td\n"; + } + + return position; + }; + + for (var lineIndex = 0; lineIndex < da.length; lineIndex++) { + wordSpacing = ""; + + switch (variant) { + case ARRAY: + content = (isHex ? "<" : "(") + da[lineIndex][0] + (isHex ? ">" : ")"); + posX = parseFloat(da[lineIndex][1]); + posY = parseFloat(da[lineIndex][2]); + break; + + case STRING: + content = (isHex ? "<" : "(") + da[lineIndex] + (isHex ? ">" : ")"); + posX = getHorizontalCoordinate(x); + posY = getVerticalCoordinate(y); + break; + } + + if (typeof wordSpacingPerLine !== "undefined" && typeof wordSpacingPerLine[lineIndex] !== "undefined") { + wordSpacing = wordSpacingPerLine[lineIndex] + " Tw\n"; + } + + if (lineIndex === 0) { + text.push(wordSpacing + generatePosition(posX, posY, transformationMatrix) + content); + } else if (variant === STRING) { + text.push(wordSpacing + content); + } else if (variant === ARRAY) { + text.push(wordSpacing + generatePosition(posX, posY, transformationMatrix) + content); + } + } + + text = variant === STRING ? text.join(" Tj\nT* ") : text.join(" Tj\n"); + text += " Tj\n"; + var result = "BT\n/"; + result += activeFontKey + " " + activeFontSize + " Tf\n"; // font face, style, size + + result += hpf(activeFontSize * lineHeight) + " TL\n"; // line spacing + + result += textColor + "\n"; + result += xtra; + result += text; + result += "ET"; + out(result); + usedFonts[activeFontKey] = true; + return scope; + }; + /** + * Letter spacing method to print text with gaps + * + * @function + * @instance + * @param {String|Array} text String to be added to the page. + * @param {number} x Coordinate (in units declared at inception of PDF document) against left edge of the page + * @param {number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page + * @param {number} spacing Spacing (in units declared at inception) + * @returns {jsPDF} + * @memberof jsPDF# + * @name lstext + * @deprecated We'll be removing this function. It doesn't take character width into account. + */ + + + API.__private__.lstext = API.lstext = function (text, x, y, charSpace) { + return this.text(text, x, y, { + charSpace: charSpace + }); + }; // PDF supports these path painting and clip path operators: + // + // S - stroke + // s - close/stroke + // f (F) - fill non-zero + // f* - fill evenodd + // B - fill stroke nonzero + // B* - fill stroke evenodd + // b - close fill stroke nonzero + // b* - close fill stroke evenodd + // n - nothing (consume path) + // W - clip nonzero + // W* - clip evenodd + // + // In order to keep the API small, we omit the close-and-fill/stroke operators and provide a separate close() + // method. + + /** + * + * @name clip + * @function + * @instance + * @param {string} rule Only possible value is 'evenodd' + * @returns {jsPDF} + * @memberof jsPDF# + * @description All .clip() after calling drawing ops with a style argument of null. + */ + + + var clip = API.__private__.clip = API.clip = function (rule) { + // Call .clip() after calling drawing ops with a style argument of null + // W is the PDF clipping op + if ("evenodd" === rule) { + out("W*"); + } else { + out("W"); + } + + return this; + }; + /** + * @name clipEvenOdd + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @description Modify the current clip path by intersecting it with the current path using the even-odd rule. Note + * that this will NOT consume the current path. In order to only use this path for clipping call + * {@link API.discardPath} afterwards. + */ + + + API.clipEvenOdd = function () { + return clip("evenodd"); + }; + /** + * This fixes the previous function clip(). Perhaps the 'stroke path' hack was due to the missing 'n' instruction? + * We introduce the fixed version so as to not break API. + * @param fillRule + * @deprecated + * @ignore + */ + + + API.__private__.clip_fixed = API.clip_fixed = function (rule) { + return API.clip(rule); + }; + /** + * Consumes the current path without any effect. Mainly used in combination with {@link clip} or + * {@link clipEvenOdd}. The PDF "n" operator. + * @name discardPath + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + */ + + + API.__private__.discardPath = API.discardPath = function () { + out("n"); + return this; + }; + + var isValidStyle = API.__private__.isValidStyle = function (style) { + var validStyleVariants = [undefined, null, "S", "D", "F", "DF", "FD", "f", "f*", "B", "B*", "n"]; + var result = false; + + if (validStyleVariants.indexOf(style) !== -1) { + result = true; + } + + return result; + }; + + API.__private__.setDefaultPathOperation = API.setDefaultPathOperation = function (operator) { + if (isValidStyle(operator)) { + defaultPathOperation = operator; + } + + return this; + }; + + var getStyle = API.__private__.getStyle = API.getStyle = function (style) { + // see path-painting operators in PDF spec + var op = defaultPathOperation; // stroke + + switch (style) { + case "D": + case "S": + op = "S"; // stroke + + break; + + case "F": + op = "f"; // fill + + break; + + case "FD": + case "DF": + op = "B"; + break; + + case "f": + case "f*": + case "B": + case "B*": + /* + Allow direct use of these PDF path-painting operators: + - f fill using nonzero winding number rule + - f* fill using even-odd rule + - B fill then stroke with fill using non-zero winding number rule + - B* fill then stroke with fill using even-odd rule + */ + op = style; + break; + } + + return op; + }; + /** + * Close the current path. The PDF "h" operator. + * @name close + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + */ + + + var close = API.close = function () { + out("h"); + return this; + }; + /** + * Stroke the path. The PDF "S" operator. + * @name stroke + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + */ + + + API.stroke = function () { + out("S"); + return this; + }; + /** + * Fill the current path using the nonzero winding number rule. If a pattern is provided, the path will be filled + * with this pattern, otherwise with the current fill color. Equivalent to the PDF "f" operator. + * @name fill + * @function + * @instance + * @param {PatternData=} pattern If provided the path will be filled with this pattern + * @returns {jsPDF} + * @memberof jsPDF# + */ + + + API.fill = function (pattern) { + fillWithOptionalPattern("f", pattern); + return this; + }; + /** + * Fill the current path using the even-odd rule. The PDF f* operator. + * @see API.fill + * @name fillEvenOdd + * @function + * @instance + * @param {PatternData=} pattern If provided the path will be filled with this pattern + * @returns {jsPDF} + * @memberof jsPDF# + */ + + + API.fillEvenOdd = function (pattern) { + fillWithOptionalPattern("f*", pattern); + return this; + }; + /** + * Fill using the nonzero winding number rule and then stroke the current Path. The PDF "B" operator. + * @see API.fill + * @name fillStroke + * @function + * @instance + * @param {PatternData=} pattern If provided the path will be stroked with this pattern + * @returns {jsPDF} + * @memberof jsPDF# + */ + + + API.fillStroke = function (pattern) { + fillWithOptionalPattern("B", pattern); + return this; + }; + /** + * Fill using the even-odd rule and then stroke the current Path. The PDF "B" operator. + * @see API.fill + * @name fillStrokeEvenOdd + * @function + * @instance + * @param {PatternData=} pattern If provided the path will be fill-stroked with this pattern + * @returns {jsPDF} + * @memberof jsPDF# + */ + + + API.fillStrokeEvenOdd = function (pattern) { + fillWithOptionalPattern("B*", pattern); + return this; + }; + + var fillWithOptionalPattern = function fillWithOptionalPattern(style, pattern) { + if (_typeof(pattern) === "object") { + fillWithPattern(pattern, style); + } else { + out(style); + } + }; + + var putStyle = function putStyle(style, patternKey, patternData) { + if (style === null || apiMode === ApiMode.ADVANCED && style === undefined) { + return; + } + + style = getStyle(style); // stroking / filling / both the path + + if (!patternKey) { + out(style); + return; + } + + if (!patternData) { + patternData = { + matrix: identityMatrix + }; + } + + if (patternData instanceof Matrix) { + patternData = { + matrix: patternData + }; + } + + patternData.key = patternKey; + patternData || (patternData = identityMatrix); + fillWithPattern(patternData, style); + }; + + var fillWithPattern = function fillWithPattern(patternData, style) { + var patternId = patternMap[patternData.key]; + var pattern = patterns[patternId]; + + if (pattern instanceof API.ShadingPattern) { + out("q"); + out(clipRuleFromStyle(style)); + + if (pattern.gState) { + API.setGState(pattern.gState); + } + + out(patternData.matrix.toString() + " cm"); + out("/" + patternId + " sh"); + out("Q"); + } else if (pattern instanceof API.TilingPattern) { + // pdf draws patterns starting at the bottom left corner and they are not affected by the global transformation, + // so we must flip them + var matrix = new Matrix(1, 0, 0, -1, 0, getPageHeight()); + + if (patternData.matrix) { + matrix = matrix.multiply(patternData.matrix || identityMatrix); // we cannot apply a matrix to the pattern on use so we must abuse the pattern matrix and create new instances + // for each use + + patternId = pattern.createClone(patternData.key, patternData.boundingBox, patternData.xStep, patternData.yStep, matrix).id; + } + + out("q"); + out("/Pattern cs"); + out("/" + patternId + " scn"); + + if (pattern.gState) { + API.setGState(pattern.gState); + } + + out(style); + out("Q"); + } + }; + + var clipRuleFromStyle = function clipRuleFromStyle(style) { + switch (style) { + case "f": + case "F": + return "W n"; + + case "f*": + return "W* n"; + + case "B": + return "W S"; + + case "B*": + return "W* S"; + // these two are for compatibility reasons (in the past, calling any primitive method with a shading pattern + // and "n"/"S" as style would still fill/fill and stroke the path) + + case "S": + return "W S"; + + case "n": + return "W n"; + } + }; + /** + * Begin a new subpath by moving the current point to coordinates (x, y). The PDF "m" operator. + * @param {number} x + * @param {number} y + * @name moveTo + * @function + * @instance + * @memberof jsPDF# + * @returns {jsPDF} + */ + + + var moveTo = API.moveTo = function (x, y) { + out(hpf(scale(x)) + " " + hpf(transformScaleY(y)) + " m"); + return this; + }; + /** + * Append a straight line segment from the current point to the point (x, y). The PDF "l" operator. + * @param {number} x + * @param {number} y + * @memberof jsPDF# + * @name lineTo + * @function + * @instance + * @memberof jsPDF# + * @returns {jsPDF} + */ + + + var lineTo = API.lineTo = function (x, y) { + out(hpf(scale(x)) + " " + hpf(transformScaleY(y)) + " l"); + return this; + }; + /** + * Append a cubic Bézier curve to the current path. The curve shall extend from the current point to the point + * (x3, y3), using (x1, y1) and (x2, y2) as Bézier control points. The new current point shall be (x3, x3). + * @param {number} x1 + * @param {number} y1 + * @param {number} x2 + * @param {number} y2 + * @param {number} x3 + * @param {number} y3 + * @memberof jsPDF# + * @name curveTo + * @function + * @instance + * @memberof jsPDF# + * @returns {jsPDF} + */ + + + var curveTo = API.curveTo = function (x1, y1, x2, y2, x3, y3) { + out([hpf(scale(x1)), hpf(transformScaleY(y1)), hpf(scale(x2)), hpf(transformScaleY(y2)), hpf(scale(x3)), hpf(transformScaleY(y3)), "c"].join(" ")); + return this; + }; + /** + * Draw a line on the current page. + * + * @name line + * @function + * @instance + * @param {number} x1 + * @param {number} y1 + * @param {number} x2 + * @param {number} y2 + * @param {string} style A string specifying the painting style or null. Valid styles include: 'S' [default] - stroke, 'F' - fill, and 'DF' (or 'FD') - fill then stroke. A null value postpones setting the style so that a shape may be composed using multiple method calls. The last drawing method call used to define the shape should not have a null style argument. default: 'S' + * @returns {jsPDF} + * @memberof jsPDF# + */ + + + API.__private__.line = API.line = function (x1, y1, x2, y2, style) { + if (isNaN(x1) || isNaN(y1) || isNaN(x2) || isNaN(y2) || !isValidStyle(style)) { + throw new Error("Invalid arguments passed to jsPDF.line"); + } + + if (apiMode === ApiMode.COMPAT) { + return this.lines([[x2 - x1, y2 - y1]], x1, y1, [1, 1], style || "S"); + } else { + return this.lines([[x2 - x1, y2 - y1]], x1, y1, [1, 1]).stroke(); + } + }; + /** + * @typedef {Object} PatternData + * {Matrix|undefined} matrix + * {Number|undefined} xStep + * {Number|undefined} yStep + * {Array.|undefined} boundingBox + */ + + /** + * Adds series of curves (straight lines or cubic bezier curves) to canvas, starting at `x`, `y` coordinates. + * All data points in `lines` are relative to last line origin. + * `x`, `y` become x1,y1 for first line / curve in the set. + * For lines you only need to specify [x2, y2] - (ending point) vector against x1, y1 starting point. + * For bezier curves you need to specify [x2,y2,x3,y3,x4,y4] - vectors to control points 1, 2, ending point. All vectors are against the start of the curve - x1,y1. + * + * @example .lines([[2,2],[-2,2],[1,1,2,2,3,3],[2,1]], 212,110, [1,1], 'F', false) // line, line, bezier curve, line + * @param {Array} lines Array of *vector* shifts as pairs (lines) or sextets (cubic bezier curves). + * @param {number} x Coordinate (in units declared at inception of PDF document) against left edge of the page + * @param {number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page + * @param {number} scale (Defaults to [1.0,1.0]) x,y Scaling factor for all vectors. Elements can be any floating number Sub-one makes drawing smaller. Over-one grows the drawing. Negative flips the direction. + * @param {string=} style A string specifying the painting style or null. Valid styles include: + * 'S' [default] - stroke, + * 'F' - fill, + * and 'DF' (or 'FD') - fill then stroke. + * In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple + * method calls. The last drawing method call used to define the shape should not have a null style argument. + * + * In "advanced" API mode this parameter is deprecated. + * @param {Boolean=} closed If true, the path is closed with a straight line from the end of the last curve to the starting point. + * @param {String=} patternKey The pattern key for the pattern that should be used to fill the path. Deprecated! + * @param {(Matrix|PatternData)=} patternData The matrix that transforms the pattern into user space, or an object that + * will modify the pattern on use. Deprecated! + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name lines + */ + + + API.__private__.lines = API.lines = function (lines, x, y, scale, style, closed, patternKey, patternData) { + var scalex, scaley, i, l, leg, x2, y2, x3, y3, x4, y4, tmp; // Pre-August-2012 the order of arguments was function(x, y, lines, scale, style) + // in effort to make all calls have similar signature like + // function(content, coordinateX, coordinateY , miscellaneous) + // this method had its args flipped. + // code below allows backward compatibility with old arg order. + + if (typeof lines === "number") { + tmp = y; + y = x; + x = lines; + lines = tmp; + } + + scale = scale || [1, 1]; + closed = closed || false; + + if (isNaN(x) || isNaN(y) || !Array.isArray(lines) || !Array.isArray(scale) || !isValidStyle(style) || typeof closed !== "boolean") { + throw new Error("Invalid arguments passed to jsPDF.lines"); + } // starting point + + + moveTo(x, y); + scalex = scale[0]; + scaley = scale[1]; + l = lines.length; //, x2, y2 // bezier only. In page default measurement "units", *after* scaling + //, x3, y3 // bezier only. In page default measurement "units", *after* scaling + // ending point for all, lines and bezier. . In page default measurement "units", *after* scaling + + x4 = x; // last / ending point = starting point for first item. + + y4 = y; // last / ending point = starting point for first item. + + for (i = 0; i < l; i++) { + leg = lines[i]; + + if (leg.length === 2) { + // simple line + x4 = leg[0] * scalex + x4; // here last x4 was prior ending point + + y4 = leg[1] * scaley + y4; // here last y4 was prior ending point + + lineTo(x4, y4); + } else { + // bezier curve + x2 = leg[0] * scalex + x4; // here last x4 is prior ending point + + y2 = leg[1] * scaley + y4; // here last y4 is prior ending point + + x3 = leg[2] * scalex + x4; // here last x4 is prior ending point + + y3 = leg[3] * scaley + y4; // here last y4 is prior ending point + + x4 = leg[4] * scalex + x4; // here last x4 was prior ending point + + y4 = leg[5] * scaley + y4; // here last y4 was prior ending point + + curveTo(x2, y2, x3, y3, x4, y4); + } + } + + if (closed) { + close(); + } + + putStyle(style, patternKey, patternData); + return this; + }; + /** + * Similar to {@link API.lines} but all coordinates are interpreted as absolute coordinates instead of relative. + * @param {Array} lines An array of {op: operator, c: coordinates} object, where op is one of "m" (move to), "l" (line to) + * "c" (cubic bezier curve) and "h" (close (sub)path)). c is an array of coordinates. "m" and "l" expect two, "c" + * six and "h" an empty array (or undefined). + * @param {String=} style The style. Deprecated! + * @param {String=} patternKey The pattern key for the pattern that should be used to fill the path. Deprecated! + * @param {(Matrix|PatternData)=} patternData The matrix that transforms the pattern into user space, or an object that + * will modify the pattern on use. Deprecated! + * @function + * @returns {jsPDF} + * @memberof jsPDF# + * @name path + */ + + + API.path = function (lines, style, patternKey, patternData) { + for (var i = 0; i < lines.length; i++) { + var leg = lines[i]; + var coords = leg.c; + + switch (leg.op) { + case "m": + moveTo(coords[0], coords[1]); + break; + + case "l": + lineTo(coords[0], coords[1]); + break; + + case "c": + curveTo.apply(this, coords); + break; + + case "h": + close(); + break; + } + } + + putStyle(style, patternKey, patternData); + return this; + }; + /** + * Adds a rectangle to PDF. + * + * @param {number} x Coordinate (in units declared at inception of PDF document) against left edge of the page + * @param {number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page + * @param {number} w Width (in units declared at inception of PDF document) + * @param {number} h Height (in units declared at inception of PDF document) + * @param {string=} style A string specifying the painting style or null. Valid styles include: + * 'S' [default] - stroke, + * 'F' - fill, + * and 'DF' (or 'FD') - fill then stroke. + * In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple + * method calls. The last drawing method call used to define the shape should not have a null style argument. + * + * In "advanced" API mode this parameter is deprecated. + * @param {String=} patternKey The pattern key for the pattern that should be used to fill the primitive. Deprecated! + * @param {(Matrix|PatternData)=} patternData The matrix that transforms the pattern into user space, or an object that + * will modify the pattern on use. Deprecated! + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name rect + */ + + + API.__private__.rect = API.rect = function (x, y, w, h, style, patternKey, patternData) { + if (isNaN(x) || isNaN(y) || isNaN(w) || isNaN(h) || !isValidStyle(style)) { + throw new Error("Invalid arguments passed to jsPDF.rect"); + } + + if (apiMode === ApiMode.COMPAT) { + h = -h; + } + + out([hpf(scale(x)), hpf(transformScaleY(y)), hpf(scale(w)), hpf(scale(h)), "re"].join(" ")); + putStyle(style, patternKey, patternData); + return this; + }; + /** + * Adds a triangle to PDF. + * + * @param {number} x1 Coordinate (in units declared at inception of PDF document) against left edge of the page + * @param {number} y1 Coordinate (in units declared at inception of PDF document) against upper edge of the page + * @param {number} x2 Coordinate (in units declared at inception of PDF document) against left edge of the page + * @param {number} y2 Coordinate (in units declared at inception of PDF document) against upper edge of the page + * @param {number} x3 Coordinate (in units declared at inception of PDF document) against left edge of the page + * @param {number} y3 Coordinate (in units declared at inception of PDF document) against upper edge of the page + * @param {string=} style A string specifying the painting style or null. Valid styles include: + * 'S' [default] - stroke, + * 'F' - fill, + * and 'DF' (or 'FD') - fill then stroke. + * In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple + * method calls. The last drawing method call used to define the shape should not have a null style argument. + * + * In "advanced" API mode this parameter is deprecated. + * @param {String=} patternKey The pattern key for the pattern that should be used to fill the primitive. Deprecated! + * @param {(Matrix|PatternData)=} patternData The matrix that transforms the pattern into user space, or an object that + * will modify the pattern on use. Deprecated! + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name triangle + */ + + + API.__private__.triangle = API.triangle = function (x1, y1, x2, y2, x3, y3, style, patternKey, patternData) { + if (isNaN(x1) || isNaN(y1) || isNaN(x2) || isNaN(y2) || isNaN(x3) || isNaN(y3) || !isValidStyle(style)) { + throw new Error("Invalid arguments passed to jsPDF.triangle"); + } + + this.lines([[x2 - x1, y2 - y1], // vector to point 2 + [x3 - x2, y3 - y2], // vector to point 3 + [x1 - x3, y1 - y3] // closing vector back to point 1 + ], x1, y1, // start of path + [1, 1], style, true, patternKey, patternData); + return this; + }; + /** + * Adds a rectangle with rounded corners to PDF. + * + * @param {number} x Coordinate (in units declared at inception of PDF document) against left edge of the page + * @param {number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page + * @param {number} w Width (in units declared at inception of PDF document) + * @param {number} h Height (in units declared at inception of PDF document) + * @param {number} rx Radius along x axis (in units declared at inception of PDF document) + * @param {number} ry Radius along y axis (in units declared at inception of PDF document) + * @param {string=} style A string specifying the painting style or null. Valid styles include: + * 'S' [default] - stroke, + * 'F' - fill, + * and 'DF' (or 'FD') - fill then stroke. + * In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple + * method calls. The last drawing method call used to define the shape should not have a null style argument. + * + * In "advanced" API mode this parameter is deprecated. + * @param {String=} patternKey The pattern key for the pattern that should be used to fill the primitive. Deprecated! + * @param {(Matrix|PatternData)=} patternData The matrix that transforms the pattern into user space, or an object that + * will modify the pattern on use. Deprecated! + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name roundedRect + */ + + + API.__private__.roundedRect = API.roundedRect = function (x, y, w, h, rx, ry, style, patternKey, patternData) { + if (isNaN(x) || isNaN(y) || isNaN(w) || isNaN(h) || isNaN(rx) || isNaN(ry) || !isValidStyle(style)) { + throw new Error("Invalid arguments passed to jsPDF.roundedRect"); + } + + var MyArc = 4 / 3 * (Math.SQRT2 - 1); + rx = Math.min(rx, w * 0.5); + ry = Math.min(ry, h * 0.5); + this.lines([[w - 2 * rx, 0], [rx * MyArc, 0, rx, ry - ry * MyArc, rx, ry], [0, h - 2 * ry], [0, ry * MyArc, -(rx * MyArc), ry, -rx, ry], [-w + 2 * rx, 0], [-(rx * MyArc), 0, -rx, -(ry * MyArc), -rx, -ry], [0, -h + 2 * ry], [0, -(ry * MyArc), rx * MyArc, -ry, rx, -ry]], x + rx, y, // start of path + [1, 1], style, true, patternKey, patternData); + return this; + }; + /** + * Adds an ellipse to PDF. + * + * @param {number} x Coordinate (in units declared at inception of PDF document) against left edge of the page + * @param {number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page + * @param {number} rx Radius along x axis (in units declared at inception of PDF document) + * @param {number} ry Radius along y axis (in units declared at inception of PDF document) + * @param {string=} style A string specifying the painting style or null. Valid styles include: + * 'S' [default] - stroke, + * 'F' - fill, + * and 'DF' (or 'FD') - fill then stroke. + * In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple + * method calls. The last drawing method call used to define the shape should not have a null style argument. + * + * In "advanced" API mode this parameter is deprecated. + * @param {String=} patternKey The pattern key for the pattern that should be used to fill the primitive. Deprecated! + * @param {(Matrix|PatternData)=} patternData The matrix that transforms the pattern into user space, or an object that + * will modify the pattern on use. Deprecated! + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name ellipse + */ + + + API.__private__.ellipse = API.ellipse = function (x, y, rx, ry, style, patternKey, patternData) { + if (isNaN(x) || isNaN(y) || isNaN(rx) || isNaN(ry) || !isValidStyle(style)) { + throw new Error("Invalid arguments passed to jsPDF.ellipse"); + } + + var lx = 4 / 3 * (Math.SQRT2 - 1) * rx, + ly = 4 / 3 * (Math.SQRT2 - 1) * ry; + moveTo(x + rx, y); + curveTo(x + rx, y - ly, x + lx, y - ry, x, y - ry); + curveTo(x - lx, y - ry, x - rx, y - ly, x - rx, y); + curveTo(x - rx, y + ly, x - lx, y + ry, x, y + ry); + curveTo(x + lx, y + ry, x + rx, y + ly, x + rx, y); + putStyle(style, patternKey, patternData); + return this; + }; + /** + * Adds an circle to PDF. + * + * @param {number} x Coordinate (in units declared at inception of PDF document) against left edge of the page + * @param {number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page + * @param {number} r Radius (in units declared at inception of PDF document) + * @param {string=} style A string specifying the painting style or null. Valid styles include: + * 'S' [default] - stroke, + * 'F' - fill, + * and 'DF' (or 'FD') - fill then stroke. + * In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple + * method calls. The last drawing method call used to define the shape should not have a null style argument. + * + * In "advanced" API mode this parameter is deprecated. + * @param {String=} patternKey The pattern key for the pattern that should be used to fill the primitive. Deprecated! + * @param {(Matrix|PatternData)=} patternData The matrix that transforms the pattern into user space, or an object that + * will modify the pattern on use. Deprecated! + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name circle + */ + + + API.__private__.circle = API.circle = function (x, y, r, style, patternKey, patternData) { + if (isNaN(x) || isNaN(y) || isNaN(r) || !isValidStyle(style)) { + throw new Error("Invalid arguments passed to jsPDF.circle"); + } + + return this.ellipse(x, y, r, r, style, patternKey, patternData); + }; + /** + * Sets text font face, variant for upcoming text elements. + * See output of jsPDF.getFontList() for possible font names, styles. + * + * @param {string} fontName Font name or family. Example: "times". + * @param {string} fontStyle Font style or variant. Example: "italic". + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name setFont + */ + + + API.setFont = function (fontName, fontStyle) { + activeFontKey = getFont(fontName, fontStyle, { + disableWarning: false + }); + return this; + }; + /** + * Gets text font face, variant for upcoming text elements. + * + * @function + * @instance + * @returns {Object} + * @memberof jsPDF# + * @name getFont + */ + + + var getFontEntry = API.__private__.getFont = API.getFont = function () { + return fonts[getFont.apply(API, arguments)]; + }; + /** + * Switches font style or variant for upcoming text elements, + * while keeping the font face or family same. + * See output of jsPDF.getFontList() for possible font names, styles. + * + * @param {string} style Font style or variant. Example: "italic". + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @deprecated + * @name setFontStyle + */ + + + API.setFontStyle = API.setFontType = function (style) { + activeFontKey = getFont(undefined, style); // if font is not found, the above line blows up and we never go further + + return this; + }; + /** + * Returns an object - a tree of fontName to fontStyle relationships available to + * active PDF document. + * + * @public + * @function + * @instance + * @returns {Object} Like {'times':['normal', 'italic', ... ], 'arial':['normal', 'bold', ... ], ... } + * @memberof jsPDF# + * @name getFontList + */ + + + API.__private__.getFontList = API.getFontList = function () { + var list = {}, + fontName, + fontStyle; + + for (fontName in fontmap) { + if (fontmap.hasOwnProperty(fontName)) { + list[fontName] = []; + + for (fontStyle in fontmap[fontName]) { + if (fontmap[fontName].hasOwnProperty(fontStyle)) { + list[fontName].push(fontStyle); + } + } + } + } + + return list; + }; + /** + * Add a custom font to the current instance. + * + * @property {string} postScriptName PDF specification full name for the font. + * @property {string} id PDF-document-instance-specific label assinged to the font. + * @property {string} fontStyle Style of the Font. + * @property {Object} encoding Encoding_name-to-Font_metrics_object mapping. + * @function + * @instance + * @memberof jsPDF# + * @name addFont + * @returns {string} fontId + */ + + + API.addFont = function (postScriptName, fontName, fontStyle, encoding) { + encoding = encoding || "Identity-H"; + return addFont.call(this, postScriptName, fontName, fontStyle, encoding); + }; + + var lineWidth = options.lineWidth || 0.200025; // 2mm + + /** + * Sets line width for upcoming lines. + * + * @param {number} width Line width (in units declared at inception of PDF document). + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name setLineWidth + */ + + var setLineWidth = API.__private__.setLineWidth = API.setLineWidth = function (width) { + out(hpf(scale(width)) + " w"); + return this; + }; + /** + * Sets the dash pattern for upcoming lines. + * + * To reset the settings simply call the method without any parameters. + * @param {Array} dashArray An array containing 0-2 numbers. The first number sets the length of the + * dashes, the second number the length of the gaps. If the second number is missing, the gaps are considered + * to be as long as the dashes. An empty array means solid, unbroken lines. + * @param {number} dashPhase The phase lines start with. + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name setLineDashPattern + */ + + + API.__private__.setLineDash = jsPDF.API.setLineDash = jsPDF.API.setLineDashPattern = function (dashArray, dashPhase) { + dashArray = dashArray || []; + dashPhase = dashPhase || 0; + + if (isNaN(dashPhase) || !Array.isArray(dashArray)) { + throw new Error("Invalid arguments passed to jsPDF.setLineDash"); + } + + dashArray = dashArray.map(function (x) { + return hpf(scale(x)); + }).join(" "); + dashPhase = hpf(scale(dashPhase)); + out("[" + dashArray + "] " + dashPhase + " d"); + return this; + }; + + var lineHeightFactor; + + var getLineHeight = API.__private__.getLineHeight = API.getLineHeight = function () { + return activeFontSize * lineHeightFactor; + }; + + API.__private__.getLineHeight = API.getLineHeight = function () { + return activeFontSize * lineHeightFactor; + }; + /** + * Sets the LineHeightFactor of proportion. + * + * @param {number} value LineHeightFactor value. Default: 1.15. + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name setLineHeightFactor + */ + + + var setLineHeightFactor = API.__private__.setLineHeightFactor = API.setLineHeightFactor = function (value) { + value = value || 1.15; + + if (typeof value === "number") { + lineHeightFactor = value; + } + + return this; + }; + /** + * Gets the LineHeightFactor, default: 1.15. + * + * @function + * @instance + * @returns {number} lineHeightFactor + * @memberof jsPDF# + * @name getLineHeightFactor + */ + + + var getLineHeightFactor = API.__private__.getLineHeightFactor = API.getLineHeightFactor = function () { + return lineHeightFactor; + }; + + setLineHeightFactor(options.lineHeight); + + var getHorizontalCoordinate = API.__private__.getHorizontalCoordinate = function (value) { + return scale(value); + }; + + var getVerticalCoordinate = API.__private__.getVerticalCoordinate = function (value) { + if (apiMode === ApiMode.ADVANCED) { + return value; + } else { + var pageHeight = pagesContext[currentPage].mediaBox.topRightY - pagesContext[currentPage].mediaBox.bottomLeftY; + return pageHeight - scale(value); + } + }; + + var getHorizontalCoordinateString = API.__private__.getHorizontalCoordinateString = API.getHorizontalCoordinateString = function (value) { + return hpf(getHorizontalCoordinate(value)); + }; + + var getVerticalCoordinateString = API.__private__.getVerticalCoordinateString = API.getVerticalCoordinateString = function (value) { + return hpf(getVerticalCoordinate(value)); + }; + + var strokeColor = options.strokeColor || "0 G"; + /** + * Gets the stroke color for upcoming elements. + * + * @function + * @instance + * @returns {string} colorAsHex + * @memberof jsPDF# + * @name getDrawColor + */ + + API.__private__.getStrokeColor = API.getDrawColor = function () { + return decodeColorString(strokeColor); + }; + /** + * Sets the stroke color for upcoming elements. + * + * Depending on the number of arguments given, Gray, RGB, or CMYK + * color space is implied. + * + * When only ch1 is given, "Gray" color space is implied and it + * must be a value in the range from 0.00 (solid black) to to 1.00 (white) + * if values are communicated as String types, or in range from 0 (black) + * to 255 (white) if communicated as Number type. + * The RGB-like 0-255 range is provided for backward compatibility. + * + * When only ch1,ch2,ch3 are given, "RGB" color space is implied and each + * value must be in the range from 0.00 (minimum intensity) to to 1.00 + * (max intensity) if values are communicated as String types, or + * from 0 (min intensity) to to 255 (max intensity) if values are communicated + * as Number types. + * The RGB-like 0-255 range is provided for backward compatibility. + * + * When ch1,ch2,ch3,ch4 are given, "CMYK" color space is implied and each + * value must be a in the range from 0.00 (0% concentration) to to + * 1.00 (100% concentration) + * + * Because JavaScript treats fixed point numbers badly (rounds to + * floating point nearest to binary representation) it is highly advised to + * communicate the fractional numbers as String types, not JavaScript Number type. + * + * @param {Number|String} ch1 Color channel value or {string} ch1 color value in hexadecimal, example: '#FFFFFF'. + * @param {Number} ch2 Color channel value. + * @param {Number} ch3 Color channel value. + * @param {Number} ch4 Color channel value. + * + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name setDrawColor + */ + + + API.__private__.setStrokeColor = API.setDrawColor = function (ch1, ch2, ch3, ch4) { + var options = { + ch1: ch1, + ch2: ch2, + ch3: ch3, + ch4: ch4, + pdfColorType: "draw", + precision: 2 + }; + strokeColor = encodeColorString(options); + out(strokeColor); + return this; + }; + + var fillColor = options.fillColor || "0 g"; + /** + * Gets the fill color for upcoming elements. + * + * @function + * @instance + * @returns {string} colorAsHex + * @memberof jsPDF# + * @name getFillColor + */ + + API.__private__.getFillColor = API.getFillColor = function () { + return decodeColorString(fillColor); + }; + /** + * Sets the fill color for upcoming elements. + * + * Depending on the number of arguments given, Gray, RGB, or CMYK + * color space is implied. + * + * When only ch1 is given, "Gray" color space is implied and it + * must be a value in the range from 0.00 (solid black) to to 1.00 (white) + * if values are communicated as String types, or in range from 0 (black) + * to 255 (white) if communicated as Number type. + * The RGB-like 0-255 range is provided for backward compatibility. + * + * When only ch1,ch2,ch3 are given, "RGB" color space is implied and each + * value must be in the range from 0.00 (minimum intensity) to to 1.00 + * (max intensity) if values are communicated as String types, or + * from 0 (min intensity) to to 255 (max intensity) if values are communicated + * as Number types. + * The RGB-like 0-255 range is provided for backward compatibility. + * + * When ch1,ch2,ch3,ch4 are given, "CMYK" color space is implied and each + * value must be a in the range from 0.00 (0% concentration) to to + * 1.00 (100% concentration) + * + * Because JavaScript treats fixed point numbers badly (rounds to + * floating point nearest to binary representation) it is highly advised to + * communicate the fractional numbers as String types, not JavaScript Number type. + * + * @param {Number|String} ch1 Color channel value or {string} ch1 color value in hexadecimal, example: '#FFFFFF'. + * @param {Number} ch2 Color channel value. + * @param {Number} ch3 Color channel value. + * @param {Number} ch4 Color channel value. + * + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name setFillColor + */ + + + API.__private__.setFillColor = API.setFillColor = function (ch1, ch2, ch3, ch4) { + var options = { + ch1: ch1, + ch2: ch2, + ch3: ch3, + ch4: ch4, + pdfColorType: "fill", + precision: 2 + }; + fillColor = encodeColorString(options); + out(fillColor); + return this; + }; + + var textColor = options.textColor || "0 g"; + /** + * Gets the text color for upcoming elements. + * + * @function + * @instance + * @returns {string} colorAsHex + * @memberof jsPDF# + * @name getTextColor + */ + + var getTextColor = API.__private__.getTextColor = API.getTextColor = function () { + return decodeColorString(textColor); + }; + /** + * Sets the text color for upcoming elements. + * + * Depending on the number of arguments given, Gray, RGB, or CMYK + * color space is implied. + * + * When only ch1 is given, "Gray" color space is implied and it + * must be a value in the range from 0.00 (solid black) to to 1.00 (white) + * if values are communicated as String types, or in range from 0 (black) + * to 255 (white) if communicated as Number type. + * The RGB-like 0-255 range is provided for backward compatibility. + * + * When only ch1,ch2,ch3 are given, "RGB" color space is implied and each + * value must be in the range from 0.00 (minimum intensity) to to 1.00 + * (max intensity) if values are communicated as String types, or + * from 0 (min intensity) to to 255 (max intensity) if values are communicated + * as Number types. + * The RGB-like 0-255 range is provided for backward compatibility. + * + * When ch1,ch2,ch3,ch4 are given, "CMYK" color space is implied and each + * value must be a in the range from 0.00 (0% concentration) to to + * 1.00 (100% concentration) + * + * Because JavaScript treats fixed point numbers badly (rounds to + * floating point nearest to binary representation) it is highly advised to + * communicate the fractional numbers as String types, not JavaScript Number type. + * + * @param {Number|String} ch1 Color channel value or {string} ch1 color value in hexadecimal, example: '#FFFFFF'. + * @param {Number} ch2 Color channel value. + * @param {Number} ch3 Color channel value. + * @param {Number} ch4 Color channel value. + * + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name setTextColor + */ + + + API.__private__.setTextColor = API.setTextColor = function (ch1, ch2, ch3, ch4) { + var options = { + ch1: ch1, + ch2: ch2, + ch3: ch3, + ch4: ch4, + pdfColorType: "text", + precision: 3 + }; + textColor = encodeColorString(options); + return this; + }; + + var activeCharSpace = options.charSpace; + /** + * Get global value of CharSpace. + * + * @function + * @instance + * @returns {number} charSpace + * @memberof jsPDF# + * @name getCharSpace + */ + + var getCharSpace = API.__private__.getCharSpace = API.getCharSpace = function () { + return parseFloat(activeCharSpace || 0); + }; + /** + * Set global value of CharSpace. + * + * @param {number} charSpace + * @function + * @instance + * @returns {jsPDF} jsPDF-instance + * @memberof jsPDF# + * @name setCharSpace + */ + + + API.__private__.setCharSpace = API.setCharSpace = function (charSpace) { + if (isNaN(charSpace)) { + throw new Error("Invalid argument passed to jsPDF.setCharSpace"); + } + + activeCharSpace = charSpace; + return this; + }; + + var lineCapID = 0; + /** + * Is an Object providing a mapping from human-readable to + * integer flag values designating the varieties of line cap + * and join styles. + * + * @memberof jsPDF# + * @name CapJoinStyles + */ + + API.CapJoinStyles = { + 0: 0, + butt: 0, + but: 0, + miter: 0, + 1: 1, + round: 1, + rounded: 1, + circle: 1, + 2: 2, + projecting: 2, + project: 2, + square: 2, + bevel: 2 + }; + /** + * Sets the line cap styles. + * See {jsPDF.CapJoinStyles} for variants. + * + * @param {String|Number} style A string or number identifying the type of line cap. + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name setLineCap + */ + + API.__private__.setLineCap = API.setLineCap = function (style) { + var id = API.CapJoinStyles[style]; + + if (id === undefined) { + throw new Error("Line cap style of '" + style + "' is not recognized. See or extend .CapJoinStyles property for valid styles"); + } + + lineCapID = id; + out(id + " J"); + return this; + }; + + var lineJoinID = 0; + /** + * Sets the line join styles. + * See {jsPDF.CapJoinStyles} for variants. + * + * @param {String|Number} style A string or number identifying the type of line join. + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name setLineJoin + */ + + API.__private__.setLineJoin = API.setLineJoin = function (style) { + var id = API.CapJoinStyles[style]; + + if (id === undefined) { + throw new Error("Line join style of '" + style + "' is not recognized. See or extend .CapJoinStyles property for valid styles"); + } + + lineJoinID = id; + out(id + " j"); + return this; + }; + /** + * Sets the miterLimit property, which effects the maximum miter length. + * + * @param {number} length The length of the miter + * @function + * @instance + * @returns {jsPDF} + * @memberof jsPDF# + * @name setLineMiterLimit + */ + + API.__private__.setLineMiterLimit = API.__private__.setMiterLimit = API.setLineMiterLimit = API.setMiterLimit = function (length) { + length = length || 0; + + if (isNaN(length)) { + throw new Error("Invalid argument passed to jsPDF.setLineMiterLimit"); + } + + out(hpf(scale(length)) + " M"); + return this; + }; + /** + * An object representing a pdf graphics state. + * @class GState + */ + + /** + * + * @param parameters A parameter object that contains all properties this graphics state wants to set. + * Supported are: opacity, stroke-opacity + * @constructor + */ + + + API.GState = function GState(parameters) { + if (!(this instanceof GState)) { + return new GState(parameters); + } + /** + * @name GState#opacity + * @type {any} + */ + + /** + * @name GState#stroke-opacity + * @type {any} + */ + + + var supported = "opacity,stroke-opacity".split(","); + + for (var p in parameters) { + if (parameters.hasOwnProperty(p) && supported.indexOf(p) >= 0) { + this[p] = parameters[p]; + } + } + /** + * @name GState#id + * @type {string} + */ + + + this.id = ""; // set by addGState() + + /** + * @name GState#objectNumber + * @type {number} + */ + + this.objectNumber = -1; // will be set by putGState() + }; + + API.GState.prototype.equals = function equals(other) { + var ignore = "id,objectNumber,equals"; + var p; + if (!other || _typeof(other) !== _typeof(this)) { return false; } + var count = 0; + + for (p in this) { + if (ignore.indexOf(p) >= 0) { continue; } + if (this.hasOwnProperty(p) && !other.hasOwnProperty(p)) { return false; } + if (this[p] !== other[p]) { return false; } + count++; + } + + for (p in other) { + if (other.hasOwnProperty(p) && ignore.indexOf(p) < 0) { count--; } + } + + return count === 0; + }; + /** + * Sets a either previously added {@link GState} (via {@link addGState}) or a new {@link GState}. + * @param {String|GState} gState If type is string, a previously added GState is used, if type is GState + * it will be added before use. + * @function + * @returns {jsPDF} + * @memberof jsPDF# + * @name setGState + */ + + + API.setGState = function (gState) { + if (typeof gState === "string") { + gState = gStates[gStatesMap[gState]]; + } else { + gState = addGState(null, gState); + } + + if (!gState.equals(activeGState)) { + out("/" + gState.id + " gs"); + activeGState = gState; + } + }; + /** + * Adds a new Graphics State. Duplicates are automatically eliminated. + * @param {String} key Might also be null, if no later reference to this gState is needed + * @param {Object} gState The gState object + */ + + + var addGState = function addGState(key, gState) { + // only add it if it is not already present (the keys provided by the user must be unique!) + if (key && gStatesMap[key]) { return; } + var duplicate = false; + + for (var s in gStates) { + if (gStates.hasOwnProperty(s)) { + if (gStates[s].equals(gState)) { + duplicate = true; + break; + } + } + } + + if (duplicate) { + gState = gStates[s]; + } else { + var gStateKey = "GS" + (Object.keys(gStates).length + 1).toString(10); + gStates[gStateKey] = gState; + gState.id = gStateKey; + } // several user keys may point to the same GState object + + + key && (gStatesMap[key] = gState.id); + events.publish("addGState", gState); + return gState; + }; + /** + * Adds a new {@link GState} for later use. See {@link setGState}. + * @param {String} key + * @param {GState} gState + * @function + * @instance + * @returns {jsPDF} + * + * @memberof jsPDF# + * @name addGState + */ + + + API.addGState = function (key, gState) { + addGState(key, gState); + return this; + }; + /** + * Saves the current graphics state ("pushes it on the stack"). It can be restored by {@link restoreGraphicsState} + * later. Here, the general pdf graphics state is meant, also including the current transformation matrix, + * fill and stroke colors etc. + * @function + * @returns {jsPDF} + * @memberof jsPDF# + * @name saveGraphicsState + */ + + + API.saveGraphicsState = function () { + out("q"); // as we cannot set font key and size independently we must keep track of both + + fontStateStack.push({ + key: activeFontKey, + size: activeFontSize, + color: textColor + }); + return this; + }; + /** + * Restores a previously saved graphics state saved by {@link saveGraphicsState} ("pops the stack"). + * @function + * @returns {jsPDF} + * @memberof jsPDF# + * @name restoreGraphicsState + */ + + + API.restoreGraphicsState = function () { + out("Q"); // restore previous font state + + var fontState = fontStateStack.pop(); + activeFontKey = fontState.key; + activeFontSize = fontState.size; + textColor = fontState.color; + activeGState = null; + return this; + }; + /** + * Appends this matrix to the left of all previously applied matrices. + * + * @param {Matrix} matrix + * @function + * @returns {jsPDF} + * @memberof jsPDF# + * @name setCurrentTransformationMatrix + */ + + + API.setCurrentTransformationMatrix = function (matrix) { + out(matrix.toString() + " cm"); + return this; + }; + /** + * Inserts a debug comment into the generated pdf. + * @function + * @instance + * @param {String} text + * @returns {jsPDF} + * @memberof jsPDF# + * @name comment + */ + + + API.comment = function (text) { + out("#" + text); + return this; + }; + /** + * Point + */ + + + var Point = function Point(x, y) { + var _x = x || 0; + + Object.defineProperty(this, "x", { + enumerable: true, + get: function get() { + return _x; + }, + set: function set(value) { + if (!isNaN(value)) { + _x = parseFloat(value); + } + } + }); + + var _y = y || 0; + + Object.defineProperty(this, "y", { + enumerable: true, + get: function get() { + return _y; + }, + set: function set(value) { + if (!isNaN(value)) { + _y = parseFloat(value); + } + } + }); + var _type = "pt"; + Object.defineProperty(this, "type", { + enumerable: true, + get: function get() { + return _type; + }, + set: function set(value) { + _type = value.toString(); + } + }); + return this; + }; + /** + * Rectangle + */ + + + var Rectangle = function Rectangle(x, y, w, h) { + Point.call(this, x, y); + this.type = "rect"; + + var _w = w || 0; + + Object.defineProperty(this, "w", { + enumerable: true, + get: function get() { + return _w; + }, + set: function set(value) { + if (!isNaN(value)) { + _w = parseFloat(value); + } + } + }); + + var _h = h || 0; + + Object.defineProperty(this, "h", { + enumerable: true, + get: function get() { + return _h; + }, + set: function set(value) { + if (!isNaN(value)) { + _h = parseFloat(value); + } + } + }); + return this; + }; + /** + * FormObject/RenderTarget + */ + + + var RenderTarget = function RenderTarget() { + this.page = page; + this.currentPage = currentPage; + this.pages = pages.slice(0); + this.pagesContext = pagesContext.slice(0); + this.x = pageX; + this.y = pageY; + this.matrix = pageMatrix; + this.width = getPageWidth(currentPage); + this.height = getPageHeight(currentPage); + this.outputDestination = outputDestination; + this.id = ""; // set by endFormObject() + + this.objectNumber = -1; // will be set by putXObject() + }; + + RenderTarget.prototype.restore = function () { + page = this.page; + currentPage = this.currentPage; + pagesContext = this.pagesContext; + pages = this.pages; + pageX = this.x; + pageY = this.y; + pageMatrix = this.matrix; + setPageWidth(currentPage, this.width); + setPageHeight(currentPage, this.height); + outputDestination = this.outputDestination; + }; + + var beginNewRenderTarget = function beginNewRenderTarget(x, y, width, height, matrix) { + // save current state + renderTargetStack.push(new RenderTarget()); // clear pages + + page = currentPage = 0; + pages = []; + pageX = x; + pageY = y; + pageMatrix = matrix; + beginPage([width, height]); + }; + + var endFormObject = function endFormObject(key) { + // only add it if it is not already present (the keys provided by the user must be unique!) + if (renderTargetMap[key]) { return; } // save the created xObject + + var newXObject = new RenderTarget(); + var xObjectId = "Xo" + (Object.keys(renderTargets).length + 1).toString(10); + newXObject.id = xObjectId; + renderTargetMap[key] = xObjectId; + renderTargets[xObjectId] = newXObject; + events.publish("addFormObject", newXObject); // restore state from stack + + renderTargetStack.pop().restore(); + }; + /** + * Starts a new pdf form object, which means that all consequent draw calls target a new independent object + * until {@link endFormObject} is called. The created object can be referenced and drawn later using + * {@link doFormObject}. Nested form objects are possible. + * x, y, width, height set the bounding box that is used to clip the content. + * + * @param {number} x + * @param {number} y + * @param {number} width + * @param {number} height + * @param {Matrix} matrix The matrix that will be applied to convert the form objects coordinate system to + * the parent's. + * @function + * @returns {jsPDF} + * @memberof jsPDF# + * @name beginFormObject + */ + + + API.beginFormObject = function (x, y, width, height, matrix) { + // The user can set the output target to a new form object. Nested form objects are possible. + // Currently, they use the resource dictionary of the surrounding stream. This should be changed, as + // the PDF-Spec states: + // "In PDF 1.2 and later versions, form XObjects may be independent of the content streams in which + // they appear, and this is strongly recommended although not requiredIn PDF 1.2 and later versions, + // form XObjects may be independent of the content streams in which they appear, and this is strongly + // recommended although not required" + beginNewRenderTarget(x, y, width, height, matrix); + return this; + }; + /** + * Completes and saves the form object. + * @param {String} key The key by which this form object can be referenced. + * @function + * @returns {jsPDF} + * @memberof jsPDF# + * @name endFormObject + */ + + + API.endFormObject = function (key) { + endFormObject(key); + return this; + }; + /** + * Draws the specified form object by referencing to the respective pdf XObject created with + * {@link API.beginFormObject} and {@link endFormObject}. + * The location is determined by matrix. + * + * @param {String} key The key to the form object. + * @param {Matrix} matrix The matrix applied before drawing the form object. + * @function + * @returns {jsPDF} + * @memberof jsPDF# + * @name doFormObject + */ + + + API.doFormObject = function (key, matrix) { + var xObject = renderTargets[renderTargetMap[key]]; + out("q"); + out(matrix.toString() + " cm"); + out("/" + xObject.id + " Do"); + out("Q"); + return this; + }; + /** + * Returns the form object specified by key. + * @param key {String} + * @returns {{x: number, y: number, width: number, height: number, matrix: Matrix}} + * @function + * @returns {jsPDF} + * @memberof jsPDF# + * @name getFormObject + */ + + + API.getFormObject = function (key) { + var xObject = renderTargets[renderTargetMap[key]]; + return { + x: xObject.x, + y: xObject.y, + width: xObject.width, + height: xObject.height, + matrix: xObject.matrix + }; + }; + /** + * Saves as PDF document. An alias of jsPDF.output('save', 'filename.pdf'). + * Uses FileSaver.js-method saveAs. + * + * @memberof jsPDF# + * @name save + * @function + * @instance + * @param {string} filename The filename including extension. + * @param {Object} options An Object with additional options, possible options: 'returnPromise'. + * @returns {jsPDF} jsPDF-instance */ + + + API.save = function (filename, options) { + filename = filename || "generated.pdf"; + options = options || {}; + options.returnPromise = options.returnPromise || false; + + if (options.returnPromise === false) { + saveAs(getBlob(buildDocument()), filename); + + if (typeof saveAs.unload === "function") { + if (global.setTimeout) { + setTimeout(saveAs.unload, 911); + } + } + } else { + return new Promise(function (resolve, reject) { + try { + var result = saveAs(getBlob(buildDocument()), filename); + + if (typeof saveAs.unload === "function") { + if (global.setTimeout) { + setTimeout(saveAs.unload, 911); + } + } + + resolve(result); + } catch (e) { + reject(e.message); + } + }); + } + }; // applying plugins (more methods) ON TOP of built-in API. + // this is intentional as we allow plugins to override + // built-ins + + + for (var plugin in jsPDF.API) { + if (jsPDF.API.hasOwnProperty(plugin)) { + if (plugin === "events" && jsPDF.API.events.length) { + (function (events, newEvents) { + // jsPDF.API.events is a JS Array of Arrays + // where each Array is a pair of event name, handler + // Events were added by plugins to the jsPDF instantiator. + // These are always added to the new instance and some ran + // during instantiation. + var eventname, handler_and_args, i; + + for (i = newEvents.length - 1; i !== -1; i--) { + // subscribe takes 3 args: 'topic', function, runonce_flag + // if undefined, runonce is false. + // users can attach callback directly, + // or they can attach an array with [callback, runonce_flag] + // that's what the "apply" magic is for below. + eventname = newEvents[i][0]; + handler_and_args = newEvents[i][1]; + events.subscribe.apply(events, [eventname].concat(typeof handler_and_args === "function" ? [handler_and_args] : handler_and_args)); + } + })(events, jsPDF.API.events); + } else { + API[plugin] = jsPDF.API[plugin]; + } + } + } + + var getPageWidth = API.getPageWidth = function (pageNumber) { + pageNumber = pageNumber || currentPage; + return (pagesContext[pageNumber].mediaBox.topRightX - pagesContext[pageNumber].mediaBox.bottomLeftX) / scaleFactor; + }; + + var setPageWidth = API.setPageWidth = function (pageNumber, value) { + pagesContext[pageNumber].mediaBox.topRightX = value * scaleFactor + pagesContext[pageNumber].mediaBox.bottomLeftX; + }; + + var getPageHeight = API.getPageHeight = function (pageNumber) { + pageNumber = pageNumber || currentPage; + return (pagesContext[pageNumber].mediaBox.topRightY - pagesContext[pageNumber].mediaBox.bottomLeftY) / scaleFactor; + }; + + var setPageHeight = API.setPageHeight = function (pageNumber, value) { + pagesContext[pageNumber].mediaBox.topRightY = value * scaleFactor + pagesContext[pageNumber].mediaBox.bottomLeftY; + }; + /** + * Object exposing internal API to plugins + * @public + * @ignore + */ + + + API.internal = { + pdfEscape: pdfEscape, + getStyle: getStyle, + getFont: getFontEntry, + getFontSize: getFontSize, + getCharSpace: getCharSpace, + getTextColor: getTextColor, + getLineHeight: getLineHeight, + getLineHeightFactor: getLineHeightFactor, + write: write, + getHorizontalCoordinate: getHorizontalCoordinate, + getVerticalCoordinate: getVerticalCoordinate, + getCoordinateString: getHorizontalCoordinateString, + getVerticalCoordinateString: getVerticalCoordinateString, + collections: {}, + newObject: newObject, + newAdditionalObject: newAdditionalObject, + newObjectDeferred: newObjectDeferred, + newObjectDeferredBegin: newObjectDeferredBegin, + getFilters: getFilters, + putStream: putStream, + events: events, + scaleFactor: scaleFactor, + pageSize: { + getWidth: function getWidth() { + return getPageWidth(currentPage); + }, + setWidth: function setWidth(value) { + setPageWidth(currentPage, value); + }, + getHeight: function getHeight() { + return getPageHeight(currentPage); + }, + setHeight: function setHeight(value) { + setPageHeight(currentPage, value); + } + }, + output: output, + getNumberOfPages: getNumberOfPages, + pages: pages, + out: out, + f2: f2, + f3: f3, + getPageInfo: getPageInfo, + getPageInfoByObjId: getPageInfoByObjId, + getCurrentPageInfo: getCurrentPageInfo, + getPDFVersion: getPdfVersion, + Point: Point, + Rectangle: Rectangle, + Matrix: Matrix, + hasHotfix: hasHotfix //Expose the hasHotfix check so plugins can also check them. + + }; + Object.defineProperty(API.internal.pageSize, "width", { + get: function get() { + return getPageWidth(currentPage); + }, + set: function set(value) { + setPageWidth(currentPage, value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(API.internal.pageSize, "height", { + get: function get() { + return getPageHeight(currentPage); + }, + set: function set(value) { + setPageHeight(currentPage, value); + }, + enumerable: true, + configurable: true + }); ////////////////////////////////////////////////////// + // continuing initialization of jsPDF Document object + ////////////////////////////////////////////////////// + // Add the first page automatically + + addFonts(standardFonts); + activeFontKey = "F1"; + + _addPage(format, orientation); + + events.publish("initialized"); + return API; + } + /** + * jsPDF.API is a STATIC property of jsPDF class. + * jsPDF.API is an object you can add methods and properties to. + * The methods / properties you add will show up in new jsPDF objects. + * + * One property is prepopulated. It is the 'events' Object. Plugin authors can add topics, + * callbacks to this object. These will be reassigned to all new instances of jsPDF. + * + * @static + * @public + * @memberof jsPDF# + * @name API + * + * @example + * jsPDF.API.mymethod = function(){ + * // 'this' will be ref to internal API object. see jsPDF source + * // , so you can refer to built-in methods like so: + * // this.line(....) + * // this.text(....) + * } + * var pdfdoc = new jsPDF() + * pdfdoc.mymethod() // <- !!!!!! + */ + + + jsPDF.API = { + events: [] + }; + /** + * The version of jsPDF. + * @name version + * @type {string} + * @memberof jsPDF# + */ + + jsPDF.version = '1.5.3'; + + if (typeof define === "function" && define.amd) { + define(function () { + return jsPDF; + }); + } else if (typeof module !== "undefined" && module.exports) { + module.exports = jsPDF; + module.exports.jsPDF = jsPDF; + } else { + global.jsPDF = jsPDF; + } + + return jsPDF; +}(typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function("return this")()); // `self` is undefined in Firefox for Android content script context +// while `this` is nsIContentFrameMessageManager +// with an attribute `content` that corresponds to the window + +/* global jsPDF */ + +/** @license + * jsPDF addImage plugin + * Copyright (c) 2012 Jason Siefken, https://github.com/siefkenj/ + * 2013 Chris Dowling, https://github.com/gingerchris + * 2013 Trinh Ho, https://github.com/ineedfat + * 2013 Edwin Alejandro Perez, https://github.com/eaparango + * 2013 Norah Smith, https://github.com/burnburnrocket + * 2014 Diego Casorran, https://github.com/diegocr + * 2014 James Robb, https://github.com/jamesbrobb + * + * + */ + +/** + * @name addImage + * @module + */ +(function (jsPDFAPI) { + + var namespace = "addImage_"; + jsPDFAPI.__addimage__ = {}; + var UNKNOWN = "UNKNOWN"; + var imageFileTypeHeaders = { + PNG: [[0x89, 0x50, 0x4e, 0x47]], + TIFF: [[0x4d, 0x4d, 0x00, 0x2a], //Motorola + [0x49, 0x49, 0x2a, 0x00] //Intel + ], + JPEG: [[0xff, 0xd8, 0xff, 0xe0, undefined, undefined, 0x4a, 0x46, 0x49, 0x46, 0x00], //JFIF + [0xff, 0xd8, 0xff, 0xe1, undefined, undefined, 0x45, 0x78, 0x69, 0x66, 0x00, 0x00], //Exif + [0xff, 0xd8, 0xff, 0xdb], //JPEG RAW + [0xff, 0xd8, 0xff, 0xee] //EXIF RAW + ], + JPEG2000: [[0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20]], + GIF87a: [[0x47, 0x49, 0x46, 0x38, 0x37, 0x61]], + GIF89a: [[0x47, 0x49, 0x46, 0x38, 0x39, 0x61]], + WEBP: [[0x52, 0x49, 0x46, 0x46, undefined, undefined, undefined, undefined, 0x57, 0x45, 0x42, 0x50]], + BMP: [[0x42, 0x4d], //BM - Windows 3.1x, 95, NT, ... etc. + [0x42, 0x41], //BA - OS/2 struct bitmap array + [0x43, 0x49], //CI - OS/2 struct color icon + [0x43, 0x50], //CP - OS/2 const color pointer + [0x49, 0x43], //IC - OS/2 struct icon + [0x50, 0x54] //PT - OS/2 pointer + ] + }; + /** + * Recognize filetype of Image by magic-bytes + * + * https://en.wikipedia.org/wiki/List_of_file_signatures + * + * @name getImageFileTypeByImageData + * @public + * @function + * @param {string|arraybuffer} imageData imageData as binary String or arraybuffer + * @param {string} format format of file if filetype-recognition fails, e.g. 'JPEG' + * + * @returns {string} filetype of Image + */ + + var getImageFileTypeByImageData = jsPDFAPI.__addimage__.getImageFileTypeByImageData = function (imageData, fallbackFormat) { + fallbackFormat = fallbackFormat || UNKNOWN; + var i; + var j; + var result = UNKNOWN; + var headerSchemata; + var compareResult; + var fileType; + + if (isArrayBufferView(imageData)) { + for (fileType in imageFileTypeHeaders) { + headerSchemata = imageFileTypeHeaders[fileType]; + + for (i = 0; i < headerSchemata.length; i += 1) { + compareResult = true; + + for (j = 0; j < headerSchemata[i].length; j += 1) { + if (headerSchemata[i][j] === undefined) { + continue; + } + + if (headerSchemata[i][j] !== imageData[j]) { + compareResult = false; + break; + } + } + + if (compareResult === true) { + result = fileType; + break; + } + } + } + } else { + for (fileType in imageFileTypeHeaders) { + headerSchemata = imageFileTypeHeaders[fileType]; + + for (i = 0; i < headerSchemata.length; i += 1) { + compareResult = true; + + for (j = 0; j < headerSchemata[i].length; j += 1) { + if (headerSchemata[i][j] === undefined) { + continue; + } + + if (headerSchemata[i][j] !== imageData.charCodeAt(j)) { + compareResult = false; + break; + } + } + + if (compareResult === true) { + result = fileType; + break; + } + } + } + } + + if (result === UNKNOWN && fallbackFormat !== UNKNOWN) { + result = fallbackFormat; + } + + return result; + }; // Image functionality ported from pdf.js + + + var putImage = function putImage(image) { + var out = this.internal.write; + var putStream = this.internal.putStream; + var getFilters = this.internal.getFilters; + var filter = getFilters(); + + while (filter.indexOf("FlateEncode") !== -1) { + filter.splice(filter.indexOf("FlateEncode"), 1); + } + + image.objectId = this.internal.newObject(); + var additionalKeyValues = []; + additionalKeyValues.push({ + key: "Type", + value: "/XObject" + }); + additionalKeyValues.push({ + key: "Subtype", + value: "/Image" + }); + additionalKeyValues.push({ + key: "Width", + value: image.width + }); + additionalKeyValues.push({ + key: "Height", + value: image.height + }); + + if (image.colorSpace === color_spaces.INDEXED) { + additionalKeyValues.push({ + key: "ColorSpace", + value: "[/Indexed /DeviceRGB " + ( // if an indexed png defines more than one colour with transparency, we've created a sMask + image.palette.length / 3 - 1) + " " + ("sMask" in image && typeof image.sMask !== "undefined" ? image.objectId + 2 : image.objectId + 1) + " 0 R]" + }); + } else { + additionalKeyValues.push({ + key: "ColorSpace", + value: "/" + image.colorSpace + }); + + if (image.colorSpace === color_spaces.DEVICE_CMYK) { + additionalKeyValues.push({ + key: "Decode", + value: "[1 0 1 0 1 0 1 0]" + }); + } + } + + additionalKeyValues.push({ + key: "BitsPerComponent", + value: image.bitsPerComponent + }); + + if ("decodeParameters" in image && typeof image.decodeParameters !== "undefined") { + additionalKeyValues.push({ + key: "DecodeParms", + value: "<<" + image.decodeParameters + ">>" + }); + } + + if ("transparency" in image && Array.isArray(image.transparency)) { + var transparency = "", + i = 0, + len = image.transparency.length; + + for (; i < len; i++) { + transparency += image.transparency[i] + " " + image.transparency[i] + " "; + } + + additionalKeyValues.push({ + key: "Mask", + value: "[" + transparency + "]" + }); + } + + if (typeof image.sMask !== "undefined") { + additionalKeyValues.push({ + key: "SMask", + value: image.objectId + 1 + " 0 R" + }); + } + + var alreadyAppliedFilters = typeof image.filter !== "undefined" ? ["/" + image.filter] : undefined; + putStream({ + data: image.data, + additionalKeyValues: additionalKeyValues, + alreadyAppliedFilters: alreadyAppliedFilters + }); + out("endobj"); // Soft mask + + if ("sMask" in image && typeof image.sMask !== "undefined") { + var decodeParameters = "/Predictor " + image.predictor + " /Colors 1 /BitsPerComponent " + image.bitsPerComponent + " /Columns " + image.width; + var sMask = { + width: image.width, + height: image.height, + colorSpace: "DeviceGray", + bitsPerComponent: image.bitsPerComponent, + decodeParameters: decodeParameters, + data: image.sMask + }; + + if ("filter" in image) { + sMask.filter = image.filter; + } + + putImage.call(this, sMask); + } //Palette + + + if (image.colorSpace === color_spaces.INDEXED) { + this.internal.newObject(); //out('<< /Filter / ' + img['f'] +' /Length ' + img['pal'].length + '>>'); + //putStream(zlib.compress(img['pal'])); + + putStream({ + data: arrayBufferToBinaryString(new Uint8Array(image.palette)) + }); + out("endobj"); + } + }; + + var putResourcesCallback = function putResourcesCallback() { + var images = this.internal.collections[namespace + "images"]; + + for (var i in images) { + putImage.call(this, images[i]); + } + }; + + var putXObjectsDictCallback = function putXObjectsDictCallback() { + var images = this.internal.collections[namespace + "images"], + out = this.internal.write, + image; + + for (var i in images) { + image = images[i]; + out("/I" + image.index, image.objectId, "0", "R"); + } + }; + + var checkCompressValue = function checkCompressValue(value) { + if (value && typeof value === "string") { value = value.toUpperCase(); } + return value in jsPDFAPI.image_compression ? value : image_compression.NONE; + }; + + var initialize = function initialize() { + if (!this.internal.collections[namespace + "images"]) { + this.internal.collections[namespace + "images"] = {}; + this.internal.events.subscribe("putResources", putResourcesCallback); + this.internal.events.subscribe("putXobjectDict", putXObjectsDictCallback); + } + }; + + var getImages = function getImages() { + var images = this.internal.collections[namespace + "images"]; + initialize.call(this); + return images; + }; + + var getImageIndex = function getImageIndex() { + return Object.keys(this.internal.collections[namespace + "images"]).length; + }; + + var notDefined = function notDefined(value) { + return typeof value === "undefined" || value === null || value.length === 0; + }; + + var generateAliasFromImageData = function generateAliasFromImageData(imageData) { + if (typeof imageData === "string" || isArrayBufferView(imageData)) { + return sHashCode(imageData); + } + + return null; + }; + + var isImageTypeSupported = function isImageTypeSupported(type) { + return typeof jsPDFAPI["process" + type.toUpperCase()] === "function"; + }; + + var isDOMElement = function isDOMElement(object) { + return _typeof(object) === "object" && object.nodeType === 1; + }; + + var getImageDataFromElement = function getImageDataFromElement(element, format) { + //if element is an image which uses data url definition, just return the dataurl + if (element.nodeName === "IMG" && element.hasAttribute("src")) { + var src = "" + element.getAttribute("src"); //is base64 encoded dataUrl, directly process it + + if (src.indexOf("data:image/") === 0) { + return atob(unescape(src).split("base64,").pop()); + } //it is probably an url, try to load it + + + var tmpImageData = jsPDFAPI.loadFile(src, true); + + if (tmpImageData !== undefined) { + return tmpImageData; + } + } + + if (element.nodeName === "CANVAS") { + var mimeType; + + switch (format) { + case "PNG": + mimeType = "image/png"; + break; + + case "WEBP": + mimeType = "image/webp"; + break; + + case "JPEG": + case "JPG": + default: + mimeType = "image/jpeg"; + break; + } + + return atob(element.toDataURL(mimeType, 1.0).split("base64,").pop()); + } + }; + + var checkImagesForAlias = function checkImagesForAlias(alias) { + var images = this.internal.collections[namespace + "images"]; + + if (images) { + for (var e in images) { + if (alias === images[e].alias) { + return images[e]; + } + } + } + }; + + var determineWidthAndHeight = function determineWidthAndHeight(width, height, image) { + if (!width && !height) { + width = -96; + height = -96; + } + + if (width < 0) { + width = -1 * image.width * 72 / width / this.internal.scaleFactor; + } + + if (height < 0) { + height = -1 * image.height * 72 / height / this.internal.scaleFactor; + } + + if (width === 0) { + width = height * image.width / image.height; + } + + if (height === 0) { + height = width * image.height / image.width; + } + + return [width, height]; + }; + + var writeImageToPDF = function writeImageToPDF(x, y, width, height, image, rotation) { + var dims = determineWidthAndHeight.call(this, width, height, image), + coord = this.internal.getCoordinateString, + vcoord = this.internal.getVerticalCoordinateString; + var images = getImages.call(this); + width = dims[0]; + height = dims[1]; + images[image.index] = image; + + if (rotation) { + rotation *= Math.PI / 180; + var c = Math.cos(rotation); + var s = Math.sin(rotation); //like in pdf Reference do it 4 digits instead of 2 + + var f4 = function f4(number) { + return number.toFixed(4); + }; + + var rotationTransformationMatrix = [f4(c), f4(s), f4(s * -1), f4(c), 0, 0, "cm"]; + } + + this.internal.write("q"); //Save graphics state + + if (rotation) { + this.internal.write([1, "0", "0", 1, coord(x), vcoord(y + height), "cm"].join(" ")); //Translate + + this.internal.write(rotationTransformationMatrix.join(" ")); //Rotate + + this.internal.write([coord(width), "0", "0", coord(height), "0", "0", "cm"].join(" ")); //Scale + } else { + this.internal.write([coord(width), "0", "0", coord(height), coord(x), vcoord(y + height), "cm"].join(" ")); //Translate and Scale + } + + if (this.isAdvancedAPI()) { + // draw image bottom up when in "advanced" API mode + this.internal.write([1, 0, 0, -1, 0, 0, "cm"].join(" ")); + } + + this.internal.write("/I" + image.index + " Do"); //Paint Image + + this.internal.write("Q"); //Restore graphics state + }; + /** + * COLOR SPACES + */ + + + var color_spaces = jsPDFAPI.color_spaces = { + DEVICE_RGB: "DeviceRGB", + DEVICE_GRAY: "DeviceGray", + DEVICE_CMYK: "DeviceCMYK", + CAL_GREY: "CalGray", + CAL_RGB: "CalRGB", + LAB: "Lab", + ICC_BASED: "ICCBased", + INDEXED: "Indexed", + PATTERN: "Pattern", + SEPARATION: "Separation", + DEVICE_N: "DeviceN" + }; + /** + * DECODE METHODS + */ + + jsPDFAPI.decode = { + DCT_DECODE: "DCTDecode", + FLATE_DECODE: "FlateDecode", + LZW_DECODE: "LZWDecode", + JPX_DECODE: "JPXDecode", + JBIG2_DECODE: "JBIG2Decode", + ASCII85_DECODE: "ASCII85Decode", + ASCII_HEX_DECODE: "ASCIIHexDecode", + RUN_LENGTH_DECODE: "RunLengthDecode", + CCITT_FAX_DECODE: "CCITTFaxDecode" + }; + /** + * IMAGE COMPRESSION TYPES + */ + + var image_compression = jsPDFAPI.image_compression = { + NONE: "NONE", + FAST: "FAST", + MEDIUM: "MEDIUM", + SLOW: "SLOW" + }; + /** + * @name sHashCode + * @function + * @param {string} data + * @returns {string} + */ + + var sHashCode = jsPDFAPI.__addimage__.sHashCode = function (data) { + var hash = 0, + i, + len; + + if (typeof data === "string") { + len = data.length; + + for (i = 0; i < len; i++) { + hash = (hash << 5) - hash + data.charCodeAt(i); + hash |= 0; // Convert to 32bit integer + } + } else if (isArrayBufferView(data)) { + len = data.byteLength / 2; + + for (i = 0; i < len; i++) { + hash = (hash << 5) - hash + data[i]; + hash |= 0; // Convert to 32bit integer + } + } + + return hash; + }; + /** + * Validates if given String is a valid Base64-String + * + * @name validateStringAsBase64 + * @public + * @function + * @param {String} possible Base64-String + * + * @returns {boolean} + */ + + + var validateStringAsBase64 = jsPDFAPI.__addimage__.validateStringAsBase64 = function (possibleBase64String) { + possibleBase64String = possibleBase64String || ""; + possibleBase64String.toString().trim(); + var result = true; + + if (possibleBase64String.length === 0) { + result = false; + } + + if (possibleBase64String.length % 4 !== 0) { + result = false; + } + + if (/^[A-Za-z0-9+/]+$/.test(possibleBase64String.substr(0, possibleBase64String.length - 2)) === false) { + result = false; + } + + if (/^[A-Za-z0-9/][A-Za-z0-9+/]|[A-Za-z0-9+/]=|==$/.test(possibleBase64String.substr(-2)) === false) { + result = false; + } + + return result; + }; + /** + * Strips out and returns info from a valid base64 data URI + * + * @name extractImageFromDataUrl + * @function + * @param {string} dataUrl a valid data URI of format 'data:[][;base64],' + * @returns {Array}an Array containing the following + * [0] the complete data URI + * [1] + * [2] format - the second part of the mime-type i.e 'png' in 'image/png' + * [4] + */ + + + var extractImageFromDataUrl = jsPDFAPI.__addimage__.extractImageFromDataUrl = function (dataUrl) { + dataUrl = dataUrl || ""; + var dataUrlParts = dataUrl.split("base64,"); + var result = null; + + if (dataUrlParts.length === 2) { + var extractedInfo = /^data:(\w*\/\w*);*(charset=[\w=-]*)*;*$/.exec(dataUrlParts[0]); + + if (Array.isArray(extractedInfo)) { + result = { + mimeType: extractedInfo[1], + charset: extractedInfo[2], + data: dataUrlParts[1] + }; + } + } + + return result; + }; + /** + * Check to see if ArrayBuffer is supported + * + * @name supportsArrayBuffer + * @function + * @returns {boolean} + */ + + + var supportsArrayBuffer = jsPDFAPI.__addimage__.supportsArrayBuffer = function () { + return typeof ArrayBuffer !== "undefined" && typeof Uint8Array !== "undefined"; + }; + /** + * Tests supplied object to determine if ArrayBuffer + * + * @name isArrayBuffer + * @function + * @param {Object} object an Object + * + * @returns {boolean} + */ + + + jsPDFAPI.__addimage__.isArrayBuffer = function (object) { + return supportsArrayBuffer() && object instanceof ArrayBuffer; + }; + /** + * Tests supplied object to determine if it implements the ArrayBufferView (TypedArray) interface + * + * @name isArrayBufferView + * @function + * @param {Object} object an Object + * @returns {boolean} + */ + + + var isArrayBufferView = jsPDFAPI.__addimage__.isArrayBufferView = function (object) { + return supportsArrayBuffer() && typeof Uint32Array !== "undefined" && (object instanceof Int8Array || object instanceof Uint8Array || typeof Uint8ClampedArray !== "undefined" && object instanceof Uint8ClampedArray || object instanceof Int16Array || object instanceof Uint16Array || object instanceof Int32Array || object instanceof Uint32Array || object instanceof Float32Array || object instanceof Float64Array); + }; + /** + * Convert Binary String to ArrayBuffer + * + * @name binaryStringToUint8Array + * @public + * @function + * @param {string} BinaryString with ImageData + * @returns {Uint8Array} + */ + + + var binaryStringToUint8Array = jsPDFAPI.__addimage__.binaryStringToUint8Array = function (binary_string) { + var len = binary_string.length; + var bytes = new Uint8Array(len); + + for (var i = 0; i < len; i++) { + bytes[i] = binary_string.charCodeAt(i); + } + + return bytes; + }; + /** + * Convert the Buffer to a Binary String + * + * @name arrayBufferToBinaryString + * @public + * @function + * @param {ArrayBuffer} ArrayBuffer with ImageData + * + * @returns {String} + */ + + + var arrayBufferToBinaryString = jsPDFAPI.__addimage__.arrayBufferToBinaryString = function (buffer) { + try { + return atob(btoa(String.fromCharCode.apply(null, buffer))); + } catch (e) { + if (typeof Uint8Array !== "undefined" && typeof Uint8Array.prototype.reduce !== "undefined") { + return new Uint8Array(buffer).reduce(function (data, _byte) { + return data.push(String.fromCharCode(_byte)), data; + }, []).join(""); + } + } + }; + /** + * Adds an Image to the PDF. + * + * @name addImage + * @public + * @function + * @param {string|HTMLImageElement|HTMLCanvasElement|Uint8Array} imageData imageData as base64 encoded DataUrl or Image-HTMLElement or Canvas-HTMLElement + * @param {string} format format of file if filetype-recognition fails or in case of a Canvas-Element needs to be specified (default for Canvas is JPEG), e.g. 'JPEG', 'PNG', 'WEBP' + * @param {number} x x Coordinate (in units declared at inception of PDF document) against left edge of the page + * @param {number} y y Coordinate (in units declared at inception of PDF document) against upper edge of the page + * @param {number} width width of the image (in units declared at inception of PDF document) + * @param {number} height height of the Image (in units declared at inception of PDF document) + * @param {string} alias alias of the image (if used multiple times) + * @param {string} compression compression of the generated JPEG, can have the values 'NONE', 'FAST', 'MEDIUM' and 'SLOW' + * @param {number} rotation rotation of the image in degrees (0-359) + * + * @returns jsPDF + */ + + + jsPDFAPI.addImage = function () { + var imageData, format, x, y, w, h, alias, compression, rotation; + imageData = arguments[0]; + + if (typeof arguments[1] === "number") { + format = UNKNOWN; + x = arguments[1]; + y = arguments[2]; + w = arguments[3]; + h = arguments[4]; + alias = arguments[5]; + compression = arguments[6]; + rotation = arguments[7]; + } else { + format = arguments[1]; + x = arguments[2]; + y = arguments[3]; + w = arguments[4]; + h = arguments[5]; + alias = arguments[6]; + compression = arguments[7]; + rotation = arguments[8]; + } + + if (_typeof(imageData) === "object" && !isDOMElement(imageData) && "imageData" in imageData) { + var options = imageData; + imageData = options.imageData; + format = options.format || format || UNKNOWN; + x = options.x || x || 0; + y = options.y || y || 0; + w = options.w || options.width || w; + h = options.h || options.height || h; + alias = options.alias || alias; + compression = options.compression || compression; + rotation = options.rotation || options.angle || rotation; + } //If compression is not explicitly set, determine if we should use compression + + + var filter = this.internal.getFilters(); + + if (compression === undefined && filter.indexOf("FlateEncode") !== -1) { + compression = "SLOW"; + } + + if (isNaN(x) || isNaN(y)) { + throw new Error("Invalid coordinates passed to jsPDF.addImage"); + } + + initialize.call(this); + var image = processImageData.call(this, imageData, format, alias, compression); + writeImageToPDF.call(this, x, y, w, h, image, rotation); + return this; + }; + + var processImageData = function processImageData(imageData, format, alias, compression) { + var result, dataAsBinaryString; + + if (typeof imageData === "string" && getImageFileTypeByImageData(imageData) === UNKNOWN) { + imageData = unescape(imageData); + var tmpImageData = convertBase64ToBinaryString(imageData, false); + + if (tmpImageData !== "") { + imageData = tmpImageData; + } else { + tmpImageData = jsPDFAPI.loadFile(imageData, true); + + if (tmpImageData !== undefined) { + imageData = tmpImageData; + } + } + } + + if (isDOMElement(imageData)) { + imageData = getImageDataFromElement(imageData, format); + } + + format = getImageFileTypeByImageData(imageData, format); + + if (!isImageTypeSupported(format)) { + throw new Error("addImage does not support files of type '" + format + "', please ensure that a plugin for '" + format + "' support is added."); + } // now do the heavy lifting + + + if (notDefined(alias)) { + alias = generateAliasFromImageData(imageData); + } + + result = checkImagesForAlias.call(this, alias); + + if (!result) { + if (supportsArrayBuffer()) { + // no need to convert if imageData is already uint8array + if (!(imageData instanceof Uint8Array)) { + dataAsBinaryString = imageData; + imageData = binaryStringToUint8Array(imageData); + } + } + + result = this["process" + format.toUpperCase()](imageData, getImageIndex.call(this), alias, checkCompressValue(compression), dataAsBinaryString); + } + + if (!result) { + throw new Error("An unknown error occurred whilst processing the image."); + } + + return result; + }; + /** + * @name convertBase64ToBinaryString + * @function + * @param {string} stringData + * @returns {string} binary string + */ + + + var convertBase64ToBinaryString = jsPDFAPI.__addimage__.convertBase64ToBinaryString = function (stringData, throwError) { + throwError = typeof throwError === "boolean" ? throwError : true; + var base64Info; + var imageData = ""; + var rawData; + + if (typeof stringData === "string") { + base64Info = extractImageFromDataUrl(stringData); + rawData = base64Info !== null ? base64Info.data : stringData; + + try { + imageData = atob(rawData); + } catch (e) { + if (throwError) { + if (!validateStringAsBase64(rawData)) { + throw new Error("Supplied Data is not a valid base64-String jsPDF.convertBase64ToBinaryString "); + } else { + throw new Error("atob-Error in jsPDF.convertBase64ToBinaryString " + e.message); + } + } + } + } + + return imageData; + }; + /** + * @name getImageProperties + * @function + * @param {Object} imageData + * @returns {Object} + */ + + + jsPDFAPI.getImageProperties = function (imageData) { + var image; + var tmpImageData = ""; + var format; + + if (isDOMElement(imageData)) { + imageData = getImageDataFromElement(imageData); + } + + if (typeof imageData === "string" && getImageFileTypeByImageData(imageData) === UNKNOWN) { + tmpImageData = convertBase64ToBinaryString(imageData, false); + + if (tmpImageData === "") { + tmpImageData = jsPDFAPI.loadFile(imageData) || ""; + } + + imageData = tmpImageData; + } + + format = getImageFileTypeByImageData(imageData); + + if (!isImageTypeSupported(format)) { + throw new Error("addImage does not support files of type '" + format + "', please ensure that a plugin for '" + format + "' support is added."); + } + + if (supportsArrayBuffer() && !(imageData instanceof Uint8Array)) { + imageData = binaryStringToUint8Array(imageData); + } + + image = this["process" + format.toUpperCase()](imageData); + + if (!image) { + throw new Error("An unknown error occurred whilst processing the image"); + } + + image.fileType = format; + return image; + }; +})(jsPDF.API); + +/* global jsPDF */ + +/** + * @license + * Copyright (c) 2014 Steven Spungin (TwelveTone LLC) steven@twelvetone.tv + * + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ + +/** + * jsPDF Annotations PlugIn + * + * There are many types of annotations in a PDF document. Annotations are placed + * on a page at a particular location. They are not 'attached' to an object. + *
+ * This plugin current supports
+ *
  • Goto Page (set pageNumber and top in options) + *
  • Goto Name (set name and top in options) + *
  • Goto URL (set url in options) + *

    + * The destination magnification factor can also be specified when goto is a page number or a named destination. (see documentation below) + * (set magFactor in options). XYZ is the default. + *

    + *

    + * Links, Text, Popup, and FreeText are supported. + *

    + *

    + * Options In PDF spec Not Implemented Yet + *

  • link border + *
  • named target + *
  • page coordinates + *
  • destination page scaling and layout + *
  • actions other than URL and GotoPage + *
  • background / hover actions + *

    + * @name annotations + * @module + */ + +/* + Destination Magnification Factors + See PDF 1.3 Page 386 for meanings and options + + [supported] + XYZ (options; left top zoom) + Fit (no options) + FitH (options: top) + FitV (options: left) + + [not supported] + FitR + FitB + FitBH + FitBV + */ +(function (jsPDFAPI) { + + var notEmpty = function notEmpty(obj) { + if (typeof obj != "undefined") { + if (obj != "") { + return true; + } + } + }; + + jsPDF.API.events.push(["addPage", function (addPageData) { + var pageInfo = this.internal.getPageInfo(addPageData.pageNumber); + pageInfo.pageContext.annotations = []; + }]); + jsPDFAPI.events.push(["putPage", function (putPageData) { + var getHorizontalCoordinateString = this.internal.getCoordinateString; + var getVerticalCoordinateString = this.internal.getVerticalCoordinateString; + var pageInfo = this.internal.getPageInfoByObjId(putPageData.objId); + var pageAnnos = putPageData.pageContext.annotations; + var anno, rect, line; + var found = false; + + for (var a = 0; a < pageAnnos.length && !found; a++) { + anno = pageAnnos[a]; + + switch (anno.type) { + case "link": + if (notEmpty(anno.options.url) || notEmpty(anno.options.pageNumber)) { + found = true; + } + + break; + + case "reference": + case "text": + case "freetext": + found = true; + break; + } + } + + if (found == false) { + return; + } + + this.internal.write("/Annots ["); + + for (var i = 0; i < pageAnnos.length; i++) { + anno = pageAnnos[i]; + + switch (anno.type) { + case "reference": + // References to Widget Annotations (for AcroForm Fields) + this.internal.write(" " + anno.object.objId + " 0 R "); + break; + + case "text": + // Create a an object for both the text and the popup + var objText = this.internal.newAdditionalObject(); + var objPopup = this.internal.newAdditionalObject(); + var title = anno.title || "Note"; + rect = "/Rect [" + getHorizontalCoordinateString(anno.bounds.x) + " " + getVerticalCoordinateString(anno.bounds.y + anno.bounds.h) + " " + getHorizontalCoordinateString(anno.bounds.x + anno.bounds.w) + " " + getVerticalCoordinateString(anno.bounds.y) + "] "; + line = "<>"; + objText.content = line; + var parent = objText.objId + " 0 R"; + var popoff = 30; + rect = "/Rect [" + getHorizontalCoordinateString(anno.bounds.x + popoff) + " " + getVerticalCoordinateString(anno.bounds.y + anno.bounds.h) + " " + getHorizontalCoordinateString(anno.bounds.x + anno.bounds.w + popoff) + " " + getVerticalCoordinateString(anno.bounds.y) + "] "; + line = "<>"; + } else if (anno.options.pageNumber) { + // first page is 0 + var info = this.internal.getPageInfo(anno.options.pageNumber); + line = "< pageNumber or url [required] + *

    If pageNumber is specified, top and zoom may also be specified

    + * @name link + * @function + * @param {number} x + * @param {number} y + * @param {number} w + * @param {number} h + * @param {Object} options + */ + + + jsPDFAPI.link = function (x, y, w, h, options) { + var pageInfo = this.internal.getCurrentPageInfo(); + pageInfo.pageContext.annotations.push({ + x: x, + y: y, + w: w, + h: h, + options: options, + type: "link" + }); + }; + /** + * Currently only supports single line text. + * Returns the width of the text/link + * + * @name textWithLink + * @function + * @param {string} text + * @param {number} x + * @param {number} y + * @param {Object} options + * @returns {number} width the width of the text/link + */ + + + jsPDFAPI.textWithLink = function (text, x, y, options) { + var width = this.getTextWidth(text); + var height = this.internal.getLineHeight() / this.internal.scaleFactor; + this.text(text, x, y, options); //TODO We really need the text baseline height to do this correctly. + // Or ability to draw text on top, bottom, center, or baseline. + + y += height * 0.2; + this.link(x, y - height, width, height, options); + return width; + }; //TODO move into external library + + /** + * @name getTextWidth + * @function + * @param {string} text + * @returns {number} txtWidth + */ + + + jsPDFAPI.getTextWidth = function (text) { + var fontSize = this.internal.getFontSize(); + var txtWidth = this.getStringUnitWidth(text) * fontSize / this.internal.scaleFactor; + return txtWidth; + }; + + return this; +})(jsPDF.API); + +/* global jsPDF */ + +/** + * @license + * Copyright (c) 2017 Aras Abbasi + * + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ + +/** + * jsPDF arabic parser PlugIn + * + * @name arabic + * @module + */ +(function (jsPDFAPI) { + /** + * Arabic shape substitutions: char code => (isolated, final, initial, medial). + * Arabic Substition A + */ + + var arabicSubstitionA = { + 0x0621: [0xfe80], + // ARABIC LETTER HAMZA + 0x0622: [0xfe81, 0xfe82], + // ARABIC LETTER ALEF WITH MADDA ABOVE + 0x0623: [0xfe83, 0xfe84], + // ARABIC LETTER ALEF WITH HAMZA ABOVE + 0x0624: [0xfe85, 0xfe86], + // ARABIC LETTER WAW WITH HAMZA ABOVE + 0x0625: [0xfe87, 0xfe88], + // ARABIC LETTER ALEF WITH HAMZA BELOW + 0x0626: [0xfe89, 0xfe8a, 0xfe8b, 0xfe8c], + // ARABIC LETTER YEH WITH HAMZA ABOVE + 0x0627: [0xfe8d, 0xfe8e], + // ARABIC LETTER ALEF + 0x0628: [0xfe8f, 0xfe90, 0xfe91, 0xfe92], + // ARABIC LETTER BEH + 0x0629: [0xfe93, 0xfe94], + // ARABIC LETTER TEH MARBUTA + 0x062a: [0xfe95, 0xfe96, 0xfe97, 0xfe98], + // ARABIC LETTER TEH + 0x062b: [0xfe99, 0xfe9a, 0xfe9b, 0xfe9c], + // ARABIC LETTER THEH + 0x062c: [0xfe9d, 0xfe9e, 0xfe9f, 0xfea0], + // ARABIC LETTER JEEM + 0x062d: [0xfea1, 0xfea2, 0xfea3, 0xfea4], + // ARABIC LETTER HAH + 0x062e: [0xfea5, 0xfea6, 0xfea7, 0xfea8], + // ARABIC LETTER KHAH + 0x062f: [0xfea9, 0xfeaa], + // ARABIC LETTER DAL + 0x0630: [0xfeab, 0xfeac], + // ARABIC LETTER THAL + 0x0631: [0xfead, 0xfeae], + // ARABIC LETTER REH + 0x0632: [0xfeaf, 0xfeb0], + // ARABIC LETTER ZAIN + 0x0633: [0xfeb1, 0xfeb2, 0xfeb3, 0xfeb4], + // ARABIC LETTER SEEN + 0x0634: [0xfeb5, 0xfeb6, 0xfeb7, 0xfeb8], + // ARABIC LETTER SHEEN + 0x0635: [0xfeb9, 0xfeba, 0xfebb, 0xfebc], + // ARABIC LETTER SAD + 0x0636: [0xfebd, 0xfebe, 0xfebf, 0xfec0], + // ARABIC LETTER DAD + 0x0637: [0xfec1, 0xfec2, 0xfec3, 0xfec4], + // ARABIC LETTER TAH + 0x0638: [0xfec5, 0xfec6, 0xfec7, 0xfec8], + // ARABIC LETTER ZAH + 0x0639: [0xfec9, 0xfeca, 0xfecb, 0xfecc], + // ARABIC LETTER AIN + 0x063a: [0xfecd, 0xfece, 0xfecf, 0xfed0], + // ARABIC LETTER GHAIN + 0x0641: [0xfed1, 0xfed2, 0xfed3, 0xfed4], + // ARABIC LETTER FEH + 0x0642: [0xfed5, 0xfed6, 0xfed7, 0xfed8], + // ARABIC LETTER QAF + 0x0643: [0xfed9, 0xfeda, 0xfedb, 0xfedc], + // ARABIC LETTER KAF + 0x0644: [0xfedd, 0xfede, 0xfedf, 0xfee0], + // ARABIC LETTER LAM + 0x0645: [0xfee1, 0xfee2, 0xfee3, 0xfee4], + // ARABIC LETTER MEEM + 0x0646: [0xfee5, 0xfee6, 0xfee7, 0xfee8], + // ARABIC LETTER NOON + 0x0647: [0xfee9, 0xfeea, 0xfeeb, 0xfeec], + // ARABIC LETTER HEH + 0x0648: [0xfeed, 0xfeee], + // ARABIC LETTER WAW + 0x0649: [0xfeef, 0xfef0, 64488, 64489], + // ARABIC LETTER ALEF MAKSURA + 0x064a: [0xfef1, 0xfef2, 0xfef3, 0xfef4], + // ARABIC LETTER YEH + 0x0671: [0xfb50, 0xfb51], + // ARABIC LETTER ALEF WASLA + 0x0677: [0xfbdd], + // ARABIC LETTER U WITH HAMZA ABOVE + 0x0679: [0xfb66, 0xfb67, 0xfb68, 0xfb69], + // ARABIC LETTER TTEH + 0x067a: [0xfb5e, 0xfb5f, 0xfb60, 0xfb61], + // ARABIC LETTER TTEHEH + 0x067b: [0xfb52, 0xfb53, 0xfb54, 0xfb55], + // ARABIC LETTER BEEH + 0x067e: [0xfb56, 0xfb57, 0xfb58, 0xfb59], + // ARABIC LETTER PEH + 0x067f: [0xfb62, 0xfb63, 0xfb64, 0xfb65], + // ARABIC LETTER TEHEH + 0x0680: [0xfb5a, 0xfb5b, 0xfb5c, 0xfb5d], + // ARABIC LETTER BEHEH + 0x0683: [0xfb76, 0xfb77, 0xfb78, 0xfb79], + // ARABIC LETTER NYEH + 0x0684: [0xfb72, 0xfb73, 0xfb74, 0xfb75], + // ARABIC LETTER DYEH + 0x0686: [0xfb7a, 0xfb7b, 0xfb7c, 0xfb7d], + // ARABIC LETTER TCHEH + 0x0687: [0xfb7e, 0xfb7f, 0xfb80, 0xfb81], + // ARABIC LETTER TCHEHEH + 0x0688: [0xfb88, 0xfb89], + // ARABIC LETTER DDAL + 0x068c: [0xfb84, 0xfb85], + // ARABIC LETTER DAHAL + 0x068d: [0xfb82, 0xfb83], + // ARABIC LETTER DDAHAL + 0x068e: [0xfb86, 0xfb87], + // ARABIC LETTER DUL + 0x0691: [0xfb8c, 0xfb8d], + // ARABIC LETTER RREH + 0x0698: [0xfb8a, 0xfb8b], + // ARABIC LETTER JEH + 0x06a4: [0xfb6a, 0xfb6b, 0xfb6c, 0xfb6d], + // ARABIC LETTER VEH + 0x06a6: [0xfb6e, 0xfb6f, 0xfb70, 0xfb71], + // ARABIC LETTER PEHEH + 0x06a9: [0xfb8e, 0xfb8f, 0xfb90, 0xfb91], + // ARABIC LETTER KEHEH + 0x06ad: [0xfbd3, 0xfbd4, 0xfbd5, 0xfbd6], + // ARABIC LETTER NG + 0x06af: [0xfb92, 0xfb93, 0xfb94, 0xfb95], + // ARABIC LETTER GAF + 0x06b1: [0xfb9a, 0xfb9b, 0xfb9c, 0xfb9d], + // ARABIC LETTER NGOEH + 0x06b3: [0xfb96, 0xfb97, 0xfb98, 0xfb99], + // ARABIC LETTER GUEH + 0x06ba: [0xfb9e, 0xfb9f], + // ARABIC LETTER NOON GHUNNA + 0x06bb: [0xfba0, 0xfba1, 0xfba2, 0xfba3], + // ARABIC LETTER RNOON + 0x06be: [0xfbaa, 0xfbab, 0xfbac, 0xfbad], + // ARABIC LETTER HEH DOACHASHMEE + 0x06c0: [0xfba4, 0xfba5], + // ARABIC LETTER HEH WITH YEH ABOVE + 0x06c1: [0xfba6, 0xfba7, 0xfba8, 0xfba9], + // ARABIC LETTER HEH GOAL + 0x06c5: [0xfbe0, 0xfbe1], + // ARABIC LETTER KIRGHIZ OE + 0x06c6: [0xfbd9, 0xfbda], + // ARABIC LETTER OE + 0x06c7: [0xfbd7, 0xfbd8], + // ARABIC LETTER U + 0x06c8: [0xfbdb, 0xfbdc], + // ARABIC LETTER YU + 0x06c9: [0xfbe2, 0xfbe3], + // ARABIC LETTER KIRGHIZ YU + 0x06cb: [0xfbde, 0xfbdf], + // ARABIC LETTER VE + 0x06cc: [0xfbfc, 0xfbfd, 0xfbfe, 0xfbff], + // ARABIC LETTER FARSI YEH + 0x06d0: [0xfbe4, 0xfbe5, 0xfbe6, 0xfbe7], + //ARABIC LETTER E + 0x06d2: [0xfbae, 0xfbaf], + // ARABIC LETTER YEH BARREE + 0x06d3: [0xfbb0, 0xfbb1] // ARABIC LETTER YEH BARREE WITH HAMZA ABOVE + + }; + /* + var ligaturesSubstitutionA = { + 0xFBEA: []// ARABIC LIGATURE YEH WITH HAMZA ABOVE WITH ALEF ISOLATED FORM + }; + */ + + var ligatures = { + 0xfedf: { + 0xfe82: 0xfef5, + // ARABIC LIGATURE LAM WITH ALEF WITH MADDA ABOVE ISOLATED FORM + 0xfe84: 0xfef7, + // ARABIC LIGATURE LAM WITH ALEF WITH HAMZA ABOVE ISOLATED FORM + 0xfe88: 0xfef9, + // ARABIC LIGATURE LAM WITH ALEF WITH HAMZA BELOW ISOLATED FORM + 0xfe8e: 0xfefb // ARABIC LIGATURE LAM WITH ALEF ISOLATED FORM + + }, + 0xfee0: { + 0xfe82: 0xfef6, + // ARABIC LIGATURE LAM WITH ALEF WITH MADDA ABOVE FINAL FORM + 0xfe84: 0xfef8, + // ARABIC LIGATURE LAM WITH ALEF WITH HAMZA ABOVE FINAL FORM + 0xfe88: 0xfefa, + // ARABIC LIGATURE LAM WITH ALEF WITH HAMZA BELOW FINAL FORM + 0xfe8e: 0xfefc // ARABIC LIGATURE LAM WITH ALEF FINAL FORM + + }, + 0xfe8d: { + 0xfedf: { + 0xfee0: { + 0xfeea: 0xfdf2 + } + } + }, + // ALLAH + 0x0651: { + 0x064c: 0xfc5e, + // Shadda + Dammatan + 0x064d: 0xfc5f, + // Shadda + Kasratan + 0x064e: 0xfc60, + // Shadda + Fatha + 0x064f: 0xfc61, + // Shadda + Damma + 0x0650: 0xfc62 // Shadda + Kasra + + } + }; + var arabic_diacritics = { + 1612: 64606, + // Shadda + Dammatan + 1613: 64607, + // Shadda + Kasratan + 1614: 64608, + // Shadda + Fatha + 1615: 64609, + // Shadda + Damma + 1616: 64610 // Shadda + Kasra + + }; + var alfletter = [1570, 1571, 1573, 1575]; + var noChangeInForm = -1; + var isolatedForm = 0; + var finalForm = 1; + var initialForm = 2; + var medialForm = 3; + jsPDFAPI.__arabicParser__ = {}; //private + + var isInArabicSubstitutionA = jsPDFAPI.__arabicParser__.isInArabicSubstitutionA = function (letter) { + return typeof arabicSubstitionA[letter.charCodeAt(0)] !== "undefined"; + }; + + var isArabicLetter = jsPDFAPI.__arabicParser__.isArabicLetter = function (letter) { + return typeof letter === "string" && /^[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]+$/.test(letter); + }; + + var isArabicEndLetter = jsPDFAPI.__arabicParser__.isArabicEndLetter = function (letter) { + return isArabicLetter(letter) && isInArabicSubstitutionA(letter) && arabicSubstitionA[letter.charCodeAt(0)].length <= 2; + }; + + var isArabicAlfLetter = jsPDFAPI.__arabicParser__.isArabicAlfLetter = function (letter) { + return isArabicLetter(letter) && alfletter.indexOf(letter.charCodeAt(0)) >= 0; + }; + + jsPDFAPI.__arabicParser__.arabicLetterHasIsolatedForm = function (letter) { + return isArabicLetter(letter) && isInArabicSubstitutionA(letter) && arabicSubstitionA[letter.charCodeAt(0)].length >= 1; + }; + + var arabicLetterHasFinalForm = jsPDFAPI.__arabicParser__.arabicLetterHasFinalForm = function (letter) { + return isArabicLetter(letter) && isInArabicSubstitutionA(letter) && arabicSubstitionA[letter.charCodeAt(0)].length >= 2; + }; + + jsPDFAPI.__arabicParser__.arabicLetterHasInitialForm = function (letter) { + return isArabicLetter(letter) && isInArabicSubstitutionA(letter) && arabicSubstitionA[letter.charCodeAt(0)].length >= 3; + }; + + var arabicLetterHasMedialForm = jsPDFAPI.__arabicParser__.arabicLetterHasMedialForm = function (letter) { + return isArabicLetter(letter) && isInArabicSubstitutionA(letter) && arabicSubstitionA[letter.charCodeAt(0)].length == 4; + }; + + var resolveLigatures = jsPDFAPI.__arabicParser__.resolveLigatures = function (letters) { + var i = 0; + var tmpLigatures = ligatures; + var result = ""; + var effectedLetters = 0; + + for (i = 0; i < letters.length; i += 1) { + if (typeof tmpLigatures[letters.charCodeAt(i)] !== "undefined") { + effectedLetters++; + tmpLigatures = tmpLigatures[letters.charCodeAt(i)]; + + if (typeof tmpLigatures === "number") { + result += String.fromCharCode(tmpLigatures); + tmpLigatures = ligatures; + effectedLetters = 0; + } + + if (i === letters.length - 1) { + tmpLigatures = ligatures; + result += letters.charAt(i - (effectedLetters - 1)); + i = i - (effectedLetters - 1); + effectedLetters = 0; + } + } else { + tmpLigatures = ligatures; + result += letters.charAt(i - effectedLetters); + i = i - effectedLetters; + effectedLetters = 0; + } + } + + return result; + }; + + jsPDFAPI.__arabicParser__.isArabicDiacritic = function (letter) { + return letter !== undefined && arabic_diacritics[letter.charCodeAt(0)] !== undefined; + }; + + var getCorrectForm = jsPDFAPI.__arabicParser__.getCorrectForm = function (currentChar, beforeChar, nextChar) { + if (!isArabicLetter(currentChar)) { + return -1; + } + + if (isInArabicSubstitutionA(currentChar) === false) { + return noChangeInForm; + } + + if (!arabicLetterHasFinalForm(currentChar) || !isArabicLetter(beforeChar) && !isArabicLetter(nextChar) || !isArabicLetter(nextChar) && isArabicEndLetter(beforeChar) || isArabicEndLetter(currentChar) && !isArabicLetter(beforeChar) || isArabicEndLetter(currentChar) && isArabicAlfLetter(beforeChar) || isArabicEndLetter(currentChar) && isArabicEndLetter(beforeChar)) { + return isolatedForm; + } + + if (arabicLetterHasMedialForm(currentChar) && isArabicLetter(beforeChar) && !isArabicEndLetter(beforeChar) && isArabicLetter(nextChar) && arabicLetterHasFinalForm(nextChar)) { + return medialForm; + } + + if (isArabicEndLetter(currentChar) || !isArabicLetter(nextChar)) { + return finalForm; + } + + return initialForm; + }; + /** + * @name processArabic + * @function + * @param {string} text + * @returns {string} + */ + + + var parseArabic = function parseArabic(text) { + text = text || ""; + var result = ""; + var i = 0; + var j = 0; + var position = 0; + var currentLetter = ""; + var prevLetter = ""; + var nextLetter = ""; + var words = text.split("\\s+"); + var newWords = []; + + for (i = 0; i < words.length; i += 1) { + newWords.push(""); + + for (j = 0; j < words[i].length; j += 1) { + currentLetter = words[i][j]; + prevLetter = words[i][j - 1]; + nextLetter = words[i][j + 1]; + + if (isArabicLetter(currentLetter)) { + position = getCorrectForm(currentLetter, prevLetter, nextLetter); + + if (position !== -1) { + newWords[i] += String.fromCharCode(arabicSubstitionA[currentLetter.charCodeAt(0)][position]); + } else { + newWords[i] += currentLetter; + } + } else { + newWords[i] += currentLetter; + } + } + + newWords[i] = resolveLigatures(newWords[i]); + } + + result = newWords.join(" "); + return result; + }; + + var processArabic = jsPDFAPI.__arabicParser__.processArabic = jsPDFAPI.processArabic = function () { + var text = typeof arguments[0] === "string" ? arguments[0] : arguments[0].text; + var tmpText = []; + var result; + + if (Array.isArray(text)) { + var i = 0; + tmpText = []; + + for (i = 0; i < text.length; i += 1) { + if (Array.isArray(text[i])) { + tmpText.push([parseArabic(text[i][0]), text[i][1], text[i][2]]); + } else { + tmpText.push([parseArabic(text[i])]); + } + } + + result = tmpText; + } else { + result = parseArabic(text); + } + + if (typeof arguments[0] === "string") { + return result; + } else { + arguments[0].text = result; + return arguments[0]; + } + }; + + jsPDFAPI.events.push(["preProcessText", processArabic]); +})(jsPDF.API); + +/* global jsPDF */ + +/** @license + * jsPDF Autoprint Plugin + * + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ + +/** + * @name autoprint + * @module + */ +(function (jsPDFAPI) { + /** + * Makes the PDF automatically open the print-Dialog when opened in a PDF-viewer. + * + * @name autoPrint + * @function + * @param {Object} options (optional) Set the attribute variant to 'non-conform' (default) or 'javascript' to activate different methods of automatic printing when opening in a PDF-viewer . + * @returns {jsPDF} + * @example + * var doc = new jsPDF(); + * doc.text(10, 10, 'This is a test'); + * doc.autoPrint({variant: 'non-conform'}); + * doc.save('autoprint.pdf'); + */ + + jsPDFAPI.autoPrint = function (options) { + + var refAutoPrintTag; + options = options || {}; + options.variant = options.variant || "non-conform"; + + switch (options.variant) { + case "javascript": + //https://github.com/Rob--W/pdf.js/commit/c676ecb5a0f54677b9f3340c3ef2cf42225453bb + this.addJS("print({});"); + break; + + case "non-conform": + default: + this.internal.events.subscribe("postPutResources", function () { + refAutoPrintTag = this.internal.newObject(); + this.internal.out("<<"); + this.internal.out("/S /Named"); + this.internal.out("/Type /Action"); + this.internal.out("/N /Print"); + this.internal.out(">>"); + this.internal.out("endobj"); + }); + this.internal.events.subscribe("putCatalog", function () { + this.internal.out("/OpenAction " + refAutoPrintTag + " 0 R"); + }); + break; + } + + return this; + }; +})(jsPDF.API); + +/* global jsPDF */ + +/** + * @license + * Copyright (c) 2014 Steven Spungin (TwelveTone LLC) steven@twelvetone.tv + * + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ + +/** + * jsPDF Canvas PlugIn + * This plugin mimics the HTML5 Canvas + * + * The goal is to provide a way for current canvas users to print directly to a PDF. + * @name canvas + * @module + */ +(function (jsPDFAPI) { + /** + * @class Canvas + * @classdesc A Canvas Wrapper for jsPDF + */ + + var Canvas = function Canvas() { + var jsPdfInstance = undefined; + Object.defineProperty(this, "pdf", { + get: function get() { + return jsPdfInstance; + }, + set: function set(value) { + jsPdfInstance = value; + } + }); + var _width = 150; + /** + * The height property is a positive integer reflecting the height HTML attribute of the element interpreted in CSS pixels. When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of 150 is used. + * This is one of the two properties, the other being width, that controls the size of the canvas. + * + * @name width + */ + + Object.defineProperty(this, "width", { + get: function get() { + return _width; + }, + set: function set(value) { + if (isNaN(value) || Number.isInteger(value) === false || value < 0) { + _width = 150; + } else { + _width = value; + } + + if (this.getContext("2d").pageWrapXEnabled) { + this.getContext("2d").pageWrapX = _width + 1; + } + } + }); + var _height = 300; + /** + * The width property is a positive integer reflecting the width HTML attribute of the element interpreted in CSS pixels. When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of 300 is used. + * This is one of the two properties, the other being height, that controls the size of the canvas. + * + * @name height + */ + + Object.defineProperty(this, "height", { + get: function get() { + return _height; + }, + set: function set(value) { + if (isNaN(value) || Number.isInteger(value) === false || value < 0) { + _height = 300; + } else { + _height = value; + } + + if (this.getContext("2d").pageWrapYEnabled) { + this.getContext("2d").pageWrapY = _height + 1; + } + } + }); + var _childNodes = []; + Object.defineProperty(this, "childNodes", { + get: function get() { + return _childNodes; + }, + set: function set(value) { + _childNodes = value; + } + }); + var _style = {}; + Object.defineProperty(this, "style", { + get: function get() { + return _style; + }, + set: function set(value) { + _style = value; + } + }); + Object.defineProperty(this, "parentNode", {}); + }; + /** + * The getContext() method returns a drawing context on the canvas, or null if the context identifier is not supported. + * + * @name getContext + * @function + * @param {string} contextType Is a String containing the context identifier defining the drawing context associated to the canvas. Possible value is "2d", leading to the creation of a Context2D object representing a two-dimensional rendering context. + * @param {object} contextAttributes + */ + + + Canvas.prototype.getContext = function (contextType, contextAttributes) { + contextType = contextType || "2d"; + var key; + + if (contextType !== "2d") { + return null; + } + + for (key in contextAttributes) { + if (this.pdf.context2d.hasOwnProperty(key)) { + this.pdf.context2d[key] = contextAttributes[key]; + } + } + + this.pdf.context2d._canvas = this; + return this.pdf.context2d; + }; + /** + * The toDataURL() method is just a stub to throw an error if accidently called. + * + * @name toDataURL + * @function + */ + + + Canvas.prototype.toDataURL = function () { + throw new Error("toDataURL is not implemented."); + }; + + jsPDFAPI.events.push(["initialized", function () { + this.canvas = new Canvas(); + this.canvas.pdf = this; + }]); + return this; +})(jsPDF.API); + +/*global jsPDF */ + +/** + * @license + * ==================================================================== + * Copyright (c) 2013 Youssef Beddad, youssef.beddad@gmail.com + * 2013 Eduardo Menezes de Morais, eduardo.morais@usp.br + * 2013 Lee Driscoll, https://github.com/lsdriscoll + * 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria + * 2014 James Hall, james@parall.ax + * 2014 Diego Casorran, https://github.com/diegocr + * + * + * ==================================================================== + */ + +/** + * @name cell + * @module + */ +(function (jsPDFAPI) { + + var NO_MARGINS = { + left: 0, + top: 0, + bottom: 0, + right: 0 + }; + var px2pt = 0.264583 * 72 / 25.4; + var printingHeaderRow = false; + + var _initialize = function _initialize() { + if (typeof this.internal.__cell__ === "undefined") { + this.internal.__cell__ = {}; + this.internal.__cell__.padding = 3; + this.internal.__cell__.headerFunction = undefined; + this.internal.__cell__.margins = Object.assign({}, NO_MARGINS); + this.internal.__cell__.margins.width = this.getPageWidth(); + + _reset.call(this); + } + }; + + var _reset = function _reset() { + this.internal.__cell__.lastCell = new Cell(); + this.internal.__cell__.pages = 1; + }; + + var Cell = function Cell() { + var _x = arguments[0]; + Object.defineProperty(this, "x", { + enumerable: true, + get: function get() { + return _x; + }, + set: function set(value) { + _x = value; + } + }); + var _y = arguments[1]; + Object.defineProperty(this, "y", { + enumerable: true, + get: function get() { + return _y; + }, + set: function set(value) { + _y = value; + } + }); + var _width = arguments[2]; + Object.defineProperty(this, "width", { + enumerable: true, + get: function get() { + return _width; + }, + set: function set(value) { + _width = value; + } + }); + var _height = arguments[3]; + Object.defineProperty(this, "height", { + enumerable: true, + get: function get() { + return _height; + }, + set: function set(value) { + _height = value; + } + }); + var _text = arguments[4]; + Object.defineProperty(this, "text", { + enumerable: true, + get: function get() { + return _text; + }, + set: function set(value) { + _text = value; + } + }); + var _lineNumber = arguments[5]; + Object.defineProperty(this, "lineNumber", { + enumerable: true, + get: function get() { + return _lineNumber; + }, + set: function set(value) { + _lineNumber = value; + } + }); + var _align = arguments[6]; + Object.defineProperty(this, "align", { + enumerable: true, + get: function get() { + return _align; + }, + set: function set(value) { + _align = value; + } + }); + return this; + }; + + Cell.prototype.clone = function () { + return new Cell(this.x, this.y, this.width, this.height, this.text, this.lineNumber, this.align); + }; + + Cell.prototype.toArray = function () { + return [this.x, this.y, this.width, this.height, this.text, this.lineNumber, this.align]; + }; + /** + * @name setHeaderFunction + * @function + * @param {function} func + */ + + + jsPDFAPI.setHeaderFunction = function (func) { + _initialize.call(this); + + this.internal.__cell__.headerFunction = typeof func === "function" ? func : undefined; + return this; + }; + /** + * @name getTextDimensions + * @function + * @param {string} txt + * @returns {Object} dimensions + */ + + + jsPDFAPI.getTextDimensions = function (text, options) { + _initialize.call(this); + + options = options || {}; + var fontSize = options.fontSize || this.getFontSize(); + var font = options.font || this.getFont(); + var scaleFactor = options.scaleFactor || this.internal.scaleFactor; + var width = 0; + var amountOfLines = 0; + var height = 0; + var tempWidth = 0; + + if (!Array.isArray(text) && typeof text !== "string") { + throw new Error("getTextDimensions expects text-parameter to be of type String or an Array of Strings."); + } + + text = Array.isArray(text) ? text : [text]; + + for (var i = 0; i < text.length; i++) { + tempWidth = this.getStringUnitWidth(text[i], { + font: font + }) * fontSize; + + if (width < tempWidth) { + width = tempWidth; + } + + if (width !== 0) { + amountOfLines = text.length; + } + } + + width = width / scaleFactor; + height = Math.max((amountOfLines * fontSize * this.getLineHeightFactor() - fontSize * (this.getLineHeightFactor() - 1)) / scaleFactor, 0); + return { + w: width, + h: height + }; + }; + /** + * @name cellAddPage + * @function + */ + + + jsPDFAPI.cellAddPage = function () { + _initialize.call(this); + + this.addPage(); + var margins = this.internal.__cell__.margins || NO_MARGINS; + this.internal.__cell__.lastCell = new Cell(margins.left, margins.top, undefined, undefined); + this.internal.__cell__.pages += 1; + return this; + }; + /** + * @name cellInitialize + * @function + * @deprecated + */ + + + jsPDFAPI.cellInitialize = function () { + _initialize.call(this); + + _reset.call(this); + }; + /** + * @name cell + * @function + * @param {number} x + * @param {number} y + * @param {number} width + * @param {number} height + * @param {string} text + * @param {number} lineNumber lineNumber + * @param {string} align + * @return {jsPDF} jsPDF-instance + */ + + + var cell = jsPDFAPI.cell = function () { + var currentCell; + + if (arguments[0] instanceof Cell) { + currentCell = arguments[0]; + } else { + currentCell = new Cell(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]); + } + + _initialize.call(this); + + var lastCell = this.internal.__cell__.lastCell; + var padding = this.internal.__cell__.padding; + var margins = this.internal.__cell__.margins || NO_MARGINS; + var tableHeaderRow = this.internal.__cell__.tableHeaderRow; + var printHeaders = this.internal.__cell__.printHeaders; // If this is not the first cell, we must change its position + + if (typeof lastCell.lineNumber !== "undefined") { + if (lastCell.lineNumber === currentCell.lineNumber) { + //Same line + currentCell.x = (lastCell.x || 0) + (lastCell.width || 0); + currentCell.y = lastCell.y || 0; + } else { + //New line + if (lastCell.y + lastCell.height + currentCell.height + margins.bottom > this.getPageHeight()) { + this.cellAddPage(); + currentCell.y = margins.top; + + if (printHeaders && tableHeaderRow) { + this.printHeaderRow(currentCell.lineNumber, true); + currentCell.y += tableHeaderRow[0].height; + } + } else { + currentCell.y = lastCell.y + lastCell.height || currentCell.y; + } + } + } + + if (typeof currentCell.text[0] !== "undefined") { + this.rect(currentCell.x, currentCell.y, currentCell.width, currentCell.height, printingHeaderRow === true ? "FD" : undefined); + + if (currentCell.align === "right") { + this.text(currentCell.text, currentCell.x + currentCell.width - padding, currentCell.y + padding, { + align: "right", + baseline: "top" + }); + } else if (currentCell.align === "center") { + this.text(currentCell.text, currentCell.x + currentCell.width / 2, currentCell.y + padding, { + align: "center", + baseline: "top", + maxWidth: currentCell.width - padding - padding + }); + } else { + this.text(currentCell.text, currentCell.x + padding, currentCell.y + padding, { + align: "left", + baseline: "top", + maxWidth: currentCell.width - padding - padding + }); + } + } + + this.internal.__cell__.lastCell = currentCell; + return this; + }; + /** + * Create a table from a set of data. + * @name table + * @function + * @param {Integer} [x] : left-position for top-left corner of table + * @param {Integer} [y] top-position for top-left corner of table + * @param {Object[]} [data] An array of objects containing key-value pairs corresponding to a row of data. + * @param {String[]} [headers] Omit or null to auto-generate headers at a performance cost + * @param {Object} [config.printHeaders] True to print column headers at the top of every page + * @param {Object} [config.autoSize] True to dynamically set the column widths to match the widest cell value + * @param {Object} [config.margins] margin values for left, top, bottom, and width + * @param {Object} [config.fontSize] Integer fontSize to use (optional) + * @param {Object} [config.padding] cell-padding in pt to use (optional) + * @param {Object} [config.headerBackgroundColor] default is #c8c8c8 (optional) + * @returns {jsPDF} jsPDF-instance + */ + + + jsPDFAPI.table = function (x, y, data, headers, config) { + _initialize.call(this); + + if (!data) { + throw new Error("No data for PDF table."); + } + + config = config || {}; + var headerNames = [], + headerLabels = [], + headerAligns = [], + i, + columnMatrix = {}, + columnWidths = {}, + column, + columnMinWidths = [], + j, + tableHeaderConfigs = [], + //set up defaults. If a value is provided in config, defaults will be overwritten: + autoSize = config.autoSize || false, + printHeaders = config.printHeaders === false ? false : true, + fontSize = config.css && typeof config.css["font-size"] !== "undefined" ? config.css["font-size"] * 16 : config.fontSize || 12, + margins = config.margins || Object.assign({ + width: this.getPageWidth() + }, NO_MARGINS), + padding = typeof config.padding === "number" ? config.padding : 3, + headerBackgroundColor = config.headerBackgroundColor || "#c8c8c8"; + + _reset.call(this); + + this.internal.__cell__.printHeaders = printHeaders; + this.internal.__cell__.margins = margins; + this.internal.__cell__.table_font_size = fontSize; + this.internal.__cell__.padding = padding; + this.internal.__cell__.headerBackgroundColor = headerBackgroundColor; + this.setFontSize(fontSize); // Set header values + + if (headers === undefined || headers === null) { + // No headers defined so we derive from data + headerNames = Object.keys(data[0]); + headerLabels = headerNames; + headerAligns = headerNames.map(function () { + return "left"; + }); + } else if (Array.isArray(headers) && _typeof(headers[0]) === "object") { + headerNames = headers.map(function (header) { + return header.name; + }); + headerLabels = headers.map(function (header) { + return header.prompt || header.name || ""; + }); + headerAligns = headerNames.map(function (header) { + return header.align || "left"; + }); // Split header configs into names and prompts + + for (i = 0; i < headers.length; i += 1) { + columnWidths[headers[i].name] = headers[i].width * px2pt; + } + } else if (Array.isArray(headers) && typeof headers[0] === "string") { + headerNames = headers; + headerLabels = headerNames; + headerAligns = headerNames.map(function () { + return "left"; + }); + } + + if (autoSize) { + var headerName; + + for (i = 0; i < headerNames.length; i += 1) { + headerName = headerNames[i]; // Create a matrix of columns e.g., {column_title: [row1_Record, row2_Record]} + + columnMatrix[headerName] = data.map(function (rec) { + return rec[headerName]; + }); // get header width + + this.setFontStyle("bold"); + columnMinWidths.push(this.getTextDimensions(headerLabels[i], { + fontSize: this.internal.__cell__.table_font_size, + scaleFactor: this.internal.scaleFactor + }).w); + column = columnMatrix[headerName]; // get cell widths + + this.setFontStyle("normal"); + + for (j = 0; j < column.length; j += 1) { + columnMinWidths.push(this.getTextDimensions(column[j], { + fontSize: this.internal.__cell__.table_font_size, + scaleFactor: this.internal.scaleFactor + }).w); + } // get final column width + + + columnWidths[headerName] = Math.max.apply(null, columnMinWidths) + padding + padding; //have to reset + + columnMinWidths = []; + } + } // -- Construct the table + + + if (printHeaders) { + var row = {}; + + for (i = 0; i < headerNames.length; i += 1) { + row[headerNames[i]] = {}; + row[headerNames[i]].text = headerLabels[i]; + row[headerNames[i]].align = headerAligns[i]; + } + + var rowHeight = calculateLineHeight.call(this, row, columnWidths); // Construct the header row + + tableHeaderConfigs = headerNames.map(function (value) { + return new Cell(x, y, columnWidths[value], rowHeight, row[value].text, undefined, row[value].align); + }); // Store the table header config + + this.setTableHeaderRow(tableHeaderConfigs); // Print the header for the start of the table + + this.printHeaderRow(1, false); + } // Construct the data rows + + + var align = headers.reduce(function (pv, cv) { + pv[cv.name] = cv.align; + return pv; + }, {}); + + for (i = 0; i < data.length; i += 1) { + var lineHeight = calculateLineHeight.call(this, data[i], columnWidths); + + for (j = 0; j < headerNames.length; j += 1) { + cell.call(this, new Cell(x, y, columnWidths[headerNames[j]], lineHeight, data[i][headerNames[j]], i + 2, align[headerNames[j]])); + } + } + + this.internal.__cell__.table_x = x; + this.internal.__cell__.table_y = y; + return this; + }; + /** + * Calculate the height for containing the highest column + * + * @name calculateLineHeight + * @function + * @param {Object[]} model is the line of data we want to calculate the height of + * @param {Integer[]} columnWidths is size of each column + * @returns {number} lineHeight + * @private + */ + + + var calculateLineHeight = function calculateLineHeight(model, columnWidths) { + var padding = this.internal.__cell__.padding; + var fontSize = this.internal.__cell__.table_font_size; + var scaleFactor = this.internal.scaleFactor; + return Object.keys(model).map(function (key) { + return [key, model[key]]; + }).map(function (item) { + var key = item[0]; + var value = item[1]; + return _typeof(value) === "object" ? [key, value.text] : [key, value]; + }).map(function (item) { + var key = item[0]; + var value = item[1]; + return this.splitTextToSize(value, columnWidths[key] - padding - padding); + }, this).map(function (value) { + return this.getLineHeightFactor() * value.length * fontSize / scaleFactor + padding + padding; + }, this).reduce(function (pv, cv) { + return Math.max(pv, cv); + }, 0); + }; + /** + * Store the config for outputting a table header + * + * @name setTableHeaderRow + * @function + * @param {Object[]} config + * An array of cell configs that would define a header row: Each config matches the config used by jsPDFAPI.cell + * except the lineNumber parameter is excluded + */ + + + jsPDFAPI.setTableHeaderRow = function (config) { + _initialize.call(this); + + this.internal.__cell__.tableHeaderRow = config; + }; + /** + * Output the store header row + * + * @name printHeaderRow + * @function + * @param {number} lineNumber The line number to output the header at + * @param {boolean} new_page + */ + + + jsPDFAPI.printHeaderRow = function (lineNumber, new_page) { + _initialize.call(this); + + if (!this.internal.__cell__.tableHeaderRow) { + throw new Error("Property tableHeaderRow does not exist."); + } + + var tableHeaderCell; + printingHeaderRow = true; + + if (typeof this.internal.__cell__.headerFunction === "function") { + var position = this.internal.__cell__.headerFunction(this, this.internal.__cell__.pages); + + this.internal.__cell__.lastCell = new Cell(position[0], position[1], position[2], position[3], undefined, -1); + } + + this.setFontStyle("bold"); + var tempHeaderConf = []; + + for (var i = 0; i < this.internal.__cell__.tableHeaderRow.length; i += 1) { + tableHeaderCell = this.internal.__cell__.tableHeaderRow[i].clone(); + + if (new_page) { + tableHeaderCell.y = this.internal.__cell__.margins.top || 0; + tempHeaderConf.push(tableHeaderCell); + } + + tableHeaderCell.lineNumber = lineNumber; + this.setFillColor(this.internal.__cell__.headerBackgroundColor); + cell.call(this, tableHeaderCell); + } + + if (tempHeaderConf.length > 0) { + this.setTableHeaderRow(tempHeaderConf); + } + + this.setFontStyle("normal"); + printingHeaderRow = false; + }; +})(jsPDF.API); + +/* eslint-disable no-fallthrough */ + +/* eslint-disable no-console */ + +/* global jsPDF, RGBColor */ + +/** + * jsPDF Context2D PlugIn Copyright (c) 2014 Steven Spungin (TwelveTone LLC) steven@twelvetone.tv + * + * Licensed under the MIT License. http://opensource.org/licenses/mit-license + */ + +/** + * This plugin mimics the HTML5 CanvasRenderingContext2D. + * + * The goal is to provide a way for current canvas implementations to print directly to a PDF. + * + * @name context2d + * @module + */ +(function (jsPDFAPI) { + + var ContextLayer = function ContextLayer(ctx) { + ctx = ctx || {}; + this.isStrokeTransparent = ctx.isStrokeTransparent || false; + this.strokeOpacity = ctx.strokeOpacity || 1; + this.strokeStyle = ctx.strokeStyle || "#000000"; + this.fillStyle = ctx.fillStyle || "#000000"; + this.isFillTransparent = ctx.isFillTransparent || false; + this.fillOpacity = ctx.fillOpacity || 1; + this.font = ctx.font || "10px sans-serif"; + this.textBaseline = ctx.textBaseline || "alphabetic"; + this.textAlign = ctx.textAlign || "left"; + this.lineWidth = ctx.lineWidth || 1; + this.lineJoin = ctx.lineJoin || "miter"; + this.lineCap = ctx.lineCap || "butt"; + this.path = ctx.path || []; + this.transform = typeof ctx.transform !== "undefined" ? ctx.transform.clone() : new Matrix(); + this.globalCompositeOperation = ctx.globalCompositeOperation || "normal"; + this.globalAlpha = ctx.globalAlpha || 1.0; + this.clip_path = ctx.clip_path || []; + this.currentPoint = ctx.currentPoint || new Point(); + this.miterLimit = ctx.miterLimit || 10.0; + this.lastPoint = ctx.lastPoint || new Point(); + this.ignoreClearRect = typeof ctx.ignoreClearRect === "boolean" ? ctx.ignoreClearRect : true; + return this; + }; //stub + + + var f2, getHorizontalCoordinateString, getVerticalCoordinateString, getHorizontalCoordinate, getVerticalCoordinate, Point, Rectangle, Matrix, _ctx; + + jsPDFAPI.events.push(["initialized", function () { + this.context2d = new Context2D(this); + f2 = this.internal.f2; + getHorizontalCoordinateString = this.internal.getCoordinateString; + getVerticalCoordinateString = this.internal.getVerticalCoordinateString; + getHorizontalCoordinate = this.internal.getHorizontalCoordinate; + getVerticalCoordinate = this.internal.getVerticalCoordinate; + Point = this.internal.Point; + Rectangle = this.internal.Rectangle; + Matrix = this.internal.Matrix; + _ctx = new ContextLayer(); + }]); + + var Context2D = function Context2D(pdf) { + Object.defineProperty(this, "canvas", { + get: function get() { + return { + parentNode: false, + style: false + }; + } + }); + var _pdf = pdf; + Object.defineProperty(this, "pdf", { + get: function get() { + return _pdf; + } + }); + var _pageWrapXEnabled = false; + /** + * @name pageWrapXEnabled + * @type {boolean} + * @default false + */ + + Object.defineProperty(this, "pageWrapXEnabled", { + get: function get() { + return _pageWrapXEnabled; + }, + set: function set(value) { + _pageWrapXEnabled = Boolean(value); + } + }); + var _pageWrapYEnabled = false; + /** + * @name pageWrapYEnabled + * @type {boolean} + * @default true + */ + + Object.defineProperty(this, "pageWrapYEnabled", { + get: function get() { + return _pageWrapYEnabled; + }, + set: function set(value) { + _pageWrapYEnabled = Boolean(value); + } + }); + var _posX = 0; + /** + * @name posX + * @type {number} + * @default 0 + */ + + Object.defineProperty(this, "posX", { + get: function get() { + return _posX; + }, + set: function set(value) { + if (!isNaN(value)) { + _posX = value; + } + } + }); + var _posY = 0; + /** + * @name posY + * @type {number} + * @default 0 + */ + + Object.defineProperty(this, "posY", { + get: function get() { + return _posY; + }, + set: function set(value) { + if (!isNaN(value)) { + _posY = value; + } + } + }); + var _autoPaging = false; + /** + * @name autoPaging + * @type {boolean} + * @default true + */ + + Object.defineProperty(this, "autoPaging", { + get: function get() { + return _autoPaging; + }, + set: function set(value) { + _autoPaging = Boolean(value); + } + }); + var lastBreak = 0; + /** + * @name lastBreak + * @type {number} + * @default 0 + */ + + Object.defineProperty(this, "lastBreak", { + get: function get() { + return lastBreak; + }, + set: function set(value) { + lastBreak = value; + } + }); + var pageBreaks = []; + /** + * Y Position of page breaks. + * @name pageBreaks + * @type {number} + * @default 0 + */ + + Object.defineProperty(this, "pageBreaks", { + get: function get() { + return pageBreaks; + }, + set: function set(value) { + pageBreaks = value; + } + }); + /** + * @name ctx + * @type {object} + * @default {} + */ + + Object.defineProperty(this, "ctx", { + get: function get() { + return _ctx; + }, + set: function set(value) { + if (value instanceof ContextLayer) { + _ctx = value; + } + } + }); + /** + * @name path + * @type {array} + * @default [] + */ + + Object.defineProperty(this, "path", { + get: function get() { + return _ctx.path; + }, + set: function set(value) { + _ctx.path = value; + } + }); + /** + * @name ctxStack + * @type {array} + * @default [] + */ + + var _ctxStack = []; + Object.defineProperty(this, "ctxStack", { + get: function get() { + return _ctxStack; + }, + set: function set(value) { + _ctxStack = value; + } + }); + /** + * Sets or returns the color, gradient, or pattern used to fill the drawing + * + * @name fillStyle + * @default #000000 + * @property {(color|gradient|pattern)} value The color of the drawing. Default value is #000000
    + * A gradient object (linear or radial) used to fill the drawing (not supported by context2d)
    + * A pattern object to use to fill the drawing (not supported by context2d) + */ + + Object.defineProperty(this, "fillStyle", { + get: function get() { + return this.ctx.fillStyle; + }, + set: function set(value) { + var rgba; + rgba = getRGBA(value); + this.ctx.fillStyle = rgba.style; + this.ctx.isFillTransparent = rgba.a === 0; + this.ctx.fillOpacity = rgba.a; + this.pdf.setFillColor(rgba.r, rgba.g, rgba.b, { + a: rgba.a + }); + this.pdf.setTextColor(rgba.r, rgba.g, rgba.b, { + a: rgba.a + }); + } + }); + /** + * Sets or returns the color, gradient, or pattern used for strokes + * + * @name strokeStyle + * @default #000000 + * @property {color} color A CSS color value that indicates the stroke color of the drawing. Default value is #000000 (not supported by context2d) + * @property {gradient} gradient A gradient object (linear or radial) used to create a gradient stroke (not supported by context2d) + * @property {pattern} pattern A pattern object used to create a pattern stroke (not supported by context2d) + */ + + Object.defineProperty(this, "strokeStyle", { + get: function get() { + return this.ctx.strokeStyle; + }, + set: function set(value) { + var rgba = getRGBA(value); + this.ctx.strokeStyle = rgba.style; + this.ctx.isStrokeTransparent = rgba.a === 0; + this.ctx.strokeOpacity = rgba.a; + + if (rgba.a === 0) { + this.pdf.setDrawColor(255, 255, 255); + } else if (rgba.a === 1) { + this.pdf.setDrawColor(rgba.r, rgba.g, rgba.b); + } else { + this.pdf.setDrawColor(rgba.r, rgba.g, rgba.b); + } + } + }); + /** + * Sets or returns the style of the end caps for a line + * + * @name lineCap + * @default butt + * @property {(butt|round|square)} lineCap butt A flat edge is added to each end of the line
    + * round A rounded end cap is added to each end of the line
    + * square A square end cap is added to each end of the line
    + */ + + Object.defineProperty(this, "lineCap", { + get: function get() { + return this.ctx.lineCap; + }, + set: function set(value) { + if (["butt", "round", "square"].indexOf(value) !== -1) { + this.ctx.lineCap = value; + this.pdf.setLineCap(value); + } + } + }); + /** + * Sets or returns the current line width + * + * @name lineWidth + * @default 1 + * @property {number} lineWidth The current line width, in pixels + */ + + Object.defineProperty(this, "lineWidth", { + get: function get() { + return this.ctx.lineWidth; + }, + set: function set(value) { + if (!isNaN(value)) { + this.ctx.lineWidth = value; + this.pdf.setLineWidth(value); + } + } + }); + /** + * Sets or returns the type of corner created, when two lines meet + */ + + Object.defineProperty(this, "lineJoin", { + get: function get() { + return this.ctx.lineJoin; + }, + set: function set(value) { + if (["bevel", "round", "miter"].indexOf(value) !== -1) { + this.ctx.lineJoin = value; + this.pdf.setLineJoin(value); + } + } + }); + /** + * A number specifying the miter limit ratio in coordinate space units. Zero, negative, Infinity, and NaN values are ignored. The default value is 10.0. + * + * @name miterLimit + * @default 10 + */ + + Object.defineProperty(this, "miterLimit", { + get: function get() { + return this.ctx.miterLimit; + }, + set: function set(value) { + if (!isNaN(value)) { + this.ctx.miterLimit = value; + this.pdf.setMiterLimit(value); + } + } + }); + Object.defineProperty(this, "textBaseline", { + get: function get() { + return this.ctx.textBaseline; + }, + set: function set(value) { + this.ctx.textBaseline = value; + } + }); + Object.defineProperty(this, "textAlign", { + get: function get() { + return this.ctx.textAlign; + }, + set: function set(value) { + if (["right", "end", "center", "left", "start"].indexOf(value) !== -1) { + this.ctx.textAlign = value; + } + } + }); + Object.defineProperty(this, "font", { + get: function get() { + return this.ctx.font; + }, + set: function set(value) { + this.ctx.font = value; + var rx, matches; //source: https://stackoverflow.com/a/10136041 + // eslint-disable-next-line no-useless-escape + + rx = /^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-_,\"\'\sa-z]+?)\s*$/i; + matches = rx.exec(value); + + if (matches !== null) { + var fontStyle = matches[1]; + var fontVariant = matches[2]; + var fontWeight = matches[3]; + var fontSize = matches[4]; + var lineHeight = matches[5]; + var fontFamily = matches[6]; + } else { + return; + } + + var rxFontSize = /^([.\d]+)((?:%|in|[cem]m|ex|p[ctx]))$/i; + var fontSizeUnit = rxFontSize.exec(fontSize)[2]; + + if ("px" === fontSizeUnit) { + fontSize = Math.floor(parseFloat(fontSize)); + } else if ("em" === fontSizeUnit) { + fontSize = Math.floor(parseFloat(fontSize) * this.pdf.getFontSize()); + } else { + fontSize = Math.floor(parseFloat(fontSize)); + } + + this.pdf.setFontSize(fontSize); + var style = ""; + + if (fontWeight === "bold" || parseInt(fontWeight, 10) >= 700 || fontStyle === "bold") { + style = "bold"; + } + + if (fontStyle === "italic") { + style += "italic"; + } + + if (style.length === 0) { + style = "normal"; + } + + var jsPdfFontName = ""; + var parts = fontFamily.toLowerCase().replace(/"|'/g, "").split(/\s*,\s*/); + var fallbackFonts = { + arial: "Helvetica", + verdana: "Helvetica", + helvetica: "Helvetica", + "sans-serif": "Helvetica", + fixed: "Courier", + monospace: "Courier", + terminal: "Courier", + courier: "Courier", + times: "Times", + cursive: "Times", + fantasy: "Times", + serif: "Times" + }; + + for (var i = 0; i < parts.length; i++) { + if (this.pdf.internal.getFont(parts[i], style, { + noFallback: true, + disableWarning: true + }) !== undefined) { + jsPdfFontName = parts[i]; + break; + } else if (style === "bolditalic" && this.pdf.internal.getFont(parts[i], "bold", { + noFallback: true, + disableWarning: true + }) !== undefined) { + jsPdfFontName = parts[i]; + style = "bold"; + } else if (this.pdf.internal.getFont(parts[i], "normal", { + noFallback: true, + disableWarning: true + }) !== undefined) { + jsPdfFontName = parts[i]; + style = "normal"; + break; + } + } + + if (jsPdfFontName === "") { + for (var j = 0; j < parts.length; j++) { + if (fallbackFonts[parts[j]]) { + jsPdfFontName = fallbackFonts[parts[j]]; + break; + } + } + } + + jsPdfFontName = jsPdfFontName === "" ? "Times" : jsPdfFontName; + this.pdf.setFont(jsPdfFontName, style); + } + }); + Object.defineProperty(this, "globalCompositeOperation", { + get: function get() { + return this.ctx.globalCompositeOperation; + }, + set: function set(value) { + this.ctx.globalCompositeOperation = value; + } + }); + Object.defineProperty(this, "globalAlpha", { + get: function get() { + return this.ctx.globalAlpha; + }, + set: function set(value) { + this.ctx.globalAlpha = value; + } + }); // Not HTML API + + Object.defineProperty(this, "ignoreClearRect", { + get: function get() { + return this.ctx.ignoreClearRect; + }, + set: function set(value) { + this.ctx.ignoreClearRect = Boolean(value); + } + }); + }; + + Context2D.prototype.fill = function () { + pathPreProcess.call(this, "fill", false); + }; + /** + * Actually draws the path you have defined + * + * @name stroke + * @function + * @description The stroke() method actually draws the path you have defined with all those moveTo() and lineTo() methods. The default color is black. + */ + + + Context2D.prototype.stroke = function () { + pathPreProcess.call(this, "stroke", false); + }; + /** + * Begins a path, or resets the current + * + * @name beginPath + * @function + * @description The beginPath() method begins a path, or resets the current path. + */ + + + Context2D.prototype.beginPath = function () { + this.path = [{ + type: "begin" + }]; + }; + /** + * Moves the path to the specified point in the canvas, without creating a line + * + * @name moveTo + * @function + * @param x {Number} The x-coordinate of where to move the path to + * @param y {Number} The y-coordinate of where to move the path to + */ + + + Context2D.prototype.moveTo = function (x, y) { + if (isNaN(x) || isNaN(y)) { + console.error("jsPDF.context2d.moveTo: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.moveTo"); + } + + var pt = this.ctx.transform.applyToPoint(new Point(x, y)); + this.path.push({ + type: "mt", + x: pt.x, + y: pt.y + }); + this.ctx.lastPoint = new Point(x, y); + }; + /** + * Creates a path from the current point back to the starting point + * + * @name closePath + * @function + * @description The closePath() method creates a path from the current point back to the starting point. + */ + + + Context2D.prototype.closePath = function () { + var pathBegin = new Point(0, 0); + var i = 0; + + for (i = this.path.length - 1; i !== -1; i--) { + if (this.path[i].type === "begin") { + if (_typeof(this.path[i + 1]) === "object" && typeof this.path[i + 1].x === "number") { + pathBegin = new Point(this.path[i + 1].x, this.path[i + 1].y); + this.path.push({ + type: "lt", + x: pathBegin.x, + y: pathBegin.y + }); + break; + } + } + } + + if (_typeof(this.path[i + 2]) === "object" && typeof this.path[i + 2].x === "number") { + this.path.push(JSON.parse(JSON.stringify(this.path[i + 2]))); + } + + this.path.push({ + type: "close" + }); + this.ctx.lastPoint = new Point(pathBegin.x, pathBegin.y); + }; + /** + * Adds a new point and creates a line to that point from the last specified point in the canvas + * + * @name lineTo + * @function + * @param x The x-coordinate of where to create the line to + * @param y The y-coordinate of where to create the line to + * @description The lineTo() method adds a new point and creates a line TO that point FROM the last specified point in the canvas (this method does not draw the line). + */ + + + Context2D.prototype.lineTo = function (x, y) { + if (isNaN(x) || isNaN(y)) { + console.error("jsPDF.context2d.lineTo: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.lineTo"); + } + + var pt = this.ctx.transform.applyToPoint(new Point(x, y)); + this.path.push({ + type: "lt", + x: pt.x, + y: pt.y + }); + this.ctx.lastPoint = new Point(pt.x, pt.y); + }; + /** + * Clips a region of any shape and size from the original canvas + * + * @name clip + * @function + * @description The clip() method clips a region of any shape and size from the original canvas. + */ + + + Context2D.prototype.clip = function () { + this.ctx.clip_path = JSON.parse(JSON.stringify(this.path)); + pathPreProcess.call(this, null, true); + }; + /** + * Creates a cubic Bézier curve + * + * @name quadraticCurveTo + * @function + * @param cpx {Number} The x-coordinate of the Bézier control point + * @param cpy {Number} The y-coordinate of the Bézier control point + * @param x {Number} The x-coordinate of the ending point + * @param y {Number} The y-coordinate of the ending point + * @description The quadraticCurveTo() method adds a point to the current path by using the specified control points that represent a quadratic Bézier curve.

    A quadratic Bézier curve requires two points. The first point is a control point that is used in the quadratic Bézier calculation and the second point is the ending point for the curve. The starting point for the curve is the last point in the current path. If a path does not exist, use the beginPath() and moveTo() methods to define a starting point. + */ + + + Context2D.prototype.quadraticCurveTo = function (cpx, cpy, x, y) { + if (isNaN(x) || isNaN(y) || isNaN(cpx) || isNaN(cpy)) { + console.error("jsPDF.context2d.quadraticCurveTo: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.quadraticCurveTo"); + } + + var pt0 = this.ctx.transform.applyToPoint(new Point(x, y)); + var pt1 = this.ctx.transform.applyToPoint(new Point(cpx, cpy)); + this.path.push({ + type: "qct", + x1: pt1.x, + y1: pt1.y, + x: pt0.x, + y: pt0.y + }); + this.ctx.lastPoint = new Point(pt0.x, pt0.y); + }; + /** + * Creates a cubic Bézier curve + * + * @name bezierCurveTo + * @function + * @param cp1x {Number} The x-coordinate of the first Bézier control point + * @param cp1y {Number} The y-coordinate of the first Bézier control point + * @param cp2x {Number} The x-coordinate of the second Bézier control point + * @param cp2y {Number} The y-coordinate of the second Bézier control point + * @param x {Number} The x-coordinate of the ending point + * @param y {Number} The y-coordinate of the ending point + * @description The bezierCurveTo() method adds a point to the current path by using the specified control points that represent a cubic Bézier curve.

    A cubic bezier curve requires three points. The first two points are control points that are used in the cubic Bézier calculation and the last point is the ending point for the curve. The starting point for the curve is the last point in the current path. If a path does not exist, use the beginPath() and moveTo() methods to define a starting point. + */ + + + Context2D.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) { + if (isNaN(x) || isNaN(y) || isNaN(cp1x) || isNaN(cp1y) || isNaN(cp2x) || isNaN(cp2y)) { + console.error("jsPDF.context2d.bezierCurveTo: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.bezierCurveTo"); + } + + var pt0 = this.ctx.transform.applyToPoint(new Point(x, y)); + var pt1 = this.ctx.transform.applyToPoint(new Point(cp1x, cp1y)); + var pt2 = this.ctx.transform.applyToPoint(new Point(cp2x, cp2y)); + this.path.push({ + type: "bct", + x1: pt1.x, + y1: pt1.y, + x2: pt2.x, + y2: pt2.y, + x: pt0.x, + y: pt0.y + }); + this.ctx.lastPoint = new Point(pt0.x, pt0.y); + }; + /** + * Creates an arc/curve (used to create circles, or parts of circles) + * + * @name arc + * @function + * @param x {Number} The x-coordinate of the center of the circle + * @param y {Number} The y-coordinate of the center of the circle + * @param radius {Number} The radius of the circle + * @param startAngle {Number} The starting angle, in radians (0 is at the 3 o'clock position of the arc's circle) + * @param endAngle {Number} The ending angle, in radians + * @param counterclockwise {Boolean} Optional. Specifies whether the drawing should be counterclockwise or clockwise. False is default, and indicates clockwise, while true indicates counter-clockwise. + * @description The arc() method creates an arc/curve (used to create circles, or parts of circles). + */ + + + Context2D.prototype.arc = function (x, y, radius, startAngle, endAngle, counterclockwise) { + if (isNaN(x) || isNaN(y) || isNaN(radius) || isNaN(startAngle) || isNaN(endAngle)) { + console.error("jsPDF.context2d.arc: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.arc"); + } + + counterclockwise = Boolean(counterclockwise); + + if (!this.ctx.transform.isIdentity) { + var xpt = this.ctx.transform.applyToPoint(new Point(x, y)); + x = xpt.x; + y = xpt.y; + var x_radPt = this.ctx.transform.applyToPoint(new Point(0, radius)); + var x_radPt0 = this.ctx.transform.applyToPoint(new Point(0, 0)); + radius = Math.sqrt(Math.pow(x_radPt.x - x_radPt0.x, 2) + Math.pow(x_radPt.y - x_radPt0.y, 2)); + } + + if (Math.abs(endAngle - startAngle) >= 2 * Math.PI) { + startAngle = 0; + endAngle = 2 * Math.PI; + } + + this.path.push({ + type: "arc", + x: x, + y: y, + radius: radius, + startAngle: startAngle, + endAngle: endAngle, + counterclockwise: counterclockwise + }); // this.ctx.lastPoint(new Point(pt.x,pt.y)); + }; + /** + * Creates an arc/curve between two tangents + * + * @name arcTo + * @function + * @param x1 {Number} The x-coordinate of the first tangent + * @param y1 {Number} The y-coordinate of the first tangent + * @param x2 {Number} The x-coordinate of the second tangent + * @param y2 {Number} The y-coordinate of the second tangent + * @param radius The radius of the arc + * @description The arcTo() method creates an arc/curve between two tangents on the canvas. + */ + // eslint-disable-next-line no-unused-vars + + + Context2D.prototype.arcTo = function (x1, y1, x2, y2, radius) { + throw new Error("arcTo not implemented."); + }; + /** + * Creates a rectangle + * + * @name rect + * @function + * @param x {Number} The x-coordinate of the upper-left corner of the rectangle + * @param y {Number} The y-coordinate of the upper-left corner of the rectangle + * @param w {Number} The width of the rectangle, in pixels + * @param h {Number} The height of the rectangle, in pixels + * @description The rect() method creates a rectangle. + */ + + + Context2D.prototype.rect = function (x, y, w, h) { + if (isNaN(x) || isNaN(y) || isNaN(w) || isNaN(h)) { + console.error("jsPDF.context2d.rect: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.rect"); + } + + this.moveTo(x, y); + this.lineTo(x + w, y); + this.lineTo(x + w, y + h); + this.lineTo(x, y + h); + this.lineTo(x, y); + this.lineTo(x + w, y); + this.lineTo(x, y); + }; + /** + * Draws a "filled" rectangle + * + * @name fillRect + * @function + * @param x {Number} The x-coordinate of the upper-left corner of the rectangle + * @param y {Number} The y-coordinate of the upper-left corner of the rectangle + * @param w {Number} The width of the rectangle, in pixels + * @param h {Number} The height of the rectangle, in pixels + * @description The fillRect() method draws a "filled" rectangle. The default color of the fill is black. + */ + + + Context2D.prototype.fillRect = function (x, y, w, h) { + if (isNaN(x) || isNaN(y) || isNaN(w) || isNaN(h)) { + console.error("jsPDF.context2d.fillRect: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.fillRect"); + } + + if (isFillTransparent.call(this)) { + return; + } + + var tmp = {}; + + if (this.lineCap !== "butt") { + tmp.lineCap = this.lineCap; + this.lineCap = "butt"; + } + + if (this.lineJoin !== "miter") { + tmp.lineJoin = this.lineJoin; + this.lineJoin = "miter"; + } + + this.beginPath(); + this.rect(x, y, w, h); + this.fill(); + + if (tmp.hasOwnProperty("lineCap")) { + this.lineCap = tmp.lineCap; + } + + if (tmp.hasOwnProperty("lineJoin")) { + this.lineJoin = tmp.lineJoin; + } + }; + /** + * Draws a rectangle (no fill) + * + * @name strokeRect + * @function + * @param x {Number} The x-coordinate of the upper-left corner of the rectangle + * @param y {Number} The y-coordinate of the upper-left corner of the rectangle + * @param w {Number} The width of the rectangle, in pixels + * @param h {Number} The height of the rectangle, in pixels + * @description The strokeRect() method draws a rectangle (no fill). The default color of the stroke is black. + */ + + + Context2D.prototype.strokeRect = function strokeRect(x, y, w, h) { + if (isNaN(x) || isNaN(y) || isNaN(w) || isNaN(h)) { + console.error("jsPDF.context2d.strokeRect: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.strokeRect"); + } + + if (isStrokeTransparent.call(this)) { + return; + } + + this.beginPath(); + this.rect(x, y, w, h); + this.stroke(); + }; + /** + * Clears the specified pixels within a given rectangle + * + * @name clearRect + * @function + * @param x {Number} The x-coordinate of the upper-left corner of the rectangle + * @param y {Number} The y-coordinate of the upper-left corner of the rectangle + * @param w {Number} The width of the rectangle to clear, in pixels + * @param h {Number} The height of the rectangle to clear, in pixels + * @description We cannot clear PDF commands that were already written to PDF, so we use white instead.
    + * As a special case, read a special flag (ignoreClearRect) and do nothing if it is set. + * This results in all calls to clearRect() to do nothing, and keep the canvas transparent. + * This flag is stored in the save/restore context and is managed the same way as other drawing states. + * + */ + + + Context2D.prototype.clearRect = function (x, y, w, h) { + if (isNaN(x) || isNaN(y) || isNaN(w) || isNaN(h)) { + console.error("jsPDF.context2d.clearRect: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.clearRect"); + } + + if (this.ignoreClearRect) { + return; + } + + this.fillStyle = "#ffffff"; + this.fillRect(x, y, w, h); + }; + /** + * Saves the state of the current context + * + * @name save + * @function + */ + + + Context2D.prototype.save = function (doStackPush) { + doStackPush = typeof doStackPush === "boolean" ? doStackPush : true; + var tmpPageNumber = this.pdf.internal.getCurrentPageInfo().pageNumber; + + for (var i = 0; i < this.pdf.internal.getNumberOfPages(); i++) { + this.pdf.setPage(i + 1); + this.pdf.internal.out("q"); + } + + this.pdf.setPage(tmpPageNumber); + + if (doStackPush) { + this.ctx.fontSize = this.pdf.internal.getFontSize(); + var ctx = new ContextLayer(this.ctx); + this.ctxStack.push(this.ctx); + this.ctx = ctx; + } + }; + /** + * Returns previously saved path state and attributes + * + * @name restore + * @function + */ + + + Context2D.prototype.restore = function (doStackPop) { + doStackPop = typeof doStackPop === "boolean" ? doStackPop : true; + var tmpPageNumber = this.pdf.internal.getCurrentPageInfo().pageNumber; + + for (var i = 0; i < this.pdf.internal.getNumberOfPages(); i++) { + this.pdf.setPage(i + 1); + this.pdf.internal.out("Q"); + } + + this.pdf.setPage(tmpPageNumber); + + if (doStackPop && this.ctxStack.length !== 0) { + this.ctx = this.ctxStack.pop(); + this.fillStyle = this.ctx.fillStyle; + this.strokeStyle = this.ctx.strokeStyle; + this.font = this.ctx.font; + this.lineCap = this.ctx.lineCap; + this.lineWidth = this.ctx.lineWidth; + this.lineJoin = this.ctx.lineJoin; + } + }; + /** + * @name toDataURL + * @function + */ + + + Context2D.prototype.toDataURL = function () { + throw new Error("toDataUrl not implemented."); + }; //helper functions + + /** + * Get the decimal values of r, g, b and a + * + * @name getRGBA + * @function + * @private + * @ignore + */ + + + var getRGBA = function getRGBA(style) { + var rxRgb = /rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/; + var rxRgba = /rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d.]+)\s*\)/; + var rxTransparent = /transparent|rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*0+\s*\)/; + var r, g, b, a; + + if (style.isCanvasGradient === true) { + style = style.getColor(); + } + + if (!style) { + return { + r: 0, + g: 0, + b: 0, + a: 0, + style: style + }; + } + + if (rxTransparent.test(style)) { + r = 0; + g = 0; + b = 0; + a = 0; + } else { + var matches = rxRgb.exec(style); + + if (matches !== null) { + r = parseInt(matches[1]); + g = parseInt(matches[2]); + b = parseInt(matches[3]); + a = 1; + } else { + matches = rxRgba.exec(style); + + if (matches !== null) { + r = parseInt(matches[1]); + g = parseInt(matches[2]); + b = parseInt(matches[3]); + a = parseFloat(matches[4]); + } else { + a = 1; + + if (typeof style === "string" && style.charAt(0) !== "#") { + var rgbColor = new RGBColor(style); + + if (rgbColor.ok) { + style = rgbColor.toHex(); + } else { + style = "#000000"; + } + } + + if (style.length === 4) { + r = style.substring(1, 2); + r += r; + g = style.substring(2, 3); + g += g; + b = style.substring(3, 4); + b += b; + } else { + r = style.substring(1, 3); + g = style.substring(3, 5); + b = style.substring(5, 7); + } + + r = parseInt(r, 16); + g = parseInt(g, 16); + b = parseInt(b, 16); + } + } + } + + return { + r: r, + g: g, + b: b, + a: a, + style: style + }; + }; + /** + * @name isFillTransparent + * @function + * @private + * @ignore + * @returns {Boolean} + */ + + + var isFillTransparent = function isFillTransparent() { + return this.ctx.isFillTransparent || this.globalAlpha == 0; + }; + /** + * @name isStrokeTransparent + * @function + * @private + * @ignore + * @returns {Boolean} + */ + + + var isStrokeTransparent = function isStrokeTransparent() { + return Boolean(this.ctx.isStrokeTransparent || this.globalAlpha == 0); + }; + /** + * Draws "filled" text on the canvas + * + * @name fillText + * @function + * @param text {String} Specifies the text that will be written on the canvas + * @param x {Number} The x coordinate where to start painting the text (relative to the canvas) + * @param y {Number} The y coordinate where to start painting the text (relative to the canvas) + * @param maxWidth {Number} Optional. The maximum allowed width of the text, in pixels + * @description The fillText() method draws filled text on the canvas. The default color of the text is black. + */ + + + Context2D.prototype.fillText = function (text, x, y, maxWidth) { + if (isNaN(x) || isNaN(y) || typeof text !== "string") { + console.error("jsPDF.context2d.fillText: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.fillText"); + } + + maxWidth = isNaN(maxWidth) ? undefined : maxWidth; + + if (isFillTransparent.call(this)) { + return; + } + + y = getBaseline.call(this, y); + var degs = rad2deg(this.ctx.transform.rotation); // We only use X axis as scale hint + + var scale = this.ctx.transform.scaleX; + putText.call(this, { + text: text, + x: x, + y: y, + scale: scale, + angle: degs, + align: this.textAlign, + maxWidth: maxWidth + }); + }; + /** + * Draws text on the canvas (no fill) + * + * @name strokeText + * @function + * @param text {String} Specifies the text that will be written on the canvas + * @param x {Number} The x coordinate where to start painting the text (relative to the canvas) + * @param y {Number} The y coordinate where to start painting the text (relative to the canvas) + * @param maxWidth {Number} Optional. The maximum allowed width of the text, in pixels + * @description The strokeText() method draws text (with no fill) on the canvas. The default color of the text is black. + */ + + + Context2D.prototype.strokeText = function (text, x, y, maxWidth) { + if (isNaN(x) || isNaN(y) || typeof text !== "string") { + console.error("jsPDF.context2d.strokeText: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.strokeText"); + } + + if (isStrokeTransparent.call(this)) { + return; + } + + maxWidth = isNaN(maxWidth) ? undefined : maxWidth; + y = getBaseline.call(this, y); + var degs = rad2deg(this.ctx.transform.rotation); + var scale = this.ctx.transform.scaleX; + putText.call(this, { + text: text, + x: x, + y: y, + scale: scale, + renderingMode: "stroke", + angle: degs, + align: this.textAlign, + maxWidth: maxWidth + }); + }; + /** + * Returns an object that contains the width of the specified text + * + * @name measureText + * @function + * @param text {String} The text to be measured + * @description The measureText() method returns an object that contains the width of the specified text, in pixels. + * @returns {Number} + */ + + + Context2D.prototype.measureText = function (text) { + if (typeof text !== "string") { + console.error("jsPDF.context2d.measureText: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.measureText"); + } + + var pdf = this.pdf; + var k = this.pdf.internal.scaleFactor; + var fontSize = pdf.internal.getFontSize(); + var txtWidth = pdf.getStringUnitWidth(text) * fontSize / pdf.internal.scaleFactor; + txtWidth *= Math.round(k * 96 / 72 * 10000) / 10000; + + var TextMetrics = function TextMetrics(options) { + options = options || {}; + + var _width = options.width || 0; + + Object.defineProperty(this, "width", { + get: function get() { + return _width; + } + }); + return this; + }; + + return new TextMetrics({ + width: txtWidth + }); + }; //Transformations + + /** + * Scales the current drawing bigger or smaller + * + * @name scale + * @function + * @param scalewidth {Number} Scales the width of the current drawing (1=100%, 0.5=50%, 2=200%, etc.) + * @param scaleheight {Number} Scales the height of the current drawing (1=100%, 0.5=50%, 2=200%, etc.) + * @description The scale() method scales the current drawing, bigger or smaller. + */ + + + Context2D.prototype.scale = function (scalewidth, scaleheight) { + if (isNaN(scalewidth) || isNaN(scaleheight)) { + console.error("jsPDF.context2d.scale: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.scale"); + } + + var matrix = new Matrix(scalewidth, 0.0, 0.0, scaleheight, 0.0, 0.0); + this.ctx.transform = this.ctx.transform.multiply(matrix); + }; + /** + * Rotates the current drawing + * + * @name rotate + * @function + * @param angle {Number} The rotation angle, in radians. + * @description To calculate from degrees to radians: degrees*Math.PI/180.
    + * Example: to rotate 5 degrees, specify the following: 5*Math.PI/180 + */ + + + Context2D.prototype.rotate = function (angle) { + if (isNaN(angle)) { + console.error("jsPDF.context2d.rotate: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.rotate"); + } + + var matrix = new Matrix(Math.cos(angle), Math.sin(angle), -Math.sin(angle), Math.cos(angle), 0.0, 0.0); + this.ctx.transform = this.ctx.transform.multiply(matrix); + }; + /** + * Remaps the (0,0) position on the canvas + * + * @name translate + * @function + * @param x {Number} The value to add to horizontal (x) coordinates + * @param y {Number} The value to add to vertical (y) coordinates + * @description The translate() method remaps the (0,0) position on the canvas. + */ + + + Context2D.prototype.translate = function (x, y) { + if (isNaN(x) || isNaN(y)) { + console.error("jsPDF.context2d.translate: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.translate"); + } + + var matrix = new Matrix(1.0, 0.0, 0.0, 1.0, x, y); + this.ctx.transform = this.ctx.transform.multiply(matrix); + }; + /** + * Replaces the current transformation matrix for the drawing + * + * @name transform + * @function + * @param a {Number} Horizontal scaling + * @param b {Number} Horizontal skewing + * @param c {Number} Vertical skewing + * @param d {Number} Vertical scaling + * @param e {Number} Horizontal moving + * @param f {Number} Vertical moving + * @description Each object on the canvas has a current transformation matrix.

    The transform() method replaces the current transformation matrix. It multiplies the current transformation matrix with the matrix described by:



    a c e

    b d f

    0 0 1

    In other words, the transform() method lets you scale, rotate, move, and skew the current context. + */ + + + Context2D.prototype.transform = function (a, b, c, d, e, f) { + if (isNaN(a) || isNaN(b) || isNaN(c) || isNaN(d) || isNaN(e) || isNaN(f)) { + console.error("jsPDF.context2d.transform: Invalid arguments", arguments); + throw new Error("Invalid arguments passed to jsPDF.context2d.transform"); + } + + var matrix = new Matrix(a, b, c, d, e, f); + this.ctx.transform = this.ctx.transform.multiply(matrix); + }; + /** + * Resets the current transform to the identity matrix. Then runs transform() + * + * @name setTransform + * @function + * @param a {Number} Horizontal scaling + * @param b {Number} Horizontal skewing + * @param c {Number} Vertical skewing + * @param d {Number} Vertical scaling + * @param e {Number} Horizontal moving + * @param f {Number} Vertical moving + * @description Each object on the canvas has a current transformation matrix.

    The setTransform() method resets the current transform to the identity matrix, and then runs transform() with the same arguments.

    In other words, the setTransform() method lets you scale, rotate, move, and skew the current context. + */ + + + Context2D.prototype.setTransform = function (a, b, c, d, e, f) { + a = isNaN(a) ? 1 : a; + b = isNaN(b) ? 0 : b; + c = isNaN(c) ? 0 : c; + d = isNaN(d) ? 1 : d; + e = isNaN(e) ? 0 : e; + f = isNaN(f) ? 0 : f; + this.ctx.transform = new Matrix(a, b, c, d, e, f); + }; + /** + * Draws an image, canvas, or video onto the canvas + * + * @function + * @param img {} Specifies the image, canvas, or video element to use + * @param sx {Number} Optional. The x coordinate where to start clipping + * @param sy {Number} Optional. The y coordinate where to start clipping + * @param swidth {Number} Optional. The width of the clipped image + * @param sheight {Number} Optional. The height of the clipped image + * @param x {Number} The x coordinate where to place the image on the canvas + * @param y {Number} The y coordinate where to place the image on the canvas + * @param width {Number} Optional. The width of the image to use (stretch or reduce the image) + * @param height {Number} Optional. The height of the image to use (stretch or reduce the image) + */ + + + Context2D.prototype.drawImage = function (img, sx, sy, swidth, sheight, x, y, width, height) { + var imageProperties = this.pdf.getImageProperties(img); + var factorX = 1; + var factorY = 1; + var clipFactorX = 1; + var clipFactorY = 1; + + if (typeof swidth !== "undefined" && typeof width !== "undefined") { + clipFactorX = width / swidth; + clipFactorY = height / sheight; + factorX = imageProperties.width / swidth * width / swidth; + factorY = imageProperties.height / sheight * height / sheight; + } //is sx and sy are set and x and y not, set x and y with values of sx and sy + + + if (typeof x === "undefined") { + x = sx; + y = sy; + sx = 0; + sy = 0; + } + + if (typeof swidth !== "undefined" && typeof width === "undefined") { + width = swidth; + height = sheight; + } + + if (typeof swidth === "undefined" && typeof width === "undefined") { + width = imageProperties.width; + height = imageProperties.height; + } + + var decomposedTransformationMatrix = this.ctx.transform.decompose(); + var angle = rad2deg(decomposedTransformationMatrix.rotate.shx); + var matrix = new Matrix(); + matrix = matrix.multiply(decomposedTransformationMatrix.translate); + matrix = matrix.multiply(decomposedTransformationMatrix.skew); + matrix = matrix.multiply(decomposedTransformationMatrix.scale); + var xRect = matrix.applyToRectangle(new Rectangle(x - sx * clipFactorX, y - sy * clipFactorY, swidth * factorX, sheight * factorY)); + var pageArray = getPagesByPath.call(this, xRect); + var pages = []; + + for (var ii = 0; ii < pageArray.length; ii += 1) { + if (pages.indexOf(pageArray[ii]) === -1) { + pages.push(pageArray[ii]); + } + } + + pages.sort(); + var clipPath; + + if (this.autoPaging) { + var min = pages[0]; + var max = pages[pages.length - 1]; + + for (var i = min; i < max + 1; i++) { + this.pdf.setPage(i); + + if (this.ctx.clip_path.length !== 0) { + var tmpPaths = this.path; + clipPath = JSON.parse(JSON.stringify(this.ctx.clip_path)); + this.path = pathPositionRedo(clipPath, this.posX, -1 * this.pdf.internal.pageSize.height * (i - 1) + this.posY); + drawPaths.call(this, "fill", true); + this.path = tmpPaths; + } + + var tmpRect = JSON.parse(JSON.stringify(xRect)); + tmpRect = pathPositionRedo([tmpRect], this.posX, -1 * this.pdf.internal.pageSize.height * (i - 1) + this.posY)[0]; + this.pdf.addImage(img, "JPEG", tmpRect.x, tmpRect.y, tmpRect.w, tmpRect.h, null, null, angle); + } + } else { + this.pdf.addImage(img, "JPEG", xRect.x, xRect.y, xRect.w, xRect.h, null, null, angle); + } + }; + + var getPagesByPath = function getPagesByPath(path, pageWrapX, pageWrapY) { + var result = []; + pageWrapX = pageWrapX || this.pdf.internal.pageSize.width; + pageWrapY = pageWrapY || this.pdf.internal.pageSize.height; + + switch (path.type) { + default: + case "mt": + case "lt": + result.push(Math.floor((path.y + this.posY) / pageWrapY) + 1); + break; + + case "arc": + result.push(Math.floor((path.y + this.posY - path.radius) / pageWrapY) + 1); + result.push(Math.floor((path.y + this.posY + path.radius) / pageWrapY) + 1); + break; + + case "qct": + var rectOfQuadraticCurve = getQuadraticCurveBoundary(this.ctx.lastPoint.x, this.ctx.lastPoint.y, path.x1, path.y1, path.x, path.y); + result.push(Math.floor(rectOfQuadraticCurve.y / pageWrapY) + 1); + result.push(Math.floor((rectOfQuadraticCurve.y + rectOfQuadraticCurve.h) / pageWrapY) + 1); + break; + + case "bct": + var rectOfBezierCurve = getBezierCurveBoundary(this.ctx.lastPoint.x, this.ctx.lastPoint.y, path.x1, path.y1, path.x2, path.y2, path.x, path.y); + result.push(Math.floor(rectOfBezierCurve.y / pageWrapY) + 1); + result.push(Math.floor((rectOfBezierCurve.y + rectOfBezierCurve.h) / pageWrapY) + 1); + break; + + case "rect": + result.push(Math.floor((path.y + this.posY) / pageWrapY) + 1); + result.push(Math.floor((path.y + path.h + this.posY) / pageWrapY) + 1); + } + + for (var i = 0; i < result.length; i += 1) { + while (this.pdf.internal.getNumberOfPages() < result[i]) { + addPage.call(this); + } + } + + return result; + }; + + var addPage = function addPage() { + var fillStyle = this.fillStyle; + var strokeStyle = this.strokeStyle; + var font = this.font; + var lineCap = this.lineCap; + var lineWidth = this.lineWidth; + var lineJoin = this.lineJoin; + this.pdf.addPage(); + this.fillStyle = fillStyle; + this.strokeStyle = strokeStyle; + this.font = font; + this.lineCap = lineCap; + this.lineWidth = lineWidth; + this.lineJoin = lineJoin; + }; + + var pathPositionRedo = function pathPositionRedo(paths, x, y) { + for (var i = 0; i < paths.length; i++) { + switch (paths[i].type) { + case "bct": + paths[i].x2 += x; + paths[i].y2 += y; + + case "qct": + paths[i].x1 += x; + paths[i].y1 += y; + + case "mt": + case "lt": + case "arc": + default: + paths[i].x += x; + paths[i].y += y; + } + } + + return paths; + }; + + var pathPreProcess = function pathPreProcess(rule, isClip) { + var fillStyle = this.fillStyle; + var strokeStyle = this.strokeStyle; + var lineCap = this.lineCap; + var lineWidth = this.lineWidth; + var lineJoin = this.lineJoin; + var origPath = JSON.parse(JSON.stringify(this.path)); + var xPath = JSON.parse(JSON.stringify(this.path)); + var clipPath; + var tmpPath; + var pages = []; + + for (var i = 0; i < xPath.length; i++) { + if (typeof xPath[i].x !== "undefined") { + var page = getPagesByPath.call(this, xPath[i]); + + for (var ii = 0; ii < page.length; ii += 1) { + if (pages.indexOf(page[ii]) === -1) { + pages.push(page[ii]); + } + } + } + } + + for (var j = 0; j < pages.length; j++) { + while (this.pdf.internal.getNumberOfPages() < pages[j]) { + addPage.call(this); + } + } + + pages.sort(); + + if (this.autoPaging) { + var min = pages[0]; + var max = pages[pages.length - 1]; + + for (var k = min; k < max + 1; k++) { + this.pdf.setPage(k); + this.fillStyle = fillStyle; + this.strokeStyle = strokeStyle; + this.lineCap = lineCap; + this.lineWidth = lineWidth; + this.lineJoin = lineJoin; + + if (this.ctx.clip_path.length !== 0) { + var tmpPaths = this.path; + clipPath = JSON.parse(JSON.stringify(this.ctx.clip_path)); + this.path = pathPositionRedo(clipPath, this.posX, -1 * this.pdf.internal.pageSize.height * (k - 1) + this.posY); + drawPaths.call(this, rule, true); + this.path = tmpPaths; + } + + tmpPath = JSON.parse(JSON.stringify(origPath)); + this.path = pathPositionRedo(tmpPath, this.posX, -1 * this.pdf.internal.pageSize.height * (k - 1) + this.posY); + + if (isClip === false || k === 0) { + drawPaths.call(this, rule, isClip); + } + } + } else { + drawPaths.call(this, rule, isClip); + } + + this.path = origPath; + }; + /** + * Processes the paths + * + * @function + * @param rule {String} + * @param isClip {Boolean} + * @private + * @ignore + */ + + + var drawPaths = function drawPaths(rule, isClip) { + if (rule === "stroke" && !isClip && isStrokeTransparent.call(this)) { + return; + } + + if (rule !== "stroke" && !isClip && isFillTransparent.call(this)) { + return; + } + + var moves = []; //var alpha = (this.ctx.fillOpacity < 1) ? this.ctx.fillOpacity : this.ctx.globalAlpha; + + var delta; + var xPath = this.path; + + for (var i = 0; i < xPath.length; i++) { + var pt = xPath[i]; + + switch (pt.type) { + case "begin": + moves.push({ + begin: true + }); + break; + + case "close": + moves.push({ + close: true + }); + break; + + case "mt": + moves.push({ + start: pt, + deltas: [], + abs: [] + }); + break; + + case "lt": + var iii = moves.length; + + if (!isNaN(xPath[i - 1].x)) { + delta = [pt.x - xPath[i - 1].x, pt.y - xPath[i - 1].y]; + + if (iii > 0) { + for (iii; iii >= 0; iii--) { + if (moves[iii - 1].close !== true && moves[iii - 1].begin !== true) { + moves[iii - 1].deltas.push(delta); + moves[iii - 1].abs.push(pt); + break; + } + } + } + } + + break; + + case "bct": + delta = [pt.x1 - xPath[i - 1].x, pt.y1 - xPath[i - 1].y, pt.x2 - xPath[i - 1].x, pt.y2 - xPath[i - 1].y, pt.x - xPath[i - 1].x, pt.y - xPath[i - 1].y]; + moves[moves.length - 1].deltas.push(delta); + break; + + case "qct": + var x1 = xPath[i - 1].x + 2.0 / 3.0 * (pt.x1 - xPath[i - 1].x); + var y1 = xPath[i - 1].y + 2.0 / 3.0 * (pt.y1 - xPath[i - 1].y); + var x2 = pt.x + 2.0 / 3.0 * (pt.x1 - pt.x); + var y2 = pt.y + 2.0 / 3.0 * (pt.y1 - pt.y); + var x3 = pt.x; + var y3 = pt.y; + delta = [x1 - xPath[i - 1].x, y1 - xPath[i - 1].y, x2 - xPath[i - 1].x, y2 - xPath[i - 1].y, x3 - xPath[i - 1].x, y3 - xPath[i - 1].y]; + moves[moves.length - 1].deltas.push(delta); + break; + + case "arc": + moves.push({ + deltas: [], + abs: [], + arc: true + }); + + if (Array.isArray(moves[moves.length - 1].abs)) { + moves[moves.length - 1].abs.push(pt); + } + + break; + } + } + + var style; + + if (!isClip) { + if (rule === "stroke") { + style = "stroke"; + } else { + style = "fill"; + } + } else { + style = null; + } + + for (var k = 0; k < moves.length; k++) { + if (moves[k].arc) { + var arcs = moves[k].abs; + + for (var ii = 0; ii < arcs.length; ii++) { + var arc = arcs[ii]; + + if (arc.type === "arc") { + drawArc.call(this, arc.x, arc.y, arc.radius, arc.startAngle, arc.endAngle, arc.counterclockwise, undefined, isClip); + } else { + drawLine.call(this, arc.x, arc.y); + } + } + + putStyle.call(this, style); + this.pdf.internal.out("h"); + } + + if (!moves[k].arc) { + if (moves[k].close !== true && moves[k].begin !== true) { + var x = moves[k].start.x; + var y = moves[k].start.y; + drawLines.call(this, moves[k].deltas, x, y); + } + } + } + + if (style) { + putStyle.call(this, style); + } + + if (isClip) { + doClip.call(this); + } + }; + + var getBaseline = function getBaseline(y) { + var height = this.pdf.internal.getFontSize() / this.pdf.internal.scaleFactor; + var descent = height * (this.pdf.internal.getLineHeightFactor() - 1); + + switch (this.ctx.textBaseline) { + case "bottom": + return y - descent; + + case "top": + return y + height - descent; + + case "hanging": + return y + height - 2 * descent; + + case "middle": + return y + height / 2 - descent; + + case "ideographic": + // TODO not implemented + return y; + + case "alphabetic": + default: + return y; + } + }; + + Context2D.prototype.createLinearGradient = function createLinearGradient() { + var canvasGradient = function canvasGradient() {}; + + canvasGradient.colorStops = []; + + canvasGradient.addColorStop = function (offset, color) { + this.colorStops.push([offset, color]); + }; + + canvasGradient.getColor = function () { + if (this.colorStops.length === 0) { + return "#000000"; + } + + return this.colorStops[0][1]; + }; + + canvasGradient.isCanvasGradient = true; + return canvasGradient; + }; + + Context2D.prototype.createPattern = function createPattern() { + return this.createLinearGradient(); + }; + + Context2D.prototype.createRadialGradient = function createRadialGradient() { + return this.createLinearGradient(); + }; + /** + * + * @param x Edge point X + * @param y Edge point Y + * @param r Radius + * @param a1 start angle + * @param a2 end angle + * @param counterclockwise + * @param style + * @param isClip + */ + + + var drawArc = function drawArc(x, y, r, a1, a2, counterclockwise, style, isClip) { + var curves = createArc.call(this, r, a1, a2, counterclockwise); + + for (var i = 0; i < curves.length; i++) { + var curve = curves[i]; + + if (i === 0) { + doMove.call(this, curve.x1 + x, curve.y1 + y); + } + + drawCurve.call(this, x, y, curve.x2, curve.y2, curve.x3, curve.y3, curve.x4, curve.y4); + } + + if (!isClip) { + putStyle.call(this, style); + } else { + doClip.call(this); + } + }; + + var putStyle = function putStyle(style) { + switch (style) { + case "stroke": + this.pdf.internal.out("S"); + break; + + case "fill": + this.pdf.internal.out("f"); + break; + } + }; + + var doClip = function doClip() { + this.pdf.clip(); + this.pdf.discardPath(); + }; + + var doMove = function doMove(x, y) { + this.pdf.internal.out(getHorizontalCoordinateString(x) + " " + getVerticalCoordinateString(y) + " m"); + }; + + var putText = function putText(options) { + var textAlign; + + switch (options.align) { + case "right": + case "end": + textAlign = "right"; + break; + + case "center": + textAlign = "center"; + break; + + case "left": + case "start": + default: + textAlign = "left"; + break; + } + + var pt = this.ctx.transform.applyToPoint(new Point(options.x, options.y)); + var decomposedTransformationMatrix = this.ctx.transform.decompose(); + var matrix = new Matrix(); + matrix = matrix.multiply(decomposedTransformationMatrix.translate); + matrix = matrix.multiply(decomposedTransformationMatrix.skew); + matrix = matrix.multiply(decomposedTransformationMatrix.scale); + var textDimensions = this.pdf.getTextDimensions(options.text); + var textRect = this.ctx.transform.applyToRectangle(new Rectangle(options.x, options.y, textDimensions.w, textDimensions.h)); + var textXRect = matrix.applyToRectangle(new Rectangle(options.x, options.y - textDimensions.h, textDimensions.w, textDimensions.h)); + var pageArray = getPagesByPath.call(this, textXRect); + var pages = []; + + for (var ii = 0; ii < pageArray.length; ii += 1) { + if (pages.indexOf(pageArray[ii]) === -1) { + pages.push(pageArray[ii]); + } + } + + pages.sort(); + var clipPath, oldSize; + + if (this.autoPaging === true) { + var min = pages[0]; + var max = pages[pages.length - 1]; + + for (var i = min; i < max + 1; i++) { + this.pdf.setPage(i); + + if (this.ctx.clip_path.length !== 0) { + var tmpPaths = this.path; + clipPath = JSON.parse(JSON.stringify(this.ctx.clip_path)); + this.path = pathPositionRedo(clipPath, this.posX, -1 * this.pdf.internal.pageSize.height * (i - 1) + this.posY); + drawPaths.call(this, "fill", true); + this.path = tmpPaths; + } + + var tmpRect = JSON.parse(JSON.stringify(textRect)); + tmpRect = pathPositionRedo([tmpRect], this.posX, -1 * this.pdf.internal.pageSize.height * (i - 1) + this.posY)[0]; + + if (options.scale >= 0.01) { + oldSize = this.pdf.internal.getFontSize(); + this.pdf.setFontSize(oldSize * options.scale); + } + + this.pdf.text(options.text, tmpRect.x, tmpRect.y, { + angle: options.angle, + align: textAlign, + renderingMode: options.renderingMode, + maxWidth: options.maxWidth + }); + + if (options.scale >= 0.01) { + this.pdf.setFontSize(oldSize); + } + } + } else { + if (options.scale >= 0.01) { + oldSize = this.pdf.internal.getFontSize(); + this.pdf.setFontSize(oldSize * options.scale); + } + + this.pdf.text(options.text, pt.x + this.posX, pt.y + this.posY, { + angle: options.angle, + align: textAlign, + renderingMode: options.renderingMode, + maxWidth: options.maxWidth + }); + + if (options.scale >= 0.01) { + this.pdf.setFontSize(oldSize); + } + } + }; + + var drawLine = function drawLine(x, y, prevX, prevY) { + prevX = prevX || 0; + prevY = prevY || 0; + this.pdf.internal.out(getHorizontalCoordinateString(x + prevX) + " " + getVerticalCoordinateString(y + prevY) + " l"); + }; + + var drawLines = function drawLines(lines, x, y) { + return this.pdf.lines(lines, x, y, null, null); + }; + + var drawCurve = function drawCurve(x, y, x1, y1, x2, y2, x3, y3) { + this.pdf.internal.out([f2(getHorizontalCoordinate(x1 + x)), f2(getVerticalCoordinate(y1 + y)), f2(getHorizontalCoordinate(x2 + x)), f2(getVerticalCoordinate(y2 + y)), f2(getHorizontalCoordinate(x3 + x)), f2(getVerticalCoordinate(y3 + y)), "c"].join(" ")); + }; + /** + * Return a array of objects that represent bezier curves which approximate the circular arc centered at the origin, from startAngle to endAngle (radians) with the specified radius. + * + * Each bezier curve is an object with four points, where x1,y1 and x4,y4 are the arc's end points and x2,y2 and x3,y3 are the cubic bezier's control points. + * @function createArc + */ + + + var createArc = function createArc(radius, startAngle, endAngle, anticlockwise) { + var EPSILON = 0.00001; // Roughly 1/1000th of a degree, see below + + var twoPi = Math.PI * 2; + var halfPi = Math.PI / 2.0; + + while (startAngle > endAngle) { + startAngle = startAngle - twoPi; + } + + var totalAngle = Math.abs(endAngle - startAngle); + + if (totalAngle < twoPi) { + if (anticlockwise) { + totalAngle = twoPi - totalAngle; + } + } // Compute the sequence of arc curves, up to PI/2 at a time. + + + var curves = []; // clockwise or counterclockwise + + var sgn = anticlockwise ? -1 : +1; + var a1 = startAngle; + + for (; totalAngle > EPSILON;) { + var remain = sgn * Math.min(totalAngle, halfPi); + var a2 = a1 + remain; + curves.push(createSmallArc.call(this, radius, a1, a2)); + totalAngle -= Math.abs(a2 - a1); + a1 = a2; + } + + return curves; + }; + /** + * Cubic bezier approximation of a circular arc centered at the origin, from (radians) a1 to a2, where a2-a1 < pi/2. The arc's radius is r. + * + * Returns an object with four points, where x1,y1 and x4,y4 are the arc's end points and x2,y2 and x3,y3 are the cubic bezier's control points. + * + * This algorithm is based on the approach described in: A. Riškus, "Approximation of a Cubic Bezier Curve by Circular Arcs and Vice Versa," Information Technology and Control, 35(4), 2006 pp. 371-378. + */ + + + var createSmallArc = function createSmallArc(r, a1, a2) { + var a = (a2 - a1) / 2.0; + var x4 = r * Math.cos(a); + var y4 = r * Math.sin(a); + var x1 = x4; + var y1 = -y4; + var q1 = x1 * x1 + y1 * y1; + var q2 = q1 + x1 * x4 + y1 * y4; + var k2 = 4 / 3 * (Math.sqrt(2 * q1 * q2) - q2) / (x1 * y4 - y1 * x4); + var x2 = x1 - k2 * y1; + var y2 = y1 + k2 * x1; + var x3 = x2; + var y3 = -y2; + var ar = a + a1; + var cos_ar = Math.cos(ar); + var sin_ar = Math.sin(ar); + return { + x1: r * Math.cos(a1), + y1: r * Math.sin(a1), + x2: x2 * cos_ar - y2 * sin_ar, + y2: x2 * sin_ar + y2 * cos_ar, + x3: x3 * cos_ar - y3 * sin_ar, + y3: x3 * sin_ar + y3 * cos_ar, + x4: r * Math.cos(a2), + y4: r * Math.sin(a2) + }; + }; + + var rad2deg = function rad2deg(value) { + return value * 180 / Math.PI; + }; + + var getQuadraticCurveBoundary = function getQuadraticCurveBoundary(sx, sy, cpx, cpy, ex, ey) { + var midX1 = sx + (cpx - sx) * 0.5; + var midY1 = sy + (cpy - sy) * 0.5; + var midX2 = ex + (cpx - ex) * 0.5; + var midY2 = ey + (cpy - ey) * 0.5; + var resultX1 = Math.min(sx, ex, midX1, midX2); + var resultX2 = Math.max(sx, ex, midX1, midX2); + var resultY1 = Math.min(sy, ey, midY1, midY2); + var resultY2 = Math.max(sy, ey, midY1, midY2); + return new Rectangle(resultX1, resultY1, resultX2 - resultX1, resultY2 - resultY1); + }; //De Casteljau algorithm + + + var getBezierCurveBoundary = function getBezierCurveBoundary(ax, ay, bx, by, cx, cy, dx, dy) { + var tobx = bx - ax; + var toby = by - ay; + var tocx = cx - bx; + var tocy = cy - by; + var todx = dx - cx; + var tody = dy - cy; + var precision = 40; + var d, i, px, py, qx, qy, rx, ry, tx, ty, sx, sy, x, y, minx, miny, maxx, maxy, toqx, toqy, torx, tory, totx, toty; + + for (i = 0; i < precision + 1; i++) { + d = i / precision; + px = ax + d * tobx; + py = ay + d * toby; + qx = bx + d * tocx; + qy = by + d * tocy; + rx = cx + d * todx; + ry = cy + d * tody; + toqx = qx - px; + toqy = qy - py; + torx = rx - qx; + tory = ry - qy; + sx = px + d * toqx; + sy = py + d * toqy; + tx = qx + d * torx; + ty = qy + d * tory; + totx = tx - sx; + toty = ty - sy; + x = sx + d * totx; + y = sy + d * toty; + + if (i == 0) { + minx = x; + miny = y; + maxx = x; + maxy = y; + } else { + minx = Math.min(minx, x); + miny = Math.min(miny, y); + maxx = Math.max(maxx, x); + maxy = Math.max(maxy, y); + } + } + + return new Rectangle(Math.round(minx), Math.round(miny), Math.round(maxx - minx), Math.round(maxy - miny)); + }; +})(jsPDF.API); + +/* global jsPDF, Deflater */ + +/** + * jsPDF filters PlugIn + * Copyright (c) 2014 Aras Abbasi + * + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ +(function (jsPDFAPI) { + + var ASCII85Encode = function ASCII85Encode(a) { + var b, c, d, e, f, g, h, i, j, k; // eslint-disable-next-line no-control-regex + + for (!/[^\x00-\xFF]/.test(a), b = "\x00\x00\x00\x00".slice(a.length % 4 || 4), a += b, c = [], d = 0, e = a.length; e > d; d += 4) { + f = (a.charCodeAt(d) << 24) + (a.charCodeAt(d + 1) << 16) + (a.charCodeAt(d + 2) << 8) + a.charCodeAt(d + 3), 0 !== f ? (k = f % 85, f = (f - k) / 85, j = f % 85, f = (f - j) / 85, i = f % 85, f = (f - i) / 85, h = f % 85, f = (f - h) / 85, g = f % 85, c.push(g + 33, h + 33, i + 33, j + 33, k + 33)) : c.push(122); + } + + return function (a, b) { + for (var c = b; c > 0; c--) { + a.pop(); + } + }(c, b.length), String.fromCharCode.apply(String, c) + "~>"; + }; + + var ASCII85Decode = function ASCII85Decode(a) { + var c, + d, + e, + f, + g, + h = String, + l = "length", + w = 255, + x = "charCodeAt", + y = "slice", + z = "replace"; + + for ("~>" === a[y](-2), a = a[y](0, -2)[z](/\s/g, "")[z]("z", "!!!!!"), c = "uuuuu"[y](a[l] % 5 || 5), a += c, e = [], f = 0, g = a[l]; g > f; f += 5) { + d = 52200625 * (a[x](f) - 33) + 614125 * (a[x](f + 1) - 33) + 7225 * (a[x](f + 2) - 33) + 85 * (a[x](f + 3) - 33) + (a[x](f + 4) - 33), e.push(w & d >> 24, w & d >> 16, w & d >> 8, w & d); + } + + return function (a, b) { + for (var c = b; c > 0; c--) { + a.pop(); + } + }(e, c[l]), h.fromCharCode.apply(h, e); + }; + + var ASCIIHexEncode = function ASCIIHexEncode(value) { + return value.split("").map(function (value) { + return ("0" + value.charCodeAt().toString(16)).slice(-2); + }).join("") + ">"; + }; + + var ASCIIHexDecode = function ASCIIHexDecode(value) { + var regexCheckIfHex = new RegExp(/^([0-9A-Fa-f]{2})+$/); + value = value.replace(/\s/g, ""); + + if (value.indexOf(">") !== -1) { + value = value.substr(0, value.indexOf(">")); + } + + if (value.length % 2) { + value += "0"; + } + + if (regexCheckIfHex.test(value) === false) { + return ""; + } + + var result = ""; + + for (var i = 0; i < value.length; i += 2) { + result += String.fromCharCode("0x" + (value[i] + value[i + 1])); + } + + return result; + }; + /* + var FlatePredictors = { + None: 1, + TIFF: 2, + PNG_None: 10, + PNG_Sub: 11, + PNG_Up: 12, + PNG_Average: 13, + PNG_Paeth: 14, + PNG_Optimum: 15 + }; + */ + + + var appendBuffer = function appendBuffer(buffer1, buffer2) { + var combinedBuffer = new Uint8Array(buffer1.byteLength + buffer2.byteLength); + combinedBuffer.set(new Uint8Array(buffer1), 0); + combinedBuffer.set(new Uint8Array(buffer2), buffer1.byteLength); + return combinedBuffer; + }; + + var FlateEncode = function FlateEncode(data) { + var arr = []; + var i = data.length; + var adler32; + var deflater; + + while (i--) { + arr[i] = data.charCodeAt(i); + } + + adler32 = jsPDFAPI.adler32cs.from(data); + deflater = new Deflater(6); + data = deflater.append(new Uint8Array(arr)); + data = appendBuffer(data, deflater.flush()); + arr = new Uint8Array(data.byteLength + 6); + arr.set(new Uint8Array([120, 156])); + arr.set(data, 2); + arr.set(new Uint8Array([adler32 & 0xff, adler32 >> 8 & 0xff, adler32 >> 16 & 0xff, adler32 >> 24 & 0xff]), data.byteLength + 2); + data = arr.reduce(function (data, _byte) { + return data + String.fromCharCode(_byte); + }, ""); + return data; + }; + + jsPDFAPI.processDataByFilters = function (origData, filterChain) { + + var i = 0; + var data = origData || ""; + var reverseChain = []; + filterChain = filterChain || []; + + if (typeof filterChain === "string") { + filterChain = [filterChain]; + } + + for (i = 0; i < filterChain.length; i += 1) { + switch (filterChain[i]) { + case "ASCII85Decode": + case "/ASCII85Decode": + data = ASCII85Decode(data); + reverseChain.push("/ASCII85Encode"); + break; + + case "ASCII85Encode": + case "/ASCII85Encode": + data = ASCII85Encode(data); + reverseChain.push("/ASCII85Decode"); + break; + + case "ASCIIHexDecode": + case "/ASCIIHexDecode": + data = ASCIIHexDecode(data); + reverseChain.push("/ASCIIHexEncode"); + break; + + case "ASCIIHexEncode": + case "/ASCIIHexEncode": + data = ASCIIHexEncode(data); + reverseChain.push("/ASCIIHexDecode"); + break; + + case "FlateEncode": + case "/FlateEncode": + data = FlateEncode(data); + reverseChain.push("/FlateDecode"); + break; + + default: + throw new Error('The filter: "' + filterChain[i] + '" is not implemented'); + } + } + + return { + data: data, + reverseChain: reverseChain.reverse().join(" ") + }; + }; +})(jsPDF.API); + +/* global jsPDF */ + +/** + * jsPDF fileloading PlugIn + * Copyright (c) 2018 Aras Abbasi (aras.abbasi@gmail.com) + * + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ + +/** + * @name fileloading + * @module + */ +(function (jsPDFAPI) { + /** + * @name loadFile + * @function + * @param {string} url + * @param {boolean} sync + * @param {function} callback + * @returns {string|undefined} result + */ + + jsPDFAPI.loadFile = function (url, sync, callback) { + sync = sync === false ? false : true; + callback = typeof callback === "function" ? callback : function () {}; + var result = undefined; + + var xhr = function xhr(url, sync, callback) { + var request = new XMLHttpRequest(); + var i = 0; + + var sanitizeUnicode = function sanitizeUnicode(data) { + var dataLength = data.length; + var charArray = []; + var StringFromCharCode = String.fromCharCode; //Transform Unicode to ASCII + + for (i = 0; i < dataLength; i += 1) { + charArray.push(StringFromCharCode(data.charCodeAt(i) & 0xff)); + } + + return charArray.join(""); + }; + + request.open("GET", url, !sync); // XHR binary charset opt by Marcus Granado 2006 [http://mgran.blogspot.com] + + request.overrideMimeType("text/plain; charset=x-user-defined"); + + if (sync === false) { + request.onload = function () { + if (request.status === 200) { + callback(sanitizeUnicode(this.responseText)); + } else { + callback(undefined); + } + }; + } + + request.send(null); + + if (sync && request.status === 200) { + return sanitizeUnicode(request.responseText); + } + }; + + try { + result = xhr(url, sync, callback); // eslint-disable-next-line no-empty + } catch (e) {} + + return result; + }; + /** + * @name loadImageFile + * @function + * @param {string} path + * @param {boolean} sync + * @param {function} callback + */ + + + jsPDFAPI.loadImageFile = jsPDFAPI.loadFile; +})(jsPDF.API); + +/* global jsPDF html2canvas */ + +/** + * Copyright (c) 2018 Erik Koopmans + * Released under the MIT License. + * + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ + +/** + * jsPDF html PlugIn + * + * @name html + * @module + */ +(function (jsPDFAPI, global) { + + if (typeof Promise === "undefined") { + // eslint-disable-next-line no-console + console.warn("Promise not found. html-Plugin will not work"); + return; + } + /** + * Determine the type of a variable/object. + * + * @private + * @ignore + */ + + + var objType = function objType(obj) { + var type = _typeof(obj); + + if (type === "undefined") { return "undefined"; }else if (type === "string" || obj instanceof String) { return "string"; }else if (type === "number" || obj instanceof Number) { return "number"; }else if (type === "function" || obj instanceof Function) { return "function"; }else if (!!obj && obj.constructor === Array) { return "array"; }else if (obj && obj.nodeType === 1) { return "element"; }else if (type === "object") { return "object"; }else { return "unknown"; } + }; + /** + * Create an HTML element with optional className, innerHTML, and style. + * + * @private + * @ignore + */ + + + var createElement = function createElement(tagName, opt) { + var el = document.createElement(tagName); + if (opt.className) { el.className = opt.className; } + + if (opt.innerHTML) { + el.innerHTML = opt.innerHTML; + var scripts = el.getElementsByTagName("script"); + + for (var i = scripts.length; i-- > 0;) { + scripts[i].parentNode.removeChild(scripts[i]); + } + } + + for (var key in opt.style) { + el.style[key] = opt.style[key]; + } + + return el; + }; + /** + * Deep-clone a node and preserve contents/properties. + * + * @private + * @ignore + */ + + + var cloneNode = function cloneNode(node, javascriptEnabled) { + // Recursively clone the node. + var clone = node.nodeType === 3 ? document.createTextNode(node.nodeValue) : node.cloneNode(false); + + for (var child = node.firstChild; child; child = child.nextSibling) { + if (javascriptEnabled === true || child.nodeType !== 1 || child.nodeName !== "SCRIPT") { + clone.appendChild(cloneNode(child, javascriptEnabled)); + } + } + + if (node.nodeType === 1) { + // Preserve contents/properties of special nodes. + if (node.nodeName === "CANVAS") { + clone.width = node.width; + clone.height = node.height; + clone.getContext("2d").drawImage(node, 0, 0); + } else if (node.nodeName === "TEXTAREA" || node.nodeName === "SELECT") { + clone.value = node.value; + } // Preserve the node's scroll position when it loads. + + + clone.addEventListener("load", function () { + clone.scrollTop = node.scrollTop; + clone.scrollLeft = node.scrollLeft; + }, true); + } // Return the cloned node. + + + return clone; + }; + /* ----- CONSTRUCTOR ----- */ + + + var Worker = function Worker(opt) { + // Create the root parent for the proto chain, and the starting Worker. + var root = Object.assign(Worker.convert(Promise.resolve()), JSON.parse(JSON.stringify(Worker.template))); + var self = Worker.convert(Promise.resolve(), root); // Set progress, optional settings, and return. + + self = self.setProgress(1, Worker, 1, [Worker]); + self = self.set(opt); + return self; + }; // Boilerplate for subclassing Promise. + + + Worker.prototype = Object.create(Promise.prototype); + Worker.prototype.constructor = Worker; // Converts/casts promises into Workers. + + Worker.convert = function convert(promise, inherit) { + // Uses prototypal inheritance to receive changes made to ancestors' properties. + promise.__proto__ = inherit || Worker.prototype; + return promise; + }; + + Worker.template = { + prop: { + src: null, + container: null, + overlay: null, + canvas: null, + img: null, + pdf: null, + pageSize: null, + callback: function callback() {} + }, + progress: { + val: 0, + state: null, + n: 0, + stack: [] + }, + opt: { + filename: "file.pdf", + margin: [0, 0, 0, 0], + enableLinks: true, + x: 0, + y: 0, + html2canvas: {}, + jsPDF: {}, + backgroundColor: "transparent" + } + }; + /* ----- FROM / TO ----- */ + + Worker.prototype.from = function from(src, type) { + function getType(src) { + switch (objType(src)) { + case "string": + return "string"; + + case "element": + return src.nodeName.toLowerCase === "canvas" ? "canvas" : "element"; + + default: + return "unknown"; + } + } + + return this.then(function from_main() { + type = type || getType(src); + + switch (type) { + case "string": + return this.set({ + src: createElement("div", { + innerHTML: src + }) + }); + + case "element": + return this.set({ + src: src + }); + + case "canvas": + return this.set({ + canvas: src + }); + + case "img": + return this.set({ + img: src + }); + + default: + return this.error("Unknown source type."); + } + }); + }; + + Worker.prototype.to = function to(target) { + // Route the 'to' request to the appropriate method. + switch (target) { + case "container": + return this.toContainer(); + + case "canvas": + return this.toCanvas(); + + case "img": + return this.toImg(); + + case "pdf": + return this.toPdf(); + + default: + return this.error("Invalid target."); + } + }; + + Worker.prototype.toContainer = function toContainer() { + // Set up function prerequisites. + var prereqs = [function checkSrc() { + return this.prop.src || this.error("Cannot duplicate - no source HTML."); + }, function checkPageSize() { + return this.prop.pageSize || this.setPageSize(); + }]; + return this.thenList(prereqs).then(function toContainer_main() { + // Define the CSS styles for the container and its overlay parent. + var overlayCSS = { + position: "fixed", + overflow: "hidden", + zIndex: 1000, + left: "-100000px", + right: 0, + bottom: 0, + top: 0 + }; + var containerCSS = { + position: "relative", + display: "inline-block", + width: Math.max(this.prop.src.clientWidth, this.prop.src.scrollWidth, this.prop.src.offsetWidth) + "px", + left: 0, + right: 0, + top: 0, + margin: "auto", + backgroundColor: this.opt.backgroundColor + }; // Set the overlay to hidden (could be changed in the future to provide a print preview). + + var source = cloneNode(this.prop.src, this.opt.html2canvas.javascriptEnabled); + + if (source.tagName === "BODY") { + containerCSS.height = Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight) + "px"; + } + + this.prop.overlay = createElement("div", { + className: "html2pdf__overlay", + style: overlayCSS + }); + this.prop.container = createElement("div", { + className: "html2pdf__container", + style: containerCSS + }); + this.prop.container.appendChild(source); + this.prop.container.firstChild.appendChild(createElement("div", { + style: { + clear: "both", + border: "0 none transparent", + margin: 0, + padding: 0, + height: 0 + } + })); + this.prop.container.style["float"] = "none"; + this.prop.overlay.appendChild(this.prop.container); + document.body.appendChild(this.prop.overlay); + this.prop.container.firstChild.style.position = "relative"; + this.prop.container.height = Math.max(this.prop.container.firstChild.clientHeight, this.prop.container.firstChild.scrollHeight, this.prop.container.firstChild.offsetHeight) + "px"; + }); + }; + + Worker.prototype.toCanvas = function toCanvas() { + // Set up function prerequisites. + var prereqs = [function checkContainer() { + return document.body.contains(this.prop.container) || this.toContainer(); + }]; // Fulfill prereqs then create the canvas. + + return this.thenList(prereqs).then(function toCanvas_main() { + // Handle old-fashioned 'onrendered' argument. + var options = Object.assign({}, this.opt.html2canvas); + delete options.onrendered; + + if (!this.isHtml2CanvasLoaded()) { + return; + } + + return html2canvas(this.prop.container, options); + }).then(function toCanvas_post(canvas) { + // Handle old-fashioned 'onrendered' argument. + var onRendered = this.opt.html2canvas.onrendered || function () {}; + + onRendered(canvas); + this.prop.canvas = canvas; + document.body.removeChild(this.prop.overlay); + }); + }; + + Worker.prototype.toContext2d = function toContext2d() { + // Set up function prerequisites. + var prereqs = [function checkContainer() { + return document.body.contains(this.prop.container) || this.toContainer(); + }]; // Fulfill prereqs then create the canvas. + + return this.thenList(prereqs).then(function toContext2d_main() { + // Handle old-fashioned 'onrendered' argument. + var pdf = this.opt.jsPDF; + var options = Object.assign({ + async: true, + allowTaint: true, + backgroundColor: "#ffffff", + imageTimeout: 15000, + logging: true, + proxy: null, + removeContainer: true, + foreignObjectRendering: false, + useCORS: false + }, this.opt.html2canvas); + delete options.onrendered; + pdf.context2d.autoPaging = true; + pdf.context2d.posX = this.opt.x; + pdf.context2d.posY = this.opt.y; + options.windowHeight = options.windowHeight || 0; + options.windowHeight = options.windowHeight == 0 ? Math.max(this.prop.container.clientHeight, this.prop.container.scrollHeight, this.prop.container.offsetHeight) : options.windowHeight; + + if (!this.isHtml2CanvasLoaded()) { + return; + } + + return html2canvas(this.prop.container, options); + }).then(function toContext2d_post(canvas) { + // Handle old-fashioned 'onrendered' argument. + var onRendered = this.opt.html2canvas.onrendered || function () {}; + + onRendered(canvas); + this.prop.canvas = canvas; + document.body.removeChild(this.prop.overlay); + }); + }; + + Worker.prototype.toImg = function toImg() { + // Set up function prerequisites. + var prereqs = [function checkCanvas() { + return this.prop.canvas || this.toCanvas(); + }]; // Fulfill prereqs then create the image. + + return this.thenList(prereqs).then(function toImg_main() { + var imgData = this.prop.canvas.toDataURL("image/" + this.opt.image.type, this.opt.image.quality); + this.prop.img = document.createElement("img"); + this.prop.img.src = imgData; + }); + }; + + Worker.prototype.toPdf = function toPdf() { + // Set up function prerequisites. + var prereqs = [function checkContext2d() { + return this.toContext2d(); + } //function checkCanvas() { return this.prop.canvas || this.toCanvas(); } + ]; // Fulfill prereqs then create the image. + + return this.thenList(prereqs).then(function toPdf_main() { + // Create local copies of frequently used properties. + this.prop.pdf = this.prop.pdf || this.opt.jsPDF; + }); + }; + /* ----- OUTPUT / SAVE ----- */ + + + Worker.prototype.output = function output(type, options, src) { + // Redirect requests to the correct function (outputPdf / outputImg). + src = src || "pdf"; + + if (src.toLowerCase() === "img" || src.toLowerCase() === "image") { + return this.outputImg(type, options); + } else { + return this.outputPdf(type, options); + } + }; + + Worker.prototype.outputPdf = function outputPdf(type, options) { + // Set up function prerequisites. + var prereqs = [function checkPdf() { + return this.prop.pdf || this.toPdf(); + }]; // Fulfill prereqs then perform the appropriate output. + + return this.thenList(prereqs).then(function outputPdf_main() { + /* Currently implemented output types: + * https://rawgit.com/MrRio/jsPDF/master/docs/jspdf.js.html#line992 + * save(options), arraybuffer, blob, bloburi/bloburl, + * datauristring/dataurlstring, dataurlnewwindow, datauri/dataurl + */ + return this.prop.pdf.output(type, options); + }); + }; + + Worker.prototype.outputImg = function outputImg(type) { + // Set up function prerequisites. + var prereqs = [function checkImg() { + return this.prop.img || this.toImg(); + }]; // Fulfill prereqs then perform the appropriate output. + + return this.thenList(prereqs).then(function outputImg_main() { + switch (type) { + case undefined: + case "img": + return this.prop.img; + + case "datauristring": + case "dataurlstring": + return this.prop.img.src; + + case "datauri": + case "dataurl": + return document.location.href = this.prop.img.src; + + default: + throw 'Image output type "' + type + '" is not supported.'; + } + }); + }; + + Worker.prototype.isHtml2CanvasLoaded = function () { + var result = typeof global.html2canvas !== "undefined"; + + if (!result) { + throw new Error("html2canvas not loaded."); + } + + return result; + }; + + Worker.prototype.save = function save(filename) { + // Set up function prerequisites. + var prereqs = [function checkPdf() { + return this.prop.pdf || this.toPdf(); + }]; + + if (!this.isHtml2CanvasLoaded()) { + return; + } // Fulfill prereqs, update the filename (if provided), and save the PDF. + + + return this.thenList(prereqs).set(filename ? { + filename: filename + } : null).then(function save_main() { + this.prop.pdf.save(this.opt.filename); + }); + }; + + Worker.prototype.doCallback = function doCallback() { + // Set up function prerequisites. + var prereqs = [function checkPdf() { + return this.prop.pdf || this.toPdf(); + }]; + + if (!this.isHtml2CanvasLoaded()) { + return; + } // Fulfill prereqs, update the filename (if provided), and save the PDF. + + + return this.thenList(prereqs).then(function doCallback_main() { + this.prop.callback(this.prop.pdf); + }); + }; + /* ----- SET / GET ----- */ + + + Worker.prototype.set = function set(opt) { + // TODO: Implement ordered pairs? + // Silently ignore invalid or empty input. + if (objType(opt) !== "object") { + return this; + } // Build an array of setter functions to queue. + + + var fns = Object.keys(opt || {}).map(function (key) { + if (key in Worker.template.prop) { + // Set pre-defined properties. + return function set_prop() { + this.prop[key] = opt[key]; + }; + } else { + switch (key) { + case "margin": + return this.setMargin.bind(this, opt.margin); + + case "jsPDF": + return function set_jsPDF() { + this.opt.jsPDF = opt.jsPDF; + return this.setPageSize(); + }; + + case "pageSize": + return this.setPageSize.bind(this, opt.pageSize); + + default: + // Set any other properties in opt. + return function set_opt() { + this.opt[key] = opt[key]; + }; + } + } + }, this); // Set properties within the promise chain. + + return this.then(function set_main() { + return this.thenList(fns); + }); + }; + + Worker.prototype.get = function get(key, cbk) { + return this.then(function get_main() { + // Fetch the requested property, either as a predefined prop or in opt. + var val = key in Worker.template.prop ? this.prop[key] : this.opt[key]; + return cbk ? cbk(val) : val; + }); + }; + + Worker.prototype.setMargin = function setMargin(margin) { + return this.then(function setMargin_main() { + // Parse the margin property. + switch (objType(margin)) { + case "number": + margin = [margin, margin, margin, margin]; + // eslint-disable-next-line no-fallthrough + + case "array": + if (margin.length === 2) { + margin = [margin[0], margin[1], margin[0], margin[1]]; + } + + if (margin.length === 4) { + break; + } + + // eslint-disable-next-line no-fallthrough + + default: + return this.error("Invalid margin array."); + } // Set the margin property, then update pageSize. + + + this.opt.margin = margin; + }).then(this.setPageSize); + }; + + Worker.prototype.setPageSize = function setPageSize(pageSize) { + function toPx(val, k) { + return Math.floor(val * k / 72 * 96); + } + + return this.then(function setPageSize_main() { + // Retrieve page-size based on jsPDF settings, if not explicitly provided. + pageSize = pageSize || jsPDF.getPageSize(this.opt.jsPDF); // Add 'inner' field if not present. + + if (!pageSize.hasOwnProperty("inner")) { + pageSize.inner = { + width: pageSize.width - this.opt.margin[1] - this.opt.margin[3], + height: pageSize.height - this.opt.margin[0] - this.opt.margin[2] + }; + pageSize.inner.px = { + width: toPx(pageSize.inner.width, pageSize.k), + height: toPx(pageSize.inner.height, pageSize.k) + }; + pageSize.inner.ratio = pageSize.inner.height / pageSize.inner.width; + } // Attach pageSize to this. + + + this.prop.pageSize = pageSize; + }); + }; + + Worker.prototype.setProgress = function setProgress(val, state, n, stack) { + // Immediately update all progress values. + if (val != null) { this.progress.val = val; } + if (state != null) { this.progress.state = state; } + if (n != null) { this.progress.n = n; } + if (stack != null) { this.progress.stack = stack; } + this.progress.ratio = this.progress.val / this.progress.state; // Return this for command chaining. + + return this; + }; + + Worker.prototype.updateProgress = function updateProgress(val, state, n, stack) { + // Immediately update all progress values, using setProgress. + return this.setProgress(val ? this.progress.val + val : null, state ? state : null, n ? this.progress.n + n : null, stack ? this.progress.stack.concat(stack) : null); + }; + /* ----- PROMISE MAPPING ----- */ + + + Worker.prototype.then = function then(onFulfilled, onRejected) { + // Wrap `this` for encapsulation. + var self = this; + return this.thenCore(onFulfilled, onRejected, function then_main(onFulfilled, onRejected) { + // Update progress while queuing, calling, and resolving `then`. + self.updateProgress(null, null, 1, [onFulfilled]); + return Promise.prototype.then.call(this, function then_pre(val) { + self.updateProgress(null, onFulfilled); + return val; + }).then(onFulfilled, onRejected).then(function then_post(val) { + self.updateProgress(1); + return val; + }); + }); + }; + + Worker.prototype.thenCore = function thenCore(onFulfilled, onRejected, thenBase) { + // Handle optional thenBase parameter. + thenBase = thenBase || Promise.prototype.then; // Wrap `this` for encapsulation and bind it to the promise handlers. + + var self = this; + + if (onFulfilled) { + onFulfilled = onFulfilled.bind(self); + } + + if (onRejected) { + onRejected = onRejected.bind(self); + } // Cast self into a Promise to avoid polyfills recursively defining `then`. + + + var isNative = Promise.toString().indexOf("[native code]") !== -1 && Promise.name === "Promise"; + var selfPromise = isNative ? self : Worker.convert(Object.assign({}, self), Promise.prototype); // Return the promise, after casting it into a Worker and preserving props. + + var returnVal = thenBase.call(selfPromise, onFulfilled, onRejected); + return Worker.convert(returnVal, self.__proto__); + }; + + Worker.prototype.thenExternal = function thenExternal(onFulfilled, onRejected) { + // Call `then` and return a standard promise (exits the Worker chain). + return Promise.prototype.then.call(this, onFulfilled, onRejected); + }; + + Worker.prototype.thenList = function thenList(fns) { + // Queue a series of promise 'factories' into the promise chain. + var self = this; + fns.forEach(function thenList_forEach(fn) { + self = self.thenCore(fn); + }); + return self; + }; + + Worker.prototype["catch"] = function (onRejected) { + // Bind `this` to the promise handler, call `catch`, and return a Worker. + if (onRejected) { + onRejected = onRejected.bind(this); + } + + var returnVal = Promise.prototype["catch"].call(this, onRejected); + return Worker.convert(returnVal, this); + }; + + Worker.prototype.catchExternal = function catchExternal(onRejected) { + // Call `catch` and return a standard promise (exits the Worker chain). + return Promise.prototype["catch"].call(this, onRejected); + }; + + Worker.prototype.error = function error(msg) { + // Throw the error in the Promise chain. + return this.then(function error_main() { + throw new Error(msg); + }); + }; + /* ----- ALIASES ----- */ + + + Worker.prototype.using = Worker.prototype.set; + Worker.prototype.saveAs = Worker.prototype.save; + Worker.prototype["export"] = Worker.prototype.output; + Worker.prototype.run = Worker.prototype.then; // Get dimensions of a PDF page, as determined by jsPDF. + + jsPDF.getPageSize = function (orientation, unit, format) { + // Decode options object + if (_typeof(orientation) === "object") { + var options = orientation; + orientation = options.orientation; + unit = options.unit || unit; + format = options.format || format; + } // Default options + + + unit = unit || "mm"; + format = format || "a4"; + orientation = ("" + (orientation || "P")).toLowerCase(); + var format_as_string = ("" + format).toLowerCase(); // Size in pt of various paper formats + + var pageFormats = { + a0: [2383.94, 3370.39], + a1: [1683.78, 2383.94], + a2: [1190.55, 1683.78], + a3: [841.89, 1190.55], + a4: [595.28, 841.89], + a5: [419.53, 595.28], + a6: [297.64, 419.53], + a7: [209.76, 297.64], + a8: [147.4, 209.76], + a9: [104.88, 147.4], + a10: [73.7, 104.88], + b0: [2834.65, 4008.19], + b1: [2004.09, 2834.65], + b2: [1417.32, 2004.09], + b3: [1000.63, 1417.32], + b4: [708.66, 1000.63], + b5: [498.9, 708.66], + b6: [354.33, 498.9], + b7: [249.45, 354.33], + b8: [175.75, 249.45], + b9: [124.72, 175.75], + b10: [87.87, 124.72], + c0: [2599.37, 3676.54], + c1: [1836.85, 2599.37], + c2: [1298.27, 1836.85], + c3: [918.43, 1298.27], + c4: [649.13, 918.43], + c5: [459.21, 649.13], + c6: [323.15, 459.21], + c7: [229.61, 323.15], + c8: [161.57, 229.61], + c9: [113.39, 161.57], + c10: [79.37, 113.39], + dl: [311.81, 623.62], + letter: [612, 792], + "government-letter": [576, 756], + legal: [612, 1008], + "junior-legal": [576, 360], + ledger: [1224, 792], + tabloid: [792, 1224], + "credit-card": [153, 243] + }; + var k; // Unit conversion + + switch (unit) { + case "pt": + k = 1; + break; + + case "mm": + k = 72 / 25.4; + break; + + case "cm": + k = 72 / 2.54; + break; + + case "in": + k = 72; + break; + + case "px": + k = 72 / 96; + break; + + case "pc": + k = 12; + break; + + case "em": + k = 12; + break; + + case "ex": + k = 6; + break; + + default: + throw "Invalid unit: " + unit; + } + + var pageHeight = 0; + var pageWidth = 0; // Dimensions are stored as user units and converted to points on output + + if (pageFormats.hasOwnProperty(format_as_string)) { + pageHeight = pageFormats[format_as_string][1] / k; + pageWidth = pageFormats[format_as_string][0] / k; + } else { + try { + pageHeight = format[1]; + pageWidth = format[0]; + } catch (err) { + throw new Error("Invalid format: " + format); + } + } + + var tmp; // Handle page orientation + + if (orientation === "p" || orientation === "portrait") { + orientation = "p"; + + if (pageWidth > pageHeight) { + tmp = pageWidth; + pageWidth = pageHeight; + pageHeight = tmp; + } + } else if (orientation === "l" || orientation === "landscape") { + orientation = "l"; + + if (pageHeight > pageWidth) { + tmp = pageWidth; + pageWidth = pageHeight; + pageHeight = tmp; + } + } else { + throw "Invalid orientation: " + orientation; + } // Return information (k is the unit conversion ratio from pts) + + + var info = { + width: pageWidth, + height: pageHeight, + unit: unit, + k: k, + orientation: orientation + }; + return info; + }; + /** + * Generate a PDF from an HTML element or string using. + * + * @name html + * @function + * @param {HTMLElement|string} source The source HTMLElement or a string containing HTML. + * @param {Object} [options] Collection of settings + * @param {string} [options.callback] The mandatory callback-function gets as first parameter the current jsPDF instance + * + * @example + * var doc = new jsPDF(); + * + * doc.html(document.body, { + * callback: function (doc) { + * doc.save(); + * } + * }); + */ + + + jsPDFAPI.html = function (src, options) { + + options = options || {}; + + options.callback = options.callback || function () {}; + + options.html2canvas = options.html2canvas || {}; + options.html2canvas.canvas = options.html2canvas.canvas || this.canvas; + options.jsPDF = options.jsPDF || this; // Create a new worker with the given options. + + var worker = new Worker(options); + + if (!options.worker) { + // If worker is not set to true, perform the traditional 'simple' operation. + return worker.from(src).doCallback(); + } else { + // Otherwise, return the worker for new Promise-based operation. + return worker; + } + }; +})(jsPDF.API, typeof window !== "undefined" && window || typeof global !== "undefined" && global); + +/*global jsPDF */ + +/** + * @license + * ==================================================================== + * Copyright (c) 2013 Youssef Beddad, youssef.beddad@gmail.com + * + * + * ==================================================================== + */ + +/** + * jsPDF JavaScript plugin + * + * @name javascript + * @module + */ +(function (jsPDFAPI) { + + var jsNamesObj, jsJsObj, text; + /** + * @name addJS + * @function + * @param {string} javascript The javascript to be embedded into the PDF-file. + * @returns {jsPDF} + */ + + jsPDFAPI.addJS = function (javascript) { + text = javascript; + this.internal.events.subscribe("postPutResources", function () { + jsNamesObj = this.internal.newObject(); + this.internal.out("<<"); + this.internal.out("/Names [(EmbeddedJS) " + (jsNamesObj + 1) + " 0 R]"); + this.internal.out(">>"); + this.internal.out("endobj"); + jsJsObj = this.internal.newObject(); + this.internal.out("<<"); + this.internal.out("/S /JavaScript"); + this.internal.out("/JS (" + text + ")"); + this.internal.out(">>"); + this.internal.out("endobj"); + }); + this.internal.events.subscribe("putCatalog", function () { + if (jsNamesObj !== undefined && jsJsObj !== undefined) { + this.internal.out("/Names <>"); + } + }); + return this; + }; +})(jsPDF.API); + +/* global jsPDF */ + +/** + * @license + * Copyright (c) 2014 Steven Spungin (TwelveTone LLC) steven@twelvetone.tv + * + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ + +/** + * jsPDF Outline PlugIn + * + * Generates a PDF Outline + * @name outline + * @module + */ +(function (jsPDFAPI) { + + var namesOid; //var destsGoto = []; + + jsPDFAPI.events.push(["postPutResources", function () { + var pdf = this; + var rx = /^(\d+) 0 obj$/; // Write action goto objects for each page + // this.outline.destsGoto = []; + // for (var i = 0; i < totalPages; i++) { + // var id = pdf.internal.newObject(); + // this.outline.destsGoto.push(id); + // pdf.internal.write("<> endobj"); + // } + // + // for (var i = 0; i < dests.length; i++) { + // pdf.internal.write("(page_" + (i + 1) + ")" + dests[i] + " 0 + // R"); + // } + // + + if (this.outline.root.children.length > 0) { + var lines = pdf.outline.render().split(/\r\n/); + + for (var i = 0; i < lines.length; i++) { + var line = lines[i]; + var m = rx.exec(line); + + if (m != null) { + var oid = m[1]; + pdf.internal.newObjectDeferredBegin(oid, false); + } + + pdf.internal.write(line); + } + } // This code will write named destination for each page reference + // (page_1, etc) + + + if (this.outline.createNamedDestinations) { + var totalPages = this.internal.pages.length; // WARNING: this assumes jsPDF starts on page 3 and pageIDs + // follow 5, 7, 9, etc + // Write destination objects for each page + + var dests = []; + + for (var i = 0; i < totalPages; i++) { + var id = pdf.internal.newObject(); + dests.push(id); + var info = pdf.internal.getPageInfo(i + 1); + pdf.internal.write("<< /D[" + info.objId + " 0 R /XYZ null null null]>> endobj"); + } // assign a name for each destination + + + var names2Oid = pdf.internal.newObject(); + pdf.internal.write("<< /Names [ "); + + for (var i = 0; i < dests.length; i++) { + pdf.internal.write("(page_" + (i + 1) + ")" + dests[i] + " 0 R"); + } + + pdf.internal.write(" ] >>", "endobj"); // var kids = pdf.internal.newObject(); + // pdf.internal.write('<< /Kids [ ' + names2Oid + ' 0 R'); + // pdf.internal.write(' ] >>', 'endobj'); + + namesOid = pdf.internal.newObject(); + pdf.internal.write("<< /Dests " + names2Oid + " 0 R"); + pdf.internal.write(">>", "endobj"); + } + }]); + jsPDFAPI.events.push(["putCatalog", function () { + var pdf = this; + + if (pdf.outline.root.children.length > 0) { + pdf.internal.write("/Outlines", this.outline.makeRef(this.outline.root)); + + if (this.outline.createNamedDestinations) { + pdf.internal.write("/Names " + namesOid + " 0 R"); + } // Open with Bookmarks showing + // pdf.internal.write("/PageMode /UseOutlines"); + + } + }]); + jsPDFAPI.events.push(["initialized", function () { + var pdf = this; + pdf.outline = { + createNamedDestinations: false, + root: { + children: [] + } + }; + /** + * Options: pageNumber + */ + + pdf.outline.add = function (parent, title, options) { + var item = { + title: title, + options: options, + children: [] + }; + + if (parent == null) { + parent = this.root; + } + + parent.children.push(item); + return item; + }; + + pdf.outline.render = function () { + this.ctx = {}; + this.ctx.val = ""; + this.ctx.pdf = pdf; + this.genIds_r(this.root); + this.renderRoot(this.root); + this.renderItems(this.root); + return this.ctx.val; + }; + + pdf.outline.genIds_r = function (node) { + node.id = pdf.internal.newObjectDeferred(); + + for (var i = 0; i < node.children.length; i++) { + this.genIds_r(node.children[i]); + } + }; + + pdf.outline.renderRoot = function (node) { + this.objStart(node); + this.line("/Type /Outlines"); + + if (node.children.length > 0) { + this.line("/First " + this.makeRef(node.children[0])); + this.line("/Last " + this.makeRef(node.children[node.children.length - 1])); + } + + this.line("/Count " + this.count_r({ + count: 0 + }, node)); + this.objEnd(); + }; + + pdf.outline.renderItems = function (node) { + var getVerticalCoordinateString = this.ctx.pdf.internal.getVerticalCoordinateString; + + for (var i = 0; i < node.children.length; i++) { + var item = node.children[i]; + this.objStart(item); + this.line("/Title " + this.makeString(item.title)); + this.line("/Parent " + this.makeRef(node)); + + if (i > 0) { + this.line("/Prev " + this.makeRef(node.children[i - 1])); + } + + if (i < node.children.length - 1) { + this.line("/Next " + this.makeRef(node.children[i + 1])); + } + + if (item.children.length > 0) { + this.line("/First " + this.makeRef(item.children[0])); + this.line("/Last " + this.makeRef(item.children[item.children.length - 1])); + } + + var count = this.count = this.count_r({ + count: 0 + }, item); + + if (count > 0) { + this.line("/Count " + count); + } + + if (item.options) { + if (item.options.pageNumber) { + // Explicit Destination + //WARNING this assumes page ids are 3,5,7, etc. + var info = pdf.internal.getPageInfo(item.options.pageNumber); + this.line("/Dest " + "[" + info.objId + " 0 R /XYZ 0 " + getVerticalCoordinateString(0) + " 0]"); // this line does not work on all clients (pageNumber instead of page ref) + //this.line('/Dest ' + '[' + (item.options.pageNumber - 1) + ' /XYZ 0 ' + this.ctx.pdf.internal.pageSize.getHeight() + ' 0]'); + // Named Destination + // this.line('/Dest (page_' + (item.options.pageNumber) + ')'); + // Action Destination + // var id = pdf.internal.newObject(); + // pdf.internal.write('<> endobj'); + // this.line('/A ' + id + ' 0 R' ); + } + } + + this.objEnd(); + } + + for (var z = 0; z < node.children.length; z++) { + this.renderItems(node.children[z]); + } + }; + + pdf.outline.line = function (text) { + this.ctx.val += text + "\r\n"; + }; + + pdf.outline.makeRef = function (node) { + return node.id + " 0 R"; + }; + + pdf.outline.makeString = function (val) { + return "(" + pdf.internal.pdfEscape(val) + ")"; + }; + + pdf.outline.objStart = function (node) { + this.ctx.val += "\r\n" + node.id + " 0 obj" + "\r\n<<\r\n"; + }; + + pdf.outline.objEnd = function () { + this.ctx.val += ">> \r\n" + "endobj" + "\r\n"; + }; + + pdf.outline.count_r = function (ctx, node) { + for (var i = 0; i < node.children.length; i++) { + ctx.count++; + this.count_r(ctx, node.children[i]); + } + + return ctx.count; + }; + }]); + return this; +})(jsPDF.API); + +/* global jsPDF */ + +/** + * @license + * + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ + +/** + * jsPDF jpeg Support PlugIn + * + * @name jpeg_support + * @module + */ +(function (jsPDFAPI) { + /** + * 0xc0 (SOF) Huffman - Baseline DCT + * 0xc1 (SOF) Huffman - Extended sequential DCT + * 0xc2 Progressive DCT (SOF2) + * 0xc3 Spatial (sequential) lossless (SOF3) + * 0xc4 Differential sequential DCT (SOF5) + * 0xc5 Differential progressive DCT (SOF6) + * 0xc6 Differential spatial (SOF7) + * 0xc7 + */ + + var markers = [0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7]; //takes a string imgData containing the raw bytes of + //a jpeg image and returns [width, height] + //Algorithm from: http://www.64lines.com/jpeg-width-height + + var getJpegInfo = function getJpegInfo(imgData) { + var width, height, numcomponents; + var blockLength = imgData.charCodeAt(4) * 256 + imgData.charCodeAt(5); + var len = imgData.length; + var result = { + width: 0, + height: 0, + numcomponents: 1 + }; + + for (var i = 4; i < len; i += 2) { + i += blockLength; + + if (markers.indexOf(imgData.charCodeAt(i + 1)) !== -1) { + height = imgData.charCodeAt(i + 5) * 256 + imgData.charCodeAt(i + 6); + width = imgData.charCodeAt(i + 7) * 256 + imgData.charCodeAt(i + 8); + numcomponents = imgData.charCodeAt(i + 9); + result = { + width: width, + height: height, + numcomponents: numcomponents + }; + break; + } else { + blockLength = imgData.charCodeAt(i + 2) * 256 + imgData.charCodeAt(i + 3); + } + } + + return result; + }; + /** + * @ignore + */ + + + jsPDFAPI.processJPEG = function (data, index, alias, compression, dataAsBinaryString, colorSpace) { + var filter = this.decode.DCT_DECODE, + bpc = 8, + dims, + result = null; + + if (typeof data === "string" || this.__addimage__.isArrayBuffer(data) || this.__addimage__.isArrayBufferView(data)) { + // if we already have a stored binary string rep use that + data = dataAsBinaryString || data; + data = this.__addimage__.isArrayBuffer(data) ? new Uint8Array(data) : data; + data = this.__addimage__.isArrayBufferView(data) ? this.__addimage__.arrayBufferToBinaryString(data) : data; + dims = getJpegInfo(data); + + switch (dims.numcomponents) { + case 1: + colorSpace = this.color_spaces.DEVICE_GRAY; + break; + + case 4: + colorSpace = this.color_spaces.DEVICE_CMYK; + break; + + case 3: + colorSpace = this.color_spaces.DEVICE_RGB; + break; + } + + result = { + data: data, + width: dims.width, + height: dims.height, + colorSpace: colorSpace, + bitsPerComponent: bpc, + filter: filter, + index: index, + alias: alias + }; + } + + return result; + }; +})(jsPDF.API); + +/* global jsPDF, Deflater, PNG */ + +/** + * @license + * + * Copyright (c) 2014 James Robb, https://github.com/jamesbrobb + * + * + * ==================================================================== + */ + +/** + * jsPDF PNG PlugIn + * @name png_support + * @module + */ +(function (jsPDFAPI, global) { + /* + * @see http://www.w3.org/TR/PNG-Chunks.html + * + Color Allowed Interpretation + Type Bit Depths + 0 1,2,4,8,16 Each pixel is a grayscale sample. + 2 8,16 Each pixel is an R,G,B triple. + 3 1,2,4,8 Each pixel is a palette index; + a PLTE chunk must appear. + 4 8,16 Each pixel is a grayscale sample, + followed by an alpha sample. + 6 8,16 Each pixel is an R,G,B triple, + followed by an alpha sample. + */ + + /* + * PNG filter method types + * + * @see http://www.w3.org/TR/PNG-Filters.html + * @see http://www.libpng.org/pub/png/book/chapter09.html + * + * This is what the value 'Predictor' in decode params relates to + * + * 15 is "optimal prediction", which means the prediction algorithm can change from line to line. + * In that case, you actually have to read the first byte off each line for the prediction algorthim (which should be 0-4, corresponding to PDF 10-14) and select the appropriate unprediction algorithm based on that byte. + * + 0 None + 1 Sub + 2 Up + 3 Average + 4 Paeth + */ + + var doesNotHavePngJS = function doesNotHavePngJS() { + return typeof global.PNG !== "function" || typeof global.FlateStream !== "function"; + }; + + var canCompress = function canCompress(value) { + return value !== jsPDFAPI.image_compression.NONE && hasCompressionJS(); + }; + + var hasCompressionJS = function hasCompressionJS() { + return typeof Deflater === "function"; + }; + + var compressBytes = function compressBytes(bytes, lineLength, colorsPerPixel, compression) { + var level = 5; + var filter_method = filterUp; + + switch (compression) { + case jsPDFAPI.image_compression.FAST: + level = 3; + filter_method = filterSub; + break; + + case jsPDFAPI.image_compression.MEDIUM: + level = 6; + filter_method = filterAverage; + break; + + case jsPDFAPI.image_compression.SLOW: + level = 9; + filter_method = filterPaeth; + break; + } + + bytes = applyPngFilterMethod(bytes, lineLength, colorsPerPixel, filter_method); + var header = new Uint8Array(createZlibHeader(level)); + var checksum = jsPDF.API.adler32cs.fromBuffer(bytes.buffer); + var deflate = new Deflater(level); + var a = deflate.append(bytes); + var cBytes = deflate.flush(); + var len = header.length + a.length + cBytes.length; + var cmpd = new Uint8Array(len + 4); + cmpd.set(header); + cmpd.set(a, header.length); + cmpd.set(cBytes, header.length + a.length); + cmpd[len++] = checksum >>> 24 & 0xff; + cmpd[len++] = checksum >>> 16 & 0xff; + cmpd[len++] = checksum >>> 8 & 0xff; + cmpd[len++] = checksum & 0xff; + return jsPDFAPI.__addimage__.arrayBufferToBinaryString(cmpd); + }; + + var createZlibHeader = function createZlibHeader(level) { + /* + * @see http://www.ietf.org/rfc/rfc1950.txt for zlib header + */ + var hdr = 30720; + var flevel = Math.min(3, (level - 1 & 0xff) >> 1); + hdr |= flevel << 6; + hdr |= 0; //FDICT + + hdr += 31 - hdr % 31; + return [120, hdr & 0xff & 0xff]; + }; + + var applyPngFilterMethod = function applyPngFilterMethod(bytes, lineLength, colorsPerPixel, filter_method) { + var lines = bytes.length / lineLength, + result = new Uint8Array(bytes.length + lines), + filter_methods = getFilterMethods(), + line, + prevLine, + offset; + + for (var i = 0; i < lines; i += 1) { + offset = i * lineLength; + line = bytes.subarray(offset, offset + lineLength); + + if (filter_method) { + result.set(filter_method(line, colorsPerPixel, prevLine), offset + i); + } else { + var len = filter_methods.length, + results = []; + + for (var j; j < len; j += 1) { + results[j] = filter_methods[j](line, colorsPerPixel, prevLine); + } + + var ind = getIndexOfSmallestSum(results.concat()); + result.set(results[ind], offset + i); + } + + prevLine = line; + } + + return result; + }; + + var filterNone = function filterNone(line) { + /*var result = new Uint8Array(line.length + 1); + result[0] = 0; + result.set(line, 1);*/ + var result = Array.apply([], line); + result.unshift(0); + return result; + }; + + var filterSub = function filterSub(line, colorsPerPixel) { + var result = [], + len = line.length, + left; + result[0] = 1; + + for (var i = 0; i < len; i += 1) { + left = line[i - colorsPerPixel] || 0; + result[i + 1] = line[i] - left + 0x0100 & 0xff; + } + + return result; + }; + + var filterUp = function filterUp(line, colorsPerPixel, prevLine) { + var result = [], + len = line.length, + up; + result[0] = 2; + + for (var i = 0; i < len; i += 1) { + up = prevLine && prevLine[i] || 0; + result[i + 1] = line[i] - up + 0x0100 & 0xff; + } + + return result; + }; + + var filterAverage = function filterAverage(line, colorsPerPixel, prevLine) { + var result = [], + len = line.length, + left, + up; + result[0] = 3; + + for (var i = 0; i < len; i += 1) { + left = line[i - colorsPerPixel] || 0; + up = prevLine && prevLine[i] || 0; + result[i + 1] = line[i] + 0x0100 - (left + up >>> 1) & 0xff; + } + + return result; + }; + + var filterPaeth = function filterPaeth(line, colorsPerPixel, prevLine) { + var result = [], + len = line.length, + left, + up, + upLeft, + paeth; + result[0] = 4; + + for (var i = 0; i < len; i += 1) { + left = line[i - colorsPerPixel] || 0; + up = prevLine && prevLine[i] || 0; + upLeft = prevLine && prevLine[i - colorsPerPixel] || 0; + paeth = paethPredictor(left, up, upLeft); + result[i + 1] = line[i] - paeth + 0x0100 & 0xff; + } + + return result; + }; + + var paethPredictor = function paethPredictor(left, up, upLeft) { + if (left === up && up === upLeft) { + return left; + } + + var pLeft = Math.abs(up - upLeft), + pUp = Math.abs(left - upLeft), + pUpLeft = Math.abs(left + up - upLeft - upLeft); + return pLeft <= pUp && pLeft <= pUpLeft ? left : pUp <= pUpLeft ? up : upLeft; + }; + + var getFilterMethods = function getFilterMethods() { + return [filterNone, filterSub, filterUp, filterAverage, filterPaeth]; + }; + + var getIndexOfSmallestSum = function getIndexOfSmallestSum(arrays) { + var sum = arrays.map(function (value) { + return value.reduce(function (pv, cv) { + return pv + Math.abs(cv); + }, 0); + }); + return sum.indexOf(Math.min.apply(null, sum)); + }; + + var getPredictorFromCompression = function getPredictorFromCompression(compression) { + var predictor; + + switch (compression) { + case jsPDFAPI.image_compression.FAST: + predictor = 11; + break; + + case jsPDFAPI.image_compression.MEDIUM: + predictor = 13; + break; + + case jsPDFAPI.image_compression.SLOW: + predictor = 14; + break; + + default: + predictor = 12; + break; + } + + return predictor; + }; + /** + * @name processPNG + * @function + * @ignore + */ + + + jsPDFAPI.processPNG = function (imageData, index, alias, compression) { + + var colorSpace, + filter = this.decode.FLATE_DECODE, + bitsPerComponent, + image, + decodeParameters = "", + trns, + colors, + pal, + smask, + pixels, + len, + alphaData, + imgData, + hasColors, + pixel, + i, + n; + if (this.__addimage__.isArrayBuffer(imageData)) { imageData = new Uint8Array(imageData); } + + if (this.__addimage__.isArrayBufferView(imageData)) { + if (doesNotHavePngJS()) { + throw new Error("PNG support requires png.js and zlib.js"); + } + + image = new PNG(imageData); + imageData = image.imgData; + bitsPerComponent = image.bits; + colorSpace = image.colorSpace; + colors = image.colors; + /* + * colorType 6 - Each pixel is an R,G,B triple, followed by an alpha sample. + * + * colorType 4 - Each pixel is a grayscale sample, followed by an alpha sample. + * + * Extract alpha to create two separate images, using the alpha as a sMask + */ + + if ([4, 6].indexOf(image.colorType) !== -1) { + /* + * processes 8 bit RGBA and grayscale + alpha images + */ + if (image.bits === 8) { + pixels = image.pixelBitlength == 32 ? new Uint32Array(image.decodePixels().buffer) : image.pixelBitlength == 16 ? new Uint16Array(image.decodePixels().buffer) : new Uint8Array(image.decodePixels().buffer); + len = pixels.length; + imgData = new Uint8Array(len * image.colors); + alphaData = new Uint8Array(len); + var pDiff = image.pixelBitlength - image.bits; + i = 0; + n = 0; + var pbl; + + for (; i < len; i++) { + pixel = pixels[i]; + pbl = 0; + + while (pbl < pDiff) { + imgData[n++] = pixel >>> pbl & 0xff; + pbl = pbl + image.bits; + } + + alphaData[i] = pixel >>> pbl & 0xff; + } + } + /* + * processes 16 bit RGBA and grayscale + alpha images + */ + + + if (image.bits === 16) { + pixels = new Uint32Array(image.decodePixels().buffer); + len = pixels.length; + imgData = new Uint8Array(len * (32 / image.pixelBitlength) * image.colors); + alphaData = new Uint8Array(len * (32 / image.pixelBitlength)); + hasColors = image.colors > 1; + i = 0; + n = 0; + var a = 0; + + while (i < len) { + pixel = pixels[i++]; + imgData[n++] = pixel >>> 0 & 0xff; + + if (hasColors) { + imgData[n++] = pixel >>> 16 & 0xff; + pixel = pixels[i++]; + imgData[n++] = pixel >>> 0 & 0xff; + } + + alphaData[a++] = pixel >>> 16 & 0xff; + } + + bitsPerComponent = 8; + } + + if (canCompress(compression)) { + imageData = compressBytes(imgData, image.width * image.colors, image.colors, compression); + smask = compressBytes(alphaData, image.width, 1, compression); + } else { + imageData = imgData; + smask = alphaData; + filter = undefined; + } + } + /* + * Indexed png. Each pixel is a palette index. + */ + + + if (image.colorType === 3) { + colorSpace = this.color_spaces.INDEXED; + pal = image.palette; + + if (image.transparency.indexed) { + var trans = image.transparency.indexed; + var total = 0; + i = 0; + len = trans.length; + + for (; i < len; ++i) { + total += trans[i]; + } + + total = total / 255; + /* + * a single color is specified as 100% transparent (0), + * so we set trns to use a /Mask with that index + */ + + if (total === len - 1 && trans.indexOf(0) !== -1) { + trns = [trans.indexOf(0)]; + /* + * there's more than one colour within the palette that specifies + * a transparency value less than 255, so we unroll the pixels to create an image sMask + */ + } else if (total !== len) { + pixels = image.decodePixels(); + alphaData = new Uint8Array(pixels.length); + i = 0; + len = pixels.length; + + for (; i < len; i++) { + alphaData[i] = trans[pixels[i]]; + } + + smask = compressBytes(alphaData, image.width, 1); + } + } + } + + var predictor = getPredictorFromCompression(compression); + + if (filter === this.decode.FLATE_DECODE) { + decodeParameters = "/Predictor " + predictor + " "; + } + + decodeParameters += "/Colors " + colors + " /BitsPerComponent " + bitsPerComponent + " /Columns " + image.width; + + if (this.__addimage__.isArrayBuffer(imageData) || this.__addimage__.isArrayBufferView(imageData)) { + imageData = this.__addimage__.arrayBufferToBinaryString(imageData); + } + + if (smask && this.__addimage__.isArrayBuffer(smask) || this.__addimage__.isArrayBufferView(smask)) { + smask = this.__addimage__.arrayBufferToBinaryString(smask); + } + + return { + alias: alias, + data: imageData, + index: index, + filter: filter, + decodeParameters: decodeParameters, + transparency: trns, + palette: pal, + sMask: smask, + predictor: predictor, + width: image.width, + height: image.height, + bitsPerComponent: bitsPerComponent, + colorSpace: colorSpace + }; + } + }; +})(jsPDF.API, typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function("return this")()); // `self` is undefined in Firefox for Android content script context +// while `this` is nsIContentFrameMessageManager +// with an attribute `content` that corresponds to the window + +/* global jsPDF, GifReader, JPEGEncoder */ + +/** + * @license + * Copyright (c) 2017 Aras Abbasi + * + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ + +/** + * jsPDF Gif Support PlugIn + * + * @name gif_support + * @module + */ +(function (jsPDFAPI) { + + jsPDFAPI.processGIF89A = function (imageData, index, alias, compression) { + var reader = new GifReader(imageData); + var width = reader.width, + height = reader.height; + var qu = 100; + var pixels = []; + reader.decodeAndBlitFrameRGBA(0, pixels); + var rawImageData = { + data: pixels, + width: width, + height: height + }; + var encoder = new JPEGEncoder(qu); + var data = encoder.encode(rawImageData, qu); + return jsPDFAPI.processJPEG.call(this, data, index, alias, compression); + }; + + jsPDFAPI.processGIF87A = jsPDFAPI.processGIF89A; +})(jsPDF.API); + +/* global jsPDF, BmpDecoder, JPEGEncoder */ + +/** + * Copyright (c) 2018 Aras Abbasi + * + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ + +/** + * jsPDF bmp Support PlugIn + * @name bmp_support + * @module + */ +(function (jsPDFAPI) { + + jsPDFAPI.processBMP = function (imageData, index, alias, compression) { + var reader = new BmpDecoder(imageData, false); + var width = reader.width, + height = reader.height; + var qu = 100; + var pixels = reader.getData(); + var rawImageData = { + data: pixels, + width: width, + height: height + }; + var encoder = new JPEGEncoder(qu); + var data = encoder.encode(rawImageData, qu); + return jsPDFAPI.processJPEG.call(this, data, index, alias, compression); + }; +})(jsPDF.API); + +/* global jsPDF, JPEGEncoder, WebPDecoder */ + +/** + * @license + * Copyright (c) 2019 Aras Abbasi + * + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ + +/** + * jsPDF webp Support PlugIn + * + * @name webp_support + * @module + */ +(function (jsPDFAPI) { + + jsPDFAPI.processWEBP = function (imageData, index, alias, compression) { + var reader = new WebPDecoder(imageData, false); + var width = reader.width, + height = reader.height; + var qu = 100; + var pixels = reader.getData(); + var rawImageData = { + data: pixels, + width: width, + height: height + }; + var encoder = new JPEGEncoder(qu); + var data = encoder.encode(rawImageData, qu); + return jsPDFAPI.processJPEG.call(this, data, index, alias, compression); + }; +})(jsPDF.API); + +/* global jsPDF */ + +/** + * @license + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ + +/** + * jsPDF setLanguage Plugin + * + * @name setLanguage + * @module + */ +(function (jsPDFAPI) { + /** + * Add Language Tag to the generated PDF + * + * @name setLanguage + * @function + * @param {string} langCode The Language code as ISO-639-1 (e.g. 'en') or as country language code (e.g. 'en-GB'). + * @returns {jsPDF} + * @example + * var doc = new jsPDF() + * doc.text(10, 10, 'This is a test') + * doc.setLanguage("en-US") + * doc.save('english.pdf') + */ + + jsPDFAPI.setLanguage = function (langCode) { + + var langCodes = { + af: "Afrikaans", + sq: "Albanian", + ar: "Arabic (Standard)", + "ar-DZ": "Arabic (Algeria)", + "ar-BH": "Arabic (Bahrain)", + "ar-EG": "Arabic (Egypt)", + "ar-IQ": "Arabic (Iraq)", + "ar-JO": "Arabic (Jordan)", + "ar-KW": "Arabic (Kuwait)", + "ar-LB": "Arabic (Lebanon)", + "ar-LY": "Arabic (Libya)", + "ar-MA": "Arabic (Morocco)", + "ar-OM": "Arabic (Oman)", + "ar-QA": "Arabic (Qatar)", + "ar-SA": "Arabic (Saudi Arabia)", + "ar-SY": "Arabic (Syria)", + "ar-TN": "Arabic (Tunisia)", + "ar-AE": "Arabic (U.A.E.)", + "ar-YE": "Arabic (Yemen)", + an: "Aragonese", + hy: "Armenian", + as: "Assamese", + ast: "Asturian", + az: "Azerbaijani", + eu: "Basque", + be: "Belarusian", + bn: "Bengali", + bs: "Bosnian", + br: "Breton", + bg: "Bulgarian", + my: "Burmese", + ca: "Catalan", + ch: "Chamorro", + ce: "Chechen", + zh: "Chinese", + "zh-HK": "Chinese (Hong Kong)", + "zh-CN": "Chinese (PRC)", + "zh-SG": "Chinese (Singapore)", + "zh-TW": "Chinese (Taiwan)", + cv: "Chuvash", + co: "Corsican", + cr: "Cree", + hr: "Croatian", + cs: "Czech", + da: "Danish", + nl: "Dutch (Standard)", + "nl-BE": "Dutch (Belgian)", + en: "English", + "en-AU": "English (Australia)", + "en-BZ": "English (Belize)", + "en-CA": "English (Canada)", + "en-IE": "English (Ireland)", + "en-JM": "English (Jamaica)", + "en-NZ": "English (New Zealand)", + "en-PH": "English (Philippines)", + "en-ZA": "English (South Africa)", + "en-TT": "English (Trinidad & Tobago)", + "en-GB": "English (United Kingdom)", + "en-US": "English (United States)", + "en-ZW": "English (Zimbabwe)", + eo: "Esperanto", + et: "Estonian", + fo: "Faeroese", + fj: "Fijian", + fi: "Finnish", + fr: "French (Standard)", + "fr-BE": "French (Belgium)", + "fr-CA": "French (Canada)", + "fr-FR": "French (France)", + "fr-LU": "French (Luxembourg)", + "fr-MC": "French (Monaco)", + "fr-CH": "French (Switzerland)", + fy: "Frisian", + fur: "Friulian", + gd: "Gaelic (Scots)", + "gd-IE": "Gaelic (Irish)", + gl: "Galacian", + ka: "Georgian", + de: "German (Standard)", + "de-AT": "German (Austria)", + "de-DE": "German (Germany)", + "de-LI": "German (Liechtenstein)", + "de-LU": "German (Luxembourg)", + "de-CH": "German (Switzerland)", + el: "Greek", + gu: "Gujurati", + ht: "Haitian", + he: "Hebrew", + hi: "Hindi", + hu: "Hungarian", + is: "Icelandic", + id: "Indonesian", + iu: "Inuktitut", + ga: "Irish", + it: "Italian (Standard)", + "it-CH": "Italian (Switzerland)", + ja: "Japanese", + kn: "Kannada", + ks: "Kashmiri", + kk: "Kazakh", + km: "Khmer", + ky: "Kirghiz", + tlh: "Klingon", + ko: "Korean", + "ko-KP": "Korean (North Korea)", + "ko-KR": "Korean (South Korea)", + la: "Latin", + lv: "Latvian", + lt: "Lithuanian", + lb: "Luxembourgish", + mk: "FYRO Macedonian", + ms: "Malay", + ml: "Malayalam", + mt: "Maltese", + mi: "Maori", + mr: "Marathi", + mo: "Moldavian", + nv: "Navajo", + ng: "Ndonga", + ne: "Nepali", + no: "Norwegian", + nb: "Norwegian (Bokmal)", + nn: "Norwegian (Nynorsk)", + oc: "Occitan", + or: "Oriya", + om: "Oromo", + fa: "Persian", + "fa-IR": "Persian/Iran", + pl: "Polish", + pt: "Portuguese", + "pt-BR": "Portuguese (Brazil)", + pa: "Punjabi", + "pa-IN": "Punjabi (India)", + "pa-PK": "Punjabi (Pakistan)", + qu: "Quechua", + rm: "Rhaeto-Romanic", + ro: "Romanian", + "ro-MO": "Romanian (Moldavia)", + ru: "Russian", + "ru-MO": "Russian (Moldavia)", + sz: "Sami (Lappish)", + sg: "Sango", + sa: "Sanskrit", + sc: "Sardinian", + sd: "Sindhi", + si: "Singhalese", + sr: "Serbian", + sk: "Slovak", + sl: "Slovenian", + so: "Somani", + sb: "Sorbian", + es: "Spanish", + "es-AR": "Spanish (Argentina)", + "es-BO": "Spanish (Bolivia)", + "es-CL": "Spanish (Chile)", + "es-CO": "Spanish (Colombia)", + "es-CR": "Spanish (Costa Rica)", + "es-DO": "Spanish (Dominican Republic)", + "es-EC": "Spanish (Ecuador)", + "es-SV": "Spanish (El Salvador)", + "es-GT": "Spanish (Guatemala)", + "es-HN": "Spanish (Honduras)", + "es-MX": "Spanish (Mexico)", + "es-NI": "Spanish (Nicaragua)", + "es-PA": "Spanish (Panama)", + "es-PY": "Spanish (Paraguay)", + "es-PE": "Spanish (Peru)", + "es-PR": "Spanish (Puerto Rico)", + "es-ES": "Spanish (Spain)", + "es-UY": "Spanish (Uruguay)", + "es-VE": "Spanish (Venezuela)", + sx: "Sutu", + sw: "Swahili", + sv: "Swedish", + "sv-FI": "Swedish (Finland)", + "sv-SV": "Swedish (Sweden)", + ta: "Tamil", + tt: "Tatar", + te: "Teluga", + th: "Thai", + tig: "Tigre", + ts: "Tsonga", + tn: "Tswana", + tr: "Turkish", + tk: "Turkmen", + uk: "Ukrainian", + hsb: "Upper Sorbian", + ur: "Urdu", + ve: "Venda", + vi: "Vietnamese", + vo: "Volapuk", + wa: "Walloon", + cy: "Welsh", + xh: "Xhosa", + ji: "Yiddish", + zu: "Zulu" + }; + + if (this.internal.languageSettings === undefined) { + this.internal.languageSettings = {}; + this.internal.languageSettings.isSubscribed = false; + } + + if (langCodes[langCode] !== undefined) { + this.internal.languageSettings.languageCode = langCode; + + if (this.internal.languageSettings.isSubscribed === false) { + this.internal.events.subscribe("putCatalog", function () { + this.internal.write("/Lang (" + this.internal.languageSettings.languageCode + ")"); + }); + this.internal.languageSettings.isSubscribed = true; + } + } + + return this; + }; +})(jsPDF.API); + +/* global jsPDF */ + +/** @license + * MIT license. + * Copyright (c) 2012 Willow Systems Corporation, willow-systems.com + * 2014 Diego Casorran, https://github.com/diegocr + * + * + * ==================================================================== + */ + +/** + * jsPDF split_text_to_size plugin + * + * @name split_text_to_size + * @module + */ +(function (API) { + /** + * Returns an array of length matching length of the 'word' string, with each + * cell occupied by the width of the char in that position. + * + * @name getCharWidthsArray + * @function + * @param {string} text + * @param {Object} options + * @returns {Array} + */ + + var getCharWidthsArray = API.getCharWidthsArray = function (text, options) { + options = options || {}; + var activeFont = options.font || this.internal.getFont(); + var fontSize = options.fontSize || this.internal.getFontSize(); + var charSpace = options.charSpace || this.internal.getCharSpace(); + var widths = options.widths ? options.widths : activeFont.metadata.Unicode.widths; + var widthsFractionOf = widths.fof ? widths.fof : 1; + var kerning = options.kerning ? options.kerning : activeFont.metadata.Unicode.kerning; + var kerningFractionOf = kerning.fof ? kerning.fof : 1; + var doKerning = options.doKerning === false ? false : true; + var kerningValue = 0; + var i; + var length = text.length; + var char_code; + var prior_char_code = 0; //for kerning + + var default_char_width = widths[0] || widthsFractionOf; + var output = []; + + for (i = 0; i < length; i++) { + char_code = text.charCodeAt(i); + + if (typeof activeFont.metadata.widthOfString === "function") { + output.push((activeFont.metadata.widthOfGlyph(activeFont.metadata.characterToGlyph(char_code)) + charSpace * (1000 / fontSize) || 0) / 1000); + } else { + if (doKerning && _typeof(kerning[char_code]) === "object" && !isNaN(parseInt(kerning[char_code][prior_char_code], 10))) { + kerningValue = kerning[char_code][prior_char_code] / kerningFractionOf; + } else { + kerningValue = 0; + } + + output.push((widths[char_code] || default_char_width) / widthsFractionOf + kerningValue); + } + + prior_char_code = char_code; + } + + return output; + }; + /** + * Returns a widths of string in a given font, if the font size is set as 1 point. + * + * In other words, this is "proportional" value. For 1 unit of font size, the length + * of the string will be that much. + * + * Multiply by font size to get actual width in *points* + * Then divide by 72 to get inches or divide by (72/25.6) to get 'mm' etc. + * + * @name getStringUnitWidth + * @public + * @function + * @param {string} text + * @param {string} options + * @returns {number} result + */ + + + var getStringUnitWidth = API.getStringUnitWidth = function (text, options) { + options = options || {}; + var fontSize = options.fontSize || this.internal.getFontSize(); + var font = options.font || this.internal.getFont(); + var charSpace = options.charSpace || this.internal.getCharSpace(); + var result = 0; + + if (API.processArabic) { + text = API.processArabic(text); + } + + if (typeof font.metadata.widthOfString === "function") { + result = font.metadata.widthOfString(text, fontSize, charSpace) / fontSize; + } else { + result = getCharWidthsArray.apply(this, arguments).reduce(function (pv, cv) { + return pv + cv; + }, 0); + } + + return result; + }; + /** + returns array of lines + */ + + + var splitLongWord = function splitLongWord(word, widths_array, firstLineMaxLen, maxLen) { + var answer = []; // 1st, chop off the piece that can fit on the hanging line. + + var i = 0, + l = word.length, + workingLen = 0; + + while (i !== l && workingLen + widths_array[i] < firstLineMaxLen) { + workingLen += widths_array[i]; + i++; + } // this is first line. + + + answer.push(word.slice(0, i)); // 2nd. Split the rest into maxLen pieces. + + var startOfLine = i; + workingLen = 0; + + while (i !== l) { + if (workingLen + widths_array[i] > maxLen) { + answer.push(word.slice(startOfLine, i)); + workingLen = 0; + startOfLine = i; + } + + workingLen += widths_array[i]; + i++; + } + + if (startOfLine !== i) { + answer.push(word.slice(startOfLine, i)); + } + + return answer; + }; // Note, all sizing inputs for this function must be in "font measurement units" + // By default, for PDF, it's "point". + + + var splitParagraphIntoLines = function splitParagraphIntoLines(text, maxlen, options) { + // at this time works only on Western scripts, ones with space char + // separating the words. Feel free to expand. + if (!options) { + options = {}; + } + + var line = [], + lines = [line], + line_length = options.textIndent || 0, + separator_length = 0, + current_word_length = 0, + word, + widths_array, + words = text.split(" "), + spaceCharWidth = getCharWidthsArray.apply(this, [" ", options])[0], + i, + l, + tmp, + lineIndent; + + if (options.lineIndent === -1) { + lineIndent = words[0].length + 2; + } else { + lineIndent = options.lineIndent || 0; + } + + if (lineIndent) { + var pad = Array(lineIndent).join(" "), + wrds = []; + words.map(function (wrd) { + wrd = wrd.split(/\s*\n/); + + if (wrd.length > 1) { + wrds = wrds.concat(wrd.map(function (wrd, idx) { + return (idx && wrd.length ? "\n" : "") + wrd; + })); + } else { + wrds.push(wrd[0]); + } + }); + words = wrds; + lineIndent = getStringUnitWidth.apply(this, [pad, options]); + } + + for (i = 0, l = words.length; i < l; i++) { + var force = 0; + word = words[i]; + + if (lineIndent && word[0] == "\n") { + word = word.substr(1); + force = 1; + } + + widths_array = getCharWidthsArray.apply(this, [word, options]); + current_word_length = widths_array.reduce(function (pv, cv) { + return pv + cv; + }, 0); + + if (line_length + separator_length + current_word_length > maxlen || force) { + if (current_word_length > maxlen) { + // this happens when you have space-less long URLs for example. + // we just chop these to size. We do NOT insert hiphens + tmp = splitLongWord.apply(this, [word, widths_array, maxlen - (line_length + separator_length), maxlen]); // first line we add to existing line object + + line.push(tmp.shift()); // it's ok to have extra space indicator there + // last line we make into new line object + + line = [tmp.pop()]; // lines in the middle we apped to lines object as whole lines + + while (tmp.length) { + lines.push([tmp.shift()]); // single fragment occupies whole line + } + + current_word_length = widths_array.slice(word.length - (line[0] ? line[0].length : 0)).reduce(function (pv, cv) { + return pv + cv; + }, 0); + } else { + // just put it on a new line + line = [word]; + } // now we attach new line to lines + + + lines.push(line); + line_length = current_word_length + lineIndent; + separator_length = spaceCharWidth; + } else { + line.push(word); + line_length += separator_length + current_word_length; + separator_length = spaceCharWidth; + } + } + + var postProcess; + + if (lineIndent) { + postProcess = function postProcess(ln, idx) { + return (idx ? pad : "") + ln.join(" "); + }; + } else { + postProcess = function postProcess(ln) { + return ln.join(" "); + }; + } + + return lines.map(postProcess); + }; + /** + * Splits a given string into an array of strings. Uses 'size' value + * (in measurement units declared as default for the jsPDF instance) + * and the font's "widths" and "Kerning" tables, where available, to + * determine display length of a given string for a given font. + * + * We use character's 100% of unit size (height) as width when Width + * table or other default width is not available. + * + * @name splitTextToSize + * @public + * @function + * @param {string} text Unencoded, regular JavaScript (Unicode, UTF-16 / UCS-2) string. + * @param {number} size Nominal number, measured in units default to this instance of jsPDF. + * @param {Object} options Optional flags needed for chopper to do the right thing. + * @returns {Array} array Array with strings chopped to size. + */ + + + API.splitTextToSize = function (text, maxlen, options) { + + options = options || {}; + + var fsize = options.fontSize || this.internal.getFontSize(), + newOptions = function (options) { + var widths = { + 0: 1 + }, + kerning = {}; + + if (!options.widths || !options.kerning) { + var f = this.internal.getFont(options.fontName, options.fontStyle), + encoding = "Unicode"; // NOT UTF8, NOT UTF16BE/LE, NOT UCS2BE/LE + // Actual JavaScript-native String's 16bit char codes used. + // no multi-byte logic here + + if (f.metadata[encoding]) { + return { + widths: f.metadata[encoding].widths || widths, + kerning: f.metadata[encoding].kerning || kerning + }; + } else { + return { + font: f.metadata, + fontSize: this.internal.getFontSize(), + charSpace: this.internal.getCharSpace() + }; + } + } else { + return { + widths: options.widths, + kerning: options.kerning + }; + } + }.call(this, options); // first we split on end-of-line chars + + + var paragraphs; + + if (Array.isArray(text)) { + paragraphs = text; + } else { + paragraphs = text.split(/\r?\n/); + } // now we convert size (max length of line) into "font size units" + // at present time, the "font size unit" is always 'point' + // 'proportional' means, "in proportion to font size" + + + var fontUnit_maxLen = 1.0 * this.internal.scaleFactor * maxlen / fsize; // at this time, fsize is always in "points" regardless of the default measurement unit of the doc. + // this may change in the future? + // until then, proportional_maxlen is likely to be in 'points' + // If first line is to be indented (shorter or longer) than maxLen + // we indicate that by using CSS-style "text-indent" option. + // here it's in font units too (which is likely 'points') + // it can be negative (which makes the first line longer than maxLen) + + newOptions.textIndent = options.textIndent ? options.textIndent * 1.0 * this.internal.scaleFactor / fsize : 0; + newOptions.lineIndent = options.lineIndent; + var i, + l, + output = []; + + for (i = 0, l = paragraphs.length; i < l; i++) { + output = output.concat(splitParagraphIntoLines.apply(this, [paragraphs[i], fontUnit_maxLen, newOptions])); + } + + return output; + }; +})(jsPDF.API); + +/* global jsPDF */ + +/** @license + jsPDF standard_fonts_metrics plugin + * Copyright (c) 2012 Willow Systems Corporation, willow-systems.com + * MIT license. + * + * ==================================================================== + */ + +/** + * This file adds the standard font metrics to jsPDF. + * + * Font metrics data is reprocessed derivative of contents of + * "Font Metrics for PDF Core 14 Fonts" package, which exhibits the following copyright and license: + * + * Copyright (c) 1989, 1990, 1991, 1992, 1993, 1997 Adobe Systems Incorporated. All Rights Reserved. + * + * This file and the 14 PostScript(R) AFM files it accompanies may be used, + * copied, and distributed for any purpose and without charge, with or without + * modification, provided that all copyright notices are retained; that the AFM + * files are not distributed without this file; that all modifications to this + * file or any of the AFM files are prominently noted in the modified file(s); + * and that this paragraph is not modified. Adobe Systems has no responsibility + * or obligation to support the use of the AFM files. + * + * @name standard_fonts_metrics + * @module + */ +(function (API) { + + API.__fontmetrics__ = API.__fontmetrics__ || {}; + var decoded = "0123456789abcdef", + encoded = "klmnopqrstuvwxyz", + mappingUncompress = {}, + mappingCompress = {}; + + for (var i = 0; i < encoded.length; i++) { + mappingUncompress[encoded[i]] = decoded[i]; + mappingCompress[decoded[i]] = encoded[i]; + } + + var hex = function hex(value) { + return "0x" + parseInt(value, 10).toString(16); + }; + + var compress = API.__fontmetrics__.compress = function (data) { + var vals = ["{"]; + var value, keystring, valuestring, numberprefix; + + for (var key in data) { + value = data[key]; + + if (!isNaN(parseInt(key, 10))) { + key = parseInt(key, 10); + keystring = hex(key).slice(2); + keystring = keystring.slice(0, -1) + mappingCompress[keystring.slice(-1)]; + } else { + keystring = "'" + key + "'"; + } + + if (typeof value == "number") { + if (value < 0) { + valuestring = hex(value).slice(3); + numberprefix = "-"; + } else { + valuestring = hex(value).slice(2); + numberprefix = ""; + } + + valuestring = numberprefix + valuestring.slice(0, -1) + mappingCompress[valuestring.slice(-1)]; + } else { + if (_typeof(value) === "object") { + valuestring = compress(value); + } else { + throw new Error("Don't know what to do with value type " + _typeof(value) + "."); + } + } + + vals.push(keystring + valuestring); + } + + vals.push("}"); + return vals.join(""); + }; + /** + * Uncompresses data compressed into custom, base16-like format. + * + * @public + * @function + * @param + * @returns {Type} + */ + + + var uncompress = API.__fontmetrics__.uncompress = function (data) { + if (typeof data !== "string") { + throw new Error("Invalid argument passed to uncompress."); + } + + var output = {}, + sign = 1, + stringparts, + // undef. will be [] in string mode + activeobject = output, + parentchain = [], + parent_key_pair, + keyparts = "", + valueparts = "", + key, + // undef. will be Truthy when Key is resolved. + datalen = data.length - 1, + // stripping ending } + ch; + + for (var i = 1; i < datalen; i += 1) { + // - { } ' are special. + ch = data[i]; + + if (ch == "'") { + if (stringparts) { + // end of string mode + key = stringparts.join(""); + stringparts = undefined; + } else { + // start of string mode + stringparts = []; + } + } else if (stringparts) { + stringparts.push(ch); + } else if (ch == "{") { + // start of object + parentchain.push([activeobject, key]); + activeobject = {}; + key = undefined; + } else if (ch == "}") { + // end of object + parent_key_pair = parentchain.pop(); + parent_key_pair[0][parent_key_pair[1]] = activeobject; + key = undefined; + activeobject = parent_key_pair[0]; + } else if (ch == "-") { + sign = -1; + } else { + // must be number + if (key === undefined) { + if (mappingUncompress.hasOwnProperty(ch)) { + keyparts += mappingUncompress[ch]; + key = parseInt(keyparts, 16) * sign; + sign = +1; + keyparts = ""; + } else { + keyparts += ch; + } + } else { + if (mappingUncompress.hasOwnProperty(ch)) { + valueparts += mappingUncompress[ch]; + activeobject[key] = parseInt(valueparts, 16) * sign; + sign = +1; + key = undefined; + valueparts = ""; + } else { + valueparts += ch; + } + } + } + } + + return output; + }; // encoding = 'Unicode' + // NOT UTF8, NOT UTF16BE/LE, NOT UCS2BE/LE. NO clever BOM behavior + // Actual 16bit char codes used. + // no multi-byte logic here + // Unicode characters to WinAnsiEncoding: + // {402: 131, 8211: 150, 8212: 151, 8216: 145, 8217: 146, 8218: 130, 8220: 147, 8221: 148, 8222: 132, 8224: 134, 8225: 135, 8226: 149, 8230: 133, 8364: 128, 8240:137, 8249: 139, 8250: 155, 710: 136, 8482: 153, 338: 140, 339: 156, 732: 152, 352: 138, 353: 154, 376: 159, 381: 142, 382: 158} + // as you can see, all Unicode chars are outside of 0-255 range. No char code conflicts. + // this means that you can give Win cp1252 encoded strings to jsPDF for rendering directly + // as well as give strings with some (supported by these fonts) Unicode characters and + // these will be mapped to win cp1252 + // for example, you can send char code (cp1252) 0x80 or (unicode) 0x20AC, getting "Euro" glyph displayed in both cases. + + + var encodingBlock = { + codePages: ["WinAnsiEncoding"], + WinAnsiEncoding: uncompress("{19m8n201n9q201o9r201s9l201t9m201u8m201w9n201x9o201y8o202k8q202l8r202m9p202q8p20aw8k203k8t203t8v203u9v2cq8s212m9t15m8w15n9w2dw9s16k8u16l9u17s9z17x8y17y9y}") + }; + var encodings = { + Unicode: { + Courier: encodingBlock, + "Courier-Bold": encodingBlock, + "Courier-BoldOblique": encodingBlock, + "Courier-Oblique": encodingBlock, + Helvetica: encodingBlock, + "Helvetica-Bold": encodingBlock, + "Helvetica-BoldOblique": encodingBlock, + "Helvetica-Oblique": encodingBlock, + "Times-Roman": encodingBlock, + "Times-Bold": encodingBlock, + "Times-BoldItalic": encodingBlock, + "Times-Italic": encodingBlock // , 'Symbol' + // , 'ZapfDingbats' + + } + }; + var fontMetrics = { + Unicode: { + // all sizing numbers are n/fontMetricsFractionOf = one font size unit + // this means that if fontMetricsFractionOf = 1000, and letter A's width is 476, it's + // width is 476/1000 or 47.6% of its height (regardless of font size) + // At this time this value applies to "widths" and "kerning" numbers. + // char code 0 represents "default" (average) width - use it for chars missing in this table. + // key 'fof' represents the "fontMetricsFractionOf" value + "Courier-Oblique": uncompress("{'widths'{k3w'fof'6o}'kerning'{'fof'-6o}}"), + "Times-BoldItalic": uncompress("{'widths'{k3o2q4ycx2r201n3m201o6o201s2l201t2l201u2l201w3m201x3m201y3m2k1t2l2r202m2n2n3m2o3m2p5n202q6o2r1w2s2l2t2l2u3m2v3t2w1t2x2l2y1t2z1w3k3m3l3m3m3m3n3m3o3m3p3m3q3m3r3m3s3m203t2l203u2l3v2l3w3t3x3t3y3t3z3m4k5n4l4m4m4m4n4m4o4s4p4m4q4m4r4s4s4y4t2r4u3m4v4m4w3x4x5t4y4s4z4s5k3x5l4s5m4m5n3r5o3x5p4s5q4m5r5t5s4m5t3x5u3x5v2l5w1w5x2l5y3t5z3m6k2l6l3m6m3m6n2w6o3m6p2w6q2l6r3m6s3r6t1w6u1w6v3m6w1w6x4y6y3r6z3m7k3m7l3m7m2r7n2r7o1w7p3r7q2w7r4m7s3m7t2w7u2r7v2n7w1q7x2n7y3t202l3mcl4mal2ram3man3mao3map3mar3mas2lat4uau1uav3maw3way4uaz2lbk2sbl3t'fof'6obo2lbp3tbq3mbr1tbs2lbu1ybv3mbz3mck4m202k3mcm4mcn4mco4mcp4mcq5ycr4mcs4mct4mcu4mcv4mcw2r2m3rcy2rcz2rdl4sdm4sdn4sdo4sdp4sdq4sds4sdt4sdu4sdv4sdw4sdz3mek3mel3mem3men3meo3mep3meq4ser2wes2wet2weu2wev2wew1wex1wey1wez1wfl3rfm3mfn3mfo3mfp3mfq3mfr3tfs3mft3rfu3rfv3rfw3rfz2w203k6o212m6o2dw2l2cq2l3t3m3u2l17s3x19m3m}'kerning'{cl{4qu5kt5qt5rs17ss5ts}201s{201ss}201t{cks4lscmscnscoscpscls2wu2yu201ts}201x{2wu2yu}2k{201ts}2w{4qx5kx5ou5qx5rs17su5tu}2x{17su5tu5ou}2y{4qx5kx5ou5qx5rs17ss5ts}'fof'-6ofn{17sw5tw5ou5qw5rs}7t{cksclscmscnscoscps4ls}3u{17su5tu5os5qs}3v{17su5tu5os5qs}7p{17su5tu}ck{4qu5kt5qt5rs17ss5ts}4l{4qu5kt5qt5rs17ss5ts}cm{4qu5kt5qt5rs17ss5ts}cn{4qu5kt5qt5rs17ss5ts}co{4qu5kt5qt5rs17ss5ts}cp{4qu5kt5qt5rs17ss5ts}6l{4qu5ou5qw5rt17su5tu}5q{ckuclucmucnucoucpu4lu}5r{ckuclucmucnucoucpu4lu}7q{cksclscmscnscoscps4ls}6p{4qu5ou5qw5rt17sw5tw}ek{4qu5ou5qw5rt17su5tu}el{4qu5ou5qw5rt17su5tu}em{4qu5ou5qw5rt17su5tu}en{4qu5ou5qw5rt17su5tu}eo{4qu5ou5qw5rt17su5tu}ep{4qu5ou5qw5rt17su5tu}es{17ss5ts5qs4qu}et{4qu5ou5qw5rt17sw5tw}eu{4qu5ou5qw5rt17ss5ts}ev{17ss5ts5qs4qu}6z{17sw5tw5ou5qw5rs}fm{17sw5tw5ou5qw5rs}7n{201ts}fo{17sw5tw5ou5qw5rs}fp{17sw5tw5ou5qw5rs}fq{17sw5tw5ou5qw5rs}7r{cksclscmscnscoscps4ls}fs{17sw5tw5ou5qw5rs}ft{17su5tu}fu{17su5tu}fv{17su5tu}fw{17su5tu}fz{cksclscmscnscoscps4ls}}}"), + "Helvetica-Bold": uncompress("{'widths'{k3s2q4scx1w201n3r201o6o201s1w201t1w201u1w201w3m201x3m201y3m2k1w2l2l202m2n2n3r2o3r2p5t202q6o2r1s2s2l2t2l2u2r2v3u2w1w2x2l2y1w2z1w3k3r3l3r3m3r3n3r3o3r3p3r3q3r3r3r3s3r203t2l203u2l3v2l3w3u3x3u3y3u3z3x4k6l4l4s4m4s4n4s4o4s4p4m4q3x4r4y4s4s4t1w4u3r4v4s4w3x4x5n4y4s4z4y5k4m5l4y5m4s5n4m5o3x5p4s5q4m5r5y5s4m5t4m5u3x5v2l5w1w5x2l5y3u5z3r6k2l6l3r6m3x6n3r6o3x6p3r6q2l6r3x6s3x6t1w6u1w6v3r6w1w6x5t6y3x6z3x7k3x7l3x7m2r7n3r7o2l7p3x7q3r7r4y7s3r7t3r7u3m7v2r7w1w7x2r7y3u202l3rcl4sal2lam3ran3rao3rap3rar3ras2lat4tau2pav3raw3uay4taz2lbk2sbl3u'fof'6obo2lbp3xbq3rbr1wbs2lbu2obv3rbz3xck4s202k3rcm4scn4sco4scp4scq6ocr4scs4mct4mcu4mcv4mcw1w2m2zcy1wcz1wdl4sdm4ydn4ydo4ydp4ydq4yds4ydt4sdu4sdv4sdw4sdz3xek3rel3rem3ren3reo3rep3req5ter3res3ret3reu3rev3rew1wex1wey1wez1wfl3xfm3xfn3xfo3xfp3xfq3xfr3ufs3xft3xfu3xfv3xfw3xfz3r203k6o212m6o2dw2l2cq2l3t3r3u2l17s4m19m3r}'kerning'{cl{4qs5ku5ot5qs17sv5tv}201t{2ww4wy2yw}201w{2ks}201x{2ww4wy2yw}2k{201ts201xs}2w{7qs4qu5kw5os5qw5rs17su5tu7tsfzs}2x{5ow5qs}2y{7qs4qu5kw5os5qw5rs17su5tu7tsfzs}'fof'-6o7p{17su5tu5ot}ck{4qs5ku5ot5qs17sv5tv}4l{4qs5ku5ot5qs17sv5tv}cm{4qs5ku5ot5qs17sv5tv}cn{4qs5ku5ot5qs17sv5tv}co{4qs5ku5ot5qs17sv5tv}cp{4qs5ku5ot5qs17sv5tv}6l{17st5tt5os}17s{2kwclvcmvcnvcovcpv4lv4wwckv}5o{2kucltcmtcntcotcpt4lt4wtckt}5q{2ksclscmscnscoscps4ls4wvcks}5r{2ks4ws}5t{2kwclvcmvcnvcovcpv4lv4wwckv}eo{17st5tt5os}fu{17su5tu5ot}6p{17ss5ts}ek{17st5tt5os}el{17st5tt5os}em{17st5tt5os}en{17st5tt5os}6o{201ts}ep{17st5tt5os}es{17ss5ts}et{17ss5ts}eu{17ss5ts}ev{17ss5ts}6z{17su5tu5os5qt}fm{17su5tu5os5qt}fn{17su5tu5os5qt}fo{17su5tu5os5qt}fp{17su5tu5os5qt}fq{17su5tu5os5qt}fs{17su5tu5os5qt}ft{17su5tu5ot}7m{5os}fv{17su5tu5ot}fw{17su5tu5ot}}}"), + Courier: uncompress("{'widths'{k3w'fof'6o}'kerning'{'fof'-6o}}"), + "Courier-BoldOblique": uncompress("{'widths'{k3w'fof'6o}'kerning'{'fof'-6o}}"), + "Times-Bold": uncompress("{'widths'{k3q2q5ncx2r201n3m201o6o201s2l201t2l201u2l201w3m201x3m201y3m2k1t2l2l202m2n2n3m2o3m2p6o202q6o2r1w2s2l2t2l2u3m2v3t2w1t2x2l2y1t2z1w3k3m3l3m3m3m3n3m3o3m3p3m3q3m3r3m3s3m203t2l203u2l3v2l3w3t3x3t3y3t3z3m4k5x4l4s4m4m4n4s4o4s4p4m4q3x4r4y4s4y4t2r4u3m4v4y4w4m4x5y4y4s4z4y5k3x5l4y5m4s5n3r5o4m5p4s5q4s5r6o5s4s5t4s5u4m5v2l5w1w5x2l5y3u5z3m6k2l6l3m6m3r6n2w6o3r6p2w6q2l6r3m6s3r6t1w6u2l6v3r6w1w6x5n6y3r6z3m7k3r7l3r7m2w7n2r7o2l7p3r7q3m7r4s7s3m7t3m7u2w7v2r7w1q7x2r7y3o202l3mcl4sal2lam3man3mao3map3mar3mas2lat4uau1yav3maw3tay4uaz2lbk2sbl3t'fof'6obo2lbp3rbr1tbs2lbu2lbv3mbz3mck4s202k3mcm4scn4sco4scp4scq6ocr4scs4mct4mcu4mcv4mcw2r2m3rcy2rcz2rdl4sdm4ydn4ydo4ydp4ydq4yds4ydt4sdu4sdv4sdw4sdz3rek3mel3mem3men3meo3mep3meq4ser2wes2wet2weu2wev2wew1wex1wey1wez1wfl3rfm3mfn3mfo3mfp3mfq3mfr3tfs3mft3rfu3rfv3rfw3rfz3m203k6o212m6o2dw2l2cq2l3t3m3u2l17s4s19m3m}'kerning'{cl{4qt5ks5ot5qy5rw17sv5tv}201t{cks4lscmscnscoscpscls4wv}2k{201ts}2w{4qu5ku7mu5os5qx5ru17su5tu}2x{17su5tu5ou5qs}2y{4qv5kv7mu5ot5qz5ru17su5tu}'fof'-6o7t{cksclscmscnscoscps4ls}3u{17su5tu5os5qu}3v{17su5tu5os5qu}fu{17su5tu5ou5qu}7p{17su5tu5ou5qu}ck{4qt5ks5ot5qy5rw17sv5tv}4l{4qt5ks5ot5qy5rw17sv5tv}cm{4qt5ks5ot5qy5rw17sv5tv}cn{4qt5ks5ot5qy5rw17sv5tv}co{4qt5ks5ot5qy5rw17sv5tv}cp{4qt5ks5ot5qy5rw17sv5tv}6l{17st5tt5ou5qu}17s{ckuclucmucnucoucpu4lu4wu}5o{ckuclucmucnucoucpu4lu4wu}5q{ckzclzcmzcnzcozcpz4lz4wu}5r{ckxclxcmxcnxcoxcpx4lx4wu}5t{ckuclucmucnucoucpu4lu4wu}7q{ckuclucmucnucoucpu4lu}6p{17sw5tw5ou5qu}ek{17st5tt5qu}el{17st5tt5ou5qu}em{17st5tt5qu}en{17st5tt5qu}eo{17st5tt5qu}ep{17st5tt5ou5qu}es{17ss5ts5qu}et{17sw5tw5ou5qu}eu{17sw5tw5ou5qu}ev{17ss5ts5qu}6z{17sw5tw5ou5qu5rs}fm{17sw5tw5ou5qu5rs}fn{17sw5tw5ou5qu5rs}fo{17sw5tw5ou5qu5rs}fp{17sw5tw5ou5qu5rs}fq{17sw5tw5ou5qu5rs}7r{cktcltcmtcntcotcpt4lt5os}fs{17sw5tw5ou5qu5rs}ft{17su5tu5ou5qu}7m{5os}fv{17su5tu5ou5qu}fw{17su5tu5ou5qu}fz{cksclscmscnscoscps4ls}}}"), + Symbol: uncompress("{'widths'{k3uaw4r19m3m2k1t2l2l202m2y2n3m2p5n202q6o3k3m2s2l2t2l2v3r2w1t3m3m2y1t2z1wbk2sbl3r'fof'6o3n3m3o3m3p3m3q3m3r3m3s3m3t3m3u1w3v1w3w3r3x3r3y3r3z2wbp3t3l3m5v2l5x2l5z3m2q4yfr3r7v3k7w1o7x3k}'kerning'{'fof'-6o}}"), + Helvetica: uncompress("{'widths'{k3p2q4mcx1w201n3r201o6o201s1q201t1q201u1q201w2l201x2l201y2l2k1w2l1w202m2n2n3r2o3r2p5t202q6o2r1n2s2l2t2l2u2r2v3u2w1w2x2l2y1w2z1w3k3r3l3r3m3r3n3r3o3r3p3r3q3r3r3r3s3r203t2l203u2l3v1w3w3u3x3u3y3u3z3r4k6p4l4m4m4m4n4s4o4s4p4m4q3x4r4y4s4s4t1w4u3m4v4m4w3r4x5n4y4s4z4y5k4m5l4y5m4s5n4m5o3x5p4s5q4m5r5y5s4m5t4m5u3x5v1w5w1w5x1w5y2z5z3r6k2l6l3r6m3r6n3m6o3r6p3r6q1w6r3r6s3r6t1q6u1q6v3m6w1q6x5n6y3r6z3r7k3r7l3r7m2l7n3m7o1w7p3r7q3m7r4s7s3m7t3m7u3m7v2l7w1u7x2l7y3u202l3rcl4mal2lam3ran3rao3rap3rar3ras2lat4tau2pav3raw3uay4taz2lbk2sbl3u'fof'6obo2lbp3rbr1wbs2lbu2obv3rbz3xck4m202k3rcm4mcn4mco4mcp4mcq6ocr4scs4mct4mcu4mcv4mcw1w2m2ncy1wcz1wdl4sdm4ydn4ydo4ydp4ydq4yds4ydt4sdu4sdv4sdw4sdz3xek3rel3rem3ren3reo3rep3req5ter3mes3ret3reu3rev3rew1wex1wey1wez1wfl3rfm3rfn3rfo3rfp3rfq3rfr3ufs3xft3rfu3rfv3rfw3rfz3m203k6o212m6o2dw2l2cq2l3t3r3u1w17s4m19m3r}'kerning'{5q{4wv}cl{4qs5kw5ow5qs17sv5tv}201t{2wu4w1k2yu}201x{2wu4wy2yu}17s{2ktclucmucnu4otcpu4lu4wycoucku}2w{7qs4qz5k1m17sy5ow5qx5rsfsu5ty7tufzu}2x{17sy5ty5oy5qs}2y{7qs4qz5k1m17sy5ow5qx5rsfsu5ty7tufzu}'fof'-6o7p{17sv5tv5ow}ck{4qs5kw5ow5qs17sv5tv}4l{4qs5kw5ow5qs17sv5tv}cm{4qs5kw5ow5qs17sv5tv}cn{4qs5kw5ow5qs17sv5tv}co{4qs5kw5ow5qs17sv5tv}cp{4qs5kw5ow5qs17sv5tv}6l{17sy5ty5ow}do{17st5tt}4z{17st5tt}7s{fst}dm{17st5tt}dn{17st5tt}5o{ckwclwcmwcnwcowcpw4lw4wv}dp{17st5tt}dq{17st5tt}7t{5ow}ds{17st5tt}5t{2ktclucmucnu4otcpu4lu4wycoucku}fu{17sv5tv5ow}6p{17sy5ty5ow5qs}ek{17sy5ty5ow}el{17sy5ty5ow}em{17sy5ty5ow}en{5ty}eo{17sy5ty5ow}ep{17sy5ty5ow}es{17sy5ty5qs}et{17sy5ty5ow5qs}eu{17sy5ty5ow5qs}ev{17sy5ty5ow5qs}6z{17sy5ty5ow5qs}fm{17sy5ty5ow5qs}fn{17sy5ty5ow5qs}fo{17sy5ty5ow5qs}fp{17sy5ty5qs}fq{17sy5ty5ow5qs}7r{5ow}fs{17sy5ty5ow5qs}ft{17sv5tv5ow}7m{5ow}fv{17sv5tv5ow}fw{17sv5tv5ow}}}"), + "Helvetica-BoldOblique": uncompress("{'widths'{k3s2q4scx1w201n3r201o6o201s1w201t1w201u1w201w3m201x3m201y3m2k1w2l2l202m2n2n3r2o3r2p5t202q6o2r1s2s2l2t2l2u2r2v3u2w1w2x2l2y1w2z1w3k3r3l3r3m3r3n3r3o3r3p3r3q3r3r3r3s3r203t2l203u2l3v2l3w3u3x3u3y3u3z3x4k6l4l4s4m4s4n4s4o4s4p4m4q3x4r4y4s4s4t1w4u3r4v4s4w3x4x5n4y4s4z4y5k4m5l4y5m4s5n4m5o3x5p4s5q4m5r5y5s4m5t4m5u3x5v2l5w1w5x2l5y3u5z3r6k2l6l3r6m3x6n3r6o3x6p3r6q2l6r3x6s3x6t1w6u1w6v3r6w1w6x5t6y3x6z3x7k3x7l3x7m2r7n3r7o2l7p3x7q3r7r4y7s3r7t3r7u3m7v2r7w1w7x2r7y3u202l3rcl4sal2lam3ran3rao3rap3rar3ras2lat4tau2pav3raw3uay4taz2lbk2sbl3u'fof'6obo2lbp3xbq3rbr1wbs2lbu2obv3rbz3xck4s202k3rcm4scn4sco4scp4scq6ocr4scs4mct4mcu4mcv4mcw1w2m2zcy1wcz1wdl4sdm4ydn4ydo4ydp4ydq4yds4ydt4sdu4sdv4sdw4sdz3xek3rel3rem3ren3reo3rep3req5ter3res3ret3reu3rev3rew1wex1wey1wez1wfl3xfm3xfn3xfo3xfp3xfq3xfr3ufs3xft3xfu3xfv3xfw3xfz3r203k6o212m6o2dw2l2cq2l3t3r3u2l17s4m19m3r}'kerning'{cl{4qs5ku5ot5qs17sv5tv}201t{2ww4wy2yw}201w{2ks}201x{2ww4wy2yw}2k{201ts201xs}2w{7qs4qu5kw5os5qw5rs17su5tu7tsfzs}2x{5ow5qs}2y{7qs4qu5kw5os5qw5rs17su5tu7tsfzs}'fof'-6o7p{17su5tu5ot}ck{4qs5ku5ot5qs17sv5tv}4l{4qs5ku5ot5qs17sv5tv}cm{4qs5ku5ot5qs17sv5tv}cn{4qs5ku5ot5qs17sv5tv}co{4qs5ku5ot5qs17sv5tv}cp{4qs5ku5ot5qs17sv5tv}6l{17st5tt5os}17s{2kwclvcmvcnvcovcpv4lv4wwckv}5o{2kucltcmtcntcotcpt4lt4wtckt}5q{2ksclscmscnscoscps4ls4wvcks}5r{2ks4ws}5t{2kwclvcmvcnvcovcpv4lv4wwckv}eo{17st5tt5os}fu{17su5tu5ot}6p{17ss5ts}ek{17st5tt5os}el{17st5tt5os}em{17st5tt5os}en{17st5tt5os}6o{201ts}ep{17st5tt5os}es{17ss5ts}et{17ss5ts}eu{17ss5ts}ev{17ss5ts}6z{17su5tu5os5qt}fm{17su5tu5os5qt}fn{17su5tu5os5qt}fo{17su5tu5os5qt}fp{17su5tu5os5qt}fq{17su5tu5os5qt}fs{17su5tu5os5qt}ft{17su5tu5ot}7m{5os}fv{17su5tu5ot}fw{17su5tu5ot}}}"), + ZapfDingbats: uncompress("{'widths'{k4u2k1w'fof'6o}'kerning'{'fof'-6o}}"), + "Courier-Bold": uncompress("{'widths'{k3w'fof'6o}'kerning'{'fof'-6o}}"), + "Times-Italic": uncompress("{'widths'{k3n2q4ycx2l201n3m201o5t201s2l201t2l201u2l201w3r201x3r201y3r2k1t2l2l202m2n2n3m2o3m2p5n202q5t2r1p2s2l2t2l2u3m2v4n2w1t2x2l2y1t2z1w3k3m3l3m3m3m3n3m3o3m3p3m3q3m3r3m3s3m203t2l203u2l3v2l3w4n3x4n3y4n3z3m4k5w4l3x4m3x4n4m4o4s4p3x4q3x4r4s4s4s4t2l4u2w4v4m4w3r4x5n4y4m4z4s5k3x5l4s5m3x5n3m5o3r5p4s5q3x5r5n5s3x5t3r5u3r5v2r5w1w5x2r5y2u5z3m6k2l6l3m6m3m6n2w6o3m6p2w6q1w6r3m6s3m6t1w6u1w6v2w6w1w6x4s6y3m6z3m7k3m7l3m7m2r7n2r7o1w7p3m7q2w7r4m7s2w7t2w7u2r7v2s7w1v7x2s7y3q202l3mcl3xal2ram3man3mao3map3mar3mas2lat4wau1vav3maw4nay4waz2lbk2sbl4n'fof'6obo2lbp3mbq3obr1tbs2lbu1zbv3mbz3mck3x202k3mcm3xcn3xco3xcp3xcq5tcr4mcs3xct3xcu3xcv3xcw2l2m2ucy2lcz2ldl4mdm4sdn4sdo4sdp4sdq4sds4sdt4sdu4sdv4sdw4sdz3mek3mel3mem3men3meo3mep3meq4mer2wes2wet2weu2wev2wew1wex1wey1wez1wfl3mfm3mfn3mfo3mfp3mfq3mfr4nfs3mft3mfu3mfv3mfw3mfz2w203k6o212m6m2dw2l2cq2l3t3m3u2l17s3r19m3m}'kerning'{cl{5kt4qw}201s{201sw}201t{201tw2wy2yy6q-t}201x{2wy2yy}2k{201tw}2w{7qs4qy7rs5ky7mw5os5qx5ru17su5tu}2x{17ss5ts5os}2y{7qs4qy7rs5ky7mw5os5qx5ru17su5tu}'fof'-6o6t{17ss5ts5qs}7t{5os}3v{5qs}7p{17su5tu5qs}ck{5kt4qw}4l{5kt4qw}cm{5kt4qw}cn{5kt4qw}co{5kt4qw}cp{5kt4qw}6l{4qs5ks5ou5qw5ru17su5tu}17s{2ks}5q{ckvclvcmvcnvcovcpv4lv}5r{ckuclucmucnucoucpu4lu}5t{2ks}6p{4qs5ks5ou5qw5ru17su5tu}ek{4qs5ks5ou5qw5ru17su5tu}el{4qs5ks5ou5qw5ru17su5tu}em{4qs5ks5ou5qw5ru17su5tu}en{4qs5ks5ou5qw5ru17su5tu}eo{4qs5ks5ou5qw5ru17su5tu}ep{4qs5ks5ou5qw5ru17su5tu}es{5ks5qs4qs}et{4qs5ks5ou5qw5ru17su5tu}eu{4qs5ks5qw5ru17su5tu}ev{5ks5qs4qs}ex{17ss5ts5qs}6z{4qv5ks5ou5qw5ru17su5tu}fm{4qv5ks5ou5qw5ru17su5tu}fn{4qv5ks5ou5qw5ru17su5tu}fo{4qv5ks5ou5qw5ru17su5tu}fp{4qv5ks5ou5qw5ru17su5tu}fq{4qv5ks5ou5qw5ru17su5tu}7r{5os}fs{4qv5ks5ou5qw5ru17su5tu}ft{17su5tu5qs}fu{17su5tu5qs}fv{17su5tu5qs}fw{17su5tu5qs}}}"), + "Times-Roman": uncompress("{'widths'{k3n2q4ycx2l201n3m201o6o201s2l201t2l201u2l201w2w201x2w201y2w2k1t2l2l202m2n2n3m2o3m2p5n202q6o2r1m2s2l2t2l2u3m2v3s2w1t2x2l2y1t2z1w3k3m3l3m3m3m3n3m3o3m3p3m3q3m3r3m3s3m203t2l203u2l3v1w3w3s3x3s3y3s3z2w4k5w4l4s4m4m4n4m4o4s4p3x4q3r4r4s4s4s4t2l4u2r4v4s4w3x4x5t4y4s4z4s5k3r5l4s5m4m5n3r5o3x5p4s5q4s5r5y5s4s5t4s5u3x5v2l5w1w5x2l5y2z5z3m6k2l6l2w6m3m6n2w6o3m6p2w6q2l6r3m6s3m6t1w6u1w6v3m6w1w6x4y6y3m6z3m7k3m7l3m7m2l7n2r7o1w7p3m7q3m7r4s7s3m7t3m7u2w7v3k7w1o7x3k7y3q202l3mcl4sal2lam3man3mao3map3mar3mas2lat4wau1vav3maw3say4waz2lbk2sbl3s'fof'6obo2lbp3mbq2xbr1tbs2lbu1zbv3mbz2wck4s202k3mcm4scn4sco4scp4scq5tcr4mcs3xct3xcu3xcv3xcw2l2m2tcy2lcz2ldl4sdm4sdn4sdo4sdp4sdq4sds4sdt4sdu4sdv4sdw4sdz3mek2wel2wem2wen2weo2wep2weq4mer2wes2wet2weu2wev2wew1wex1wey1wez1wfl3mfm3mfn3mfo3mfp3mfq3mfr3sfs3mft3mfu3mfv3mfw3mfz3m203k6o212m6m2dw2l2cq2l3t3m3u1w17s4s19m3m}'kerning'{cl{4qs5ku17sw5ou5qy5rw201ss5tw201ws}201s{201ss}201t{ckw4lwcmwcnwcowcpwclw4wu201ts}2k{201ts}2w{4qs5kw5os5qx5ru17sx5tx}2x{17sw5tw5ou5qu}2y{4qs5kw5os5qx5ru17sx5tx}'fof'-6o7t{ckuclucmucnucoucpu4lu5os5rs}3u{17su5tu5qs}3v{17su5tu5qs}7p{17sw5tw5qs}ck{4qs5ku17sw5ou5qy5rw201ss5tw201ws}4l{4qs5ku17sw5ou5qy5rw201ss5tw201ws}cm{4qs5ku17sw5ou5qy5rw201ss5tw201ws}cn{4qs5ku17sw5ou5qy5rw201ss5tw201ws}co{4qs5ku17sw5ou5qy5rw201ss5tw201ws}cp{4qs5ku17sw5ou5qy5rw201ss5tw201ws}6l{17su5tu5os5qw5rs}17s{2ktclvcmvcnvcovcpv4lv4wuckv}5o{ckwclwcmwcnwcowcpw4lw4wu}5q{ckyclycmycnycoycpy4ly4wu5ms}5r{cktcltcmtcntcotcpt4lt4ws}5t{2ktclvcmvcnvcovcpv4lv4wuckv}7q{cksclscmscnscoscps4ls}6p{17su5tu5qw5rs}ek{5qs5rs}el{17su5tu5os5qw5rs}em{17su5tu5os5qs5rs}en{17su5qs5rs}eo{5qs5rs}ep{17su5tu5os5qw5rs}es{5qs}et{17su5tu5qw5rs}eu{17su5tu5qs5rs}ev{5qs}6z{17sv5tv5os5qx5rs}fm{5os5qt5rs}fn{17sv5tv5os5qx5rs}fo{17sv5tv5os5qx5rs}fp{5os5qt5rs}fq{5os5qt5rs}7r{ckuclucmucnucoucpu4lu5os}fs{17sv5tv5os5qx5rs}ft{17ss5ts5qs}fu{17sw5tw5qs}fv{17sw5tw5qs}fw{17ss5ts5qs}fz{ckuclucmucnucoucpu4lu5os5rs}}}"), + "Helvetica-Oblique": uncompress("{'widths'{k3p2q4mcx1w201n3r201o6o201s1q201t1q201u1q201w2l201x2l201y2l2k1w2l1w202m2n2n3r2o3r2p5t202q6o2r1n2s2l2t2l2u2r2v3u2w1w2x2l2y1w2z1w3k3r3l3r3m3r3n3r3o3r3p3r3q3r3r3r3s3r203t2l203u2l3v1w3w3u3x3u3y3u3z3r4k6p4l4m4m4m4n4s4o4s4p4m4q3x4r4y4s4s4t1w4u3m4v4m4w3r4x5n4y4s4z4y5k4m5l4y5m4s5n4m5o3x5p4s5q4m5r5y5s4m5t4m5u3x5v1w5w1w5x1w5y2z5z3r6k2l6l3r6m3r6n3m6o3r6p3r6q1w6r3r6s3r6t1q6u1q6v3m6w1q6x5n6y3r6z3r7k3r7l3r7m2l7n3m7o1w7p3r7q3m7r4s7s3m7t3m7u3m7v2l7w1u7x2l7y3u202l3rcl4mal2lam3ran3rao3rap3rar3ras2lat4tau2pav3raw3uay4taz2lbk2sbl3u'fof'6obo2lbp3rbr1wbs2lbu2obv3rbz3xck4m202k3rcm4mcn4mco4mcp4mcq6ocr4scs4mct4mcu4mcv4mcw1w2m2ncy1wcz1wdl4sdm4ydn4ydo4ydp4ydq4yds4ydt4sdu4sdv4sdw4sdz3xek3rel3rem3ren3reo3rep3req5ter3mes3ret3reu3rev3rew1wex1wey1wez1wfl3rfm3rfn3rfo3rfp3rfq3rfr3ufs3xft3rfu3rfv3rfw3rfz3m203k6o212m6o2dw2l2cq2l3t3r3u1w17s4m19m3r}'kerning'{5q{4wv}cl{4qs5kw5ow5qs17sv5tv}201t{2wu4w1k2yu}201x{2wu4wy2yu}17s{2ktclucmucnu4otcpu4lu4wycoucku}2w{7qs4qz5k1m17sy5ow5qx5rsfsu5ty7tufzu}2x{17sy5ty5oy5qs}2y{7qs4qz5k1m17sy5ow5qx5rsfsu5ty7tufzu}'fof'-6o7p{17sv5tv5ow}ck{4qs5kw5ow5qs17sv5tv}4l{4qs5kw5ow5qs17sv5tv}cm{4qs5kw5ow5qs17sv5tv}cn{4qs5kw5ow5qs17sv5tv}co{4qs5kw5ow5qs17sv5tv}cp{4qs5kw5ow5qs17sv5tv}6l{17sy5ty5ow}do{17st5tt}4z{17st5tt}7s{fst}dm{17st5tt}dn{17st5tt}5o{ckwclwcmwcnwcowcpw4lw4wv}dp{17st5tt}dq{17st5tt}7t{5ow}ds{17st5tt}5t{2ktclucmucnu4otcpu4lu4wycoucku}fu{17sv5tv5ow}6p{17sy5ty5ow5qs}ek{17sy5ty5ow}el{17sy5ty5ow}em{17sy5ty5ow}en{5ty}eo{17sy5ty5ow}ep{17sy5ty5ow}es{17sy5ty5qs}et{17sy5ty5ow5qs}eu{17sy5ty5ow5qs}ev{17sy5ty5ow5qs}6z{17sy5ty5ow5qs}fm{17sy5ty5ow5qs}fn{17sy5ty5ow5qs}fo{17sy5ty5ow5qs}fp{17sy5ty5qs}fq{17sy5ty5ow5qs}7r{5ow}fs{17sy5ty5ow5qs}ft{17sv5tv5ow}7m{5ow}fv{17sv5tv5ow}fw{17sv5tv5ow}}}") + } + }; + /* + This event handler is fired when a new jsPDF object is initialized + This event handler appends metrics data to standard fonts within + that jsPDF instance. The metrics are mapped over Unicode character + codes, NOT CIDs or other codes matching the StandardEncoding table of the + standard PDF fonts. + Future: + Also included is the encoding maping table, converting Unicode (UCS-2, UTF-16) + char codes to StandardEncoding character codes. The encoding table is to be used + somewhere around "pdfEscape" call. + */ + + API.events.push(["addFont", function (data) { + var font = data.font; + var metrics = fontMetrics["Unicode"][font.postScriptName]; + + if (metrics) { + font.metadata["Unicode"] = {}; + font.metadata["Unicode"].widths = metrics.widths; + font.metadata["Unicode"].kerning = metrics.kerning; + } + + var encodingBlock = encodings["Unicode"][font.postScriptName]; + + if (encodingBlock) { + font.metadata["Unicode"].encoding = encodingBlock; + font.encoding = encodingBlock.codePages[0]; + } + }]); // end of adding event handler +})(jsPDF.API); + +/* global jsPDF, canvg */ + +/** @license + * Copyright (c) 2012 Willow Systems Corporation, willow-systems.com + * + * + * ==================================================================== + */ + +/** + * jsPDF SVG plugin + * + * @name svg + * @module + */ +(function (jsPDFAPI) { + /** + * Parses SVG XML and converts only some of the SVG elements into + * PDF elements. + * + * Supports: + * paths + * + * @name addSvg + * @public + * @function + * @param {string} SVG-Data as Text + * @param {number} x Coordinate (in units declared at inception of PDF document) against left edge of the page + * @param {number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page + * @param {number} width of SVG (in units declared at inception of PDF document) + * @param {number} height of SVG (in units declared at inception of PDF document) + * @returns {Object} jsPDF-instance + */ + + jsPDFAPI.addSvg = function (svgtext, x, y, w, h) { + // 'this' is _jsPDF object returned when jsPDF is inited (new jsPDF()) + if (x === undefined || y === undefined) { + throw new Error("addSVG needs values for 'x' and 'y'"); + } + + function InjectCSS(cssbody, document) { + var styletag = document.createElement("style"); + styletag.type = "text/css"; + + if (styletag.styleSheet) { + // ie + styletag.styleSheet.cssText = cssbody; + } else { + // others + styletag.appendChild(document.createTextNode(cssbody)); + } + + document.getElementsByTagName("head")[0].appendChild(styletag); + } + + function createWorkerNode(document) { + var frameID = "childframe", + // Date.now().toString() + '_' + (Math.random() * 100).toString() + frame = document.createElement("iframe"); + InjectCSS(".jsPDF_sillysvg_iframe {display:none;position:absolute;}", document); + frame.name = frameID; + frame.setAttribute("width", 0); + frame.setAttribute("height", 0); + frame.setAttribute("frameborder", "0"); + frame.setAttribute("scrolling", "no"); + frame.setAttribute("seamless", "seamless"); + frame.setAttribute("class", "jsPDF_sillysvg_iframe"); + document.body.appendChild(frame); + return frame; + } + + function attachSVGToWorkerNode(svgtext, frame) { + var framedoc = (frame.contentWindow || frame.contentDocument).document; + framedoc.write(svgtext); + framedoc.close(); + return framedoc.getElementsByTagName("svg")[0]; + } + + function convertPathToPDFLinesArgs(path) { + // - starting coordinate pair + // - array of arrays of vector shifts (2-len for line, 6 len for bezier) + // - scale array [horizontal, vertical] ratios + // - style (stroke, fill, both) + + var x = parseFloat(path[1]), + y = parseFloat(path[2]), + vectors = [], + position = 3, + len = path.length; + + while (position < len) { + if (path[position] === "c") { + vectors.push([parseFloat(path[position + 1]), parseFloat(path[position + 2]), parseFloat(path[position + 3]), parseFloat(path[position + 4]), parseFloat(path[position + 5]), parseFloat(path[position + 6])]); + position += 7; + } else if (path[position] === "l") { + vectors.push([parseFloat(path[position + 1]), parseFloat(path[position + 2])]); + position += 3; + } else { + position += 1; + } + } + + return [x, y, vectors]; + } + + var workernode = createWorkerNode(document), + svgnode = attachSVGToWorkerNode(svgtext, workernode), + scale = [1, 1], + svgw = parseFloat(svgnode.getAttribute("width")), + svgh = parseFloat(svgnode.getAttribute("height")); + + if (svgw && svgh) { + // setting both w and h makes image stretch to size. + // this may distort the image, but fits your demanded size + if (w && h) { + scale = [w / svgw, h / svgh]; + } // if only one is set, that value is set as max and SVG + // is scaled proportionately. + else if (w) { + scale = [w / svgw, w / svgw]; + } else if (h) { + scale = [h / svgh, h / svgh]; + } + } + + var i, + l, + tmp, + linesargs, + items = svgnode.childNodes; + + for (i = 0, l = items.length; i < l; i++) { + tmp = items[i]; + + if (tmp.tagName && tmp.tagName.toUpperCase() === "PATH") { + linesargs = convertPathToPDFLinesArgs(tmp.getAttribute("d").split(tmp.getAttribute("d").indexOf(",") === -1 ? " " : ",")); // path start x coordinate + + linesargs[0] = linesargs[0] * scale[0] + x; // where x is upper left X of image + // path start y coordinate + + linesargs[1] = linesargs[1] * scale[1] + y; // where y is upper left Y of image + // the rest of lines are vectors. these will adjust with scale value auto. + + this.lines.call(this, linesargs[2], // lines + linesargs[0], // starting x + linesargs[1], // starting y + scale); + } + } // clean up + // workernode.parentNode.removeChild(workernode) + + + return this; + }; //fallback + + + jsPDFAPI.addSVG = jsPDFAPI.addSvg; + /** + * Parses SVG XML and saves it as image into the PDF. + * + * Depends on canvas-element and canvg + * + * @name addSvgAsImage + * @public + * @function + * @param {string} SVG-Data as Text + * @param {number} x Coordinate (in units declared at inception of PDF document) against left edge of the page + * @param {number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page + * @param {number} width of SVG-Image (in units declared at inception of PDF document) + * @param {number} height of SVG-Image (in units declared at inception of PDF document) + * @param {string} alias of SVG-Image (if used multiple times) + * @param {string} compression of the generated JPEG, can have the values 'NONE', 'FAST', 'MEDIUM' and 'SLOW' + * @param {number} rotation of the image in degrees (0-359) + * + * @returns jsPDF jsPDF-instance + */ + + jsPDFAPI.addSvgAsImage = function (svg, x, y, w, h, alias, compression, rotation) { + if (isNaN(x) || isNaN(y)) { + console.error("jsPDF.addSvgAsImage: Invalid coordinates", arguments); + throw new Error("Invalid coordinates passed to jsPDF.addSvgAsImage"); + } + + if (isNaN(w) || isNaN(h)) { + console.error("jsPDF.addSvgAsImage: Invalid measurements", arguments); + throw new Error("Invalid measurements (width and/or height) passed to jsPDF.addSvgAsImage"); + } + + var canvas = document.createElement("canvas"); + canvas.width = w; + canvas.height = h; + var ctx = canvas.getContext("2d"); + ctx.fillStyle = "#fff"; /// set white fill style + + ctx.fillRect(0, 0, canvas.width, canvas.height); //load a svg snippet in the canvas with id = 'drawingArea' + + canvg(canvas, svg, { + ignoreMouse: true, + ignoreAnimation: true, + ignoreDimensions: true, + ignoreClear: true + }); + this.addImage(canvas.toDataURL("image/jpeg", 1.0), x, y, w, h, compression, rotation); + return this; + }; +})(jsPDF.API); + +/* global jsPDF */ + +/** + * @license + * ==================================================================== + * Copyright (c) 2013 Eduardo Menezes de Morais, eduardo.morais@usp.br + * + * + * ==================================================================== + */ + +/** + * jsPDF total_pages plugin + * @name total_pages + * @module + */ +(function (jsPDFAPI) { + /** + * @name putTotalPages + * @function + * @param {string} pageExpression Regular Expression + * @returns {jsPDF} jsPDF-instance + */ + + jsPDFAPI.putTotalPages = function (pageExpression) { + + var replaceExpression; + var totalNumberOfPages = 0; + + if (parseInt(this.internal.getFont().id.substr(1), 10) < 15) { + replaceExpression = new RegExp(pageExpression, "g"); + totalNumberOfPages = this.internal.getNumberOfPages(); + } else { + replaceExpression = new RegExp(this.pdfEscape16(pageExpression, this.internal.getFont()), "g"); + totalNumberOfPages = this.pdfEscape16(this.internal.getNumberOfPages() + "", this.internal.getFont()); + } + + for (var n = 1; n <= this.internal.getNumberOfPages(); n++) { + for (var i = 0; i < this.internal.pages[n].length; i++) { + this.internal.pages[n][i] = this.internal.pages[n][i].replace(replaceExpression, totalNumberOfPages); + } + } + + return this; + }; +})(jsPDF.API); + +/* global jsPDF */ + +/** + * jsPDF viewerPreferences Plugin + * @author Aras Abbasi (github.com/arasabbasi) + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ + +/** + * Adds the ability to set ViewerPreferences and by thus + * controlling the way the document is to be presented on the + * screen or in print. + * @name viewerpreferences + * @module + */ +(function (jsPDFAPI) { + /** + * Set the ViewerPreferences of the generated PDF + * + * @name viewerPreferences + * @function + * @public + * @param {Object} options Array with the ViewerPreferences
    + * Example: doc.viewerPreferences({"FitWindow":true});
    + *
    + * You can set following preferences:
    + *
    + * HideToolbar (boolean)
    + * Default value: false
    + *
    + * HideMenubar (boolean)
    + * Default value: false.
    + *
    + * HideWindowUI (boolean)
    + * Default value: false.
    + *
    + * FitWindow (boolean)
    + * Default value: false.
    + *
    + * CenterWindow (boolean)
    + * Default value: false
    + *
    + * DisplayDocTitle (boolean)
    + * Default value: false.
    + *
    + * NonFullScreenPageMode (string)
    + * Possible values: UseNone, UseOutlines, UseThumbs, UseOC
    + * Default value: UseNone
    + *
    + * Direction (string)
    + * Possible values: L2R, R2L
    + * Default value: L2R.
    + *
    + * ViewArea (string)
    + * Possible values: MediaBox, CropBox, TrimBox, BleedBox, ArtBox
    + * Default value: CropBox.
    + *
    + * ViewClip (string)
    + * Possible values: MediaBox, CropBox, TrimBox, BleedBox, ArtBox
    + * Default value: CropBox
    + *
    + * PrintArea (string)
    + * Possible values: MediaBox, CropBox, TrimBox, BleedBox, ArtBox
    + * Default value: CropBox
    + *
    + * PrintClip (string)
    + * Possible values: MediaBox, CropBox, TrimBox, BleedBox, ArtBox
    + * Default value: CropBox.
    + *
    + * PrintScaling (string)
    + * Possible values: AppDefault, None
    + * Default value: AppDefault.
    + *
    + * Duplex (string)
    + * Possible values: Simplex, DuplexFlipLongEdge, DuplexFlipShortEdge + * Default value: none
    + *
    + * PickTrayByPDFSize (boolean)
    + * Default value: false
    + *
    + * PrintPageRange (Array)
    + * Example: [[1,5], [7,9]]
    + * Default value: as defined by PDF viewer application
    + *
    + * NumCopies (Number)
    + * Possible values: 1, 2, 3, 4, 5
    + * Default value: 1
    + *
    + * For more information see the PDF Reference, sixth edition on Page 577 + * @param {boolean} doReset True to reset the settings + * @function + * @returns jsPDF jsPDF-instance + * @example + * var doc = new jsPDF() + * doc.text('This is a test', 10, 10) + * doc.viewerPreferences({'FitWindow': true}, true) + * doc.save("viewerPreferences.pdf") + * + * // Example printing 10 copies, using cropbox, and hiding UI. + * doc.viewerPreferences({ + * 'HideWindowUI': true, + * 'PrintArea': 'CropBox', + * 'NumCopies': 10 + * }) + */ + + jsPDFAPI.viewerPreferences = function (options, doReset) { + options = options || {}; + doReset = doReset || false; + var configuration; + var configurationTemplate = { + HideToolbar: { + defaultValue: false, + value: false, + type: "boolean", + explicitSet: false, + valueSet: [true, false], + pdfVersion: 1.3 + }, + HideMenubar: { + defaultValue: false, + value: false, + type: "boolean", + explicitSet: false, + valueSet: [true, false], + pdfVersion: 1.3 + }, + HideWindowUI: { + defaultValue: false, + value: false, + type: "boolean", + explicitSet: false, + valueSet: [true, false], + pdfVersion: 1.3 + }, + FitWindow: { + defaultValue: false, + value: false, + type: "boolean", + explicitSet: false, + valueSet: [true, false], + pdfVersion: 1.3 + }, + CenterWindow: { + defaultValue: false, + value: false, + type: "boolean", + explicitSet: false, + valueSet: [true, false], + pdfVersion: 1.3 + }, + DisplayDocTitle: { + defaultValue: false, + value: false, + type: "boolean", + explicitSet: false, + valueSet: [true, false], + pdfVersion: 1.4 + }, + NonFullScreenPageMode: { + defaultValue: "UseNone", + value: "UseNone", + type: "name", + explicitSet: false, + valueSet: ["UseNone", "UseOutlines", "UseThumbs", "UseOC"], + pdfVersion: 1.3 + }, + Direction: { + defaultValue: "L2R", + value: "L2R", + type: "name", + explicitSet: false, + valueSet: ["L2R", "R2L"], + pdfVersion: 1.3 + }, + ViewArea: { + defaultValue: "CropBox", + value: "CropBox", + type: "name", + explicitSet: false, + valueSet: ["MediaBox", "CropBox", "TrimBox", "BleedBox", "ArtBox"], + pdfVersion: 1.4 + }, + ViewClip: { + defaultValue: "CropBox", + value: "CropBox", + type: "name", + explicitSet: false, + valueSet: ["MediaBox", "CropBox", "TrimBox", "BleedBox", "ArtBox"], + pdfVersion: 1.4 + }, + PrintArea: { + defaultValue: "CropBox", + value: "CropBox", + type: "name", + explicitSet: false, + valueSet: ["MediaBox", "CropBox", "TrimBox", "BleedBox", "ArtBox"], + pdfVersion: 1.4 + }, + PrintClip: { + defaultValue: "CropBox", + value: "CropBox", + type: "name", + explicitSet: false, + valueSet: ["MediaBox", "CropBox", "TrimBox", "BleedBox", "ArtBox"], + pdfVersion: 1.4 + }, + PrintScaling: { + defaultValue: "AppDefault", + value: "AppDefault", + type: "name", + explicitSet: false, + valueSet: ["AppDefault", "None"], + pdfVersion: 1.6 + }, + Duplex: { + defaultValue: "", + value: "none", + type: "name", + explicitSet: false, + valueSet: ["Simplex", "DuplexFlipShortEdge", "DuplexFlipLongEdge", "none"], + pdfVersion: 1.7 + }, + PickTrayByPDFSize: { + defaultValue: false, + value: false, + type: "boolean", + explicitSet: false, + valueSet: [true, false], + pdfVersion: 1.7 + }, + PrintPageRange: { + defaultValue: "", + value: "", + type: "array", + explicitSet: false, + valueSet: null, + pdfVersion: 1.7 + }, + NumCopies: { + defaultValue: 1, + value: 1, + type: "integer", + explicitSet: false, + valueSet: null, + pdfVersion: 1.7 + } + }; + var configurationKeys = Object.keys(configurationTemplate); + var rangeArray = []; + var i = 0; + var j = 0; + var k = 0; + var isValid; + var method; + var value; + + function arrayContainsElement(array, element) { + var iterator; + var result = false; + + for (iterator = 0; iterator < array.length; iterator += 1) { + if (array[iterator] === element) { + result = true; + } + } + + return result; + } + + if (this.internal.viewerpreferences === undefined) { + this.internal.viewerpreferences = {}; + this.internal.viewerpreferences.configuration = JSON.parse(JSON.stringify(configurationTemplate)); + this.internal.viewerpreferences.isSubscribed = false; + } + + configuration = this.internal.viewerpreferences.configuration; + + if (options === "reset" || doReset === true) { + var len = configurationKeys.length; + + for (k = 0; k < len; k += 1) { + configuration[configurationKeys[k]].value = configuration[configurationKeys[k]].defaultValue; + configuration[configurationKeys[k]].explicitSet = false; + } + } + + if (_typeof(options) === "object") { + for (method in options) { + value = options[method]; + + if (arrayContainsElement(configurationKeys, method) && value !== undefined) { + if (configuration[method].type === "boolean" && typeof value === "boolean") { + configuration[method].value = value; + } else if (configuration[method].type === "name" && arrayContainsElement(configuration[method].valueSet, value)) { + configuration[method].value = value; + } else if (configuration[method].type === "integer" && Number.isInteger(value)) { + configuration[method].value = value; + } else if (configuration[method].type === "array") { + for (i = 0; i < value.length; i += 1) { + isValid = true; + + if (value[i].length === 1 && typeof value[i][0] === "number") { + rangeArray.push(String(value[i] - 1)); + } else if (value[i].length > 1) { + for (j = 0; j < value[i].length; j += 1) { + if (typeof value[i][j] !== "number") { + isValid = false; + } + } + + if (isValid === true) { + rangeArray.push([value[i][0] - 1, value[i][1] - 1].join(" ")); + } + } + } + + configuration[method].value = "[" + rangeArray.join(" ") + "]"; + } else { + configuration[method].value = configuration[method].defaultValue; + } + + configuration[method].explicitSet = true; + } + } + } + + if (this.internal.viewerpreferences.isSubscribed === false) { + this.internal.events.subscribe("putCatalog", function () { + var pdfDict = []; + var vPref; + + for (vPref in configuration) { + if (configuration[vPref].explicitSet === true) { + if (configuration[vPref].type === "name") { + pdfDict.push("/" + vPref + " /" + configuration[vPref].value); + } else { + pdfDict.push("/" + vPref + " " + configuration[vPref].value); + } + } + } + + if (pdfDict.length !== 0) { + this.internal.write("/ViewerPreferences\n<<\n" + pdfDict.join("\n") + "\n>>"); + } + }); + this.internal.viewerpreferences.isSubscribed = true; + } + + this.internal.viewerpreferences.configuration = configuration; + return this; + }; +})(jsPDF.API); + +/* global jsPDF */ + +/** ==================================================================== + * jsPDF XMP metadata plugin + * Copyright (c) 2016 Jussi Utunen, u-jussi@suomi24.fi + * + * + * ==================================================================== + */ + +/** + * @name xmp_metadata + * @module + */ +(function (jsPDFAPI) { + + var postPutResources = function postPutResources() { + var xmpmeta_beginning = ''; + var rdf_beginning = ''; + var rdf_ending = ""; + var xmpmeta_ending = ""; + var utf8_xmpmeta_beginning = unescape(encodeURIComponent(xmpmeta_beginning)); + var utf8_rdf_beginning = unescape(encodeURIComponent(rdf_beginning)); + var utf8_metadata = unescape(encodeURIComponent(this.internal.__metadata__.metadata)); + var utf8_rdf_ending = unescape(encodeURIComponent(rdf_ending)); + var utf8_xmpmeta_ending = unescape(encodeURIComponent(xmpmeta_ending)); + var total_len = utf8_rdf_beginning.length + utf8_metadata.length + utf8_rdf_ending.length + utf8_xmpmeta_beginning.length + utf8_xmpmeta_ending.length; + this.internal.__metadata__.metadata_object_number = this.internal.newObject(); + this.internal.write("<< /Type /Metadata /Subtype /XML /Length " + total_len + " >>"); + this.internal.write("stream"); + this.internal.write(utf8_xmpmeta_beginning + utf8_rdf_beginning + utf8_metadata + utf8_rdf_ending + utf8_xmpmeta_ending); + this.internal.write("endstream"); + this.internal.write("endobj"); + }; + + var putCatalog = function putCatalog() { + if (this.internal.__metadata__.metadata_object_number) { + this.internal.write("/Metadata " + this.internal.__metadata__.metadata_object_number + " 0 R"); + } + }; + /** + * Adds XMP formatted metadata to PDF + * + * @name addMetadata + * @function + * @param {String} metadata The actual metadata to be added. The metadata shall be stored as XMP simple value. Note that if the metadata string contains XML markup characters "<", ">" or "&", those characters should be written using XML entities. + * @param {String} namespaceuri Sets the namespace URI for the metadata. Last character should be slash or hash. + * @returns {jsPDF} jsPDF-instance + */ + + + jsPDFAPI.addMetadata = function (metadata, namespaceuri) { + if (typeof this.internal.__metadata__ === "undefined") { + this.internal.__metadata__ = { + metadata: metadata, + namespaceuri: namespaceuri || "http://jspdf.default.namespaceuri/" + }; + this.internal.events.subscribe("putCatalog", putCatalog); + this.internal.events.subscribe("postPutResources", postPutResources); + } + + return this; + }; +})(jsPDF.API); + +/* global jsPDF */ + +/** + * @name utf8 + * @module + */ +(function (jsPDF) { + + var jsPDFAPI = jsPDF.API; + /***************************************************************************************************/ + + /* function : pdfEscape16 */ + + /* comment : The character id of a 2-byte string is converted to a hexadecimal number by obtaining */ + + /* the corresponding glyph id and width, and then adding padding to the string. */ + + /***************************************************************************************************/ + + var pdfEscape16 = jsPDFAPI.pdfEscape16 = function (text, font) { + var widths = font.metadata.Unicode.widths; + var padz = ["", "0", "00", "000", "0000"]; + var ar = [""]; + + for (var i = 0, l = text.length, t; i < l; ++i) { + t = font.metadata.characterToGlyph(text.charCodeAt(i)); + font.metadata.glyIdsUsed.push(t); + font.metadata.toUnicode[t] = text.charCodeAt(i); + + if (widths.indexOf(t) == -1) { + widths.push(t); + widths.push([parseInt(font.metadata.widthOfGlyph(t), 10)]); + } + + if (t == "0") { + //Spaces are not allowed in cmap. + return ar.join(""); + } else { + t = t.toString(16); + ar.push(padz[4 - t.length], t); + } + } + + return ar.join(""); + }; + + var toUnicodeCmap = function toUnicodeCmap(map) { + var code, codes, range, unicode, unicodeMap, _i, _len; + + unicodeMap = "/CIDInit /ProcSet findresource begin\n12 dict begin\nbegincmap\n/CIDSystemInfo <<\n /Registry (Adobe)\n /Ordering (UCS)\n /Supplement 0\n>> def\n/CMapName /Adobe-Identity-UCS def\n/CMapType 2 def\n1 begincodespacerange\n<0000>\nendcodespacerange"; + codes = Object.keys(map).sort(function (a, b) { + return a - b; + }); + range = []; + + for (_i = 0, _len = codes.length; _i < _len; _i++) { + code = codes[_i]; + + if (range.length >= 100) { + unicodeMap += "\n" + range.length + " beginbfchar\n" + range.join("\n") + "\nendbfchar"; + range = []; + } + + if (map[code] !== undefined && map[code] !== null && typeof map[code].toString === "function") { + unicode = ("0000" + map[code].toString(16)).slice(-4); + code = ("0000" + (+code).toString(16)).slice(-4); + range.push("<" + code + "><" + unicode + ">"); + } + } + + if (range.length) { + unicodeMap += "\n" + range.length + " beginbfchar\n" + range.join("\n") + "\nendbfchar\n"; + } + + unicodeMap += "endcmap\nCMapName currentdict /CMap defineresource pop\nend\nend"; + return unicodeMap; + }; + + var identityHFunction = function identityHFunction(options) { + var font = options.font; + var out = options.out; + var newObject = options.newObject; + var putStream = options.putStream; + var pdfEscapeWithNeededParanthesis = options.pdfEscapeWithNeededParanthesis; + + if (font.metadata instanceof jsPDF.API.TTFFont && font.encoding === "Identity-H") { + //Tag with Identity-H + var widths = font.metadata.Unicode.widths; + var data = font.metadata.subset.encode(font.metadata.glyIdsUsed, 1); + var pdfOutput = data; + var pdfOutput2 = ""; + + for (var i = 0; i < pdfOutput.length; i++) { + pdfOutput2 += String.fromCharCode(pdfOutput[i]); + } + + var fontTable = newObject(); + putStream({ + data: pdfOutput2, + addLength1: true + }); + out("endobj"); + var cmap = newObject(); + var cmapData = toUnicodeCmap(font.metadata.toUnicode); + putStream({ + data: cmapData, + addLength1: true + }); + out("endobj"); + var fontDescriptor = newObject(); + out("<<"); + out("/Type /FontDescriptor"); + out("/FontName /" + pdfEscapeWithNeededParanthesis(font.fontName)); + out("/FontFile2 " + fontTable + " 0 R"); + out("/FontBBox " + jsPDF.API.PDFObject.convert(font.metadata.bbox)); + out("/Flags " + font.metadata.flags); + out("/StemV " + font.metadata.stemV); + out("/ItalicAngle " + font.metadata.italicAngle); + out("/Ascent " + font.metadata.ascender); + out("/Descent " + font.metadata.decender); + out("/CapHeight " + font.metadata.capHeight); + out(">>"); + out("endobj"); + var DescendantFont = newObject(); + out("<<"); + out("/Type /Font"); + out("/BaseFont /" + pdfEscapeWithNeededParanthesis(font.fontName)); + out("/FontDescriptor " + fontDescriptor + " 0 R"); + out("/W " + jsPDF.API.PDFObject.convert(widths)); + out("/CIDToGIDMap /Identity"); + out("/DW 1000"); + out("/Subtype /CIDFontType2"); + out("/CIDSystemInfo"); + out("<<"); + out("/Supplement 0"); + out("/Registry (Adobe)"); + out("/Ordering (" + font.encoding + ")"); + out(">>"); + out(">>"); + out("endobj"); + font.objectNumber = newObject(); + out("<<"); + out("/Type /Font"); + out("/Subtype /Type0"); + out("/ToUnicode " + cmap + " 0 R"); + out("/BaseFont /" + font.fontName); + out("/Encoding /" + font.encoding); + out("/DescendantFonts [" + DescendantFont + " 0 R]"); + out(">>"); + out("endobj"); + font.isAlreadyPutted = true; + } + }; + + jsPDFAPI.events.push(["putFont", function (args) { + identityHFunction(args); + }]); + + var winAnsiEncodingFunction = function winAnsiEncodingFunction(options) { + var font = options.font; + var out = options.out; + var newObject = options.newObject; + var putStream = options.putStream; + var pdfEscapeWithNeededParanthesis = options.pdfEscapeWithNeededParanthesis; + + if (font.metadata instanceof jsPDF.API.TTFFont && font.encoding === "WinAnsiEncoding") { + //Tag with WinAnsi encoding + var data = font.metadata.rawData; + var pdfOutput = data; + var pdfOutput2 = ""; + + for (var i = 0; i < pdfOutput.length; i++) { + pdfOutput2 += String.fromCharCode(pdfOutput[i]); + } + + var fontTable = newObject(); + putStream({ + data: pdfOutput2, + addLength1: true + }); + out("endobj"); + var cmap = newObject(); + var cmapData = toUnicodeCmap(font.metadata.toUnicode); + putStream({ + data: cmapData, + addLength1: true + }); + out("endobj"); + var fontDescriptor = newObject(); + out("<<"); + out("/Descent " + font.metadata.decender); + out("/CapHeight " + font.metadata.capHeight); + out("/StemV " + font.metadata.stemV); + out("/Type /FontDescriptor"); + out("/FontFile2 " + fontTable + " 0 R"); + out("/Flags 96"); + out("/FontBBox " + jsPDF.API.PDFObject.convert(font.metadata.bbox)); + out("/FontName /" + pdfEscapeWithNeededParanthesis(font.fontName)); + out("/ItalicAngle " + font.metadata.italicAngle); + out("/Ascent " + font.metadata.ascender); + out(">>"); + out("endobj"); + font.objectNumber = newObject(); + + for (var j = 0; j < font.metadata.hmtx.widths.length; j++) { + font.metadata.hmtx.widths[j] = parseInt(font.metadata.hmtx.widths[j] * (1000 / font.metadata.head.unitsPerEm)); //Change the width of Em units to Point units. + } + + out("<>"); + out("endobj"); + font.isAlreadyPutted = true; + } + }; + + jsPDFAPI.events.push(["putFont", function (args) { + winAnsiEncodingFunction(args); + }]); + + var utf8TextFunction = function utf8TextFunction(args) { + var text = args.text || ""; + var x = args.x; + var y = args.y; + var options = args.options || {}; + var mutex = args.mutex || {}; + var pdfEscape = mutex.pdfEscape; + var activeFontKey = mutex.activeFontKey; + var fonts = mutex.fonts; + var key = activeFontKey; + var str = "", + s = 0, + cmapConfirm; + var strText = ""; + var encoding = fonts[key].encoding; + + if (fonts[key].encoding !== "Identity-H") { + return { + text: text, + x: x, + y: y, + options: options, + mutex: mutex + }; + } + + strText = text; + key = activeFontKey; + + if (Array.isArray(text)) { + strText = text[0]; + } + + for (s = 0; s < strText.length; s += 1) { + if (fonts[key].metadata.hasOwnProperty("cmap")) { + cmapConfirm = fonts[key].metadata.cmap.unicode.codeMap[strText[s].charCodeAt(0)]; + /* + if (Object.prototype.toString.call(text) === '[object Array]') { + var i = 0; + // for (i = 0; i < text.length; i += 1) { + if (Object.prototype.toString.call(text[s]) === '[object Array]') { + cmapConfirm = fonts[key].metadata.cmap.unicode.codeMap[strText[s][0].charCodeAt(0)]; //Make sure the cmap has the corresponding glyph id + } else { + + } + //} + + } else { + cmapConfirm = fonts[key].metadata.cmap.unicode.codeMap[strText[s].charCodeAt(0)]; //Make sure the cmap has the corresponding glyph id + }*/ + } + + if (!cmapConfirm) { + if (strText[s].charCodeAt(0) < 256 && fonts[key].metadata.hasOwnProperty("Unicode")) { + str += strText[s]; + } else { + str += ""; + } + } else { + str += strText[s]; + } + } + + var result = ""; + + if (parseInt(key.slice(1)) < 14 || encoding === "WinAnsiEncoding") { + //For the default 13 font + result = pdfEscape(str, key).split("").map(function (cv) { + return cv.charCodeAt(0).toString(16); + }).join(""); + } else if (encoding === "Identity-H") { + result = pdfEscape16(str, fonts[key]); + } + + mutex.isHex = true; + return { + text: result, + x: x, + y: y, + options: options, + mutex: mutex + }; + }; + + var utf8EscapeFunction = function utf8EscapeFunction(parms) { + var text = parms.text || "", + x = parms.x, + y = parms.y, + options = parms.options, + mutex = parms.mutex; + var tmpText = []; + var args = { + text: text, + x: x, + y: y, + options: options, + mutex: mutex + }; + + if (Array.isArray(text)) { + var i = 0; + + for (i = 0; i < text.length; i += 1) { + if (Array.isArray(text[i])) { + if (text[i].length === 3) { + tmpText.push([utf8TextFunction(Object.assign({}, args, { + text: text[i][0] + })).text, text[i][1], text[i][2]]); + } else { + tmpText.push(utf8TextFunction(Object.assign({}, args, { + text: text[i] + })).text); + } + } else { + tmpText.push(utf8TextFunction(Object.assign({}, args, { + text: text[i] + })).text); + } + } + + parms.text = tmpText; + } else { + parms.text = utf8TextFunction(Object.assign({}, args, { + text: text + })).text; + } + }; + + jsPDFAPI.events.push(["postProcessText", utf8EscapeFunction]); +})(jsPDF); + +/* global jsPDF */ + +/* + * Copyright (c) 2012 chick307 + * + * Licensed under the MIT License. + * http://opensource.org/licenses/mit-license + */ +(function (jsPDF, callback) { + jsPDF.API.adler32cs = callback(); +})(jsPDF, function () { + var _hasArrayBuffer = typeof ArrayBuffer === "function" && typeof Uint8Array === "function"; + + var _Buffer = null, + _isBuffer = function () { + if (!_hasArrayBuffer) { return function _isBuffer() { + return false; + }; } + + try { + var buffer = {}; + if (typeof buffer.Buffer === "function") { _Buffer = buffer.Buffer; } // eslint-disable-next-line no-empty + } catch (error) {} + + return function _isBuffer(value) { + return value instanceof ArrayBuffer || _Buffer !== null && value instanceof _Buffer; + }; + }(); + + var _utf8ToBinary = function () { + if (_Buffer !== null) { + return function _utf8ToBinary(utf8String) { + return new _Buffer(utf8String, "utf8").toString("binary"); + }; + } else { + return function _utf8ToBinary(utf8String) { + return unescape(encodeURIComponent(utf8String)); + }; + } + }(); + + var MOD = 65521; + + var _update = function _update(checksum, binaryString) { + var a = checksum & 0xffff, + b = checksum >>> 16; + + for (var i = 0, length = binaryString.length; i < length; i++) { + a = (a + (binaryString.charCodeAt(i) & 0xff)) % MOD; + b = (b + a) % MOD; + } + + return (b << 16 | a) >>> 0; + }; + + var _updateUint8Array = function _updateUint8Array(checksum, uint8Array) { + var a = checksum & 0xffff, + b = checksum >>> 16; + + for (var i = 0, length = uint8Array.length; i < length; i++) { + a = (a + uint8Array[i]) % MOD; + b = (b + a) % MOD; + } + + return (b << 16 | a) >>> 0; + }; + + var exports = {}; + + var Adler32 = exports.Adler32 = function () { + var ctor = function Adler32(checksum) { + if (!(this instanceof ctor)) { + throw new TypeError("Constructor cannot called be as a function."); + } + + if (!isFinite(checksum = checksum === null ? 1 : +checksum)) { + throw new Error("First arguments needs to be a finite number."); + } + + this.checksum = checksum >>> 0; + }; + + var proto = ctor.prototype = {}; + proto.constructor = ctor; + + ctor.from = function (from) { + from.prototype = proto; + return from; + }(function from(binaryString) { + if (!(this instanceof ctor)) { + throw new TypeError("Constructor cannot called be as a function."); + } + + if (binaryString === null) { throw new Error("First argument needs to be a string."); } + this.checksum = _update(1, binaryString.toString()); + }); + + ctor.fromUtf8 = function (fromUtf8) { + fromUtf8.prototype = proto; + return fromUtf8; + }(function fromUtf8(utf8String) { + if (!(this instanceof ctor)) { + throw new TypeError("Constructor cannot called be as a function."); + } + + if (utf8String === null) { throw new Error("First argument needs to be a string."); } + + var binaryString = _utf8ToBinary(utf8String.toString()); + + this.checksum = _update(1, binaryString); + }); + + if (_hasArrayBuffer) { + ctor.fromBuffer = function (fromBuffer) { + fromBuffer.prototype = proto; + return fromBuffer; + }(function fromBuffer(buffer) { + if (!(this instanceof ctor)) { + throw new TypeError("Constructor cannot called be as a function."); + } + + if (!_isBuffer(buffer)) { throw new Error("First argument needs to be ArrayBuffer."); } + var array = new Uint8Array(buffer); + return this.checksum = _updateUint8Array(1, array); + }); + } + + proto.update = function update(binaryString) { + if (binaryString === null) { throw new Error("First argument needs to be a string."); } + binaryString = binaryString.toString(); + return this.checksum = _update(this.checksum, binaryString); + }; + + proto.updateUtf8 = function updateUtf8(utf8String) { + if (utf8String === null) { throw new Error("First argument needs to be a string."); } + + var binaryString = _utf8ToBinary(utf8String.toString()); + + return this.checksum = _update(this.checksum, binaryString); + }; + + if (_hasArrayBuffer) { + proto.updateBuffer = function updateBuffer(buffer) { + if (!_isBuffer(buffer)) { throw new Error("First argument needs to be ArrayBuffer."); } + var array = new Uint8Array(buffer); + return this.checksum = _updateUint8Array(this.checksum, array); + }; + } + + proto.clone = function clone() { + return new Adler32(this.checksum); + }; + + return ctor; + }(); + + exports.from = function from(binaryString) { + if (binaryString === null) { throw new Error("First argument needs to be a string."); } + return _update(1, binaryString.toString()); + }; + + exports.fromUtf8 = function fromUtf8(utf8String) { + if (utf8String === null) { throw new Error("First argument needs to be a string."); } + + var binaryString = _utf8ToBinary(utf8String.toString()); + + return _update(1, binaryString); + }; + + if (_hasArrayBuffer) { + exports.fromBuffer = function fromBuffer(buffer) { + if (!_isBuffer(buffer)) { throw new Error("First argument need to be ArrayBuffer."); } + var array = new Uint8Array(buffer); + return _updateUint8Array(1, array); + }; + } + + return exports; +}); + +/** + * Unicode Bidi Engine based on the work of Alex Shensis (@asthensis) + * MIT License + */ +(function (jsPDF) { + /** + * Table of Unicode types. + * + * Generated by: + * + * var bidi = require("./bidi/index"); + * var bidi_accumulate = bidi.slice(0, 256).concat(bidi.slice(0x0500, 0x0500 + 256 * 3)). + * concat(bidi.slice(0x2000, 0x2000 + 256)).concat(bidi.slice(0xFB00, 0xFB00 + 256)). + * concat(bidi.slice(0xFE00, 0xFE00 + 2 * 256)); + * + * for( var i = 0; i < bidi_accumulate.length; i++) { + * if(bidi_accumulate[i] === undefined || bidi_accumulate[i] === 'ON') + * bidi_accumulate[i] = 'N'; //mark as neutral to conserve space and substitute undefined + * } + * var bidiAccumulateStr = 'return [ "' + bidi_accumulate.toString().replace(/,/g, '", "') + '" ];'; + * require("fs").writeFile('unicode-types.js', bidiAccumulateStr); + * + * Based on: + * https://github.com/mathiasbynens/unicode-8.0.0 + */ + + var bidiUnicodeTypes = ["BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "S", "B", "S", "WS", "B", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "B", "B", "B", "S", "WS", "N", "N", "ET", "ET", "ET", "N", "N", "N", "N", "N", "ES", "CS", "ES", "CS", "CS", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "CS", "N", "N", "N", "N", "N", "N", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "N", "N", "N", "N", "N", "N", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "N", "N", "N", "N", "BN", "BN", "BN", "BN", "BN", "BN", "B", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "CS", "N", "ET", "ET", "ET", "ET", "N", "N", "N", "N", "L", "N", "N", "BN", "N", "N", "ET", "ET", "EN", "EN", "N", "L", "N", "N", "N", "EN", "L", "N", "N", "N", "N", "N", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "N", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "N", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "N", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "N", "N", "L", "L", "L", "L", "L", "L", "L", "N", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "N", "L", "N", "N", "N", "N", "N", "ET", "N", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "R", "NSM", "R", "NSM", "NSM", "R", "NSM", "NSM", "R", "NSM", "N", "N", "N", "N", "N", "N", "N", "N", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "N", "N", "N", "N", "N", "R", "R", "R", "R", "R", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "AN", "AN", "AN", "AN", "AN", "AN", "N", "N", "AL", "ET", "ET", "AL", "CS", "AL", "N", "N", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "AL", "AL", "N", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "AN", "AN", "AN", "AN", "AN", "AN", "AN", "AN", "AN", "AN", "ET", "AN", "AN", "AL", "AL", "AL", "NSM", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "AN", "N", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "AL", "AL", "NSM", "NSM", "N", "NSM", "NSM", "NSM", "NSM", "AL", "AL", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "N", "AL", "AL", "NSM", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "N", "N", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "AL", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "R", "R", "N", "N", "N", "N", "R", "N", "N", "N", "N", "N", "WS", "WS", "WS", "WS", "WS", "WS", "WS", "WS", "WS", "WS", "WS", "BN", "BN", "BN", "L", "R", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "WS", "B", "LRE", "RLE", "PDF", "LRO", "RLO", "CS", "ET", "ET", "ET", "ET", "ET", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "CS", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "WS", "BN", "BN", "BN", "BN", "BN", "N", "LRI", "RLI", "FSI", "PDI", "BN", "BN", "BN", "BN", "BN", "BN", "EN", "L", "N", "N", "EN", "EN", "EN", "EN", "EN", "EN", "ES", "ES", "N", "N", "N", "L", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "ES", "ES", "N", "N", "N", "N", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "N", "N", "N", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "ET", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "L", "L", "L", "L", "L", "L", "L", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "L", "L", "L", "L", "L", "N", "N", "N", "N", "N", "R", "NSM", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "ES", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "N", "R", "R", "R", "R", "R", "N", "R", "N", "R", "R", "N", "R", "R", "N", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "CS", "N", "CS", "N", "N", "CS", "N", "N", "N", "N", "N", "N", "N", "N", "N", "ET", "N", "N", "ES", "ES", "N", "N", "N", "N", "N", "ET", "ET", "N", "N", "N", "N", "N", "AL", "AL", "AL", "AL", "AL", "N", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "N", "N", "BN", "N", "N", "N", "ET", "ET", "ET", "N", "N", "N", "N", "N", "ES", "CS", "ES", "CS", "CS", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "CS", "N", "N", "N", "N", "N", "N", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "N", "N", "N", "N", "N", "N", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "N", "N", "N", "L", "L", "L", "L", "L", "L", "N", "N", "L", "L", "L", "L", "L", "L", "N", "N", "L", "L", "L", "L", "L", "L", "N", "N", "L", "L", "L", "N", "N", "N", "ET", "ET", "N", "N", "N", "ET", "ET", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"]; + /** + * Unicode Bidi algorithm compliant Bidi engine. + * For reference see http://unicode.org/reports/tr9/ + */ + + /** + * constructor ( options ) + * + * Initializes Bidi engine + * + * @param {Object} See 'setOptions' below for detailed description. + * options are cashed between invocation of 'doBidiReorder' method + * + * sample usage pattern of BidiEngine: + * var opt = { + * isInputVisual: true, + * isInputRtl: false, + * isOutputVisual: false, + * isOutputRtl: false, + * isSymmetricSwapping: true + * } + * var sourceToTarget = [], levels = []; + * var bidiEng = Globalize.bidiEngine(opt); + * var src = "text string to be reordered"; + * var ret = bidiEng.doBidiReorder(src, sourceToTarget, levels); + */ + + jsPDF.__bidiEngine__ = jsPDF.prototype.__bidiEngine__ = function (options) { + var _UNICODE_TYPES = _bidiUnicodeTypes; + var _STATE_TABLE_LTR = [[0, 3, 0, 1, 0, 0, 0], [0, 3, 0, 1, 2, 2, 0], [0, 3, 0, 0x11, 2, 0, 1], [0, 3, 5, 5, 4, 1, 0], [0, 3, 0x15, 0x15, 4, 0, 1], [0, 3, 5, 5, 4, 2, 0]]; + var _STATE_TABLE_RTL = [[2, 0, 1, 1, 0, 1, 0], [2, 0, 1, 1, 0, 2, 0], [2, 0, 2, 1, 3, 2, 0], [2, 0, 2, 0x21, 3, 1, 1]]; + var _TYPE_NAMES_MAP = { + L: 0, + R: 1, + EN: 2, + AN: 3, + N: 4, + B: 5, + S: 6 + }; + var _UNICODE_RANGES_MAP = { + 0: 0, + 5: 1, + 6: 2, + 7: 3, + 0x20: 4, + 0xfb: 5, + 0xfe: 6, + 0xff: 7 + }; + var _SWAP_TABLE = ["(", ")", "(", "<", ">", "<", "[", "]", "[", "{", "}", "{", "\xAB", "\xBB", "\xAB", "\u2039", "\u203A", "\u2039", "\u2045", "\u2046", "\u2045", "\u207D", "\u207E", "\u207D", "\u208D", "\u208E", "\u208D", "\u2264", "\u2265", "\u2264", "\u2329", "\u232A", "\u2329", "\uFE59", "\uFE5A", "\uFE59", "\uFE5B", "\uFE5C", "\uFE5B", "\uFE5D", "\uFE5E", "\uFE5D", "\uFE64", "\uFE65", "\uFE64"]; + + var _LTR_RANGES_REG_EXPR = new RegExp(/^([1-4|9]|1[0-9]|2[0-9]|3[0168]|4[04589]|5[012]|7[78]|159|16[0-9]|17[0-2]|21[569]|22[03489]|250)$/); + + var _lastArabic = false, + _hasUbatB, + _hasUbatS, + DIR_LTR = 0, + DIR_RTL = 1, + _isInVisual, + _isInRtl, + _isOutVisual, + _isOutRtl, + _isSymmetricSwapping, + _dir = DIR_LTR; + + this.__bidiEngine__ = {}; + + var _init = function _init(text, sourceToTargetMap) { + if (sourceToTargetMap) { + for (var i = 0; i < text.length; i++) { + sourceToTargetMap[i] = i; + } + } + + if (_isInRtl === undefined) { + _isInRtl = _isContextualDirRtl(text); + } + + if (_isOutRtl === undefined) { + _isOutRtl = _isContextualDirRtl(text); + } + }; // for reference see 3.2 in http://unicode.org/reports/tr9/ + // + + + var _getCharType = function _getCharType(ch) { + var charCode = ch.charCodeAt(), + range = charCode >> 8, + rangeIdx = _UNICODE_RANGES_MAP[range]; + + if (rangeIdx !== undefined) { + return _UNICODE_TYPES[rangeIdx * 256 + (charCode & 0xff)]; + } else if (range === 0xfc || range === 0xfd) { + return "AL"; + } else if (_LTR_RANGES_REG_EXPR.test(range)) { + //unlikely case + return "L"; + } else if (range === 8) { + // even less likely + return "R"; + } + + return "N"; //undefined type, mark as neutral + }; + + var _isContextualDirRtl = function _isContextualDirRtl(text) { + for (var i = 0, charType; i < text.length; i++) { + charType = _getCharType(text.charAt(i)); + + if (charType === "L") { + return false; + } else if (charType === "R") { + return true; + } + } + + return false; + }; // for reference see 3.3.4 & 3.3.5 in http://unicode.org/reports/tr9/ + // + + + var _resolveCharType = function _resolveCharType(chars, types, resolvedTypes, index) { + var cType = types[index], + wType, + nType, + i, + len; + + switch (cType) { + case "L": + case "R": + _lastArabic = false; + break; + + case "N": + case "AN": + break; + + case "EN": + if (_lastArabic) { + cType = "AN"; + } + + break; + + case "AL": + _lastArabic = true; + cType = "R"; + break; + + case "WS": + cType = "N"; + break; + + case "CS": + if (index < 1 || index + 1 >= types.length || (wType = resolvedTypes[index - 1]) !== "EN" && wType !== "AN" || (nType = types[index + 1]) !== "EN" && nType !== "AN") { + cType = "N"; + } else if (_lastArabic) { + nType = "AN"; + } + + cType = nType === wType ? nType : "N"; + break; + + case "ES": + wType = index > 0 ? resolvedTypes[index - 1] : "B"; + cType = wType === "EN" && index + 1 < types.length && types[index + 1] === "EN" ? "EN" : "N"; + break; + + case "ET": + if (index > 0 && resolvedTypes[index - 1] === "EN") { + cType = "EN"; + break; + } else if (_lastArabic) { + cType = "N"; + break; + } + + i = index + 1; + len = types.length; + + while (i < len && types[i] === "ET") { + i++; + } + + if (i < len && types[i] === "EN") { + cType = "EN"; + } else { + cType = "N"; + } + + break; + + case "NSM": + if (_isInVisual && !_isInRtl) { + //V->L + len = types.length; + i = index + 1; + + while (i < len && types[i] === "NSM") { + i++; + } + + if (i < len) { + var c = chars[index]; + var rtlCandidate = c >= 0x0591 && c <= 0x08ff || c === 0xfb1e; + wType = types[i]; + + if (rtlCandidate && (wType === "R" || wType === "AL")) { + cType = "R"; + break; + } + } + } + + if (index < 1 || (wType = types[index - 1]) === "B") { + cType = "N"; + } else { + cType = resolvedTypes[index - 1]; + } + + break; + + case "B": + _lastArabic = false; + _hasUbatB = true; + cType = _dir; + break; + + case "S": + _hasUbatS = true; + cType = "N"; + break; + + case "LRE": + case "RLE": + case "LRO": + case "RLO": + case "PDF": + _lastArabic = false; + break; + + case "BN": + cType = "N"; + break; + } + + return cType; + }; + + var _handleUbatS = function _handleUbatS(types, levels, length) { + for (var i = 0; i < length; i++) { + if (types[i] === "S") { + levels[i] = _dir; + + for (var j = i - 1; j >= 0; j--) { + if (types[j] === "WS") { + levels[j] = _dir; + } else { + break; + } + } + } + } + }; + + var _invertString = function _invertString(text, sourceToTargetMap, levels) { + var charArray = text.split(""); + + if (levels) { + _computeLevels(charArray, levels, { + hiLevel: _dir + }); + } + + charArray.reverse(); + sourceToTargetMap && sourceToTargetMap.reverse(); + return charArray.join(""); + }; // For reference see 3.3 in http://unicode.org/reports/tr9/ + // + + + var _computeLevels = function _computeLevels(chars, levels, params) { + var action, + condition, + i, + index, + newLevel, + prevState, + condPos = -1, + len = chars.length, + newState = 0, + resolvedTypes = [], + stateTable = _dir ? _STATE_TABLE_RTL : _STATE_TABLE_LTR, + types = []; + _lastArabic = false; + _hasUbatB = false; + _hasUbatS = false; + + for (i = 0; i < len; i++) { + types[i] = _getCharType(chars[i]); + } + + for (index = 0; index < len; index++) { + prevState = newState; + resolvedTypes[index] = _resolveCharType(chars, types, resolvedTypes, index); + newState = stateTable[prevState][_TYPE_NAMES_MAP[resolvedTypes[index]]]; + action = newState & 0xf0; + newState &= 0x0f; + levels[index] = newLevel = stateTable[newState][5]; + + if (action > 0) { + if (action === 0x10) { + for (i = condPos; i < index; i++) { + levels[i] = 1; + } + + condPos = -1; + } else { + condPos = -1; + } + } + + condition = stateTable[newState][6]; + + if (condition) { + if (condPos === -1) { + condPos = index; + } + } else { + if (condPos > -1) { + for (i = condPos; i < index; i++) { + levels[i] = newLevel; + } + + condPos = -1; + } + } + + if (types[index] === "B") { + levels[index] = 0; + } + + params.hiLevel |= newLevel; + } + + if (_hasUbatS) { + _handleUbatS(types, levels, len); + } + }; // for reference see 3.4 in http://unicode.org/reports/tr9/ + // + + + var _invertByLevel = function _invertByLevel(level, charArray, sourceToTargetMap, levels, params) { + if (params.hiLevel < level) { + return; + } + + if (level === 1 && _dir === DIR_RTL && !_hasUbatB) { + charArray.reverse(); + sourceToTargetMap && sourceToTargetMap.reverse(); + return; + } + + var ch, + high, + end, + low, + len = charArray.length, + start = 0; + + while (start < len) { + if (levels[start] >= level) { + end = start + 1; + + while (end < len && levels[end] >= level) { + end++; + } + + for (low = start, high = end - 1; low < high; low++, high--) { + ch = charArray[low]; + charArray[low] = charArray[high]; + charArray[high] = ch; + + if (sourceToTargetMap) { + ch = sourceToTargetMap[low]; + sourceToTargetMap[low] = sourceToTargetMap[high]; + sourceToTargetMap[high] = ch; + } + } + + start = end; + } + + start++; + } + }; // for reference see 7 & BD16 in http://unicode.org/reports/tr9/ + // + + + var _symmetricSwap = function _symmetricSwap(charArray, levels, params) { + if (params.hiLevel !== 0 && _isSymmetricSwapping) { + for (var i = 0, index; i < charArray.length; i++) { + if (levels[i] === 1) { + index = _SWAP_TABLE.indexOf(charArray[i]); + + if (index >= 0) { + charArray[i] = _SWAP_TABLE[index + 1]; + } + } + } + } + }; + + var _reorder = function _reorder(text, sourceToTargetMap, levels) { + var charArray = text.split(""), + params = { + hiLevel: _dir + }; + + if (!levels) { + levels = []; + } + + _computeLevels(charArray, levels, params); + + _symmetricSwap(charArray, levels, params); + + _invertByLevel(DIR_RTL + 1, charArray, sourceToTargetMap, levels, params); + + _invertByLevel(DIR_RTL, charArray, sourceToTargetMap, levels, params); + + return charArray.join(""); + }; // doBidiReorder( text, sourceToTargetMap, levels ) + // Performs Bidi reordering by implementing Unicode Bidi algorithm. + // Returns reordered string + // @text [String]: + // - input string to be reordered, this is input parameter + // $sourceToTargetMap [Array] (optional) + // - resultant mapping between input and output strings, this is output parameter + // $levels [Array] (optional) + // - array of calculated Bidi levels, , this is output parameter + + + this.__bidiEngine__.doBidiReorder = function (text, sourceToTargetMap, levels) { + _init(text, sourceToTargetMap); + + if (!_isInVisual && _isOutVisual && !_isOutRtl) { + // LLTR->VLTR, LRTL->VLTR + _dir = _isInRtl ? DIR_RTL : DIR_LTR; + text = _reorder(text, sourceToTargetMap, levels); + } else if (_isInVisual && _isOutVisual && _isInRtl ^ _isOutRtl) { + // VRTL->VLTR, VLTR->VRTL + _dir = _isInRtl ? DIR_RTL : DIR_LTR; + text = _invertString(text, sourceToTargetMap, levels); + } else if (!_isInVisual && _isOutVisual && _isOutRtl) { + // LLTR->VRTL, LRTL->VRTL + _dir = _isInRtl ? DIR_RTL : DIR_LTR; + text = _reorder(text, sourceToTargetMap, levels); + text = _invertString(text, sourceToTargetMap); + } else if (_isInVisual && !_isInRtl && !_isOutVisual && !_isOutRtl) { + // VLTR->LLTR + _dir = DIR_LTR; + text = _reorder(text, sourceToTargetMap, levels); + } else if (_isInVisual && !_isOutVisual && _isInRtl ^ _isOutRtl) { + // VLTR->LRTL, VRTL->LLTR + text = _invertString(text, sourceToTargetMap); + + if (_isInRtl) { + //LLTR -> VLTR + _dir = DIR_LTR; + text = _reorder(text, sourceToTargetMap, levels); + } else { + //LRTL -> VRTL + _dir = DIR_RTL; + text = _reorder(text, sourceToTargetMap, levels); + text = _invertString(text, sourceToTargetMap); + } + } else if (_isInVisual && _isInRtl && !_isOutVisual && _isOutRtl) { + // VRTL->LRTL + _dir = DIR_RTL; + text = _reorder(text, sourceToTargetMap, levels); + text = _invertString(text, sourceToTargetMap); + } else if (!_isInVisual && !_isOutVisual && _isInRtl ^ _isOutRtl) { + // LRTL->LLTR, LLTR->LRTL + var isSymmetricSwappingOrig = _isSymmetricSwapping; + + if (_isInRtl) { + //LRTL->LLTR + _dir = DIR_RTL; + text = _reorder(text, sourceToTargetMap, levels); + _dir = DIR_LTR; + _isSymmetricSwapping = false; + text = _reorder(text, sourceToTargetMap, levels); + _isSymmetricSwapping = isSymmetricSwappingOrig; + } else { + //LLTR->LRTL + _dir = DIR_LTR; + text = _reorder(text, sourceToTargetMap, levels); + text = _invertString(text, sourceToTargetMap); + _dir = DIR_RTL; + _isSymmetricSwapping = false; + text = _reorder(text, sourceToTargetMap, levels); + _isSymmetricSwapping = isSymmetricSwappingOrig; + text = _invertString(text, sourceToTargetMap); + } + } + + return text; + }; + /** + * @name setOptions( options ) + * @function + * Sets options for Bidi conversion + * @param {Object}: + * - isInputVisual {boolean} (defaults to false): allowed values: true(Visual mode), false(Logical mode) + * - isInputRtl {boolean}: allowed values true(Right-to-left direction), false (Left-to-right directiion), undefined(Contectual direction, i.e.direction defined by first strong character of input string) + * - isOutputVisual {boolean} (defaults to false): allowed values: true(Visual mode), false(Logical mode) + * - isOutputRtl {boolean}: allowed values true(Right-to-left direction), false (Left-to-right directiion), undefined(Contectual direction, i.e.direction defined by first strong characterof input string) + * - isSymmetricSwapping {boolean} (defaults to false): allowed values true(needs symmetric swapping), false (no need in symmetric swapping), + */ + + + this.__bidiEngine__.setOptions = function (options) { + if (options) { + _isInVisual = options.isInputVisual; + _isOutVisual = options.isOutputVisual; + _isInRtl = options.isInputRtl; + _isOutRtl = options.isOutputRtl; + _isSymmetricSwapping = options.isSymmetricSwapping; + } + }; + + this.__bidiEngine__.setOptions(options); + + return this.__bidiEngine__; + }; + + var _bidiUnicodeTypes = bidiUnicodeTypes; + var bidiEngine = new jsPDF.__bidiEngine__({ + isInputVisual: true + }); + + var bidiEngineFunction = function bidiEngineFunction(args) { + var text = args.text; + var x = args.x; + var y = args.y; + var options = args.options || {}; + var mutex = args.mutex || {}; + var lang = options.lang; + var tmpText = []; + options.isInputVisual = typeof options.isInputVisual === "boolean" ? options.isInputVisual : true; + bidiEngine.setOptions(options); + + if (Object.prototype.toString.call(text) === "[object Array]") { + var i = 0; + tmpText = []; + + for (i = 0; i < text.length; i += 1) { + if (Object.prototype.toString.call(text[i]) === "[object Array]") { + tmpText.push([bidiEngine.doBidiReorder(text[i][0]), text[i][1], text[i][2]]); + } else { + tmpText.push([bidiEngine.doBidiReorder(text[i])]); + } + } + + args.text = tmpText; + } else { + args.text = bidiEngine.doBidiReorder(text); + } + + bidiEngine.setOptions({ + isInputVisual: true + }); + }; + + jsPDF.API.events.push(["postProcessText", bidiEngineFunction]); +})(jsPDF); + +/* + Copyright (c) 2008, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* +JPEG encoder ported to JavaScript and optimized by Andreas Ritter, www.bytestrom.eu, 11/2009 + +Basic GUI blocking jpeg encoder +*/ +function JPEGEncoder(quality) { + var ffloor = Math.floor; + var YTable = new Array(64); + var UVTable = new Array(64); + var fdtbl_Y = new Array(64); + var fdtbl_UV = new Array(64); + var YDC_HT; + var UVDC_HT; + var YAC_HT; + var UVAC_HT; + var bitcode = new Array(65535); + var category = new Array(65535); + var outputfDCTQuant = new Array(64); + var DU = new Array(64); + var byteout = []; + var bytenew = 0; + var bytepos = 7; + var YDU = new Array(64); + var UDU = new Array(64); + var VDU = new Array(64); + var clt = new Array(256); + var RGB_YUV_TABLE = new Array(2048); + var currentQuality; + var ZigZag = [0, 1, 5, 6, 14, 15, 27, 28, 2, 4, 7, 13, 16, 26, 29, 42, 3, 8, 12, 17, 25, 30, 41, 43, 9, 11, 18, 24, 31, 40, 44, 53, 10, 19, 23, 32, 39, 45, 52, 54, 20, 22, 33, 38, 46, 51, 55, 60, 21, 34, 37, 47, 50, 56, 59, 61, 35, 36, 48, 49, 57, 58, 62, 63]; + var std_dc_luminance_nrcodes = [0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]; + var std_dc_luminance_values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; + var std_ac_luminance_nrcodes = [0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d]; + var std_ac_luminance_values = [0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa]; + var std_dc_chrominance_nrcodes = [0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]; + var std_dc_chrominance_values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; + var std_ac_chrominance_nrcodes = [0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77]; + var std_ac_chrominance_values = [0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa]; + + function initQuantTables(sf) { + var YQT = [16, 11, 10, 16, 24, 40, 51, 61, 12, 12, 14, 19, 26, 58, 60, 55, 14, 13, 16, 24, 40, 57, 69, 56, 14, 17, 22, 29, 51, 87, 80, 62, 18, 22, 37, 56, 68, 109, 103, 77, 24, 35, 55, 64, 81, 104, 113, 92, 49, 64, 78, 87, 103, 121, 120, 101, 72, 92, 95, 98, 112, 100, 103, 99]; + + for (var i = 0; i < 64; i++) { + var t = ffloor((YQT[i] * sf + 50) / 100); + t = Math.min(Math.max(t, 1), 255); + YTable[ZigZag[i]] = t; + } + + var UVQT = [17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99, 24, 26, 56, 99, 99, 99, 99, 99, 47, 66, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99]; + + for (var j = 0; j < 64; j++) { + var u = ffloor((UVQT[j] * sf + 50) / 100); + u = Math.min(Math.max(u, 1), 255); + UVTable[ZigZag[j]] = u; + } + + var aasf = [1.0, 1.387039845, 1.306562965, 1.175875602, 1.0, 0.785694958, 0.5411961, 0.275899379]; + var k = 0; + + for (var row = 0; row < 8; row++) { + for (var col = 0; col < 8; col++) { + fdtbl_Y[k] = 1.0 / (YTable[ZigZag[k]] * aasf[row] * aasf[col] * 8.0); + fdtbl_UV[k] = 1.0 / (UVTable[ZigZag[k]] * aasf[row] * aasf[col] * 8.0); + k++; + } + } + } + + function computeHuffmanTbl(nrcodes, std_table) { + var codevalue = 0; + var pos_in_table = 0; + var HT = new Array(); + + for (var k = 1; k <= 16; k++) { + for (var j = 1; j <= nrcodes[k]; j++) { + HT[std_table[pos_in_table]] = []; + HT[std_table[pos_in_table]][0] = codevalue; + HT[std_table[pos_in_table]][1] = k; + pos_in_table++; + codevalue++; + } + + codevalue *= 2; + } + + return HT; + } + + function initHuffmanTbl() { + YDC_HT = computeHuffmanTbl(std_dc_luminance_nrcodes, std_dc_luminance_values); + UVDC_HT = computeHuffmanTbl(std_dc_chrominance_nrcodes, std_dc_chrominance_values); + YAC_HT = computeHuffmanTbl(std_ac_luminance_nrcodes, std_ac_luminance_values); + UVAC_HT = computeHuffmanTbl(std_ac_chrominance_nrcodes, std_ac_chrominance_values); + } + + function initCategoryNumber() { + var nrlower = 1; + var nrupper = 2; + + for (var cat = 1; cat <= 15; cat++) { + //Positive numbers + for (var nr = nrlower; nr < nrupper; nr++) { + category[32767 + nr] = cat; + bitcode[32767 + nr] = []; + bitcode[32767 + nr][1] = cat; + bitcode[32767 + nr][0] = nr; + } //Negative numbers + + + for (var nrneg = -(nrupper - 1); nrneg <= -nrlower; nrneg++) { + category[32767 + nrneg] = cat; + bitcode[32767 + nrneg] = []; + bitcode[32767 + nrneg][1] = cat; + bitcode[32767 + nrneg][0] = nrupper - 1 + nrneg; + } + + nrlower <<= 1; + nrupper <<= 1; + } + } + + function initRGBYUVTable() { + for (var i = 0; i < 256; i++) { + RGB_YUV_TABLE[i] = 19595 * i; + RGB_YUV_TABLE[i + 256 >> 0] = 38470 * i; + RGB_YUV_TABLE[i + 512 >> 0] = 7471 * i + 0x8000; + RGB_YUV_TABLE[i + 768 >> 0] = -11059 * i; + RGB_YUV_TABLE[i + 1024 >> 0] = -21709 * i; + RGB_YUV_TABLE[i + 1280 >> 0] = 32768 * i + 0x807fff; + RGB_YUV_TABLE[i + 1536 >> 0] = -27439 * i; + RGB_YUV_TABLE[i + 1792 >> 0] = -5329 * i; + } + } // IO functions + + + function writeBits(bs) { + var value = bs[0]; + var posval = bs[1] - 1; + + while (posval >= 0) { + if (value & 1 << posval) { + bytenew |= 1 << bytepos; + } + + posval--; + bytepos--; + + if (bytepos < 0) { + if (bytenew == 0xff) { + writeByte(0xff); + writeByte(0); + } else { + writeByte(bytenew); + } + + bytepos = 7; + bytenew = 0; + } + } + } + + function writeByte(value) { + //byteout.push(clt[value]); // write char directly instead of converting later + byteout.push(value); + } + + function writeWord(value) { + writeByte(value >> 8 & 0xff); + writeByte(value & 0xff); + } // DCT & quantization core + + + function fDCTQuant(data, fdtbl) { + var d0, d1, d2, d3, d4, d5, d6, d7; + /* Pass 1: process rows. */ + + var dataOff = 0; + var i; + var I8 = 8; + var I64 = 64; + + for (i = 0; i < I8; ++i) { + d0 = data[dataOff]; + d1 = data[dataOff + 1]; + d2 = data[dataOff + 2]; + d3 = data[dataOff + 3]; + d4 = data[dataOff + 4]; + d5 = data[dataOff + 5]; + d6 = data[dataOff + 6]; + d7 = data[dataOff + 7]; + var tmp0 = d0 + d7; + var tmp7 = d0 - d7; + var tmp1 = d1 + d6; + var tmp6 = d1 - d6; + var tmp2 = d2 + d5; + var tmp5 = d2 - d5; + var tmp3 = d3 + d4; + var tmp4 = d3 - d4; + /* Even part */ + + var tmp10 = tmp0 + tmp3; + /* phase 2 */ + + var tmp13 = tmp0 - tmp3; + var tmp11 = tmp1 + tmp2; + var tmp12 = tmp1 - tmp2; + data[dataOff] = tmp10 + tmp11; + /* phase 3 */ + + data[dataOff + 4] = tmp10 - tmp11; + var z1 = (tmp12 + tmp13) * 0.707106781; + /* c4 */ + + data[dataOff + 2] = tmp13 + z1; + /* phase 5 */ + + data[dataOff + 6] = tmp13 - z1; + /* Odd part */ + + tmp10 = tmp4 + tmp5; + /* phase 2 */ + + tmp11 = tmp5 + tmp6; + tmp12 = tmp6 + tmp7; + /* The rotator is modified from fig 4-8 to avoid extra negations. */ + + var z5 = (tmp10 - tmp12) * 0.382683433; + /* c6 */ + + var z2 = 0.5411961 * tmp10 + z5; + /* c2-c6 */ + + var z4 = 1.306562965 * tmp12 + z5; + /* c2+c6 */ + + var z3 = tmp11 * 0.707106781; + /* c4 */ + + var z11 = tmp7 + z3; + /* phase 5 */ + + var z13 = tmp7 - z3; + data[dataOff + 5] = z13 + z2; + /* phase 6 */ + + data[dataOff + 3] = z13 - z2; + data[dataOff + 1] = z11 + z4; + data[dataOff + 7] = z11 - z4; + dataOff += 8; + /* advance pointer to next row */ + } + /* Pass 2: process columns. */ + + + dataOff = 0; + + for (i = 0; i < I8; ++i) { + d0 = data[dataOff]; + d1 = data[dataOff + 8]; + d2 = data[dataOff + 16]; + d3 = data[dataOff + 24]; + d4 = data[dataOff + 32]; + d5 = data[dataOff + 40]; + d6 = data[dataOff + 48]; + d7 = data[dataOff + 56]; + var tmp0p2 = d0 + d7; + var tmp7p2 = d0 - d7; + var tmp1p2 = d1 + d6; + var tmp6p2 = d1 - d6; + var tmp2p2 = d2 + d5; + var tmp5p2 = d2 - d5; + var tmp3p2 = d3 + d4; + var tmp4p2 = d3 - d4; + /* Even part */ + + var tmp10p2 = tmp0p2 + tmp3p2; + /* phase 2 */ + + var tmp13p2 = tmp0p2 - tmp3p2; + var tmp11p2 = tmp1p2 + tmp2p2; + var tmp12p2 = tmp1p2 - tmp2p2; + data[dataOff] = tmp10p2 + tmp11p2; + /* phase 3 */ + + data[dataOff + 32] = tmp10p2 - tmp11p2; + var z1p2 = (tmp12p2 + tmp13p2) * 0.707106781; + /* c4 */ + + data[dataOff + 16] = tmp13p2 + z1p2; + /* phase 5 */ + + data[dataOff + 48] = tmp13p2 - z1p2; + /* Odd part */ + + tmp10p2 = tmp4p2 + tmp5p2; + /* phase 2 */ + + tmp11p2 = tmp5p2 + tmp6p2; + tmp12p2 = tmp6p2 + tmp7p2; + /* The rotator is modified from fig 4-8 to avoid extra negations. */ + + var z5p2 = (tmp10p2 - tmp12p2) * 0.382683433; + /* c6 */ + + var z2p2 = 0.5411961 * tmp10p2 + z5p2; + /* c2-c6 */ + + var z4p2 = 1.306562965 * tmp12p2 + z5p2; + /* c2+c6 */ + + var z3p2 = tmp11p2 * 0.707106781; + /* c4 */ + + var z11p2 = tmp7p2 + z3p2; + /* phase 5 */ + + var z13p2 = tmp7p2 - z3p2; + data[dataOff + 40] = z13p2 + z2p2; + /* phase 6 */ + + data[dataOff + 24] = z13p2 - z2p2; + data[dataOff + 8] = z11p2 + z4p2; + data[dataOff + 56] = z11p2 - z4p2; + dataOff++; + /* advance pointer to next column */ + } // Quantize/descale the coefficients + + + var fDCTQuant; + + for (i = 0; i < I64; ++i) { + // Apply the quantization and scaling factor & Round to nearest integer + fDCTQuant = data[i] * fdtbl[i]; + outputfDCTQuant[i] = fDCTQuant > 0.0 ? fDCTQuant + 0.5 | 0 : fDCTQuant - 0.5 | 0; //outputfDCTQuant[i] = fround(fDCTQuant); + } + + return outputfDCTQuant; + } + + function writeAPP0() { + writeWord(0xffe0); // marker + + writeWord(16); // length + + writeByte(0x4a); // J + + writeByte(0x46); // F + + writeByte(0x49); // I + + writeByte(0x46); // F + + writeByte(0); // = "JFIF",'\0' + + writeByte(1); // versionhi + + writeByte(1); // versionlo + + writeByte(0); // xyunits + + writeWord(1); // xdensity + + writeWord(1); // ydensity + + writeByte(0); // thumbnwidth + + writeByte(0); // thumbnheight + } + + function writeSOF0(width, height) { + writeWord(0xffc0); // marker + + writeWord(17); // length, truecolor YUV JPG + + writeByte(8); // precision + + writeWord(height); + writeWord(width); + writeByte(3); // nrofcomponents + + writeByte(1); // IdY + + writeByte(0x11); // HVY + + writeByte(0); // QTY + + writeByte(2); // IdU + + writeByte(0x11); // HVU + + writeByte(1); // QTU + + writeByte(3); // IdV + + writeByte(0x11); // HVV + + writeByte(1); // QTV + } + + function writeDQT() { + writeWord(0xffdb); // marker + + writeWord(132); // length + + writeByte(0); + + for (var i = 0; i < 64; i++) { + writeByte(YTable[i]); + } + + writeByte(1); + + for (var j = 0; j < 64; j++) { + writeByte(UVTable[j]); + } + } + + function writeDHT() { + writeWord(0xffc4); // marker + + writeWord(0x01a2); // length + + writeByte(0); // HTYDCinfo + + for (var i = 0; i < 16; i++) { + writeByte(std_dc_luminance_nrcodes[i + 1]); + } + + for (var j = 0; j <= 11; j++) { + writeByte(std_dc_luminance_values[j]); + } + + writeByte(0x10); // HTYACinfo + + for (var k = 0; k < 16; k++) { + writeByte(std_ac_luminance_nrcodes[k + 1]); + } + + for (var l = 0; l <= 161; l++) { + writeByte(std_ac_luminance_values[l]); + } + + writeByte(1); // HTUDCinfo + + for (var m = 0; m < 16; m++) { + writeByte(std_dc_chrominance_nrcodes[m + 1]); + } + + for (var n = 0; n <= 11; n++) { + writeByte(std_dc_chrominance_values[n]); + } + + writeByte(0x11); // HTUACinfo + + for (var o = 0; o < 16; o++) { + writeByte(std_ac_chrominance_nrcodes[o + 1]); + } + + for (var p = 0; p <= 161; p++) { + writeByte(std_ac_chrominance_values[p]); + } + } + + function writeSOS() { + writeWord(0xffda); // marker + + writeWord(12); // length + + writeByte(3); // nrofcomponents + + writeByte(1); // IdY + + writeByte(0); // HTY + + writeByte(2); // IdU + + writeByte(0x11); // HTU + + writeByte(3); // IdV + + writeByte(0x11); // HTV + + writeByte(0); // Ss + + writeByte(0x3f); // Se + + writeByte(0); // Bf + } + + function processDU(CDU, fdtbl, DC, HTDC, HTAC) { + var EOB = HTAC[0x00]; + var M16zeroes = HTAC[0xf0]; + var pos; + var I16 = 16; + var I63 = 63; + var I64 = 64; + var DU_DCT = fDCTQuant(CDU, fdtbl); //ZigZag reorder + + for (var j = 0; j < I64; ++j) { + DU[ZigZag[j]] = DU_DCT[j]; + } + + var Diff = DU[0] - DC; + DC = DU[0]; //Encode DC + + if (Diff == 0) { + writeBits(HTDC[0]); // Diff might be 0 + } else { + pos = 32767 + Diff; + writeBits(HTDC[category[pos]]); + writeBits(bitcode[pos]); + } //Encode ACs + + + var end0pos = 63; // was const... which is crazy + + while (end0pos > 0 && DU[end0pos] == 0) { + end0pos--; + } //end0pos = first element in reverse order !=0 + + + if (end0pos == 0) { + writeBits(EOB); + return DC; + } + + var i = 1; + var lng; + + while (i <= end0pos) { + var startpos = i; + + while (DU[i] == 0 && i <= end0pos) { + ++i; + } + + var nrzeroes = i - startpos; + + if (nrzeroes >= I16) { + lng = nrzeroes >> 4; + + for (var nrmarker = 1; nrmarker <= lng; ++nrmarker) { + writeBits(M16zeroes); + } + + nrzeroes = nrzeroes & 0xf; + } + + pos = 32767 + DU[i]; + writeBits(HTAC[(nrzeroes << 4) + category[pos]]); + writeBits(bitcode[pos]); + i++; + } + + if (end0pos != I63) { + writeBits(EOB); + } + + return DC; + } + + function initCharLookupTable() { + var sfcc = String.fromCharCode; + + for (var i = 0; i < 256; i++) { + ///// ACHTUNG // 255 + clt[i] = sfcc(i); + } + } + + this.encode = function (image, quality // image data object + ) { + if (quality) { setQuality(quality); } // Initialize bit writer + + byteout = new Array(); + bytenew = 0; + bytepos = 7; // Add JPEG headers + + writeWord(0xffd8); // SOI + + writeAPP0(); + writeDQT(); + writeSOF0(image.width, image.height); + writeDHT(); + writeSOS(); // Encode 8x8 macroblocks + + var DCY = 0; + var DCU = 0; + var DCV = 0; + bytenew = 0; + bytepos = 7; + this.encode.displayName = "_encode_"; + var imageData = image.data; + var width = image.width; + var height = image.height; + var quadWidth = width * 4; + var x, + y = 0; + var r, g, b; + var start, p, col, row, pos; + + while (y < height) { + x = 0; + + while (x < quadWidth) { + start = quadWidth * y + x; + col = -1; + row = 0; + + for (pos = 0; pos < 64; pos++) { + row = pos >> 3; // /8 + + col = (pos & 7) * 4; // %8 + + p = start + row * quadWidth + col; + + if (y + row >= height) { + // padding bottom + p -= quadWidth * (y + 1 + row - height); + } + + if (x + col >= quadWidth) { + // padding right + p -= x + col - quadWidth + 4; + } + + r = imageData[p++]; + g = imageData[p++]; + b = imageData[p++]; + /* // calculate YUV values dynamically + YDU[pos]=((( 0.29900)*r+( 0.58700)*g+( 0.11400)*b))-128; //-0x80 + UDU[pos]=(((-0.16874)*r+(-0.33126)*g+( 0.50000)*b)); + VDU[pos]=((( 0.50000)*r+(-0.41869)*g+(-0.08131)*b)); + */ + // use lookup table (slightly faster) + + YDU[pos] = (RGB_YUV_TABLE[r] + RGB_YUV_TABLE[g + 256 >> 0] + RGB_YUV_TABLE[b + 512 >> 0] >> 16) - 128; + UDU[pos] = (RGB_YUV_TABLE[r + 768 >> 0] + RGB_YUV_TABLE[g + 1024 >> 0] + RGB_YUV_TABLE[b + 1280 >> 0] >> 16) - 128; + VDU[pos] = (RGB_YUV_TABLE[r + 1280 >> 0] + RGB_YUV_TABLE[g + 1536 >> 0] + RGB_YUV_TABLE[b + 1792 >> 0] >> 16) - 128; + } + + DCY = processDU(YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT); + DCU = processDU(UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT); + DCV = processDU(VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT); + x += 32; + } + + y += 8; + } //////////////////////////////////////////////////////////////// + // Do the bit alignment of the EOI marker + + + if (bytepos >= 0) { + var fillbits = []; + fillbits[1] = bytepos + 1; + fillbits[0] = (1 << bytepos + 1) - 1; + writeBits(fillbits); + } + + writeWord(0xffd9); //EOI + + return new Uint8Array(byteout); + }; + + function setQuality(quality) { + quality = Math.min(Math.max(quality, 1), 100); + if (currentQuality == quality) { return; } // don't recalc if unchanged + + var sf = quality < 50 ? Math.floor(5000 / quality) : Math.floor(200 - quality * 2); + initQuantTables(sf); + currentQuality = quality; //console.log('Quality set to: '+quality +'%'); + } + + function init() { + quality = quality || 50; // Create tables + + initCharLookupTable(); + initHuffmanTbl(); + initCategoryNumber(); + initRGBYUVTable(); + setQuality(quality); + } + + init(); +} // eslint-disable-next-line no-empty + + +try { + exports.JPEGEncoder = JPEGEncoder; +} catch (e) {} // CommonJS. + +/** + * @author shaozilee + * + * Bmp format decoder,support 1bit 4bit 8bit 24bit bmp + * + */ +function BmpDecoder(buffer, is_with_alpha) { + this.pos = 0; + this.buffer = buffer; + this.datav = new DataView(buffer.buffer); + this.is_with_alpha = !!is_with_alpha; + this.bottom_up = true; + this.flag = String.fromCharCode(this.buffer[0]) + String.fromCharCode(this.buffer[1]); + this.pos += 2; + if (["BM", "BA", "CI", "CP", "IC", "PT"].indexOf(this.flag) === -1) { throw new Error("Invalid BMP File"); } + this.parseHeader(); + this.parseBGR(); +} + +BmpDecoder.prototype.parseHeader = function () { + this.fileSize = this.datav.getUint32(this.pos, true); + this.pos += 4; + this.reserved = this.datav.getUint32(this.pos, true); + this.pos += 4; + this.offset = this.datav.getUint32(this.pos, true); + this.pos += 4; + this.headerSize = this.datav.getUint32(this.pos, true); + this.pos += 4; + this.width = this.datav.getUint32(this.pos, true); + this.pos += 4; + this.height = this.datav.getInt32(this.pos, true); + this.pos += 4; + this.planes = this.datav.getUint16(this.pos, true); + this.pos += 2; + this.bitPP = this.datav.getUint16(this.pos, true); + this.pos += 2; + this.compress = this.datav.getUint32(this.pos, true); + this.pos += 4; + this.rawSize = this.datav.getUint32(this.pos, true); + this.pos += 4; + this.hr = this.datav.getUint32(this.pos, true); + this.pos += 4; + this.vr = this.datav.getUint32(this.pos, true); + this.pos += 4; + this.colors = this.datav.getUint32(this.pos, true); + this.pos += 4; + this.importantColors = this.datav.getUint32(this.pos, true); + this.pos += 4; + + if (this.bitPP === 16 && this.is_with_alpha) { + this.bitPP = 15; + } + + if (this.bitPP < 15) { + var len = this.colors === 0 ? 1 << this.bitPP : this.colors; + this.palette = new Array(len); + + for (var i = 0; i < len; i++) { + var blue = this.datav.getUint8(this.pos++, true); + var green = this.datav.getUint8(this.pos++, true); + var red = this.datav.getUint8(this.pos++, true); + var quad = this.datav.getUint8(this.pos++, true); + this.palette[i] = { + red: red, + green: green, + blue: blue, + quad: quad + }; + } + } + + if (this.height < 0) { + this.height *= -1; + this.bottom_up = false; + } +}; + +BmpDecoder.prototype.parseBGR = function () { + this.pos = this.offset; + + try { + var bitn = "bit" + this.bitPP; + var len = this.width * this.height * 4; + this.data = new Uint8Array(len); + this[bitn](); + } catch (e) { + console.log("bit decode error:" + e); + } +}; + +BmpDecoder.prototype.bit1 = function () { + var xlen = Math.ceil(this.width / 8); + var mode = xlen % 4; + var y; + + for (y = this.height - 1; y >= 0; y--) { + var line = this.bottom_up ? y : this.height - 1 - y; + + for (var x = 0; x < xlen; x++) { + var b = this.datav.getUint8(this.pos++, true); + var location = line * this.width * 4 + x * 8 * 4; + + for (var i = 0; i < 8; i++) { + if (x * 8 + i < this.width) { + var rgb = this.palette[b >> 7 - i & 0x1]; + this.data[location + i * 4] = rgb.blue; + this.data[location + i * 4 + 1] = rgb.green; + this.data[location + i * 4 + 2] = rgb.red; + this.data[location + i * 4 + 3] = 0xff; + } else { + break; + } + } + } + + if (mode !== 0) { + this.pos += 4 - mode; + } + } +}; + +BmpDecoder.prototype.bit4 = function () { + var xlen = Math.ceil(this.width / 2); + var mode = xlen % 4; + + for (var y = this.height - 1; y >= 0; y--) { + var line = this.bottom_up ? y : this.height - 1 - y; + + for (var x = 0; x < xlen; x++) { + var b = this.datav.getUint8(this.pos++, true); + var location = line * this.width * 4 + x * 2 * 4; + var before = b >> 4; + var after = b & 0x0f; + var rgb = this.palette[before]; + this.data[location] = rgb.blue; + this.data[location + 1] = rgb.green; + this.data[location + 2] = rgb.red; + this.data[location + 3] = 0xff; + if (x * 2 + 1 >= this.width) { break; } + rgb = this.palette[after]; + this.data[location + 4] = rgb.blue; + this.data[location + 4 + 1] = rgb.green; + this.data[location + 4 + 2] = rgb.red; + this.data[location + 4 + 3] = 0xff; + } + + if (mode !== 0) { + this.pos += 4 - mode; + } + } +}; + +BmpDecoder.prototype.bit8 = function () { + var mode = this.width % 4; + + for (var y = this.height - 1; y >= 0; y--) { + var line = this.bottom_up ? y : this.height - 1 - y; + + for (var x = 0; x < this.width; x++) { + var b = this.datav.getUint8(this.pos++, true); + var location = line * this.width * 4 + x * 4; + + if (b < this.palette.length) { + var rgb = this.palette[b]; + this.data[location] = rgb.red; + this.data[location + 1] = rgb.green; + this.data[location + 2] = rgb.blue; + this.data[location + 3] = 0xff; + } else { + this.data[location] = 0xff; + this.data[location + 1] = 0xff; + this.data[location + 2] = 0xff; + this.data[location + 3] = 0xff; + } + } + + if (mode !== 0) { + this.pos += 4 - mode; + } + } +}; + +BmpDecoder.prototype.bit15 = function () { + var dif_w = this.width % 3; + + var _11111 = parseInt("11111", 2), + _1_5 = _11111; + + for (var y = this.height - 1; y >= 0; y--) { + var line = this.bottom_up ? y : this.height - 1 - y; + + for (var x = 0; x < this.width; x++) { + var B = this.datav.getUint16(this.pos, true); + this.pos += 2; + var blue = (B & _1_5) / _1_5 * 255 | 0; + var green = (B >> 5 & _1_5) / _1_5 * 255 | 0; + var red = (B >> 10 & _1_5) / _1_5 * 255 | 0; + var alpha = B >> 15 ? 0xff : 0x00; + var location = line * this.width * 4 + x * 4; + this.data[location] = red; + this.data[location + 1] = green; + this.data[location + 2] = blue; + this.data[location + 3] = alpha; + } //skip extra bytes + + + this.pos += dif_w; + } +}; + +BmpDecoder.prototype.bit16 = function () { + var dif_w = this.width % 3; + + var _11111 = parseInt("11111", 2), + _1_5 = _11111; + + var _111111 = parseInt("111111", 2), + _1_6 = _111111; + + for (var y = this.height - 1; y >= 0; y--) { + var line = this.bottom_up ? y : this.height - 1 - y; + + for (var x = 0; x < this.width; x++) { + var B = this.datav.getUint16(this.pos, true); + this.pos += 2; + var alpha = 0xff; + var blue = (B & _1_5) / _1_5 * 255 | 0; + var green = (B >> 5 & _1_6) / _1_6 * 255 | 0; + var red = (B >> 11) / _1_5 * 255 | 0; + var location = line * this.width * 4 + x * 4; + this.data[location] = red; + this.data[location + 1] = green; + this.data[location + 2] = blue; + this.data[location + 3] = alpha; + } //skip extra bytes + + + this.pos += dif_w; + } +}; + +BmpDecoder.prototype.bit24 = function () { + //when height > 0 + for (var y = this.height - 1; y >= 0; y--) { + var line = this.bottom_up ? y : this.height - 1 - y; + + for (var x = 0; x < this.width; x++) { + var blue = this.datav.getUint8(this.pos++, true); + var green = this.datav.getUint8(this.pos++, true); + var red = this.datav.getUint8(this.pos++, true); + var location = line * this.width * 4 + x * 4; + this.data[location] = red; + this.data[location + 1] = green; + this.data[location + 2] = blue; + this.data[location + 3] = 0xff; + } //skip extra bytes + + + this.pos += this.width % 4; + } +}; +/** + * add 32bit decode func + * @author soubok + */ + + +BmpDecoder.prototype.bit32 = function () { + //when height > 0 + for (var y = this.height - 1; y >= 0; y--) { + var line = this.bottom_up ? y : this.height - 1 - y; + + for (var x = 0; x < this.width; x++) { + var blue = this.datav.getUint8(this.pos++, true); + var green = this.datav.getUint8(this.pos++, true); + var red = this.datav.getUint8(this.pos++, true); + var alpha = this.datav.getUint8(this.pos++, true); + var location = line * this.width * 4 + x * 4; + this.data[location] = red; + this.data[location + 1] = green; + this.data[location + 2] = blue; + this.data[location + 3] = alpha; + } //skip extra bytes + //this.pos += (this.width % 4); + + } +}; + +BmpDecoder.prototype.getData = function () { + return this.data; +}; // eslint-disable-next-line no-empty + + +try { + exports.BmpDecoder = BmpDecoder; +} catch (e) {} // CommonJS. + +function WebPDecoder(imageData) { + var UpsampleRgbLinePair, UpsampleBgrLinePair, UpsampleRgbaLinePair, UpsampleBgraLinePair, UpsampleArgbLinePair, UpsampleArgbLinePair, UpsampleRgba4444LinePair, UpsampleRgb565LinePair; + + function x(F) { + if (!F) { throw Error("assert :P"); } + } + + function fa(F, L, J) { + for (var H = 0; 4 > H; H++) { + if (F[L + H] != J.charCodeAt(H)) { return !0; } + } + + return !1; + } + + function I(F, L, J, H, Z) { + for (var O = 0; O < Z; O++) { + F[L + O] = J[H + O]; + } + } + + function M(F, L, J, H) { + for (var Z = 0; Z < H; Z++) { + F[L + Z] = J; + } + } + + function V(F) { + return new Int32Array(F); + } + + function wa(F, L) { + for (var J = [], H = 0; H < F; H++) { + J.push(new L()); + } + + return J; + } + + function wb() { + function F(J, H, Z) { + for (var O = Z[H], L = 0; L < O; L++) { + J.push(Z.length > H + 1 ? [] : 0); + if (Z.length < H + 1) { break; } + F(J[L], H + 1, Z); + } + } + + var L = []; + F(L, 0, [3, 11]); + return L; + } + + function Ed(F, L) { + function J(H, O, F) { + for (var Z = F[O], ma = 0; ma < Z; ma++) { + H.push(F.length > O + 1 ? [] : new L()); + if (F.length < O + 1) { break; } + J(H[ma], O + 1, F); + } + } + + var H = []; + J(H, 0, F); + return H; + } + + WebPDecoder = function WebPDecoder() { + var self = this; + + function L(a, b) { + for (var c = 1 << b - 1 >>> 0; a & c;) { + c >>>= 1; + } + + return c ? (a & c - 1) + c : a; + } + + function J(a, b, c, d, e) { + x(!(d % c)); + + do { + d -= c, a[b + d] = e; + } while (0 < d); + } + + function H(a, b, c, d, e, f) { + var g = b, + h = 1 << c, + k, + l, + m = V(16), + n = V(16); + x(0 != e); + x(null != d); + x(null != a); + x(0 < c); + + for (l = 0; l < e; ++l) { + if (15 < d[l]) { return 0; } + ++m[d[l]]; + } + + if (m[0] == e) { return 0; } + n[1] = 0; + + for (k = 1; 15 > k; ++k) { + if (m[k] > 1 << k) { return 0; } + n[k + 1] = n[k] + m[k]; + } + + for (l = 0; l < e; ++l) { + k = d[l], 0 < d[l] && (f[n[k]++] = l); + } + + if (1 == n[15]) { return d = new O(), d.g = 0, d.value = f[0], J(a, g, 1, h, d), h; } + var r = -1, + q = h - 1, + t = 0, + v = 1, + p = 1, + u, + w = 1 << c; + l = 0; + k = 1; + + for (e = 2; k <= c; ++k, e <<= 1) { + p <<= 1; + v += p; + p -= m[k]; + if (0 > p) { return 0; } + + for (; 0 < m[k]; --m[k]) { + d = new O(), d.g = k, d.value = f[l++], J(a, g + t, e, w, d), t = L(t, k); + } + } + + k = c + 1; + + for (e = 2; 15 >= k; ++k, e <<= 1) { + p <<= 1; + v += p; + p -= m[k]; + if (0 > p) { return 0; } + + for (; 0 < m[k]; --m[k]) { + d = new O(); + + if ((t & q) != r) { + g += w; + r = k; + + for (u = 1 << r - c; 15 > r;) { + u -= m[r]; + if (0 >= u) { break; } + ++r; + u <<= 1; + } + + u = r - c; + w = 1 << u; + h += w; + r = t & q; + a[b + r].g = u + c; + a[b + r].value = g - b - r; + } + + d.g = k - c; + d.value = f[l++]; + J(a, g + (t >> c), e, w, d); + t = L(t, k); + } + } + + return v != 2 * n[15] - 1 ? 0 : h; + } + + function Z(a, b, c, d, e) { + x(2328 >= e); + if (512 >= e) { var f = V(512); }else if (f = V(e), null == f) { return 0; } + return H(a, b, c, d, e, f); + } + + function O() { + this.value = this.g = 0; + } + + function Fd() { + this.value = this.g = 0; + } + + function Ub() { + this.G = wa(5, O); + this.H = V(5); + this.jc = this.Qb = this.qb = this.nd = 0; + this.pd = wa(xb, Fd); + } + + function ma(a, b, c, d) { + x(null != a); + x(null != b); + x(2147483648 > d); + a.Ca = 254; + a.I = 0; + a.b = -8; + a.Ka = 0; + a.oa = b; + a.pa = c; + a.Jd = b; + a.Yc = c + d; + a.Zc = 4 <= d ? c + d - 4 + 1 : c; + Qa(a); + } + + function na(a, b) { + for (var c = 0; 0 < b--;) { + c |= K(a, 128) << b; + } + + return c; + } + + function ca(a, b) { + var c = na(a, b); + return G(a) ? -c : c; + } + + function cb(a, b, c, d) { + var e, + f = 0; + x(null != a); + x(null != b); + x(4294967288 > d); + a.Sb = d; + a.Ra = 0; + a.u = 0; + a.h = 0; + 4 < d && (d = 4); + + for (e = 0; e < d; ++e) { + f += b[c + e] << 8 * e; + } + + a.Ra = f; + a.bb = d; + a.oa = b; + a.pa = c; + } + + function Vb(a) { + for (; 8 <= a.u && a.bb < a.Sb;) { + a.Ra >>>= 8, a.Ra += a.oa[a.pa + a.bb] << ob - 8 >>> 0, ++a.bb, a.u -= 8; + } + + db(a) && (a.h = 1, a.u = 0); + } + + function D(a, b) { + x(0 <= b); + + if (!a.h && b <= Gd) { + var c = pb(a) & Hd[b]; + a.u += b; + Vb(a); + return c; + } + + a.h = 1; + return a.u = 0; + } + + function Wb() { + this.b = this.Ca = this.I = 0; + this.oa = []; + this.pa = 0; + this.Jd = []; + this.Yc = 0; + this.Zc = []; + this.Ka = 0; + } + + function Ra() { + this.Ra = 0; + this.oa = []; + this.h = this.u = this.bb = this.Sb = this.pa = 0; + } + + function pb(a) { + return a.Ra >>> (a.u & ob - 1) >>> 0; + } + + function db(a) { + x(a.bb <= a.Sb); + return a.h || a.bb == a.Sb && a.u > ob; + } + + function qb(a, b) { + a.u = b; + a.h = db(a); + } + + function Sa(a) { + a.u >= Xb && (x(a.u >= Xb), Vb(a)); + } + + function Qa(a) { + x(null != a && null != a.oa); + a.pa < a.Zc ? (a.I = (a.oa[a.pa++] | a.I << 8) >>> 0, a.b += 8) : (x(null != a && null != a.oa), a.pa < a.Yc ? (a.b += 8, a.I = a.oa[a.pa++] | a.I << 8) : a.Ka ? a.b = 0 : (a.I <<= 8, a.b += 8, a.Ka = 1)); + } + + function G(a) { + return na(a, 1); + } + + function K(a, b) { + var c = a.Ca; + 0 > a.b && Qa(a); + var d = a.b, + e = c * b >>> 8, + f = (a.I >>> d > e) + 0; + f ? (c -= e, a.I -= e + 1 << d >>> 0) : c = e + 1; + d = c; + + for (e = 0; 256 <= d;) { + e += 8, d >>= 8; + } + + d = 7 ^ e + Id[d]; + a.b -= d; + a.Ca = (c << d) - 1; + return f; + } + + function ra(a, b, c) { + a[b + 0] = c >> 24 & 255; + a[b + 1] = c >> 16 & 255; + a[b + 2] = c >> 8 & 255; + a[b + 3] = c >> 0 & 255; + } + + function Ta(a, b) { + return a[b + 0] << 0 | a[b + 1] << 8; + } + + function Yb(a, b) { + return Ta(a, b) | a[b + 2] << 16; + } + + function Ha(a, b) { + return Ta(a, b) | Ta(a, b + 2) << 16; + } + + function Zb(a, b) { + var c = 1 << b; + x(null != a); + x(0 < b); + a.X = V(c); + if (null == a.X) { return 0; } + a.Mb = 32 - b; + a.Xa = b; + return 1; + } + + function $b(a, b) { + x(null != a); + x(null != b); + x(a.Xa == b.Xa); + I(b.X, 0, a.X, 0, 1 << b.Xa); + } + + function ac() { + this.X = []; + this.Xa = this.Mb = 0; + } + + function bc(a, b, c, d) { + x(null != c); + x(null != d); + var e = c[0], + f = d[0]; + 0 == e && (e = (a * f + b / 2) / b); + 0 == f && (f = (b * e + a / 2) / a); + if (0 >= e || 0 >= f) { return 0; } + c[0] = e; + d[0] = f; + return 1; + } + + function xa(a, b) { + return a + (1 << b) - 1 >>> b; + } + + function yb(a, b) { + return ((a & 4278255360) + (b & 4278255360) >>> 0 & 4278255360) + ((a & 16711935) + (b & 16711935) >>> 0 & 16711935) >>> 0; + } + + function X(a, b) { + self[b] = function (b, d, e, f, g, h, k) { + var c; + + for (c = 0; c < g; ++c) { + var m = self[a](h[k + c - 1], e, f + c); + h[k + c] = yb(b[d + c], m); + } + }; + } + + function Jd() { + this.ud = this.hd = this.jd = 0; + } + + function aa(a, b) { + return (((a ^ b) & 4278124286) >>> 1) + (a & b) >>> 0; + } + + function sa(a) { + if (0 <= a && 256 > a) { return a; } + if (0 > a) { return 0; } + if (255 < a) { return 255; } + } + + function eb(a, b) { + return sa(a + (a - b + 0.5 >> 1)); + } + + function Ia(a, b, c) { + return Math.abs(b - c) - Math.abs(a - c); + } + + function cc(a, b, c, d, e, f, g) { + d = f[g - 1]; + + for (c = 0; c < e; ++c) { + f[g + c] = d = yb(a[b + c], d); + } + } + + function Kd(a, b, c, d, e) { + var f; + + for (f = 0; f < c; ++f) { + var g = a[b + f], + h = g >> 8 & 255, + k = g & 16711935, + k = k + ((h << 16) + h), + k = k & 16711935; + d[e + f] = (g & 4278255360) + k >>> 0; + } + } + + function dc(a, b) { + b.jd = a >> 0 & 255; + b.hd = a >> 8 & 255; + b.ud = a >> 16 & 255; + } + + function Ld(a, b, c, d, e, f) { + var g; + + for (g = 0; g < d; ++g) { + var h = b[c + g], + k = h >>> 8, + l = h >>> 16, + m = h, + l = l + ((a.jd << 24 >> 24) * (k << 24 >> 24) >>> 5), + l = l & 255, + m = m + ((a.hd << 24 >> 24) * (k << 24 >> 24) >>> 5), + m = m + ((a.ud << 24 >> 24) * (l << 24 >> 24) >>> 5), + m = m & 255; + e[f + g] = (h & 4278255360) + (l << 16) + m; + } + } + + function ec(a, b, c, d, e) { + self[b] = function (a, b, c, k, l, m, n, r, q) { + for (k = n; k < r; ++k) { + for (n = 0; n < q; ++n) { + l[m++] = e(c[d(a[b++])]); + } + } + }; + + self[a] = function (a, b, h, k, l, m, n) { + var f = 8 >> a.b, + g = a.Ea, + t = a.K[0], + v = a.w; + if (8 > f) { for (a = (1 << a.b) - 1, v = (1 << f) - 1; b < h; ++b) { + var p = 0, + u; + + for (u = 0; u < g; ++u) { + u & a || (p = d(k[l++])), m[n++] = e(t[p & v]), p >>= f; + } + } } else { self["VP8LMapColor" + c](k, l, t, v, m, n, b, h, g); } + }; + } + + function Md(a, b, c, d, e) { + for (c = b + c; b < c;) { + var f = a[b++]; + d[e++] = f >> 16 & 255; + d[e++] = f >> 8 & 255; + d[e++] = f >> 0 & 255; + } + } + + function Nd(a, b, c, d, e) { + for (c = b + c; b < c;) { + var f = a[b++]; + d[e++] = f >> 16 & 255; + d[e++] = f >> 8 & 255; + d[e++] = f >> 0 & 255; + d[e++] = f >> 24 & 255; + } + } + + function Od(a, b, c, d, e) { + for (c = b + c; b < c;) { + var f = a[b++], + g = f >> 16 & 240 | f >> 12 & 15, + f = f >> 0 & 240 | f >> 28 & 15; + d[e++] = g; + d[e++] = f; + } + } + + function Pd(a, b, c, d, e) { + for (c = b + c; b < c;) { + var f = a[b++], + g = f >> 16 & 248 | f >> 13 & 7, + f = f >> 5 & 224 | f >> 3 & 31; + d[e++] = g; + d[e++] = f; + } + } + + function Qd(a, b, c, d, e) { + for (c = b + c; b < c;) { + var f = a[b++]; + d[e++] = f >> 0 & 255; + d[e++] = f >> 8 & 255; + d[e++] = f >> 16 & 255; + } + } + + function fb(a, b, c, d, e, f) { + if (0 == f) { for (c = b + c; b < c;) { + f = a[b++], ra(d, (f[0] >> 24 | f[1] >> 8 & 65280 | f[2] << 8 & 16711680 | f[3] << 24) >>> 0), e += 32; + } } else { I(d, e, a, b, c); } + } + + function gb(a, b) { + self[b][0] = self[a + "0"]; + self[b][1] = self[a + "1"]; + self[b][2] = self[a + "2"]; + self[b][3] = self[a + "3"]; + self[b][4] = self[a + "4"]; + self[b][5] = self[a + "5"]; + self[b][6] = self[a + "6"]; + self[b][7] = self[a + "7"]; + self[b][8] = self[a + "8"]; + self[b][9] = self[a + "9"]; + self[b][10] = self[a + "10"]; + self[b][11] = self[a + "11"]; + self[b][12] = self[a + "12"]; + self[b][13] = self[a + "13"]; + self[b][14] = self[a + "0"]; + self[b][15] = self[a + "0"]; + } + + function hb(a) { + return a == zb || a == Ab || a == Ja || a == Bb; + } + + function Rd() { + this.eb = []; + this.size = this.A = this.fb = 0; + } + + function Sd() { + this.y = []; + this.f = []; + this.ea = []; + this.F = []; + this.Tc = this.Ed = this.Cd = this.Fd = this.lb = this.Db = this.Ab = this.fa = this.J = this.W = this.N = this.O = 0; + } + + function Cb() { + this.Rd = this.height = this.width = this.S = 0; + this.f = {}; + this.f.RGBA = new Rd(); + this.f.kb = new Sd(); + this.sd = null; + } + + function Td() { + this.width = [0]; + this.height = [0]; + this.Pd = [0]; + this.Qd = [0]; + this.format = [0]; + } + + function Ud() { + this.Id = this.fd = this.Md = this.hb = this.ib = this.da = this.bd = this.cd = this.j = this.v = this.Da = this.Sd = this.ob = 0; + } + + function Vd(a) { + alert("todo:WebPSamplerProcessPlane"); + return a.T; + } + + function Wd(a, b) { + var c = a.T, + d = b.ba.f.RGBA, + e = d.eb, + f = d.fb + a.ka * d.A, + g = P[b.ba.S], + h = a.y, + k = a.O, + l = a.f, + m = a.N, + n = a.ea, + r = a.W, + q = b.cc, + t = b.dc, + v = b.Mc, + p = b.Nc, + u = a.ka, + w = a.ka + a.T, + y = a.U, + A = y + 1 >> 1; + 0 == u ? g(h, k, null, null, l, m, n, r, l, m, n, r, e, f, null, null, y) : (g(b.ec, b.fc, h, k, q, t, v, p, l, m, n, r, e, f - d.A, e, f, y), ++c); + + for (; u + 2 < w; u += 2) { + q = l, t = m, v = n, p = r, m += a.Rc, r += a.Rc, f += 2 * d.A, k += 2 * a.fa, g(h, k - a.fa, h, k, q, t, v, p, l, m, n, r, e, f - d.A, e, f, y); + } + + k += a.fa; + a.j + w < a.o ? (I(b.ec, b.fc, h, k, y), I(b.cc, b.dc, l, m, A), I(b.Mc, b.Nc, n, r, A), c--) : w & 1 || g(h, k, null, null, l, m, n, r, l, m, n, r, e, f + d.A, null, null, y); + return c; + } + + function Xd(a, b, c) { + var d = a.F, + e = [a.J]; + + if (null != d) { + var f = a.U, + g = b.ba.S, + h = g == ya || g == Ja; + b = b.ba.f.RGBA; + var k = [0], + l = a.ka; + k[0] = a.T; + a.Kb && (0 == l ? --k[0] : (--l, e[0] -= a.width), a.j + a.ka + a.T == a.o && (k[0] = a.o - a.j - l)); + var m = b.eb, + l = b.fb + l * b.A; + a = fc(d, e[0], a.width, f, k, m, l + (h ? 0 : 3), b.A); + x(c == k); + a && hb(g) && za(m, l, h, f, k, b.A); + } + + return 0; + } + + function gc(a) { + var b = a.ma, + c = b.ba.S, + d = 11 > c, + e = c == Ua || c == Va || c == ya || c == Db || 12 == c || hb(c); + b.memory = null; + b.Ib = null; + b.Jb = null; + b.Nd = null; + if (!hc(b.Oa, a, e ? 11 : 12)) { return 0; } + e && hb(c) && ic(); + if (a.da) { alert("todo:use_scaling"); }else { + if (d) { + if (b.Ib = Vd, a.Kb) { + c = a.U + 1 >> 1; + b.memory = V(a.U + 2 * c); + if (null == b.memory) { return 0; } + b.ec = b.memory; + b.fc = 0; + b.cc = b.ec; + b.dc = b.fc + a.U; + b.Mc = b.cc; + b.Nc = b.dc + c; + b.Ib = Wd; + ic(); + } + } else { alert("todo:EmitYUV"); } + + e && (b.Jb = Xd, d && Aa()); + } + + if (d && !jc) { + for (a = 0; 256 > a; ++a) { + Yd[a] = 89858 * (a - 128) + Ba >> Wa, Zd[a] = -22014 * (a - 128) + Ba, $d[a] = -45773 * (a - 128), ae[a] = 113618 * (a - 128) + Ba >> Wa; + } + + for (a = ta; a < Eb; ++a) { + b = 76283 * (a - 16) + Ba >> Wa, be[a - ta] = ga(b, 255), ce[a - ta] = ga(b + 8 >> 4, 15); + } + + jc = 1; + } + + return 1; + } + + function kc(a) { + var b = a.ma, + c = a.U, + d = a.T; + x(!(a.ka & 1)); + if (0 >= c || 0 >= d) { return 0; } + c = b.Ib(a, b); + null != b.Jb && b.Jb(a, b, c); + b.Dc += c; + return 1; + } + + function lc(a) { + a.ma.memory = null; + } + + function mc(a, b, c, d) { + if (47 != D(a, 8)) { return 0; } + b[0] = D(a, 14) + 1; + c[0] = D(a, 14) + 1; + d[0] = D(a, 1); + return 0 != D(a, 3) ? 0 : !a.h; + } + + function ib(a, b) { + if (4 > a) { return a + 1; } + var c = a - 2 >> 1; + return (2 + (a & 1) << c) + D(b, c) + 1; + } + + function nc(a, b) { + if (120 < b) { return b - 120; } + var c = de[b - 1], + c = (c >> 4) * a + (8 - (c & 15)); + return 1 <= c ? c : 1; + } + + function ua(a, b, c) { + var d = pb(c); + b += d & 255; + var e = a[b].g - 8; + 0 < e && (qb(c, c.u + 8), d = pb(c), b += a[b].value, b += d & (1 << e) - 1); + qb(c, c.u + a[b].g); + return a[b].value; + } + + function ub(a, b, c) { + c.g += a.g; + c.value += a.value << b >>> 0; + x(8 >= c.g); + return a.g; + } + + function ha(a, b, c) { + var d = a.xc; + b = 0 == d ? 0 : a.vc[a.md * (c >> d) + (b >> d)]; + x(b < a.Wb); + return a.Ya[b]; + } + + function oc(a, b, c, d) { + var e = a.ab, + f = a.c * b, + g = a.C; + b = g + b; + var h = c, + k = d; + d = a.Ta; + + for (c = a.Ua; 0 < e--;) { + var l = a.gc[e], + m = g, + n = b, + r = h, + q = k, + k = d, + h = c, + t = l.Ea; + x(m < n); + x(n <= l.nc); + + switch (l.hc) { + case 2: + pc(r, q, (n - m) * t, k, h); + break; + + case 0: + var v = l, + p = m, + u = n, + w = k, + y = h, + A = v.Ea; + 0 == p && (ee(r, q, null, null, 1, w, y), cc(r, q + 1, 0, 0, A - 1, w, y + 1), q += A, y += A, ++p); + + for (var E = 1 << v.b, B = E - 1, C = xa(A, v.b), N = v.K, v = v.w + (p >> v.b) * C; p < u;) { + var z = N, + Q = v, + S = 1; + + for (fe(r, q, w, y - A, 1, w, y); S < A;) { + var K = qc[z[Q++] >> 8 & 15], + D = (S & ~B) + E; + D > A && (D = A); + K(r, q + +S, w, y + S - A, D - S, w, y + S); + S = D; + } + + q += A; + y += A; + ++p; + p & B || (v += C); + } + + n != l.nc && I(k, h - t, k, h + (n - m - 1) * t, t); + break; + + case 1: + t = r; + u = q; + r = l.Ea; + q = 1 << l.b; + w = q - 1; + y = r & ~w; + A = r - y; + p = xa(r, l.b); + E = l.K; + + for (l = l.w + (m >> l.b) * p; m < n;) { + B = E; + C = l; + N = new Jd(); + v = u + y; + + for (z = u + r; u < v;) { + dc(B[C++], N), Fb(N, t, u, q, k, h), u += q, h += q; + } + + u < z && (dc(B[C++], N), Fb(N, t, u, A, k, h), u += A, h += A); + ++m; + m & w || (l += p); + } + + break; + + case 3: + if (r == k && q == h && 0 < l.b) { + y = (n - m) * xa(l.Ea, l.b); + t = h + (n - m) * t - y; + u = k; + r = t; + q = k; + w = h; + A = y; + p = []; + + for (y = A - 1; 0 <= y; --y) { + p[y] = q[w + y]; + } + + for (y = A - 1; 0 <= y; --y) { + u[r + y] = p[y]; + } + + rc(l, m, n, k, t, k, h); + } else { rc(l, m, n, r, q, k, h); } + + } + + h = d; + k = c; + } + + k != c && I(d, c, h, k, f); + } + + function ge(a, b) { + var c = a.V, + d = a.Ba + a.c * a.C, + e = b - a.C; + x(b <= a.l.o); + x(16 >= e); + + if (0 < e) { + var f = a.l, + g = a.Ta, + h = a.Ua, + k = f.width; + oc(a, e, c, d); + h = [h]; + c = a.C; + d = b; + e = h; + x(c < d); + x(f.v < f.va); + d > f.o && (d = f.o); + + if (c < f.j) { + var l = f.j - c, + c = f.j; + e[0] += l * k; + } + + c >= d ? c = 0 : (e[0] += 4 * f.v, f.ka = c - f.j, f.U = f.va - f.v, f.T = d - c, c = 1); + + if (c) { + h = h[0]; + c = a.ca; + + if (11 > c.S) { + for (var m = c.f.RGBA, d = c.S, e = f.U, f = f.T, l = m.eb, n = m.A, r = f, m = m.fb + a.Ma * m.A; 0 < r--;) { + var q = g, + t = h, + v = e, + p = l, + u = m; + + switch (d) { + case Ca: + sc(q, t, v, p, u); + break; + + case Ua: + Gb(q, t, v, p, u); + break; + + case zb: + Gb(q, t, v, p, u); + za(p, u, 0, v, 1, 0); + break; + + case tc: + uc(q, t, v, p, u); + break; + + case Va: + fb(q, t, v, p, u, 1); + break; + + case Ab: + fb(q, t, v, p, u, 1); + za(p, u, 0, v, 1, 0); + break; + + case ya: + fb(q, t, v, p, u, 0); + break; + + case Ja: + fb(q, t, v, p, u, 0); + za(p, u, 1, v, 1, 0); + break; + + case Db: + Hb(q, t, v, p, u); + break; + + case Bb: + Hb(q, t, v, p, u); + vc(p, u, v, 1, 0); + break; + + case wc: + xc(q, t, v, p, u); + break; + + default: + x(0); + } + + h += k; + m += n; + } + + a.Ma += f; + } else { alert("todo:EmitRescaledRowsYUVA"); } + + x(a.Ma <= c.height); + } + } + + a.C = b; + x(a.C <= a.i); + } + + function yc(a) { + var b; + if (0 < a.ua) { return 0; } + + for (b = 0; b < a.Wb; ++b) { + var c = a.Ya[b].G, + d = a.Ya[b].H; + if (0 < c[1][d[1] + 0].g || 0 < c[2][d[2] + 0].g || 0 < c[3][d[3] + 0].g) { return 0; } + } + + return 1; + } + + function zc(a, b, c, d, e, f) { + if (0 != a.Z) { + var g = a.qd, + h = a.rd; + + for (x(null != ia[a.Z]); b < c; ++b) { + ia[a.Z](g, h, d, e, d, e, f), g = d, h = e, e += f; + } + + a.qd = g; + a.rd = h; + } + } + + function Ib(a, b) { + var c = a.l.ma, + d = 0 == c.Z || 1 == c.Z ? a.l.j : a.C, + d = a.C < d ? d : a.C; + x(b <= a.l.o); + + if (b > d) { + var e = a.l.width, + f = c.ca, + g = c.tb + e * d, + h = a.V, + k = a.Ba + a.c * d, + l = a.gc; + x(1 == a.ab); + x(3 == l[0].hc); + he(l[0], d, b, h, k, f, g); + zc(c, d, b, f, g, e); + } + + a.C = a.Ma = b; + } + + function Jb(a, b, c, d, e, f, g) { + var h = a.$ / d, + k = a.$ % d, + l = a.m, + m = a.s, + n = c + a.$, + r = n; + e = c + d * e; + var q = c + d * f, + t = 280 + m.ua, + v = a.Pb ? h : 16777216, + p = 0 < m.ua ? m.Wa : null, + u = m.wc, + w = n < q ? ha(m, k, h) : null; + x(a.C < f); + x(q <= e); + var y = !1; + + a: for (;;) { + for (; y || n < q;) { + var A = 0; + + if (h >= v) { + var v = a, + E = n - c; + x(v.Pb); + v.wd = v.m; + v.xd = E; + 0 < v.s.ua && $b(v.s.Wa, v.s.vb); + v = h + ie; + } + + k & u || (w = ha(m, k, h)); + x(null != w); + w.Qb && (b[n] = w.qb, y = !0); + if (!y) { if (Sa(l), w.jc) { + var A = l, + E = b, + B = n, + C = w.pd[pb(A) & xb - 1]; + x(w.jc); + 256 > C.g ? (qb(A, A.u + C.g), E[B] = C.value, A = 0) : (qb(A, A.u + C.g - 256), x(256 <= C.value), A = C.value); + 0 == A && (y = !0); + } else { A = ua(w.G[0], w.H[0], l); } } + if (l.h) { break; } + + if (y || 256 > A) { + if (!y) { if (w.nd) { b[n] = (w.qb | A << 8) >>> 0; }else { + Sa(l); + y = ua(w.G[1], w.H[1], l); + Sa(l); + E = ua(w.G[2], w.H[2], l); + B = ua(w.G[3], w.H[3], l); + if (l.h) { break; } + b[n] = (B << 24 | y << 16 | A << 8 | E) >>> 0; + } } + y = !1; + ++n; + ++k; + if (k >= d && (k = 0, ++h, null != g && h <= f && !(h % 16) && g(a, h), null != p)) { for (; r < n;) { + A = b[r++], p.X[(506832829 * A & 4294967295) >>> p.Mb] = A; + } } + } else if (280 > A) { + A = ib(A - 256, l); + E = ua(w.G[4], w.H[4], l); + Sa(l); + E = ib(E, l); + E = nc(d, E); + if (l.h) { break; } + if (n - c < E || e - n < A) { break a; }else { for (B = 0; B < A; ++B) { + b[n + B] = b[n + B - E]; + } } + n += A; + + for (k += A; k >= d;) { + k -= d, ++h, null != g && h <= f && !(h % 16) && g(a, h); + } + + x(n <= e); + k & u && (w = ha(m, k, h)); + if (null != p) { for (; r < n;) { + A = b[r++], p.X[(506832829 * A & 4294967295) >>> p.Mb] = A; + } } + } else if (A < t) { + y = A - 280; + + for (x(null != p); r < n;) { + A = b[r++], p.X[(506832829 * A & 4294967295) >>> p.Mb] = A; + } + + A = n; + E = p; + x(!(y >>> E.Xa)); + b[A] = E.X[y]; + y = !0; + } else { break a; } + + y || x(l.h == db(l)); + } + + if (a.Pb && l.h && n < e) { x(a.m.h), a.a = 5, a.m = a.wd, a.$ = a.xd, 0 < a.s.ua && $b(a.s.vb, a.s.Wa); }else if (l.h) { break a; }else { null != g && g(a, h > f ? f : h), a.a = 0, a.$ = n - c; } + return 1; + } + + a.a = 3; + return 0; + } + + function Ac(a) { + x(null != a); + a.vc = null; + a.yc = null; + a.Ya = null; + var b = a.Wa; + null != b && (b.X = null); + a.vb = null; + x(null != a); + } + + function Bc() { + var a = new je(); + if (null == a) { return null; } + a.a = 0; + a.xb = Cc; + gb("Predictor", "VP8LPredictors"); + gb("Predictor", "VP8LPredictors_C"); + gb("PredictorAdd", "VP8LPredictorsAdd"); + gb("PredictorAdd", "VP8LPredictorsAdd_C"); + pc = Kd; + Fb = Ld; + sc = Md; + Gb = Nd; + Hb = Od; + xc = Pd; + uc = Qd; + self.VP8LMapColor32b = ke; + self.VP8LMapColor8b = le; + return a; + } + + function rb(a, b, c, d, e) { + var f = 1, + g = [a], + h = [b], + k = d.m, + l = d.s, + m = null, + n = 0; + + a: for (;;) { + if (c) { for (; f && D(k, 1);) { + var r = g, + q = h, + t = d, + v = 1, + p = t.m, + u = t.gc[t.ab], + w = D(p, 2); + if (t.Oc & 1 << w) { f = 0; }else { + t.Oc |= 1 << w; + u.hc = w; + u.Ea = r[0]; + u.nc = q[0]; + u.K = [null]; + ++t.ab; + x(4 >= t.ab); + + switch (w) { + case 0: + case 1: + u.b = D(p, 3) + 2; + v = rb(xa(u.Ea, u.b), xa(u.nc, u.b), 0, t, u.K); + u.K = u.K[0]; + break; + + case 3: + var y = D(p, 8) + 1, + A = 16 < y ? 0 : 4 < y ? 1 : 2 < y ? 2 : 3; + r[0] = xa(u.Ea, A); + u.b = A; + var v = rb(y, 1, 0, t, u.K), + E; + + if (E = v) { + var B, + C = y, + N = u, + z = 1 << (8 >> N.b), + Q = V(z); + if (null == Q) { E = 0; }else { + var S = N.K[0], + K = N.w; + Q[0] = N.K[0][0]; + + for (B = 1; B < 1 * C; ++B) { + Q[B] = yb(S[K + B], Q[B - 1]); + } + + for (; B < 4 * z; ++B) { + Q[B] = 0; + } + + N.K[0] = null; + N.K[0] = Q; + E = 1; + } + } + + v = E; + break; + + case 2: + break; + + default: + x(0); + } + + f = v; + } + } } + g = g[0]; + h = h[0]; + + if (f && D(k, 1) && (n = D(k, 4), f = 1 <= n && 11 >= n, !f)) { + d.a = 3; + break a; + } + + var H; + if (H = f) { b: { + var F = d, + G = g, + L = h, + J = n, + T = c, + Da, + ba, + X = F.m, + R = F.s, + P = [null], + U, + W = 1, + aa = 0, + na = me[J]; + + c: for (;;) { + if (T && D(X, 1)) { + var ca = D(X, 3) + 2, + ga = xa(G, ca), + ka = xa(L, ca), + qa = ga * ka; + if (!rb(ga, ka, 0, F, P)) { break c; } + P = P[0]; + R.xc = ca; + + for (Da = 0; Da < qa; ++Da) { + var ia = P[Da] >> 8 & 65535; + P[Da] = ia; + ia >= W && (W = ia + 1); + } + } + + if (X.h) { break c; } + + for (ba = 0; 5 > ba; ++ba) { + var Y = Dc[ba]; + !ba && 0 < J && (Y += 1 << J); + aa < Y && (aa = Y); + } + + var ma = wa(W * na, O); + var ua = W, + va = wa(ua, Ub); + if (null == va) { var la = null; }else { x(65536 >= ua), la = va; } + var ha = V(aa); + + if (null == la || null == ha || null == ma) { + F.a = 1; + break c; + } + + var pa = ma; + + for (Da = U = 0; Da < W; ++Da) { + var ja = la[Da], + da = ja.G, + ea = ja.H, + Fa = 0, + ra = 1, + Ha = 0; + + for (ba = 0; 5 > ba; ++ba) { + Y = Dc[ba]; + da[ba] = pa; + ea[ba] = U; + !ba && 0 < J && (Y += 1 << J); + + d: { + var sa, + za = Y, + ta = F, + oa = ha, + db = pa, + eb = U, + Ia = 0, + Ka = ta.m, + fb = D(Ka, 1); + M(oa, 0, 0, za); + + if (fb) { + var gb = D(Ka, 1) + 1, + hb = D(Ka, 1), + Ja = D(Ka, 0 == hb ? 1 : 8); + oa[Ja] = 1; + 2 == gb && (Ja = D(Ka, 8), oa[Ja] = 1); + var ya = 1; + } else { + var Ua = V(19), + Va = D(Ka, 4) + 4; + + if (19 < Va) { + ta.a = 3; + var Aa = 0; + break d; + } + + for (sa = 0; sa < Va; ++sa) { + Ua[ne[sa]] = D(Ka, 3); + } + + var Ba = void 0, + sb = void 0, + Wa = ta, + ib = Ua, + Ca = za, + Xa = oa, + Oa = 0, + La = Wa.m, + Ya = 8, + Za = wa(128, O); + + e: for (;;) { + if (!Z(Za, 0, 7, ib, 19)) { break e; } + + if (D(La, 1)) { + var kb = 2 + 2 * D(La, 3), + Ba = 2 + D(La, kb); + if (Ba > Ca) { break e; } + } else { Ba = Ca; } + + for (sb = 0; sb < Ca && Ba--;) { + Sa(La); + var $a = Za[0 + (pb(La) & 127)]; + qb(La, La.u + $a.g); + var jb = $a.value; + if (16 > jb) { Xa[sb++] = jb, 0 != jb && (Ya = jb); }else { + var lb = 16 == jb, + ab = jb - 16, + mb = oe[ab], + bb = D(La, pe[ab]) + mb; + if (sb + bb > Ca) { break e; }else { for (var nb = lb ? Ya : 0; 0 < bb--;) { + Xa[sb++] = nb; + } } + } + } + + Oa = 1; + break e; + } + + Oa || (Wa.a = 3); + ya = Oa; + } + + (ya = ya && !Ka.h) && (Ia = Z(db, eb, 8, oa, za)); + ya && 0 != Ia ? Aa = Ia : (ta.a = 3, Aa = 0); + } + + if (0 == Aa) { break c; } + ra && 1 == qe[ba] && (ra = 0 == pa[U].g); + Fa += pa[U].g; + U += Aa; + + if (3 >= ba) { + var Pa = ha[0], + tb; + + for (tb = 1; tb < Y; ++tb) { + ha[tb] > Pa && (Pa = ha[tb]); + } + + Ha += Pa; + } + } + + ja.nd = ra; + ja.Qb = 0; + ra && (ja.qb = (da[3][ea[3] + 0].value << 24 | da[1][ea[1] + 0].value << 16 | da[2][ea[2] + 0].value) >>> 0, 0 == Fa && 256 > da[0][ea[0] + 0].value && (ja.Qb = 1, ja.qb += da[0][ea[0] + 0].value << 8)); + ja.jc = !ja.Qb && 6 > Ha; + + if (ja.jc) { + var Ga, + Ea = ja; + + for (Ga = 0; Ga < xb; ++Ga) { + var Ma = Ga, + Na = Ea.pd[Ma], + vb = Ea.G[0][Ea.H[0] + Ma]; + 256 <= vb.value ? (Na.g = vb.g + 256, Na.value = vb.value) : (Na.g = 0, Na.value = 0, Ma >>= ub(vb, 8, Na), Ma >>= ub(Ea.G[1][Ea.H[1] + Ma], 16, Na), Ma >>= ub(Ea.G[2][Ea.H[2] + Ma], 0, Na), ub(Ea.G[3][Ea.H[3] + Ma], 24, Na)); + } + } + } + + R.vc = P; + R.Wb = W; + R.Ya = la; + R.yc = ma; + H = 1; + break b; + } + + H = 0; + } } + f = H; + + if (!f) { + d.a = 3; + break a; + } + + if (0 < n) { + if (l.ua = 1 << n, !Zb(l.Wa, n)) { + d.a = 1; + f = 0; + break a; + } + } else { l.ua = 0; } + + var Qa = d, + cb = g, + ob = h, + Ra = Qa.s, + Ta = Ra.xc; + Qa.c = cb; + Qa.i = ob; + Ra.md = xa(cb, Ta); + Ra.wc = 0 == Ta ? -1 : (1 << Ta) - 1; + + if (c) { + d.xb = re; + break a; + } + + m = V(g * h); + + if (null == m) { + d.a = 1; + f = 0; + break a; + } + + f = (f = Jb(d, m, 0, g, h, h, null)) && !k.h; + break a; + } + + f ? (null != e ? e[0] = m : (x(null == m), x(c)), d.$ = 0, c || Ac(l)) : Ac(l); + return f; + } + + function Ec(a, b) { + var c = a.c * a.i, + d = c + b + 16 * b; + x(a.c <= b); + a.V = V(d); + if (null == a.V) { return a.Ta = null, a.Ua = 0, a.a = 1, 0; } + a.Ta = a.V; + a.Ua = a.Ba + c + b; + return 1; + } + + function se(a, b) { + var c = a.C, + d = b - c, + e = a.V, + f = a.Ba + a.c * c; + + for (x(b <= a.l.o); 0 < d;) { + var g = 16 < d ? 16 : d, + h = a.l.ma, + k = a.l.width, + l = k * g, + m = h.ca, + n = h.tb + k * c, + r = a.Ta, + q = a.Ua; + oc(a, g, e, f); + Fc(r, q, m, n, l); + zc(h, c, c + g, m, n, k); + d -= g; + e += g * a.c; + c += g; + } + + x(c == b); + a.C = a.Ma = b; + } + + function te(a, b) { + var c = [0], + d = [0], + e = [0]; + + a: for (;;) { + if (null == a) { return 0; } + if (null == b) { return a.a = 2, 0; } + a.l = b; + a.a = 0; + cb(a.m, b.data, b.w, b.ha); + + if (!mc(a.m, c, d, e)) { + a.a = 3; + break a; + } + + a.xb = Cc; + b.width = c[0]; + b.height = d[0]; + if (!rb(c[0], d[0], 1, a, null)) { break a; } + return 1; + } + + x(0 != a.a); + return 0; + } + + function ue() { + this.ub = this.yd = this.td = this.Rb = 0; + } + + function ve() { + this.Kd = this.Ld = this.Ud = this.Td = this.i = this.c = 0; + } + + function we() { + this.Fb = this.Bb = this.Cb = 0; + this.Zb = V(4); + this.Lb = V(4); + } + + function Gc() { + this.Yb = wb(); + } + + function xe() { + this.jb = V(3); + this.Wc = Ed([4, 8], Gc); + this.Xc = Ed([4, 17], Gc); + } + + function ye() { + this.Pc = this.wb = this.Tb = this.zd = 0; + this.vd = new V(4); + this.od = new V(4); + } + + function Xa() { + this.ld = this.La = this.dd = this.tc = 0; + } + + function Hc() { + this.Na = this.la = 0; + } + + function ze() { + this.Sc = [0, 0]; + this.Eb = [0, 0]; + this.Qc = [0, 0]; + this.ia = this.lc = 0; + } + + function Kb() { + this.ad = V(384); + this.Za = 0; + this.Ob = V(16); + this.$b = this.Ad = this.ia = this.Gc = this.Hc = this.Dd = 0; + } + + function Ae() { + this.uc = this.M = this.Nb = 0; + this.wa = Array(new Xa()); + this.Y = 0; + this.ya = Array(new Kb()); + this.aa = 0; + this.l = new Oa(); + } + + function Ic() { + this.y = V(16); + this.f = V(8); + this.ea = V(8); + } + + function Be() { + this.cb = this.a = 0; + this.sc = ""; + this.m = new Wb(); + this.Od = new ue(); + this.Kc = new ve(); + this.ed = new ye(); + this.Qa = new we(); + this.Ic = this.$c = this.Aa = 0; + this.D = new Ae(); + this.Xb = this.Va = this.Hb = this.zb = this.yb = this.Ub = this.za = 0; + this.Jc = wa(8, Wb); + this.ia = 0; + this.pb = wa(4, ze); + this.Pa = new xe(); + this.Bd = this.kc = 0; + this.Ac = []; + this.Bc = 0; + this.zc = [0, 0, 0, 0]; + this.Gd = Array(new Ic()); + this.Hd = 0; + this.rb = Array(new Hc()); + this.sb = 0; + this.wa = Array(new Xa()); + this.Y = 0; + this.oc = []; + this.pc = 0; + this.sa = []; + this.ta = 0; + this.qa = []; + this.ra = 0; + this.Ha = []; + this.B = this.R = this.Ia = 0; + this.Ec = []; + this.M = this.ja = this.Vb = this.Fc = 0; + this.ya = Array(new Kb()); + this.L = this.aa = 0; + this.gd = Ed([4, 2], Xa); + this.ga = null; + this.Fa = []; + this.Cc = this.qc = this.P = 0; + this.Gb = []; + this.Uc = 0; + this.mb = []; + this.nb = 0; + this.rc = []; + this.Ga = this.Vc = 0; + } + + function ga(a, b) { + return 0 > a ? 0 : a > b ? b : a; + } + + function Oa() { + this.T = this.U = this.ka = this.height = this.width = 0; + this.y = []; + this.f = []; + this.ea = []; + this.Rc = this.fa = this.W = this.N = this.O = 0; + this.ma = "void"; + this.put = "VP8IoPutHook"; + this.ac = "VP8IoSetupHook"; + this.bc = "VP8IoTeardownHook"; + this.ha = this.Kb = 0; + this.data = []; + this.hb = this.ib = this.da = this.o = this.j = this.va = this.v = this.Da = this.ob = this.w = 0; + this.F = []; + this.J = 0; + } + + function Ce() { + var a = new Be(); + null != a && (a.a = 0, a.sc = "OK", a.cb = 0, a.Xb = 0, oa || (oa = De)); + return a; + } + + function T(a, b, c) { + 0 == a.a && (a.a = b, a.sc = c, a.cb = 0); + return 0; + } + + function Jc(a, b, c) { + return 3 <= c && 157 == a[b + 0] && 1 == a[b + 1] && 42 == a[b + 2]; + } + + function Kc(a, b) { + if (null == a) { return 0; } + a.a = 0; + a.sc = "OK"; + if (null == b) { return T(a, 2, "null VP8Io passed to VP8GetHeaders()"); } + var c = b.data; + var d = b.w; + var e = b.ha; + if (4 > e) { return T(a, 7, "Truncated header."); } + var f = c[d + 0] | c[d + 1] << 8 | c[d + 2] << 16; + var g = a.Od; + g.Rb = !(f & 1); + g.td = f >> 1 & 7; + g.yd = f >> 4 & 1; + g.ub = f >> 5; + if (3 < g.td) { return T(a, 3, "Incorrect keyframe parameters."); } + if (!g.yd) { return T(a, 4, "Frame not displayable."); } + d += 3; + e -= 3; + var h = a.Kc; + + if (g.Rb) { + if (7 > e) { return T(a, 7, "cannot parse picture header"); } + if (!Jc(c, d, e)) { return T(a, 3, "Bad code word"); } + h.c = (c[d + 4] << 8 | c[d + 3]) & 16383; + h.Td = c[d + 4] >> 6; + h.i = (c[d + 6] << 8 | c[d + 5]) & 16383; + h.Ud = c[d + 6] >> 6; + d += 7; + e -= 7; + a.za = h.c + 15 >> 4; + a.Ub = h.i + 15 >> 4; + b.width = h.c; + b.height = h.i; + b.Da = 0; + b.j = 0; + b.v = 0; + b.va = b.width; + b.o = b.height; + b.da = 0; + b.ib = b.width; + b.hb = b.height; + b.U = b.width; + b.T = b.height; + f = a.Pa; + M(f.jb, 0, 255, f.jb.length); + f = a.Qa; + x(null != f); + f.Cb = 0; + f.Bb = 0; + f.Fb = 1; + M(f.Zb, 0, 0, f.Zb.length); + M(f.Lb, 0, 0, f.Lb); + } + + if (g.ub > e) { return T(a, 7, "bad partition length"); } + f = a.m; + ma(f, c, d, g.ub); + d += g.ub; + e -= g.ub; + g.Rb && (h.Ld = G(f), h.Kd = G(f)); + h = a.Qa; + var k = a.Pa, + l; + x(null != f); + x(null != h); + h.Cb = G(f); + + if (h.Cb) { + h.Bb = G(f); + + if (G(f)) { + h.Fb = G(f); + + for (l = 0; 4 > l; ++l) { + h.Zb[l] = G(f) ? ca(f, 7) : 0; + } + + for (l = 0; 4 > l; ++l) { + h.Lb[l] = G(f) ? ca(f, 6) : 0; + } + } + + if (h.Bb) { for (l = 0; 3 > l; ++l) { + k.jb[l] = G(f) ? na(f, 8) : 255; + } } + } else { h.Bb = 0; } + + if (f.Ka) { return T(a, 3, "cannot parse segment header"); } + h = a.ed; + h.zd = G(f); + h.Tb = na(f, 6); + h.wb = na(f, 3); + h.Pc = G(f); + + if (h.Pc && G(f)) { + for (k = 0; 4 > k; ++k) { + G(f) && (h.vd[k] = ca(f, 6)); + } + + for (k = 0; 4 > k; ++k) { + G(f) && (h.od[k] = ca(f, 6)); + } + } + + a.L = 0 == h.Tb ? 0 : h.zd ? 1 : 2; + if (f.Ka) { return T(a, 3, "cannot parse filter header"); } + l = d; + var m = e; + e = l; + d = l + m; + h = m; + a.Xb = (1 << na(a.m, 2)) - 1; + k = a.Xb; + if (m < 3 * k) { c = 7; }else { + l += 3 * k; + h -= 3 * k; + + for (m = 0; m < k; ++m) { + var n = c[e + 0] | c[e + 1] << 8 | c[e + 2] << 16; + n > h && (n = h); + ma(a.Jc[+m], c, l, n); + l += n; + h -= n; + e += 3; + } + + ma(a.Jc[+k], c, l, h); + c = l < d ? 0 : 5; + } + if (0 != c) { return T(a, c, "cannot parse partitions"); } + l = a.m; + c = na(l, 7); + e = G(l) ? ca(l, 4) : 0; + d = G(l) ? ca(l, 4) : 0; + h = G(l) ? ca(l, 4) : 0; + k = G(l) ? ca(l, 4) : 0; + l = G(l) ? ca(l, 4) : 0; + m = a.Qa; + + for (n = 0; 4 > n; ++n) { + if (m.Cb) { + var r = m.Zb[n]; + m.Fb || (r += c); + } else if (0 < n) { + a.pb[n] = a.pb[0]; + continue; + } else { r = c; } + + var q = a.pb[n]; + q.Sc[0] = Lb[ga(r + e, 127)]; + q.Sc[1] = Mb[ga(r + 0, 127)]; + q.Eb[0] = 2 * Lb[ga(r + d, 127)]; + q.Eb[1] = 101581 * Mb[ga(r + h, 127)] >> 16; + 8 > q.Eb[1] && (q.Eb[1] = 8); + q.Qc[0] = Lb[ga(r + k, 117)]; + q.Qc[1] = Mb[ga(r + l, 127)]; + q.lc = r + l; + } + + if (!g.Rb) { return T(a, 4, "Not a key frame."); } + G(f); + g = a.Pa; + + for (c = 0; 4 > c; ++c) { + for (e = 0; 8 > e; ++e) { + for (d = 0; 3 > d; ++d) { + for (h = 0; 11 > h; ++h) { + k = K(f, Ee[c][e][d][h]) ? na(f, 8) : Fe[c][e][d][h], g.Wc[c][e].Yb[d][h] = k; + } + } + } + + for (e = 0; 17 > e; ++e) { + g.Xc[c][e] = g.Wc[c][Ge[e]]; + } + } + + a.kc = G(f); + a.kc && (a.Bd = na(f, 8)); + return a.cb = 1; + } + + function De(a, b, c, d, e, f, g) { + var h = b[e].Yb[c]; + + for (c = 0; 16 > e; ++e) { + if (!K(a, h[c + 0])) { return e; } + + for (; !K(a, h[c + 1]);) { + if (h = b[++e].Yb[0], c = 0, 16 == e) { return 16; } + } + + var k = b[e + 1].Yb; + + if (K(a, h[c + 2])) { + var l = a, + m = h, + n = c; + var r = 0; + if (K(l, m[n + 3])) { + if (K(l, m[n + 6])) { + h = 0; + r = K(l, m[n + 8]); + m = K(l, m[n + 9 + r]); + n = 2 * r + m; + r = 0; + + for (m = He[n]; m[h]; ++h) { + r += r + K(l, m[h]); + } + + r += 3 + (8 << n); + } else { K(l, m[n + 7]) ? (r = 7 + 2 * K(l, 165), r += K(l, 145)) : r = 5 + K(l, 159); } + } else { K(l, m[n + 4]) ? r = 3 + K(l, m[n + 5]) : r = 2; } + h = k[2]; + } else { r = 1, h = k[1]; } + + k = g + Ie[e]; + l = a; + 0 > l.b && Qa(l); + var m = l.b, + n = l.Ca >> 1, + q = n - (l.I >> m) >> 31; + --l.b; + l.Ca += q; + l.Ca |= 1; + l.I -= (n + 1 & q) << m; + f[k] = ((r ^ q) - q) * d[(0 < e) + 0]; + } + + return 16; + } + + function Lc(a) { + var b = a.rb[a.sb - 1]; + b.la = 0; + b.Na = 0; + M(a.zc, 0, 0, a.zc.length); + a.ja = 0; + } + + function Je(a, b) { + for (a.M = 0; a.M < a.Va; ++a.M) { + var c = a.Jc[a.M & a.Xb], + d = a.m, + e = a, + f; + + for (f = 0; f < e.za; ++f) { + var g = d; + var h = e; + var k = h.Ac, + l = h.Bc + 4 * f, + m = h.zc, + n = h.ya[h.aa + f]; + h.Qa.Bb ? n.$b = K(g, h.Pa.jb[0]) ? 2 + K(g, h.Pa.jb[2]) : K(g, h.Pa.jb[1]) : n.$b = 0; + h.kc && (n.Ad = K(g, h.Bd)); + n.Za = !K(g, 145) + 0; + + if (n.Za) { + var r = n.Ob, + q = 0; + + for (h = 0; 4 > h; ++h) { + var t = m[0 + h]; + var v; + + for (v = 0; 4 > v; ++v) { + t = Ke[k[l + v]][t]; + + for (var p = Mc[K(g, t[0])]; 0 < p;) { + p = Mc[2 * p + K(g, t[p])]; + } + + t = -p; + k[l + v] = t; + } + + I(r, q, k, l, 4); + q += 4; + m[0 + h] = t; + } + } else { t = K(g, 156) ? K(g, 128) ? 1 : 3 : K(g, 163) ? 2 : 0, n.Ob[0] = t, M(k, l, t, 4), M(m, 0, t, 4); } + + n.Dd = K(g, 142) ? K(g, 114) ? K(g, 183) ? 1 : 3 : 2 : 0; + } + + if (e.m.Ka) { return T(a, 7, "Premature end-of-partition0 encountered."); } + + for (; a.ja < a.za; ++a.ja) { + d = a; + e = c; + g = d.rb[d.sb - 1]; + k = d.rb[d.sb + d.ja]; + f = d.ya[d.aa + d.ja]; + if (l = d.kc ? f.Ad : 0) { g.la = k.la = 0, f.Za || (g.Na = k.Na = 0), f.Hc = 0, f.Gc = 0, f.ia = 0; }else { + var u, + w, + g = k, + k = e, + l = d.Pa.Xc, + m = d.ya[d.aa + d.ja], + n = d.pb[m.$b]; + h = m.ad; + r = 0; + q = d.rb[d.sb - 1]; + t = v = 0; + M(h, r, 0, 384); + + if (m.Za) { + var y = 0; + var A = l[3]; + } else { + p = V(16); + var E = g.Na + q.Na; + E = oa(k, l[1], E, n.Eb, 0, p, 0); + g.Na = q.Na = (0 < E) + 0; + if (1 < E) { Nc(p, 0, h, r); }else { + var B = p[0] + 3 >> 3; + + for (p = 0; 256 > p; p += 16) { + h[r + p] = B; + } + } + y = 1; + A = l[0]; + } + + var C = g.la & 15; + var N = q.la & 15; + + for (p = 0; 4 > p; ++p) { + var z = N & 1; + + for (B = w = 0; 4 > B; ++B) { + E = z + (C & 1), E = oa(k, A, E, n.Sc, y, h, r), z = E > y, C = C >> 1 | z << 7, w = w << 2 | (3 < E ? 3 : 1 < E ? 2 : 0 != h[r + 0]), r += 16; + } + + C >>= 4; + N = N >> 1 | z << 7; + v = (v << 8 | w) >>> 0; + } + + A = C; + y = N >> 4; + + for (u = 0; 4 > u; u += 2) { + w = 0; + C = g.la >> 4 + u; + N = q.la >> 4 + u; + + for (p = 0; 2 > p; ++p) { + z = N & 1; + + for (B = 0; 2 > B; ++B) { + E = z + (C & 1), E = oa(k, l[2], E, n.Qc, 0, h, r), z = 0 < E, C = C >> 1 | z << 3, w = w << 2 | (3 < E ? 3 : 1 < E ? 2 : 0 != h[r + 0]), r += 16; + } + + C >>= 2; + N = N >> 1 | z << 5; + } + + t |= w << 4 * u; + A |= C << 4 << u; + y |= (N & 240) << u; + } + + g.la = A; + q.la = y; + m.Hc = v; + m.Gc = t; + m.ia = t & 43690 ? 0 : n.ia; + l = !(v | t); + } + 0 < d.L && (d.wa[d.Y + d.ja] = d.gd[f.$b][f.Za], d.wa[d.Y + d.ja].La |= !l); + if (e.Ka) { return T(a, 7, "Premature end-of-file encountered."); } + } + + Lc(a); + c = a; + d = b; + e = 1; + f = c.D; + g = 0 < c.L && c.M >= c.zb && c.M <= c.Va; + if (0 == c.Aa) { a: { + f.M = c.M, f.uc = g, Oc(c, f), e = 1; + w = c.D; + f = w.Nb; + t = Ya[c.L]; + g = t * c.R; + k = t / 2 * c.B; + p = 16 * f * c.R; + B = 8 * f * c.B; + l = c.sa; + m = c.ta - g + p; + n = c.qa; + h = c.ra - k + B; + r = c.Ha; + q = c.Ia - k + B; + C = w.M; + N = 0 == C; + v = C >= c.Va - 1; + 2 == c.Aa && Oc(c, w); + if (w.uc) { for (E = c, z = E.D.M, x(E.D.uc), w = E.yb; w < E.Hb; ++w) { + var Q = E; + y = w; + A = z; + var S = Q.D, + D = S.Nb; + u = Q.R; + var S = S.wa[S.Y + y], + F = Q.sa, + H = Q.ta + 16 * D * u + 16 * y, + J = S.dd, + G = S.tc; + if (0 != G) { if (x(3 <= G), 1 == Q.L) { 0 < y && Pc(F, H, u, G + 4), S.La && Qc(F, H, u, G), 0 < A && Rc(F, H, u, G + 4), S.La && Sc(F, H, u, G); }else { + var L = Q.B, + O = Q.qa, + P = Q.ra + 8 * D * L + 8 * y, + R = Q.Ha, + Q = Q.Ia + 8 * D * L + 8 * y, + D = S.ld; + 0 < y && (Tc(F, H, u, G + 4, J, D), Uc(O, P, R, Q, L, G + 4, J, D)); + S.La && (Vc(F, H, u, G, J, D), Wc(O, P, R, Q, L, G, J, D)); + 0 < A && (Xc(F, H, u, G + 4, J, D), Yc(O, P, R, Q, L, G + 4, J, D)); + S.La && (Zc(F, H, u, G, J, D), $c(O, P, R, Q, L, G, J, D)); + } } + } } + c.ia && alert("todo:DitherRow"); + + if (null != d.put) { + w = 16 * C; + C = 16 * (C + 1); + N ? (d.y = c.sa, d.O = c.ta + p, d.f = c.qa, d.N = c.ra + B, d.ea = c.Ha, d.W = c.Ia + B) : (w -= t, d.y = l, d.O = m, d.f = n, d.N = h, d.ea = r, d.W = q); + v || (C -= t); + C > d.o && (C = d.o); + d.F = null; + d.J = null; + + if (null != c.Fa && 0 < c.Fa.length && w < C && (d.J = Le(c, d, w, C - w), d.F = c.mb, null == d.F && 0 == d.F.length)) { + e = T(c, 3, "Could not decode alpha data."); + break a; + } + + w < d.j && (t = d.j - w, w = d.j, x(!(t & 1)), d.O += c.R * t, d.N += c.B * (t >> 1), d.W += c.B * (t >> 1), null != d.F && (d.J += d.width * t)); + w < C && (d.O += d.v, d.N += d.v >> 1, d.W += d.v >> 1, null != d.F && (d.J += d.v), d.ka = w - d.j, d.U = d.va - d.v, d.T = C - w, e = d.put(d)); + } + + f + 1 != c.Ic || v || (I(c.sa, c.ta - g, l, m + 16 * c.R, g), I(c.qa, c.ra - k, n, h + 8 * c.B, k), I(c.Ha, c.Ia - k, r, q + 8 * c.B, k)); + } } + if (!e) { return T(a, 6, "Output aborted."); } + } + + return 1; + } + + function Me(a, b) { + if (null == a) { return 0; } + if (null == b) { return T(a, 2, "NULL VP8Io parameter in VP8Decode()."); } + if (!a.cb && !Kc(a, b)) { return 0; } + x(a.cb); + + if (null == b.ac || b.ac(b)) { + b.ob && (a.L = 0); + var c = Ya[a.L]; + 2 == a.L ? (a.yb = 0, a.zb = 0) : (a.yb = b.v - c >> 4, a.zb = b.j - c >> 4, 0 > a.yb && (a.yb = 0), 0 > a.zb && (a.zb = 0)); + a.Va = b.o + 15 + c >> 4; + a.Hb = b.va + 15 + c >> 4; + a.Hb > a.za && (a.Hb = a.za); + a.Va > a.Ub && (a.Va = a.Ub); + + if (0 < a.L) { + var d = a.ed; + + for (c = 0; 4 > c; ++c) { + var e; + + if (a.Qa.Cb) { + var f = a.Qa.Lb[c]; + a.Qa.Fb || (f += d.Tb); + } else { f = d.Tb; } + + for (e = 0; 1 >= e; ++e) { + var g = a.gd[c][e], + h = f; + d.Pc && (h += d.vd[0], e && (h += d.od[0])); + h = 0 > h ? 0 : 63 < h ? 63 : h; + + if (0 < h) { + var k = h; + 0 < d.wb && (k = 4 < d.wb ? k >> 2 : k >> 1, k > 9 - d.wb && (k = 9 - d.wb)); + 1 > k && (k = 1); + g.dd = k; + g.tc = 2 * h + k; + g.ld = 40 <= h ? 2 : 15 <= h ? 1 : 0; + } else { g.tc = 0; } + + g.La = e; + } + } + } + + c = 0; + } else { T(a, 6, "Frame setup failed"), c = a.a; } + + if (c = 0 == c) { + if (c) { + a.$c = 0; + 0 < a.Aa || (a.Ic = Ne); + + b: { + c = a.Ic; + var k = a.za, + d = 4 * k, + l = 32 * k, + m = k + 1, + n = 0 < a.L ? k * (0 < a.Aa ? 2 : 1) : 0, + r = (2 == a.Aa ? 2 : 1) * k; + e = 3 * (16 * c + Ya[a.L]) / 2 * l; + f = null != a.Fa && 0 < a.Fa.length ? a.Kc.c * a.Kc.i : 0; + g = d + 832 + e + f; + if (g != g) { c = 0; }else { + if (g > a.Vb) { + a.Vb = 0; + a.Ec = V(g); + a.Fc = 0; + + if (null == a.Ec) { + c = T(a, 1, "no memory during frame initialization."); + break b; + } + + a.Vb = g; + } + + g = a.Ec; + h = a.Fc; + a.Ac = g; + a.Bc = h; + h += d; + a.Gd = wa(l, Ic); + a.Hd = 0; + a.rb = wa(m + 1, Hc); + a.sb = 1; + a.wa = n ? wa(n, Xa) : null; + a.Y = 0; + a.D.Nb = 0; + a.D.wa = a.wa; + a.D.Y = a.Y; + 0 < a.Aa && (a.D.Y += k); + x(!0); + a.oc = g; + a.pc = h; + h += 832; + a.ya = wa(r, Kb); + a.aa = 0; + a.D.ya = a.ya; + a.D.aa = a.aa; + 2 == a.Aa && (a.D.aa += k); + a.R = 16 * k; + a.B = 8 * k; + l = Ya[a.L]; + k = l * a.R; + l = l / 2 * a.B; + a.sa = g; + a.ta = h + k; + a.qa = a.sa; + a.ra = a.ta + 16 * c * a.R + l; + a.Ha = a.qa; + a.Ia = a.ra + 8 * c * a.B + l; + a.$c = 0; + h += e; + a.mb = f ? g : null; + a.nb = f ? h : null; + x(h + f <= a.Fc + a.Vb); + Lc(a); + M(a.Ac, a.Bc, 0, d); + c = 1; + } + } + + if (c) { + b.ka = 0; + b.y = a.sa; + b.O = a.ta; + b.f = a.qa; + b.N = a.ra; + b.ea = a.Ha; + b.Vd = a.Ia; + b.fa = a.R; + b.Rc = a.B; + b.F = null; + b.J = 0; + + if (!ad) { + for (c = -255; 255 >= c; ++c) { + bd[255 + c] = 0 > c ? -c : c; + } + + for (c = -1020; 1020 >= c; ++c) { + cd[1020 + c] = -128 > c ? -128 : 127 < c ? 127 : c; + } + + for (c = -112; 112 >= c; ++c) { + dd[112 + c] = -16 > c ? -16 : 15 < c ? 15 : c; + } + + for (c = -255; 510 >= c; ++c) { + ed[255 + c] = 0 > c ? 0 : 255 < c ? 255 : c; + } + + ad = 1; + } + + Nc = Oe; + Za = Pe; + Nb = Qe; + pa = Re; + Ob = Se; + fd = Te; + Xc = Ue; + Tc = Ve; + Yc = We; + Uc = Xe; + Zc = Ye; + Vc = Ze; + $c = $e; + Wc = af; + Rc = gd; + Pc = hd; + Sc = bf; + Qc = cf; + W[0] = df; + W[1] = ef; + W[2] = ff; + W[3] = gf; + W[4] = hf; + W[5] = jf; + W[6] = kf; + W[7] = lf; + W[8] = mf; + W[9] = nf; + Y[0] = of; + Y[1] = pf; + Y[2] = qf; + Y[3] = rf; + Y[4] = sf; + Y[5] = tf; + Y[6] = uf; + ka[0] = vf; + ka[1] = wf; + ka[2] = xf; + ka[3] = yf; + ka[4] = zf; + ka[5] = Af; + ka[6] = Bf; + c = 1; + } else { c = 0; } + } + + c && (c = Je(a, b)); + null != b.bc && b.bc(b); + c &= 1; + } + + if (!c) { return 0; } + a.cb = 0; + return c; + } + + function qa(a, b, c, d, e) { + e = a[b + c + 32 * d] + (e >> 3); + a[b + c + 32 * d] = e & -256 ? 0 > e ? 0 : 255 : e; + } + + function kb(a, b, c, d, e, f) { + qa(a, b, 0, c, d + e); + qa(a, b, 1, c, d + f); + qa(a, b, 2, c, d - f); + qa(a, b, 3, c, d - e); + } + + function da(a) { + return (20091 * a >> 16) + a; + } + + function id(a, b, c, d) { + var e = 0, + f; + var g = V(16); + + for (f = 0; 4 > f; ++f) { + var h = a[b + 0] + a[b + 8]; + var k = a[b + 0] - a[b + 8]; + var l = (35468 * a[b + 4] >> 16) - da(a[b + 12]); + var m = da(a[b + 4]) + (35468 * a[b + 12] >> 16); + g[e + 0] = h + m; + g[e + 1] = k + l; + g[e + 2] = k - l; + g[e + 3] = h - m; + e += 4; + b++; + } + + for (f = e = 0; 4 > f; ++f) { + a = g[e + 0] + 4, h = a + g[e + 8], k = a - g[e + 8], l = (35468 * g[e + 4] >> 16) - da(g[e + 12]), m = da(g[e + 4]) + (35468 * g[e + 12] >> 16), qa(c, d, 0, 0, h + m), qa(c, d, 1, 0, k + l), qa(c, d, 2, 0, k - l), qa(c, d, 3, 0, h - m), e++, d += 32; + } + } + + function Te(a, b, c, d) { + var e = a[b + 0] + 4, + f = 35468 * a[b + 4] >> 16, + g = da(a[b + 4]), + h = 35468 * a[b + 1] >> 16; + a = da(a[b + 1]); + kb(c, d, 0, e + g, a, h); + kb(c, d, 1, e + f, a, h); + kb(c, d, 2, e - f, a, h); + kb(c, d, 3, e - g, a, h); + } + + function Pe(a, b, c, d, e) { + id(a, b, c, d); + e && id(a, b + 16, c, d + 4); + } + + function Qe(a, b, c, d) { + Za(a, b + 0, c, d, 1); + Za(a, b + 32, c, d + 128, 1); + } + + function Re(a, b, c, d) { + a = a[b + 0] + 4; + var e; + + for (e = 0; 4 > e; ++e) { + for (b = 0; 4 > b; ++b) { + qa(c, d, b, e, a); + } + } + } + + function Se(a, b, c, d) { + a[b + 0] && pa(a, b + 0, c, d); + a[b + 16] && pa(a, b + 16, c, d + 4); + a[b + 32] && pa(a, b + 32, c, d + 128); + a[b + 48] && pa(a, b + 48, c, d + 128 + 4); + } + + function Oe(a, b, c, d) { + var e = V(16), + f; + + for (f = 0; 4 > f; ++f) { + var g = a[b + 0 + f] + a[b + 12 + f]; + var h = a[b + 4 + f] + a[b + 8 + f]; + var k = a[b + 4 + f] - a[b + 8 + f]; + var l = a[b + 0 + f] - a[b + 12 + f]; + e[0 + f] = g + h; + e[8 + f] = g - h; + e[4 + f] = l + k; + e[12 + f] = l - k; + } + + for (f = 0; 4 > f; ++f) { + a = e[0 + 4 * f] + 3, g = a + e[3 + 4 * f], h = e[1 + 4 * f] + e[2 + 4 * f], k = e[1 + 4 * f] - e[2 + 4 * f], l = a - e[3 + 4 * f], c[d + 0] = g + h >> 3, c[d + 16] = l + k >> 3, c[d + 32] = g - h >> 3, c[d + 48] = l - k >> 3, d += 64; + } + } + + function Pb(a, b, c) { + var d = b - 32, + e = R, + f = 255 - a[d - 1], + g; + + for (g = 0; g < c; ++g) { + var h = e, + k = f + a[b - 1], + l; + + for (l = 0; l < c; ++l) { + a[b + l] = h[k + a[d + l]]; + } + + b += 32; + } + } + + function ef(a, b) { + Pb(a, b, 4); + } + + function wf(a, b) { + Pb(a, b, 8); + } + + function pf(a, b) { + Pb(a, b, 16); + } + + function qf(a, b) { + var c; + + for (c = 0; 16 > c; ++c) { + I(a, b + 32 * c, a, b - 32, 16); + } + } + + function rf(a, b) { + var c; + + for (c = 16; 0 < c; --c) { + M(a, b, a[b - 1], 16), b += 32; + } + } + + function $a(a, b, c) { + var d; + + for (d = 0; 16 > d; ++d) { + M(b, c + 32 * d, a, 16); + } + } + + function of(a, b) { + var c = 16, + d; + + for (d = 0; 16 > d; ++d) { + c += a[b - 1 + 32 * d] + a[b + d - 32]; + } + + $a(c >> 5, a, b); + } + + function sf(a, b) { + var c = 8, + d; + + for (d = 0; 16 > d; ++d) { + c += a[b - 1 + 32 * d]; + } + + $a(c >> 4, a, b); + } + + function tf(a, b) { + var c = 8, + d; + + for (d = 0; 16 > d; ++d) { + c += a[b + d - 32]; + } + + $a(c >> 4, a, b); + } + + function uf(a, b) { + $a(128, a, b); + } + + function z(a, b, c) { + return a + 2 * b + c + 2 >> 2; + } + + function ff(a, b) { + var c = b - 32, + c = new Uint8Array([z(a[c - 1], a[c + 0], a[c + 1]), z(a[c + 0], a[c + 1], a[c + 2]), z(a[c + 1], a[c + 2], a[c + 3]), z(a[c + 2], a[c + 3], a[c + 4])]), + d; + + for (d = 0; 4 > d; ++d) { + I(a, b + 32 * d, c, 0, c.length); + } + } + + function gf(a, b) { + var c = a[b - 1], + d = a[b - 1 + 32], + e = a[b - 1 + 64], + f = a[b - 1 + 96]; + ra(a, b + 0, 16843009 * z(a[b - 1 - 32], c, d)); + ra(a, b + 32, 16843009 * z(c, d, e)); + ra(a, b + 64, 16843009 * z(d, e, f)); + ra(a, b + 96, 16843009 * z(e, f, f)); + } + + function df(a, b) { + var c = 4, + d; + + for (d = 0; 4 > d; ++d) { + c += a[b + d - 32] + a[b - 1 + 32 * d]; + } + + c >>= 3; + + for (d = 0; 4 > d; ++d) { + M(a, b + 32 * d, c, 4); + } + } + + function hf(a, b) { + var c = a[b - 1 + 0], + d = a[b - 1 + 32], + e = a[b - 1 + 64], + f = a[b - 1 - 32], + g = a[b + 0 - 32], + h = a[b + 1 - 32], + k = a[b + 2 - 32], + l = a[b + 3 - 32]; + a[b + 0 + 96] = z(d, e, a[b - 1 + 96]); + a[b + 1 + 96] = a[b + 0 + 64] = z(c, d, e); + a[b + 2 + 96] = a[b + 1 + 64] = a[b + 0 + 32] = z(f, c, d); + a[b + 3 + 96] = a[b + 2 + 64] = a[b + 1 + 32] = a[b + 0 + 0] = z(g, f, c); + a[b + 3 + 64] = a[b + 2 + 32] = a[b + 1 + 0] = z(h, g, f); + a[b + 3 + 32] = a[b + 2 + 0] = z(k, h, g); + a[b + 3 + 0] = z(l, k, h); + } + + function kf(a, b) { + var c = a[b + 1 - 32], + d = a[b + 2 - 32], + e = a[b + 3 - 32], + f = a[b + 4 - 32], + g = a[b + 5 - 32], + h = a[b + 6 - 32], + k = a[b + 7 - 32]; + a[b + 0 + 0] = z(a[b + 0 - 32], c, d); + a[b + 1 + 0] = a[b + 0 + 32] = z(c, d, e); + a[b + 2 + 0] = a[b + 1 + 32] = a[b + 0 + 64] = z(d, e, f); + a[b + 3 + 0] = a[b + 2 + 32] = a[b + 1 + 64] = a[b + 0 + 96] = z(e, f, g); + a[b + 3 + 32] = a[b + 2 + 64] = a[b + 1 + 96] = z(f, g, h); + a[b + 3 + 64] = a[b + 2 + 96] = z(g, h, k); + a[b + 3 + 96] = z(h, k, k); + } + + function jf(a, b) { + var c = a[b - 1 + 0], + d = a[b - 1 + 32], + e = a[b - 1 + 64], + f = a[b - 1 - 32], + g = a[b + 0 - 32], + h = a[b + 1 - 32], + k = a[b + 2 - 32], + l = a[b + 3 - 32]; + a[b + 0 + 0] = a[b + 1 + 64] = f + g + 1 >> 1; + a[b + 1 + 0] = a[b + 2 + 64] = g + h + 1 >> 1; + a[b + 2 + 0] = a[b + 3 + 64] = h + k + 1 >> 1; + a[b + 3 + 0] = k + l + 1 >> 1; + a[b + 0 + 96] = z(e, d, c); + a[b + 0 + 64] = z(d, c, f); + a[b + 0 + 32] = a[b + 1 + 96] = z(c, f, g); + a[b + 1 + 32] = a[b + 2 + 96] = z(f, g, h); + a[b + 2 + 32] = a[b + 3 + 96] = z(g, h, k); + a[b + 3 + 32] = z(h, k, l); + } + + function lf(a, b) { + var c = a[b + 0 - 32], + d = a[b + 1 - 32], + e = a[b + 2 - 32], + f = a[b + 3 - 32], + g = a[b + 4 - 32], + h = a[b + 5 - 32], + k = a[b + 6 - 32], + l = a[b + 7 - 32]; + a[b + 0 + 0] = c + d + 1 >> 1; + a[b + 1 + 0] = a[b + 0 + 64] = d + e + 1 >> 1; + a[b + 2 + 0] = a[b + 1 + 64] = e + f + 1 >> 1; + a[b + 3 + 0] = a[b + 2 + 64] = f + g + 1 >> 1; + a[b + 0 + 32] = z(c, d, e); + a[b + 1 + 32] = a[b + 0 + 96] = z(d, e, f); + a[b + 2 + 32] = a[b + 1 + 96] = z(e, f, g); + a[b + 3 + 32] = a[b + 2 + 96] = z(f, g, h); + a[b + 3 + 64] = z(g, h, k); + a[b + 3 + 96] = z(h, k, l); + } + + function nf(a, b) { + var c = a[b - 1 + 0], + d = a[b - 1 + 32], + e = a[b - 1 + 64], + f = a[b - 1 + 96]; + a[b + 0 + 0] = c + d + 1 >> 1; + a[b + 2 + 0] = a[b + 0 + 32] = d + e + 1 >> 1; + a[b + 2 + 32] = a[b + 0 + 64] = e + f + 1 >> 1; + a[b + 1 + 0] = z(c, d, e); + a[b + 3 + 0] = a[b + 1 + 32] = z(d, e, f); + a[b + 3 + 32] = a[b + 1 + 64] = z(e, f, f); + a[b + 3 + 64] = a[b + 2 + 64] = a[b + 0 + 96] = a[b + 1 + 96] = a[b + 2 + 96] = a[b + 3 + 96] = f; + } + + function mf(a, b) { + var c = a[b - 1 + 0], + d = a[b - 1 + 32], + e = a[b - 1 + 64], + f = a[b - 1 + 96], + g = a[b - 1 - 32], + h = a[b + 0 - 32], + k = a[b + 1 - 32], + l = a[b + 2 - 32]; + a[b + 0 + 0] = a[b + 2 + 32] = c + g + 1 >> 1; + a[b + 0 + 32] = a[b + 2 + 64] = d + c + 1 >> 1; + a[b + 0 + 64] = a[b + 2 + 96] = e + d + 1 >> 1; + a[b + 0 + 96] = f + e + 1 >> 1; + a[b + 3 + 0] = z(h, k, l); + a[b + 2 + 0] = z(g, h, k); + a[b + 1 + 0] = a[b + 3 + 32] = z(c, g, h); + a[b + 1 + 32] = a[b + 3 + 64] = z(d, c, g); + a[b + 1 + 64] = a[b + 3 + 96] = z(e, d, c); + a[b + 1 + 96] = z(f, e, d); + } + + function xf(a, b) { + var c; + + for (c = 0; 8 > c; ++c) { + I(a, b + 32 * c, a, b - 32, 8); + } + } + + function yf(a, b) { + var c; + + for (c = 0; 8 > c; ++c) { + M(a, b, a[b - 1], 8), b += 32; + } + } + + function lb(a, b, c) { + var d; + + for (d = 0; 8 > d; ++d) { + M(b, c + 32 * d, a, 8); + } + } + + function vf(a, b) { + var c = 8, + d; + + for (d = 0; 8 > d; ++d) { + c += a[b + d - 32] + a[b - 1 + 32 * d]; + } + + lb(c >> 4, a, b); + } + + function Af(a, b) { + var c = 4, + d; + + for (d = 0; 8 > d; ++d) { + c += a[b + d - 32]; + } + + lb(c >> 3, a, b); + } + + function zf(a, b) { + var c = 4, + d; + + for (d = 0; 8 > d; ++d) { + c += a[b - 1 + 32 * d]; + } + + lb(c >> 3, a, b); + } + + function Bf(a, b) { + lb(128, a, b); + } + + function ab(a, b, c) { + var d = a[b - c], + e = a[b + 0], + f = 3 * (e - d) + Qb[1020 + a[b - 2 * c] - a[b + c]], + g = mb[112 + (f + 4 >> 3)]; + a[b - c] = R[255 + d + mb[112 + (f + 3 >> 3)]]; + a[b + 0] = R[255 + e - g]; + } + + function jd(a, b, c, d) { + var e = a[b + 0], + f = a[b + c]; + return U[255 + a[b - 2 * c] - a[b - c]] > d || U[255 + f - e] > d; + } + + function kd(a, b, c, d) { + return 4 * U[255 + a[b - c] - a[b + 0]] + U[255 + a[b - 2 * c] - a[b + c]] <= d; + } + + function ld(a, b, c, d, e) { + var f = a[b - 3 * c], + g = a[b - 2 * c], + h = a[b - c], + k = a[b + 0], + l = a[b + c], + m = a[b + 2 * c], + n = a[b + 3 * c]; + return 4 * U[255 + h - k] + U[255 + g - l] > d ? 0 : U[255 + a[b - 4 * c] - f] <= e && U[255 + f - g] <= e && U[255 + g - h] <= e && U[255 + n - m] <= e && U[255 + m - l] <= e && U[255 + l - k] <= e; + } + + function gd(a, b, c, d) { + var e = 2 * d + 1; + + for (d = 0; 16 > d; ++d) { + kd(a, b + d, c, e) && ab(a, b + d, c); + } + } + + function hd(a, b, c, d) { + var e = 2 * d + 1; + + for (d = 0; 16 > d; ++d) { + kd(a, b + d * c, 1, e) && ab(a, b + d * c, 1); + } + } + + function bf(a, b, c, d) { + var e; + + for (e = 3; 0 < e; --e) { + b += 4 * c, gd(a, b, c, d); + } + } + + function cf(a, b, c, d) { + var e; + + for (e = 3; 0 < e; --e) { + b += 4, hd(a, b, c, d); + } + } + + function ea(a, b, c, d, e, f, g, h) { + for (f = 2 * f + 1; 0 < e--;) { + if (ld(a, b, c, f, g)) { if (jd(a, b, c, h)) { ab(a, b, c); }else { + var k = a, + l = b, + m = c, + n = k[l - 2 * m], + r = k[l - m], + q = k[l + 0], + t = k[l + m], + v = k[l + 2 * m], + p = Qb[1020 + 3 * (q - r) + Qb[1020 + n - t]], + u = 27 * p + 63 >> 7, + w = 18 * p + 63 >> 7, + p = 9 * p + 63 >> 7; + k[l - 3 * m] = R[255 + k[l - 3 * m] + p]; + k[l - 2 * m] = R[255 + n + w]; + k[l - m] = R[255 + r + u]; + k[l + 0] = R[255 + q - u]; + k[l + m] = R[255 + t - w]; + k[l + 2 * m] = R[255 + v - p]; + } } + b += d; + } + } + + function Fa(a, b, c, d, e, f, g, h) { + for (f = 2 * f + 1; 0 < e--;) { + if (ld(a, b, c, f, g)) { if (jd(a, b, c, h)) { ab(a, b, c); }else { + var k = a, + l = b, + m = c, + n = k[l - m], + r = k[l + 0], + q = k[l + m], + t = 3 * (r - n), + v = mb[112 + (t + 4 >> 3)], + t = mb[112 + (t + 3 >> 3)], + p = v + 1 >> 1; + k[l - 2 * m] = R[255 + k[l - 2 * m] + p]; + k[l - m] = R[255 + n + t]; + k[l + 0] = R[255 + r - v]; + k[l + m] = R[255 + q - p]; + } } + b += d; + } + } + + function Ue(a, b, c, d, e, f) { + ea(a, b, c, 1, 16, d, e, f); + } + + function Ve(a, b, c, d, e, f) { + ea(a, b, 1, c, 16, d, e, f); + } + + function Ye(a, b, c, d, e, f) { + var g; + + for (g = 3; 0 < g; --g) { + b += 4 * c, Fa(a, b, c, 1, 16, d, e, f); + } + } + + function Ze(a, b, c, d, e, f) { + var g; + + for (g = 3; 0 < g; --g) { + b += 4, Fa(a, b, 1, c, 16, d, e, f); + } + } + + function We(a, b, c, d, e, f, g, h) { + ea(a, b, e, 1, 8, f, g, h); + ea(c, d, e, 1, 8, f, g, h); + } + + function Xe(a, b, c, d, e, f, g, h) { + ea(a, b, 1, e, 8, f, g, h); + ea(c, d, 1, e, 8, f, g, h); + } + + function $e(a, b, c, d, e, f, g, h) { + Fa(a, b + 4 * e, e, 1, 8, f, g, h); + Fa(c, d + 4 * e, e, 1, 8, f, g, h); + } + + function af(a, b, c, d, e, f, g, h) { + Fa(a, b + 4, 1, e, 8, f, g, h); + Fa(c, d + 4, 1, e, 8, f, g, h); + } + + function Cf() { + this.ba = new Cb(); + this.ec = []; + this.cc = []; + this.Mc = []; + this.Dc = this.Nc = this.dc = this.fc = 0; + this.Oa = new Ud(); + this.memory = 0; + this.Ib = "OutputFunc"; + this.Jb = "OutputAlphaFunc"; + this.Nd = "OutputRowFunc"; + } + + function md() { + this.data = []; + this.offset = this.kd = this.ha = this.w = 0; + this.na = []; + this.xa = this.gb = this.Ja = this.Sa = this.P = 0; + } + + function Df() { + this.nc = this.Ea = this.b = this.hc = 0; + this.K = []; + this.w = 0; + } + + function Ef() { + this.ua = 0; + this.Wa = new ac(); + this.vb = new ac(); + this.md = this.xc = this.wc = 0; + this.vc = []; + this.Wb = 0; + this.Ya = new Ub(); + this.yc = new O(); + } + + function je() { + this.xb = this.a = 0; + this.l = new Oa(); + this.ca = new Cb(); + this.V = []; + this.Ba = 0; + this.Ta = []; + this.Ua = 0; + this.m = new Ra(); + this.Pb = 0; + this.wd = new Ra(); + this.Ma = this.$ = this.C = this.i = this.c = this.xd = 0; + this.s = new Ef(); + this.ab = 0; + this.gc = wa(4, Df); + this.Oc = 0; + } + + function Ff() { + this.Lc = this.Z = this.$a = this.i = this.c = 0; + this.l = new Oa(); + this.ic = 0; + this.ca = []; + this.tb = 0; + this.qd = null; + this.rd = 0; + } + + function Rb(a, b, c, d, e, f, g) { + a = null == a ? 0 : a[b + 0]; + + for (b = 0; b < g; ++b) { + e[f + b] = a + c[d + b] & 255, a = e[f + b]; + } + } + + function Gf(a, b, c, d, e, f, g) { + if (null == a) { Rb(null, null, c, d, e, f, g); }else { + var h; + + for (h = 0; h < g; ++h) { + e[f + h] = a[b + h] + c[d + h] & 255; + } + } + } + + function Hf(a, b, c, d, e, f, g) { + if (null == a) { Rb(null, null, c, d, e, f, g); }else { + var h = a[b + 0], + k = h, + l = h, + m; + + for (m = 0; m < g; ++m) { + h = a[b + m], k = l + h - k, l = c[d + m] + (k & -256 ? 0 > k ? 0 : 255 : k) & 255, k = h, e[f + m] = l; + } + } + } + + function Le(a, b, c, d) { + var e = b.width, + f = b.o; + x(null != a && null != b); + if (0 > c || 0 >= d || c + d > f) { return null; } + + if (!a.Cc) { + if (null == a.ga) { + a.ga = new Ff(); + var g; + (g = null == a.ga) || (g = b.width * b.o, x(0 == a.Gb.length), a.Gb = V(g), a.Uc = 0, null == a.Gb ? g = 0 : (a.mb = a.Gb, a.nb = a.Uc, a.rc = null, g = 1), g = !g); + + if (!g) { + g = a.ga; + var h = a.Fa, + k = a.P, + l = a.qc, + m = a.mb, + n = a.nb, + r = k + 1, + q = l - 1, + t = g.l; + x(null != h && null != m && null != b); + ia[0] = null; + ia[1] = Rb; + ia[2] = Gf; + ia[3] = Hf; + g.ca = m; + g.tb = n; + g.c = b.width; + g.i = b.height; + x(0 < g.c && 0 < g.i); + if (1 >= l) { b = 0; }else if (g.$a = h[k + 0] >> 0 & 3, g.Z = h[k + 0] >> 2 & 3, g.Lc = h[k + 0] >> 4 & 3, k = h[k + 0] >> 6 & 3, 0 > g.$a || 1 < g.$a || 4 <= g.Z || 1 < g.Lc || k) { b = 0; }else if (t.put = kc, t.ac = gc, t.bc = lc, t.ma = g, t.width = b.width, t.height = b.height, t.Da = b.Da, t.v = b.v, t.va = b.va, t.j = b.j, t.o = b.o, g.$a) { b: { + x(1 == g.$a), b = Bc(); + + c: for (;;) { + if (null == b) { + b = 0; + break b; + } + + x(null != g); + g.mc = b; + b.c = g.c; + b.i = g.i; + b.l = g.l; + b.l.ma = g; + b.l.width = g.c; + b.l.height = g.i; + b.a = 0; + cb(b.m, h, r, q); + if (!rb(g.c, g.i, 1, b, null)) { break c; } + 1 == b.ab && 3 == b.gc[0].hc && yc(b.s) ? (g.ic = 1, h = b.c * b.i, b.Ta = null, b.Ua = 0, b.V = V(h), b.Ba = 0, null == b.V ? (b.a = 1, b = 0) : b = 1) : (g.ic = 0, b = Ec(b, g.c)); + if (!b) { break c; } + b = 1; + break b; + } + + g.mc = null; + b = 0; + } } else { b = q >= g.c * g.i; } + g = !b; + } + + if (g) { return null; } + 1 != a.ga.Lc ? a.Ga = 0 : d = f - c; + } + + x(null != a.ga); + x(c + d <= f); + + a: { + h = a.ga; + b = h.c; + f = h.l.o; + + if (0 == h.$a) { + r = a.rc; + q = a.Vc; + t = a.Fa; + k = a.P + 1 + c * b; + l = a.mb; + m = a.nb + c * b; + x(k <= a.P + a.qc); + if (0 != h.Z) { for (x(null != ia[h.Z]), g = 0; g < d; ++g) { + ia[h.Z](r, q, t, k, l, m, b), r = l, q = m, m += b, k += b; + } } else { for (g = 0; g < d; ++g) { + I(l, m, t, k, b), r = l, q = m, m += b, k += b; + } } + a.rc = r; + a.Vc = q; + } else { + x(null != h.mc); + b = c + d; + g = h.mc; + x(null != g); + x(b <= g.i); + if (g.C >= b) { b = 1; }else if (h.ic || Aa(), h.ic) { + var h = g.V, + r = g.Ba, + q = g.c, + v = g.i, + t = 1, + k = g.$ / q, + l = g.$ % q, + m = g.m, + n = g.s, + p = g.$, + u = q * v, + w = q * b, + y = n.wc, + A = p < w ? ha(n, l, k) : null; + x(p <= u); + x(b <= v); + x(yc(n)); + + c: for (;;) { + for (; !m.h && p < w;) { + l & y || (A = ha(n, l, k)); + x(null != A); + Sa(m); + v = ua(A.G[0], A.H[0], m); + if (256 > v) { h[r + p] = v, ++p, ++l, l >= q && (l = 0, ++k, k <= b && !(k % 16) && Ib(g, k)); }else if (280 > v) { + var v = ib(v - 256, m); + var E = ua(A.G[4], A.H[4], m); + Sa(m); + E = ib(E, m); + E = nc(q, E); + + if (p >= E && u - p >= v) { + var B; + + for (B = 0; B < v; ++B) { + h[r + p + B] = h[r + p + B - E]; + } + } else { + t = 0; + break c; + } + + p += v; + + for (l += v; l >= q;) { + l -= q, ++k, k <= b && !(k % 16) && Ib(g, k); + } + + p < w && l & y && (A = ha(n, l, k)); + } else { + t = 0; + break c; + } + x(m.h == db(m)); + } + + Ib(g, k > b ? b : k); + break c; + } + + !t || m.h && p < u ? (t = 0, g.a = m.h ? 5 : 3) : g.$ = p; + b = t; + } else { b = Jb(g, g.V, g.Ba, g.c, g.i, b, se); } + + if (!b) { + d = 0; + break a; + } + } + + c + d >= f && (a.Cc = 1); + d = 1; + } + + if (!d) { return null; } + if (a.Cc && (d = a.ga, null != d && (d.mc = null), a.ga = null, 0 < a.Ga)) { return alert("todo:WebPDequantizeLevels"), null; } + } + + return a.nb + c * e; + } + + function If(a, b, c, d, e, f) { + for (; 0 < e--;) { + var g = a, + h = b + (c ? 1 : 0), + k = a, + l = b + (c ? 0 : 3), + m; + + for (m = 0; m < d; ++m) { + var n = k[l + 4 * m]; + 255 != n && (n *= 32897, g[h + 4 * m + 0] = g[h + 4 * m + 0] * n >> 23, g[h + 4 * m + 1] = g[h + 4 * m + 1] * n >> 23, g[h + 4 * m + 2] = g[h + 4 * m + 2] * n >> 23); + } + + b += f; + } + } + + function Jf(a, b, c, d, e) { + for (; 0 < d--;) { + var f; + + for (f = 0; f < c; ++f) { + var g = a[b + 2 * f + 0], + h = a[b + 2 * f + 1], + k = h & 15, + l = 4369 * k, + h = (h & 240 | h >> 4) * l >> 16; + a[b + 2 * f + 0] = (g & 240 | g >> 4) * l >> 16 & 240 | (g & 15 | g << 4) * l >> 16 >> 4 & 15; + a[b + 2 * f + 1] = h & 240 | k; + } + + b += e; + } + } + + function Kf(a, b, c, d, e, f, g, h) { + var k = 255, + l, + m; + + for (m = 0; m < e; ++m) { + for (l = 0; l < d; ++l) { + var n = a[b + l]; + f[g + 4 * l] = n; + k &= n; + } + + b += c; + g += h; + } + + return 255 != k; + } + + function Lf(a, b, c, d, e) { + var f; + + for (f = 0; f < e; ++f) { + c[d + f] = a[b + f] >> 8; + } + } + + function Aa() { + za = If; + vc = Jf; + fc = Kf; + Fc = Lf; + } + + function va(a, b, c) { + self[a] = function (a, e, f, g, h, k, l, m, n, r, q, t, v, p, u, w, y) { + var d, + E = y - 1 >> 1; + var B = h[k + 0] | l[m + 0] << 16; + var C = n[r + 0] | q[t + 0] << 16; + x(null != a); + var z = 3 * B + C + 131074 >> 2; + b(a[e + 0], z & 255, z >> 16, v, p); + null != f && (z = 3 * C + B + 131074 >> 2, b(f[g + 0], z & 255, z >> 16, u, w)); + + for (d = 1; d <= E; ++d) { + var D = h[k + d] | l[m + d] << 16; + var G = n[r + d] | q[t + d] << 16; + var F = B + D + C + G + 524296; + var H = F + 2 * (D + C) >> 3; + F = F + 2 * (B + G) >> 3; + z = H + B >> 1; + B = F + D >> 1; + b(a[e + 2 * d - 1], z & 255, z >> 16, v, p + (2 * d - 1) * c); + b(a[e + 2 * d - 0], B & 255, B >> 16, v, p + (2 * d - 0) * c); + null != f && (z = F + C >> 1, B = H + G >> 1, b(f[g + 2 * d - 1], z & 255, z >> 16, u, w + (2 * d - 1) * c), b(f[g + 2 * d + 0], B & 255, B >> 16, u, w + (2 * d + 0) * c)); + B = D; + C = G; + } + + y & 1 || (z = 3 * B + C + 131074 >> 2, b(a[e + y - 1], z & 255, z >> 16, v, p + (y - 1) * c), null != f && (z = 3 * C + B + 131074 >> 2, b(f[g + y - 1], z & 255, z >> 16, u, w + (y - 1) * c))); + }; + } + + function ic() { + P[Ca] = Mf; + P[Ua] = nd; + P[tc] = Nf; + P[Va] = od; + P[ya] = pd; + P[Db] = qd; + P[wc] = Of; + P[zb] = nd; + P[Ab] = od; + P[Ja] = pd; + P[Bb] = qd; + } + + function Sb(a) { + return a & ~Pf ? 0 > a ? 0 : 255 : a >> rd; + } + + function bb(a, b) { + return Sb((19077 * a >> 8) + (26149 * b >> 8) - 14234); + } + + function nb(a, b, c) { + return Sb((19077 * a >> 8) - (6419 * b >> 8) - (13320 * c >> 8) + 8708); + } + + function Pa(a, b) { + return Sb((19077 * a >> 8) + (33050 * b >> 8) - 17685); + } + + function Ga(a, b, c, d, e) { + d[e + 0] = bb(a, c); + d[e + 1] = nb(a, b, c); + d[e + 2] = Pa(a, b); + } + + function Tb(a, b, c, d, e) { + d[e + 0] = Pa(a, b); + d[e + 1] = nb(a, b, c); + d[e + 2] = bb(a, c); + } + + function sd(a, b, c, d, e) { + var f = nb(a, b, c); + b = f << 3 & 224 | Pa(a, b) >> 3; + d[e + 0] = bb(a, c) & 248 | f >> 5; + d[e + 1] = b; + } + + function td(a, b, c, d, e) { + var f = Pa(a, b) & 240 | 15; + d[e + 0] = bb(a, c) & 240 | nb(a, b, c) >> 4; + d[e + 1] = f; + } + + function ud(a, b, c, d, e) { + d[e + 0] = 255; + Ga(a, b, c, d, e + 1); + } + + function vd(a, b, c, d, e) { + Tb(a, b, c, d, e); + d[e + 3] = 255; + } + + function wd(a, b, c, d, e) { + Ga(a, b, c, d, e); + d[e + 3] = 255; + } + + function la(a, b, c) { + self[a] = function (a, e, f, g, h, k, l, m, n) { + for (var d = m + (n & -2) * c; m != d;) { + b(a[e + 0], f[g + 0], h[k + 0], l, m), b(a[e + 1], f[g + 0], h[k + 0], l, m + c), e += 2, ++g, ++k, m += 2 * c; + } + + n & 1 && b(a[e + 0], f[g + 0], h[k + 0], l, m); + }; + } + + function xd(a, b, c) { + return 0 == c ? 0 == a ? 0 == b ? 6 : 5 : 0 == b ? 4 : 0 : c; + } + + function yd(a, b, c, d, e) { + switch (a >>> 30) { + case 3: + Za(b, c, d, e, 0); + break; + + case 2: + fd(b, c, d, e); + break; + + case 1: + pa(b, c, d, e); + } + } + + function Oc(a, b) { + var c, + d, + e = b.M, + f = b.Nb, + g = a.oc, + h = a.pc + 40, + k = a.oc, + l = a.pc + 584, + m = a.oc, + n = a.pc + 600; + + for (c = 0; 16 > c; ++c) { + g[h + 32 * c - 1] = 129; + } + + for (c = 0; 8 > c; ++c) { + k[l + 32 * c - 1] = 129, m[n + 32 * c - 1] = 129; + } + + 0 < e ? g[h - 1 - 32] = k[l - 1 - 32] = m[n - 1 - 32] = 129 : (M(g, h - 32 - 1, 127, 21), M(k, l - 32 - 1, 127, 9), M(m, n - 32 - 1, 127, 9)); + + for (d = 0; d < a.za; ++d) { + var r = b.ya[b.aa + d]; + + if (0 < d) { + for (c = -1; 16 > c; ++c) { + I(g, h + 32 * c - 4, g, h + 32 * c + 12, 4); + } + + for (c = -1; 8 > c; ++c) { + I(k, l + 32 * c - 4, k, l + 32 * c + 4, 4), I(m, n + 32 * c - 4, m, n + 32 * c + 4, 4); + } + } + + var q = a.Gd, + t = a.Hd + d, + v = r.ad, + p = r.Hc; + 0 < e && (I(g, h - 32, q[t].y, 0, 16), I(k, l - 32, q[t].f, 0, 8), I(m, n - 32, q[t].ea, 0, 8)); + + if (r.Za) { + var u = g; + var w = h - 32 + 16; + 0 < e && (d >= a.za - 1 ? M(u, w, q[t].y[15], 4) : I(u, w, q[t + 1].y, 0, 4)); + + for (c = 0; 4 > c; c++) { + u[w + 128 + c] = u[w + 256 + c] = u[w + 384 + c] = u[w + 0 + c]; + } + + for (c = 0; 16 > c; ++c, p <<= 2) { + u = g, w = h + zd[c], W[r.Ob[c]](u, w), yd(p, v, 16 * +c, u, w); + } + } else if (u = xd(d, e, r.Ob[0]), Y[u](g, h), 0 != p) { for (c = 0; 16 > c; ++c, p <<= 2) { + yd(p, v, 16 * +c, g, h + zd[c]); + } } + + c = r.Gc; + u = xd(d, e, r.Dd); + ka[u](k, l); + ka[u](m, n); + r = c >> 0; + p = v; + u = k; + w = l; + r & 255 && (r & 170 ? Nb(p, 256, u, w) : Ob(p, 256, u, w)); + c >>= 8; + r = m; + p = n; + c & 255 && (c & 170 ? Nb(v, 320, r, p) : Ob(v, 320, r, p)); + e < a.Ub - 1 && (I(q[t].y, 0, g, h + 480, 16), I(q[t].f, 0, k, l + 224, 8), I(q[t].ea, 0, m, n + 224, 8)); + c = 8 * f * a.B; + q = a.sa; + t = a.ta + 16 * d + 16 * f * a.R; + v = a.qa; + r = a.ra + 8 * d + c; + p = a.Ha; + u = a.Ia + 8 * d + c; + + for (c = 0; 16 > c; ++c) { + I(q, t + c * a.R, g, h + 32 * c, 16); + } + + for (c = 0; 8 > c; ++c) { + I(v, r + c * a.B, k, l + 32 * c, 8), I(p, u + c * a.B, m, n + 32 * c, 8); + } + } + } + + function Ad(a, b, c, d, e, f, g, h, k) { + var l = [0], + m = [0], + n = 0, + r = null != k ? k.kd : 0, + q = null != k ? k : new md(); + if (null == a || 12 > c) { return 7; } + q.data = a; + q.w = b; + q.ha = c; + b = [b]; + c = [c]; + q.gb = [q.gb]; + + a: { + var t = b; + var v = c; + var p = q.gb; + x(null != a); + x(null != v); + x(null != p); + p[0] = 0; + + if (12 <= v[0] && !fa(a, t[0], "RIFF")) { + if (fa(a, t[0] + 8, "WEBP")) { + p = 3; + break a; + } + + var u = Ha(a, t[0] + 4); + + if (12 > u || 4294967286 < u) { + p = 3; + break a; + } + + if (r && u > v[0] - 8) { + p = 7; + break a; + } + + p[0] = u; + t[0] += 12; + v[0] -= 12; + } + + p = 0; + } + + if (0 != p) { return p; } + u = 0 < q.gb[0]; + + for (c = c[0];;) { + t = [0]; + n = [n]; + + a: { + var w = a; + v = b; + p = c; + var y = n, + A = l, + z = m, + B = t; + y[0] = 0; + if (8 > p[0]) { p = 7; }else { + if (!fa(w, v[0], "VP8X")) { + if (10 != Ha(w, v[0] + 4)) { + p = 3; + break a; + } + + if (18 > p[0]) { + p = 7; + break a; + } + + var C = Ha(w, v[0] + 8); + var D = 1 + Yb(w, v[0] + 12); + w = 1 + Yb(w, v[0] + 15); + + if (2147483648 <= D * w) { + p = 3; + break a; + } + + null != B && (B[0] = C); + null != A && (A[0] = D); + null != z && (z[0] = w); + v[0] += 18; + p[0] -= 18; + y[0] = 1; + } + + p = 0; + } + } + + n = n[0]; + t = t[0]; + if (0 != p) { return p; } + v = !!(t & 2); + if (!u && n) { return 3; } + null != f && (f[0] = !!(t & 16)); + null != g && (g[0] = v); + null != h && (h[0] = 0); + g = l[0]; + t = m[0]; + + if (n && v && null == k) { + p = 0; + break; + } + + if (4 > c) { + p = 7; + break; + } + + if (u && n || !u && !n && !fa(a, b[0], "ALPH")) { + c = [c]; + q.na = [q.na]; + q.P = [q.P]; + q.Sa = [q.Sa]; + + a: { + C = a; + p = b; + u = c; + var y = q.gb, + A = q.na, + z = q.P, + B = q.Sa; + D = 22; + x(null != C); + x(null != u); + w = p[0]; + var F = u[0]; + x(null != A); + x(null != B); + A[0] = null; + z[0] = null; + + for (B[0] = 0;;) { + p[0] = w; + u[0] = F; + + if (8 > F) { + p = 7; + break a; + } + + var G = Ha(C, w + 4); + + if (4294967286 < G) { + p = 3; + break a; + } + + var H = 8 + G + 1 & -2; + D += H; + + if (0 < y && D > y) { + p = 3; + break a; + } + + if (!fa(C, w, "VP8 ") || !fa(C, w, "VP8L")) { + p = 0; + break a; + } + + if (F[0] < H) { + p = 7; + break a; + } + + fa(C, w, "ALPH") || (A[0] = C, z[0] = w + 8, B[0] = G); + w += H; + F -= H; + } + } + + c = c[0]; + q.na = q.na[0]; + q.P = q.P[0]; + q.Sa = q.Sa[0]; + if (0 != p) { break; } + } + + c = [c]; + q.Ja = [q.Ja]; + q.xa = [q.xa]; + + a: if (y = a, p = b, u = c, A = q.gb[0], z = q.Ja, B = q.xa, C = p[0], w = !fa(y, C, "VP8 "), D = !fa(y, C, "VP8L"), x(null != y), x(null != u), x(null != z), x(null != B), 8 > u[0]) { p = 7; }else { + if (w || D) { + y = Ha(y, C + 4); + + if (12 <= A && y > A - 12) { + p = 3; + break a; + } + + if (r && y > u[0] - 8) { + p = 7; + break a; + } + + z[0] = y; + p[0] += 8; + u[0] -= 8; + B[0] = D; + } else { B[0] = 5 <= u[0] && 47 == y[C + 0] && !(y[C + 4] >> 5), z[0] = u[0]; } + + p = 0; + } + + c = c[0]; + q.Ja = q.Ja[0]; + q.xa = q.xa[0]; + b = b[0]; + if (0 != p) { break; } + if (4294967286 < q.Ja) { return 3; } + null == h || v || (h[0] = q.xa ? 2 : 1); + g = [g]; + t = [t]; + + if (q.xa) { + if (5 > c) { + p = 7; + break; + } + + h = g; + r = t; + v = f; + null == a || 5 > c ? a = 0 : 5 <= c && 47 == a[b + 0] && !(a[b + 4] >> 5) ? (u = [0], y = [0], A = [0], z = new Ra(), cb(z, a, b, c), mc(z, u, y, A) ? (null != h && (h[0] = u[0]), null != r && (r[0] = y[0]), null != v && (v[0] = A[0]), a = 1) : a = 0) : a = 0; + } else { + if (10 > c) { + p = 7; + break; + } + + h = t; + null == a || 10 > c || !Jc(a, b + 3, c - 3) ? a = 0 : (r = a[b + 0] | a[b + 1] << 8 | a[b + 2] << 16, v = (a[b + 7] << 8 | a[b + 6]) & 16383, a = (a[b + 9] << 8 | a[b + 8]) & 16383, r & 1 || 3 < (r >> 1 & 7) || !(r >> 4 & 1) || r >> 5 >= q.Ja || !v || !a ? a = 0 : (g && (g[0] = v), h && (h[0] = a), a = 1)); + } + + if (!a) { return 3; } + g = g[0]; + t = t[0]; + if (n && (l[0] != g || m[0] != t)) { return 3; } + null != k && (k[0] = q, k.offset = b - k.w, x(4294967286 > b - k.w), x(k.offset == k.ha - c)); + break; + } + + return 0 == p || 7 == p && n && null == k ? (null != f && (f[0] |= null != q.na && 0 < q.na.length), null != d && (d[0] = g), null != e && (e[0] = t), 0) : p; + } + + function hc(a, b, c) { + var d = b.width, + e = b.height, + f = 0, + g = 0, + h = d, + k = e; + b.Da = null != a && 0 < a.Da; + if (b.Da && (h = a.cd, k = a.bd, f = a.v, g = a.j, 11 > c || (f &= -2, g &= -2), 0 > f || 0 > g || 0 >= h || 0 >= k || f + h > d || g + k > e)) { return 0; } + b.v = f; + b.j = g; + b.va = f + h; + b.o = g + k; + b.U = h; + b.T = k; + b.da = null != a && 0 < a.da; + + if (b.da) { + c = [a.ib]; + f = [a.hb]; + if (!bc(h, k, c, f)) { return 0; } + b.ib = c[0]; + b.hb = f[0]; + } + + b.ob = null != a && a.ob; + b.Kb = null == a || !a.Sd; + b.da && (b.ob = b.ib < 3 * d / 4 && b.hb < 3 * e / 4, b.Kb = 0); + return 1; + } + + function Bd(a) { + if (null == a) { return 2; } + + if (11 > a.S) { + var b = a.f.RGBA; + b.fb += (a.height - 1) * b.A; + b.A = -b.A; + } else { b = a.f.kb, a = a.height, b.O += (a - 1) * b.fa, b.fa = -b.fa, b.N += (a - 1 >> 1) * b.Ab, b.Ab = -b.Ab, b.W += (a - 1 >> 1) * b.Db, b.Db = -b.Db, null != b.F && (b.J += (a - 1) * b.lb, b.lb = -b.lb); } + + return 0; + } + + function Cd(a, b, c, d) { + if (null == d || 0 >= a || 0 >= b) { return 2; } + + if (null != c) { + if (c.Da) { + var e = c.cd, + f = c.bd, + g = c.v & -2, + h = c.j & -2; + if (0 > g || 0 > h || 0 >= e || 0 >= f || g + e > a || h + f > b) { return 2; } + a = e; + b = f; + } + + if (c.da) { + e = [c.ib]; + f = [c.hb]; + if (!bc(a, b, e, f)) { return 2; } + a = e[0]; + b = f[0]; + } + } + + d.width = a; + d.height = b; + + a: { + var k = d.width; + var l = d.height; + a = d.S; + if (0 >= k || 0 >= l || !(a >= Ca && 13 > a)) { a = 2; }else { + if (0 >= d.Rd && null == d.sd) { + var g = f = e = b = 0, + h = k * Dd[a], + m = h * l; + 11 > a || (b = (k + 1) / 2, f = (l + 1) / 2 * b, 12 == a && (e = k, g = e * l)); + l = V(m + 2 * f + g); + + if (null == l) { + a = 1; + break a; + } + + d.sd = l; + 11 > a ? (k = d.f.RGBA, k.eb = l, k.fb = 0, k.A = h, k.size = m) : (k = d.f.kb, k.y = l, k.O = 0, k.fa = h, k.Fd = m, k.f = l, k.N = 0 + m, k.Ab = b, k.Cd = f, k.ea = l, k.W = 0 + m + f, k.Db = b, k.Ed = f, 12 == a && (k.F = l, k.J = 0 + m + 2 * f), k.Tc = g, k.lb = e); + } + + b = 1; + e = d.S; + f = d.width; + g = d.height; + if (e >= Ca && 13 > e) { + if (11 > e) { a = d.f.RGBA, h = Math.abs(a.A), b &= h * (g - 1) + f <= a.size, b &= h >= f * Dd[e], b &= null != a.eb; }else { + a = d.f.kb; + h = (f + 1) / 2; + m = (g + 1) / 2; + k = Math.abs(a.fa); + var l = Math.abs(a.Ab), + n = Math.abs(a.Db), + r = Math.abs(a.lb), + q = r * (g - 1) + f; + b &= k * (g - 1) + f <= a.Fd; + b &= l * (m - 1) + h <= a.Cd; + b &= n * (m - 1) + h <= a.Ed; + b = b & k >= f & l >= h & n >= h; + b &= null != a.y; + b &= null != a.f; + b &= null != a.ea; + 12 == e && (b &= r >= f, b &= q <= a.Tc, b &= null != a.F); + } + } else { b = 0; } + a = b ? 0 : 2; + } + } + + if (0 != a) { return a; } + null != c && c.fd && (a = Bd(d)); + return a; + } + + var xb = 64, + Hd = [0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215], + Gd = 24, + ob = 32, + Xb = 8, + Id = [0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]; + X("Predictor0", "PredictorAdd0"); + + self.Predictor0 = function () { + return 4278190080; + }; + + self.Predictor1 = function (a) { + return a; + }; + + self.Predictor2 = function (a, b, c) { + return b[c + 0]; + }; + + self.Predictor3 = function (a, b, c) { + return b[c + 1]; + }; + + self.Predictor4 = function (a, b, c) { + return b[c - 1]; + }; + + self.Predictor5 = function (a, b, c) { + return aa(aa(a, b[c + 1]), b[c + 0]); + }; + + self.Predictor6 = function (a, b, c) { + return aa(a, b[c - 1]); + }; + + self.Predictor7 = function (a, b, c) { + return aa(a, b[c + 0]); + }; + + self.Predictor8 = function (a, b, c) { + return aa(b[c - 1], b[c + 0]); + }; + + self.Predictor9 = function (a, b, c) { + return aa(b[c + 0], b[c + 1]); + }; + + self.Predictor10 = function (a, b, c) { + return aa(aa(a, b[c - 1]), aa(b[c + 0], b[c + 1])); + }; + + self.Predictor11 = function (a, b, c) { + var d = b[c + 0]; + b = b[c - 1]; + return 0 >= Ia(d >> 24 & 255, a >> 24 & 255, b >> 24 & 255) + Ia(d >> 16 & 255, a >> 16 & 255, b >> 16 & 255) + Ia(d >> 8 & 255, a >> 8 & 255, b >> 8 & 255) + Ia(d & 255, a & 255, b & 255) ? d : a; + }; + + self.Predictor12 = function (a, b, c) { + var d = b[c + 0]; + b = b[c - 1]; + return (sa((a >> 24 & 255) + (d >> 24 & 255) - (b >> 24 & 255)) << 24 | sa((a >> 16 & 255) + (d >> 16 & 255) - (b >> 16 & 255)) << 16 | sa((a >> 8 & 255) + (d >> 8 & 255) - (b >> 8 & 255)) << 8 | sa((a & 255) + (d & 255) - (b & 255))) >>> 0; + }; + + self.Predictor13 = function (a, b, c) { + var d = b[c - 1]; + a = aa(a, b[c + 0]); + return (eb(a >> 24 & 255, d >> 24 & 255) << 24 | eb(a >> 16 & 255, d >> 16 & 255) << 16 | eb(a >> 8 & 255, d >> 8 & 255) << 8 | eb(a >> 0 & 255, d >> 0 & 255)) >>> 0; + }; + + var ee = self.PredictorAdd0; + self.PredictorAdd1 = cc; + X("Predictor2", "PredictorAdd2"); + X("Predictor3", "PredictorAdd3"); + X("Predictor4", "PredictorAdd4"); + X("Predictor5", "PredictorAdd5"); + X("Predictor6", "PredictorAdd6"); + X("Predictor7", "PredictorAdd7"); + X("Predictor8", "PredictorAdd8"); + X("Predictor9", "PredictorAdd9"); + X("Predictor10", "PredictorAdd10"); + X("Predictor11", "PredictorAdd11"); + X("Predictor12", "PredictorAdd12"); + X("Predictor13", "PredictorAdd13"); + var fe = self.PredictorAdd2; + ec("ColorIndexInverseTransform", "MapARGB", "32b", function (a) { + return a >> 8 & 255; + }, function (a) { + return a; + }); + ec("VP8LColorIndexInverseTransformAlpha", "MapAlpha", "8b", function (a) { + return a; + }, function (a) { + return a >> 8 & 255; + }); + var rc = self.ColorIndexInverseTransform, + ke = self.MapARGB, + he = self.VP8LColorIndexInverseTransformAlpha, + le = self.MapAlpha, + pc, + qc = self.VP8LPredictorsAdd = []; + qc.length = 16; + (self.VP8LPredictors = []).length = 16; + (self.VP8LPredictorsAdd_C = []).length = 16; + (self.VP8LPredictors_C = []).length = 16; + var Fb, + sc, + Gb, + Hb, + xc, + uc, + bd = V(511), + cd = V(2041), + dd = V(225), + ed = V(767), + ad = 0, + Qb = cd, + mb = dd, + R = ed, + U = bd, + Ca = 0, + Ua = 1, + tc = 2, + Va = 3, + ya = 4, + Db = 5, + wc = 6, + zb = 7, + Ab = 8, + Ja = 9, + Bb = 10, + pe = [2, 3, 7], + oe = [3, 3, 11], + Dc = [280, 256, 256, 256, 40], + qe = [0, 1, 1, 1, 0], + ne = [17, 18, 0, 1, 2, 3, 4, 5, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + de = [24, 7, 23, 25, 40, 6, 39, 41, 22, 26, 38, 42, 56, 5, 55, 57, 21, 27, 54, 58, 37, 43, 72, 4, 71, 73, 20, 28, 53, 59, 70, 74, 36, 44, 88, 69, 75, 52, 60, 3, 87, 89, 19, 29, 86, 90, 35, 45, 68, 76, 85, 91, 51, 61, 104, 2, 103, 105, 18, 30, 102, 106, 34, 46, 84, 92, 67, 77, 101, 107, 50, 62, 120, 1, 119, 121, 83, 93, 17, 31, 100, 108, 66, 78, 118, 122, 33, 47, 117, 123, 49, 63, 99, 109, 82, 94, 0, 116, 124, 65, 79, 16, 32, 98, 110, 48, 115, 125, 81, 95, 64, 114, 126, 97, 111, 80, 113, 127, 96, 112], + me = [2954, 2956, 2958, 2962, 2970, 2986, 3018, 3082, 3212, 3468, 3980, 5004], + ie = 8, + Lb = [4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, 17, 18, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 91, 93, 95, 96, 98, 100, 101, 102, 104, 106, 108, 110, 112, 114, 116, 118, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 143, 145, 148, 151, 154, 157], + Mb = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, 146, 149, 152, 155, 158, 161, 164, 167, 170, 173, 177, 181, 185, 189, 193, 197, 201, 205, 209, 213, 217, 221, 225, 229, 234, 239, 245, 249, 254, 259, 264, 269, 274, 279, 284], + oa = null, + He = [[173, 148, 140, 0], [176, 155, 140, 135, 0], [180, 157, 141, 134, 130, 0], [254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129, 0]], + Ie = [0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15], + Mc = [-0, 1, -1, 2, -2, 3, 4, 6, -3, 5, -4, -5, -6, 7, -7, 8, -8, -9], + Fe = [[[[128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128], [128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128], [128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128]], [[253, 136, 254, 255, 228, 219, 128, 128, 128, 128, 128], [189, 129, 242, 255, 227, 213, 255, 219, 128, 128, 128], [106, 126, 227, 252, 214, 209, 255, 255, 128, 128, 128]], [[1, 98, 248, 255, 236, 226, 255, 255, 128, 128, 128], [181, 133, 238, 254, 221, 234, 255, 154, 128, 128, 128], [78, 134, 202, 247, 198, 180, 255, 219, 128, 128, 128]], [[1, 185, 249, 255, 243, 255, 128, 128, 128, 128, 128], [184, 150, 247, 255, 236, 224, 128, 128, 128, 128, 128], [77, 110, 216, 255, 236, 230, 128, 128, 128, 128, 128]], [[1, 101, 251, 255, 241, 255, 128, 128, 128, 128, 128], [170, 139, 241, 252, 236, 209, 255, 255, 128, 128, 128], [37, 116, 196, 243, 228, 255, 255, 255, 128, 128, 128]], [[1, 204, 254, 255, 245, 255, 128, 128, 128, 128, 128], [207, 160, 250, 255, 238, 128, 128, 128, 128, 128, 128], [102, 103, 231, 255, 211, 171, 128, 128, 128, 128, 128]], [[1, 152, 252, 255, 240, 255, 128, 128, 128, 128, 128], [177, 135, 243, 255, 234, 225, 128, 128, 128, 128, 128], [80, 129, 211, 255, 194, 224, 128, 128, 128, 128, 128]], [[1, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128], [246, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128], [255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128]]], [[[198, 35, 237, 223, 193, 187, 162, 160, 145, 155, 62], [131, 45, 198, 221, 172, 176, 220, 157, 252, 221, 1], [68, 47, 146, 208, 149, 167, 221, 162, 255, 223, 128]], [[1, 149, 241, 255, 221, 224, 255, 255, 128, 128, 128], [184, 141, 234, 253, 222, 220, 255, 199, 128, 128, 128], [81, 99, 181, 242, 176, 190, 249, 202, 255, 255, 128]], [[1, 129, 232, 253, 214, 197, 242, 196, 255, 255, 128], [99, 121, 210, 250, 201, 198, 255, 202, 128, 128, 128], [23, 91, 163, 242, 170, 187, 247, 210, 255, 255, 128]], [[1, 200, 246, 255, 234, 255, 128, 128, 128, 128, 128], [109, 178, 241, 255, 231, 245, 255, 255, 128, 128, 128], [44, 130, 201, 253, 205, 192, 255, 255, 128, 128, 128]], [[1, 132, 239, 251, 219, 209, 255, 165, 128, 128, 128], [94, 136, 225, 251, 218, 190, 255, 255, 128, 128, 128], [22, 100, 174, 245, 186, 161, 255, 199, 128, 128, 128]], [[1, 182, 249, 255, 232, 235, 128, 128, 128, 128, 128], [124, 143, 241, 255, 227, 234, 128, 128, 128, 128, 128], [35, 77, 181, 251, 193, 211, 255, 205, 128, 128, 128]], [[1, 157, 247, 255, 236, 231, 255, 255, 128, 128, 128], [121, 141, 235, 255, 225, 227, 255, 255, 128, 128, 128], [45, 99, 188, 251, 195, 217, 255, 224, 128, 128, 128]], [[1, 1, 251, 255, 213, 255, 128, 128, 128, 128, 128], [203, 1, 248, 255, 255, 128, 128, 128, 128, 128, 128], [137, 1, 177, 255, 224, 255, 128, 128, 128, 128, 128]]], [[[253, 9, 248, 251, 207, 208, 255, 192, 128, 128, 128], [175, 13, 224, 243, 193, 185, 249, 198, 255, 255, 128], [73, 17, 171, 221, 161, 179, 236, 167, 255, 234, 128]], [[1, 95, 247, 253, 212, 183, 255, 255, 128, 128, 128], [239, 90, 244, 250, 211, 209, 255, 255, 128, 128, 128], [155, 77, 195, 248, 188, 195, 255, 255, 128, 128, 128]], [[1, 24, 239, 251, 218, 219, 255, 205, 128, 128, 128], [201, 51, 219, 255, 196, 186, 128, 128, 128, 128, 128], [69, 46, 190, 239, 201, 218, 255, 228, 128, 128, 128]], [[1, 191, 251, 255, 255, 128, 128, 128, 128, 128, 128], [223, 165, 249, 255, 213, 255, 128, 128, 128, 128, 128], [141, 124, 248, 255, 255, 128, 128, 128, 128, 128, 128]], [[1, 16, 248, 255, 255, 128, 128, 128, 128, 128, 128], [190, 36, 230, 255, 236, 255, 128, 128, 128, 128, 128], [149, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128]], [[1, 226, 255, 128, 128, 128, 128, 128, 128, 128, 128], [247, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128], [240, 128, 255, 128, 128, 128, 128, 128, 128, 128, 128]], [[1, 134, 252, 255, 255, 128, 128, 128, 128, 128, 128], [213, 62, 250, 255, 255, 128, 128, 128, 128, 128, 128], [55, 93, 255, 128, 128, 128, 128, 128, 128, 128, 128]], [[128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128], [128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128], [128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128]]], [[[202, 24, 213, 235, 186, 191, 220, 160, 240, 175, 255], [126, 38, 182, 232, 169, 184, 228, 174, 255, 187, 128], [61, 46, 138, 219, 151, 178, 240, 170, 255, 216, 128]], [[1, 112, 230, 250, 199, 191, 247, 159, 255, 255, 128], [166, 109, 228, 252, 211, 215, 255, 174, 128, 128, 128], [39, 77, 162, 232, 172, 180, 245, 178, 255, 255, 128]], [[1, 52, 220, 246, 198, 199, 249, 220, 255, 255, 128], [124, 74, 191, 243, 183, 193, 250, 221, 255, 255, 128], [24, 71, 130, 219, 154, 170, 243, 182, 255, 255, 128]], [[1, 182, 225, 249, 219, 240, 255, 224, 128, 128, 128], [149, 150, 226, 252, 216, 205, 255, 171, 128, 128, 128], [28, 108, 170, 242, 183, 194, 254, 223, 255, 255, 128]], [[1, 81, 230, 252, 204, 203, 255, 192, 128, 128, 128], [123, 102, 209, 247, 188, 196, 255, 233, 128, 128, 128], [20, 95, 153, 243, 164, 173, 255, 203, 128, 128, 128]], [[1, 222, 248, 255, 216, 213, 128, 128, 128, 128, 128], [168, 175, 246, 252, 235, 205, 255, 255, 128, 128, 128], [47, 116, 215, 255, 211, 212, 255, 255, 128, 128, 128]], [[1, 121, 236, 253, 212, 214, 255, 255, 128, 128, 128], [141, 84, 213, 252, 201, 202, 255, 219, 128, 128, 128], [42, 80, 160, 240, 162, 185, 255, 205, 128, 128, 128]], [[1, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128], [244, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128], [238, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128]]]], + Ke = [[[231, 120, 48, 89, 115, 113, 120, 152, 112], [152, 179, 64, 126, 170, 118, 46, 70, 95], [175, 69, 143, 80, 85, 82, 72, 155, 103], [56, 58, 10, 171, 218, 189, 17, 13, 152], [114, 26, 17, 163, 44, 195, 21, 10, 173], [121, 24, 80, 195, 26, 62, 44, 64, 85], [144, 71, 10, 38, 171, 213, 144, 34, 26], [170, 46, 55, 19, 136, 160, 33, 206, 71], [63, 20, 8, 114, 114, 208, 12, 9, 226], [81, 40, 11, 96, 182, 84, 29, 16, 36]], [[134, 183, 89, 137, 98, 101, 106, 165, 148], [72, 187, 100, 130, 157, 111, 32, 75, 80], [66, 102, 167, 99, 74, 62, 40, 234, 128], [41, 53, 9, 178, 241, 141, 26, 8, 107], [74, 43, 26, 146, 73, 166, 49, 23, 157], [65, 38, 105, 160, 51, 52, 31, 115, 128], [104, 79, 12, 27, 217, 255, 87, 17, 7], [87, 68, 71, 44, 114, 51, 15, 186, 23], [47, 41, 14, 110, 182, 183, 21, 17, 194], [66, 45, 25, 102, 197, 189, 23, 18, 22]], [[88, 88, 147, 150, 42, 46, 45, 196, 205], [43, 97, 183, 117, 85, 38, 35, 179, 61], [39, 53, 200, 87, 26, 21, 43, 232, 171], [56, 34, 51, 104, 114, 102, 29, 93, 77], [39, 28, 85, 171, 58, 165, 90, 98, 64], [34, 22, 116, 206, 23, 34, 43, 166, 73], [107, 54, 32, 26, 51, 1, 81, 43, 31], [68, 25, 106, 22, 64, 171, 36, 225, 114], [34, 19, 21, 102, 132, 188, 16, 76, 124], [62, 18, 78, 95, 85, 57, 50, 48, 51]], [[193, 101, 35, 159, 215, 111, 89, 46, 111], [60, 148, 31, 172, 219, 228, 21, 18, 111], [112, 113, 77, 85, 179, 255, 38, 120, 114], [40, 42, 1, 196, 245, 209, 10, 25, 109], [88, 43, 29, 140, 166, 213, 37, 43, 154], [61, 63, 30, 155, 67, 45, 68, 1, 209], [100, 80, 8, 43, 154, 1, 51, 26, 71], [142, 78, 78, 16, 255, 128, 34, 197, 171], [41, 40, 5, 102, 211, 183, 4, 1, 221], [51, 50, 17, 168, 209, 192, 23, 25, 82]], [[138, 31, 36, 171, 27, 166, 38, 44, 229], [67, 87, 58, 169, 82, 115, 26, 59, 179], [63, 59, 90, 180, 59, 166, 93, 73, 154], [40, 40, 21, 116, 143, 209, 34, 39, 175], [47, 15, 16, 183, 34, 223, 49, 45, 183], [46, 17, 33, 183, 6, 98, 15, 32, 183], [57, 46, 22, 24, 128, 1, 54, 17, 37], [65, 32, 73, 115, 28, 128, 23, 128, 205], [40, 3, 9, 115, 51, 192, 18, 6, 223], [87, 37, 9, 115, 59, 77, 64, 21, 47]], [[104, 55, 44, 218, 9, 54, 53, 130, 226], [64, 90, 70, 205, 40, 41, 23, 26, 57], [54, 57, 112, 184, 5, 41, 38, 166, 213], [30, 34, 26, 133, 152, 116, 10, 32, 134], [39, 19, 53, 221, 26, 114, 32, 73, 255], [31, 9, 65, 234, 2, 15, 1, 118, 73], [75, 32, 12, 51, 192, 255, 160, 43, 51], [88, 31, 35, 67, 102, 85, 55, 186, 85], [56, 21, 23, 111, 59, 205, 45, 37, 192], [55, 38, 70, 124, 73, 102, 1, 34, 98]], [[125, 98, 42, 88, 104, 85, 117, 175, 82], [95, 84, 53, 89, 128, 100, 113, 101, 45], [75, 79, 123, 47, 51, 128, 81, 171, 1], [57, 17, 5, 71, 102, 57, 53, 41, 49], [38, 33, 13, 121, 57, 73, 26, 1, 85], [41, 10, 67, 138, 77, 110, 90, 47, 114], [115, 21, 2, 10, 102, 255, 166, 23, 6], [101, 29, 16, 10, 85, 128, 101, 196, 26], [57, 18, 10, 102, 102, 213, 34, 20, 43], [117, 20, 15, 36, 163, 128, 68, 1, 26]], [[102, 61, 71, 37, 34, 53, 31, 243, 192], [69, 60, 71, 38, 73, 119, 28, 222, 37], [68, 45, 128, 34, 1, 47, 11, 245, 171], [62, 17, 19, 70, 146, 85, 55, 62, 70], [37, 43, 37, 154, 100, 163, 85, 160, 1], [63, 9, 92, 136, 28, 64, 32, 201, 85], [75, 15, 9, 9, 64, 255, 184, 119, 16], [86, 6, 28, 5, 64, 255, 25, 248, 1], [56, 8, 17, 132, 137, 255, 55, 116, 128], [58, 15, 20, 82, 135, 57, 26, 121, 40]], [[164, 50, 31, 137, 154, 133, 25, 35, 218], [51, 103, 44, 131, 131, 123, 31, 6, 158], [86, 40, 64, 135, 148, 224, 45, 183, 128], [22, 26, 17, 131, 240, 154, 14, 1, 209], [45, 16, 21, 91, 64, 222, 7, 1, 197], [56, 21, 39, 155, 60, 138, 23, 102, 213], [83, 12, 13, 54, 192, 255, 68, 47, 28], [85, 26, 85, 85, 128, 128, 32, 146, 171], [18, 11, 7, 63, 144, 171, 4, 4, 246], [35, 27, 10, 146, 174, 171, 12, 26, 128]], [[190, 80, 35, 99, 180, 80, 126, 54, 45], [85, 126, 47, 87, 176, 51, 41, 20, 32], [101, 75, 128, 139, 118, 146, 116, 128, 85], [56, 41, 15, 176, 236, 85, 37, 9, 62], [71, 30, 17, 119, 118, 255, 17, 18, 138], [101, 38, 60, 138, 55, 70, 43, 26, 142], [146, 36, 19, 30, 171, 255, 97, 27, 20], [138, 45, 61, 62, 219, 1, 81, 188, 64], [32, 41, 20, 117, 151, 142, 20, 21, 163], [112, 19, 12, 61, 195, 128, 48, 4, 24]]], + Ee = [[[[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[176, 246, 255, 255, 255, 255, 255, 255, 255, 255, 255], [223, 241, 252, 255, 255, 255, 255, 255, 255, 255, 255], [249, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 244, 252, 255, 255, 255, 255, 255, 255, 255, 255], [234, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255], [253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 246, 254, 255, 255, 255, 255, 255, 255, 255, 255], [239, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255], [254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255], [251, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255], [251, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255], [254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 254, 253, 255, 254, 255, 255, 255, 255, 255, 255], [250, 255, 254, 255, 254, 255, 255, 255, 255, 255, 255], [254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]]], [[[217, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [225, 252, 241, 253, 255, 255, 254, 255, 255, 255, 255], [234, 250, 241, 250, 253, 255, 253, 254, 255, 255, 255]], [[255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255], [223, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255], [238, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255]], [[255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255], [249, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255], [247, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255], [252, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255], [253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255], [250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]]], [[[186, 251, 250, 255, 255, 255, 255, 255, 255, 255, 255], [234, 251, 244, 254, 255, 255, 255, 255, 255, 255, 255], [251, 251, 243, 253, 254, 255, 254, 255, 255, 255, 255]], [[255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255], [236, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255], [251, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255]], [[255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255], [254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255], [254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255], [254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]]], [[[248, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [250, 254, 252, 254, 255, 255, 255, 255, 255, 255, 255], [248, 254, 249, 253, 255, 255, 255, 255, 255, 255, 255]], [[255, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255], [246, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255], [252, 254, 251, 254, 254, 255, 255, 255, 255, 255, 255]], [[255, 254, 252, 255, 255, 255, 255, 255, 255, 255, 255], [248, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255], [253, 255, 254, 254, 255, 255, 255, 255, 255, 255, 255]], [[255, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255], [245, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255], [253, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 251, 253, 255, 255, 255, 255, 255, 255, 255, 255], [252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255], [255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 252, 255, 255, 255, 255, 255, 255, 255, 255, 255], [249, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 255, 253, 255, 255, 255, 255, 255, 255, 255, 255], [250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], [[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]]]], + Ge = [0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 0], + Nc, + Y = [], + W = [], + ka = [], + Za, + fd, + Nb, + pa, + Ob, + Xc, + Tc, + Yc, + Uc, + Zc, + Vc, + $c, + Wc, + Rc, + Pc, + Sc, + Qc, + re = 1, + Cc = 2, + ia = [], + za, + vc, + fc, + Fc, + P = []; + va("UpsampleRgbLinePair", Ga, 3); + va("UpsampleBgrLinePair", Tb, 3); + va("UpsampleRgbaLinePair", wd, 4); + va("UpsampleBgraLinePair", vd, 4); + va("UpsampleArgbLinePair", ud, 4); + va("UpsampleRgba4444LinePair", td, 2); + va("UpsampleRgb565LinePair", sd, 2); + var Mf = UpsampleRgbLinePair, + Nf = UpsampleBgrLinePair, + nd = UpsampleRgbaLinePair, + od = UpsampleBgraLinePair, + pd = UpsampleArgbLinePair, + qd = UpsampleRgba4444LinePair, + Of = UpsampleRgb565LinePair, + Wa = 16, + Ba = 1 << Wa - 1, + ta = -227, + Eb = 482, + rd = 6, + Pf = (256 << rd) - 1, + jc = 0, + Yd = V(256), + ae = V(256), + $d = V(256), + Zd = V(256), + be = V(Eb - ta), + ce = V(Eb - ta); + la("YuvToRgbRow", Ga, 3); + la("YuvToBgrRow", Tb, 3); + la("YuvToRgbaRow", wd, 4); + la("YuvToBgraRow", vd, 4); + la("YuvToArgbRow", ud, 4); + la("YuvToRgba4444Row", td, 2); + la("YuvToRgb565Row", sd, 2); + var zd = [0, 4, 8, 12, 128, 132, 136, 140, 256, 260, 264, 268, 384, 388, 392, 396], + Ya = [0, 2, 8], + Qf = [8, 7, 6, 4, 4, 2, 2, 2, 1, 1, 1, 1], + Ne = 1; + + this.WebPDecodeRGBA = function (a, b, c, d, e) { + var f = Ua; + var g = new Cf(), + h = new Cb(); + g.ba = h; + h.S = f; + h.width = [h.width]; + h.height = [h.height]; + var k = h.width; + var l = h.height, + m = new Td(); + if (null == m || null == a) { var n = 2; }else { x(null != m), n = Ad(a, b, c, m.width, m.height, m.Pd, m.Qd, m.format, null); } + 0 != n ? k = 0 : (null != k && (k[0] = m.width[0]), null != l && (l[0] = m.height[0]), k = 1); + + if (k) { + h.width = h.width[0]; + h.height = h.height[0]; + null != d && (d[0] = h.width); + null != e && (e[0] = h.height); + + b: { + d = new Oa(); + e = new md(); + e.data = a; + e.w = b; + e.ha = c; + e.kd = 1; + b = [0]; + x(null != e); + a = Ad(e.data, e.w, e.ha, null, null, null, b, null, e); + (0 == a || 7 == a) && b[0] && (a = 4); + b = a; + + if (0 == b) { + x(null != g); + d.data = e.data; + d.w = e.w + e.offset; + d.ha = e.ha - e.offset; + d.put = kc; + d.ac = gc; + d.bc = lc; + d.ma = g; + + if (e.xa) { + a = Bc(); + + if (null == a) { + g = 1; + break b; + } + + if (te(a, d)) { + b = Cd(d.width, d.height, g.Oa, g.ba); + + if (d = 0 == b) { + c: { + d = a; + + d: for (;;) { + if (null == d) { + d = 0; + break c; + } + + x(null != d.s.yc); + x(null != d.s.Ya); + x(0 < d.s.Wb); + c = d.l; + x(null != c); + e = c.ma; + x(null != e); + + if (0 != d.xb) { + d.ca = e.ba; + d.tb = e.tb; + x(null != d.ca); + + if (!hc(e.Oa, c, Va)) { + d.a = 2; + break d; + } + + if (!Ec(d, c.width)) { break d; } + if (c.da) { break d; } + (c.da || hb(d.ca.S)) && Aa(); + 11 > d.ca.S || (alert("todo:WebPInitConvertARGBToYUV"), null != d.ca.f.kb.F && Aa()); + + if (d.Pb && 0 < d.s.ua && null == d.s.vb.X && !Zb(d.s.vb, d.s.Wa.Xa)) { + d.a = 1; + break d; + } + + d.xb = 0; + } + + if (!Jb(d, d.V, d.Ba, d.c, d.i, c.o, ge)) { break d; } + e.Dc = d.Ma; + d = 1; + break c; + } + + x(0 != d.a); + d = 0; + } + + d = !d; + } + + d && (b = a.a); + } else { b = a.a; } + } else { + a = new Ce(); + + if (null == a) { + g = 1; + break b; + } + + a.Fa = e.na; + a.P = e.P; + a.qc = e.Sa; + + if (Kc(a, d)) { + if (b = Cd(d.width, d.height, g.Oa, g.ba), 0 == b) { + a.Aa = 0; + c = g.Oa; + e = a; + x(null != e); + + if (null != c) { + k = c.Md; + k = 0 > k ? 0 : 100 < k ? 255 : 255 * k / 100; + + if (0 < k) { + for (l = m = 0; 4 > l; ++l) { + n = e.pb[l], 12 > n.lc && (n.ia = k * Qf[0 > n.lc ? 0 : n.lc] >> 3), m |= n.ia; + } + + m && (alert("todo:VP8InitRandom"), e.ia = 1); + } + + e.Ga = c.Id; + 100 < e.Ga ? e.Ga = 100 : 0 > e.Ga && (e.Ga = 0); + } + + Me(a, d) || (b = a.a); + } + } else { b = a.a; } + } + + 0 == b && null != g.Oa && g.Oa.fd && (b = Bd(g.ba)); + } + + g = b; + } + + f = 0 != g ? null : 11 > f ? h.f.RGBA.eb : h.f.kb.y; + } else { f = null; } + + return f; + }; + + var Dd = [3, 4, 3, 4, 4, 2, 2, 4, 4, 4, 2, 1, 1]; + }; + + new WebPDecoder(); + /*Copyright (c) 2017 Dominik Homberger + + https://webpjs.appspot.com + WebPRiffParser dominikhlbg@gmail.com + */ + + function memcmp(data, data_off, str, size) { + for (var i = 0; i < size; i++) { + if (data[data_off + i] != str.charCodeAt(i)) { return true; } + } + + return false; + } + + function GetTag(data, data_off) { + var str = ""; + + for (var i = 0; i < 4; i++) { + str += String.fromCharCode(data[data_off++]); + } + + return str; + } + + function GetLE16(data, data_off) { + return data[data_off + 0] << 0 | data[data_off + 1] << 8; + } + + function GetLE24(data, data_off) { + return (data[data_off + 0] << 0 | data[data_off + 1] << 8 | data[data_off + 2] << 16) >>> 0; + } + + function GetLE32(data, data_off) { + return (data[data_off + 0] << 0 | data[data_off + 1] << 8 | data[data_off + 2] << 16 | data[data_off + 3] << 24) >>> 0; + } + + function WebPRiffParser(src, src_off) { + var imagearray = {}; + var i = 0; + var alpha_chunk = false; + var alpha_size = 0; + var alpha_offset = 0; + imagearray["frames"] = []; + if (memcmp(src, src_off, "RIFF", 4)) { return; } + src_off += 4; + var riff_size = GetLE32(src, src_off) + 8; + src_off += 8; + + while (src_off < src.length) { + var fourcc = GetTag(src, src_off); + src_off += 4; + var payload_size = GetLE32(src, src_off); + src_off += 4; + var payload_size_padded = payload_size + (payload_size & 1); + + switch (fourcc) { + case "VP8 ": + case "VP8L": + if (typeof imagearray["frames"][i] === "undefined") { imagearray["frames"][i] = {}; } + var obj = imagearray["frames"][i]; + var height = [0]; + var width = [0]; + obj["src_off"] = alpha_chunk ? alpha_offset : src_off - 8; + obj["src_size"] = alpha_size + payload_size + 8; //var rgba = webpdecoder.WebPDecodeRGBA(src,(alpha_chunk?alpha_offset:src_off-8),alpha_size+payload_size+8,width,height); + //imagearray[i]={'rgba':rgba,'width':width[0],'height':height[0]}; + + i++; + + if (alpha_chunk) { + alpha_chunk = false; + alpha_size = 0; + alpha_offset = 0; + } + + break; + + case "VP8X": + var obj = imagearray["header"] = {}; + var feature_flags = obj["feature_flags"] = src[src_off]; + var src_off_ = src_off + 4; + var canvas_width = obj["canvas_width"] = 1 + GetLE24(src, src_off_); + src_off_ += 3; + var canvas_height = obj["canvas_height"] = 1 + GetLE24(src, src_off_); + src_off_ += 3; + break; + + case "ALPH": + alpha_chunk = true; + alpha_size = payload_size_padded + 8; + alpha_offset = src_off - 8; + break; + + case "ANIM": + var obj = imagearray["header"]; + var bgcolor = obj["bgcolor"] = GetLE32(src, src_off); + src_off_ = src_off + 4; + var loop_count = obj["loop_count"] = GetLE16(src, src_off_); + src_off_ += 2; + break; + + case "ANMF": + var offset_x = 0, + offset_y = 0, + width = 0, + height = 0, + duration = 0, + blend = 0, + dispose = 0, + temp = 0; + var obj = imagearray["frames"][i] = {}; + obj["offset_x"] = offset_x = 2 * GetLE24(src, src_off); + src_off += 3; + obj["offset_y"] = offset_y = 2 * GetLE24(src, src_off); + src_off += 3; + obj["width"] = width = 1 + GetLE24(src, src_off); + src_off += 3; + obj["height"] = height = 1 + GetLE24(src, src_off); + src_off += 3; + obj["duration"] = duration = GetLE24(src, src_off); + src_off += 3; + temp = src[src_off++]; + obj["dispose"] = dispose = temp & 1; + obj["blend"] = blend = temp >> 1 & 1; + break; + + default: + } + + if (fourcc != "ANMF") { src_off += payload_size_padded; } + } + + return imagearray; + } + + var height = [0]; + var width = [0]; + var pixels = []; + var webpdecoder = new WebPDecoder(); + var response = imageData; + var imagearray = WebPRiffParser(response, 0); + imagearray["response"] = response; + imagearray["rgbaoutput"] = true; + imagearray["dataurl"] = false; + var header = imagearray["header"] ? imagearray["header"] : null; + var frames = imagearray["frames"] ? imagearray["frames"] : null; + + if (header) { + header["loop_counter"] = header["loop_count"]; + height = header["canvas_height"]; + width = header["canvas_width"]; + + for (var f = 0; f < frames.length; f++) { + if (frames[f]["blend"] == 0) { + break; + } + } + } + + var frame = frames[0]; + var rgba = webpdecoder.WebPDecodeRGBA(response, frame["src_off"], frame["src_size"], width, height); + frame["rgba"] = rgba; + frame["imgwidth"] = width[0]; + frame["imgheight"] = height[0]; + + for (var i = 0; i < width[0] * height[0] * 4; i++) { + pixels[i] = rgba[i]; + } + + this.width = width; + this.height = height; + this.data = pixels; + return this; +} + +WebPDecoder.prototype.getData = function () { + return this.data; +}; + +try { + exports.WebPDecoder = WebPDecoder; +} catch (e) {} // CommonJS. + +/* + Copyright (c) 2013 Gildas Lormeau. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + + 3. The names of the authors may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, + INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * This program is based on JZlib 1.0.2 ymnk, JCraft,Inc. + * JZlib is based on zlib-1.1.3, so all credit should go authors + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu) + * and contributors of zlib. + */ +(function (global) { + + var MAX_BITS = 15; + var D_CODES = 30; + var BL_CODES = 19; + var LENGTH_CODES = 29; + var LITERALS = 256; + var L_CODES = LITERALS + 1 + LENGTH_CODES; + var HEAP_SIZE = 2 * L_CODES + 1; + var END_BLOCK = 256; // Bit length codes must not exceed MAX_BL_BITS bits + + var MAX_BL_BITS = 7; // repeat previous bit length 3-6 times (2 bits of repeat count) + + var REP_3_6 = 16; // repeat a zero length 3-10 times (3 bits of repeat count) + + var REPZ_3_10 = 17; // repeat a zero length 11-138 times (7 bits of repeat count) + + var REPZ_11_138 = 18; // The lengths of the bit length codes are sent in order of decreasing + // probability, to avoid transmitting the lengths for unused bit + // length codes. + + var Buf_size = 8 * 2; // JZlib version : "1.0.2" + + var Z_DEFAULT_COMPRESSION = -1; // compression strategy + + var Z_FILTERED = 1; + var Z_HUFFMAN_ONLY = 2; + var Z_DEFAULT_STRATEGY = 0; + var Z_NO_FLUSH = 0; + var Z_PARTIAL_FLUSH = 1; + var Z_FULL_FLUSH = 3; + var Z_FINISH = 4; + var Z_OK = 0; + var Z_STREAM_END = 1; + var Z_NEED_DICT = 2; + var Z_STREAM_ERROR = -2; + var Z_DATA_ERROR = -3; + var Z_BUF_ERROR = -5; // Tree + // see definition of array dist_code below + + var _dist_code = [0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29]; + + function Tree() { + var that = this; // dyn_tree; // the dynamic tree + // max_code; // largest code with non zero frequency + // stat_desc; // the corresponding static tree + // Compute the optimal bit lengths for a tree and update the total bit + // length + // for the current block. + // IN assertion: the fields freq and dad are set, heap[heap_max] and + // above are the tree nodes sorted by increasing frequency. + // OUT assertions: the field len is set to the optimal bit length, the + // array bl_count contains the frequencies for each bit length. + // The length opt_len is updated; static_len is also updated if stree is + // not null. + + function gen_bitlen(s) { + var tree = that.dyn_tree; + var stree = that.stat_desc.static_tree; + var extra = that.stat_desc.extra_bits; + var base = that.stat_desc.extra_base; + var max_length = that.stat_desc.max_length; + var h; // heap index + + var n, m; // iterate over the tree elements + + var bits; // bit length + + var xbits; // extra bits + + var f; // frequency + + var overflow = 0; // number of elements with bit length too large + + for (bits = 0; bits <= MAX_BITS; bits++) { + s.bl_count[bits] = 0; + } // In a first pass, compute the optimal bit lengths (which may + // overflow in the case of the bit length tree). + + + tree[s.heap[s.heap_max] * 2 + 1] = 0; // root of the heap + + for (h = s.heap_max + 1; h < HEAP_SIZE; h++) { + n = s.heap[h]; + bits = tree[tree[n * 2 + 1] * 2 + 1] + 1; + + if (bits > max_length) { + bits = max_length; + overflow++; + } + + tree[n * 2 + 1] = bits; // We overwrite tree[n*2+1] which is no longer needed + + if (n > that.max_code) { continue; } // not a leaf node + + s.bl_count[bits]++; + xbits = 0; + if (n >= base) { xbits = extra[n - base]; } + f = tree[n * 2]; + s.opt_len += f * (bits + xbits); + if (stree) { s.static_len += f * (stree[n * 2 + 1] + xbits); } + } + + if (overflow === 0) { return; } // This happens for example on obj2 and pic of the Calgary corpus + // Find the first bit length which could increase: + + do { + bits = max_length - 1; + + while (s.bl_count[bits] === 0) { + bits--; + } + + s.bl_count[bits]--; // move one leaf down the tree + + s.bl_count[bits + 1] += 2; // move one overflow item as its brother + + s.bl_count[max_length]--; // The brother of the overflow item also moves one step up, + // but this does not affect bl_count[max_length] + + overflow -= 2; + } while (overflow > 0); + + for (bits = max_length; bits !== 0; bits--) { + n = s.bl_count[bits]; + + while (n !== 0) { + m = s.heap[--h]; + if (m > that.max_code) { continue; } + + if (tree[m * 2 + 1] !== bits) { + s.opt_len += (bits - tree[m * 2 + 1]) * tree[m * 2]; + tree[m * 2 + 1] = bits; + } + + n--; + } + } + } // Reverse the first len bits of a code, using straightforward code (a + // faster + // method would use a table) + // IN assertion: 1 <= len <= 15 + + + function bi_reverse(code, // the value to invert + len // its bit length + ) { + var res = 0; + + do { + res |= code & 1; + code >>>= 1; + res <<= 1; + } while (--len > 0); + + return res >>> 1; + } // Generate the codes for a given tree and bit counts (which need not be + // optimal). + // IN assertion: the array bl_count contains the bit length statistics for + // the given tree and the field len is set for all tree elements. + // OUT assertion: the field code is set for all tree elements of non + // zero code length. + + + function gen_codes(tree, // the tree to decorate + max_code, // largest code with non zero frequency + bl_count // number of codes at each bit length + ) { + var next_code = []; // next code value for each + // bit length + + var code = 0; // running code value + + var bits; // bit index + + var n; // code index + + var len; // The distribution counts are first used to generate the code values + // without bit reversal. + + for (bits = 1; bits <= MAX_BITS; bits++) { + next_code[bits] = code = code + bl_count[bits - 1] << 1; + } // Check that the bit counts in bl_count are consistent. The last code + // must be all ones. + // Assert (code + bl_count[MAX_BITS]-1 === (1<= 1; n--) { + s.pqdownheap(tree, n); + } // Construct the Huffman tree by repeatedly combining the least two + // frequent nodes. + + + node = elems; // next internal node of the tree + + do { + // n = node of least frequency + n = s.heap[1]; + s.heap[1] = s.heap[s.heap_len--]; + s.pqdownheap(tree, 1); + m = s.heap[1]; // m = node of next least frequency + + s.heap[--s.heap_max] = n; // keep the nodes sorted by frequency + + s.heap[--s.heap_max] = m; // Create a new node father of n and m + + tree[node * 2] = tree[n * 2] + tree[m * 2]; + s.depth[node] = Math.max(s.depth[n], s.depth[m]) + 1; + tree[n * 2 + 1] = tree[m * 2 + 1] = node; // and insert the new node in the heap + + s.heap[1] = node++; + s.pqdownheap(tree, 1); + } while (s.heap_len >= 2); + + s.heap[--s.heap_max] = s.heap[1]; // At this point, the fields freq and dad are set. We can now + // generate the bit lengths. + + gen_bitlen(s); // The field len is now set, we can generate the bit codes + + gen_codes(tree, that.max_code, s.bl_count); + }; + } + + Tree._length_code = [0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28]; + Tree.base_length = [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 0]; + Tree.base_dist = [0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576]; // Mapping from a distance to a distance code. dist is the distance - 1 and + // must not have side effects. _dist_code[256] and _dist_code[257] are never + // used. + + Tree.d_code = function (dist) { + return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)]; + }; // extra bits for each length code + + + Tree.extra_lbits = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]; // extra bits for each distance code + + Tree.extra_dbits = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]; // extra bits for each bit length code + + Tree.extra_blbits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]; + Tree.bl_order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; // StaticTree + + function StaticTree(static_tree, extra_bits, extra_base, elems, max_length) { + var that = this; + that.static_tree = static_tree; + that.extra_bits = extra_bits; + that.extra_base = extra_base; + that.elems = elems; + that.max_length = max_length; + } + + StaticTree.static_ltree = [12, 8, 140, 8, 76, 8, 204, 8, 44, 8, 172, 8, 108, 8, 236, 8, 28, 8, 156, 8, 92, 8, 220, 8, 60, 8, 188, 8, 124, 8, 252, 8, 2, 8, 130, 8, 66, 8, 194, 8, 34, 8, 162, 8, 98, 8, 226, 8, 18, 8, 146, 8, 82, 8, 210, 8, 50, 8, 178, 8, 114, 8, 242, 8, 10, 8, 138, 8, 74, 8, 202, 8, 42, 8, 170, 8, 106, 8, 234, 8, 26, 8, 154, 8, 90, 8, 218, 8, 58, 8, 186, 8, 122, 8, 250, 8, 6, 8, 134, 8, 70, 8, 198, 8, 38, 8, 166, 8, 102, 8, 230, 8, 22, 8, 150, 8, 86, 8, 214, 8, 54, 8, 182, 8, 118, 8, 246, 8, 14, 8, 142, 8, 78, 8, 206, 8, 46, 8, 174, 8, 110, 8, 238, 8, 30, 8, 158, 8, 94, 8, 222, 8, 62, 8, 190, 8, 126, 8, 254, 8, 1, 8, 129, 8, 65, 8, 193, 8, 33, 8, 161, 8, 97, 8, 225, 8, 17, 8, 145, 8, 81, 8, 209, 8, 49, 8, 177, 8, 113, 8, 241, 8, 9, 8, 137, 8, 73, 8, 201, 8, 41, 8, 169, 8, 105, 8, 233, 8, 25, 8, 153, 8, 89, 8, 217, 8, 57, 8, 185, 8, 121, 8, 249, 8, 5, 8, 133, 8, 69, 8, 197, 8, 37, 8, 165, 8, 101, 8, 229, 8, 21, 8, 149, 8, 85, 8, 213, 8, 53, 8, 181, 8, 117, 8, 245, 8, 13, 8, 141, 8, 77, 8, 205, 8, 45, 8, 173, 8, 109, 8, 237, 8, 29, 8, 157, 8, 93, 8, 221, 8, 61, 8, 189, 8, 125, 8, 253, 8, 19, 9, 275, 9, 147, 9, 403, 9, 83, 9, 339, 9, 211, 9, 467, 9, 51, 9, 307, 9, 179, 9, 435, 9, 115, 9, 371, 9, 243, 9, 499, 9, 11, 9, 267, 9, 139, 9, 395, 9, 75, 9, 331, 9, 203, 9, 459, 9, 43, 9, 299, 9, 171, 9, 427, 9, 107, 9, 363, 9, 235, 9, 491, 9, 27, 9, 283, 9, 155, 9, 411, 9, 91, 9, 347, 9, 219, 9, 475, 9, 59, 9, 315, 9, 187, 9, 443, 9, 123, 9, 379, 9, 251, 9, 507, 9, 7, 9, 263, 9, 135, 9, 391, 9, 71, 9, 327, 9, 199, 9, 455, 9, 39, 9, 295, 9, 167, 9, 423, 9, 103, 9, 359, 9, 231, 9, 487, 9, 23, 9, 279, 9, 151, 9, 407, 9, 87, 9, 343, 9, 215, 9, 471, 9, 55, 9, 311, 9, 183, 9, 439, 9, 119, 9, 375, 9, 247, 9, 503, 9, 15, 9, 271, 9, 143, 9, 399, 9, 79, 9, 335, 9, 207, 9, 463, 9, 47, 9, 303, 9, 175, 9, 431, 9, 111, 9, 367, 9, 239, 9, 495, 9, 31, 9, 287, 9, 159, 9, 415, 9, 95, 9, 351, 9, 223, 9, 479, 9, 63, 9, 319, 9, 191, 9, 447, 9, 127, 9, 383, 9, 255, 9, 511, 9, 0, 7, 64, 7, 32, 7, 96, 7, 16, 7, 80, 7, 48, 7, 112, 7, 8, 7, 72, 7, 40, 7, 104, 7, 24, 7, 88, 7, 56, 7, 120, 7, 4, 7, 68, 7, 36, 7, 100, 7, 20, 7, 84, 7, 52, 7, 116, 7, 3, 8, 131, 8, 67, 8, 195, 8, 35, 8, 163, 8, 99, 8, 227, 8]; + StaticTree.static_dtree = [0, 5, 16, 5, 8, 5, 24, 5, 4, 5, 20, 5, 12, 5, 28, 5, 2, 5, 18, 5, 10, 5, 26, 5, 6, 5, 22, 5, 14, 5, 30, 5, 1, 5, 17, 5, 9, 5, 25, 5, 5, 5, 21, 5, 13, 5, 29, 5, 3, 5, 19, 5, 11, 5, 27, 5, 7, 5, 23, 5]; + StaticTree.static_l_desc = new StaticTree(StaticTree.static_ltree, Tree.extra_lbits, LITERALS + 1, L_CODES, MAX_BITS); + StaticTree.static_d_desc = new StaticTree(StaticTree.static_dtree, Tree.extra_dbits, 0, D_CODES, MAX_BITS); + StaticTree.static_bl_desc = new StaticTree(null, Tree.extra_blbits, 0, BL_CODES, MAX_BL_BITS); // Deflate + + var MAX_MEM_LEVEL = 9; + var DEF_MEM_LEVEL = 8; + + function Config(good_length, max_lazy, nice_length, max_chain, func) { + var that = this; + that.good_length = good_length; + that.max_lazy = max_lazy; + that.nice_length = nice_length; + that.max_chain = max_chain; + that.func = func; + } + + var STORED = 0; + var FAST = 1; + var SLOW = 2; + var config_table = [new Config(0, 0, 0, 0, STORED), new Config(4, 4, 8, 4, FAST), new Config(4, 5, 16, 8, FAST), new Config(4, 6, 32, 32, FAST), new Config(4, 4, 16, 16, SLOW), new Config(8, 16, 32, 32, SLOW), new Config(8, 16, 128, 128, SLOW), new Config(8, 32, 128, 256, SLOW), new Config(32, 128, 258, 1024, SLOW), new Config(32, 258, 258, 4096, SLOW)]; + var z_errmsg = ["need dictionary", // Z_NEED_DICT + // 2 + "stream end", // Z_STREAM_END 1 + "", // Z_OK 0 + "", // Z_ERRNO (-1) + "stream error", // Z_STREAM_ERROR (-2) + "data error", // Z_DATA_ERROR (-3) + "", // Z_MEM_ERROR (-4) + "buffer error", // Z_BUF_ERROR (-5) + "", // Z_VERSION_ERROR (-6) + ""]; // block not completed, need more input or more output + + var NeedMore = 0; // block flush performed + + var BlockDone = 1; // finish started, need only more output at next deflate + + var FinishStarted = 2; // finish done, accept no more input or output + + var FinishDone = 3; // preset dictionary flag in zlib header + + var PRESET_DICT = 0x20; + var INIT_STATE = 42; + var BUSY_STATE = 113; + var FINISH_STATE = 666; // The deflate compression method + + var Z_DEFLATED = 8; + var STORED_BLOCK = 0; + var STATIC_TREES = 1; + var DYN_TREES = 2; + var MIN_MATCH = 3; + var MAX_MATCH = 258; + var MIN_LOOKAHEAD = MAX_MATCH + MIN_MATCH + 1; + + function smaller(tree, n, m, depth) { + var tn2 = tree[n * 2]; + var tm2 = tree[m * 2]; + return tn2 < tm2 || tn2 === tm2 && depth[n] <= depth[m]; + } + + function Deflate() { + var that = this; + var strm; // pointer back to this zlib stream + + var status; // as the name implies + // pending_buf; // output still pending + + var pending_buf_size; // size of pending_buf + + var last_flush; // value of flush param for previous deflate call + + var w_size; // LZ77 window size (32K by default) + + var w_bits; // log2(w_size) (8..16) + + var w_mask; // w_size - 1 + + var window; // Sliding window. Input bytes are read into the second half of the window, + // and move to the first half later to keep a dictionary of at least wSize + // bytes. With this organization, matches are limited to a distance of + // wSize-MAX_MATCH bytes, but this ensures that IO is always + // performed with a length multiple of the block size. Also, it limits + // the window size to 64K, which is quite useful on MSDOS. + // To do: use the user input buffer as sliding window. + + var window_size; // Actual size of window: 2*wSize, except when the user input buffer + // is directly used as sliding window. + + var prev; // Link to older string with same hash index. To limit the size of this + // array to 64K, this link is maintained only for the last 32K strings. + // An index in this array is thus a window index modulo 32K. + + var head; // Heads of the hash chains or NIL. + + var ins_h; // hash index of string to be inserted + + var hash_size; // number of elements in hash table + + var hash_bits; // log2(hash_size) + + var hash_mask; // hash_size-1 + // Number of bits by which ins_h must be shifted at each input + // step. It must be such that after MIN_MATCH steps, the oldest + // byte no longer takes part in the hash key, that is: + // hash_shift * MIN_MATCH >= hash_bits + + var hash_shift; // Window position at the beginning of the current output block. Gets + // negative when the window is moved backwards. + + var block_start; + var match_length; // length of best match + + var prev_match; // previous match + + var match_available; // set if previous match exists + + var strstart; // start of string to insert + + var match_start; // start of matching string + + var lookahead; // number of valid bytes ahead in window + // Length of the best match at previous step. Matches not greater than this + // are discarded. This is used in the lazy match evaluation. + + var prev_length; // To speed up deflation, hash chains are never searched beyond this + // length. A higher limit improves compression ratio but degrades the speed. + + var max_chain_length; // Attempt to find a better match only when the current match is strictly + // smaller than this value. This mechanism is used only for compression + // levels >= 4. + + var max_lazy_match; // Insert new strings in the hash table only if the match length is not + // greater than this length. This saves time but degrades compression. + // max_insert_length is used only for compression levels <= 3. + + var level; // compression level (1..9) + + var strategy; // favor or force Huffman coding + // Use a faster search when the previous match is longer than this + + var good_match; // Stop searching when current match exceeds this + + var nice_match; + var dyn_ltree; // literal and length tree + + var dyn_dtree; // distance tree + + var bl_tree; // Huffman tree for bit lengths + + var l_desc = new Tree(); // desc for literal tree + + var d_desc = new Tree(); // desc for distance tree + + var bl_desc = new Tree(); // desc for bit length tree + // that.heap_len; // number of elements in the heap + // that.heap_max; // element of largest frequency + // The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. + // The same heap array is used to build all trees. + // Depth of each subtree used as tie breaker for trees of equal frequency + + that.depth = []; + var l_buf; // index for literals or lengths */ + // Size of match buffer for literals/lengths. There are 4 reasons for + // limiting lit_bufsize to 64K: + // - frequencies can be kept in 16 bit counters + // - if compression is not successful for the first block, all input + // data is still in the window so we can still emit a stored block even + // when input comes from standard input. (This can also be done for + // all blocks if lit_bufsize is not greater than 32K.) + // - if compression is not successful for a file smaller than 64K, we can + // even emit a stored file instead of a stored block (saving 5 bytes). + // This is applicable only for zip (not gzip or zlib). + // - creating new Huffman trees less frequently may not provide fast + // adaptation to changes in the input data statistics. (Take for + // example a binary file with poorly compressible code followed by + // a highly compressible string table.) Smaller buffer sizes give + // fast adaptation but have of course the overhead of transmitting + // trees more frequently. + // - I can't count above 4 + + var lit_bufsize; + var last_lit; // running index in l_buf + // Buffer for distances. To simplify the code, d_buf and l_buf have + // the same number of elements. To use different lengths, an extra flag + // array would be necessary. + + var d_buf; // index of pendig_buf + // that.opt_len; // bit length of current block with optimal trees + // that.static_len; // bit length of current block with static trees + + var matches; // number of string matches in current block + + var last_eob_len; // bit length of EOB code for last block + // Output buffer. bits are inserted starting at the bottom (least + // significant bits). + + var bi_buf; // Number of valid bits in bi_buf. All bits above the last valid bit + // are always zero. + + var bi_valid; // number of codes at each bit length for an optimal tree + + that.bl_count = []; // heap used to build the Huffman trees + + that.heap = []; + dyn_ltree = []; + dyn_dtree = []; + bl_tree = []; + + function lm_init() { + var i; + window_size = 2 * w_size; + head[hash_size - 1] = 0; + + for (i = 0; i < hash_size - 1; i++) { + head[i] = 0; + } // Set the default configuration parameters: + + + max_lazy_match = config_table[level].max_lazy; + good_match = config_table[level].good_length; + nice_match = config_table[level].nice_length; + max_chain_length = config_table[level].max_chain; + strstart = 0; + block_start = 0; + lookahead = 0; + match_length = prev_length = MIN_MATCH - 1; + match_available = 0; + ins_h = 0; + } + + function init_block() { + var i; // Initialize the trees. + + for (i = 0; i < L_CODES; i++) { + dyn_ltree[i * 2] = 0; + } + + for (i = 0; i < D_CODES; i++) { + dyn_dtree[i * 2] = 0; + } + + for (i = 0; i < BL_CODES; i++) { + bl_tree[i * 2] = 0; + } + + dyn_ltree[END_BLOCK * 2] = 1; + that.opt_len = that.static_len = 0; + last_lit = matches = 0; + } // Initialize the tree data structures for a new zlib stream. + + + function tr_init() { + l_desc.dyn_tree = dyn_ltree; + l_desc.stat_desc = StaticTree.static_l_desc; + d_desc.dyn_tree = dyn_dtree; + d_desc.stat_desc = StaticTree.static_d_desc; + bl_desc.dyn_tree = bl_tree; + bl_desc.stat_desc = StaticTree.static_bl_desc; + bi_buf = 0; + bi_valid = 0; + last_eob_len = 8; // enough lookahead for inflate + // Initialize the first block of the first file: + + init_block(); + } // Restore the heap property by moving down the tree starting at node k, + // exchanging a node with the smallest of its two sons if necessary, + // stopping + // when the heap property is re-established (each father smaller than its + // two sons). + + + that.pqdownheap = function (tree, // the tree to restore + k // node to move down + ) { + var heap = that.heap; + var v = heap[k]; + var j = k << 1; // left son of k + + while (j <= that.heap_len) { + // Set j to the smallest of the two sons: + if (j < that.heap_len && smaller(tree, heap[j + 1], heap[j], that.depth)) { + j++; + } // Exit if v is smaller than both sons + + + if (smaller(tree, v, heap[j], that.depth)) { break; } // Exchange v with the smallest son + + heap[k] = heap[j]; + k = j; // And continue down the tree, setting j to the left son of k + + j <<= 1; + } + + heap[k] = v; + }; // Scan a literal or distance tree to determine the frequencies of the codes + // in the bit length tree. + + + function scan_tree(tree, // the tree to be scanned + max_code // and its largest code of non zero frequency + ) { + var n; // iterates over all tree elements + + var prevlen = -1; // last emitted length + + var curlen; // length of current code + + var nextlen = tree[0 * 2 + 1]; // length of next code + + var count = 0; // repeat count of the current code + + var max_count = 7; // max repeat count + + var min_count = 4; // min repeat count + + if (nextlen === 0) { + max_count = 138; + min_count = 3; + } + + tree[(max_code + 1) * 2 + 1] = 0xffff; // guard + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; + nextlen = tree[(n + 1) * 2 + 1]; + + if (++count < max_count && curlen === nextlen) { + continue; + } else if (count < min_count) { + bl_tree[curlen * 2] += count; + } else if (curlen !== 0) { + if (curlen !== prevlen) { bl_tree[curlen * 2]++; } + bl_tree[REP_3_6 * 2]++; + } else if (count <= 10) { + bl_tree[REPZ_3_10 * 2]++; + } else { + bl_tree[REPZ_11_138 * 2]++; + } + + count = 0; + prevlen = curlen; + + if (nextlen === 0) { + max_count = 138; + min_count = 3; + } else if (curlen === nextlen) { + max_count = 6; + min_count = 3; + } else { + max_count = 7; + min_count = 4; + } + } + } // Construct the Huffman tree for the bit lengths and return the index in + // bl_order of the last bit length code to send. + + + function build_bl_tree() { + var max_blindex; // index of last bit length code of non zero freq + // Determine the bit length frequencies for literal and distance trees + + scan_tree(dyn_ltree, l_desc.max_code); + scan_tree(dyn_dtree, d_desc.max_code); // Build the bit length tree: + + bl_desc.build_tree(that); // opt_len now includes the length of the tree representations, except + // the lengths of the bit lengths codes and the 5+5+4 bits for the + // counts. + // Determine the number of bit length codes to send. The pkzip format + // requires that at least 4 bit length codes be sent. (appnote.txt says + // 3 but the actual value used is 4.) + + for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) { + if (bl_tree[Tree.bl_order[max_blindex] * 2 + 1] !== 0) { break; } + } // Update opt_len to include the bit length tree and counts + + + that.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4; + return max_blindex; + } // Output a byte on the stream. + // IN assertion: there is enough room in pending_buf. + + + function put_byte(p) { + that.pending_buf[that.pending++] = p; + } + + function put_short(w) { + put_byte(w & 0xff); + put_byte(w >>> 8 & 0xff); + } + + function putShortMSB(b) { + put_byte(b >> 8 & 0xff); + put_byte(b & 0xff & 0xff); + } + + function send_bits(value, length) { + var val, + len = length; + + if (bi_valid > Buf_size - len) { + val = value; // bi_buf |= (val << bi_valid); + + bi_buf |= val << bi_valid & 0xffff; + put_short(bi_buf); + bi_buf = val >>> Buf_size - bi_valid; + bi_valid += len - Buf_size; + } else { + // bi_buf |= (value) << bi_valid; + bi_buf |= value << bi_valid & 0xffff; + bi_valid += len; + } + } + + function send_code(c, tree) { + var c2 = c * 2; + send_bits(tree[c2] & 0xffff, tree[c2 + 1] & 0xffff); + } // Send a literal or distance tree in compressed form, using the codes in + // bl_tree. + + + function send_tree(tree, // the tree to be sent + max_code // and its largest code of non zero frequency + ) { + var n; // iterates over all tree elements + + var prevlen = -1; // last emitted length + + var curlen; // length of current code + + var nextlen = tree[0 * 2 + 1]; // length of next code + + var count = 0; // repeat count of the current code + + var max_count = 7; // max repeat count + + var min_count = 4; // min repeat count + + if (nextlen === 0) { + max_count = 138; + min_count = 3; + } + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; + nextlen = tree[(n + 1) * 2 + 1]; + + if (++count < max_count && curlen === nextlen) { + continue; + } else if (count < min_count) { + do { + send_code(curlen, bl_tree); + } while (--count !== 0); + } else if (curlen !== 0) { + if (curlen !== prevlen) { + send_code(curlen, bl_tree); + count--; + } + + send_code(REP_3_6, bl_tree); + send_bits(count - 3, 2); + } else if (count <= 10) { + send_code(REPZ_3_10, bl_tree); + send_bits(count - 3, 3); + } else { + send_code(REPZ_11_138, bl_tree); + send_bits(count - 11, 7); + } + + count = 0; + prevlen = curlen; + + if (nextlen === 0) { + max_count = 138; + min_count = 3; + } else if (curlen === nextlen) { + max_count = 6; + min_count = 3; + } else { + max_count = 7; + min_count = 4; + } + } + } // Send the header for a block using dynamic Huffman trees: the counts, the + // lengths of the bit length codes, the literal tree and the distance tree. + // IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. + + + function send_all_trees(lcodes, dcodes, blcodes) { + var rank; // index in bl_order + + send_bits(lcodes - 257, 5); // not +255 as stated in appnote.txt + + send_bits(dcodes - 1, 5); + send_bits(blcodes - 4, 4); // not -3 as stated in appnote.txt + + for (rank = 0; rank < blcodes; rank++) { + send_bits(bl_tree[Tree.bl_order[rank] * 2 + 1], 3); + } + + send_tree(dyn_ltree, lcodes - 1); // literal tree + + send_tree(dyn_dtree, dcodes - 1); // distance tree + } // Flush the bit buffer, keeping at most 7 bits in it. + + + function bi_flush() { + if (bi_valid === 16) { + put_short(bi_buf); + bi_buf = 0; + bi_valid = 0; + } else if (bi_valid >= 8) { + put_byte(bi_buf & 0xff); + bi_buf >>>= 8; + bi_valid -= 8; + } + } // Send one empty static block to give enough lookahead for inflate. + // This takes 10 bits, of which 7 may remain in the bit buffer. + // The current inflate code requires 9 bits of lookahead. If the + // last two codes for the previous block (real code plus EOB) were coded + // on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode + // the last real code. In this case we send two empty static blocks instead + // of one. (There are no problems if the previous block is stored or fixed.) + // To simplify the code, we assume the worst case of last real code encoded + // on one bit only. + + + function _tr_align() { + send_bits(STATIC_TREES << 1, 3); + send_code(END_BLOCK, StaticTree.static_ltree); + bi_flush(); // Of the 10 bits for the empty block, we have already sent + // (10 - bi_valid) bits. The lookahead for the last real code (before + // the EOB of the previous block) was thus at least one plus the length + // of the EOB plus what we have just sent of the empty static block. + + if (1 + last_eob_len + 10 - bi_valid < 9) { + send_bits(STATIC_TREES << 1, 3); + send_code(END_BLOCK, StaticTree.static_ltree); + bi_flush(); + } + + last_eob_len = 7; + } // Save the match info and tally the frequency counts. Return true if + // the current block must be flushed. + + + function _tr_tally(dist, // distance of matched string + lc // match length-MIN_MATCH or unmatched char (if dist==0) + ) { + var out_length, in_length, dcode; + that.pending_buf[d_buf + last_lit * 2] = dist >>> 8 & 0xff; + that.pending_buf[d_buf + last_lit * 2 + 1] = dist & 0xff; + that.pending_buf[l_buf + last_lit] = lc & 0xff; + last_lit++; + + if (dist === 0) { + // lc is the unmatched char + dyn_ltree[lc * 2]++; + } else { + matches++; // Here, lc is the match length - MIN_MATCH + + dist--; // dist = match distance - 1 + + dyn_ltree[(Tree._length_code[lc] + LITERALS + 1) * 2]++; + dyn_dtree[Tree.d_code(dist) * 2]++; + } + + if ((last_lit & 0x1fff) === 0 && level > 2) { + // Compute an upper bound for the compressed length + out_length = last_lit * 8; + in_length = strstart - block_start; + + for (dcode = 0; dcode < D_CODES; dcode++) { + out_length += dyn_dtree[dcode * 2] * (5 + Tree.extra_dbits[dcode]); + } + + out_length >>>= 3; + if (matches < Math.floor(last_lit / 2) && out_length < Math.floor(in_length / 2)) { return true; } + } + + return last_lit === lit_bufsize - 1; // We avoid equality with lit_bufsize because of wraparound at 64K + // on 16 bit machines and because stored blocks are restricted to + // 64K-1 bytes. + } // Send the block data compressed using the given Huffman trees + + + function compress_block(ltree, dtree) { + var dist; // distance of matched string + + var lc; // match length or unmatched char (if dist === 0) + + var lx = 0; // running index in l_buf + + var code; // the code to send + + var extra; // number of extra bits to send + + if (last_lit !== 0) { + do { + dist = that.pending_buf[d_buf + lx * 2] << 8 & 0xff00 | that.pending_buf[d_buf + lx * 2 + 1] & 0xff; + lc = that.pending_buf[l_buf + lx] & 0xff; + lx++; + + if (dist === 0) { + send_code(lc, ltree); // send a literal byte + } else { + // Here, lc is the match length - MIN_MATCH + code = Tree._length_code[lc]; + send_code(code + LITERALS + 1, ltree); // send the length + // code + + extra = Tree.extra_lbits[code]; + + if (extra !== 0) { + lc -= Tree.base_length[code]; + send_bits(lc, extra); // send the extra length bits + } + + dist--; // dist is now the match distance - 1 + + code = Tree.d_code(dist); + send_code(code, dtree); // send the distance code + + extra = Tree.extra_dbits[code]; + + if (extra !== 0) { + dist -= Tree.base_dist[code]; + send_bits(dist, extra); // send the extra distance bits + } + } // literal or match pair ? + // Check that the overlay between pending_buf and d_buf+l_buf is + // ok: + + } while (lx < last_lit); + } + + send_code(END_BLOCK, ltree); + last_eob_len = ltree[END_BLOCK * 2 + 1]; + } // Flush the bit buffer and align the output on a byte boundary + + + function bi_windup() { + if (bi_valid > 8) { + put_short(bi_buf); + } else if (bi_valid > 0) { + put_byte(bi_buf & 0xff); + } + + bi_buf = 0; + bi_valid = 0; + } // Copy a stored block, storing first the length and its + // one's complement if requested. + + + function copy_block(buf, // the input data + len, // its length + header // true if block header must be written + ) { + bi_windup(); // align on byte boundary + + last_eob_len = 8; // enough lookahead for inflate + + if (header) { + put_short(len); + put_short(~len); + } + + that.pending_buf.set(window.subarray(buf, buf + len), that.pending); + that.pending += len; + } // Send a stored block + + + function _tr_stored_block(buf, // input block + stored_len, // length of input block + eof // true if this is the last block for a file + ) { + send_bits((STORED_BLOCK << 1) + (eof ? 1 : 0), 3); // send block type + + copy_block(buf, stored_len, true); // with header + } // Determine the best encoding for the current block: dynamic trees, static + // trees or store, and output the encoded block to the zip file. + + + function _tr_flush_block(buf, // input block, or NULL if too old + stored_len, // length of input block + eof // true if this is the last block for a file + ) { + var opt_lenb, static_lenb; // opt_len and static_len in bytes + + var max_blindex = 0; // index of last bit length code of non zero freq + // Build the Huffman trees unless a stored block is forced + + if (level > 0) { + // Construct the literal and distance trees + l_desc.build_tree(that); + d_desc.build_tree(that); // At this point, opt_len and static_len are the total bit lengths + // of + // the compressed block data, excluding the tree representations. + // Build the bit length tree for the above two trees, and get the + // index + // in bl_order of the last bit length code to send. + + max_blindex = build_bl_tree(); // Determine the best encoding. Compute first the block length in + // bytes + + opt_lenb = that.opt_len + 3 + 7 >>> 3; + static_lenb = that.static_len + 3 + 7 >>> 3; + if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; } + } else { + opt_lenb = static_lenb = stored_len + 5; // force a stored block + } + + if (stored_len + 4 <= opt_lenb && buf !== -1) { + // 4: two words for the lengths + // The test buf !== NULL is only necessary if LIT_BUFSIZE > WSIZE. + // Otherwise we can't have processed more than WSIZE input bytes + // since + // the last block flush, because compression would have been + // successful. If LIT_BUFSIZE <= WSIZE, it is never too late to + // transform a block into a stored block. + _tr_stored_block(buf, stored_len, eof); + } else if (static_lenb === opt_lenb) { + send_bits((STATIC_TREES << 1) + (eof ? 1 : 0), 3); + compress_block(StaticTree.static_ltree, StaticTree.static_dtree); + } else { + send_bits((DYN_TREES << 1) + (eof ? 1 : 0), 3); + send_all_trees(l_desc.max_code + 1, d_desc.max_code + 1, max_blindex + 1); + compress_block(dyn_ltree, dyn_dtree); + } // The above check is made mod 2^32, for files larger than 512 MB + // and uLong implemented on 32 bits. + + + init_block(); + + if (eof) { + bi_windup(); + } + } + + function flush_block_only(eof) { + _tr_flush_block(block_start >= 0 ? block_start : -1, strstart - block_start, eof); + + block_start = strstart; + strm.flush_pending(); + } // Fill the window when the lookahead becomes insufficient. + // Updates strstart and lookahead. + // + // IN assertion: lookahead < MIN_LOOKAHEAD + // OUT assertions: strstart <= window_size-MIN_LOOKAHEAD + // At least one byte has been read, or avail_in === 0; reads are + // performed for at least two bytes (required for the zip translate_eol + // option -- not supported here). + + + function fill_window() { + var n, m; + var p; + var more; // Amount of free space at the end of the window. + + do { + more = window_size - lookahead - strstart; // Deal with !@#$% 64K limit: + + if (more === 0 && strstart === 0 && lookahead === 0) { + more = w_size; + } else if (more === -1) { + // Very unlikely, but possible on 16 bit machine if strstart == + // 0 + // and lookahead === 1 (input done one byte at time) + more--; // If the window is almost full and there is insufficient + // lookahead, + // move the upper half to the lower one to make room in the + // upper half. + } else if (strstart >= w_size + w_size - MIN_LOOKAHEAD) { + window.set(window.subarray(w_size, w_size + w_size), 0); + match_start -= w_size; + strstart -= w_size; // we now have strstart >= MAX_DIST + + block_start -= w_size; // Slide the hash table (could be avoided with 32 bit values + // at the expense of memory usage). We slide even when level == + // 0 + // to keep the hash table consistent if we switch back to level + // > 0 + // later. (Using level 0 permanently is not an optimal usage of + // zlib, so we don't care about this pathological case.) + + n = hash_size; + p = n; + + do { + m = head[--p] & 0xffff; + head[p] = m >= w_size ? m - w_size : 0; + } while (--n !== 0); + + n = w_size; + p = n; + + do { + m = prev[--p] & 0xffff; + prev[p] = m >= w_size ? m - w_size : 0; // If n is not on any hash chain, prev[n] is garbage but + // its value will never be used. + } while (--n !== 0); + + more += w_size; + } + + if (strm.avail_in === 0) { return; } // If there was no sliding: + // strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && + // more === window_size - lookahead - strstart + // => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) + // => more >= window_size - 2*WSIZE + 2 + // In the BIG_MEM or MMAP case (not yet supported), + // window_size === input_size + MIN_LOOKAHEAD && + // strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. + // Otherwise, window_size === 2*WSIZE so more >= 2. + // If there was sliding, more >= WSIZE. So in all cases, more >= 2. + + n = strm.read_buf(window, strstart + lookahead, more); + lookahead += n; // Initialize the hash value now that we have some input: + + if (lookahead >= MIN_MATCH) { + ins_h = window[strstart] & 0xff; + ins_h = (ins_h << hash_shift ^ window[strstart + 1] & 0xff) & hash_mask; + } // If the whole input has less than MIN_MATCH bytes, ins_h is + // garbage, + // but this is not important since only literal bytes will be + // emitted. + + } while (lookahead < MIN_LOOKAHEAD && strm.avail_in !== 0); + } // Copy without compression as much as possible from the input stream, + // return + // the current block state. + // This function does not insert new strings in the dictionary since + // uncompressible data is probably not useful. This function is used + // only for the level=0 compression option. + // NOTE: this function should be optimized to avoid extra copying from + // window to pending_buf. + + + function deflate_stored(flush) { + // Stored blocks are limited to 0xffff bytes, pending_buf is limited + // to pending_buf_size, and each stored block has a 5 byte header: + var max_block_size = 0xffff; + var max_start; + + if (max_block_size > pending_buf_size - 5) { + max_block_size = pending_buf_size - 5; + } // Copy as much as possible from input to output: + + + while (true) { + // Fill the window as much as possible: + if (lookahead <= 1) { + fill_window(); + if (lookahead === 0 && flush === Z_NO_FLUSH) { return NeedMore; } + if (lookahead === 0) { break; } // flush the current block + } + + strstart += lookahead; + lookahead = 0; // Emit a stored block if pending_buf will be full: + + max_start = block_start + max_block_size; + + if (strstart === 0 || strstart >= max_start) { + // strstart === 0 is possible when wraparound on 16-bit machine + lookahead = strstart - max_start; + strstart = max_start; + flush_block_only(false); + if (strm.avail_out === 0) { return NeedMore; } + } // Flush if we may have to slide, otherwise block_start may become + // negative and the data will be gone: + + + if (strstart - block_start >= w_size - MIN_LOOKAHEAD) { + flush_block_only(false); + if (strm.avail_out === 0) { return NeedMore; } + } + } + + flush_block_only(flush === Z_FINISH); + if (strm.avail_out === 0) { return flush === Z_FINISH ? FinishStarted : NeedMore; } + return flush === Z_FINISH ? FinishDone : BlockDone; + } + + function longest_match(cur_match) { + var chain_length = max_chain_length; // max hash chain length + + var scan = strstart; // current string + + var match; // matched string + + var len; // length of current match + + var best_len = prev_length; // best match length so far + + var limit = strstart > w_size - MIN_LOOKAHEAD ? strstart - (w_size - MIN_LOOKAHEAD) : 0; + var _nice_match = nice_match; // Stop when cur_match becomes <= limit. To simplify the code, + // we prevent matches with the string of window index 0. + + var wmask = w_mask; + var strend = strstart + MAX_MATCH; + var scan_end1 = window[scan + best_len - 1]; + var scan_end = window[scan + best_len]; // The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of + // 16. + // It is easy to get rid of this optimization if necessary. + // Do not waste too much time if we already have a good match: + + if (prev_length >= good_match) { + chain_length >>= 2; + } // Do not look for matches beyond the end of the input. This is + // necessary + // to make deflate deterministic. + + + if (_nice_match > lookahead) { _nice_match = lookahead; } + + do { + match = cur_match; // Skip to next match if the match length cannot increase + // or if the match length is less than 2: + + if (window[match + best_len] !== scan_end || window[match + best_len - 1] !== scan_end1 || window[match] !== window[scan] || window[++match] !== window[scan + 1]) { continue; } // The check at best_len-1 can be removed because it will be made + // again later. (This heuristic is not always a win.) + // It is not necessary to compare scan[2] and match[2] since they + // are always equal when the other bytes match, given that + // the hash keys are equal and that HASH_BITS >= 8. + + scan += 2; + match++; // We check for insufficient lookahead only every 8th comparison; + // the 256th check will be made at strstart+258. + + do {} while (window[++scan] === window[++match] && window[++scan] === window[++match] && window[++scan] === window[++match] && window[++scan] === window[++match] && window[++scan] === window[++match] && window[++scan] === window[++match] && window[++scan] === window[++match] && window[++scan] === window[++match] && scan < strend); + + len = MAX_MATCH - (strend - scan); + scan = strend - MAX_MATCH; + + if (len > best_len) { + match_start = cur_match; + best_len = len; + if (len >= _nice_match) { break; } + scan_end1 = window[scan + best_len - 1]; + scan_end = window[scan + best_len]; + } + } while ((cur_match = prev[cur_match & wmask] & 0xffff) > limit && --chain_length !== 0); + + if (best_len <= lookahead) { return best_len; } + return lookahead; + } // Compress as much as possible from the input stream, return the current + // block state. + // This function does not perform lazy evaluation of matches and inserts + // new strings in the dictionary only for unmatched strings or for short + // matches. It is used only for the fast compression options. + + + function deflate_fast(flush) { + // short hash_head = 0; // head of the hash chain + var hash_head = 0; // head of the hash chain + + var bflush; // set if current block must be flushed + + while (true) { + // Make sure that we always have enough lookahead, except + // at the end of the input file. We need MAX_MATCH bytes + // for the next match, plus MIN_MATCH bytes to insert the + // string following the next match. + if (lookahead < MIN_LOOKAHEAD) { + fill_window(); + + if (lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) { + return NeedMore; + } + + if (lookahead === 0) { break; } // flush the current block + } // Insert the string window[strstart .. strstart+2] in the + // dictionary, and set hash_head to the head of the hash chain: + + + if (lookahead >= MIN_MATCH) { + ins_h = (ins_h << hash_shift ^ window[strstart + (MIN_MATCH - 1)] & 0xff) & hash_mask; // prev[strstart&w_mask]=hash_head=head[ins_h]; + + hash_head = head[ins_h] & 0xffff; + prev[strstart & w_mask] = head[ins_h]; + head[ins_h] = strstart; + } // Find the longest match, discarding those <= prev_length. + // At this point we have always match_length < MIN_MATCH + + + if (hash_head !== 0 && (strstart - hash_head & 0xffff) <= w_size - MIN_LOOKAHEAD) { + // To simplify the code, we prevent matches with the string + // of window index 0 (in particular we have to avoid a match + // of the string with itself at the start of the input file). + if (strategy !== Z_HUFFMAN_ONLY) { + match_length = longest_match(hash_head); + } // longest_match() sets match_start + + } + + if (match_length >= MIN_MATCH) { + // check_match(strstart, match_start, match_length); + bflush = _tr_tally(strstart - match_start, match_length - MIN_MATCH); + lookahead -= match_length; // Insert new strings in the hash table only if the match length + // is not too large. This saves time but degrades compression. + + if (match_length <= max_lazy_match && lookahead >= MIN_MATCH) { + match_length--; // string at strstart already in hash table + + do { + strstart++; + ins_h = (ins_h << hash_shift ^ window[strstart + (MIN_MATCH - 1)] & 0xff) & hash_mask; // prev[strstart&w_mask]=hash_head=head[ins_h]; + + hash_head = head[ins_h] & 0xffff; + prev[strstart & w_mask] = head[ins_h]; + head[ins_h] = strstart; // strstart never exceeds WSIZE-MAX_MATCH, so there are + // always MIN_MATCH bytes ahead. + } while (--match_length !== 0); + + strstart++; + } else { + strstart += match_length; + match_length = 0; + ins_h = window[strstart] & 0xff; + ins_h = (ins_h << hash_shift ^ window[strstart + 1] & 0xff) & hash_mask; // If lookahead < MIN_MATCH, ins_h is garbage, but it does + // not + // matter since it will be recomputed at next deflate call. + } + } else { + // No match, output a literal byte + bflush = _tr_tally(0, window[strstart] & 0xff); + lookahead--; + strstart++; + } + + if (bflush) { + flush_block_only(false); + if (strm.avail_out === 0) { return NeedMore; } + } + } + + flush_block_only(flush === Z_FINISH); + + if (strm.avail_out === 0) { + if (flush === Z_FINISH) { return FinishStarted; }else { return NeedMore; } + } + + return flush === Z_FINISH ? FinishDone : BlockDone; + } // Same as above, but achieves better compression. We use a lazy + // evaluation for matches: a match is finally adopted only if there is + // no better match at the next window position. + + + function deflate_slow(flush) { + // short hash_head = 0; // head of hash chain + var hash_head = 0; // head of hash chain + + var bflush; // set if current block must be flushed + + var max_insert; // Process the input block. + + while (true) { + // Make sure that we always have enough lookahead, except + // at the end of the input file. We need MAX_MATCH bytes + // for the next match, plus MIN_MATCH bytes to insert the + // string following the next match. + if (lookahead < MIN_LOOKAHEAD) { + fill_window(); + + if (lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) { + return NeedMore; + } + + if (lookahead === 0) { break; } // flush the current block + } // Insert the string window[strstart .. strstart+2] in the + // dictionary, and set hash_head to the head of the hash chain: + + + if (lookahead >= MIN_MATCH) { + ins_h = (ins_h << hash_shift ^ window[strstart + (MIN_MATCH - 1)] & 0xff) & hash_mask; // prev[strstart&w_mask]=hash_head=head[ins_h]; + + hash_head = head[ins_h] & 0xffff; + prev[strstart & w_mask] = head[ins_h]; + head[ins_h] = strstart; + } // Find the longest match, discarding those <= prev_length. + + + prev_length = match_length; + prev_match = match_start; + match_length = MIN_MATCH - 1; + + if (hash_head !== 0 && prev_length < max_lazy_match && (strstart - hash_head & 0xffff) <= w_size - MIN_LOOKAHEAD) { + // To simplify the code, we prevent matches with the string + // of window index 0 (in particular we have to avoid a match + // of the string with itself at the start of the input file). + if (strategy !== Z_HUFFMAN_ONLY) { + match_length = longest_match(hash_head); + } // longest_match() sets match_start + + + if (match_length <= 5 && (strategy === Z_FILTERED || match_length === MIN_MATCH && strstart - match_start > 4096)) { + // If prev_match is also MIN_MATCH, match_start is garbage + // but we will ignore the current match anyway. + match_length = MIN_MATCH - 1; + } + } // If there was a match at the previous step and the current + // match is not better, output the previous match: + + + if (prev_length >= MIN_MATCH && match_length <= prev_length) { + max_insert = strstart + lookahead - MIN_MATCH; // Do not insert strings in hash table beyond this. + // check_match(strstart-1, prev_match, prev_length); + + bflush = _tr_tally(strstart - 1 - prev_match, prev_length - MIN_MATCH); // Insert in hash table all strings up to the end of the match. + // strstart-1 and strstart are already inserted. If there is not + // enough lookahead, the last two strings are not inserted in + // the hash table. + + lookahead -= prev_length - 1; + prev_length -= 2; + + do { + if (++strstart <= max_insert) { + ins_h = (ins_h << hash_shift ^ window[strstart + (MIN_MATCH - 1)] & 0xff) & hash_mask; // prev[strstart&w_mask]=hash_head=head[ins_h]; + + hash_head = head[ins_h] & 0xffff; + prev[strstart & w_mask] = head[ins_h]; + head[ins_h] = strstart; + } + } while (--prev_length !== 0); + + match_available = 0; + match_length = MIN_MATCH - 1; + strstart++; + + if (bflush) { + flush_block_only(false); + if (strm.avail_out === 0) { return NeedMore; } + } + } else if (match_available !== 0) { + // If there was no match at the previous position, output a + // single literal. If there was a match but the current match + // is longer, truncate the previous match to a single literal. + bflush = _tr_tally(0, window[strstart - 1] & 0xff); + + if (bflush) { + flush_block_only(false); + } + + strstart++; + lookahead--; + if (strm.avail_out === 0) { return NeedMore; } + } else { + // There is no previous match to compare with, wait for + // the next step to decide. + match_available = 1; + strstart++; + lookahead--; + } + } + + if (match_available !== 0) { + bflush = _tr_tally(0, window[strstart - 1] & 0xff); + match_available = 0; + } + + flush_block_only(flush === Z_FINISH); + + if (strm.avail_out === 0) { + if (flush === Z_FINISH) { return FinishStarted; }else { return NeedMore; } + } + + return flush === Z_FINISH ? FinishDone : BlockDone; + } + + function deflateReset(strm) { + strm.total_in = strm.total_out = 0; + strm.msg = null; // + + that.pending = 0; + that.pending_out = 0; + status = BUSY_STATE; + last_flush = Z_NO_FLUSH; + tr_init(); + lm_init(); + return Z_OK; + } + + that.deflateInit = function (strm, _level, bits, _method, memLevel, _strategy) { + if (!_method) { _method = Z_DEFLATED; } + if (!memLevel) { memLevel = DEF_MEM_LEVEL; } + if (!_strategy) { _strategy = Z_DEFAULT_STRATEGY; } // byte[] my_version=ZLIB_VERSION; + // + // if (!version || version[0] !== my_version[0] + // || stream_size !== sizeof(z_stream)) { + // return Z_VERSION_ERROR; + // } + + strm.msg = null; + if (_level === Z_DEFAULT_COMPRESSION) { _level = 6; } + + if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || _method !== Z_DEFLATED || bits < 9 || bits > 15 || _level < 0 || _level > 9 || _strategy < 0 || _strategy > Z_HUFFMAN_ONLY) { + return Z_STREAM_ERROR; + } + + strm.dstate = that; + w_bits = bits; + w_size = 1 << w_bits; + w_mask = w_size - 1; + hash_bits = memLevel + 7; + hash_size = 1 << hash_bits; + hash_mask = hash_size - 1; + hash_shift = Math.floor((hash_bits + MIN_MATCH - 1) / MIN_MATCH); + window = new Uint8Array(w_size * 2); + prev = []; + head = []; + lit_bufsize = 1 << memLevel + 6; // 16K elements by default + // We overlay pending_buf and d_buf+l_buf. This works since the average + // output size for (length,distance) codes is <= 24 bits. + + that.pending_buf = new Uint8Array(lit_bufsize * 4); + pending_buf_size = lit_bufsize * 4; + d_buf = Math.floor(lit_bufsize / 2); + l_buf = (1 + 2) * lit_bufsize; + level = _level; + strategy = _strategy; + return deflateReset(strm); + }; + + that.deflateEnd = function () { + if (status !== INIT_STATE && status !== BUSY_STATE && status !== FINISH_STATE) { + return Z_STREAM_ERROR; + } // Deallocate in reverse order of allocations: + + + that.pending_buf = null; + head = null; + prev = null; + window = null; // free + + that.dstate = null; + return status === BUSY_STATE ? Z_DATA_ERROR : Z_OK; + }; + + that.deflateParams = function (strm, _level, _strategy) { + var err = Z_OK; + + if (_level === Z_DEFAULT_COMPRESSION) { + _level = 6; + } + + if (_level < 0 || _level > 9 || _strategy < 0 || _strategy > Z_HUFFMAN_ONLY) { + return Z_STREAM_ERROR; + } + + if (config_table[level].func !== config_table[_level].func && strm.total_in !== 0) { + // Flush the last buffer: + err = strm.deflate(Z_PARTIAL_FLUSH); + } + + if (level !== _level) { + level = _level; + max_lazy_match = config_table[level].max_lazy; + good_match = config_table[level].good_length; + nice_match = config_table[level].nice_length; + max_chain_length = config_table[level].max_chain; + } + + strategy = _strategy; + return err; + }; + + that.deflateSetDictionary = function (strm, dictionary, dictLength) { + var length = dictLength; + var n, + index = 0; + if (!dictionary || status !== INIT_STATE) { return Z_STREAM_ERROR; } + if (length < MIN_MATCH) { return Z_OK; } + + if (length > w_size - MIN_LOOKAHEAD) { + length = w_size - MIN_LOOKAHEAD; + index = dictLength - length; // use the tail of the dictionary + } + + window.set(dictionary.subarray(index, index + length), 0); + strstart = length; + block_start = length; // Insert all strings in the hash table (except for the last two bytes). + // s->lookahead stays null, so s->ins_h will be recomputed at the next + // call of fill_window. + + ins_h = window[0] & 0xff; + ins_h = (ins_h << hash_shift ^ window[1] & 0xff) & hash_mask; + + for (n = 0; n <= length - MIN_MATCH; n++) { + ins_h = (ins_h << hash_shift ^ window[n + (MIN_MATCH - 1)] & 0xff) & hash_mask; + prev[n & w_mask] = head[ins_h]; + head[ins_h] = n; + } + + return Z_OK; + }; + + that.deflate = function (_strm, flush) { + var i, header, level_flags, old_flush, bstate; + + if (flush > Z_FINISH || flush < 0) { + return Z_STREAM_ERROR; + } + + if (!_strm.next_out || !_strm.next_in && _strm.avail_in !== 0 || status === FINISH_STATE && flush !== Z_FINISH) { + _strm.msg = z_errmsg[Z_NEED_DICT - Z_STREAM_ERROR]; + return Z_STREAM_ERROR; + } + + if (_strm.avail_out === 0) { + _strm.msg = z_errmsg[Z_NEED_DICT - Z_BUF_ERROR]; + return Z_BUF_ERROR; + } + + strm = _strm; // just in case + + old_flush = last_flush; + last_flush = flush; // Write the zlib header + + if (status === INIT_STATE) { + header = Z_DEFLATED + (w_bits - 8 << 4) << 8; + level_flags = (level - 1 & 0xff) >> 1; + if (level_flags > 3) { level_flags = 3; } + header |= level_flags << 6; + if (strstart !== 0) { header |= PRESET_DICT; } + header += 31 - header % 31; + status = BUSY_STATE; + putShortMSB(header); + } // Flush as much pending output as possible + + + if (that.pending !== 0) { + strm.flush_pending(); + + if (strm.avail_out === 0) { + // console.log(" avail_out==0"); + // Since avail_out is 0, deflate will be called again with + // more output space, but possibly with both pending and + // avail_in equal to zero. There won't be anything to do, + // but this is not an error situation so make sure we + // return OK instead of BUF_ERROR at next call of deflate: + last_flush = -1; + return Z_OK; + } // Make sure there is something to do and avoid duplicate + // consecutive + // flushes. For repeated and useless calls with Z_FINISH, we keep + // returning Z_STREAM_END instead of Z_BUFF_ERROR. + + } else if (strm.avail_in === 0 && flush <= old_flush && flush !== Z_FINISH) { + strm.msg = z_errmsg[Z_NEED_DICT - Z_BUF_ERROR]; + return Z_BUF_ERROR; + } // User must not provide more input after the first FINISH: + + + if (status === FINISH_STATE && strm.avail_in !== 0) { + _strm.msg = z_errmsg[Z_NEED_DICT - Z_BUF_ERROR]; + return Z_BUF_ERROR; + } // Start a new block or continue the current one. + + + if (strm.avail_in !== 0 || lookahead !== 0 || flush !== Z_NO_FLUSH && status !== FINISH_STATE) { + bstate = -1; + + switch (config_table[level].func) { + case STORED: + bstate = deflate_stored(flush); + break; + + case FAST: + bstate = deflate_fast(flush); + break; + + case SLOW: + bstate = deflate_slow(flush); + break; + + default: + } + + if (bstate === FinishStarted || bstate === FinishDone) { + status = FINISH_STATE; + } + + if (bstate === NeedMore || bstate === FinishStarted) { + if (strm.avail_out === 0) { + last_flush = -1; // avoid BUF_ERROR next call, see above + } + + return Z_OK; // If flush !== Z_NO_FLUSH && avail_out === 0, the next call + // of deflate should use the same flush parameter to make sure + // that the flush is complete. So we don't have to output an + // empty block here, this will be done at next call. This also + // ensures that for a very small output buffer, we emit at most + // one empty block. + } + + if (bstate === BlockDone) { + if (flush === Z_PARTIAL_FLUSH) { + _tr_align(); + } else { + // FULL_FLUSH or SYNC_FLUSH + _tr_stored_block(0, 0, false); // For a full flush, this empty block will be recognized + // as a special marker by inflate_sync(). + + + if (flush === Z_FULL_FLUSH) { + // state.head[s.hash_size-1]=0; + for (i = 0; i < hash_size + /*-1*/ + ; i++) { + // forget history + head[i] = 0; + } + } + } + + strm.flush_pending(); + + if (strm.avail_out === 0) { + last_flush = -1; // avoid BUF_ERROR at next call, see above + + return Z_OK; + } + } + } + + if (flush !== Z_FINISH) { return Z_OK; } + return Z_STREAM_END; + }; + } // ZStream + + + function ZStream() { + var that = this; + that.next_in_index = 0; + that.next_out_index = 0; // that.next_in; // next input byte + + that.avail_in = 0; // number of bytes available at next_in + + that.total_in = 0; // total nb of input bytes read so far + // that.next_out; // next output byte should be put there + + that.avail_out = 0; // remaining free space at next_out + + that.total_out = 0; // total nb of bytes output so far + // that.msg; + // that.dstate; + } + + ZStream.prototype = { + deflateInit: function deflateInit(level, bits) { + var that = this; + that.dstate = new Deflate(); + if (!bits) { bits = MAX_BITS; } + return that.dstate.deflateInit(that, level, bits); + }, + deflate: function deflate(flush) { + var that = this; + + if (!that.dstate) { + return Z_STREAM_ERROR; + } + + return that.dstate.deflate(that, flush); + }, + deflateEnd: function deflateEnd() { + var that = this; + if (!that.dstate) { return Z_STREAM_ERROR; } + var ret = that.dstate.deflateEnd(); + that.dstate = null; + return ret; + }, + deflateParams: function deflateParams(level, strategy) { + var that = this; + if (!that.dstate) { return Z_STREAM_ERROR; } + return that.dstate.deflateParams(that, level, strategy); + }, + deflateSetDictionary: function deflateSetDictionary(dictionary, dictLength) { + var that = this; + if (!that.dstate) { return Z_STREAM_ERROR; } + return that.dstate.deflateSetDictionary(that, dictionary, dictLength); + }, + // Read a new buffer from the current input stream, update the + // total number of bytes read. All deflate() input goes through + // this function so some applications may wish to modify it to avoid + // allocating a large strm->next_in buffer and copying from it. + // (See also flush_pending()). + read_buf: function read_buf(buf, start, size) { + var that = this; + var len = that.avail_in; + if (len > size) { len = size; } + if (len === 0) { return 0; } + that.avail_in -= len; + buf.set(that.next_in.subarray(that.next_in_index, that.next_in_index + len), start); + that.next_in_index += len; + that.total_in += len; + return len; + }, + // Flush as much pending output as possible. All deflate() output goes + // through this function so some applications may wish to modify it + // to avoid allocating a large strm->next_out buffer and copying into it. + // (See also read_buf()). + flush_pending: function flush_pending() { + var that = this; + var len = that.dstate.pending; + if (len > that.avail_out) { len = that.avail_out; } + if (len === 0) { return; } // if (that.dstate.pending_buf.length <= that.dstate.pending_out || that.next_out.length <= that.next_out_index + // || that.dstate.pending_buf.length < (that.dstate.pending_out + len) || that.next_out.length < (that.next_out_index + + // len)) { + // console.log(that.dstate.pending_buf.length + ", " + that.dstate.pending_out + ", " + that.next_out.length + ", " + + // that.next_out_index + ", " + len); + // console.log("avail_out=" + that.avail_out); + // } + + that.next_out.set(that.dstate.pending_buf.subarray(that.dstate.pending_out, that.dstate.pending_out + len), that.next_out_index); + that.next_out_index += len; + that.dstate.pending_out += len; + that.total_out += len; + that.avail_out -= len; + that.dstate.pending -= len; + + if (that.dstate.pending === 0) { + that.dstate.pending_out = 0; + } + } + }; // Deflater + + function Deflater(options) { + var that = this; + var z = new ZStream(); + var bufsize = 512; + var flush = Z_NO_FLUSH; + var buf = new Uint8Array(bufsize); + var level = options ? options.level : Z_DEFAULT_COMPRESSION; + if (typeof level === "undefined") { level = Z_DEFAULT_COMPRESSION; } + z.deflateInit(level); + z.next_out = buf; + + that.append = function (data, onprogress) { + var err, + buffers = [], + lastIndex = 0, + bufferIndex = 0, + bufferSize = 0, + array; + if (!data.length) { return; } + z.next_in_index = 0; + z.next_in = data; + z.avail_in = data.length; + + do { + z.next_out_index = 0; + z.avail_out = bufsize; + err = z.deflate(flush); + if (err !== Z_OK) { throw new Error("deflating: " + z.msg); } + if (z.next_out_index) { if (z.next_out_index === bufsize) { buffers.push(new Uint8Array(buf)); }else { buffers.push(new Uint8Array(buf.subarray(0, z.next_out_index))); } } + bufferSize += z.next_out_index; + + if (onprogress && z.next_in_index > 0 && z.next_in_index !== lastIndex) { + onprogress(z.next_in_index); + lastIndex = z.next_in_index; + } + } while (z.avail_in > 0 || z.avail_out === 0); + + array = new Uint8Array(bufferSize); + buffers.forEach(function (chunk) { + array.set(chunk, bufferIndex); + bufferIndex += chunk.length; + }); + return array; + }; + + that.flush = function () { + var err, + buffers = [], + bufferIndex = 0, + bufferSize = 0, + array; + + do { + z.next_out_index = 0; + z.avail_out = bufsize; + err = z.deflate(Z_FINISH); + if (err !== Z_STREAM_END && err !== Z_OK) { throw new Error("deflating: " + z.msg); } + if (bufsize - z.avail_out > 0) { buffers.push(new Uint8Array(buf.subarray(0, z.next_out_index))); } + bufferSize += z.next_out_index; + } while (z.avail_in > 0 || z.avail_out === 0); + + z.deflateEnd(); + array = new Uint8Array(bufferSize); + buffers.forEach(function (chunk) { + array.set(chunk, bufferIndex); + bufferIndex += chunk.length; + }); + return array; + }; + } // 'zip' may not be defined in z-worker and some tests + + + var env = global.zip || global; + env.Deflater = env._jzlib_Deflater = Deflater; +})(typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function("return this")()); // `self` is undefined in Firefox for Android content script context +// while `this` is nsIContentFrameMessageManager +// with an attribute `content` that corresponds to the window + +/** + * A class to parse color values + * @author Stoyan Stefanov + * {@link http://www.phpied.com/rgb-color-parser-in-javascript/} + * @license Use it if you like it + */ +(function (global) { + + function RGBColor(color_string) { + color_string = color_string || ""; + this.ok = false; // strip any leading # + + if (color_string.charAt(0) == "#") { + // remove # if any + color_string = color_string.substr(1, 6); + } + + color_string = color_string.replace(/ /g, ""); + color_string = color_string.toLowerCase(); + var channels; // before getting into regexps, try simple matches + // and overwrite the input + + var simple_colors = { + aliceblue: "f0f8ff", + antiquewhite: "faebd7", + aqua: "00ffff", + aquamarine: "7fffd4", + azure: "f0ffff", + beige: "f5f5dc", + bisque: "ffe4c4", + black: "000000", + blanchedalmond: "ffebcd", + blue: "0000ff", + blueviolet: "8a2be2", + brown: "a52a2a", + burlywood: "deb887", + cadetblue: "5f9ea0", + chartreuse: "7fff00", + chocolate: "d2691e", + coral: "ff7f50", + cornflowerblue: "6495ed", + cornsilk: "fff8dc", + crimson: "dc143c", + cyan: "00ffff", + darkblue: "00008b", + darkcyan: "008b8b", + darkgoldenrod: "b8860b", + darkgray: "a9a9a9", + darkgreen: "006400", + darkkhaki: "bdb76b", + darkmagenta: "8b008b", + darkolivegreen: "556b2f", + darkorange: "ff8c00", + darkorchid: "9932cc", + darkred: "8b0000", + darksalmon: "e9967a", + darkseagreen: "8fbc8f", + darkslateblue: "483d8b", + darkslategray: "2f4f4f", + darkturquoise: "00ced1", + darkviolet: "9400d3", + deeppink: "ff1493", + deepskyblue: "00bfff", + dimgray: "696969", + dodgerblue: "1e90ff", + feldspar: "d19275", + firebrick: "b22222", + floralwhite: "fffaf0", + forestgreen: "228b22", + fuchsia: "ff00ff", + gainsboro: "dcdcdc", + ghostwhite: "f8f8ff", + gold: "ffd700", + goldenrod: "daa520", + gray: "808080", + green: "008000", + greenyellow: "adff2f", + honeydew: "f0fff0", + hotpink: "ff69b4", + indianred: "cd5c5c", + indigo: "4b0082", + ivory: "fffff0", + khaki: "f0e68c", + lavender: "e6e6fa", + lavenderblush: "fff0f5", + lawngreen: "7cfc00", + lemonchiffon: "fffacd", + lightblue: "add8e6", + lightcoral: "f08080", + lightcyan: "e0ffff", + lightgoldenrodyellow: "fafad2", + lightgrey: "d3d3d3", + lightgreen: "90ee90", + lightpink: "ffb6c1", + lightsalmon: "ffa07a", + lightseagreen: "20b2aa", + lightskyblue: "87cefa", + lightslateblue: "8470ff", + lightslategray: "778899", + lightsteelblue: "b0c4de", + lightyellow: "ffffe0", + lime: "00ff00", + limegreen: "32cd32", + linen: "faf0e6", + magenta: "ff00ff", + maroon: "800000", + mediumaquamarine: "66cdaa", + mediumblue: "0000cd", + mediumorchid: "ba55d3", + mediumpurple: "9370d8", + mediumseagreen: "3cb371", + mediumslateblue: "7b68ee", + mediumspringgreen: "00fa9a", + mediumturquoise: "48d1cc", + mediumvioletred: "c71585", + midnightblue: "191970", + mintcream: "f5fffa", + mistyrose: "ffe4e1", + moccasin: "ffe4b5", + navajowhite: "ffdead", + navy: "000080", + oldlace: "fdf5e6", + olive: "808000", + olivedrab: "6b8e23", + orange: "ffa500", + orangered: "ff4500", + orchid: "da70d6", + palegoldenrod: "eee8aa", + palegreen: "98fb98", + paleturquoise: "afeeee", + palevioletred: "d87093", + papayawhip: "ffefd5", + peachpuff: "ffdab9", + peru: "cd853f", + pink: "ffc0cb", + plum: "dda0dd", + powderblue: "b0e0e6", + purple: "800080", + red: "ff0000", + rosybrown: "bc8f8f", + royalblue: "4169e1", + saddlebrown: "8b4513", + salmon: "fa8072", + sandybrown: "f4a460", + seagreen: "2e8b57", + seashell: "fff5ee", + sienna: "a0522d", + silver: "c0c0c0", + skyblue: "87ceeb", + slateblue: "6a5acd", + slategray: "708090", + snow: "fffafa", + springgreen: "00ff7f", + steelblue: "4682b4", + tan: "d2b48c", + teal: "008080", + thistle: "d8bfd8", + tomato: "ff6347", + turquoise: "40e0d0", + violet: "ee82ee", + violetred: "d02090", + wheat: "f5deb3", + white: "ffffff", + whitesmoke: "f5f5f5", + yellow: "ffff00", + yellowgreen: "9acd32" + }; + color_string = simple_colors[color_string] || color_string; // array of color definition objects + + var color_defs = [{ + re: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/, + example: ["rgb(123, 234, 45)", "rgb(255,234,245)"], + process: function process(bits) { + return [parseInt(bits[1]), parseInt(bits[2]), parseInt(bits[3])]; + } + }, { + re: /^(\w{2})(\w{2})(\w{2})$/, + example: ["#00ff00", "336699"], + process: function process(bits) { + return [parseInt(bits[1], 16), parseInt(bits[2], 16), parseInt(bits[3], 16)]; + } + }, { + re: /^(\w{1})(\w{1})(\w{1})$/, + example: ["#fb0", "f0f"], + process: function process(bits) { + return [parseInt(bits[1] + bits[1], 16), parseInt(bits[2] + bits[2], 16), parseInt(bits[3] + bits[3], 16)]; + } + }]; // search through the definitions to find a match + + for (var i = 0; i < color_defs.length; i++) { + var re = color_defs[i].re; + var processor = color_defs[i].process; + var bits = re.exec(color_string); + + if (bits) { + channels = processor(bits); + this.r = channels[0]; + this.g = channels[1]; + this.b = channels[2]; + this.ok = true; + } + } // validate/cleanup values + + + this.r = this.r < 0 || isNaN(this.r) ? 0 : this.r > 255 ? 255 : this.r; + this.g = this.g < 0 || isNaN(this.g) ? 0 : this.g > 255 ? 255 : this.g; + this.b = this.b < 0 || isNaN(this.b) ? 0 : this.b > 255 ? 255 : this.b; // some getters + + this.toRGB = function () { + return "rgb(" + this.r + ", " + this.g + ", " + this.b + ")"; + }; + + this.toHex = function () { + var r = this.r.toString(16); + var g = this.g.toString(16); + var b = this.b.toString(16); + if (r.length == 1) { r = "0" + r; } + if (g.length == 1) { g = "0" + g; } + if (b.length == 1) { b = "0" + b; } + return "#" + r + g + b; + }; + } + + global.RGBColor = RGBColor; +})(typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function("return this")()); // `self` is undefined in Firefox for Android content script context +// while `this` is nsIContentFrameMessageManager +// with an attribute `content` that corresponds to the window + +/* eslint-disable no-control-regex */ + +/* global jsPDF */ + +/************************************************ + * Title : custom font * + * Start Data : 2017. 01. 22. * + * Comment : TEXT API * + ************************************************/ + +/****************************** + * jsPDF extension API Design * + * ****************************/ +(function (jsPDF) { + + jsPDF.API.TTFFont = function () { + /************************************************************************/ + + /* function : open */ + + /* comment : Decode the encoded ttf content and create a TTFFont object. */ + + /************************************************************************/ + TTFFont.open = function (file) { + return new TTFFont(file); + }; + /***************************************************************/ + + /* function : TTFFont gernerator */ + + /* comment : Decode TTF contents are parsed, Data, */ + + /* Subset object is created, and registerTTF function is called.*/ + + /***************************************************************/ + + + function TTFFont(rawData) { + var data; + this.rawData = rawData; + data = this.contents = new Data(rawData); + this.contents.pos = 4; + + if (data.readString(4) === 'ttcf') { + throw new Error("TTCF not supported."); + } else { + data.pos = 0; + this.parse(); + this.subset = new Subset(this); + this.registerTTF(); + } + } + /********************************************************/ + + /* function : parse */ + + /* comment : TTF Parses the file contents by each table.*/ + + /********************************************************/ + + + TTFFont.prototype.parse = function () { + this.directory = new Directory(this.contents); + this.head = new HeadTable(this); + this.name = new NameTable(this); + this.cmap = new CmapTable(this); + this.toUnicode = {}; + this.hhea = new HheaTable(this); + this.maxp = new MaxpTable(this); + this.hmtx = new HmtxTable(this); + this.post = new PostTable(this); + this.os2 = new OS2Table(this); + this.loca = new LocaTable(this); + this.glyf = new GlyfTable(this); + this.ascender = this.os2.exists && this.os2.ascender || this.hhea.ascender; + this.decender = this.os2.exists && this.os2.decender || this.hhea.decender; + this.lineGap = this.os2.exists && this.os2.lineGap || this.hhea.lineGap; + return this.bbox = [this.head.xMin, this.head.yMin, this.head.xMax, this.head.yMax]; + }; + /***************************************************************/ + + /* function : registerTTF */ + + /* comment : Get the value to assign pdf font descriptors. */ + + /***************************************************************/ + + + TTFFont.prototype.registerTTF = function () { + var e, hi, low, raw, _ref; + + this.scaleFactor = 1000.0 / this.head.unitsPerEm; + + this.bbox = function () { + var _i, _len, _ref, _results; + + _ref = this.bbox; + _results = []; + + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + e = _ref[_i]; + + _results.push(Math.round(e * this.scaleFactor)); + } + + return _results; + }.call(this); + + this.stemV = 0; + + if (this.post.exists) { + raw = this.post.italic_angle; + hi = raw >> 16; + low = raw & 0xFF; + + if ((hi & 0x8000) !== 0) { + hi = -((hi ^ 0xFFFF) + 1); + } + + this.italicAngle = +("" + hi + "." + low); + } else { + this.italicAngle = 0; + } + + this.ascender = Math.round(this.ascender * this.scaleFactor); + this.decender = Math.round(this.decender * this.scaleFactor); + this.lineGap = Math.round(this.lineGap * this.scaleFactor); + this.capHeight = this.os2.exists && this.os2.capHeight || this.ascender; + this.xHeight = this.os2.exists && this.os2.xHeight || 0; + this.familyClass = (this.os2.exists && this.os2.familyClass || 0) >> 8; + this.isSerif = (_ref = this.familyClass) === 1 || _ref === 2 || _ref === 3 || _ref === 4 || _ref === 5 || _ref === 7; + this.isScript = this.familyClass === 10; + this.flags = 0; + + if (this.post.isFixedPitch) { + this.flags |= 1 << 0; + } + + if (this.isSerif) { + this.flags |= 1 << 1; + } + + if (this.isScript) { + this.flags |= 1 << 3; + } + + if (this.italicAngle !== 0) { + this.flags |= 1 << 6; + } + + this.flags |= 1 << 5; + + if (!this.cmap.unicode) { + throw new Error('No unicode cmap for font'); + } + }; + + TTFFont.prototype.characterToGlyph = function (character) { + var _ref; + + return ((_ref = this.cmap.unicode) != null ? _ref.codeMap[character] : void 0) || 0; + }; + + TTFFont.prototype.widthOfGlyph = function (glyph) { + var scale; + scale = 1000.0 / this.head.unitsPerEm; + return this.hmtx.forGlyph(glyph).advance * scale; + }; + + TTFFont.prototype.widthOfString = function (string, size, charSpace) { + var charCode, i, scale, width, _ref; + + string = '' + string; + width = 0; + + for (i = 0, _ref = string.length; 0 <= _ref ? i < _ref : i > _ref; i = 0 <= _ref ? ++i : --i) { + charCode = string.charCodeAt(i); + width += this.widthOfGlyph(this.characterToGlyph(charCode)) + charSpace * (1000 / size) || 0; + } + + scale = size / 1000; + return width * scale; + }; + + TTFFont.prototype.lineHeight = function (size, includeGap) { + var gap; + + if (includeGap == null) { + includeGap = false; + } + + gap = includeGap ? this.lineGap : 0; + return (this.ascender + gap - this.decender) / 1000 * size; + }; + + return TTFFont; + }(); + /************************************************************************************************/ + + /* function : Data */ + + /* comment : The ttf data decoded and stored in an array is read and written to the Data object.*/ + + /************************************************************************************************/ + + + var Data = function () { + function Data(data) { + this.data = data != null ? data : []; + this.pos = 0; + this.length = this.data.length; + } + + Data.prototype.readByte = function () { + return this.data[this.pos++]; + }; + + Data.prototype.writeByte = function (_byte) { + return this.data[this.pos++] = _byte; + }; + + Data.prototype.readUInt32 = function () { + var b1, b2, b3, b4; + b1 = this.readByte() * 0x1000000; + b2 = this.readByte() << 16; + b3 = this.readByte() << 8; + b4 = this.readByte(); + return b1 + b2 + b3 + b4; + }; + + Data.prototype.writeUInt32 = function (val) { + this.writeByte(val >>> 24 & 0xff); + this.writeByte(val >> 16 & 0xff); + this.writeByte(val >> 8 & 0xff); + return this.writeByte(val & 0xff); + }; + + Data.prototype.readInt32 = function () { + var _int; + + _int = this.readUInt32(); + + if (_int >= 0x80000000) { + return _int - 0x100000000; + } else { + return _int; + } + }; + + Data.prototype.writeInt32 = function (val) { + if (val < 0) { + val += 0x100000000; + } + + return this.writeUInt32(val); + }; + + Data.prototype.readUInt16 = function () { + var b1, b2; + b1 = this.readByte() << 8; + b2 = this.readByte(); + return b1 | b2; + }; + + Data.prototype.writeUInt16 = function (val) { + this.writeByte(val >> 8 & 0xff); + return this.writeByte(val & 0xff); + }; + + Data.prototype.readInt16 = function () { + var _int2; + + _int2 = this.readUInt16(); + + if (_int2 >= 0x8000) { + return _int2 - 0x10000; + } else { + return _int2; + } + }; + + Data.prototype.writeInt16 = function (val) { + if (val < 0) { + val += 0x10000; + } + + return this.writeUInt16(val); + }; + + Data.prototype.readString = function (length) { + var i, ret; + ret = []; + + for (i = 0; 0 <= length ? i < length : i > length; i = 0 <= length ? ++i : --i) { + ret[i] = String.fromCharCode(this.readByte()); + } + + return ret.join(""); + }; + + Data.prototype.writeString = function (val) { + var i, _ref, _results; + + _results = []; + + for (i = 0, _ref = val.length; 0 <= _ref ? i < _ref : i > _ref; i = 0 <= _ref ? ++i : --i) { + _results.push(this.writeByte(val.charCodeAt(i))); + } + + return _results; + }; + /*Data.prototype.stringAt = function (pos, length) { + this.pos = pos; + return this.readString(length); + };*/ + + + Data.prototype.readShort = function () { + return this.readInt16(); + }; + + Data.prototype.writeShort = function (val) { + return this.writeInt16(val); + }; + + Data.prototype.readLongLong = function () { + var b1, b2, b3, b4, b5, b6, b7, b8; + b1 = this.readByte(); + b2 = this.readByte(); + b3 = this.readByte(); + b4 = this.readByte(); + b5 = this.readByte(); + b6 = this.readByte(); + b7 = this.readByte(); + b8 = this.readByte(); + + if (b1 & 0x80) { + return ((b1 ^ 0xff) * 0x100000000000000 + (b2 ^ 0xff) * 0x1000000000000 + (b3 ^ 0xff) * 0x10000000000 + (b4 ^ 0xff) * 0x100000000 + (b5 ^ 0xff) * 0x1000000 + (b6 ^ 0xff) * 0x10000 + (b7 ^ 0xff) * 0x100 + (b8 ^ 0xff) + 1) * -1; + } + + return b1 * 0x100000000000000 + b2 * 0x1000000000000 + b3 * 0x10000000000 + b4 * 0x100000000 + b5 * 0x1000000 + b6 * 0x10000 + b7 * 0x100 + b8; + }; + + Data.prototype.writeLongLong = function (val) { + var high, low; + high = Math.floor(val / 0x100000000); + low = val & 0xffffffff; + this.writeByte(high >> 24 & 0xff); + this.writeByte(high >> 16 & 0xff); + this.writeByte(high >> 8 & 0xff); + this.writeByte(high & 0xff); + this.writeByte(low >> 24 & 0xff); + this.writeByte(low >> 16 & 0xff); + this.writeByte(low >> 8 & 0xff); + return this.writeByte(low & 0xff); + }; + + Data.prototype.readInt = function () { + return this.readInt32(); + }; + + Data.prototype.writeInt = function (val) { + return this.writeInt32(val); + }; + /*Data.prototype.slice = function (start, end) { + return this.data.slice(start, end); + };*/ + + + Data.prototype.read = function (bytes) { + var buf, i; + buf = []; + + for (i = 0; 0 <= bytes ? i < bytes : i > bytes; i = 0 <= bytes ? ++i : --i) { + buf.push(this.readByte()); + } + + return buf; + }; + + Data.prototype.write = function (bytes) { + var _byte2, i, _len, _results; + + _results = []; + + for (i = 0, _len = bytes.length; i < _len; i++) { + _byte2 = bytes[i]; + + _results.push(this.writeByte(_byte2)); + } + + return _results; + }; + + return Data; + }(); + + var Directory = function () { + var checksum; + /*****************************************************************************************************/ + + /* function : Directory generator */ + + /* comment : Initialize the offset, tag, length, and checksum for each table for the font to be used.*/ + + /*****************************************************************************************************/ + + function Directory(data) { + var entry, i, _ref; + + this.scalarType = data.readInt(); + this.tableCount = data.readShort(); + this.searchRange = data.readShort(); + this.entrySelector = data.readShort(); + this.rangeShift = data.readShort(); + this.tables = {}; + + for (i = 0, _ref = this.tableCount; 0 <= _ref ? i < _ref : i > _ref; i = 0 <= _ref ? ++i : --i) { + entry = { + tag: data.readString(4), + checksum: data.readInt(), + offset: data.readInt(), + length: data.readInt() + }; + this.tables[entry.tag] = entry; + } + } + /********************************************************************************************************/ + + /* function : encode */ + + /* comment : It encodes and stores the font table object and information used for the directory object. */ + + /********************************************************************************************************/ + + + Directory.prototype.encode = function (tables) { + var adjustment, directory, directoryLength, entrySelector, headOffset, log2, offset, rangeShift, searchRange, sum, table, tableCount, tableData, tag; + tableCount = Object.keys(tables).length; + log2 = Math.log(2); + searchRange = Math.floor(Math.log(tableCount) / log2) * 16; + entrySelector = Math.floor(searchRange / log2); + rangeShift = tableCount * 16 - searchRange; + directory = new Data(); + directory.writeInt(this.scalarType); + directory.writeShort(tableCount); + directory.writeShort(searchRange); + directory.writeShort(entrySelector); + directory.writeShort(rangeShift); + directoryLength = tableCount * 16; + offset = directory.pos + directoryLength; + headOffset = null; + tableData = []; + + for (tag in tables) { + table = tables[tag]; + directory.writeString(tag); + directory.writeInt(checksum(table)); + directory.writeInt(offset); + directory.writeInt(table.length); + tableData = tableData.concat(table); + + if (tag === "head") { + headOffset = offset; + } + + offset += table.length; + + while (offset % 4) { + tableData.push(0); + offset++; + } + } + + directory.write(tableData); + sum = checksum(directory.data); + adjustment = 0xb1b0afba - sum; + directory.pos = headOffset + 8; + directory.writeUInt32(adjustment); + return directory.data; + }; + /***************************************************************/ + + /* function : checksum */ + + /* comment : Duplicate the table for the tag. */ + + /***************************************************************/ + + + checksum = function checksum(data) { + var i, sum, tmp, _ref; + + data = __slice.call(data); + + while (data.length % 4) { + data.push(0); + } + + tmp = new Data(data); + sum = 0; + + for (i = 0, _ref = data.length; i < _ref; i = i += 4) { + sum += tmp.readUInt32(); + } + + return sum & 0xffffffff; + }; + + return Directory; + }(); + + var Table, + __hasProp = {}.hasOwnProperty, + __extends = function __extends(child, parent) { + for (var key in parent) { + if (__hasProp.call(parent, key)) { child[key] = parent[key]; } + } + + function ctor() { + this.constructor = child; + } + + ctor.prototype = parent.prototype; + child.prototype = new ctor(); + child.__super__ = parent.prototype; + return child; + }; + /***************************************************************/ + + /* function : Table */ + + /* comment : Save info for each table, and parse the table. */ + + /***************************************************************/ + + + Table = function () { + function Table(file) { + var info; + this.file = file; + info = this.file.directory.tables[this.tag]; + this.exists = !!info; + + if (info) { + this.offset = info.offset, this.length = info.length; + this.parse(this.file.contents); + } + } + + Table.prototype.parse = function () {}; + + Table.prototype.encode = function () {}; + + Table.prototype.raw = function () { + if (!this.exists) { + return null; + } + + this.file.contents.pos = this.offset; + return this.file.contents.read(this.length); + }; + + return Table; + }(); + + var HeadTable = function (_super) { + __extends(HeadTable, _super); + + function HeadTable() { + return HeadTable.__super__.constructor.apply(this, arguments); + } + + HeadTable.prototype.tag = "head"; + + HeadTable.prototype.parse = function (data) { + data.pos = this.offset; + this.version = data.readInt(); + this.revision = data.readInt(); + this.checkSumAdjustment = data.readInt(); + this.magicNumber = data.readInt(); + this.flags = data.readShort(); + this.unitsPerEm = data.readShort(); + this.created = data.readLongLong(); + this.modified = data.readLongLong(); + this.xMin = data.readShort(); + this.yMin = data.readShort(); + this.xMax = data.readShort(); + this.yMax = data.readShort(); + this.macStyle = data.readShort(); + this.lowestRecPPEM = data.readShort(); + this.fontDirectionHint = data.readShort(); + this.indexToLocFormat = data.readShort(); + return this.glyphDataFormat = data.readShort(); + }; + + HeadTable.prototype.encode = function (indexToLocFormat) { + var table; + table = new Data(); + table.writeInt(this.version); + table.writeInt(this.revision); + table.writeInt(this.checkSumAdjustment); + table.writeInt(this.magicNumber); + table.writeShort(this.flags); + table.writeShort(this.unitsPerEm); + table.writeLongLong(this.created); + table.writeLongLong(this.modified); + table.writeShort(this.xMin); + table.writeShort(this.yMin); + table.writeShort(this.xMax); + table.writeShort(this.yMax); + table.writeShort(this.macStyle); + table.writeShort(this.lowestRecPPEM); + table.writeShort(this.fontDirectionHint); + table.writeShort(indexToLocFormat); + table.writeShort(this.glyphDataFormat); + return table.data; + }; + + return HeadTable; + }(Table); + /************************************************************************************/ + + /* function : CmapEntry */ + + /* comment : Cmap Initializes and encodes object information (required by pdf spec).*/ + + /************************************************************************************/ + + + var CmapEntry = function () { + function CmapEntry(data, offset) { + var code, count, endCode, glyphId, glyphIds, i, idDelta, idRangeOffset, index, saveOffset, segCount, segCountX2, start, startCode, tail, _j, _k, _len; + + this.platformID = data.readUInt16(); + this.encodingID = data.readShort(); + this.offset = offset + data.readInt(); + saveOffset = data.pos; + data.pos = this.offset; + this.format = data.readUInt16(); + this.length = data.readUInt16(); + this.language = data.readUInt16(); + this.isUnicode = this.platformID === 3 && this.encodingID === 1 && this.format === 4 || this.platformID === 0 && this.format === 4; + this.codeMap = {}; + + switch (this.format) { + case 0: + for (i = 0; i < 256; ++i) { + this.codeMap[i] = data.readByte(); + } + + break; + + case 4: + segCountX2 = data.readUInt16(); + segCount = segCountX2 / 2; + data.pos += 6; + + endCode = function () { + var _j, _results; + + _results = []; + + for (i = _j = 0; 0 <= segCount ? _j < segCount : _j > segCount; i = 0 <= segCount ? ++_j : --_j) { + _results.push(data.readUInt16()); + } + + return _results; + }(); + + data.pos += 2; + + startCode = function () { + var _j, _results; + + _results = []; + + for (i = _j = 0; 0 <= segCount ? _j < segCount : _j > segCount; i = 0 <= segCount ? ++_j : --_j) { + _results.push(data.readUInt16()); + } + + return _results; + }(); + + idDelta = function () { + var _j, _results; + + _results = []; + + for (i = _j = 0; 0 <= segCount ? _j < segCount : _j > segCount; i = 0 <= segCount ? ++_j : --_j) { + _results.push(data.readUInt16()); + } + + return _results; + }(); + + idRangeOffset = function () { + var _j, _results; + + _results = []; + + for (i = _j = 0; 0 <= segCount ? _j < segCount : _j > segCount; i = 0 <= segCount ? ++_j : --_j) { + _results.push(data.readUInt16()); + } + + return _results; + }(); + + count = (this.length - data.pos + this.offset) / 2; + + glyphIds = function () { + var _j, _results; + + _results = []; + + for (i = _j = 0; 0 <= count ? _j < count : _j > count; i = 0 <= count ? ++_j : --_j) { + _results.push(data.readUInt16()); + } + + return _results; + }(); + + for (i = _j = 0, _len = endCode.length; _j < _len; i = ++_j) { + tail = endCode[i]; + start = startCode[i]; + + for (code = _k = start; start <= tail ? _k <= tail : _k >= tail; code = start <= tail ? ++_k : --_k) { + if (idRangeOffset[i] === 0) { + glyphId = code + idDelta[i]; + } else { + index = idRangeOffset[i] / 2 + (code - start) - (segCount - i); + glyphId = glyphIds[index] || 0; + + if (glyphId !== 0) { + glyphId += idDelta[i]; + } + } + + this.codeMap[code] = glyphId & 0xffff; + } + } + + } + + data.pos = saveOffset; + } + + CmapEntry.encode = function (charmap, encoding) { + var charMap, code, codeMap, codes, delta, deltas, diff, endCode, endCodes, entrySelector, glyphIDs, i, id, indexes, last, map, nextID, offset, old, rangeOffsets, rangeShift, searchRange, segCount, segCountX2, startCode, startCodes, startGlyph, subtable, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _len6, _len7, _m, _n, _name, _o, _p, _q; + + subtable = new Data(); + codes = Object.keys(charmap).sort(function (a, b) { + return a - b; + }); + + switch (encoding) { + case "macroman": + id = 0; + + indexes = function () { + var _results = []; + + for (i = 0; i < 256; ++i) { + _results.push(0); + } + + return _results; + }(); + + map = { + 0: 0 + }; + codeMap = {}; + + for (_i = 0, _len = codes.length; _i < _len; _i++) { + code = codes[_i]; + + if (map[_name = charmap[code]] == null) { + map[_name] = ++id; + } + + codeMap[code] = { + old: charmap[code], + "new": map[charmap[code]] + }; + indexes[code] = map[charmap[code]]; + } + + subtable.writeUInt16(1); + subtable.writeUInt16(0); + subtable.writeUInt32(12); + subtable.writeUInt16(0); + subtable.writeUInt16(262); + subtable.writeUInt16(0); + subtable.write(indexes); + return { + charMap: codeMap, + subtable: subtable.data, + maxGlyphID: id + 1 + }; + + case "unicode": + startCodes = []; + endCodes = []; + nextID = 0; + map = {}; + charMap = {}; + last = diff = null; + + for (_j = 0, _len1 = codes.length; _j < _len1; _j++) { + code = codes[_j]; + old = charmap[code]; + + if (map[old] == null) { + map[old] = ++nextID; + } + + charMap[code] = { + old: old, + "new": map[old] + }; + delta = map[old] - code; + + if (last == null || delta !== diff) { + if (last) { + endCodes.push(last); + } + + startCodes.push(code); + diff = delta; + } + + last = code; + } + + if (last) { + endCodes.push(last); + } + + endCodes.push(0xffff); + startCodes.push(0xffff); + segCount = startCodes.length; + segCountX2 = segCount * 2; + searchRange = 2 * Math.pow(Math.log(segCount) / Math.LN2, 2); + entrySelector = Math.log(searchRange / 2) / Math.LN2; + rangeShift = 2 * segCount - searchRange; + deltas = []; + rangeOffsets = []; + glyphIDs = []; + + for (i = _k = 0, _len2 = startCodes.length; _k < _len2; i = ++_k) { + startCode = startCodes[i]; + endCode = endCodes[i]; + + if (startCode === 0xffff) { + deltas.push(0); + rangeOffsets.push(0); + break; + } + + startGlyph = charMap[startCode]["new"]; + + if (startCode - startGlyph >= 0x8000) { + deltas.push(0); + rangeOffsets.push(2 * (glyphIDs.length + segCount - i)); + + for (code = _l = startCode; startCode <= endCode ? _l <= endCode : _l >= endCode; code = startCode <= endCode ? ++_l : --_l) { + glyphIDs.push(charMap[code]["new"]); + } + } else { + deltas.push(startGlyph - startCode); + rangeOffsets.push(0); + } + } + + subtable.writeUInt16(3); + subtable.writeUInt16(1); + subtable.writeUInt32(12); + subtable.writeUInt16(4); + subtable.writeUInt16(16 + segCount * 8 + glyphIDs.length * 2); + subtable.writeUInt16(0); + subtable.writeUInt16(segCountX2); + subtable.writeUInt16(searchRange); + subtable.writeUInt16(entrySelector); + subtable.writeUInt16(rangeShift); + + for (_m = 0, _len3 = endCodes.length; _m < _len3; _m++) { + code = endCodes[_m]; + subtable.writeUInt16(code); + } + + subtable.writeUInt16(0); + + for (_n = 0, _len4 = startCodes.length; _n < _len4; _n++) { + code = startCodes[_n]; + subtable.writeUInt16(code); + } + + for (_o = 0, _len5 = deltas.length; _o < _len5; _o++) { + delta = deltas[_o]; + subtable.writeUInt16(delta); + } + + for (_p = 0, _len6 = rangeOffsets.length; _p < _len6; _p++) { + offset = rangeOffsets[_p]; + subtable.writeUInt16(offset); + } + + for (_q = 0, _len7 = glyphIDs.length; _q < _len7; _q++) { + id = glyphIDs[_q]; + subtable.writeUInt16(id); + } + + return { + charMap: charMap, + subtable: subtable.data, + maxGlyphID: nextID + 1 + }; + } + }; + + return CmapEntry; + }(); + + var CmapTable = function (_super) { + __extends(CmapTable, _super); + + function CmapTable() { + return CmapTable.__super__.constructor.apply(this, arguments); + } + + CmapTable.prototype.tag = "cmap"; + + CmapTable.prototype.parse = function (data) { + var entry, i, tableCount; + data.pos = this.offset; + this.version = data.readUInt16(); + tableCount = data.readUInt16(); + this.tables = []; + this.unicode = null; + + for (i = 0; 0 <= tableCount ? i < tableCount : i > tableCount; i = 0 <= tableCount ? ++i : --i) { + entry = new CmapEntry(data, this.offset); + this.tables.push(entry); + + if (entry.isUnicode) { + if (this.unicode == null) { + this.unicode = entry; + } + } + } + + return true; + }; + /*************************************************************************/ + + /* function : encode */ + + /* comment : Encode the cmap table corresponding to the input character. */ + + /*************************************************************************/ + + + CmapTable.encode = function (charmap, encoding) { + var result, table; + + if (encoding == null) { + encoding = "macroman"; + } + + result = CmapEntry.encode(charmap, encoding); + table = new Data(); + table.writeUInt16(0); + table.writeUInt16(1); + result.table = table.data.concat(result.subtable); + return result; + }; + + return CmapTable; + }(Table); + + var HheaTable = function (_super) { + __extends(HheaTable, _super); + + function HheaTable() { + return HheaTable.__super__.constructor.apply(this, arguments); + } + + HheaTable.prototype.tag = "hhea"; + + HheaTable.prototype.parse = function (data) { + data.pos = this.offset; + this.version = data.readInt(); + this.ascender = data.readShort(); + this.decender = data.readShort(); + this.lineGap = data.readShort(); + this.advanceWidthMax = data.readShort(); + this.minLeftSideBearing = data.readShort(); + this.minRightSideBearing = data.readShort(); + this.xMaxExtent = data.readShort(); + this.caretSlopeRise = data.readShort(); + this.caretSlopeRun = data.readShort(); + this.caretOffset = data.readShort(); + data.pos += 4 * 2; + this.metricDataFormat = data.readShort(); + return this.numberOfMetrics = data.readUInt16(); + }; + /*HheaTable.prototype.encode = function (ids) { + var i, table, _i, _ref; + table = new Data; + table.writeInt(this.version); + table.writeShort(this.ascender); + table.writeShort(this.decender); + table.writeShort(this.lineGap); + table.writeShort(this.advanceWidthMax); + table.writeShort(this.minLeftSideBearing); + table.writeShort(this.minRightSideBearing); + table.writeShort(this.xMaxExtent); + table.writeShort(this.caretSlopeRise); + table.writeShort(this.caretSlopeRun); + table.writeShort(this.caretOffset); + for (i = _i = 0, _ref = 4 * 2; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + table.writeByte(0); + } + table.writeShort(this.metricDataFormat); + table.writeUInt16(ids.length); + return table.data; + };*/ + + + return HheaTable; + }(Table); + + var OS2Table = function (_super) { + __extends(OS2Table, _super); + + function OS2Table() { + return OS2Table.__super__.constructor.apply(this, arguments); + } + + OS2Table.prototype.tag = "OS/2"; + + OS2Table.prototype.parse = function (data) { + data.pos = this.offset; + this.version = data.readUInt16(); + this.averageCharWidth = data.readShort(); + this.weightClass = data.readUInt16(); + this.widthClass = data.readUInt16(); + this.type = data.readShort(); + this.ySubscriptXSize = data.readShort(); + this.ySubscriptYSize = data.readShort(); + this.ySubscriptXOffset = data.readShort(); + this.ySubscriptYOffset = data.readShort(); + this.ySuperscriptXSize = data.readShort(); + this.ySuperscriptYSize = data.readShort(); + this.ySuperscriptXOffset = data.readShort(); + this.ySuperscriptYOffset = data.readShort(); + this.yStrikeoutSize = data.readShort(); + this.yStrikeoutPosition = data.readShort(); + this.familyClass = data.readShort(); + + this.panose = function () { + var i, _results; + + _results = []; + + for (i = 0; i < 10; ++i) { + _results.push(data.readByte()); + } + + return _results; + }(); + + this.charRange = function () { + var i, _results; + + _results = []; + + for (i = 0; i < 4; ++i) { + _results.push(data.readInt()); + } + + return _results; + }(); + + this.vendorID = data.readString(4); + this.selection = data.readShort(); + this.firstCharIndex = data.readShort(); + this.lastCharIndex = data.readShort(); + + if (this.version > 0) { + this.ascent = data.readShort(); + this.descent = data.readShort(); + this.lineGap = data.readShort(); + this.winAscent = data.readShort(); + this.winDescent = data.readShort(); + + this.codePageRange = function () { + var i, _results; + + _results = []; + + for (i = 0; i < 2; i = ++i) { + _results.push(data.readInt()); + } + + return _results; + }(); + + if (this.version > 1) { + this.xHeight = data.readShort(); + this.capHeight = data.readShort(); + this.defaultChar = data.readShort(); + this.breakChar = data.readShort(); + return this.maxContext = data.readShort(); + } + } + }; + /*OS2Table.prototype.encode = function () { + return this.raw(); + };*/ + + + return OS2Table; + }(Table); + + var PostTable = function (_super) { + + __extends(PostTable, _super); + + function PostTable() { + return PostTable.__super__.constructor.apply(this, arguments); + } + + PostTable.prototype.tag = "post"; + + PostTable.prototype.parse = function (data) { + var length, numberOfGlyphs, _results; + + data.pos = this.offset; + this.format = data.readInt(); + this.italicAngle = data.readInt(); + this.underlinePosition = data.readShort(); + this.underlineThickness = data.readShort(); + this.isFixedPitch = data.readInt(); + this.minMemType42 = data.readInt(); + this.maxMemType42 = data.readInt(); + this.minMemType1 = data.readInt(); + this.maxMemType1 = data.readInt(); + + switch (this.format) { + case 0x00010000: + break; + + case 0x00020000: + numberOfGlyphs = data.readUInt16(); + this.glyphNameIndex = []; + var i; + + for (i = 0; 0 <= numberOfGlyphs ? i < numberOfGlyphs : i > numberOfGlyphs; i = 0 <= numberOfGlyphs ? ++i : --i) { + this.glyphNameIndex.push(data.readUInt16()); + } + + this.names = []; + _results = []; + + while (data.pos < this.offset + this.length) { + length = data.readByte(); + + _results.push(this.names.push(data.readString(length))); + } + + return _results; + + case 0x00025000: + numberOfGlyphs = data.readUInt16(); + return this.offsets = data.read(numberOfGlyphs); + + case 0x00030000: + break; + + case 0x00040000: + return this.map = function () { + var _j, _ref, _results1; + + _results1 = []; + + for (i = _j = 0, _ref = this.file.maxp.numGlyphs; 0 <= _ref ? _j < _ref : _j > _ref; i = 0 <= _ref ? ++_j : --_j) { + _results1.push(data.readUInt32()); + } + + return _results1; + }.call(this); + } + }; + return PostTable; + }(Table); + /*********************************************************************************************************/ + + /* function : NameEntry */ + + /* comment : Store copyright information, platformID, encodingID, and languageID in the NameEntry object.*/ + + /*********************************************************************************************************/ + + + var NameEntry = function () { + function NameEntry(raw, entry) { + this.raw = raw; + this.length = raw.length; + this.platformID = entry.platformID; + this.encodingID = entry.encodingID; + this.languageID = entry.languageID; + } + + return NameEntry; + }(); + + var NameTable = function (_super) { + + __extends(NameTable, _super); + + function NameTable() { + return NameTable.__super__.constructor.apply(this, arguments); + } + + NameTable.prototype.tag = "name"; + + NameTable.prototype.parse = function (data) { + var count, entries, entry, i, name, stringOffset, strings, text, _j, _len, _name; + + data.pos = this.offset; + data.readShort(); //format + + count = data.readShort(); + stringOffset = data.readShort(); + entries = []; + + for (i = 0; 0 <= count ? i < count : i > count; i = 0 <= count ? ++i : --i) { + entries.push({ + platformID: data.readShort(), + encodingID: data.readShort(), + languageID: data.readShort(), + nameID: data.readShort(), + length: data.readShort(), + offset: this.offset + stringOffset + data.readShort() + }); + } + + strings = {}; + + for (i = _j = 0, _len = entries.length; _j < _len; i = ++_j) { + entry = entries[i]; + data.pos = entry.offset; + text = data.readString(entry.length); + name = new NameEntry(text, entry); + + if (strings[_name = entry.nameID] == null) { + strings[_name] = []; + } + + strings[entry.nameID].push(name); + } + + this.strings = strings; + this.copyright = strings[0]; + this.fontFamily = strings[1]; + this.fontSubfamily = strings[2]; + this.uniqueSubfamily = strings[3]; + this.fontName = strings[4]; + this.version = strings[5]; + + try { + this.postscriptName = strings[6][0].raw.replace(/[\x00-\x19\x80-\xff]/g, ""); + } catch (e) { + this.postscriptName = strings[4][0].raw.replace(/[\x00-\x19\x80-\xff]/g, ""); + } + + this.trademark = strings[7]; + this.manufacturer = strings[8]; + this.designer = strings[9]; + this.description = strings[10]; + this.vendorUrl = strings[11]; + this.designerUrl = strings[12]; + this.license = strings[13]; + this.licenseUrl = strings[14]; + this.preferredFamily = strings[15]; + this.preferredSubfamily = strings[17]; + this.compatibleFull = strings[18]; + return this.sampleText = strings[19]; + }; + /*NameTable.prototype.encode = function () { + var id, list, nameID, nameTable, postscriptName, strCount, strTable, string, strings, table, val, _i, _len, _ref; + strings = {}; + _ref = this.strings; + for (id in _ref) { + val = _ref[id]; + strings[id] = val; + } + postscriptName = new NameEntry("" + subsetTag + "+" + this.postscriptName, { + platformID: 1 + , encodingID: 0 + , languageID: 0 + }); + strings[6] = [postscriptName]; + subsetTag = successorOf(subsetTag); + strCount = 0; + for (id in strings) { + list = strings[id]; + if (list != null) { + strCount += list.length; + } + } + table = new Data; + strTable = new Data; + table.writeShort(0); + table.writeShort(strCount); + table.writeShort(6 + 12 * strCount); + for (nameID in strings) { + list = strings[nameID]; + if (list != null) { + for (_i = 0, _len = list.length; _i < _len; _i++) { + string = list[_i]; + table.writeShort(string.platformID); + table.writeShort(string.encodingID); + table.writeShort(string.languageID); + table.writeShort(nameID); + table.writeShort(string.length); + table.writeShort(strTable.pos); + strTable.writeString(string.raw); + } + } + } + return nameTable = { + postscriptName: postscriptName.raw + , table: table.data.concat(strTable.data) + }; + };*/ + + return NameTable; + }(Table); + + var MaxpTable = function (_super) { + __extends(MaxpTable, _super); + + function MaxpTable() { + return MaxpTable.__super__.constructor.apply(this, arguments); + } + + MaxpTable.prototype.tag = "maxp"; + + MaxpTable.prototype.parse = function (data) { + data.pos = this.offset; + this.version = data.readInt(); + this.numGlyphs = data.readUInt16(); + this.maxPoints = data.readUInt16(); + this.maxContours = data.readUInt16(); + this.maxCompositePoints = data.readUInt16(); + this.maxComponentContours = data.readUInt16(); + this.maxZones = data.readUInt16(); + this.maxTwilightPoints = data.readUInt16(); + this.maxStorage = data.readUInt16(); + this.maxFunctionDefs = data.readUInt16(); + this.maxInstructionDefs = data.readUInt16(); + this.maxStackElements = data.readUInt16(); + this.maxSizeOfInstructions = data.readUInt16(); + this.maxComponentElements = data.readUInt16(); + return this.maxComponentDepth = data.readUInt16(); + }; + /*MaxpTable.prototype.encode = function (ids) { + var table; + table = new Data; + table.writeInt(this.version); + table.writeUInt16(ids.length); + table.writeUInt16(this.maxPoints); + table.writeUInt16(this.maxContours); + table.writeUInt16(this.maxCompositePoints); + table.writeUInt16(this.maxComponentContours); + table.writeUInt16(this.maxZones); + table.writeUInt16(this.maxTwilightPoints); + table.writeUInt16(this.maxStorage); + table.writeUInt16(this.maxFunctionDefs); + table.writeUInt16(this.maxInstructionDefs); + table.writeUInt16(this.maxStackElements); + table.writeUInt16(this.maxSizeOfInstructions); + table.writeUInt16(this.maxComponentElements); + table.writeUInt16(this.maxComponentDepth); + return table.data; + };*/ + + + return MaxpTable; + }(Table); + + var HmtxTable = function (_super) { + __extends(HmtxTable, _super); + + function HmtxTable() { + return HmtxTable.__super__.constructor.apply(this, arguments); + } + + HmtxTable.prototype.tag = "hmtx"; + + HmtxTable.prototype.parse = function (data) { + var i, last, lsbCount, m, _j, _ref, _results; + + data.pos = this.offset; + this.metrics = []; + + for (i = 0, _ref = this.file.hhea.numberOfMetrics; 0 <= _ref ? i < _ref : i > _ref; i = 0 <= _ref ? ++i : --i) { + this.metrics.push({ + advance: data.readUInt16(), + lsb: data.readInt16() + }); + } + + lsbCount = this.file.maxp.numGlyphs - this.file.hhea.numberOfMetrics; + + this.leftSideBearings = function () { + var _j, _results; + + _results = []; + + for (i = _j = 0; 0 <= lsbCount ? _j < lsbCount : _j > lsbCount; i = 0 <= lsbCount ? ++_j : --_j) { + _results.push(data.readInt16()); + } + + return _results; + }(); + + this.widths = function () { + var _j, _len, _ref1, _results; + + _ref1 = this.metrics; + _results = []; + + for (_j = 0, _len = _ref1.length; _j < _len; _j++) { + m = _ref1[_j]; + + _results.push(m.advance); + } + + return _results; + }.call(this); + + last = this.widths[this.widths.length - 1]; + _results = []; + + for (i = _j = 0; 0 <= lsbCount ? _j < lsbCount : _j > lsbCount; i = 0 <= lsbCount ? ++_j : --_j) { + _results.push(this.widths.push(last)); + } + + return _results; + }; + /***************************************************************/ + + /* function : forGlyph */ + + /* comment : Returns the advance width and lsb for this glyph. */ + + /***************************************************************/ + + + HmtxTable.prototype.forGlyph = function (id) { + if (id in this.metrics) { + return this.metrics[id]; + } + + return { + advance: this.metrics[this.metrics.length - 1].advance, + lsb: this.leftSideBearings[id - this.metrics.length] + }; + }; + /*HmtxTable.prototype.encode = function (mapping) { + var id, metric, table, _i, _len; + table = new Data; + for (_i = 0, _len = mapping.length; _i < _len; _i++) { + id = mapping[_i]; + metric = this.forGlyph(id); + table.writeUInt16(metric.advance); + table.writeUInt16(metric.lsb); + } + return table.data; + };*/ + + + return HmtxTable; + }(Table); + + var __slice = [].slice; + + var GlyfTable = function (_super) { + __extends(GlyfTable, _super); + + function GlyfTable() { + return GlyfTable.__super__.constructor.apply(this, arguments); + } + + GlyfTable.prototype.tag = "glyf"; + + GlyfTable.prototype.parse = function () { + return this.cache = {}; + }; + + GlyfTable.prototype.glyphFor = function (id) { + var data, index, length, loca, numberOfContours, raw, xMax, xMin, yMax, yMin; + + if (id in this.cache) { + return this.cache[id]; + } + + loca = this.file.loca; + data = this.file.contents; + index = loca.indexOf(id); + length = loca.lengthOf(id); + + if (length === 0) { + return this.cache[id] = null; + } + + data.pos = this.offset + index; + raw = new Data(data.read(length)); + numberOfContours = raw.readShort(); + xMin = raw.readShort(); + yMin = raw.readShort(); + xMax = raw.readShort(); + yMax = raw.readShort(); + + if (numberOfContours === -1) { + this.cache[id] = new CompoundGlyph(raw, xMin, yMin, xMax, yMax); + } else { + this.cache[id] = new SimpleGlyph(raw, numberOfContours, xMin, yMin, xMax, yMax); + } + + return this.cache[id]; + }; + + GlyfTable.prototype.encode = function (glyphs, mapping, old2new) { + var glyph, id, offsets, table, _i, _len; + + table = []; + offsets = []; + + for (_i = 0, _len = mapping.length; _i < _len; _i++) { + id = mapping[_i]; + glyph = glyphs[id]; + offsets.push(table.length); + + if (glyph) { + table = table.concat(glyph.encode(old2new)); + } + } + + offsets.push(table.length); + return { + table: table, + offsets: offsets + }; + }; + + return GlyfTable; + }(Table); + + var SimpleGlyph = function () { + /**************************************************************************/ + + /* function : SimpleGlyph */ + + /* comment : Stores raw, xMin, yMin, xMax, and yMax values for this glyph.*/ + + /**************************************************************************/ + function SimpleGlyph(raw, numberOfContours, xMin, yMin, xMax, yMax) { + this.raw = raw; + this.numberOfContours = numberOfContours; + this.xMin = xMin; + this.yMin = yMin; + this.xMax = xMax; + this.yMax = yMax; + this.compound = false; + } + + SimpleGlyph.prototype.encode = function () { + return this.raw.data; + }; + + return SimpleGlyph; + }(); + + var CompoundGlyph = function () { + var ARG_1_AND_2_ARE_WORDS, MORE_COMPONENTS, WE_HAVE_AN_X_AND_Y_SCALE, WE_HAVE_A_SCALE, WE_HAVE_A_TWO_BY_TWO; + ARG_1_AND_2_ARE_WORDS = 0x0001; + WE_HAVE_A_SCALE = 0x0008; + MORE_COMPONENTS = 0x0020; + WE_HAVE_AN_X_AND_Y_SCALE = 0x0040; + WE_HAVE_A_TWO_BY_TWO = 0x0080; + /********************************************************************************************************************/ + + /* function : CompoundGlypg generator */ + + /* comment : It stores raw, xMin, yMin, xMax, yMax, glyph id, and glyph offset for the corresponding compound glyph.*/ + + /********************************************************************************************************************/ + + function CompoundGlyph(raw, xMin, yMin, xMax, yMax) { + var data, flags; + this.raw = raw; + this.xMin = xMin; + this.yMin = yMin; + this.xMax = xMax; + this.yMax = yMax; + this.compound = true; + this.glyphIDs = []; + this.glyphOffsets = []; + data = this.raw; + + while (true) { + flags = data.readShort(); + this.glyphOffsets.push(data.pos); + this.glyphIDs.push(data.readShort()); + + if (!(flags & MORE_COMPONENTS)) { + break; + } + + if (flags & ARG_1_AND_2_ARE_WORDS) { + data.pos += 4; + } else { + data.pos += 2; + } + + if (flags & WE_HAVE_A_TWO_BY_TWO) { + data.pos += 8; + } else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) { + data.pos += 4; + } else if (flags & WE_HAVE_A_SCALE) { + data.pos += 2; + } + } + } + /****************************************************************************************************************/ + + /* function : CompoundGlypg encode */ + + /* comment : After creating a table for the characters you typed, you call directory.encode to encode the table.*/ + + /****************************************************************************************************************/ + + + CompoundGlyph.prototype.encode = function () { + var i, result, _len, _ref; + + result = new Data(__slice.call(this.raw.data)); + _ref = this.glyphIDs; + + for (i = 0, _len = _ref.length; i < _len; ++i) { + result.pos = this.glyphOffsets[i]; + } + + return result.data; + }; + + return CompoundGlyph; + }(); + + var LocaTable = function (_super) { + __extends(LocaTable, _super); + + function LocaTable() { + return LocaTable.__super__.constructor.apply(this, arguments); + } + + LocaTable.prototype.tag = "loca"; + + LocaTable.prototype.parse = function (data) { + var format, i; + data.pos = this.offset; + format = this.file.head.indexToLocFormat; + + if (format === 0) { + return this.offsets = function () { + var _ref, _results; + + _results = []; + + for (i = 0, _ref = this.length; i < _ref; i += 2) { + _results.push(data.readUInt16() * 2); + } + + return _results; + }.call(this); + } else { + return this.offsets = function () { + var _ref, _results; + + _results = []; + + for (i = 0, _ref = this.length; i < _ref; i += 4) { + _results.push(data.readUInt32()); + } + + return _results; + }.call(this); + } + }; + + LocaTable.prototype.indexOf = function (id) { + return this.offsets[id]; + }; + + LocaTable.prototype.lengthOf = function (id) { + return this.offsets[id + 1] - this.offsets[id]; + }; + + LocaTable.prototype.encode = function (offsets, activeGlyphs) { + var LocaTable = new Uint32Array(this.offsets.length); + var glyfPtr = 0; + var listGlyf = 0; + + for (var k = 0; k < LocaTable.length; ++k) { + LocaTable[k] = glyfPtr; + + if (listGlyf < activeGlyphs.length && activeGlyphs[listGlyf] == k) { + ++listGlyf; + LocaTable[k] = glyfPtr; + var start = this.offsets[k]; + var len = this.offsets[k + 1] - start; + + if (len > 0) { + glyfPtr += len; + } + } + } + + var newLocaTable = new Array(LocaTable.length * 4); + + for (var j = 0; j < LocaTable.length; ++j) { + newLocaTable[4 * j + 3] = LocaTable[j] & 0x000000ff; + newLocaTable[4 * j + 2] = (LocaTable[j] & 0x0000ff00) >> 8; + newLocaTable[4 * j + 1] = (LocaTable[j] & 0x00ff0000) >> 16; + newLocaTable[4 * j] = (LocaTable[j] & 0xff000000) >> 24; + } + + return newLocaTable; + }; + + return LocaTable; + }(Table); + /************************************************************************************/ + + /* function : invert */ + + /* comment : Change the object's (key: value) to create an object with (value: key).*/ + + /************************************************************************************/ + + + var invert = function invert(object) { + var key, ret, val; + ret = {}; + + for (key in object) { + val = object[key]; + ret[val] = key; + } + + return ret; + }; + /*var successorOf = function (input) { + var added, alphabet, carry, i, index, isUpperCase, last, length, next, result; + alphabet = 'abcdefghijklmnopqrstuvwxyz'; + length = alphabet.length; + result = input; + i = input.length; + while (i >= 0) { + last = input.charAt(--i); + if (isNaN(last)) { + index = alphabet.indexOf(last.toLowerCase()); + if (index === -1) { + next = last; + carry = true; + } + else { + next = alphabet.charAt((index + 1) % length); + isUpperCase = last === last.toUpperCase(); + if (isUpperCase) { + next = next.toUpperCase(); + } + carry = index + 1 >= length; + if (carry && i === 0) { + added = isUpperCase ? 'A' : 'a'; + result = added + next + result.slice(1); + break; + } + } + } + else { + next = +last + 1; + carry = next > 9; + if (carry) { + next = 0; + } + if (carry && i === 0) { + result = '1' + next + result.slice(1); + break; + } + } + result = result.slice(0, i) + next + result.slice(i + 1); + if (!carry) { + break; + } + } + return result; + };*/ + + + var Subset = function () { + function Subset(font) { + this.font = font; + this.subset = {}; + this.unicodes = {}; + this.next = 33; + } + /*Subset.prototype.use = function (character) { + var i, _i, _ref; + if (typeof character === 'string') { + for (i = _i = 0, _ref = character.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + this.use(character.charCodeAt(i)); + } + return; + } + if (!this.unicodes[character]) { + this.subset[this.next] = character; + return this.unicodes[character] = this.next++; + } + };*/ + + /*Subset.prototype.encodeText = function (text) { + var char, i, string, _i, _ref; + string = ''; + for (i = _i = 0, _ref = text.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + char = this.unicodes[text.charCodeAt(i)]; + string += String.fromCharCode(char); + } + return string; + };*/ + + /***************************************************************/ + + /* function : generateCmap */ + + /* comment : Returns the unicode cmap for this font. */ + + /***************************************************************/ + + + Subset.prototype.generateCmap = function () { + var mapping, roman, unicode, unicodeCmap, _ref; + + unicodeCmap = this.font.cmap.tables[0].codeMap; + mapping = {}; + _ref = this.subset; + + for (roman in _ref) { + unicode = _ref[roman]; + mapping[roman] = unicodeCmap[unicode]; + } + + return mapping; + }; + /*Subset.prototype.glyphIDs = function () { + var ret, roman, unicode, unicodeCmap, val, _ref; + unicodeCmap = this.font.cmap.tables[0].codeMap; + ret = [0]; + _ref = this.subset; + for (roman in _ref) { + unicode = _ref[roman]; + val = unicodeCmap[unicode]; + if ((val != null) && __indexOf.call(ret, val) < 0) { + ret.push(val); + } + } + return ret.sort(); + };*/ + + /******************************************************************/ + + /* function : glyphsFor */ + + /* comment : Returns simple glyph objects for the input character.*/ + + /******************************************************************/ + + + Subset.prototype.glyphsFor = function (glyphIDs) { + var additionalIDs, glyph, glyphs, id, _i, _len, _ref; + + glyphs = {}; + + for (_i = 0, _len = glyphIDs.length; _i < _len; _i++) { + id = glyphIDs[_i]; + glyphs[id] = this.font.glyf.glyphFor(id); + } + + additionalIDs = []; + + for (id in glyphs) { + glyph = glyphs[id]; + + if (glyph != null ? glyph.compound : void 0) { + additionalIDs.push.apply(additionalIDs, glyph.glyphIDs); + } + } + + if (additionalIDs.length > 0) { + _ref = this.glyphsFor(additionalIDs); + + for (id in _ref) { + glyph = _ref[id]; + glyphs[id] = glyph; + } + } + + return glyphs; + }; + /***************************************************************/ + + /* function : encode */ + + /* comment : Encode various tables for the characters you use. */ + + /***************************************************************/ + + + Subset.prototype.encode = function (glyID, indexToLocFormat) { + var cmap, code, glyf, glyphs, id, ids, loca, new2old, newIDs, nextGlyphID, old2new, oldID, oldIDs, tables, _ref; + + cmap = CmapTable.encode(this.generateCmap(), "unicode"); + glyphs = this.glyphsFor(glyID); + old2new = { + 0: 0 + }; + _ref = cmap.charMap; + + for (code in _ref) { + ids = _ref[code]; + old2new[ids.old] = ids["new"]; + } + + nextGlyphID = cmap.maxGlyphID; + + for (oldID in glyphs) { + if (!(oldID in old2new)) { + old2new[oldID] = nextGlyphID++; + } + } + + new2old = invert(old2new); + newIDs = Object.keys(new2old).sort(function (a, b) { + return a - b; + }); + + oldIDs = function () { + var _i, _len, _results; + + _results = []; + + for (_i = 0, _len = newIDs.length; _i < _len; _i++) { + id = newIDs[_i]; + + _results.push(new2old[id]); + } + + return _results; + }(); + + glyf = this.font.glyf.encode(glyphs, oldIDs, old2new); + loca = this.font.loca.encode(glyf.offsets, oldIDs); + tables = { + cmap: this.font.cmap.raw(), + glyf: glyf.table, + loca: loca, + hmtx: this.font.hmtx.raw(), + hhea: this.font.hhea.raw(), + maxp: this.font.maxp.raw(), + post: this.font.post.raw(), + name: this.font.name.raw(), + head: this.font.head.encode(indexToLocFormat) + }; + + if (this.font.os2.exists) { + tables["OS/2"] = this.font.os2.raw(); + } + + return this.font.directory.encode(tables); + }; + + return Subset; + }(); + + jsPDF.API.PDFObject = function () { + var pad; + + function PDFObject() {} + + pad = function pad(str, length) { + return (Array(length + 1).join("0") + str).slice(-length); + }; + /*****************************************************************************/ + + /* function : convert */ + + /* comment :Converts pdf tag's / FontBBox and array values in / W to strings */ + + /*****************************************************************************/ + + + PDFObject.convert = function (object) { + var e, items, key, out, val; + + if (Array.isArray(object)) { + items = function () { + var _i, _len, _results; + + _results = []; + + for (_i = 0, _len = object.length; _i < _len; _i++) { + e = object[_i]; + + _results.push(PDFObject.convert(e)); + } + + return _results; + }().join(" "); + + return "[" + items + "]"; + } else if (typeof object === "string") { + return "/" + object; + } else if (object != null ? object.isString : void 0) { + return "(" + object + ")"; + } else if (object instanceof Date) { + return "(D:" + pad(object.getUTCFullYear(), 4) + pad(object.getUTCMonth(), 2) + pad(object.getUTCDate(), 2) + pad(object.getUTCHours(), 2) + pad(object.getUTCMinutes(), 2) + pad(object.getUTCSeconds(), 2) + "Z)"; + } else if ({}.toString.call(object) === "[object Object]") { + out = ["<<"]; + + for (key in object) { + val = object[key]; + out.push("/" + key + " " + PDFObject.convert(val)); + } + + out.push(">>"); + return out.join("\n"); + } else { + return "" + object; + } + }; + + return PDFObject; + }(); +})(jsPDF); + +/* global FlateStream */ +// Generated by CoffeeScript 1.4.0 + +/* +# PNG.js +# Copyright (c) 2011 Devon Govett +# MIT LICENSE +# +# +*/ +(function (global) { + global.PNG = function () { + var APNG_BLEND_OP_SOURCE, APNG_DISPOSE_OP_BACKGROUND, APNG_DISPOSE_OP_PREVIOUS, makeImage, scratchCanvas, scratchCtx; + APNG_DISPOSE_OP_BACKGROUND = 1; + APNG_DISPOSE_OP_PREVIOUS = 2; + APNG_BLEND_OP_SOURCE = 0; + + function PNG(data) { + var chunkSize, colors, palLen, delayDen, delayNum, frame, i, index, key, section, palShort, text, _i, _j, _ref; + + this.data = data; + this.pos = 8; + this.palette = []; + this.imgData = []; + this.transparency = {}; + this.animation = null; + this.text = {}; + frame = null; + + while (true) { + chunkSize = this.readUInt32(); + + section = function () { + var _i, _results; + + _results = []; + + for (i = _i = 0; _i < 4; i = ++_i) { + _results.push(String.fromCharCode(this.data[this.pos++])); + } + + return _results; + }.call(this).join(""); + + switch (section) { + case "IHDR": + this.width = this.readUInt32(); + this.height = this.readUInt32(); + this.bits = this.data[this.pos++]; + this.colorType = this.data[this.pos++]; + this.compressionMethod = this.data[this.pos++]; + this.filterMethod = this.data[this.pos++]; + this.interlaceMethod = this.data[this.pos++]; + break; + + case "acTL": + this.animation = { + numFrames: this.readUInt32(), + numPlays: this.readUInt32() || Infinity, + frames: [] + }; + break; + + case "PLTE": + this.palette = this.read(chunkSize); + break; + + case "fcTL": + if (frame) { + this.animation.frames.push(frame); + } + + this.pos += 4; + frame = { + width: this.readUInt32(), + height: this.readUInt32(), + xOffset: this.readUInt32(), + yOffset: this.readUInt32() + }; + delayNum = this.readUInt16(); + delayDen = this.readUInt16() || 100; + frame.delay = 1000 * delayNum / delayDen; + frame.disposeOp = this.data[this.pos++]; + frame.blendOp = this.data[this.pos++]; + frame.data = []; + break; + + case "IDAT": + case "fdAT": + if (section === "fdAT") { + this.pos += 4; + chunkSize -= 4; + } + + data = (frame != null ? frame.data : void 0) || this.imgData; + + for (i = _i = 0; 0 <= chunkSize ? _i < chunkSize : _i > chunkSize; i = 0 <= chunkSize ? ++_i : --_i) { + data.push(this.data[this.pos++]); + } + + break; + + case "tRNS": + this.transparency = {}; + + switch (this.colorType) { + case 3: + palLen = this.palette.length / 3; + this.transparency.indexed = this.read(chunkSize); + if (this.transparency.indexed.length > palLen) { throw new Error("More transparent colors than palette size"); } + /* + * According to the PNG spec trns should be increased to the same size as palette if shorter + */ + //palShort = 255 - this.transparency.indexed.length; + + palShort = palLen - this.transparency.indexed.length; + + if (palShort > 0) { + for (i = _j = 0; 0 <= palShort ? _j < palShort : _j > palShort; i = 0 <= palShort ? ++_j : --_j) { + this.transparency.indexed.push(255); + } + } + + break; + + case 0: + this.transparency.grayscale = this.read(chunkSize)[0]; + break; + + case 2: + this.transparency.rgb = this.read(chunkSize); + } + + break; + + case "tEXt": + text = this.read(chunkSize); + index = text.indexOf(0); + key = String.fromCharCode.apply(String, text.slice(0, index)); + this.text[key] = String.fromCharCode.apply(String, text.slice(index + 1)); + break; + + case "IEND": + if (frame) { + this.animation.frames.push(frame); + } + + this.colors = function () { + switch (this.colorType) { + case 0: + case 3: + case 4: + return 1; + + case 2: + case 6: + return 3; + } + }.call(this); + + this.hasAlphaChannel = (_ref = this.colorType) === 4 || _ref === 6; + colors = this.colors + (this.hasAlphaChannel ? 1 : 0); + this.pixelBitlength = this.bits * colors; + + this.colorSpace = function () { + switch (this.colors) { + case 1: + return "DeviceGray"; + + case 3: + return "DeviceRGB"; + } + }.call(this); + + this.imgData = new Uint8Array(this.imgData); + return; + + default: + this.pos += chunkSize; + } + + this.pos += 4; + + if (this.pos > this.data.length) { + throw new Error("Incomplete or corrupt PNG file"); + } + } + } + + PNG.prototype.read = function (bytes) { + var i, _i, _results; + + _results = []; + + for (i = _i = 0; 0 <= bytes ? _i < bytes : _i > bytes; i = 0 <= bytes ? ++_i : --_i) { + _results.push(this.data[this.pos++]); + } + + return _results; + }; + + PNG.prototype.readUInt32 = function () { + var b1, b2, b3, b4; + b1 = this.data[this.pos++] << 24; + b2 = this.data[this.pos++] << 16; + b3 = this.data[this.pos++] << 8; + b4 = this.data[this.pos++]; + return b1 | b2 | b3 | b4; + }; + + PNG.prototype.readUInt16 = function () { + var b1, b2; + b1 = this.data[this.pos++] << 8; + b2 = this.data[this.pos++]; + return b1 | b2; + }; + + PNG.prototype.decodePixels = function (data) { + var pixelBytes = this.pixelBitlength / 8; + var fullPixels = new Uint8Array(this.width * this.height * pixelBytes); + var pos = 0; + + var _this = this; + + if (data == null) { + data = this.imgData; + } + + if (data.length === 0) { + return new Uint8Array(0); + } + + data = new FlateStream(data); + data = data.getBytes(); + + function pass(x0, y0, dx, dy) { + var abyte, c, col, i, left, length, p, pa, paeth, pb, pc, pixels, row, scanlineLength, upper, upperLeft, _i, _j, _k, _l, _m; + + var w = Math.ceil((_this.width - x0) / dx), + h = Math.ceil((_this.height - y0) / dy); + var isFull = _this.width == w && _this.height == h; + scanlineLength = pixelBytes * w; + pixels = isFull ? fullPixels : new Uint8Array(scanlineLength * h); + length = data.length; + row = 0; + c = 0; + + while (row < h && pos < length) { + switch (data[pos++]) { + case 0: + for (i = _i = 0; _i < scanlineLength; i = _i += 1) { + pixels[c++] = data[pos++]; + } + + break; + + case 1: + for (i = _j = 0; _j < scanlineLength; i = _j += 1) { + abyte = data[pos++]; + left = i < pixelBytes ? 0 : pixels[c - pixelBytes]; + pixels[c++] = (abyte + left) % 256; + } + + break; + + case 2: + for (i = _k = 0; _k < scanlineLength; i = _k += 1) { + abyte = data[pos++]; + col = (i - i % pixelBytes) / pixelBytes; + upper = row && pixels[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes]; + pixels[c++] = (upper + abyte) % 256; + } + + break; + + case 3: + for (i = _l = 0; _l < scanlineLength; i = _l += 1) { + abyte = data[pos++]; + col = (i - i % pixelBytes) / pixelBytes; + left = i < pixelBytes ? 0 : pixels[c - pixelBytes]; + upper = row && pixels[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes]; + pixels[c++] = (abyte + Math.floor((left + upper) / 2)) % 256; + } + + break; + + case 4: + for (i = _m = 0; _m < scanlineLength; i = _m += 1) { + abyte = data[pos++]; + col = (i - i % pixelBytes) / pixelBytes; + left = i < pixelBytes ? 0 : pixels[c - pixelBytes]; + + if (row === 0) { + upper = upperLeft = 0; + } else { + upper = pixels[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes]; + upperLeft = col && pixels[(row - 1) * scanlineLength + (col - 1) * pixelBytes + i % pixelBytes]; + } + + p = left + upper - upperLeft; + pa = Math.abs(p - left); + pb = Math.abs(p - upper); + pc = Math.abs(p - upperLeft); + + if (pa <= pb && pa <= pc) { + paeth = left; + } else if (pb <= pc) { + paeth = upper; + } else { + paeth = upperLeft; + } + + pixels[c++] = (abyte + paeth) % 256; + } + + break; + + default: + throw new Error("Invalid filter algorithm: " + data[pos - 1]); + } + + if (!isFull) { + var fullPos = ((y0 + row * dy) * _this.width + x0) * pixelBytes; + var partPos = row * scanlineLength; + + for (i = 0; i < w; i += 1) { + for (var j = 0; j < pixelBytes; j += 1) { + fullPixels[fullPos++] = pixels[partPos++]; + } + + fullPos += (dx - 1) * pixelBytes; + } + } + + row++; + } + } + + if (_this.interlaceMethod == 1) { + /* + 1 6 4 6 2 6 4 6 + 7 7 7 7 7 7 7 7 + 5 6 5 6 5 6 5 6 + 7 7 7 7 7 7 7 7 + 3 6 4 6 3 6 4 6 + 7 7 7 7 7 7 7 7 + 5 6 5 6 5 6 5 6 + 7 7 7 7 7 7 7 7 + */ + pass(0, 0, 8, 8); // 1 + + /* NOTE these seem to follow the pattern: + * pass(x, 0, 2*x, 2*x); + * pass(0, x, x, 2*x); + * with x being 4, 2, 1. + */ + + pass(4, 0, 8, 8); // 2 + + pass(0, 4, 4, 8); // 3 + + pass(2, 0, 4, 4); // 4 + + pass(0, 2, 2, 4); // 5 + + pass(1, 0, 2, 2); // 6 + + pass(0, 1, 1, 2); // 7 + } else { + pass(0, 0, 1, 1); + } + + return fullPixels; + }; + + PNG.prototype.decodePalette = function () { + var c, i, length, palette, pos, ret, transparency, _i, _ref, _ref1; + + palette = this.palette; + transparency = this.transparency.indexed || []; + ret = new Uint8Array((transparency.length || 0) + palette.length); + pos = 0; + length = palette.length; + c = 0; + + for (i = _i = 0, _ref = length; _i < _ref; i = _i += 3) { + ret[pos++] = palette[i]; + ret[pos++] = palette[i + 1]; + ret[pos++] = palette[i + 2]; + ret[pos++] = (_ref1 = transparency[c++]) != null ? _ref1 : 255; + } + + return ret; + }; + + PNG.prototype.copyToImageData = function (imageData, pixels) { + var alpha, colors, data, i, input, j, k, length, palette, v, _ref; + + colors = this.colors; + palette = null; + alpha = this.hasAlphaChannel; + + if (this.palette.length) { + palette = (_ref = this._decodedPalette) != null ? _ref : this._decodedPalette = this.decodePalette(); + colors = 4; + alpha = true; + } + + data = imageData.data || imageData; + length = data.length; + input = palette || pixels; + i = j = 0; + + if (colors === 1) { + while (i < length) { + k = palette ? pixels[i / 4] * 4 : j; + v = input[k++]; + data[i++] = v; + data[i++] = v; + data[i++] = v; + data[i++] = alpha ? input[k++] : 255; + j = k; + } + } else { + while (i < length) { + k = palette ? pixels[i / 4] * 4 : j; + data[i++] = input[k++]; + data[i++] = input[k++]; + data[i++] = input[k++]; + data[i++] = alpha ? input[k++] : 255; + j = k; + } + } + }; + + PNG.prototype.decode = function () { + var ret; + ret = new Uint8Array(this.width * this.height * 4); + this.copyToImageData(ret, this.decodePixels()); + return ret; + }; + + var hasBrowserCanvas = function hasBrowserCanvas() { + if (Object.prototype.toString.call(global) === "[object Window]") { + try { + scratchCanvas = global.document.createElement("canvas"); + scratchCtx = scratchCanvas.getContext("2d"); + } catch (e) { + return false; + } + + return true; + } + + return false; + }; + + hasBrowserCanvas(); + + makeImage = function makeImage(imageData) { + if (hasBrowserCanvas() === true) { + var img; + scratchCtx.width = imageData.width; + scratchCtx.height = imageData.height; + scratchCtx.clearRect(0, 0, imageData.width, imageData.height); + scratchCtx.putImageData(imageData, 0, 0); + img = new Image(); + img.src = scratchCanvas.toDataURL(); + return img; + } + + throw new Error("This method requires a Browser with Canvas-capability."); + }; + + PNG.prototype.decodeFrames = function (ctx) { + var frame, i, imageData, pixels, _i, _len, _ref, _results; + + if (!this.animation) { + return; + } + + _ref = this.animation.frames; + _results = []; + + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + frame = _ref[i]; + imageData = ctx.createImageData(frame.width, frame.height); + pixels = this.decodePixels(new Uint8Array(frame.data)); + this.copyToImageData(imageData, pixels); + frame.imageData = imageData; + + _results.push(frame.image = makeImage(imageData)); + } + + return _results; + }; + + PNG.prototype.renderFrame = function (ctx, number) { + var frame, frames, prev; + frames = this.animation.frames; + frame = frames[number]; + prev = frames[number - 1]; + + if (number === 0) { + ctx.clearRect(0, 0, this.width, this.height); + } + + if ((prev != null ? prev.disposeOp : void 0) === APNG_DISPOSE_OP_BACKGROUND) { + ctx.clearRect(prev.xOffset, prev.yOffset, prev.width, prev.height); + } else if ((prev != null ? prev.disposeOp : void 0) === APNG_DISPOSE_OP_PREVIOUS) { + ctx.putImageData(prev.imageData, prev.xOffset, prev.yOffset); + } + + if (frame.blendOp === APNG_BLEND_OP_SOURCE) { + ctx.clearRect(frame.xOffset, frame.yOffset, frame.width, frame.height); + } + + return ctx.drawImage(frame.image, frame.xOffset, frame.yOffset); + }; + + PNG.prototype.animate = function (ctx) { + var _doFrame, + frameNumber, + frames, + numFrames, + numPlays, + _ref, + _this = this; + + frameNumber = 0; + _ref = this.animation, numFrames = _ref.numFrames, frames = _ref.frames, numPlays = _ref.numPlays; + return (_doFrame = function doFrame() { + var f, frame; + f = frameNumber++ % numFrames; + frame = frames[f]; + + _this.renderFrame(ctx, f); + + if (numFrames > 1 && frameNumber / numFrames < numPlays) { + return _this.animation._timeout = setTimeout(_doFrame, frame.delay); + } + })(); + }; + + PNG.prototype.stopAnimation = function () { + var _ref; + + return clearTimeout((_ref = this.animation) != null ? _ref._timeout : void 0); + }; + + PNG.prototype.render = function (canvas) { + var ctx, data; + + if (canvas._png) { + canvas._png.stopAnimation(); + } + + canvas._png = this; + canvas.width = this.width; + canvas.height = this.height; + ctx = canvas.getContext("2d"); + + if (this.animation) { + this.decodeFrames(ctx); + return this.animate(ctx); + } else { + data = ctx.createImageData(this.width, this.height); + this.copyToImageData(data, this.decodePixels()); + return ctx.putImageData(data, 0, 0); + } + }; + + return PNG; + }(); +})(typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function("return this")()); // `self` is undefined in Firefox for Android content script context +// while `this` is nsIContentFrameMessageManager +// with an attribute `content` that corresponds to the window + +/* + * Extracted from pdf.js + * https://github.com/andreasgal/pdf.js + * + * Copyright (c) 2011 Mozilla Foundation + * + * Contributors: Andreas Gal + * Chris G Jones + * Shaon Barman + * Vivien Nicolas <21@vingtetun.org> + * Justin D'Arcangelo + * Yury Delendik + * + * + */ +var DecodeStream = function () { + function constructor() { + this.pos = 0; + this.bufferLength = 0; + this.eof = false; + this.buffer = null; + } + + constructor.prototype = { + ensureBuffer: function decodestream_ensureBuffer(requested) { + var buffer = this.buffer; + var current = buffer ? buffer.byteLength : 0; + if (requested < current) { return buffer; } + var size = 512; + + while (size < requested) { + size <<= 1; + } + + var buffer2 = new Uint8Array(size); + + for (var i = 0; i < current; ++i) { + buffer2[i] = buffer[i]; + } + + return this.buffer = buffer2; + }, + getByte: function decodestream_getByte() { + var pos = this.pos; + + while (this.bufferLength <= pos) { + if (this.eof) { return null; } + this.readBlock(); + } + + return this.buffer[this.pos++]; + }, + getBytes: function decodestream_getBytes(length) { + var pos = this.pos; + + if (length) { + this.ensureBuffer(pos + length); + var end = pos + length; + + while (!this.eof && this.bufferLength < end) { + this.readBlock(); + } + + var bufEnd = this.bufferLength; + if (end > bufEnd) { end = bufEnd; } + } else { + while (!this.eof) { + this.readBlock(); + } + + var end = this.bufferLength; + } + + this.pos = end; + return this.buffer.subarray(pos, end); + }, + lookChar: function decodestream_lookChar() { + var pos = this.pos; + + while (this.bufferLength <= pos) { + if (this.eof) { return null; } + this.readBlock(); + } + + return String.fromCharCode(this.buffer[this.pos]); + }, + getChar: function decodestream_getChar() { + var pos = this.pos; + + while (this.bufferLength <= pos) { + if (this.eof) { return null; } + this.readBlock(); + } + + return String.fromCharCode(this.buffer[this.pos++]); + }, + makeSubStream: function decodestream_makeSubstream(start, length, dict) { + var end = start + length; + + while (this.bufferLength <= end && !this.eof) { + this.readBlock(); + } + + return new Stream(this.buffer, start, length, dict); + }, + skip: function decodestream_skip(n) { + if (!n) { n = 1; } + this.pos += n; + }, + reset: function decodestream_reset() { + this.pos = 0; + } + }; + return constructor; +}(); + +var globalObject = typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function("return this")(); + +var FlateStream = globalObject.FlateStream = function () { + if (typeof Uint32Array === "undefined") { + return undefined; + } + + var codeLenCodeMap = new Uint32Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + var lengthDecode = new Uint32Array([0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a, 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f, 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073, 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102]); + var distDecode = new Uint32Array([0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d, 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1, 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01, 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001]); + var fixedLitCodeTab = [new Uint32Array([0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0, 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0, 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0, 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8, 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8, 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8, 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4, 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4, 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4, 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc, 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec, 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc, 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2, 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2, 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2, 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca, 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea, 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da, 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6, 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6, 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6, 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce, 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee, 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de, 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe, 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1, 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1, 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1, 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9, 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9, 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9, 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5, 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5, 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5, 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd, 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed, 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd, 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3, 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3, 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3, 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb, 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb, 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db, 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7, 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7, 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7, 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf, 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef, 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df, 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff]), 9]; + var fixedDistCodeTab = [new Uint32Array([0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c, 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000, 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d, 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000]), 5]; + + function error(e) { + throw new Error(e); + } + + function constructor(bytes) { + //var bytes = stream.getBytes(); + var bytesPos = 0; + var cmf = bytes[bytesPos++]; + var flg = bytes[bytesPos++]; + if (cmf == -1 || flg == -1) { error("Invalid header in flate stream"); } + if ((cmf & 0x0f) != 0x08) { error("Unknown compression method in flate stream"); } + if (((cmf << 8) + flg) % 31 != 0) { error("Bad FCHECK in flate stream"); } + if (flg & 0x20) { error("FDICT bit set in flate stream"); } + this.bytes = bytes; + this.bytesPos = bytesPos; + this.codeSize = 0; + this.codeBuf = 0; + DecodeStream.call(this); + } + + constructor.prototype = Object.create(DecodeStream.prototype); + + constructor.prototype.getBits = function (bits) { + var codeSize = this.codeSize; + var codeBuf = this.codeBuf; + var bytes = this.bytes; + var bytesPos = this.bytesPos; + var b; + + while (codeSize < bits) { + if (typeof (b = bytes[bytesPos++]) == "undefined") { error("Bad encoding in flate stream"); } + codeBuf |= b << codeSize; + codeSize += 8; + } + + b = codeBuf & (1 << bits) - 1; + this.codeBuf = codeBuf >> bits; + this.codeSize = codeSize -= bits; + this.bytesPos = bytesPos; + return b; + }; + + constructor.prototype.getCode = function (table) { + var codes = table[0]; + var maxLen = table[1]; + var codeSize = this.codeSize; + var codeBuf = this.codeBuf; + var bytes = this.bytes; + var bytesPos = this.bytesPos; + + while (codeSize < maxLen) { + var b; + if (typeof (b = bytes[bytesPos++]) == "undefined") { error("Bad encoding in flate stream"); } + codeBuf |= b << codeSize; + codeSize += 8; + } + + var code = codes[codeBuf & (1 << maxLen) - 1]; + var codeLen = code >> 16; + var codeVal = code & 0xffff; + if (codeSize == 0 || codeSize < codeLen || codeLen == 0) { error("Bad encoding in flate stream"); } + this.codeBuf = codeBuf >> codeLen; + this.codeSize = codeSize - codeLen; + this.bytesPos = bytesPos; + return codeVal; + }; + + constructor.prototype.generateHuffmanTable = function (lengths) { + var n = lengths.length; // find max code length + + var maxLen = 0; + + for (var i = 0; i < n; ++i) { + if (lengths[i] > maxLen) { maxLen = lengths[i]; } + } // build the table + + + var size = 1 << maxLen; + var codes = new Uint32Array(size); + + for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) { + for (var val = 0; val < n; ++val) { + if (lengths[val] == len) { + // bit-reverse the code + var code2 = 0; + var t = code; + + for (var i = 0; i < len; ++i) { + code2 = code2 << 1 | t & 1; + t >>= 1; + } // fill the table entries + + + for (var i = code2; i < size; i += skip) { + codes[i] = len << 16 | val; + } + + ++code; + } + } + } + + return [codes, maxLen]; + }; + + constructor.prototype.readBlock = function () { + function repeat(stream, array, len, offset, what) { + var repeat = stream.getBits(len) + offset; + + while (repeat-- > 0) { + array[i++] = what; + } + } // read block header + + + var hdr = this.getBits(3); + if (hdr & 1) { this.eof = true; } + hdr >>= 1; + + if (hdr == 0) { + // uncompressed block + var bytes = this.bytes; + var bytesPos = this.bytesPos; + var b; + if (typeof (b = bytes[bytesPos++]) == "undefined") { error("Bad block header in flate stream"); } + var blockLen = b; + if (typeof (b = bytes[bytesPos++]) == "undefined") { error("Bad block header in flate stream"); } + blockLen |= b << 8; + if (typeof (b = bytes[bytesPos++]) == "undefined") { error("Bad block header in flate stream"); } + var check = b; + if (typeof (b = bytes[bytesPos++]) == "undefined") { error("Bad block header in flate stream"); } + check |= b << 8; + if (check != (~blockLen & 0xffff)) { error("Bad uncompressed block length in flate stream"); } + this.codeBuf = 0; + this.codeSize = 0; + var bufferLength = this.bufferLength; + var buffer = this.ensureBuffer(bufferLength + blockLen); + var end = bufferLength + blockLen; + this.bufferLength = end; + + for (var n = bufferLength; n < end; ++n) { + if (typeof (b = bytes[bytesPos++]) == "undefined") { + this.eof = true; + break; + } + + buffer[n] = b; + } + + this.bytesPos = bytesPos; + return; + } + + var litCodeTable; + var distCodeTable; + + if (hdr == 1) { + // compressed block, fixed codes + litCodeTable = fixedLitCodeTab; + distCodeTable = fixedDistCodeTab; + } else if (hdr == 2) { + // compressed block, dynamic codes + var numLitCodes = this.getBits(5) + 257; + var numDistCodes = this.getBits(5) + 1; + var numCodeLenCodes = this.getBits(4) + 4; // build the code lengths code table + + var codeLenCodeLengths = Array(codeLenCodeMap.length); + var i = 0; + + while (i < numCodeLenCodes) { + codeLenCodeLengths[codeLenCodeMap[i++]] = this.getBits(3); + } + + var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths); // build the literal and distance code tables + + var len = 0; + var i = 0; + var codes = numLitCodes + numDistCodes; + var codeLengths = new Array(codes); + + while (i < codes) { + var code = this.getCode(codeLenCodeTab); + + if (code == 16) { + repeat(this, codeLengths, 2, 3, len); + } else if (code == 17) { + repeat(this, codeLengths, 3, 3, len = 0); + } else if (code == 18) { + repeat(this, codeLengths, 7, 11, len = 0); + } else { + codeLengths[i++] = len = code; + } + } + + litCodeTable = this.generateHuffmanTable(codeLengths.slice(0, numLitCodes)); + distCodeTable = this.generateHuffmanTable(codeLengths.slice(numLitCodes, codes)); + } else { + error("Unknown block type in flate stream"); + } + + var buffer = this.buffer; + var limit = buffer ? buffer.length : 0; + var pos = this.bufferLength; + + while (true) { + var code1 = this.getCode(litCodeTable); + + if (code1 < 256) { + if (pos + 1 >= limit) { + buffer = this.ensureBuffer(pos + 1); + limit = buffer.length; + } + + buffer[pos++] = code1; + continue; + } + + if (code1 == 256) { + this.bufferLength = pos; + return; + } + + code1 -= 257; + code1 = lengthDecode[code1]; + var code2 = code1 >> 16; + if (code2 > 0) { code2 = this.getBits(code2); } + var len = (code1 & 0xffff) + code2; + code1 = this.getCode(distCodeTable); + code1 = distDecode[code1]; + code2 = code1 >> 16; + if (code2 > 0) { code2 = this.getBits(code2); } + var dist = (code1 & 0xffff) + code2; + + if (pos + len >= limit) { + buffer = this.ensureBuffer(pos + len); + limit = buffer.length; + } + + for (var k = 0; k < len; ++k, ++pos) { + buffer[pos] = buffer[pos - dist]; + } + } + }; + + return constructor; +}(); + +try { +module.exports = jsPDF; +} +catch (e) {} diff --git a/dist/jspdf.worker.min.js b/dist/jspdf.worker.min.js new file mode 100644 index 000000000..fe3bc642d --- /dev/null +++ b/dist/jspdf.worker.min.js @@ -0,0 +1,351 @@ +"use strict"; +/** @license + * + * jsPDF - PDF Document creation from JavaScript + * Version 1.5.3 Built on 2022-08-17T11:04:02.248Z + * CommitID b3ccdf139d + * + * Copyright (c) 2010-2018 James Hall , https://github.com/MrRio/jsPDF + * 2015-2018 yWorks GmbH, http://www.yworks.com + * 2015-2018 Lukas Holländer , https://github.com/HackbrettXXX + * 2016-2018 Aras Abbasi + * 2010 Aaron Spike, https://github.com/acspike + * 2012 Willow Systems Corporation, willow-systems.com + * 2012 Pablo Hess, https://github.com/pablohess + * 2012 Florian Jenett, https://github.com/fjenett + * 2013 Warren Weckesser, https://github.com/warrenweckesser + * 2013 Youssef Beddad, https://github.com/lifof + * 2013 Lee Driscoll, https://github.com/lsdriscoll + * 2013 Stefan Slonevskiy, https://github.com/stefslon + * 2013 Jeremy Morel, https://github.com/jmorel + * 2013 Christoph Hartmann, https://github.com/chris-rock + * 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria + * 2014 James Makes, https://github.com/dollaruw + * 2014 Diego Casorran, https://github.com/diegocr + * 2014 Steven Spungin, https://github.com/Flamenco + * 2014 Kenneth Glassey, https://github.com/Gavvers + * + * Licensed under the MIT License + * + * Contributor(s): + * siefkenj, ahwolf, rickygu, Midnith, saintclair, eaparango, + * kim3er, mfo, alnorth, Flamenco + */function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}window={};var jsPDF=function(ar){function sr(a){if("object"!==_typeof(a))throw new Error("Invalid Context passed to initialize PubSub (jsPDF-module)");var s={};this.subscribe=function(t,e,r){if(r=r||!1,"string"!=typeof t||"function"!=typeof e||"boolean"!=typeof r)throw new Error("Invalid arguments passed to PubSub.subscribe (jsPDF-module)");s.hasOwnProperty(t)||(s[t]={});var n=Math.random().toString(35);return s[t][n]=[e,!!r],n},this.unsubscribe=function(t){for(var e in s)if(s[e][t])return delete s[e][t],0===Object.keys(s[e]).length&&delete s[e],!0;return!1},this.publish=function(t){if(s.hasOwnProperty(t)){var e=Array.prototype.slice.call(arguments,1),r=[];for(var n in s[t]){var i=s[t][n];try{i[0].apply(a,e)}catch(t){ar.console&&console.error("jsPDF PubSub Error",t.message,t)}i[1]&&r.push(n)}r.length&&r.forEach(this.unsubscribe)}},this.getTopics=function(){return s}}function or(t){var n,a="string"==typeof arguments[0]?arguments[0]:"p",e=arguments[1],s=arguments[2],r=arguments[3],i=[],o=1,u=16,c="S";"object"===_typeof(t=t||{})&&(a=t.orientation,e=t.unit||e,s=t.format||s,r=t.compress||t.compressPdf||r,o="number"==typeof t.userUnit?Math.abs(t.userUnit):1,void 0!==t.precision&&(n=t.precision),void 0!==t.floatPrecision&&(u=t.floatPrecision),c=t.defaultPathOperation||"S"),i=t.filters||(!0===r?["FlateEncode"]:i),e=e||"mm",a=(""+(a||"P")).toLowerCase();var h=t.putOnlyUsedFonts||!1,et={},l={internal:{},__private__:{}};l.__private__.PubSub=sr;var f="1.3",d=l.__private__.getPdfVersion=function(){return f};l.__private__.setPdfVersion=function(t){f=t};var p={a0:[2383.94,3370.39],a1:[1683.78,2383.94],a2:[1190.55,1683.78],a3:[841.89,1190.55],a4:[595.28,841.89],a5:[419.53,595.28],a6:[297.64,419.53],a7:[209.76,297.64],a8:[147.4,209.76],a9:[104.88,147.4],a10:[73.7,104.88],b0:[2834.65,4008.19],b1:[2004.09,2834.65],b2:[1417.32,2004.09],b3:[1000.63,1417.32],b4:[708.66,1000.63],b5:[498.9,708.66],b6:[354.33,498.9],b7:[249.45,354.33],b8:[175.75,249.45],b9:[124.72,175.75],b10:[87.87,124.72],c0:[2599.37,3676.54],c1:[1836.85,2599.37],c2:[1298.27,1836.85],c3:[918.43,1298.27],c4:[649.13,918.43],c5:[459.21,649.13],c6:[323.15,459.21],c7:[229.61,323.15],c8:[161.57,229.61],c9:[113.39,161.57],c10:[79.37,113.39],dl:[311.81,623.62],letter:[612,792],"government-letter":[576,756],legal:[612,1008],"junior-legal":[576,360],ledger:[1224,792],tabloid:[792,1224],"credit-card":[153,243]};l.__private__.getPageFormats=function(){return p};var g=l.__private__.getPageFormat=function(t){return p[t]};s=s||"a4";var m="compat",rt="advanced",nt=m;function v(){this.saveGraphicsState(),ot(new It(tt,0,0,-tt,0,nr()*tt).toString()+" cm"),this.setFontSize(this.getFontSize()/tt),c="n",nt=rt}function b(){this.restoreGraphicsState(),c="S",nt=m}l.advancedAPI=function(t){var e=nt===m;return e&&v.call(this),"function"!=typeof t||(t(this),e&&b.call(this)),this},l.compatAPI=function(t){var e=nt===rt;return e&&b.call(this),"function"!=typeof t||(t(this),e&&v.call(this)),this},l.isAdvancedAPI=function(){return nt===rt};function it(t){if(nt!==rt)throw new Error(t+" is only available in 'advanced' API mode. You need to call advancedAPI() first.")}var at,y=l.roundToPrecision=l.__private__.roundToPrecision=function(t,e){var r=n||e;if(isNaN(t)||isNaN(r))throw new Error("Invalid argument passed to jsPDF.roundToPrecision");return t.toFixed(r).replace(/0+$/,"")};at=l.hpf=l.__private__.hpf="number"==typeof u?function(t){if(isNaN(t))throw new Error("Invalid argument passed to jsPDF.hpf");return y(t,u)}:"smart"===u?function(t){if(isNaN(t))throw new Error("Invalid argument passed to jsPDF.hpf");return y(t,-1t[u+1].offset;)u++;var h=t[u].offset,l=(r-h)/(t[u+1].offset-h),f=t[u].color,d=t[u+1].color;o+=M(Math.round((1-l)*f[0]+l*d[0]).toString(16))+M(Math.round((1-l)*f[1]+l*d[1]).toString(16))+M(Math.round((1-l)*f[2]+l*d[2]).toString(16))}return o.trim()}(t.colors,e),i=[];i.push({key:"FunctionType",value:"0"}),i.push({key:"Domain",value:"[0.0 1.0]"}),i.push({key:"Size",value:"["+e+"]"}),i.push({key:"BitsPerSample",value:"8"}),i.push({key:"Range",value:"[0.0 1.0 0.0 1.0 0.0 1.0]"}),i.push({key:"Decode",value:"[0.0 1.0 0.0 1.0 0.0 1.0]"}),ee({data:n,additionalKeyValues:i,alreadyAppliedFilters:["/ASCIIHexDecode"]}),ot("endobj"),t.objectNumber=Vt(),ot("<< /ShadingType "+t.type),ot("/ColorSpace /DeviceRGB");var a="/Coords ["+at(parseFloat(t.coords[0]))+" "+at(parseFloat(t.coords[1]))+" ";2===t.type?a+=at(parseFloat(t.coords[2]))+" "+at(parseFloat(t.coords[3])):a+=at(parseFloat(t.coords[2]))+" "+at(parseFloat(t.coords[3]))+" "+at(parseFloat(t.coords[4]))+" "+at(parseFloat(t.coords[5])),ot(a+="]"),t.matrix&&ot("/Matrix ["+t.matrix.toString()+"]"),ot("/Function "+r+" 0 R"),ot("/Extend [true true]"),ot(">>"),ot("endobj")}function Et(t,e){var r=Jt(),n=Vt();e.push({resourcesOid:r,objectOid:n}),t.objectNumber=n;var i=[];i.push({key:"Type",value:"/Pattern"}),i.push({key:"PatternType",value:"1"}),i.push({key:"PaintType",value:"1"}),i.push({key:"TilingType",value:"1"}),i.push({key:"BBox",value:"["+t.boundingBox.map(at).join(" ")+"]"}),i.push({key:"XStep",value:at(t.xStep)}),i.push({key:"YStep",value:at(t.yStep)}),i.push({key:"Resources",value:r+" 0 R"}),t.matrix&&i.push({key:"Matrix",value:"["+t.matrix.toString()+"]"}),ee({data:t.stream,additionalKeyValues:i}),ot("endobj")}function Dt(t){for(var e in t.objectNumber=Vt(),ot("<<"),t)switch(e){case"opacity":ot("/ca "+L(t[e]));break;case"stroke-opacity":ot("/CA "+L(t[e]))}ot(">>"),ot("endobj")}function Tt(t){Yt(t.resourcesOid,!0),ot("<<"),ot("/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]"),function(){for(var t in ot("/Font <<"),pt)!pt.hasOwnProperty(t)||(!1===h||!0===h&&et.hasOwnProperty(t))&&ot("/"+t+" "+pt[t].objectNumber+" 0 R");ot(">>")}(),function(){if(0>")}}(),function(t){if(0>")}}(t.objectOid),function(){if(0>")}}(),function(){for(var t in ot("/XObject <<"),St)St.hasOwnProperty(t)&&0<=St[t].objectNumber&&ot("/"+t+" "+St[t].objectNumber+" 0 R");xt.publish("putXobjectDict"),ot(">>")}(),ot(">>"),ot("endobj")}function Rt(){var t=[];!function(){for(var t in pt)!pt.hasOwnProperty(t)||(!1===h||!0===h&&et.hasOwnProperty(t))&&(r=pt[t],xt.publish("putFont",{font:r,out:ot,newObject:Vt,putStream:ee,pdfEscapeWithNeededParanthesis:e}),!0!==r.isAlreadyPutted&&(r.objectNumber=Vt(),ot("<<"),ot("/Type /Font"),ot("/BaseFont /"+e(r.postScriptName)),ot("/Subtype /Type1"),"string"==typeof r.encoding&&ot("/Encoding /"+r.encoding),ot("/FirstChar 32"),ot("/LastChar 255"),ot(">>"),ot("endobj")));function e(t,e){return-1!==t.indexOf(" ")?"("+ie(t,e)+")":ie(t,e)}var r}(),function(){var t;for(t in yt)yt.hasOwnProperty(t)&&Dt(yt[t])}(),function(){for(var t in St)St.hasOwnProperty(t)&&qt(St[t])}(),function(t){var e;for(e in vt)vt.hasOwnProperty(e)&&(vt[e]instanceof l.ShadingPattern?Bt(vt[e]):vt[e]instanceof l.TilingPattern&&Et(vt[e],t))}(t),xt.publish("putResources"),t.forEach(Tt),Tt({resourcesOid:Zt,objectOid:Number.MAX_SAFE_INTEGER}),xt.publish("postPutResources")}function Ot(t){gt[t.fontName]=gt[t.fontName]||{},gt[t.fontName][t.fontStyle]=t.id}function Ut(t,e,r,n,i){var a={id:"F"+(Object.keys(pt).length+1).toString(10),postScriptName:t,fontName:e,fontStyle:r,encoding:n,isStandardFont:i||!1,metadata:{}};return xt.publish("addFont",{font:a,instance:this}),pt[a.id]=a,Ot(a),a.id}function zt(t,e){var r,n,i;switch(a=e||a,"string"==typeof t&&(r=g(t.toLowerCase()),Array.isArray(r)&&(n=r[0],i=r[1])),Array.isArray(t)&&(n=t[0]*tt,i=t[1]*tt),isNaN(n)&&(n=s[0],i=s[1]),(14400>16&255,n=u>>8&255,i=255&u}if(void 0===n||void 0===a&&r===n&&n===i)if("string"==typeof r)e=r+" "+s[0];else switch(t.precision){case 2:e=L(r/255)+" "+s[0];break;case 3:default:e=N(r/255)+" "+s[0]}else if(void 0===a||"object"===_typeof(a)){if(a&&!isNaN(a.a)&&0===a.a)return e=["1.","1.","1.",s[1]].join(" ");if("string"==typeof r)e=[r,n,i,s[1]].join(" ");else switch(t.precision){case 2:e=[L(r/255),L(n/255),L(i/255),s[1]].join(" ");break;default:case 3:e=[N(r/255),N(n/255),N(i/255),s[1]].join(" ")}}else if("string"==typeof r)e=[r,n,i,a,s[2]].join(" ");else switch(t.precision){case 2:e=[L(r),L(n),L(i),L(a),s[2]].join(" ");break;case 3:default:e=[N(r),N(n),N(i),N(a),s[2]].join(" ")}return e},te=l.__private__.getFilters=function(){return i},ee=l.__private__.putStream=function(t){var e=(t=t||{}).data||"",r=t.filters||te(),n=t.alreadyAppliedFilters||[],i=t.addLength1||!1,a=e.length,s={};!0===r&&(r=["FlateEncode"]);var o=t.additionalKeyValues||[],u=(s=void 0!==or.API.processDataByFilters?or.API.processDataByFilters(e,r):{data:e,reverseChain:[]}).reverseChain+(Array.isArray(n)?n.join(" "):n.toString());if(0!==s.data.length&&(o.push({key:"Length",value:s.data.length}),!0===i&&o.push({key:"Length1",value:a})),0!=u.length)if(u.split("/").length-1==1)o.push({key:"Filter",value:u});else{o.push({key:"Filter",value:"["+u+"]"});for(var c=0;c>"),0!==s.data.length&&(ot("stream"),ot(s.data),ot("endstream"))},re=l.__private__.putPage=function(t){var e=t.number,r=t.data,n=t.objId,i=t.contentsObjId;Yt(n,!0),ot("<>"),ot("endobj");var a=r.join("\n");return nt===rt&&(a+="\nQ"),Yt(i,!0),ee({data:a,filters:te()}),ot("endobj"),n},ne=l.__private__.putPages=function(){var t,e,r=[];for(t=1;t<=Nt;t++)At[t].objId=Jt(),At[t].contentsObjId=Jt();for(t=1;t<=Nt;t++)r.push(re({number:t,data:R[t],objId:At[t].objId,contentsObjId:At[t].contentsObjId,mediaBox:At[t].mediaBox,cropBox:At[t].cropBox,bleedBox:At[t].bleedBox,trimBox:At[t].trimBox,artBox:At[t].artBox,userUnit:At[t].userUnit,rootDictionaryObjId:Kt,resourceDictionaryObjId:Zt}));Yt(Kt,!0),ot("<>"),ot("endobj"),xt.publish("postPutPages")},ie=l.__private__.pdfEscape=l.pdfEscape=function(t,e){return function(t,e){var r,n,i,a,s,o,u,c,h;if(i=(e=e||{}).sourceEncoding||"Unicode",s=e.outputEncoding,(e.autoencode||s)&&pt[ht].metadata&&pt[ht].metadata[i]&&pt[ht].metadata[i].encoding&&(a=pt[ht].metadata[i].encoding,!s&&pt[ht].encoding&&(s=pt[ht].encoding),!s&&a.codePages&&(s=a.codePages[0]),"string"==typeof s&&(s=a[s]),s)){for(u=!1,o=[],r=0,n=t.length;r>8&&(u=!0);t=o.join("")}for(r=t.length;void 0===u&&0!==r;)t.charCodeAt(r-1)>>8&&(u=!0),r--;if(!u)return t;for(o=e.noBOM?[]:[254,255],r=0,n=t.length;r>8)>>8)throw new Error("Character at position "+r+" of string '"+t+"' exceeds 16bits. Cannot be encoded into UCS-2 BE");o.push(h),o.push(c-(h<<8))}return String.fromCharCode.apply(void 0,o)}(t,e).replace(/\\/g,"\\\\").replace(/\(/g,"\\(").replace(/\)/g,"\\)")},ae=l.__private__.beginPage=function(t){R[++Nt]=[],At[Nt]={objId:0,contentsObjId:0,userUnit:Number(o),artBox:null,bleedBox:null,cropBox:null,trimBox:null,mediaBox:{bottomLeftX:0,bottomLeftY:0,topRightX:Number(t[0]),topRightY:Number(t[1])}},se(Nt),z(R[F])},se=function(t){0>"),ot("endobj")},ce=l.__private__.putCatalog=function(t){var e=(t=t||{}).rootDictionaryObjId||Kt;switch(Vt(),ot("<<"),ot("/Type /Catalog"),ot("/Pages "+e+" 0 R"),V||(V="fullwidth"),V){case"fullwidth":ot("/OpenAction [3 0 R /FitH null]");break;case"fullheight":ot("/OpenAction [3 0 R /FitV null]");break;case"fullpage":ot("/OpenAction [3 0 R /Fit]");break;case"original":ot("/OpenAction [3 0 R /XYZ null null 1]");break;default:var r=""+V;"%"===r.substr(r.length-1)&&(V=parseInt(V)/100),"number"==typeof V&&ot("/OpenAction [3 0 R /XYZ null null "+L(V)+"]")}switch(K||(K="continuous"),K){case"continuous":ot("/PageLayout /OneColumn");break;case"single":ot("/PageLayout /SinglePage");break;case"two":case"twoleft":ot("/PageLayout /TwoColumnLeft");break;case"tworight":ot("/PageLayout /TwoColumnRight")}Y&&ot("/PageMode /"+Y),xt.publish("putCatalog"),ot(">>"),ot("endobj")},he=l.__private__.putTrailer=function(){ot("trailer"),ot("<<"),ot("/Size "+(q+1)),ot("/Root "+q+" 0 R"),ot("/Info "+(q-1)+" 0 R"),ot("/ID [ <"+x+"> <"+x+"> ]"),ot(">>")},le=l.__private__.putHeader=function(){ot("%PDF-"+f),ot("%ºß¬à")},fe=l.__private__.putXRef=function(){var t="0000000000";ot("xref"),ot("0 "+(q+1)),ot("0000000000 65535 f");for(var e=1;e<=q;e++){"function"==typeof B[e]?ot((t+B[e]()).slice(-10)+" 00000 n"):void 0!==B[e]?ot((t+B[e]).slice(-10)+" 00000 n"):ot("0000000000 00000 n")}},de=l.__private__.buildDocument=function(){D=q=0,E=[],B=[],T=[],Kt=Jt(),Zt=Jt(),z(E),xt.publish("buildDocument"),le(),ne(),function(){xt.publish("putAdditionalObjects");for(var t=0;t<\/script>