UNPKG

gn-rtf.js

Version:

Render RTF documents in HTML. This also includes rendering WMF and EMF images which are often contained in RTF documents.

1,037 lines (985 loc) 154 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["EMFJS"] = factory(); else root["EMFJS"] = factory(); })(this, () => { return /******/ (() => { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ "./src/emfjs/Bitmap.ts": /*!*****************************!*\ !*** ./src/emfjs/Bitmap.ts ***! \*****************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ BitmapInfo: () => (/* binding */ BitmapInfo), /* harmony export */ DIBitmap: () => (/* binding */ DIBitmap) /* harmony export */ }); /* harmony import */ var _Helper__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Helper */ "./src/emfjs/Helper.ts"); /* The MIT License (MIT) Copyright (c) 2016 Tom Zoehner Copyright (c) 2018 Thomas Bluemel 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. */ var BitmapCoreHeader = /** @class */ (function () { function BitmapCoreHeader(reader, skipsize) { if (skipsize) { reader.skip(4); } this.width = reader.readUint16(); this.height = reader.readUint16(); this.planes = reader.readUint16(); this.bitcount = reader.readUint16(); } BitmapCoreHeader.prototype.colors = function () { return this.bitcount <= 8 ? 1 << this.bitcount : 0; }; return BitmapCoreHeader; }()); var BitmapInfoHeader = /** @class */ (function () { function BitmapInfoHeader(reader, skipsize) { if (skipsize) { reader.skip(4); } this.width = reader.readInt32(); this.height = reader.readInt32(); this.planes = reader.readUint16(); this.bitcount = reader.readUint16(); this.compression = reader.readUint32(); this.sizeimage = reader.readUint32(); this.xpelspermeter = reader.readInt32(); this.ypelspermeter = reader.readInt32(); this.clrused = reader.readUint32(); this.clrimportant = reader.readUint32(); } BitmapInfoHeader.prototype.colors = function () { if (this.clrused !== 0) { return this.clrused < 256 ? this.clrused : 256; } else { return this.bitcount > 8 ? 0 : 1 << this.bitcount; } }; return BitmapInfoHeader; }()); var BitmapInfo = /** @class */ (function () { function BitmapInfo(reader, usergb) { this._usergb = usergb; var hdrsize = reader.readUint32(); this._infosize = hdrsize; if (hdrsize === _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.BITMAPCOREHEADER_SIZE) { this._header = new BitmapCoreHeader(reader, false); this._infosize += this._header.colors() * (usergb ? 3 : 2); } else { this._header = new BitmapInfoHeader(reader, false); var masks = this._header.compression === _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.BitmapCompression.BI_BITFIELDS ? 3 : 0; if (hdrsize <= _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.BITMAPINFOHEADER_SIZE + (masks * 4)) { this._infosize = _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.BITMAPINFOHEADER_SIZE + (masks * 4); } this._infosize += this._header.colors() * (usergb ? 4 : 2); } } BitmapInfo.prototype.getWidth = function () { return this._header.width; }; BitmapInfo.prototype.getHeight = function () { return Math.abs(this._header.height); }; BitmapInfo.prototype.infosize = function () { return this._infosize; }; BitmapInfo.prototype.header = function () { return this._header; }; return BitmapInfo; }()); var DIBitmap = /** @class */ (function () { function DIBitmap(reader, bitmapInfo) { this._reader = reader; this._offset = reader.pos; this._location = bitmapInfo; this._info = new BitmapInfo(reader, true); } DIBitmap.prototype.getWidth = function () { return this._info.getWidth(); }; DIBitmap.prototype.getHeight = function () { return this._info.getHeight(); }; DIBitmap.prototype.totalSize = function () { return this._location.header.size + this._location.data.size; }; DIBitmap.prototype.makeBitmapFileHeader = function () { var buf = new ArrayBuffer(14); var view = new Uint8Array(buf); view[0] = 0x42; view[1] = 0x4d; _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper._writeUint32Val(view, 2, this.totalSize() + 14); _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper._writeUint32Val(view, 10, this._info.infosize() + 14); return _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper._blobToBinary(view); }; DIBitmap.prototype.base64ref = function () { var prevpos = this._reader.pos; this._reader.seek(this._offset); var mime = "image/bmp"; var header = this._info.header(); var data; if (header instanceof BitmapInfoHeader && header.compression != null) { switch (header.compression) { case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.BitmapCompression.BI_JPEG: mime = "data:image/jpeg"; break; case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.BitmapCompression.BI_PNG: mime = "data:image/png"; break; default: data = this.makeBitmapFileHeader(); break; } } else { data = this.makeBitmapFileHeader(); } this._reader.seek(this._location.header.offset); if (data != null) { data += this._reader.readBinary(this._location.header.size); } else { data = this._reader.readBinary(this._location.header.size); } this._reader.seek(this._location.data.offset); data += this._reader.readBinary(this._location.data.size); var ref = "data:" + mime + ";base64," + btoa(data); this._reader.seek(prevpos); return ref; }; return DIBitmap; }()); /***/ }), /***/ "./src/emfjs/Blob.ts": /*!***************************!*\ !*** ./src/emfjs/Blob.ts ***! \***************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ Blob: () => (/* binding */ Blob) /* harmony export */ }); /* harmony import */ var _Helper__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Helper */ "./src/emfjs/Helper.ts"); /* The MIT License (MIT) Copyright (c) 2016 Tom Zoehner Copyright (c) 2018 Thomas Bluemel 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. */ var Blob = /** @class */ (function () { function Blob(blob, offset) { if (blob instanceof Blob) { this.blob = blob.blob; this.data = blob.data; this.pos = offset || blob.pos; } else { this.blob = blob; this.data = new Uint8Array(blob); this.pos = offset || 0; } } Blob.prototype.eof = function () { return this.pos >= this.data.length; }; Blob.prototype.seek = function (newpos) { if (newpos < 0 || newpos > this.data.length) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Invalid seek position"); } this.pos = newpos; }; Blob.prototype.skip = function (cnt) { var newPos = this.pos + cnt; if (newPos > this.data.length) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Unexpected end of file"); } this.pos = newPos; }; Blob.prototype.readBinary = function (cnt) { var end = this.pos + cnt; if (end > this.data.length) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Unexpected end of file"); } var ret = ""; while (cnt-- > 0) { ret += String.fromCharCode(this.data[this.pos++]); } return ret; }; Blob.prototype.readInt8 = function () { if (this.pos + 1 > this.data.length) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Unexpected end of file"); } return this.data[this.pos++]; }; Blob.prototype.readUint8 = function () { return this.readInt8() >>> 0; }; Blob.prototype.readInt32 = function () { if (this.pos + 4 > this.data.length) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Unexpected end of file"); } var val = this.data[this.pos++]; val |= this.data[this.pos++] << 8; val |= this.data[this.pos++] << 16; val |= this.data[this.pos++] << 24; return val; }; Blob.prototype.readUint32 = function () { return this.readInt32() >>> 0; }; Blob.prototype.readUint16 = function () { if (this.pos + 2 > this.data.length) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Unexpected end of file"); } var val = this.data[this.pos++]; val |= this.data[this.pos++] << 8; return val; }; Blob.prototype.readInt16 = function () { var val = this.readUint16(); if (val > 32767) { val -= 65536; } return val; }; Blob.prototype.readString = function (length) { if (this.pos + length > this.data.length) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Unexpected end of file"); } var ret = ""; for (var i = 0; i < length; i++) { ret += String.fromCharCode(this.data[this.pos++] >>> 0); } return ret; }; Blob.prototype.readNullTermString = function (maxSize) { var ret = ""; if (maxSize > 0) { maxSize--; for (var i = 0; i < maxSize; i++) { if (this.pos + i + 1 > this.data.length) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Unexpected end of file"); } var byte = this.data[this.pos + i] >>> 0; if (byte === 0) { break; } ret += String.fromCharCode(byte); } } return ret; }; Blob.prototype.readFixedSizeUnicodeString = function (fixedSizeChars) { var ret = ""; for (var i = 0; i < fixedSizeChars; i++) { var charCode = this.readUint16(); if (charCode === 0) { if (++i < fixedSizeChars) { this.skip((fixedSizeChars - i) * 2); } break; } ret += String.fromCharCode(charCode); } return ret; }; return Blob; }()); /***/ }), /***/ "./src/emfjs/EMFRecords.ts": /*!*********************************!*\ !*** ./src/emfjs/EMFRecords.ts ***! \*********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ EMFRecords: () => (/* binding */ EMFRecords) /* harmony export */ }); /* harmony import */ var _Helper__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Helper */ "./src/emfjs/Helper.ts"); /* harmony import */ var _Primitives__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Primitives */ "./src/emfjs/Primitives.ts"); /* harmony import */ var _Region__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Region */ "./src/emfjs/Region.ts"); /* harmony import */ var _Style__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Style */ "./src/emfjs/Style.ts"); /* The MIT License (MIT) Copyright (c) 2016 Tom Zoehner Copyright (c) 2018 Thomas Bluemel 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. */ var EmfHeader = /** @class */ (function () { function EmfHeader(reader, headerSize) { var recordStart = reader.pos - 8; this.size = headerSize; this.bounds = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.RectL(reader); this.frame = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.RectL(reader); if (reader.readUint32() !== _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.FormatSignature.ENHMETA_SIGNATURE) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Invalid header signature"); } reader.skip(4); // version reader.skip(4); // bytes (size of metafile) reader.skip(4); // number of records reader.skip(2); // number of handles reader.skip(2); // reserved var descriptionLen = reader.readUint32(); var descriptionOff = reader.readUint32(); this.nPalEntries = reader.readUint32(); this.refDevCx = reader.readUint32(); this.refDevCy = reader.readUint32(); this.refDevCxMm = reader.readUint32(); this.refDevCyMm = reader.readUint32(); var hdrSize = headerSize; if (descriptionLen > 0) { if (descriptionOff < 88) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Invalid header description offset"); } hdrSize = descriptionOff + (descriptionLen * 2); if (hdrSize > headerSize) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Invalid header description length"); } var prevPos = reader.pos; reader.seek(recordStart + descriptionOff); this.description = reader.readFixedSizeUnicodeString(descriptionLen); reader.seek(prevPos); } else { this.description = ""; } if (hdrSize >= 100) { // We have a EmfMetafileHeaderExtension1 record var pixelFormatSize = reader.readUint32(); var pixelFormatOff = reader.readUint32(); var haveOpenGl = reader.readUint32(); if (haveOpenGl !== 0) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("OpenGL records are not yet supported"); } if (pixelFormatOff !== 0) { if (pixelFormatOff < 100 || pixelFormatOff < hdrSize) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Invalid pixel format offset"); } hdrSize = pixelFormatOff + pixelFormatSize; if (hdrSize > headerSize) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Invalid pixel format size"); } // TODO: read pixel format blob } if (hdrSize >= 108) { // We have a EmfMetafileHeaderExtension2 record this.displayDevCxUm = reader.readUint32(); // in micrometers this.displayDevCyUm = reader.readUint32(); // in micrometers } } } EmfHeader.prototype.toString = function () { return "{bounds: " + this.bounds.toString() + ", frame: " + this.frame.toString() + ", description: " + this.description + "}"; }; return EmfHeader; }()); var EMFRecords = /** @class */ (function () { function EMFRecords(reader, first) { this._records = []; this._header = new EmfHeader(reader, first); var all = false; var curpos = first; var _loop_1 = function () { reader.seek(curpos); var type = reader.readUint32(); var size = reader.readUint32(); if (size < 8) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Invalid record size"); } switch (type) { case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_EOF: all = true; return "break-main_loop"; case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETMAPMODE: { var mapMode_1 = reader.readInt32(); this_1._records.push(function (gdi) { gdi.setMapMode(mapMode_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETWINDOWORGEX: { var x_1 = reader.readInt32(); var y_1 = reader.readInt32(); this_1._records.push(function (gdi) { gdi.setWindowOrgEx(x_1, y_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETWINDOWEXTEX: { var x_2 = reader.readUint32(); var y_2 = reader.readUint32(); this_1._records.push(function (gdi) { gdi.setWindowExtEx(x_2, y_2); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETVIEWPORTORGEX: { var x_3 = reader.readInt32(); var y_3 = reader.readInt32(); this_1._records.push(function (gdi) { gdi.setViewportOrgEx(x_3, y_3); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETVIEWPORTEXTEX: { var x_4 = reader.readUint32(); var y_4 = reader.readUint32(); this_1._records.push(function (gdi) { gdi.setViewportExtEx(x_4, y_4); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SAVEDC: { this_1._records.push(function (gdi) { gdi.saveDC(); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_RESTOREDC: { var saved_1 = reader.readInt32(); this_1._records.push(function (gdi) { gdi.restoreDC(saved_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETBKMODE: { var bkMode_1 = reader.readUint32(); this_1._records.push(function (gdi) { gdi.setBkMode(bkMode_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETBKCOLOR: { var bkColor_1 = new _Style__WEBPACK_IMPORTED_MODULE_3__.ColorRef(reader); this_1._records.push(function (gdi) { gdi.setBkColor(bkColor_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_CREATEBRUSHINDIRECT: { var index_1 = reader.readUint32(); var brush_1 = new _Style__WEBPACK_IMPORTED_MODULE_3__.Brush(reader); this_1._records.push(function (gdi) { gdi.createBrush(index_1, brush_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_CREATEPEN: { var index_2 = reader.readUint32(); var pen_1 = new _Style__WEBPACK_IMPORTED_MODULE_3__.Pen(reader, null); this_1._records.push(function (gdi) { gdi.createPen(index_2, pen_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_EXTCREATEPEN: { var index_3 = reader.readUint32(); var offBmi = reader.readUint32(); var cbBmi = reader.readUint32(); var offBits = reader.readUint32(); var cbBits = reader.readUint32(); var pen_2 = new _Style__WEBPACK_IMPORTED_MODULE_3__.Pen(reader, { header: { off: offBmi, size: cbBmi, }, data: { off: offBits, size: cbBits, }, }); this_1._records.push(function (gdi) { gdi.createPen(index_3, pen_2); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SELECTOBJECT: { var idx_1 = reader.readUint32(); this_1._records.push(function (gdi) { gdi.selectObject(idx_1, null); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_DELETEOBJECT: { var idx_2 = reader.readUint32(); this_1._records.push(function (gdi) { gdi.deleteObject(idx_2); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_RECTANGLE: { var rect_1 = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.RectL(reader); this_1._records.push(function (gdi) { gdi.rectangle(rect_1, 0, 0); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_ROUNDRECT: { var rect_2 = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.RectL(reader); var corner_1 = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.SizeL(reader); this_1._records.push(function (gdi) { gdi.rectangle(rect_2, corner_1.cx, corner_1.cy); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_LINETO: { var x_5 = reader.readInt32(); var y_5 = reader.readInt32(); this_1._records.push(function (gdi) { gdi.lineTo(x_5, y_5); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_MOVETOEX: { var x_6 = reader.readInt32(); var y_6 = reader.readInt32(); this_1._records.push(function (gdi) { gdi.moveToEx(x_6, y_6); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYGON: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYGON16: { var isSmall = (type === _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYGON16); var bounds_1 = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.RectL(reader); var cnt = reader.readUint32(); var points_1 = []; while (cnt > 0) { points_1.push(isSmall ? new _Primitives__WEBPACK_IMPORTED_MODULE_1__.PointS(reader) : new _Primitives__WEBPACK_IMPORTED_MODULE_1__.PointL(reader)); cnt--; } this_1._records.push(function (gdi) { gdi.polygon(points_1, bounds_1, true); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYPOLYGON: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYPOLYGON16: { var isSmall = (type === _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYPOLYGON16); var bounds_2 = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.RectL(reader); var polyCnt = reader.readUint32(); reader.skip(4); // count var polygonsPtCnts = []; for (var i = 0; i < polyCnt; i++) { polygonsPtCnts.push(reader.readUint32()); } var polygons_1 = []; for (var i = 0; i < polyCnt; i++) { var ptCnt = polygonsPtCnts[i]; var p = []; for (var ip = 0; ip < ptCnt; ip++) { p.push(isSmall ? new _Primitives__WEBPACK_IMPORTED_MODULE_1__.PointS(reader) : new _Primitives__WEBPACK_IMPORTED_MODULE_1__.PointL(reader)); } polygons_1.push(p); } this_1._records.push(function (gdi) { gdi.polyPolygon(polygons_1, bounds_2); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETPOLYFILLMODE: { var polyfillmode_1 = reader.readUint32(); this_1._records.push(function (gdi) { gdi.setPolyFillMode(polyfillmode_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYLINE16: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYLINETO16: { var isLineTo_1 = (type === _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYLINETO16); var bounds_3 = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.RectL(reader); var cnt = reader.readUint32(); var points_2 = []; while (cnt > 0) { points_2.push(new _Primitives__WEBPACK_IMPORTED_MODULE_1__.PointS(reader)); cnt--; } this_1._records.push(function (gdi) { gdi.polyline(isLineTo_1, points_2, bounds_3); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYBEZIER: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYBEZIERTO: { var isPolyBezierTo_1 = (type === _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYBEZIERTO); var bounds_4 = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.RectL(reader); var cnt = reader.readUint32(); var points_3 = []; while (cnt > 0) { points_3.push(new _Primitives__WEBPACK_IMPORTED_MODULE_1__.PointL(reader)); cnt--; } this_1._records.push(function (gdi) { gdi.polybezier(isPolyBezierTo_1, points_3, bounds_4); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYBEZIER16: { var bounds_5 = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.RectL(reader); var start = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.PointL(reader); var cnt = reader.readUint32(); var points_4 = [start]; while (cnt > 0) { points_4.push(new _Primitives__WEBPACK_IMPORTED_MODULE_1__.PointS(reader)); cnt--; } this_1._records.push(function (gdi) { gdi.polybezier(false, points_4, bounds_5); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYBEZIERTO16: { var bounds_6 = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.RectL(reader); var cnt = reader.readUint32(); var points_5 = []; while (cnt > 0) { points_5.push(new _Primitives__WEBPACK_IMPORTED_MODULE_1__.PointS(reader)); cnt--; } this_1._records.push(function (gdi) { gdi.polybezier(true, points_5, bounds_6); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETTEXTALIGN: { var textAlign_1 = reader.readUint32(); this_1._records.push(function (gdi) { gdi.setTextAlign(textAlign_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETSTRETCHBLTMODE: { var stretchMode_1 = reader.readUint32(); this_1._records.push(function (gdi) { gdi.setStretchBltMode(stretchMode_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETBRUSHORGEX: { var origin_1 = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.PointL(reader); this_1._records.push(function (gdi) { gdi.setBrushOrgEx(origin_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_BEGINPATH: { this_1._records.push(function (gdi) { gdi.beginPath(); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_ENDPATH: { this_1._records.push(function (gdi) { gdi.endPath(); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_ABORTPATH: { this_1._records.push(function (gdi) { gdi.abortPath(); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_CLOSEFIGURE: { this_1._records.push(function (gdi) { gdi.closeFigure(); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_FILLPATH: { var bounds_7 = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.RectL(reader); this_1._records.push(function (gdi) { gdi.fillPath(bounds_7); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_STROKEPATH: { var bounds_8 = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.RectL(reader); this_1._records.push(function (gdi) { gdi.strokePath(bounds_8); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SELECTCLIPPATH: { var rgnMode_1 = reader.readUint32(); this_1._records.push(function (gdi) { gdi.selectClipPath(rgnMode_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_EXTSELECTCLIPRGN: { reader.skip(4); var rgnMode_2 = reader.readUint32(); var region_1 = rgnMode_2 !== _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RegionMode.RGN_COPY ? new _Region__WEBPACK_IMPORTED_MODULE_2__.Region(reader) : null; this_1._records.push(function (gdi) { gdi.selectClipRgn(rgnMode_2, region_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_OFFSETCLIPRGN: { var offset_1 = new _Primitives__WEBPACK_IMPORTED_MODULE_1__.PointL(reader); this_1._records.push(function (gdi) { gdi.offsetClipRgn(offset_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETMITERLIMIT: { var miterLimit_1 = reader.readUint32(); this_1._records.push(function (gdi) { gdi.setMiterLimit(miterLimit_1); }); break; } case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYLINE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYLINETO: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYPOLYLINE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETPIXELV: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETMAPPERFLAGS: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETROP2: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETCOLORADJUSTMENT: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETTEXTCOLOR: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETMETARGN: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_EXCLUDECLIPRECT: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_INTERSECTCLIPRECT: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SCALEVIEWPORTEXTEX: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SCALEWINDOWEXTEX: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETWORLDTRANSFORM: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_MODIFYWORLDTRANSFORM: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_ANGLEARC: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_ELLIPSE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_ARC: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_CHORD: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_PIE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SELECTPALETTE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_CREATEPALETTE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETPALETTEENTRIES: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_RESIZEPALETTE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_REALIZEPALETTE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_EXTFLOODFILL: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_ARCTO: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYDRAW: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETARCDIRECTION: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_STROKEANDFILLPATH: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_FLATTENPATH: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_WIDENPATH: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_COMMENT: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_FILLRGN: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_FRAMERGN: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_INVERTRGN: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_PAINTRGN: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_BITBLT: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_STRETCHBLT: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_MASKBLT: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_PLGBLT: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETDIBITSTODEVICE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_STRETCHDIBITS: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_EXTCREATEFONTINDIRECTW: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_EXTTEXTOUTA: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_EXTTEXTOUTW: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYPOLYLINE16: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYDRAW16: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_CREATEMONOBRUSH: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_CREATEDIBPATTERNBRUSHPT: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYTEXTOUTA: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_POLYTEXTOUTW: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETICMMODE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_CREATECOLORSPACE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETCOLORSPACE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_DELETECOLORSPACE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_GLSRECORD: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_GLSBOUNDEDRECORD: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_PIXELFORMAT: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_DRAWESCAPE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_EXTESCAPE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SMALLTEXTOUT: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_FORCEUFIMAPPING: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_NAMEDESCAPE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_COLORCORRECTPALETTE: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETICMPROFILEA: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETICMPROFILEW: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_ALPHABLEND: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETLAYOUT: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_TRANSPARENTBLT: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_GRADIENTFILL: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETLINKEDUFIS: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_SETTEXTJUSTIFICATION: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_COLORMATCHTOTARGETW: case _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType.EMR_CREATECOLORSPACEW: default: { var recordName = "UNKNOWN"; for (var name_1 in _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType) { var recordTypes = _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.RecordType; if (recordTypes[name_1] === type) { recordName = name_1; break; } } _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.log("[EMF] " + recordName + " record (0x" + type.toString(16) + ") at offset 0x" + curpos.toString(16) + " with " + size + " bytes"); break; } } curpos += size; }; var this_1 = this; main_loop: while (!all) { var state_1 = _loop_1(); switch (state_1) { case "break-main_loop": break main_loop; } } if (!all) { throw new _Helper__WEBPACK_IMPORTED_MODULE_0__.EMFJSError("Could not read all records"); } } EMFRecords.prototype.play = function (gdi) { var len = this._records.length; for (var i = 0; i < len; i++) { this._records[i](gdi); } }; return EMFRecords; }()); /***/ }), /***/ "./src/emfjs/GDIContext.ts": /*!*********************************!*\ !*** ./src/emfjs/GDIContext.ts ***! \*********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ GDIContext: () => (/* binding */ GDIContext) /* harmony export */ }); /* harmony import */ var _Helper__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Helper */ "./src/emfjs/Helper.ts"); /* harmony import */ var _Primitives__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Primitives */ "./src/emfjs/Primitives.ts"); /* harmony import */ var _Region__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Region */ "./src/emfjs/Region.ts"); /* harmony import */ var _Style__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Style */ "./src/emfjs/Style.ts"); /* The MIT License (MIT) Copyright (c) 2016 Tom Zoehner Copyright (c) 2018 Thomas Bluemel 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. */ var __extends = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var Path = /** @class */ (function (_super) { __extends(Path, _super); function Path(svgPath, copy) { var _this = _super.call(this, "path") || this; if (svgPath != null) { _this.svgPath = svgPath; } else { _this.svgPath = copy.svgPath; } return _this; } Path.prototype.clone = function () { return new Path(null, this); }; Path.prototype.toString = function () { return "{[path]}"; }; return Path; }(_Primitives__WEBPACK_IMPORTED_MODULE_1__.Obj)); function createStockObjects() { // Create global stock objects var createSolidBrush = function (r, g, b) { return new _Style__WEBPACK_IMPORTED_MODULE_3__.Brush(null, { style: _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.BrushStyle.BS_SOLID, color: new _Style__WEBPACK_IMPORTED_MODULE_3__.ColorRef(null, r, g, b), }); }; var createSolidPen = function (r, g, b) { return new _Style__WEBPACK_IMPORTED_MODULE_3__.Pen(null, _Helper__WEBPACK_IMPORTED_MODULE_0__.Helper.GDI.PenStyle.PS_SOLID, 1, new _Style__WEBPACK_IMPORTED_MODULE_3__.ColorRef(null, r, g, b), null); }; var stockObjs = { WHITE_BRUSH: createSolidBrush(255, 255, 255), LTGRAY_BRUSH: createSolidBrush(212, 208, 200), GRAY_BRUSH: createSolidBrush(128, 128, 128)