You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
37 KiB
JavaScript
29 lines
37 KiB
JavaScript
2 months ago
|
/**
|
||
|
svg2pdf.js
|
||
|
The MIT License (MIT)
|
||
|
Copyright (c) 2015-2016 yWorks GmbH
|
||
|
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.
|
||
|
*/
|
||
|
/**
|
||
|
* RGBColor.js: A class to parse color values
|
||
|
* @author Stoyan Stefanov <sstoo@gmail.com>
|
||
|
* @link http://www.phpied.com/rgb-color-parser-in-javascript/
|
||
|
* @license Use it if you like it
|
||
|
*/
|
||
|
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.svg2pdf=t()}}(function(){var t;return function t(e,r,a){function i(s,o){if(!r[s]){if(!e[s]){var u="function"==typeof require&&require;if(!o&&u)return u(s,!0);if(n)return n(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var h=r[s]={exports:{}};e[s][0].call(h.exports,function(t){var r=e[s][1][t];return i(r?r:t)},h,h.exports,t,e,r,a)}return r[s].exports}for(var n="function"==typeof require&&require,s=0;s<a.length;s++)i(a[s]);return i}({1:[function(t,e,r){"use strict";e.exports=t("./lib/svgpath")},{"./lib/svgpath":6}],2:[function(t,e,r){"use strict";function a(t,e,r,a){var i=t*a-e*r<0?-1:1,n=Math.sqrt(t*t+e*e),s=Math.sqrt(t*t+e*e),o=t*r+e*a,u=o/(n*s);return u>1&&(u=1),u<-1&&(u=-1),i*Math.acos(u)}function i(t,e,r,i,n,o,u,c,h,f){var l=f*(t-r)/2+h*(e-i)/2,d=-h*(t-r)/2+f*(e-i)/2,g=u*u,p=c*c,b=l*l,x=d*d,m=g*p-g*x-p*b;m<0&&(m=0),m/=g*x+p*b,m=Math.sqrt(m)*(n===o?-1:1);var v=m*u/c*d,y=m*-c/u*l,A=f*v-h*y+(t+r)/2,k=h*v+f*y+(e+i)/2,w=(l-v)/u,M=(d-y)/c,F=(-l-v)/u,C=(-d-y)/c,S=a(1,0,w,M),I=a(w,M,F,C);return 0===o&&I>0&&(I-=s),1===o&&I<0&&(I+=s),[A,k,S,I]}function n(t,e){var r=4/3*Math.tan(e/4),a=Math.cos(t),i=Math.sin(t),n=Math.cos(t+e),s=Math.sin(t+e);return[a,i,a-i*r,i+a*r,n+s*r,s-n*r,n,s]}var s=2*Math.PI;e.exports=function(t,e,r,a,o,u,c,h,f){var l=Math.sin(f*s/360),d=Math.cos(f*s/360),g=d*(t-r)/2+l*(e-a)/2,p=-l*(t-r)/2+d*(e-a)/2;if(0===g&&0===p)return[];if(0===c||0===h)return[];c=Math.abs(c),h=Math.abs(h);var b=g*g/(c*c)+p*p/(h*h);b>1&&(c*=Math.sqrt(b),h*=Math.sqrt(b));var x=i(t,e,r,a,o,u,c,h,l,d),m=[],v=x[2],y=x[3],A=Math.max(Math.ceil(Math.abs(y)/(s/4)),1);y/=A;for(var k=0;k<A;k++)m.push(n(v,y)),v+=y;return m.map(function(t){for(var e=0;e<t.length;e+=2){var r=t[e+0],a=t[e+1];r*=c,a*=h;var i=d*r-l*a,n=l*r+d*a;t[e+0]=i+x[0],t[e+1]=n+x[1]}return t})}},{}],3:[function(t,e,r){"use strict";function a(t,e,r){return this instanceof a?(this.rx=t,this.ry=e,void(this.ax=r)):new a(t,e,r)}var i=1e-10,n=Math.PI/180;a.prototype.transform=function(t){var e=Math.cos(this.ax*n),r=Math.sin(this.ax*n),a=[this.rx*(t[0]*e+t[2]*r),this.rx*(t[1]*e+t[3]*r),this.ry*(-t[0]*r+t[2]*e),this.ry*(-t[1]*r+t[3]*e)],s=a[0]*a[0]+a[2]*a[2],o=a[1]*a[1]+a[3]*a[3],u=((a[0]-a[3])*(a[0]-a[3])+(a[2]+a[1])*(a[2]+a[1]))*((a[0]+a[3])*(a[0]+a[3])+(a[2]-a[1])*(a[2]-a[1])),c=(s+o)/2;if(u<i*c)return this.rx=this.ry=Math.sqrt(c),this.ax=0,this;var h=a[0]*a[1]+a[2]*a[3];u=Math.sqrt(u);var f=c+u/2,l=c-u/2;return this.ax=Math.abs(h)<i&&Math.abs(f-o)<i?90:180*Math.atan(Math.abs(h)>Math.abs(f-o)?(f-s)/h:h/(f-o))/Math.PI,this.ax>=0?(this.rx=Math.sqrt(f),this.ry=Math.sqrt(l)):(this.ax+=90,this.rx=Math.sqrt(l),this.ry=Math.sqrt(f)),this},a.prototype.isDegenerate=function(){return this.rx<i*this.ry||this.ry<i*this.rx},e.exports=a},{}],4:[function(t,e,r){"use strict";function a(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}function i(){return this instanceof i?(this.queue=[],void(this.cache=null)):new i}i.prototype.matrix=function(t){return 1===t[0]&&0===t[1]&&0===t[2]&&1===t[3]&&0===t[4]&&0===t[5]?this:(this.cache=null,this.queue.push(t),this)},i.prototype.translate=function(t,e){return 0===t&&0===e||(this.cache=null,this.queue.push([1,0,0,1,t,e])),this},i.prototype.scale=function(t,e){return 1===t&&1===e||(this.cache=null,this.queue.push([t,0,0,e,0,0])),this},i.prototype.rotate=function(t,e,r){var a,i,n;return 0!==t&&(this.translate(e,r),a=t*Math.PI/180,i=Math.cos(a),n=Math.sin(a),this.queue.push([i,n,-n,i,0,0]),this.cache=null,this.translate(-e,-r)),this},i.prototype.skewX=function(t){return 0!==t&&(this.cache=null,this.queue.push([1,0,Math.tan(t*Math.PI/180),1,0,0])),this},i.prototype.skewY=function(t){return 0!==t&&(this.cache=null,this.queue.push([1,Math.tan(t*Math.PI/180),0,1,0,0])),this},i.
|
||
|
h=!0)}}),h&&(s=new o.GState({opacity:c/r.length}));var l=new o.ShadingPattern(e,r,u,s),g=i.get()+t.getAttribute("id");o.addShadingPattern(g,l),a[g]=t},B=function(t,e,r){var a=r.get()+t.getAttribute("id");e[a]=t;var i=I(t),n=new o.TilingPattern([i[0],i[1],i[0]+i[2],i[1]+i[3]],i[2],i[3],null,k(t));o.beginTilingPattern(n),z(t,o.unitMatrix,e,r,!1),o.endTilingPattern(a,n)},U=function(t,e,r,a,s){function u(){p=new n("rgb(0, 0, 0)"),g=!0,b="F"}var h,d,g=!1,p=null,b=null,x=null,m=null,y=s&&!l(t,"lineargradient,radialgradient,pattern");if(y?(h=k(t),d=I(t),o.beginFormObject(d[0],d[1],d[2],d[3],h),h=o.unitMatrix,s=!1):(h=o.matrixMult(k(t),e),o.saveGraphicsState()),l(t,"g,path,rect,text,ellipse,line,circle,polygon")){var A=f(t,"fill");if(A){var w=c.exec(A);if(w){x=a.get()+w[1];var S=v(x,r);if(S&&l(S,"lineargradient,radialgradient")){var G=h;if(!S.hasAttribute("gradientUnits")||"objectboundingbox"===S.getAttribute("gradientUnits").toLowerCase()){d||(d=I(t)),G=new o.Matrix(d[2],0,0,d[3],d[0],d[1]);var U=k(t);G=o.matrixMult(G,U)}var Q=M(S.getAttribute("gradientTransform"));m=o.matrixMult(Q,G)}else if(S&&l(S,"pattern")){var D,X,Z,R,$;m={};var W=o.unitMatrix;S.hasAttribute("patternUnits")&&"objectboundingbox"!==S.getAttribute("patternUnits").toLowerCase()||(d||(d=I(t)),W=new o.Matrix(1,0,0,1,d[0],d[1]),D=I(S),$=D[0]*d[0],X=D[1]*d[1],Z=D[2]*d[2],R=D[3]*d[3],m.boundingBox=[$,X,$+Z,X+R],m.xStep=Z,m.yStep=R);var J=o.unitMatrix;S.hasAttribute("patternContentUnits")&&"objectboundingbox"===S.getAttribute("patternContentUnits").toLowerCase()&&(d||(d=I(t)),J=new o.Matrix(d[2],0,0,d[3],0,0),D=m.boundingBox||I(S),$=D[0]/d[0],X=D[1]/d[1],Z=D[2]/d[2],R=D[3]/d[3],m.boundingBox=[$,X,$+Z,X+R],m.xStep=Z,m.yStep=R),m.matrix=o.matrixMult(o.matrixMult(J,W),h),b="F"}else x=S=null,u()}else p=C(A),p.ok?(g=!0,b="F"):b=null}else u();var K=1,tt=t.getAttribute("opacity")||t.getAttribute("fill-opacity");tt&&(K*=parseFloat(tt)),p&&"number"==typeof p.a&&(K*=p.a),o.setGState(new o.GState({opacity:K}))}if(l(t,"g,path,rect,ellipse,line,circle,polygon")){g&&o.setFillColor(p.r,p.g,p.b);var et=t.getAttribute("stroke");if(et){var rt;t.hasAttribute("stroke-width")&&(rt=Math.abs(parseFloat(t.getAttribute("stroke-width"))),o.setLineWidth(rt));var at=new n(et);at.ok&&(o.setDrawColor(at.r,at.g,at.b),0!==rt&&(b=(b||"")+"D")),t.hasAttribute("stroke-linecap")&&o.setLineCap(t.getAttribute("stroke-linecap")),t.hasAttribute("stroke-linejoin")&&o.setLineJoin(t.getAttribute("stroke-linejoin")),t.hasAttribute("stroke-dasharray")&&o.setLineDashPattern(F(t.getAttribute("stroke-dasharray")),parseInt(t.getAttribute("stroke-dashoffset"))||0),t.hasAttribute("stroke-miterlimit")&&o.setLineMiterLimit(parseFloat(t.getAttribute("stroke-miterlimit")))}}switch(i(t,p),t.tagName.toLowerCase()){case"svg":Y(t,h,r,a,s);break;case"g":V(t,h,r,a,s);case"a":case"marker":z(t,h,r,a,s);break;case"defs":z(t,h,r,a,!0);break;case"use":L(t,h,a);break;case"line":N(t,h);break;case"rect":o.setCurrentTransformationMatrix(h),O(t,b,x,m);break;case"ellipse":o.setCurrentTransformationMatrix(h),P(t,b,x,m);break;case"circle":o.setCurrentTransformationMatrix(h),E(t,b,x,m);break;case"text":j(t,h,g,p);break;case"path":q(t,h,a,b,x,m);break;case"polygon":_(t,h,b,x,m);break;case"image":o.setCurrentTransformationMatrix(h),T(t);break;case"lineargradient":H(t,"axial",[t.getAttribute("x1"),t.getAttribute("y1"),t.getAttribute("x2"),t.getAttribute("y2")],r,a);break;case"radialgradient":H(t,"radial",[t.getAttribute("fx")||t.getAttribute("cx"),t.getAttribute("fy")||t.getAttribute("cy"),0,t.getAttribute("cx")||0,t.getAttribute("cy")||0,t.getAttribute("r")||0],r,a);break;case"pattern":B(t,r,a)}y?o.endFormObject(a.get()+t.getAttribute("id")):o.restoreGraphicsState()},Q=function(t,e,r){o=e;var a=r.scale||1,i=r.xOffset||0,n=r.yOffset||0;return o.saveGraphicsState(),o.setCurrentTransformationMatrix(new o.Matrix(a,0,0,a,i,n)),U(t.cloneNode(!0),o.unitMatrix,{},new m(""),!1),o.restoreGraphicsState(),o};return"function"==typeof t&&t.amd?t(["./rgbcolor","./SvgPath"],function(t,e){return n=t,s=e,Q}):"undefined"!=typeof r&&r.exports?(n=e("./rgbcolor.
|