securityos/node_modules/rtf.js/dist/WMFJS.bundle.min.js

2 lines
54 KiB
JavaScript

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.WMFJS=e():t.WMFJS=e()}(this,(()=>(()=>{"use strict";var t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{Error:()=>a,Renderer:()=>x,loggingEnabled:()=>l});var i,s=function(){function t(){}return t.prototype.flood=function(t,e,i,s,n){var o=document.createElementNS("http://www.w3.org/2000/svg","feFlood");e&&o.setAttribute("id",e),o.setAttribute("flood-color",i),o.setAttribute("flood-opacity",s.toString()),t.appendChild(o)},t.prototype.composite=function(t,e,i,s,n,o,r,a,h){var l=document.createElementNS("http://www.w3.org/2000/svg","feComposite");e&&l.setAttribute("id",e),l.setAttribute("in",i),l.setAttribute("in2",s),t.appendChild(l)},t}(),n=function(){function t(){this._path=""}return t.prototype.move=function(t,e){this._path+=" M ".concat(t," ").concat(e)},t.prototype.path=function(){return this._path.substr(1)},t.prototype.line=function(t){var e=this;t.forEach((function(t){e._path+=" L ".concat(t[0]," ").concat(t[1])}))},t.prototype.curveC=function(t,e,i,s,n,o){this._path+=" C ".concat(t," ").concat(e,", ").concat(i," ").concat(s,", ").concat(n," ").concat(o)},t.prototype.close=function(){this._path+=" Z"},t}(),o=function(){function t(t){this.filters=new s,this._defs=void 0,this._svg=t}return t.prototype.svg=function(t,e,i,s,n,o){var r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.setAttribute("x",e.toString()),r.setAttribute("y",i.toString()),r.setAttribute("width",s.toString()),r.setAttribute("height",n.toString()),this._appendSettings(o,r),null!=t?t.appendChild(r):this._svg.appendChild(r),r},t.prototype.image=function(t,e,i,s,n,o,r){var a=document.createElementNS("http://www.w3.org/2000/svg","image");return a.setAttribute("x",e.toString()),a.setAttribute("y",i.toString()),a.setAttribute("width",s.toString()),a.setAttribute("height",n.toString()),a.setAttributeNS("http://www.w3.org/1999/xlink","href",o),this._appendSettings(r,a),t.appendChild(a),a},t.prototype.rect=function(t,e,i,s,n,o,r,a){var h=document.createElementNS("http://www.w3.org/2000/svg","rect");return h.setAttribute("x",e.toString()),h.setAttribute("y",i.toString()),h.setAttribute("width",s.toString()),h.setAttribute("height",n.toString()),void 0!==o&&(o instanceof Number?h.setAttribute("rx",o.toString()):o instanceof Object&&this._appendSettings(o,h)),void 0!==r&&h.setAttribute("ry",r.toString()),this._appendSettings(a,h),t.appendChild(h),h},t.prototype.line=function(t,e,i,s,n,o){var r=document.createElementNS("http://www.w3.org/2000/svg","line");return r.setAttribute("x1",e.toString()),r.setAttribute("y1",i.toString()),r.setAttribute("x2",s.toString()),r.setAttribute("y2",n.toString()),this._appendSettings(o,r),t.appendChild(r),r},t.prototype.polygon=function(t,e,i){var s=document.createElementNS("http://www.w3.org/2000/svg","polygon");return s.setAttribute("points",e.map((function(t){return t.join(",")})).join(" ")),this._appendSettings(i,s),t.appendChild(s),s},t.prototype.polyline=function(t,e,i){var s=document.createElementNS("http://www.w3.org/2000/svg","polyline");return s.setAttribute("points",e.map((function(t){return t.join(",")})).join(" ")),this._appendSettings(i,s),t.appendChild(s),s},t.prototype.ellipse=function(t,e,i,s,n,o){var r=document.createElementNS("http://www.w3.org/2000/svg","ellipse");return r.setAttribute("cx",e.toString()),r.setAttribute("cy",i.toString()),r.setAttribute("rx",s.toString()),r.setAttribute("ry",n.toString()),this._appendSettings(o,r),t.appendChild(r),r},t.prototype.path=function(t,e,i){var s=document.createElementNS("http://www.w3.org/2000/svg","path");return s.setAttribute("d",e.path()),this._appendSettings(i,s),t.appendChild(s),s},t.prototype.text=function(t,e,i,s,n){var o=document.createElementNS("http://www.w3.org/2000/svg","text");o.setAttribute("x",e.toString()),o.setAttribute("y",i.toString()),this._appendSettings(n,o);var r=document.createTextNode(s);return o.appendChild(r),t.appendChild(o),o},t.prototype.filter=function(t,e,i,s,n,o,r){var a=document.createElementNS("http://www.w3.org/2000/svg","filter");return a.setAttribute("x",i.toString()),a.setAttribute("y",s.toString()),a.setAttribute("width",n.toString()),a.setAttribute("height",o.toString()),this._appendSettings(r,a),t.appendChild(a),a},t.prototype.pattern=function(t,e,i,s,n,o,r){var a=document.createElementNS("http://www.w3.org/2000/svg","pattern");return e&&a.setAttribute("id",e),a.setAttribute("x",i.toString()),a.setAttribute("y",s.toString()),a.setAttribute("width",n.toString()),a.setAttribute("height",o.toString()),this._appendSettings(r,a),t.appendChild(a),a},t.prototype.defs=function(){if(void 0===this._defs){var t=document.createElementNS("http://www.w3.org/2000/svg","defs");this._svg.appendChild(t),this._defs=t}return this._defs},t.prototype.clipPath=function(t,e,i,s){var n=document.createElementNS("http://www.w3.org/2000/svg","clipPath");return e&&n.setAttribute("id",e),void 0===i&&(i="userSpaceOnUse"),n.setAttribute("clipPathUnits",i),this._appendSettings(s,n),t.appendChild(n),n},t.prototype.createPath=function(){return new n},t.prototype._appendSettings=function(t,e){void 0!==t&&Object.keys(t).forEach((function(i){e.setAttribute(i,t[i])}))},t}(),r=(i=function(t,e){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},i(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function s(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(s.prototype=e.prototype,new s)}),a=function(t){function e(e){var i=this.constructor,s=t.call(this,e)||this;return Object.setPrototypeOf(s,i.prototype),s}return r(e,t),e}(Error),h=!0;function l(t){h=t}var c=function(){function t(){}return t.log=function(t){h&&console.log(t)},t._makeUniqueId=function(t){return"wmfjs_"+t+this._uniqueId++},t._writeUint32Val=function(t,e,i){t[e++]=255&i,t[e++]=i>>>8&255,t[e++]=i>>>16&255,t[e++]=i>>>24&255},t._blobToBinary=function(t){for(var e="",i=t.length,s=0;s<i;s++)e+=String.fromCharCode(t[s]);return e},t.GDI={METAHEADER_SIZE:18,BITMAPINFOHEADER_SIZE:40,BITMAPCOREHEADER_SIZE:12,MetafileType:{MEMORYMETAFILE:1,DISKMETAFILE:2},MetafileVersion:{METAVERSION100:256,METAVERSION300:768},RecordType:{META_EOF:0,META_REALIZEPALETTE:53,META_SETPALENTRIES:55,META_SETBKMODE:258,META_SETMAPMODE:259,META_SETROP2:260,META_SETRELABS:261,META_SETPOLYFILLMODE:262,META_SETSTRETCHBLTMODE:263,META_SETTEXTCHAREXTRA:264,META_RESTOREDC:295,META_RESIZEPALETTE:313,META_DIBCREATEPATTERNBRUSH:322,META_SETLAYOUT:329,META_SETBKCOLOR:513,META_SETTEXTCOLOR:521,META_OFFSETVIEWPORTORG:529,META_LINETO:531,META_MOVETO:532,META_OFFSETCLIPRGN:544,META_FILLREGION:552,META_SETMAPPERFLAGS:561,META_SELECTPALETTE:564,META_POLYGON:804,META_POLYLINE:805,META_SETTEXTJUSTIFICATION:522,META_SETWINDOWORG:523,META_SETWINDOWEXT:524,META_SETVIEWPORTORG:525,META_SETVIEWPORTEXT:526,META_OFFSETWINDOWORG:527,META_SCALEWINDOWEXT:1040,META_SCALEVIEWPORTEXT:1042,META_EXCLUDECLIPRECT:1045,META_INTERSECTCLIPRECT:1046,META_ELLIPSE:1048,META_FLOODFILL:1049,META_FRAMEREGION:1065,META_ANIMATEPALETTE:1078,META_TEXTOUT:1313,META_POLYPOLYGON:1336,META_EXTFLOODFILL:1352,META_RECTANGLE:1051,META_SETPIXEL:1055,META_ROUNDRECT:1564,META_PATBLT:1565,META_SAVEDC:30,META_PIE:2074,META_STRETCHBLT:2851,META_ESCAPE:1574,META_INVERTREGION:298,META_PAINTREGION:299,META_SELECTCLIPREGION:300,META_SELECTOBJECT:301,META_SETTEXTALIGN:302,META_ARC:2071,META_CHORD:2096,META_BITBLT:2338,META_EXTTEXTOUT:2610,META_SETDIBTODEV:3379,META_DIBBITBLT:2368,META_DIBSTRETCHBLT:2881,META_STRETCHDIB:3907,META_DELETEOBJECT:496,META_CREATEPALETTE:247,META_CREATEPATTERNBRUSH:505,META_CREATEPENINDIRECT:762,META_CREATEFONTINDIRECT:763,META_CREATEBRUSHINDIRECT:764,META_CREATEREGION:1791},MetafileEscapes:{NEWFRAME:1,ABORTDOC:2,NEXTBAND:3,SETCOLORTABLE:4,GETCOLORTABLE:5,FLUSHOUT:6,DRAFTMODE:7,QUERYESCSUPPORT:8,SETABORTPROC:9,STARTDOC:10,ENDDOC:11,GETPHYSPAGESIZE:12,GETPRINTINGOFFSET:13,GETSCALINGFACTOR:14,META_ESCAPE_ENHANCED_METAFILE:15,SETPENWIDTH:16,SETCOPYCOUNT:17,SETPAPERSOURCE:18,PASSTHROUGH:19,GETTECHNOLOGY:20,SETLINECAP:21,SETLINEJOIN:22,SETMITERLIMIT:23,BANDINFO:24,DRAWPATTERNRECT:25,GETVECTORPENSIZE:26,GETVECTORBRUSHSIZE:27,ENABLEDUPLEX:28,GETSETPAPERBINS:29,GETSETPRINTORIENT:30,ENUMPAPERBINS:31,SETDIBSCALING:32,EPSPRINTING:33,ENUMPAPERMETRICS:34,GETSETPAPERMETRICS:35,POSTSCRIPT_DATA:37,POSTSCRIPT_IGNORE:38,GETDEVICEUNITS:42,GETEXTENDEDTEXTMETRICS:256,GETPAIRKERNTABLE:258,EXTTEXTOUT:512,GETFACENAME:513,DOWNLOADFACE:514,METAFILE_DRIVER:2049,QUERYDIBSUPPORT:3073,BEGIN_PATH:4096,CLIP_TO_PATH:4097,END_PATH:4098,OPEN_CHANNEL:4110,DOWNLOADHEADER:4111,CLOSE_CHANNEL:4112,POSTSCRIPT_PASSTHROUGH:4115,ENCAPSULATED_POSTSCRIPT:4116,POSTSCRIPT_IDENTIFY:4117,POSTSCRIPT_INJECTION:4118,CHECKJPEGFORMAT:4119,CHECKPNGFORMAT:4120,GET_PS_FEATURESETTING:4121,MXDC_ESCAPE:4122,SPCLPASSTHROUGH2:4568},MapMode:{MM_TEXT:1,MM_LOMETRIC:2,MM_HIMETRIC:3,MM_LOENGLISH:4,MM_HIENGLISH:5,MM_TWIPS:6,MM_ISOTROPIC:7,MM_ANISOTROPIC:8},StretchMode:{BLACKONWHITE:1,WHITEONBLACK:2,COLORONCOLOR:3,HALFTONE:4},TextAlignmentMode:{TA_UPDATECP:1,TA_RIGHT:2,TA_CENTER:6,TA_BOTTOM:8,TA_BASELINE:24,TA_RTLREADING:256},MixMode:{TRANSPARENT:1,OPAQUE:2},VerticalTextAlignmentMode:{VTA_BOTTOM:2,VTA_CENTER:6,VTA_LEFT:8,VTA_BASELINE:24},BrushStyle:{BS_SOLID:0,BS_NULL:1,BS_HATCHED:2,BS_PATTERN:3,BS_INDEXED:4,BS_DIBPATTERN:5,BS_DIBPATTERNPT:6,BS_PATTERN8X8:7,BS_DIBPATTERN8X8:8,BS_MONOPATTERN:9},PenStyle:{PS_SOLID:0,PS_DASH:1,PS_DOT:2,PS_DASHDOT:3,PS_DASHDOTDOT:4,PS_NULL:5,PS_INSIDEFRAME:6,PS_USERSTYLE:7,PS_ALTERNATE:8,PS_ENDCAP_SQUARE:256,PS_ENDCAP_FLAT:512,PS_JOIN_BEVEL:4096,PS_JOIN_MITER:8192},PolyFillMode:{ALTERNATE:1,WINDING:2},ColorUsage:{DIB_RGB_COLORS:0,DIB_PAL_COLORS:1,DIB_PAL_INDICES:2},PaletteEntryFlag:{PC_RESERVED:1,PC_EXPLICIT:2,PC_NOCOLLAPSE:4},BitmapCompression:{BI_RGB:0,BI_RLE8:1,BI_RLE4:2,BI_BITFIELDS:3,BI_JPEG:4,BI_PNG:5}},t._uniqueId=0,t}(),p=function(){function t(e,i){e instanceof t?(this.blob=e.blob,this.data=e.data,this.pos=i||e.pos):(this.blob=e,this.data=new Uint8Array(e),this.pos=i||0)}return t.prototype.eof=function(){return this.pos>=this.data.length},t.prototype.seek=function(t){if(t<0||t>this.data.length)throw new a("Invalid seek position");this.pos=t},t.prototype.skip=function(t){var e=this.pos+t;if(e>this.data.length)throw new a("Unexpected end of file");this.pos=e},t.prototype.readBinary=function(t){if(this.pos+t>this.data.length)throw new a("Unexpected end of file");for(var e="";t-- >0;)e+=String.fromCharCode(this.data[this.pos++]);return e},t.prototype.readInt8=function(){if(this.pos+1>this.data.length)throw new a("Unexpected end of file");return this.data[this.pos++]},t.prototype.readUint8=function(){return this.readInt8()>>>0},t.prototype.readInt32=function(){if(this.pos+4>this.data.length)throw new a("Unexpected end of file");var t=this.data[this.pos++];return t|=this.data[this.pos++]<<8,(t|=this.data[this.pos++]<<16)|this.data[this.pos++]<<24},t.prototype.readUint32=function(){return this.readInt32()>>>0},t.prototype.readUint16=function(){if(this.pos+2>this.data.length)throw new a("Unexpected end of file");return this.data[this.pos++]|this.data[this.pos++]<<8},t.prototype.readInt16=function(){var t=this.readUint16();return t>32767&&(t-=65536),t},t.prototype.readString=function(t){if(this.pos+t>this.data.length)throw new a("Unexpected end of file");for(var e="",i=0;i<t;i++)e+=String.fromCharCode(this.data[this.pos++]>>>0);return e},t.prototype.readNullTermString=function(t){var e="";if(t>0){t--;for(var i=0;i<t;i++){if(this.pos+i+1>this.data.length)throw new a("Unexpected end of file");var s=this.data[this.pos+i]>>>0;if(0===s)break;e+=String.fromCharCode(s)}}return e},t}(),u=function(){function t(t,e,i){null!=t?(this.x=t.readInt16(),this.y=t.readInt16()):(this.x=e,this.y=i)}return t.prototype.clone=function(){return new t(null,this.x,this.y)},t.prototype.toString=function(){return"{x: "+this.x+", y: "+this.y+"}"},t}(),d=function(){function t(t,e,i,s,n){null!=t?(this.bottom=t.readInt16(),this.right=t.readInt16(),this.top=t.readInt16(),this.left=t.readInt16()):(this.bottom=n,this.right=s,this.top=i,this.left=e)}return t.prototype.clone=function(){return new t(null,this.left,this.top,this.right,this.bottom)},t.prototype.toString=function(){return"{left: "+this.left+", top: "+this.top+", right: "+this.right+", bottom: "+this.bottom+"}"},t.prototype.empty=function(){return this.left>=this.right||this.top>=this.bottom},t.prototype.intersect=function(e){return this.empty()||e.empty()||this.left>=e.right||this.top>=e.bottom||this.right<=e.left||this.bottom<=e.top?null:new t(null,Math.max(this.left,e.left),Math.max(this.top,e.top),Math.min(this.right,e.right),Math.min(this.bottom,e.bottom))},t}(),T=function(){function t(t){this.type=t}return t.prototype.clone=function(){throw new a("clone not implemented")},t.prototype.toString=function(){throw new a("toString not implemented")},t}(),f=function(){var t=function(e,i){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},t(e,i)};return function(e,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function s(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(s.prototype=i.prototype,new s)}}(),E=function(t){function e(e,i){var s=t.call(this,"region")||this;if(null!=e){if(e.skip(2),6!==e.readInt16())throw new a("Invalid region identifier");e.skip(2),e.readInt16();var n=e.readInt16();e.skip(2);var o=e.readInt16(),r=e.readInt16(),h=e.readInt16(),l=e.readInt16();s.bounds=new d(null,o,r,h,l),s.scans=[];for(var c=0;c<n;c++)s.scans.push(new g(e));s._updateComplexity()}else if(null!=i){if(s.bounds=null!=i.bounds?i.bounds.clone():null,null!=i.scans)for(s.scans=[],c=0;c<i.scans.length;c++)s.scans.push(i.scans[c].clone());else s.scans=null;s.complexity=i.complexity}else s.bounds=null,s.scans=null,s.complexity=0;return s}return f(e,t),e.prototype.clone=function(){return new e(null,this)},e.prototype.toString=function(){return"{complexity: "+["null","simple","complex"][this.complexity]+" bounds: "+(null!=this.bounds?this.bounds.toString():"[none]")+" #scans: "+(null!=this.scans?this.scans.length:"[none]")+"}"},e.prototype._updateComplexity=function(){if(null==this.bounds)this.complexity=0,this.scans=null;else if(this.bounds.empty())this.complexity=0,this.scans=null,this.bounds=null;else if(null==this.scans)this.complexity=1;else if(this.complexity=2,1===this.scans.length){var t=this.scans[0];if(t.top===this.bounds.top&&t.bottom===this.bounds.bottom&&1===t.scanlines.length){var e=t.scanlines[0];e.left===this.bounds.left&&e.right===this.bounds.right&&(this.scans=null,this.complexity=1)}}},e.prototype.subtract=function(t){if(c.log("[wmf] Region "+this.toString()+" subtract "+t.toString()),null!=this.bounds&&null!=this.bounds.intersect(t)){null==this.scans&&(this.scans=[],this.scans.push(new g(null,null,this.bounds.top,this.bounds.bottom,[{left:this.bounds.left,right:this.bounds.right}])),this.complexity=2);for(var e=0;e<this.scans.length;){if((u=this.scans[e]).bottom>=t.top){var i=u.clone();u.bottom=t.top-1,i.top=t.top,u.top>=u.bottom?this.scans[e]=i:(c.log("[wmf] Region split top scan "+e+" for substraction"),this.scans.splice(++e,0,i));break}e++}for(var s=e;e<this.scans.length&&!((u=this.scans[e]).top>t.bottom);){if(u.bottom>t.bottom){i=u.clone(),u.bottom=t.bottom,i.top=t.bottom+1,u.top>=u.bottom?this.scans[e]=i:(c.log("[wmf] Region split bottom scan "+e+" for substraction"),this.scans.splice(++e,0,i));break}e++}if(s<this.scans.length){var n=e;for(e=s;e<n;)(u=this.scans[e]).subtract(t.left,t.right)?e++:(c.log("[wmf] Region remove now empty scan "+e+" due to subtraction"),this.scans.splice(e,1),n--)}if(null!=this.scans){for(var o,r=void 0,a=void 0,h=void 0,l=this.scans.length,p=0;p<l;p++){var u=this.scans[p];0===p&&(o=u.top),p===l-1&&(h=u.bottom);var T=u.scanlines.length;if(T>0){var f=u.scanlines[0];(null==r||f.left<r)&&(r=f.left),f=u.scanlines[T-1],(null==a||f.right>a)&&(a=f.right)}}null!=r&&null!=o&&null!=a&&null!=h?(this.bounds=new d(null,r,o,a,h),this._updateComplexity()):(this.bounds=null,this.scans=null,this.complexity=0)}else this._updateComplexity()}c.log("[wmf] Region subtraction -> "+this.toString())},e.prototype.intersect=function(t){if(c.log("[wmf] Region "+this.toString()+" intersect with "+t.toString()),null!=this.bounds)if(this.bounds=this.bounds.intersect(t),null!=this.bounds){if(null!=this.scans){for(var e=0;e<this.scans.length&&(i=this.scans[e]).bottom<this.bounds.top;)e++;for(e>0&&(c.log("[wmf] Region remove "+e+" scans from top"),this.scans.splice(0,e),this.scans.length>0&&(this.scans[0].top=this.bounds.top)),e=0;e<this.scans.length;){var i;if((i=this.scans[e]).top>this.bounds.bottom){c.log("[wmf] Region remove "+(this.scans.length-e)+" scans from bottom"),this.scans.splice(e,this.scans.length-e);break}i.intersect(this.bounds.left,this.bounds.right)?e++:(c.log("[wmf] Region remove now empty scan "+e+" due to intersection"),this.scans.splice(e,1))}this.scans.length>0&&(this.scans[this.scans.length-1].bottom=this.bounds.bottom),this._updateComplexity()}}else this.scans=null,this.complexity=0;c.log("[wmf] Region intersection -> "+this.toString())},e.prototype.offset=function(t,e){if(null!=this.bounds&&(this.bounds.left+=t,this.bounds.top+=e,this.bounds.right+=t,this.bounds.bottom+=e),null!=this.scans)for(var i=this.scans.length,s=0;s<i;s++){var n=this.scans[s];n.top+=e,n.bottom+=e;for(var o=n.scanlines.length,r=0;r<o;r++){var a=n.scanlines[r];a.left+=t,a.right+=t}}},e}(T),g=function(){function t(t,e,i,s,n){if(null!=t){var o=t.readUint16();this.top=t.readUint16(),this.bottom=t.readUint16(),this.scanlines=[];for(var r=0;r<o;r++){var a=t.readUint16(),h=t.readUint16();this.scanlines.push({left:a,right:h})}t.skip(2)}else if(null!=e)for(this.top=e.top,this.bottom=e.bottom,this.scanlines=[],r=0;r<e.scanlines.length;r++){var l=e.scanlines[r];this.scanlines.push({left:l.left,right:l.right})}else this.top=i,this.bottom=s,this.scanlines=n}return t.prototype.clone=function(){return new t(null,this)},t.prototype.subtract=function(t,e){var i;for(i=0;i<this.scanlines.length&&(o=this.scanlines[i]).left<=t;)o.right>=t&&(o.right=t-1,o.left>=o.right)?this.scanlines.splice(i,1):i++;for(var s=i,n=0;i<this.scanlines.length;){var o;if((o=this.scanlines[i]).right>e){o.left=e,n=i-s,o.left>=o.right&&n++;break}i++}return n>0&&s<this.scanlines.length&&this.scanlines.splice(s,n),this.scanlines.length>0},t.prototype.intersect=function(t,e){for(var i=0;i<this.scanlines.length;i++)if((s=this.scanlines[i]).left>=t||s.right>=t){i>0&&this.scanlines.splice(0,i);break}if(this.scanlines.length>0){var s;for((s=this.scanlines[0]).left<t&&(s.left=t),i=0;i<this.scanlines.length;i++)if((s=this.scanlines[i]).left>e){this.scanlines.splice(i,this.scanlines.length-i);break}this.scanlines.length>0&&(s=this.scanlines[this.scanlines.length-1]).right>e&&(s.right=e)}return this.scanlines.length>0},t.prototype.toString=function(){return"{ #scanlines: "+this.scanlines.length+"}"},t}(),_=function(){var t=function(e,i){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},t(e,i)};return function(e,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function s(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(s.prototype=i.prototype,new s)}}(),y=function(){function t(t,e){e&&t.skip(4),this.width=t.readUint16(),this.height=t.readUint16(),this.planes=t.readUint16(),this.bitcount=t.readUint16()}return t.prototype.colors=function(){return this.bitcount<=8?1<<this.bitcount:0},t}(),S=function(){function t(t,e){e&&t.skip(4),this.width=t.readInt32(),this.height=t.readInt32(),this.planes=t.readUint16(),this.bitcount=t.readUint16(),this.compression=t.readUint32(),this.sizeimage=t.readUint32(),this.xpelspermeter=t.readInt32(),this.ypelspermeter=t.readInt32(),this.clrused=t.readUint32(),this.clrimportant=t.readUint32()}return t.prototype.colors=function(){return 0!==this.clrused?this.clrused<256?this.clrused:256:this.bitcount>8?0:1<<this.bitcount},t}(),I=function(){function t(t,e){this._reader=t,this._offset=t.pos,this._usergb=e;var i=t.readUint32();if(this._infosize=i,i===c.GDI.BITMAPCOREHEADER_SIZE)this._header=new y(t,!1),this._infosize+=this._header.colors()*(e?3:2);else{this._header=new S(t,!1);var s=this._header.compression===c.GDI.BitmapCompression.BI_BITFIELDS?3:0;i<=c.GDI.BITMAPINFOHEADER_SIZE+4*s&&(this._infosize=c.GDI.BITMAPINFOHEADER_SIZE+4*s),this._infosize+=this._header.colors()*(e?4:2)}}return t.prototype.getWidth=function(){return this._header.width},t.prototype.getHeight=function(){return Math.abs(this._header.height)},t.prototype.infosize=function(){return this._infosize},t.prototype.header=function(){return this._header},t}(),v=function(){function t(t,e){this._reader=t,this._offset=t.pos,this._size=e,this._info=new I(t,!0)}return t.prototype.getWidth=function(){return this._info.getWidth()},t.prototype.getHeight=function(){return this._info.getHeight()},t.prototype.base64ref=function(){var t=this._reader.pos;this._reader.seek(this._offset);var e,i="image/bmp",s=this._info.header();if(s instanceof S&&null!=s.compression)switch(s.compression){case c.GDI.BitmapCompression.BI_JPEG:i="data:image/jpeg";break;case c.GDI.BitmapCompression.BI_PNG:i="data:image/png";break;default:e=this.makeBitmapFileHeader()}else e=this.makeBitmapFileHeader();null!=e?e+=this._reader.readBinary(this._size):e=this._reader.readBinary(this._size);var n="data:"+i+";base64,"+btoa(e);return this._reader.seek(t),n},t.prototype.makeBitmapFileHeader=function(){var t=new ArrayBuffer(14),e=new Uint8Array(t);return e[0]=66,e[1]=77,c._writeUint32Val(e,2,this._size+14),c._writeUint32Val(e,10,this._info.infosize()+14),c._blobToBinary(e)},t}(),A=function(){function t(t,e){if(null!=t){if(e=e,this._reader=t,this._offset=t.pos,this._size=e,this.type=t.readInt16(),this.width=t.readInt16(),this.height=t.readInt16(),this.widthBytes=t.readInt16(),this.planes=t.readUint8(),this.bitsPixel=t.readUint8(),this.bitsOffset=t.pos,this.bitsSize=(this.width*this.bitsPixel+15>>4<<1)*this.height,this.bitsSize>e-10)throw new a("Bitmap should have "+this.bitsSize+" bytes, but has "+(e-10))}else{var i=e;this._reader=i._reader,this._offset=i._offset,this._size=i._size,this.type=i.type,this.width=i.width,this.height=i.height,this.widthBytes=i.widthBytes,this.planes=i.planes,this.bitsPixel=i.bitsPixel,this.bitsOffset=i.bitsOffset,this.bitsSize=i.bitsSize}}return t.prototype.getWidth=function(){return this.width},t.prototype.getHeight=function(){return this.height},t.prototype.clone=function(){return new t(null,this)},t}(),b=function(t){function e(e,i){var s=t.call(this,e,i)||this;return null!=e&&(s.bitsOffset+=22),s}return _(e,t),e.prototype.clone=function(){return new e(null,this)},e}(A),w=function(){var t=function(e,i){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},t(e,i)};return function(e,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function s(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(s.prototype=i.prototype,new s)}}(),R=function(){function t(t,e,i,s){null!=t?(this.r=t.readUint8(),this.g=t.readUint8(),this.b=t.readUint8(),t.skip(1)):(this.r=e,this.g=i,this.b=s)}return t.prototype.clone=function(){return new t(null,this.r,this.g,this.b)},t.prototype.toHex=function(){return(16777216+(this.r<<16|this.g<<8|this.b)).toString(16).slice(1)},t.prototype.toString=function(){return"{r: "+this.r+", g: "+this.g+", b: "+this.b+"}"},t}(),O=function(t){function e(e,i){var s=t.call(this,"font")||this;if(null!=e){s.height=e.readInt16(),s.width=e.readInt16(),s.escapement=e.readInt16(),s.orientation=e.readInt16(),s.weight=e.readInt16(),s.italic=e.readUint8(),s.underline=e.readUint8(),s.strikeout=e.readUint8(),s.charset=e.readUint8(),s.outprecision=e.readUint8(),s.clipprecision=e.readUint8(),s.quality=e.readUint8();var n=e.readUint8();s.pitch=15&n,s.family=n>>6&3;var o=i,r=e.pos;s.facename=e.readNullTermString(Math.min(o-(e.pos-r),32))}else null!=i?(i=i,s.height=i.height,s.width=i.width,s.escapement=i.escapement,s.orientation=i.orientation,s.weight=i.weight,s.italic=i.italic,s.underline=i.underline,s.strikeout=i.strikeout,s.charset=i.charset,s.outprecision=i.outprecision,s.clipprecision=i.clipprecision,s.quality=i.quality,s.pitch=i.pitch,s.family=i.family,s.facename=i.facename):(s.height=-80,s.width=0,s.escapement=0,s.orientation=0,s.weight=400,s.italic=0,s.underline=0,s.strikeout=0,s.charset=0,s.outprecision=0,s.clipprecision=0,s.quality=0,s.pitch=0,s.family=0,s.facename="Helvetica");return s}return w(e,t),e.prototype.clone=function(){return new e(null,this)},e.prototype.toString=function(){return JSON.stringify(this)},e}(T),D=function(t){function e(e,i,s){var n=t.call(this,"brush")||this;if(null!=e){var o=i,r=e.pos;if(!0===s||!1===s)switch(n.style=e.readUint16(),s&&n.style!==c.GDI.BrushStyle.BS_PATTERN&&(n.style=c.GDI.BrushStyle.BS_DIBPATTERNPT),n.style){case c.GDI.BrushStyle.BS_SOLID:n.color=new R(e);break;case c.GDI.BrushStyle.BS_PATTERN:e.skip(s?2:6),n.pattern=new A(e,o-(e.pos-r));break;case c.GDI.BrushStyle.BS_DIBPATTERNPT:n.colorusage=s?e.readUint16():e.readUint32(),s||e.skip(2),n.dibpatternpt=new v(e,o-(e.pos-r));break;case c.GDI.BrushStyle.BS_HATCHED:n.color=new R(e),n.hatchstyle=e.readUint16()}else s instanceof b&&(n.style=c.GDI.BrushStyle.BS_PATTERN,n.pattern=s)}else if(null!=i)switch(i=i,n.style=i.style,n.style){case c.GDI.BrushStyle.BS_SOLID:n.color=i.color.clone();break;case c.GDI.BrushStyle.BS_PATTERN:n.pattern=i.pattern.clone();break;case c.GDI.BrushStyle.BS_DIBPATTERNPT:n.colorusage=i.colorusage,n.dibpatternpt=i.dibpatternpt;break;case c.GDI.BrushStyle.BS_HATCHED:n.color=i.color.clone(),n.hatchstyle=i.hatchstyle}return n}return w(e,t),e.prototype.clone=function(){return new e(null,this)},e.prototype.toString=function(){var t="{style: "+this.style;switch(this.style){case c.GDI.BrushStyle.BS_SOLID:t+=", color: "+this.color.toString();break;case c.GDI.BrushStyle.BS_DIBPATTERNPT:t+=", colorusage: "+this.colorusage;break;case c.GDI.BrushStyle.BS_HATCHED:t+=", color: "+this.color.toString()+", hatchstyle: "+this.hatchstyle}return t+"}"},e}(T),M=function(t){function e(e,i,s,n,o,r){var a=t.call(this,"pen")||this;return null!=e?(i=e.readUint16(),a.style=255&i,a.width=new u(e),a.color=new R(e),a.linecap=i&(c.GDI.PenStyle.PS_ENDCAP_SQUARE|c.GDI.PenStyle.PS_ENDCAP_FLAT),a.join=i&(c.GDI.PenStyle.PS_JOIN_BEVEL|c.GDI.PenStyle.PS_JOIN_MITER)):(a.style=i,a.width=s,a.color=n,a.linecap=o,a.join=r),a}return w(e,t),e.prototype.clone=function(){return new e(null,this.style,this.width.clone(),this.color.clone(),this.linecap,this.join)},e.prototype.toString=function(){return"{style: "+this.style+", width: "+this.width.toString()+", color: "+this.color.toString()+", linecap: "+this.linecap+", join: "+this.join+"}"},e}(T),P=function(){function t(t,e){null!=t?(this.flag=t.readUint8(),this.b=t.readUint8(),this.g=t.readUint8(),this.r=t.readUint8()):(this.flag=e.flag,this.b=e.b,this.g=e.g,this.r=e.r)}return t.prototype.clone=function(){return new t(null,this)},t}(),m=function(t){function e(e,i){var s=t.call(this,"palette")||this;if(null!=e){s.start=e.readUint16();var n=e.readUint16();for(s.entries=[];n>0;)s.entries.push(new P(e)),n--}else{s.start=i.start,s.entries=[];for(var o=i.entries.length,r=0;r<o;r++)s.entries.push(i.entries[r])}return s}return w(e,t),e.prototype.clone=function(){return new e(null,this)},e.prototype.toString=function(){return"{ #entries: "+this.entries.length+"}"},e}(T),C=function(t,e){if(null!=t)for(var i in this._svggroup=t._svggroup,this._svgclipChanged=t._svgclipChanged,this._svgtextbkfilter=t._svgtextbkfilter,this.mapmode=t.mapmode,this.stretchmode=t.stretchmode,this.textalign=t.textalign,this.bkmode=t.bkmode,this.textcolor=t.textcolor.clone(),this.bkcolor=t.bkcolor.clone(),this.polyfillmode=t.polyfillmode,this.wx=t.wx,this.wy=t.wy,this.ww=t.ww,this.wh=t.wh,this.vx=t.vx,this.vy=t.vy,this.vw=t.vw,this.vh=t.vh,this.x=t.x,this.y=t.y,this.clip=t.clip,this.ownclip=!1,this.selected={},t.selected)this.selected[i]=t.selected[i];else for(var i in this._svggroup=null,this._svgclipChanged=!1,this._svgtextbkfilter=null,this.mapmode=c.GDI.MapMode.MM_ANISOTROPIC,this.stretchmode=c.GDI.StretchMode.COLORONCOLOR,this.textalign=0,this.bkmode=c.GDI.MixMode.OPAQUE,this.textcolor=new R(null,0,0,0),this.bkcolor=new R(null,255,255,255),this.polyfillmode=c.GDI.PolyFillMode.ALTERNATE,this.wx=0,this.wy=0,this.ww=0,this.wh=0,this.vx=0,this.vy=0,this.vw=0,this.vh=0,this.x=0,this.y=0,this.clip=null,this.ownclip=!1,this.selected={},e){var s=e[i];this.selected[i]=null!=s?s.clone():null}},N=function(){function t(t){this._svg=t,this._svgdefs=null,this._svgPatterns={},this._svgClipPaths={},this.defObjects={brush:new D(null,null),pen:new M(null,c.GDI.PenStyle.PS_SOLID,new u(null,1,1),new R(null,0,0,0),0,0),font:new O(null,null),palette:null,region:null},this.state=new C(null,this.defObjects),this.statestack=[this.state],this.objects={}}return t.prototype.setMapMode=function(t){c.log("[gdi] setMapMode: mode="+t),this.state.mapmode=t,this.state._svggroup=null},t.prototype.setWindowOrg=function(t,e){c.log("[gdi] setWindowOrg: x="+t+" y="+e),this.state.wx=t,this.state.wy=e,this.state._svggroup=null},t.prototype.setWindowExt=function(t,e){c.log("[gdi] setWindowExt: x="+t+" y="+e),this.state.ww=t,this.state.wh=e,this.state._svggroup=null},t.prototype.offsetWindowOrg=function(t,e){c.log("[gdi] offsetWindowOrg: offX="+t+" offY="+e),this.state.wx+=t,this.state.wy+=e,this.state._svggroup=null},t.prototype.setViewportOrg=function(t,e){c.log("[gdi] setViewportOrg: x="+t+" y="+e),this.state.vx=t,this.state.vy=e,this.state._svggroup=null},t.prototype.setViewportExt=function(t,e){c.log("[gdi] setViewportExt: x="+t+" y="+e),this.state.vw=t,this.state.vh=e,this.state._svggroup=null},t.prototype.offsetViewportOrg=function(t,e){c.log("[gdi] offsetViewportOrg: offX="+t+" offY="+e),this.state.vx+=t,this.state.vy+=e,this.state._svggroup=null},t.prototype.saveDC=function(){c.log("[gdi] saveDC");var t=this.state;this.state=new C(this.state),this.statestack.push(t),this.state._svggroup=null},t.prototype.restoreDC=function(t){if(c.log("[gdi] restoreDC: saved="+t),!(this.statestack.length>1))throw new a("No saved contexts");if(-1===t)this.state=this.statestack.pop();else{if(t<-1)throw new a("restoreDC: relative restore not implemented");if(t>1)throw new a("restoreDC: absolute restore not implemented")}this.state._svggroup=null},t.prototype.escape=function(t,e,i,s){c.log("[gdi] escape: func="+t+" offset="+i+" count="+s)},t.prototype.setStretchBltMode=function(t){c.log("[gdi] setStretchBltMode: stretchMode="+t)},t.prototype.stretchDib=function(t,e,i,s,n,o,r,a,h,l,p){c.log("[gdi] stretchDib: srcX="+t+" srcY="+e+" srcW="+i+" srcH="+s+" dstX="+n+" dstY="+o+" dstW="+r+" dstH="+a+" rasterOp=0x"+h.toString(16)),t=this._todevX(t),e=this._todevY(e),i=this._todevW(i),s=this._todevH(s),n=this._todevX(n),o=this._todevY(o),r=this._todevW(r),a=this._todevH(a),c.log("[gdi] stretchDib: TRANSLATED: srcX="+t+" srcY="+e+" srcW="+i+" srcH="+s+" dstX="+n+" dstY="+o+" dstW="+r+" dstH="+a+" rasterOp=0x"+h.toString(16)+" colorUsage=0x"+l.toString(16)),this._pushGroup(),this._svg.image(this.state._svggroup,n,o,r,a,p.base64ref())},t.prototype.dibBits=function(t,e,i,s,n,o,r,a){c.log("[gdi] stretchDibBits: srcX="+t+" srcY="+e+" dstX="+i+" dstY="+s+" width="+n+" height="+o+" rasterOp=0x"+r.toString(16)),t=this._todevX(t),e=this._todevY(e),i=this._todevX(i),s=this._todevY(s),n=this._todevW(n),o=this._todevH(o),c.log("[gdi] dibBits: TRANSLATED: srcX="+t+" srcY="+e+NaN+i+" dstY="+s+" width="+n+" height="+o+" rasterOp=0x"+r.toString(16)),this._pushGroup(),this._svg.image(this.state._svggroup,i,s,n,o,a.base64ref())},t.prototype.stretchDibBits=function(t,e,i,s,n,o,r,a,h,l){c.log("[gdi] stretchDibBits: srcX="+t+" srcY="+e+" srcW="+i+" srcH="+s+" dstX="+n+" dstY="+o+" dstW="+r+" dstH="+a+" rasterOp=0x"+h.toString(16)),t=this._todevX(t),e=this._todevY(e),i=this._todevW(i),s=this._todevH(s),n=this._todevX(n),o=this._todevY(o),r=this._todevW(r),a=this._todevH(a),c.log("[gdi] stretchDibBits: TRANSLATED: srcX="+t+" srcY="+e+" srcW="+i+" srcH="+s+" dstX="+n+" dstY="+o+" dstW="+r+" dstH="+a+" rasterOp=0x"+h.toString(16)),this._pushGroup(),this._svg.image(this.state._svggroup,n,o,r,a,l.base64ref())},t.prototype.rectangle=function(t,e,i){c.log("[gdi] rectangle: rect="+t.toString()+" with pen "+this.state.selected.pen.toString()+" and brush "+this.state.selected.brush.toString());var s=this._todevY(t.bottom),n=this._todevX(t.right),o=this._todevY(t.top),r=this._todevX(t.left);e=this._todevH(e),i=this._todevH(i),c.log("[gdi] rectangle: TRANSLATED: bottom="+s+" right="+n+" top="+o+" left="+r+" rh="+i+" rw="+e),this._pushGroup();var a=this._applyOpts(null,!0,!0,!1);this._svg.rect(this.state._svggroup,r,o,n-r,s-o,e/2,i/2,a)},t.prototype.textOut=function(t,e,i){c.log("[gdi] textOut: x="+t+" y="+e+" text="+i+" with font "+this.state.selected.font.toString()),t=this._todevX(t),e=this._todevY(e),c.log("[gdi] textOut: TRANSLATED: x="+t+" y="+e),this._pushGroup();var s=this._applyOpts(null,!1,!1,!0);if(0!==this.state.selected.font.escapement&&(s.transform="rotate("+[-this.state.selected.font.escapement/10,t,e]+")",s.style="dominant-baseline: middle; text-anchor: start;"),this.state.bkmode===c.GDI.MixMode.OPAQUE){if(null==this.state._svgtextbkfilter){var n=c._makeUniqueId("f"),o=this._svg.filter(this._getSvgDef(),n,0,0,1,1);this._svg.filters.flood(o,null,"#"+this.state.bkcolor.toHex(),1),this._svg.filters.composite(o,null,null,"SourceGraphic"),this.state._svgtextbkfilter=o}s.filter="url(#"+this.state._svgtextbkfilter.id+")"}this._svg.text(this.state._svggroup,t,e,i,s)},t.prototype.extTextOut=function(t,e,i,s,n,o){c.log("[gdi] extTextOut: x="+t+" y="+e+" text="+i+" with font "+this.state.selected.font.toString()),t=this._todevX(t),e=this._todevY(e),c.log("[gdi] extTextOut: TRANSLATED: x="+t+" y="+e),this._pushGroup();var r=this._applyOpts(null,!1,!1,!0);if(0!==this.state.selected.font.escapement&&(r.transform="rotate("+[-this.state.selected.font.escapement/10,t,e]+")",r.style="dominant-baseline: middle; text-anchor: start;"),this.state.bkmode===c.GDI.MixMode.OPAQUE){if(null==this.state._svgtextbkfilter){var a=c._makeUniqueId("f"),h=this._svg.filter(this._getSvgDef(),a,0,0,1,1);this._svg.filters.flood(h,null,"#"+this.state.bkcolor.toHex(),1),this._svg.filters.composite(h,null,null,"SourceGraphic"),this.state._svgtextbkfilter=h}r.filter="url(#"+this.state._svgtextbkfilter.id+")"}this._svg.text(this.state._svggroup,t,e,i,r)},t.prototype.lineTo=function(t,e){c.log("[gdi] lineTo: x="+t+" y="+e+" with pen "+this.state.selected.pen.toString());var i=this._todevX(t),s=this._todevY(e),n=this._todevX(this.state.x),o=this._todevY(this.state.y);this.state.x=t,this.state.y=e,c.log("[gdi] lineTo: TRANSLATED: toX="+i+" toY="+s+" fromX="+n+" fromY="+o),this._pushGroup();var r=this._applyOpts(null,!0,!1,!1);this._svg.line(this.state._svggroup,n,o,i,s,r)},t.prototype.moveTo=function(t,e){c.log("[gdi] moveTo: x="+t+" y="+e),this.state.x=t,this.state.y=e},t.prototype.polygon=function(t,e){c.log("[gdi] polygon: points="+t+" with pen "+this.state.selected.pen.toString()+" and brush "+this.state.selected.brush.toString());for(var i=[],s=0;s<t.length;s++){var n=t[s];i.push([this._todevX(n.x),this._todevY(n.y)])}c.log("[gdi] polygon: TRANSLATED: pts="+i),e&&this._pushGroup();var o={"fill-rule":this.state.polyfillmode===c.GDI.PolyFillMode.ALTERNATE?"evenodd":"nonzero"};this._applyOpts(o,!0,!0,!1),this._svg.polygon(this.state._svggroup,i,o)},t.prototype.polyPolygon=function(t){c.log("[gdi] polyPolygon: polygons.length="+t.length+" with pen "+this.state.selected.pen.toString()+" and brush "+this.state.selected.brush.toString());for(var e=t.length,i=0;i<e;i++)this.polygon(t[i],0===i)},t.prototype.polyline=function(t){c.log("[gdi] polyline: points="+t+" with pen "+this.state.selected.pen.toString());for(var e=[],i=0;i<t.length;i++){var s=t[i];e.push([this._todevX(s.x),this._todevY(s.y)])}c.log("[gdi] polyline: TRANSLATED: pts="+e),this._pushGroup();var n=this._applyOpts({fill:"none"},!0,!1,!1);this._svg.polyline(this.state._svggroup,e,n)},t.prototype.ellipse=function(t){c.log("[gdi] ellipse: rect="+t.toString()+" with pen "+this.state.selected.pen.toString()+" and brush "+this.state.selected.brush.toString());var e=this._todevY(t.bottom),i=this._todevX(t.right),s=this._todevY(t.top),n=this._todevX(t.left);c.log("[gdi] ellipse: TRANSLATED: bottom="+e+" right="+i+" top="+s+" left="+n),this._pushGroup();var o=(i-n)/2,r=(e-s)/2,a=this._applyOpts(null,!0,!0,!1);this._svg.ellipse(this.state._svggroup,n+o,s+r,o,r,a)},t.prototype.excludeClipRect=function(t){c.log("[gdi] excludeClipRect: rect="+t.toString()),this._getClipRgn().subtract(t)},t.prototype.intersectClipRect=function(t){c.log("[gdi] intersectClipRect: rect="+t.toString()),this._getClipRgn().intersect(t)},t.prototype.offsetClipRgn=function(t,e){c.log("[gdi] offsetClipRgn: offX="+t+" offY="+e),this._getClipRgn().offset(t,e)},t.prototype.setTextAlign=function(t){c.log("[gdi] setTextAlign: textAlignmentMode=0x"+t.toString(16)),this.state.textalign=t},t.prototype.setBkMode=function(t){c.log("[gdi] setBkMode: bkMode=0x"+t.toString(16)),this.state.bkmode=t},t.prototype.setTextColor=function(t){c.log("[gdi] setTextColor: textColor="+t.toString()),this.state.textcolor=t},t.prototype.setBkColor=function(t){c.log("[gdi] setBkColor: bkColor="+t.toString()),this.state.bkcolor=t,this.state._svgtextbkfilter=null},t.prototype.setPolyFillMode=function(t){c.log("[gdi] setPolyFillMode: polyFillMode="+t),this.state.polyfillmode=t},t.prototype.createBrush=function(t){var e=this._storeObject(t);c.log("[gdi] createBrush: brush="+t.toString()+" with handle "+e)},t.prototype.createFont=function(t){var e=this._storeObject(t);c.log("[gdi] createFont: font="+t.toString()+" with handle "+e)},t.prototype.createPen=function(t){var e=this._storeObject(t);c.log("[gdi] createPen: pen="+t.toString()+" width handle "+e)},t.prototype.createPalette=function(t){var e=this._storeObject(t);c.log("[gdi] createPalette: palette="+t.toString()+" width handle "+e)},t.prototype.createRegion=function(t){var e=this._storeObject(t);c.log("[gdi] createRegion: region="+t.toString()+" width handle "+e)},t.prototype.createPatternBrush=function(t){var e=this._storeObject(t);c.log("[gdi] createRegion: region="+t.toString()+" width handle "+e)},t.prototype.selectObject=function(t,e){var i=this._getObject(t);null==i||null!=e&&i.type!==e?c.log("[gdi] selectObject: objIdx="+t+(i?" invalid object type: "+i.type:"[invalid index]")):(this._selectObject(i),c.log("[gdi] selectObject: objIdx="+t+(i?" selected "+i.type+": "+i.toString():"[invalid index]")))},t.prototype.deleteObject=function(t){var e=this._deleteObject(t);c.log("[gdi] deleteObject: objIdx="+t+(e?" deleted object":"[invalid index]"))},t.prototype._pushGroup=function(){if(null==this.state._svggroup||this.state._svgclipChanged){this.state._svgclipChanged=!1,this.state._svgtextbkfilter=null;var t={viewBox:[this.state.vx,this.state.vy,this.state.vw,this.state.vh].join(" "),preserveAspectRatio:"none"};null!=this.state.clip?(c.log("[gdi] new svg x="+this.state.vx+" y="+this.state.vy+" width="+this.state.vw+" height="+this.state.vh+" with clipping"),t["clip-path"]="url(#"+this._getSvgClipPathForRegion(this.state.clip)+")"):c.log("[gdi] new svg x="+this.state.vx+" y="+this.state.vy+" width="+this.state.vw+" height="+this.state.vh+" without clipping"),this.state._svggroup=this._svg.svg(this.state._svggroup,this.state.vx,this.state.vy,this.state.vw,this.state.vh,t)}},t.prototype._storeObject=function(t){for(var e=0;null!=this.objects[e.toString()]&&e<=65535;)e++;return e>65535?(c.log("[gdi] Too many objects!"),-1):(this.objects[e.toString()]=t,e)},t.prototype._getObject=function(t){var e=this.objects[t.toString()];return null==e&&c.log("[gdi] No object with handle "+t),e},t.prototype._getSvgDef=function(){return null==this._svgdefs&&(this._svgdefs=this._svg.defs()),this._svgdefs},t.prototype._getSvgClipPathForRegion=function(t){for(var e in this._svgClipPaths)if(this._svgClipPaths[e]===t)return e;var i=c._makeUniqueId("c"),s=this._svg.clipPath(this._getSvgDef(),i,"userSpaceOnUse");switch(t.complexity){case 1:this._svg.rect(s,this._todevX(t.bounds.left),this._todevY(t.bounds.top),this._todevW(t.bounds.right-t.bounds.left),this._todevH(t.bounds.bottom-t.bounds.top),{fill:"black","stroke-width":0});break;case 2:for(var n=0;n<t.scans.length;n++)for(var o=t.scans[n],r=0;r<o.scanlines.length;r++){var a=o.scanlines[r];this._svg.rect(s,this._todevX(a.left),this._todevY(o.top),this._todevW(a.right-a.left),this._todevH(o.bottom-o.top),{fill:"black","stroke-width":0})}}return this._svgClipPaths[i]=t,i},t.prototype._getSvgPatternForBrush=function(t){for(var e in this._svgPatterns)if(this._svgPatterns[e]===t)return e;var i,s,n;switch(t.style){case c.GDI.BrushStyle.BS_PATTERN:i=t.pattern.getWidth(),s=t.pattern.getHeight();break;case c.GDI.BrushStyle.BS_DIBPATTERNPT:i=t.dibpatternpt.getWidth(),s=t.dibpatternpt.getHeight(),n=t.dibpatternpt.base64ref();break;default:throw new a("Invalid brush style")}var o=c._makeUniqueId("p"),r=this._svg.pattern(this._getSvgDef(),o,0,0,i,s,{patternUnits:"userSpaceOnUse"});return this._svg.image(r,0,0,i,s,n),this._svgPatterns[o]=t,o},t.prototype._selectObject=function(t){this.state.selected[t.type]=t,"region"===t.type&&(this.state._svgclipChanged=!0)},t.prototype._deleteObject=function(t){var e=this.objects[t.toString()];if(null!=e){for(var i=0;i<this.statestack.length;i++){var s=this.statestack[i];s.selected[e.type]===e&&(s.selected[e.type]=this.defObjects[e.type].clone())}return delete this.objects[t.toString()],!0}return c.log("[gdi] Cannot delete object with invalid handle "+t),!1},t.prototype._getClipRgn=function(){var t,e,i,s,n;return null!=this.state.clip?this.state.ownclip||(this.state.clip=this.state.clip.clone()):null!=this.state.selected.region?this.state.clip=this.state.selected.region.clone():this.state.clip=(t=this.state.wx,e=this.state.wy,i=this.state.wx+this.state.ww,s=this.state.wy+this.state.wh,(n=new E(null,null)).bounds=new d(null,t,e,i,s),n._updateComplexity(),n),this.state.ownclip=!0,this.state.clip},t.prototype._todevX=function(t){return Math.floor((t-this.state.wx)*(this.state.vw/this.state.ww))+this.state.vx},t.prototype._todevY=function(t){return Math.floor((t-this.state.wy)*(this.state.vh/this.state.wh))+this.state.vy},t.prototype._todevW=function(t){return Math.floor(t*(this.state.vw/this.state.ww))+this.state.vx},t.prototype._todevH=function(t){return Math.floor(t*(this.state.vh/this.state.wh))+this.state.vy},t.prototype._tologicalX=function(t){return Math.floor((t-this.state.vx)/(this.state.vw/this.state.ww))+this.state.wx},t.prototype._tologicalY=function(t){return Math.floor((t-this.state.vy)/(this.state.vh/this.state.wh))+this.state.wy},t.prototype._tologicalW=function(t){return Math.floor(t/(this.state.vw/this.state.ww))+this.state.wx},t.prototype._tologicalH=function(t){return Math.floor(t/(this.state.vh/this.state.wh))+this.state.wy},t.prototype._applyOpts=function(t,e,i,s){if(null==t&&(t={}),e){var n=this.state.selected.pen;if(n.style!==c.GDI.PenStyle.PS_NULL){t.stroke="#"+n.color.toHex(),t["stroke-width"]=this._todevW(n.width.x);var o=void 0;0!=(n.linecap&c.GDI.PenStyle.PS_ENDCAP_SQUARE)?(t["stroke-linecap"]="square",o=1):0!=(n.linecap&c.GDI.PenStyle.PS_ENDCAP_FLAT)?(t["stroke-linecap"]="butt",o=t["stroke-width"]):(t["stroke-linecap"]="round",o=1),0!=(n.join&c.GDI.PenStyle.PS_JOIN_BEVEL)?t["stroke-linejoin"]="bevel":0!=(n.join&c.GDI.PenStyle.PS_JOIN_MITER)?t["stroke-linejoin"]="miter":t["stroke-linejoin"]="round";var r=4*t["stroke-width"],a=2*t["stroke-width"];switch(n.style){case c.GDI.PenStyle.PS_DASH:t["stroke-dasharray"]=[r,a].toString();break;case c.GDI.PenStyle.PS_DOT:t["stroke-dasharray"]=[o,a].toString();break;case c.GDI.PenStyle.PS_DASHDOT:t["stroke-dasharray"]=[r,a,o,a].toString();break;case c.GDI.PenStyle.PS_DASHDOTDOT:t["stroke-dasharray"]=[r,a,o,a,o,a].toString()}}}if(i){var h=this.state.selected.brush;switch(h.style){case c.GDI.BrushStyle.BS_SOLID:t.fill="#"+h.color.toHex();break;case c.GDI.BrushStyle.BS_PATTERN:case c.GDI.BrushStyle.BS_DIBPATTERNPT:t.fill="url(#"+this._getSvgPatternForBrush(h)+")";break;case c.GDI.BrushStyle.BS_NULL:t.fill="none";break;default:c.log("[gdi] unsupported brush style: "+h.style),t.fill="none"}}if(s){var l=this.state.selected.font;t["font-family"]=l.facename,t["font-size"]=this._todevH(Math.abs(l.height)),t.fill="#"+this.state.textcolor.toHex()}return t},t}(),G=function(){function t(t,e){this._records=[];var i=!1,s=e,n=function(){t.seek(s);var e=t.readUint32();if(e<3)throw new a("Invalid record size");var n=t.readUint16();switch(n){case c.GDI.RecordType.META_EOF:return i=!0,"break-main_loop";case c.GDI.RecordType.META_SETMAPMODE:var r=t.readUint16();o._records.push((function(t){t.setMapMode(r)}));break;case c.GDI.RecordType.META_SETWINDOWORG:var h=t.readInt16(),l=t.readInt16();o._records.push((function(t){t.setWindowOrg(l,h)}));break;case c.GDI.RecordType.META_SETWINDOWEXT:var T=t.readInt16(),f=t.readInt16();o._records.push((function(t){t.setWindowExt(f,T)}));break;case c.GDI.RecordType.META_OFFSETWINDOWORG:var g=t.readInt16(),_=t.readInt16();o._records.push((function(t){t.offsetWindowOrg(_,g)}));break;case c.GDI.RecordType.META_SETVIEWPORTORG:var y=t.readInt16(),S=t.readInt16();o._records.push((function(t){t.setViewportOrg(S,y)}));break;case c.GDI.RecordType.META_SETVIEWPORTEXT:var I=t.readInt16(),A=t.readInt16();o._records.push((function(t){t.setViewportExt(A,I)}));break;case c.GDI.RecordType.META_OFFSETVIEWPORTORG:var w=t.readInt16(),P=t.readInt16();o._records.push((function(t){t.offsetViewportOrg(P,w)}));break;case c.GDI.RecordType.META_SAVEDC:o._records.push((function(t){t.saveDC()}));break;case c.GDI.RecordType.META_RESTOREDC:var C=t.readInt16();o._records.push((function(t){t.restoreDC(C)}));break;case c.GDI.RecordType.META_SETSTRETCHBLTMODE:var N=t.readUint16();o._records.push((function(t){t.setStretchBltMode(N)}));break;case c.GDI.RecordType.META_DIBBITBLT:var G=3+(n>>8)!==e,x=t.readUint16()|t.readUint16()<<16,B=t.readInt16(),L=t.readInt16();G||t.skip(2);var k=t.readInt16(),U=t.readInt16(),H=t.readInt16(),F=t.readInt16();if(G){var j=2*e-(t.pos-s),X=new v(t,j);o._records.push((function(t){t.dibBits(L,B,F,H,U,k,x,X)}))}break;case c.GDI.RecordType.META_DIBSTRETCHBLT:G=3+(n>>8)!==e;var W=t.readUint16()|t.readUint16()<<16,Y=t.readInt16(),V=t.readInt16(),z=t.readInt16(),J=t.readInt16(),Z=t.readInt16(),q=t.readInt16(),K=t.readInt16(),Q=t.readInt16(),$=(j=2*e-(t.pos-s),new v(t,j));o._records.push((function(t){t.stretchDibBits(J,z,V,Y,Q,K,q,Z,W,$)}));break;case c.GDI.RecordType.META_STRETCHDIB:var tt=t.readUint16()|t.readUint16()<<16,et=t.readInt16(),it=t.readInt16(),st=t.readInt16(),nt=t.readInt16(),ot=t.readInt16(),rt=t.readInt16(),at=t.readInt16(),ht=t.readInt16(),lt=t.readInt16(),ct=(j=2*e-(t.pos-s),new v(t,j));o._records.push((function(t){t.stretchDib(ot,nt,st,it,lt,ht,at,rt,tt,et,ct)}));break;case c.GDI.RecordType.META_ESCAPE:var pt=t.readUint16(),ut=t.readUint16(),dt=t.pos,Tt=new p(t,dt);o._records.push((function(t){t.escape(pt,Tt,dt,ut)}));break;case c.GDI.RecordType.META_SETTEXTALIGN:var ft=t.readUint16();o._records.push((function(t){t.setTextAlign(ft)}));break;case c.GDI.RecordType.META_SETBKMODE:var Et=t.readUint16();o._records.push((function(t){t.setBkMode(Et)}));break;case c.GDI.RecordType.META_SETTEXTCOLOR:var gt=new R(t);o._records.push((function(t){t.setTextColor(gt)}));break;case c.GDI.RecordType.META_SETBKCOLOR:var _t=new R(t);o._records.push((function(t){t.setBkColor(_t)}));break;case c.GDI.RecordType.META_CREATEBRUSHINDIRECT:j=2*e-(t.pos-s);var yt=new D(t,j,!1);o._records.push((function(t){t.createBrush(yt)}));break;case c.GDI.RecordType.META_DIBCREATEPATTERNBRUSH:j=2*e-(t.pos-s);var St=new D(t,j,!0);o._records.push((function(t){t.createBrush(St)}));break;case c.GDI.RecordType.META_CREATEPENINDIRECT:var It=new M(t);o._records.push((function(t){t.createPen(It)}));break;case c.GDI.RecordType.META_CREATEFONTINDIRECT:j=2*e-(t.pos-s);var vt=new O(t,j);o._records.push((function(t){t.createFont(vt)}));break;case c.GDI.RecordType.META_SELECTOBJECT:var At=t.readUint16();o._records.push((function(t){t.selectObject(At,null)}));break;case c.GDI.RecordType.META_SELECTPALETTE:var bt=t.readUint16();o._records.push((function(t){t.selectObject(bt,"palette")}));break;case c.GDI.RecordType.META_SELECTCLIPREGION:var wt=t.readUint16();o._records.push((function(t){t.selectObject(wt,"region")}));break;case c.GDI.RecordType.META_DELETEOBJECT:var Rt=t.readUint16();o._records.push((function(t){t.deleteObject(Rt)}));break;case c.GDI.RecordType.META_RECTANGLE:var Ot=new d(t);o._records.push((function(t){t.rectangle(Ot,0,0)}));break;case c.GDI.RecordType.META_ROUNDRECT:var Dt=t.readInt16(),Mt=t.readInt16(),Pt=new d(t);o._records.push((function(t){t.rectangle(Pt,Mt,Dt)}));break;case c.GDI.RecordType.META_LINETO:var mt=t.readInt16(),Ct=t.readInt16();o._records.push((function(t){t.lineTo(Ct,mt)}));break;case c.GDI.RecordType.META_MOVETO:var Nt=t.readInt16(),Gt=t.readInt16();o._records.push((function(t){t.moveTo(Gt,Nt)}));break;case c.GDI.RecordType.META_TEXTOUT:if((Ht=t.readInt16())>0){var xt=t.readString(Ht);t.skip(Ht%2);var Bt=t.readInt16(),Lt=t.readInt16();o._records.push((function(t){t.textOut(Lt,Bt,xt)}))}break;case c.GDI.RecordType.META_EXTTEXTOUT:var kt=t.readInt16(),Ut=t.readInt16(),Ht=t.readInt16(),Ft=t.readUint16(),jt=null,Xt=null;2*e===14+Ht+Ht%2&&(jt=!1,Xt=!1),2*e===22+Ht+Ht%2&&(jt=!0,Xt=!1),2*e===14+Ht+Ht%2+2*Ht&&(jt=!1,Xt=!0),2*e===22+Ht+Ht%2+2*Ht&&(jt=!0,Xt=!0);var Wt=jt?new d(t):null;if(Ht>0){var Yt=t.readString(Ht);t.skip(Ht%2);var Vt=[];if(Xt)for(var zt=0;zt<Yt.length;zt++)Vt.push(t.readInt16());o._records.push((function(t){t.extTextOut(Ut,kt,Yt,Ft,Wt,Vt)}))}break;case c.GDI.RecordType.META_EXCLUDECLIPRECT:var Jt=new d(t);o._records.push((function(t){t.excludeClipRect(Jt)}));break;case c.GDI.RecordType.META_INTERSECTCLIPRECT:var Zt=new d(t);o._records.push((function(t){t.intersectClipRect(Zt)}));break;case c.GDI.RecordType.META_POLYGON:for(var qt=t.readInt16(),Kt=[];qt>0;)Kt.push(new u(t)),qt--;o._records.push((function(t){t.polygon(Kt,!0)}));break;case c.GDI.RecordType.META_SETPOLYFILLMODE:var Qt=t.readUint16();o._records.push((function(t){t.setPolyFillMode(Qt)}));break;case c.GDI.RecordType.META_POLYPOLYGON:qt=t.readUint16();var $t=[];for(zt=0;zt<qt;zt++)$t.push(t.readUint16());var te=[];for(zt=0;zt<qt;zt++){for(var ee=$t[zt],ie=[],se=0;se<ee;se++)ie.push(new u(t));te.push(ie)}o._records.push((function(t){t.polyPolygon(te)}));break;case c.GDI.RecordType.META_POLYLINE:qt=t.readInt16();for(var ne=[];qt>0;)ne.push(new u(t)),qt--;o._records.push((function(t){t.polyline(ne)}));break;case c.GDI.RecordType.META_ELLIPSE:var oe=new d(t);o._records.push((function(t){t.ellipse(oe)}));break;case c.GDI.RecordType.META_CREATEPALETTE:var re=new m(t);o._records.push((function(t){t.createPalette(re)}));break;case c.GDI.RecordType.META_CREATEREGION:var ae=new E(t);o._records.push((function(t){t.createRegion(ae)}));break;case c.GDI.RecordType.META_CREATEPATTERNBRUSH:j=2*e-(t.pos-s);var he=new b(t,j),le=new D(t,j,he);o._records.push((function(t){t.createPatternBrush(le)}));break;case c.GDI.RecordType.META_OFFSETCLIPRGN:var ce=t.readInt16(),pe=t.readInt16();o._records.push((function(t){t.offsetClipRgn(pe,ce)}));break;case c.GDI.RecordType.META_REALIZEPALETTE:case c.GDI.RecordType.META_SETPALENTRIES:case c.GDI.RecordType.META_SETROP2:case c.GDI.RecordType.META_SETRELABS:case c.GDI.RecordType.META_SETTEXTCHAREXTRA:case c.GDI.RecordType.META_RESIZEPALETTE:case c.GDI.RecordType.META_SETLAYOUT:case c.GDI.RecordType.META_FILLREGION:case c.GDI.RecordType.META_SETMAPPERFLAGS:case c.GDI.RecordType.META_SETTEXTJUSTIFICATION:case c.GDI.RecordType.META_SCALEWINDOWEXT:case c.GDI.RecordType.META_SCALEVIEWPORTEXT:case c.GDI.RecordType.META_FLOODFILL:case c.GDI.RecordType.META_FRAMEREGION:case c.GDI.RecordType.META_ANIMATEPALETTE:case c.GDI.RecordType.META_EXTFLOODFILL:case c.GDI.RecordType.META_SETPIXEL:case c.GDI.RecordType.META_PATBLT:case c.GDI.RecordType.META_PIE:case c.GDI.RecordType.META_STRETCHBLT:case c.GDI.RecordType.META_INVERTREGION:case c.GDI.RecordType.META_PAINTREGION:case c.GDI.RecordType.META_ARC:case c.GDI.RecordType.META_CHORD:case c.GDI.RecordType.META_BITBLT:case c.GDI.RecordType.META_SETDIBTODEV:default:var ue="UNKNOWN";for(var de in c.GDI.RecordType)if(c.GDI.RecordType[de]===n){ue=de;break}c.log("[WMF] "+ue+" record (0x"+n.toString(16)+") at offset 0x"+s.toString(16)+" with "+2*e+" bytes")}s+=2*e},o=this;t:for(;!i&&"break-main_loop"!==n(););if(!i)throw new a("Could not read all records")}return t.prototype.play=function(t){for(var e=this._records.length,i=0;i<e;i++)this._records[i](t)},t}(),x=function(){function t(t){this.parse(t),c.log("WMFJS.Renderer instantiated")}return t.prototype.render=function(t){var e=document.createElementNS("http://www.w3.org/2000/svg","svg");return this._render(new o(e),t.mapMode,t.xExt,t.yExt),e.setAttribute("viewBox",[0,0,t.xExt,t.yExt].join(" ")),e.setAttribute("preserveAspectRatio","none"),e.setAttribute("width",t.width),e.setAttribute("height",t.height),e},t.prototype.parse=function(t){this._img=null;var e,i,s,n,o=new p(t),r=o.readUint32();switch(2596720087===r?(s=new L(o),n=o.pos,e=o.readUint16(),i=o.readUint16()):(n=0,e=65535&r,i=r>>>16&65535),e){case c.GDI.MetafileType.MEMORYMETAFILE:case c.GDI.MetafileType.DISKMETAFILE:if(i===c.GDI.METAHEADER_SIZE/2){var h=o.readUint16();switch(h){case c.GDI.MetafileVersion.METAVERSION100:case c.GDI.MetafileVersion.METAVERSION300:this._img=new k(o,s,h,n+2*i)}}}if(null==this._img)throw new a("Format not recognized")},t.prototype._render=function(t,e,i,s){var n=new N(t);n.setViewportExt(i,s),n.setMapMode(e),c.log("[WMF] BEGIN RENDERING ---\x3e"),this._img.render(n),c.log("[WMF] <--- DONE RENDERING")},t}(),B=function(){function t(t){this.left=t.readInt16(),this.top=t.readInt16(),this.right=t.readInt16(),this.bottom=t.readInt16()}return t.prototype.toString=function(){return"{left: "+this.left+", top: "+this.top+", right: "+this.right+", bottom: "+this.bottom+"}"},t}(),L=function(t){t.skip(2),this.boundingBox=new B(t),this.unitsPerInch=t.readInt16(),t.skip(4),t.skip(2),c.log("Got bounding box "+this.boundingBox+" and "+this.unitsPerInch+" units/inch")},k=function(){function t(t,e,i,s){this._version=i,this._hdrsize=s,this._placable=e,this._records=new G(t,this._hdrsize)}return t.prototype.render=function(t){this._records.play(t)},t}();return e})()));
//# sourceMappingURL=WMFJS.bundle.min.js.map