1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00
invoiceninja/public/js/jspdf.min.js

140 lines
80 KiB
JavaScript
Raw Normal View History

2014-03-18 19:55:50 +01:00
/**
* jsPDF - PDF Document creation from JavaScript
* Version 1.0.0-trunk Built on 2014-03-10T05:30
* Commit dbb2fbceea2f397d479b802fa4fdf10e6d7c6963
*
* Copyright (c) 2010-2014 James Hall, https://github.com/MrRio/jsPDF
* 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
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Contributor(s):
* siefkenj, ahwolf, rickygu, Midnith, saintclair, eaparango,
* kim3er, mfo, alnorth,
*/
/**
* jsPDF addImage plugin (JPEG only at this time)
* 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
*/
/**
* jsPDF Cell plugin
* 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
*/
/**
* jsPDF fromHTML plugin. BETA stage. API subject to change. Needs browser, jQuery
* Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
* 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
* 2014 Diego Casorran, https://github.com/diegocr
*/
/**
* jsPDF JavaScript plugin
* Copyright (c) 2013 Youssef Beddad, youssef.beddad@gmail.com
*/
/**
2013-11-26 13:45:07 +01:00
jsPDF Silly SVG plugin
Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
2014-03-18 19:55:50 +01:00
*/
/**
2013-11-26 13:45:07 +01:00
jsPDF split_text_to_size plugin
Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
MIT license.
2014-03-18 19:55:50 +01:00
*/
/**
2013-11-26 13:45:07 +01:00
jsPDF standard_fonts_metrics plugin
Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
MIT license.
*/
2014-03-18 19:55:50 +01:00
/**
* jsPDF total_pages plugin
* Copyright (c) 2013 Eduardo Menezes de Morais, eduardo.morais@usp.br
*/
/* Blob.js
* A Blob implementation.
* 2013-12-27
* By Eli Grey, http://eligrey.com
* By Devin Samarin, https://github.com/eboyjr
* License: X11/MIT
* See LICENSE.md
*/
/*! FileSaver.js
* A saveAs() FileSaver implementation.
* 2014-01-24
* By Eli Grey, http://eligrey.com
* License: X11/MIT
* See LICENSE.md
*/
/*
* Copyright (c) 2012 chick307 <chick307@gmail.com>
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/*
Deflate.js - https://github.com/gildas-lormeau/zip.js
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.
*/
/**
* JavaScript Polyfill functions for jsPDF
* Collected from public resources by
* https://github.com/diegocr
*/
!function(t,e){if(e["true"]=t,"function"!=typeof n&&"object"!=typeof n||"undefined"==typeof URL)if("function"!=typeof n&&"object"!=typeof n||"undefined"==typeof webkitURL)var n=function(t){"use strict";var e=t.BlobBuilder||t.WebKitBlobBuilder||t.MozBlobBuilder||t.MSBlobBuilder||function(t){var e=function(t){return Object.prototype.toString.call(t).match(/^\[object\s(.*)\]$/)[1]},n=function(){this.data=[]},r=function(t,e,n){this.data=t,this.size=t.length,this.type=e,this.encoding=n},s=n.prototype,o=r.prototype,i=t.FileReaderSync,a=function(t){this.code=this[this.name=t]},u="NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR".split(" "),c=u.length,l=t.URL||t.webkitURL||t,f=l.createObjectURL,d=l.revokeObjectURL,w=l,m=t.btoa,p=t.atob,h=t.ArrayBuffer,v=t.Uint8Array;for(r.fake=o.fake=!0;c--;)a.prototype[u[c]]=c+1;return l.createObjectURL||(w=t.URL={}),w.createObjectURL=function(t){var e,n=t.type;return null===n&&(n="application/octet-stream"),t instanceof r?(e="data:"+n,"base64"===t.encoding?e+";base64,"+t.data:"URI"===t.encoding?e+","+decodeURIComponent(t.data):m?e+";base64,"+m(t.data):e+","+encodeURIComponent(t.data)):f?f.call(l,t):void 0},w.revokeObjectURL=function(t){"data:"!==t.substring(0,5)&&d&&d.call(l,t)},s.append=function(t){var n=this.data;if(v&&(t instanceof h||t instanceof v)){for(var s="",o=new v(t),u=0,c=o.length;c>u;u++)s+=String.fromCharCode(o[u]);n.push(s)}else if("Blob"===e(t)||"File"===e(t)){if(!i)throw new a("NOT_READABLE_ERR");var l=new i;n.push(l.readAsBinaryString(t))}else t instanceof r?"base64"===t.encoding&&p?n.push(p(t.data)):"URI"===t.encoding?n.push(decodeURIComponent(t.data)):"raw"===t.encoding&&n.push(t.data):("string"!=typeof t&&(t+=""),n.push(unescape(encodeURIComponent(t))))},s.getBlob=function(t){return arguments.length||(t=null),new r(this.data.join(""),t,"raw")},s.toString=function(){return"[object BlobBuilder]"},o.slice=function(t,e,n){var s=arguments.length;return 3>s&&(n=null),new r(this.data.slice(t,s>1?e:this.data.length),n,this.encoding)},o.toString=function(){return"[object Blob]"},n}(t);return function(t,n){var r=n?n.type||"":"",s=new e;if(t)for(var o=0,i=t.length;i>o;o++)s.append(t[o]);return s.getBlob(r)}}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content||this);else self.URL=webkitURL;var r=r||"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob&&navigator.msSaveOrOpenBlob.bind(navigator)||function(t){"use strict";if("undefined"==typeof navigator||!/MSIE [1-9]\./.test(navigator.userAgent)){var e=t.document,n=function(){return t.URL||t.webkitURL||t},r=t.URL||t.webkitURL||t,s=e.createElementNS("http://www.w3.org/1999/xhtml","a"),o=!t.externalHost&&"download"in s,i=t.webkitRequestFileSystem,a=t.requestFileSystem||i||t.mozRequestFileSystem,u=function(e){(t.setImmediate||t.setTimeout)(function(){throw e},0)},c="application/octet-stream",l=0,f=[],d=function(){for(var t=f.length;t--;){var e=f[t];"string"==typeof e?r.revokeObjectURL(e):e.remove()}f.length=0},w=function(t,e,n){e=[].concat(e);for(var r=e.length;r--;){var s=t["on"+e[r]];if("function"==typeof s)try{s.call(t,n||t)}catch(o){u(o)}}},m=function(r,u){var d,m,p,h=this,v=r.type,y=!1,g=function(){var t=n().createObjectURL(r);return f.push(t),t},q=function(){w(h,"writestart progress write writeend".split(" "))},b=function(){(y||!d)&&(d=g(r)),m?m.location.href=d:window.open(d,"_blank"),h.readyState=h.DONE,q()},x=function(t){return function(){return h.readyState!==h.DONE?t.apply(this,arguments):void 0}},k={create:!0,exclusive:!1};if(h.readyState=h.INIT,u||(u="download"),o){d=g(r),e=t.document,s=e.createElementNS("http://www.w3.org/1999/xhtml","a"),s.href=d,s.download=u;var _=e.createEvent("MouseEvents");return _.initMouseEvent("click",!0,!1,t,0,0,0,0,0,!1,!1,!1,!1,0,null),s.dispatchEvent(_),h.readyState=h.DONE,q(),void 0}return t.chrome&&v&&v!==c&&(p=r.slice||r.webkitSlice,r=p.call(r,0,r.size,c),y=!0),i&&"download"!==u&&(u+=".download"),(v===c||i)&&(m=t),a?(l+=r.size,a(t.TEMPORARY,l,x(function(t){t.root.getDirectory("saved",k,
},ne=function(t,e){return ee(t,e).replace(/\\/g,"\\\\").replace(/\(/g,"\\(").replace(/\)/g,"\\)")},re=function(){H("/Producer (jsPDF "+o.version+")");for(var t in I)I.hasOwnProperty(t)&&H("/"+t.substr(0,1).toUpperCase()+t.substr(1)+" ("+ne(I[t])+")");var e=new Date;H(["/CreationDate (D:",e.getFullYear(),D(e.getMonth()+1),D(e.getDate()),D(e.getHours()),D(e.getMinutes()),D(e.getSeconds()),")"].join(""))},se=function(){H("/Type /Catalog"),H("/Pages 1 0 R"),H("/OpenAction [3 0 R /FitH null]"),H("/PageLayout /OneColumn"),U.publish("putCatalog")},oe=function(){H("/Size "+(z+1)),H("/Root "+z+" 0 R"),H("/Info "+(z-1)+" 0 R")},ie=function(){E++,S=!0,F[E]=[]},ae=function(){ie(),H(L(_*m)+" w"),H(b),0!==j&&H(j.toString(10)+" J"),0!==P&&H(P.toString(10)+" j"),U.publish("addPage",{pageNumber:E})},ue=function(t,e){var n;t=void 0!==t?t:C[w].fontName,e=void 0!==e?e:C[w].fontStyle;try{n=R[t][e]}catch(r){}if(!n)throw new Error("Unable to look up font label for font '"+t+"', '"+e+"'. Refer to getFontList() for available fonts.");return n},ce=function(){S=!1,z=2,T=[],A=[],H("%PDF-"+i),W(),Y(),M(),H("<<"),re(),H(">>"),H("endobj"),M(),H("<<"),se(),H(">>"),H("endobj");var t,e=O,n="0000000000";for(H("xref"),H("0 "+(z+1)),H(n+" 65535 f "),t=1;z>=t;t++)H((n+A[t]).slice(-10)+" 00000 n ");return H("trailer"),H("<<"),oe(),H(">>"),H("startxref"),H(e),H("%%EOF"),S=!0,T.join("\n")},le=function(t){var e="S";return"F"===t?e="f":("FD"===t||"DF"===t)&&(e="B"),e},fe=function(){for(var t=ce(),e=t.length,r=new ArrayBuffer(e),s=new Uint8Array(r);e--;)s[e]=t.charCodeAt(e);return new n([r],{type:"application/pdf"})},de=te(function(e,n){switch(e){case void 0:return ce();case"save":if(navigator.getUserMedia&&(void 0===t.URL||void 0===t.URL.createObjectURL))return B.output("dataurlnewwindow");r(fe(),n),"function"==typeof r.unload&&r.unload();break;case"blob":return fe();case"datauristring":case"dataurlstring":return"data:application/pdf;base64,"+btoa(ce());case"datauri":case"dataurl":t.document.location.href="data:application/pdf;base64,"+btoa(ce());break;case"dataurlnewwindow":t.open("data:application/pdf;base64,"+btoa(ce()));break;default:throw new Error('Output type "'+e+'" is not supported.')}});if("pt"===c)m=1;else if("mm"===c)m=72/25.4;else if("cm"===c)m=72/2.54;else{if("in"!==c)throw"Invalid unit: "+c;m=72}if(a.hasOwnProperty(y))v=a[y][1]/m,h=a[y][0]/m;else try{v=l[1],h=l[0]}catch(we){throw new Error("Invalid format: "+l)}if("p"===u||"portrait"===u)u="p",h>v&&(p=h,h=v,v=p);else{if("l"!==u&&"landscape"!==u)throw"Invalid orientation: "+u;u="l",v>h&&(p=h,h=v,v=p)}B.internal={pdfEscape:ne,getStyle:le,getFont:function(){return C[ue.apply(B,arguments)]},getFontSize:function(){return x},getLineHeight:function(){return x*k},write:function(t){H(1===arguments.length?t:Array.prototype.join.call(arguments," "))},getCoordinateString:function(t){return L(t*m)},getVerticalCoordinateString:function(t){return L((v-t)*m)},collections:{},newObject:M,putStream:J,events:U,scaleFactor:m,pageSize:{width:h,height:v},output:function(t,e){return de(t,e)},getNumberOfPages:function(){return F.length-1},pages:F},B.addPage=function(){return ae(),this},B.text=function(t,e,n,r,s){"number"==typeof t&&(p=n,n=e,e=t,t=p),"string"==typeof t&&t.match(/[\n\r]/)&&(t=t.split(/\r\n|\r|\n/g)),"number"==typeof r&&(s=r,r=null);var o="",i="Td";if(s){s*=Math.PI/180;var a=Math.cos(s),u=Math.sin(s);o=[L(a),L(u),L(-1*u),L(a),""].join(" "),i="Tm"}if(r=r||{},"noBOM"in r||(r.noBOM=!0),"autoencode"in r||(r.autoencode=!0),"string"==typeof t)t=ne(t,r);else{if(!(t instanceof Array))throw new Error('Type of text must be string or Array. "'+t+'" is not recognized.');for(var c=t.concat(),l=[],f=c.length;f--;)l.push(ne(c.shift(),r));t=l.join(") Tj\nT* (")}return H("BT\n/"+w+" "+x+" Tf\n"+x*k+" TL\n"+q+"\n"+o+L(e*m)+" "+L((v-n)*m)+" "+i+"\n("+t+") Tj\nET"),this},B.line=function(t,e,n,r){return H(L(t*m)+" "+L((v-e)*m)+" m "+L(n*m)+" "+L((v-r)*m)+" l S"),this},B.lines=function(t,e,n,r,s,o){var i,a,u,c,l,f,d,w,h,y,g;for("number"==typeof t&&(p=n,n=e,e=t,t=p),r=r||[1,1],H(N(e*m)+" "+N((v-n)*m)+" m "),i=r[0],a=r[1],c=t.lengt
t.events.push(["addFonts",function(t){var e,n,o,i,a,u="Unicode";for(n in t.fonts)t.fonts.hasOwnProperty(n)&&(e=t.fonts[n],o=s[u][e.PostScriptName],o&&(i=e.metadata[u]?e.metadata[u]:e.metadata[u]={},i.widths=o.widths,i.kerning=o.kerning),a=r[u][e.PostScriptName],a&&(i=e.metadata[u]?e.metadata[u]:e.metadata[u]={},i.encoding=a,a.codePages&&a.codePages.length&&(e.encoding=a.codePages[0])))}])}(o.API),function(t){"use strict";t.putTotalPages=function(t){for(var e=new RegExp(t,"g"),n=1;n<=this.internal.getNumberOfPages();n++)for(var r=0;r<this.internal.pages[n].length;r++)this.internal.pages[n][r]=this.internal.pages[n][r].replace(e,this.internal.getNumberOfPages());return this}}(o.API)}({},function(){return this}());