mirror of
https://github.com/tbluemel/rtf.js.git
synced 2026-11-30 16:47:59 +01:00
Enable member-access tslint rule
This commit is contained in:
+280
-287
@@ -2242,207 +2242,6 @@ var GDIContext = /** @class */ (function () {
|
||||
this.statestack = [this.state];
|
||||
this.objects = {};
|
||||
}
|
||||
GDIContext.prototype._pushGroup = function () {
|
||||
if (this.state._svggroup == null || this.state._svgclipChanged) {
|
||||
this.state._svgclipChanged = false;
|
||||
this.state._svgtextbkfilter = null;
|
||||
var settings = {
|
||||
viewBox: [this.state.vx, this.state.vy, this.state.vw, this.state.vh].join(" "),
|
||||
preserveAspectRatio: "none",
|
||||
};
|
||||
if (this.state.clip != null) {
|
||||
Helper.log("[gdi] new svg x=" + this.state.vx + " y=" + this.state.vy + " width=" + this.state.vw
|
||||
+ " height=" + this.state.vh + " with clipping");
|
||||
settings["clip-path"] = "url(#" + this._getSvgClipPathForRegion(this.state.clip) + ")";
|
||||
}
|
||||
else {
|
||||
Helper.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, settings);
|
||||
}
|
||||
};
|
||||
GDIContext.prototype._getStockObject = function (idx) {
|
||||
if (idx >= 0x80000000 && idx <= 0x80000011) {
|
||||
return _StockObjects[(idx - 0x80000000).toString()];
|
||||
}
|
||||
else if (idx === Helper.GDI.StockObject.DC_BRUSH) {
|
||||
return this.state.selected.brush;
|
||||
}
|
||||
else if (idx === Helper.GDI.StockObject.DC_PEN) {
|
||||
return this.state.selected.pen;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
GDIContext.prototype._storeObject = function (obj, idx) {
|
||||
if (!idx) {
|
||||
idx = 0;
|
||||
while (this.objects[idx.toString()] != null && idx <= 65535) {
|
||||
idx++;
|
||||
}
|
||||
if (idx > 65535) {
|
||||
Helper.log("[gdi] Too many objects!");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
this.objects[idx.toString()] = obj;
|
||||
return idx;
|
||||
};
|
||||
GDIContext.prototype._getObject = function (objIdx) {
|
||||
var obj = this.objects[objIdx.toString()];
|
||||
if (obj == null) {
|
||||
obj = this._getStockObject(objIdx);
|
||||
if (obj == null) {
|
||||
Helper.log("[gdi] No object with handle " + objIdx);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
GDIContext.prototype._getSvgDef = function () {
|
||||
if (this._svgdefs == null) {
|
||||
this._svgdefs = this._svg.defs();
|
||||
}
|
||||
return this._svgdefs;
|
||||
};
|
||||
GDIContext.prototype._getSvgClipPathForRegion = function (region) {
|
||||
for (var existingId in this._svgClipPaths) {
|
||||
var rgn = this._svgClipPaths[existingId];
|
||||
if (rgn === region) {
|
||||
return existingId;
|
||||
}
|
||||
}
|
||||
var id = Helper._makeUniqueId("c");
|
||||
var sclip = this._svg.clipPath(this._getSvgDef(), id, "userSpaceOnUse");
|
||||
switch (region.complexity) {
|
||||
case 1:
|
||||
this._svg.rect(sclip, this._todevX(region.bounds.left), this._todevY(region.bounds.top), this._todevW(region.bounds.right - region.bounds.left), this._todevH(region.bounds.bottom - region.bounds.top), { fill: "black", strokeWidth: 0 });
|
||||
break;
|
||||
case 2:
|
||||
for (var i = 0; i < region.scans.length; i++) {
|
||||
var scan = region.scans[i];
|
||||
for (var j = 0; j < scan.scanlines.length; j++) {
|
||||
var scanline = scan.scanlines[j];
|
||||
this._svg.rect(sclip, this._todevX(scanline.left), this._todevY(scan.top), this._todevW(scanline.right - scanline.left), this._todevH(scan.bottom - scan.top), { fill: "black", strokeWidth: 0 });
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
this._svgClipPaths[id] = region;
|
||||
return id;
|
||||
};
|
||||
GDIContext.prototype._getSvgPatternForBrush = function (brush) {
|
||||
for (var existingId in this._svgPatterns) {
|
||||
var pat = this._svgPatterns[existingId];
|
||||
if (pat === brush) {
|
||||
return existingId;
|
||||
}
|
||||
}
|
||||
var width;
|
||||
var height;
|
||||
var img;
|
||||
switch (brush.style) {
|
||||
case Helper.GDI.BrushStyle.BS_PATTERN:
|
||||
width = brush.pattern.getWidth();
|
||||
height = brush.pattern.getHeight();
|
||||
break;
|
||||
case Helper.GDI.BrushStyle.BS_DIBPATTERNPT:
|
||||
width = brush.dibpatternpt.getWidth();
|
||||
height = brush.dibpatternpt.getHeight();
|
||||
img = brush.dibpatternpt.base64ref();
|
||||
break;
|
||||
default:
|
||||
throw new EMFJSError("Invalid brush style");
|
||||
}
|
||||
var id = Helper._makeUniqueId("p");
|
||||
var spat = this._svg.pattern(this._getSvgDef(), id, this.state.brx, this.state.bry, width, height, { patternUnits: "userSpaceOnUse" });
|
||||
this._svg.image(spat, 0, 0, width, height, img);
|
||||
this._svgPatterns[id] = brush;
|
||||
return id;
|
||||
};
|
||||
GDIContext.prototype._selectObject = function (obj) {
|
||||
this.state.selected[obj.type] = obj;
|
||||
switch (obj.type) {
|
||||
case "region":
|
||||
this.state._svgclipChanged = true;
|
||||
break;
|
||||
case "brush":
|
||||
this.state.brx = this.state.nextbrx;
|
||||
this.state.bry = this.state.nextbry;
|
||||
break;
|
||||
}
|
||||
};
|
||||
GDIContext.prototype._deleteObject = function (objIdx) {
|
||||
var obj = this.objects[objIdx.toString()];
|
||||
if (obj != null) {
|
||||
for (var i = 0; i < this.statestack.length; i++) {
|
||||
var state = this.statestack[i];
|
||||
if (state.selected[obj.type] === obj) {
|
||||
state.selected[obj.type] = this.defObjects[obj.type].clone();
|
||||
}
|
||||
}
|
||||
delete this.objects[objIdx.toString()];
|
||||
return true;
|
||||
}
|
||||
Helper.log("[gdi] Cannot delete object with invalid handle " + objIdx);
|
||||
return false;
|
||||
};
|
||||
GDIContext.prototype._getClipRgn = function () {
|
||||
if (this.state.clip != null) {
|
||||
if (!this.state.ownclip) {
|
||||
this.state.clip = this.state.clip.clone();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.state.selected.region != null) {
|
||||
this.state.clip = this.state.selected.region.clone();
|
||||
}
|
||||
else {
|
||||
this.state.clip = CreateSimpleRegion(this.state.wx, this.state.wy, this.state.wx + this.state.ww, this.state.wy + this.state.wh);
|
||||
}
|
||||
}
|
||||
this.state.ownclip = true;
|
||||
return this.state.clip;
|
||||
};
|
||||
GDIContext.prototype._todevX = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.wx) * (this.state.vw / this.state.ww)) + this.state.vx;
|
||||
};
|
||||
GDIContext.prototype._todevY = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.wy) * (this.state.vh / this.state.wh)) + this.state.vy;
|
||||
};
|
||||
GDIContext.prototype._todevW = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val * (this.state.vw / this.state.ww)) + this.state.vx;
|
||||
};
|
||||
GDIContext.prototype._todevH = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val * (this.state.vh / this.state.wh)) + this.state.vy;
|
||||
};
|
||||
GDIContext.prototype._tologicalX = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.vx) / (this.state.vw / this.state.ww)) + this.state.wx;
|
||||
};
|
||||
GDIContext.prototype._tologicalY = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.vy) / (this.state.vh / this.state.wh)) + this.state.wy;
|
||||
};
|
||||
GDIContext.prototype._tologicalW = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val / (this.state.vw / this.state.ww)) + this.state.wx;
|
||||
};
|
||||
GDIContext.prototype._tologicalH = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val / (this.state.vh / this.state.wh)) + this.state.wy;
|
||||
};
|
||||
GDIContext.prototype.setMapMode = function (mode) {
|
||||
Helper.log("[gdi] setMapMode: mode=" + mode);
|
||||
this.state.mapmode = mode;
|
||||
@@ -2505,66 +2304,6 @@ var GDIContext = /** @class */ (function () {
|
||||
GDIContext.prototype.setStretchBltMode = function (stretchMode) {
|
||||
Helper.log("[gdi] setStretchBltMode: stretchMode=" + stretchMode);
|
||||
};
|
||||
GDIContext.prototype._applyOpts = function (opts, usePen, useBrush, useFont) {
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
if (usePen) {
|
||||
var pen = this.state.selected.pen;
|
||||
if (pen.style !== Helper.GDI.PenStyle.PS_NULL) {
|
||||
opts.stroke = "#" + pen.color.toHex(); // TODO: pen style
|
||||
opts.strokeWidth = pen.width;
|
||||
opts["stroke-miterlimit"] = this.state.miterlimit;
|
||||
var dotWidth = void 0;
|
||||
opts["stroke-linecap"] = "round";
|
||||
dotWidth = 1;
|
||||
opts["stroke-linejoin"] = "round";
|
||||
var dashWidth = opts.strokeWidth * 4;
|
||||
var dotSpacing = opts.strokeWidth * 2;
|
||||
switch (pen.style) {
|
||||
case Helper.GDI.PenStyle.PS_DASH:
|
||||
opts["stroke-dasharray"] = [dashWidth, dotSpacing].toString();
|
||||
break;
|
||||
case Helper.GDI.PenStyle.PS_DOT:
|
||||
opts["stroke-dasharray"] = [dotWidth, dotSpacing].toString();
|
||||
break;
|
||||
case Helper.GDI.PenStyle.PS_DASHDOT:
|
||||
opts["stroke-dasharray"] = [dashWidth, dotSpacing, dotWidth, dotSpacing].toString();
|
||||
break;
|
||||
case Helper.GDI.PenStyle.PS_DASHDOTDOT:
|
||||
opts["stroke-dasharray"] =
|
||||
[dashWidth, dotSpacing, dotWidth, dotSpacing, dotWidth, dotSpacing].toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (useBrush) {
|
||||
var brush = this.state.selected.brush;
|
||||
switch (brush.style) {
|
||||
case Helper.GDI.BrushStyle.BS_SOLID:
|
||||
opts.fill = "#" + brush.color.toHex();
|
||||
break;
|
||||
case Helper.GDI.BrushStyle.BS_PATTERN:
|
||||
case Helper.GDI.BrushStyle.BS_DIBPATTERNPT:
|
||||
opts.fill = "url(#" + this._getSvgPatternForBrush(brush) + ")";
|
||||
break;
|
||||
case Helper.GDI.BrushStyle.BS_NULL:
|
||||
opts.fill = "none";
|
||||
break;
|
||||
default:
|
||||
Helper.log("[gdi] unsupported brush style: " + brush.style);
|
||||
opts.fill = "none";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (useFont) {
|
||||
var font = this.state.selected.font;
|
||||
opts["font-family"] = font.facename;
|
||||
opts["font-size"] = Math.abs(font.height);
|
||||
opts.fill = "#" + this.state.textcolor.toHex();
|
||||
}
|
||||
return opts;
|
||||
};
|
||||
GDIContext.prototype.rectangle = function (rect, rw, rh) {
|
||||
Helper.log("[gdi] rectangle: rect=" + rect.toString() + " with pen " + this.state.selected.pen.toString()
|
||||
+ " and brush " + this.state.selected.brush.toString());
|
||||
@@ -2767,18 +2506,17 @@ var GDIContext = /** @class */ (function () {
|
||||
+ (obj ? " invalid object type: " + obj.type : "[invalid index]"));
|
||||
}
|
||||
};
|
||||
GDIContext.prototype._abortPath = function () {
|
||||
GDIContext.prototype.abortPath = function () {
|
||||
Helper.log("[gdi] abortPath");
|
||||
if (this._svgPath != null) {
|
||||
this._svgPath = null;
|
||||
}
|
||||
};
|
||||
GDIContext.prototype.abortPath = function () {
|
||||
Helper.log("[gdi] abortPath");
|
||||
this._abortPath();
|
||||
};
|
||||
GDIContext.prototype.beginPath = function () {
|
||||
Helper.log("[gdi] beginPath");
|
||||
this._abortPath();
|
||||
if (this._svgPath != null) {
|
||||
this._svgPath = null;
|
||||
}
|
||||
this._svgPath = this._svg.createPath();
|
||||
};
|
||||
GDIContext.prototype.closeFigure = function () {
|
||||
@@ -2823,6 +2561,267 @@ var GDIContext = /** @class */ (function () {
|
||||
var ret = this._deleteObject(objIdx);
|
||||
Helper.log("[gdi] deleteObject: objIdx=" + objIdx + (ret ? " deleted object" : "[invalid index]"));
|
||||
};
|
||||
GDIContext.prototype._pushGroup = function () {
|
||||
if (this.state._svggroup == null || this.state._svgclipChanged) {
|
||||
this.state._svgclipChanged = false;
|
||||
this.state._svgtextbkfilter = null;
|
||||
var settings = {
|
||||
viewBox: [this.state.vx, this.state.vy, this.state.vw, this.state.vh].join(" "),
|
||||
preserveAspectRatio: "none",
|
||||
};
|
||||
if (this.state.clip != null) {
|
||||
Helper.log("[gdi] new svg x=" + this.state.vx + " y=" + this.state.vy + " width=" + this.state.vw
|
||||
+ " height=" + this.state.vh + " with clipping");
|
||||
settings["clip-path"] = "url(#" + this._getSvgClipPathForRegion(this.state.clip) + ")";
|
||||
}
|
||||
else {
|
||||
Helper.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, settings);
|
||||
}
|
||||
};
|
||||
GDIContext.prototype._getStockObject = function (idx) {
|
||||
if (idx >= 0x80000000 && idx <= 0x80000011) {
|
||||
return _StockObjects[(idx - 0x80000000).toString()];
|
||||
}
|
||||
else if (idx === Helper.GDI.StockObject.DC_BRUSH) {
|
||||
return this.state.selected.brush;
|
||||
}
|
||||
else if (idx === Helper.GDI.StockObject.DC_PEN) {
|
||||
return this.state.selected.pen;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
GDIContext.prototype._storeObject = function (obj, idx) {
|
||||
if (!idx) {
|
||||
idx = 0;
|
||||
while (this.objects[idx.toString()] != null && idx <= 65535) {
|
||||
idx++;
|
||||
}
|
||||
if (idx > 65535) {
|
||||
Helper.log("[gdi] Too many objects!");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
this.objects[idx.toString()] = obj;
|
||||
return idx;
|
||||
};
|
||||
GDIContext.prototype._getObject = function (objIdx) {
|
||||
var obj = this.objects[objIdx.toString()];
|
||||
if (obj == null) {
|
||||
obj = this._getStockObject(objIdx);
|
||||
if (obj == null) {
|
||||
Helper.log("[gdi] No object with handle " + objIdx);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
GDIContext.prototype._getSvgDef = function () {
|
||||
if (this._svgdefs == null) {
|
||||
this._svgdefs = this._svg.defs();
|
||||
}
|
||||
return this._svgdefs;
|
||||
};
|
||||
GDIContext.prototype._getSvgClipPathForRegion = function (region) {
|
||||
for (var existingId in this._svgClipPaths) {
|
||||
var rgn = this._svgClipPaths[existingId];
|
||||
if (rgn === region) {
|
||||
return existingId;
|
||||
}
|
||||
}
|
||||
var id = Helper._makeUniqueId("c");
|
||||
var sclip = this._svg.clipPath(this._getSvgDef(), id, "userSpaceOnUse");
|
||||
switch (region.complexity) {
|
||||
case 1:
|
||||
this._svg.rect(sclip, this._todevX(region.bounds.left), this._todevY(region.bounds.top), this._todevW(region.bounds.right - region.bounds.left), this._todevH(region.bounds.bottom - region.bounds.top), { fill: "black", strokeWidth: 0 });
|
||||
break;
|
||||
case 2:
|
||||
for (var i = 0; i < region.scans.length; i++) {
|
||||
var scan = region.scans[i];
|
||||
for (var j = 0; j < scan.scanlines.length; j++) {
|
||||
var scanline = scan.scanlines[j];
|
||||
this._svg.rect(sclip, this._todevX(scanline.left), this._todevY(scan.top), this._todevW(scanline.right - scanline.left), this._todevH(scan.bottom - scan.top), { fill: "black", strokeWidth: 0 });
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
this._svgClipPaths[id] = region;
|
||||
return id;
|
||||
};
|
||||
GDIContext.prototype._getSvgPatternForBrush = function (brush) {
|
||||
for (var existingId in this._svgPatterns) {
|
||||
var pat = this._svgPatterns[existingId];
|
||||
if (pat === brush) {
|
||||
return existingId;
|
||||
}
|
||||
}
|
||||
var width;
|
||||
var height;
|
||||
var img;
|
||||
switch (brush.style) {
|
||||
case Helper.GDI.BrushStyle.BS_PATTERN:
|
||||
width = brush.pattern.getWidth();
|
||||
height = brush.pattern.getHeight();
|
||||
break;
|
||||
case Helper.GDI.BrushStyle.BS_DIBPATTERNPT:
|
||||
width = brush.dibpatternpt.getWidth();
|
||||
height = brush.dibpatternpt.getHeight();
|
||||
img = brush.dibpatternpt.base64ref();
|
||||
break;
|
||||
default:
|
||||
throw new EMFJSError("Invalid brush style");
|
||||
}
|
||||
var id = Helper._makeUniqueId("p");
|
||||
var spat = this._svg.pattern(this._getSvgDef(), id, this.state.brx, this.state.bry, width, height, { patternUnits: "userSpaceOnUse" });
|
||||
this._svg.image(spat, 0, 0, width, height, img);
|
||||
this._svgPatterns[id] = brush;
|
||||
return id;
|
||||
};
|
||||
GDIContext.prototype._selectObject = function (obj) {
|
||||
this.state.selected[obj.type] = obj;
|
||||
switch (obj.type) {
|
||||
case "region":
|
||||
this.state._svgclipChanged = true;
|
||||
break;
|
||||
case "brush":
|
||||
this.state.brx = this.state.nextbrx;
|
||||
this.state.bry = this.state.nextbry;
|
||||
break;
|
||||
}
|
||||
};
|
||||
GDIContext.prototype._deleteObject = function (objIdx) {
|
||||
var obj = this.objects[objIdx.toString()];
|
||||
if (obj != null) {
|
||||
for (var i = 0; i < this.statestack.length; i++) {
|
||||
var state = this.statestack[i];
|
||||
if (state.selected[obj.type] === obj) {
|
||||
state.selected[obj.type] = this.defObjects[obj.type].clone();
|
||||
}
|
||||
}
|
||||
delete this.objects[objIdx.toString()];
|
||||
return true;
|
||||
}
|
||||
Helper.log("[gdi] Cannot delete object with invalid handle " + objIdx);
|
||||
return false;
|
||||
};
|
||||
GDIContext.prototype._getClipRgn = function () {
|
||||
if (this.state.clip != null) {
|
||||
if (!this.state.ownclip) {
|
||||
this.state.clip = this.state.clip.clone();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.state.selected.region != null) {
|
||||
this.state.clip = this.state.selected.region.clone();
|
||||
}
|
||||
else {
|
||||
this.state.clip = CreateSimpleRegion(this.state.wx, this.state.wy, this.state.wx + this.state.ww, this.state.wy + this.state.wh);
|
||||
}
|
||||
}
|
||||
this.state.ownclip = true;
|
||||
return this.state.clip;
|
||||
};
|
||||
GDIContext.prototype._todevX = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.wx) * (this.state.vw / this.state.ww)) + this.state.vx;
|
||||
};
|
||||
GDIContext.prototype._todevY = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.wy) * (this.state.vh / this.state.wh)) + this.state.vy;
|
||||
};
|
||||
GDIContext.prototype._todevW = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val * (this.state.vw / this.state.ww)) + this.state.vx;
|
||||
};
|
||||
GDIContext.prototype._todevH = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val * (this.state.vh / this.state.wh)) + this.state.vy;
|
||||
};
|
||||
GDIContext.prototype._tologicalX = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.vx) / (this.state.vw / this.state.ww)) + this.state.wx;
|
||||
};
|
||||
GDIContext.prototype._tologicalY = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.vy) / (this.state.vh / this.state.wh)) + this.state.wy;
|
||||
};
|
||||
GDIContext.prototype._tologicalW = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val / (this.state.vw / this.state.ww)) + this.state.wx;
|
||||
};
|
||||
GDIContext.prototype._tologicalH = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val / (this.state.vh / this.state.wh)) + this.state.wy;
|
||||
};
|
||||
GDIContext.prototype._applyOpts = function (opts, usePen, useBrush, useFont) {
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
if (usePen) {
|
||||
var pen = this.state.selected.pen;
|
||||
if (pen.style !== Helper.GDI.PenStyle.PS_NULL) {
|
||||
opts.stroke = "#" + pen.color.toHex(); // TODO: pen style
|
||||
opts.strokeWidth = pen.width;
|
||||
opts["stroke-miterlimit"] = this.state.miterlimit;
|
||||
var dotWidth = void 0;
|
||||
opts["stroke-linecap"] = "round";
|
||||
dotWidth = 1;
|
||||
opts["stroke-linejoin"] = "round";
|
||||
var dashWidth = opts.strokeWidth * 4;
|
||||
var dotSpacing = opts.strokeWidth * 2;
|
||||
switch (pen.style) {
|
||||
case Helper.GDI.PenStyle.PS_DASH:
|
||||
opts["stroke-dasharray"] = [dashWidth, dotSpacing].toString();
|
||||
break;
|
||||
case Helper.GDI.PenStyle.PS_DOT:
|
||||
opts["stroke-dasharray"] = [dotWidth, dotSpacing].toString();
|
||||
break;
|
||||
case Helper.GDI.PenStyle.PS_DASHDOT:
|
||||
opts["stroke-dasharray"] = [dashWidth, dotSpacing, dotWidth, dotSpacing].toString();
|
||||
break;
|
||||
case Helper.GDI.PenStyle.PS_DASHDOTDOT:
|
||||
opts["stroke-dasharray"] =
|
||||
[dashWidth, dotSpacing, dotWidth, dotSpacing, dotWidth, dotSpacing].toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (useBrush) {
|
||||
var brush = this.state.selected.brush;
|
||||
switch (brush.style) {
|
||||
case Helper.GDI.BrushStyle.BS_SOLID:
|
||||
opts.fill = "#" + brush.color.toHex();
|
||||
break;
|
||||
case Helper.GDI.BrushStyle.BS_PATTERN:
|
||||
case Helper.GDI.BrushStyle.BS_DIBPATTERNPT:
|
||||
opts.fill = "url(#" + this._getSvgPatternForBrush(brush) + ")";
|
||||
break;
|
||||
case Helper.GDI.BrushStyle.BS_NULL:
|
||||
opts.fill = "none";
|
||||
break;
|
||||
default:
|
||||
Helper.log("[gdi] unsupported brush style: " + brush.style);
|
||||
opts.fill = "none";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (useFont) {
|
||||
var font = this.state.selected.font;
|
||||
opts["font-family"] = font.facename;
|
||||
opts["font-size"] = Math.abs(font.height);
|
||||
opts.fill = "#" + this.state.textcolor.toHex();
|
||||
}
|
||||
return opts;
|
||||
};
|
||||
return GDIContext;
|
||||
}());
|
||||
|
||||
@@ -2852,16 +2851,25 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
var RendererSettings = /** @class */ (function () {
|
||||
function RendererSettings() {
|
||||
}
|
||||
return RendererSettings;
|
||||
}());
|
||||
var Renderer = /** @class */ (function () {
|
||||
function Renderer(blob) {
|
||||
this.parse(blob);
|
||||
Helper.log("EMFJS.Renderer instantiated");
|
||||
}
|
||||
Renderer.prototype.render = function (info) {
|
||||
var _this = this;
|
||||
var img = $("<div>").svg({
|
||||
onLoad: function (svg) {
|
||||
return _this._render(svg, info.mapMode, info.wExt, info.hExt, info.xExt, info.yExt);
|
||||
},
|
||||
settings: {
|
||||
viewBox: [0, 0, info.xExt, info.yExt].join(" "),
|
||||
preserveAspectRatio: "none",
|
||||
},
|
||||
});
|
||||
var svgContainer = $(img[0]).svg("get");
|
||||
return $(svgContainer.root()).attr("width", info.width).attr("height", info.height);
|
||||
};
|
||||
Renderer.prototype.parse = function (blob) {
|
||||
this._img = null;
|
||||
var reader = new Blob(blob);
|
||||
@@ -2887,20 +2895,6 @@ var Renderer = /** @class */ (function () {
|
||||
this._img.render(gdi);
|
||||
Helper.log("[EMF] <--- DONE RENDERING");
|
||||
};
|
||||
Renderer.prototype.render = function (info) {
|
||||
var _this = this;
|
||||
var img = $("<div>").svg({
|
||||
onLoad: function (svg) {
|
||||
return _this._render(svg, info.mapMode, info.wExt, info.hExt, info.xExt, info.yExt);
|
||||
},
|
||||
settings: {
|
||||
viewBox: [0, 0, info.xExt, info.yExt].join(" "),
|
||||
preserveAspectRatio: "none",
|
||||
},
|
||||
});
|
||||
var svgContainer = $(img[0]).svg("get");
|
||||
return $(svgContainer.root()).attr("width", info.width).attr("height", info.height);
|
||||
};
|
||||
return Renderer;
|
||||
}());
|
||||
var EMF = /** @class */ (function () {
|
||||
@@ -2944,7 +2938,6 @@ SOFTWARE.
|
||||
|
||||
exports.Error = EMFJSError;
|
||||
exports.loggingEnabled = loggingEnabled;
|
||||
exports.RendererSettings = RendererSettings;
|
||||
exports.Renderer = Renderer;
|
||||
exports.EMF = EMF;
|
||||
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+63
-63
@@ -138,14 +138,6 @@ var Helper = /** @class */ (function () {
|
||||
Helper._pxToTwips = function (px) {
|
||||
return Math.floor(px * 20 * 72 / 96);
|
||||
};
|
||||
Helper._A = "A".charCodeAt(0);
|
||||
Helper._a = "a".charCodeAt(0);
|
||||
Helper._F = "F".charCodeAt(0);
|
||||
Helper._f = "f".charCodeAt(0);
|
||||
Helper._Z = "Z".charCodeAt(0);
|
||||
Helper._z = "z".charCodeAt(0);
|
||||
Helper._0 = "0".charCodeAt(0);
|
||||
Helper._9 = "9".charCodeAt(0);
|
||||
Helper.JUSTIFICATION = {
|
||||
LEFT: "left",
|
||||
CENTER: "center",
|
||||
@@ -196,6 +188,14 @@ var Helper = /** @class */ (function () {
|
||||
HIGHANSI: "hich",
|
||||
DOUBLE: "dbch",
|
||||
};
|
||||
Helper._A = "A".charCodeAt(0);
|
||||
Helper._a = "a".charCodeAt(0);
|
||||
Helper._F = "F".charCodeAt(0);
|
||||
Helper._f = "f".charCodeAt(0);
|
||||
Helper._Z = "Z".charCodeAt(0);
|
||||
Helper._z = "z".charCodeAt(0);
|
||||
Helper._0 = "0".charCodeAt(0);
|
||||
Helper._9 = "9".charCodeAt(0);
|
||||
Helper._charsetMap = {
|
||||
0: 1252,
|
||||
77: 10000,
|
||||
@@ -7923,6 +7923,24 @@ var RtfDestination = /** @class */ (function (_super) {
|
||||
RtfDestination.prototype.sub = function () {
|
||||
Helper.log("[rtf].sub()");
|
||||
};
|
||||
RtfDestination.prototype.handleKeyword = function (keyword, param) {
|
||||
var handler = this._charFormatHandlers[keyword];
|
||||
if (handler != null) {
|
||||
handler(param);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
RtfDestination.prototype.apply = function () {
|
||||
Helper.log("[rtf] apply()");
|
||||
for (var prop in this._metadata) {
|
||||
this.inst._meta[prop] = this._metadata[prop];
|
||||
}
|
||||
delete this._metadata;
|
||||
};
|
||||
RtfDestination.prototype.setMetadata = function (prop, val) {
|
||||
this._metadata[prop] = val;
|
||||
};
|
||||
RtfDestination.prototype._addInsHandler = function (func) {
|
||||
var _this = this;
|
||||
return function (param) {
|
||||
@@ -7995,24 +8013,6 @@ var RtfDestination = /** @class */ (function (_super) {
|
||||
_this._addFormatIns(ptype, props);
|
||||
};
|
||||
};
|
||||
RtfDestination.prototype.handleKeyword = function (keyword, param) {
|
||||
var handler = this._charFormatHandlers[keyword];
|
||||
if (handler != null) {
|
||||
handler(param);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
RtfDestination.prototype.apply = function () {
|
||||
Helper.log("[rtf] apply()");
|
||||
for (var prop in this._metadata) {
|
||||
this.inst._meta[prop] = this._metadata[prop];
|
||||
}
|
||||
delete this._metadata;
|
||||
};
|
||||
RtfDestination.prototype.setMetadata = function (prop, val) {
|
||||
this._metadata[prop] = val;
|
||||
};
|
||||
return RtfDestination;
|
||||
}(DestinationBase));
|
||||
var GenericPropertyDestinationFactory = /** @class */ (function (_super) {
|
||||
@@ -8326,17 +8326,6 @@ var ColortblDestination = /** @class */ (function (_super) {
|
||||
_this.inst = inst;
|
||||
return _this;
|
||||
}
|
||||
ColortblDestination.prototype._startNewColor = function () {
|
||||
this._current = {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
tint: 255,
|
||||
shade: 255,
|
||||
theme: null,
|
||||
};
|
||||
return this._current;
|
||||
};
|
||||
ColortblDestination.prototype.appendText = function (text) {
|
||||
var len = text.length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
@@ -8359,15 +8348,6 @@ var ColortblDestination = /** @class */ (function (_super) {
|
||||
this._current = null;
|
||||
}
|
||||
};
|
||||
ColortblDestination.prototype._validateColorValueRange = function (keyword, param) {
|
||||
if (param == null) {
|
||||
throw new RTFJSError(keyword + " has no param");
|
||||
}
|
||||
if (param < 0 || param > 255) {
|
||||
throw new RTFJSError(keyword + " has invalid param value");
|
||||
}
|
||||
return param;
|
||||
};
|
||||
ColortblDestination.prototype.handleKeyword = function (keyword, param) {
|
||||
if (this._current == null) {
|
||||
this._startNewColor();
|
||||
@@ -8415,6 +8395,26 @@ var ColortblDestination = /** @class */ (function (_super) {
|
||||
this.inst._autoColor = this._autoIndex;
|
||||
delete this._colors;
|
||||
};
|
||||
ColortblDestination.prototype._startNewColor = function () {
|
||||
this._current = {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
tint: 255,
|
||||
shade: 255,
|
||||
theme: null,
|
||||
};
|
||||
return this._current;
|
||||
};
|
||||
ColortblDestination.prototype._validateColorValueRange = function (keyword, param) {
|
||||
if (param == null) {
|
||||
throw new RTFJSError(keyword + " has no param");
|
||||
}
|
||||
if (param < 0 || param > 255) {
|
||||
throw new RTFJSError(keyword + " has invalid param value");
|
||||
}
|
||||
return param;
|
||||
};
|
||||
return ColortblDestination;
|
||||
}(DestinationBase));
|
||||
var StylesheetDestinationSub = /** @class */ (function (_super) {
|
||||
@@ -8427,12 +8427,6 @@ var StylesheetDestinationSub = /** @class */ (function (_super) {
|
||||
_this.handler = _this._handleKeywordCommon("paragraph");
|
||||
return _this;
|
||||
}
|
||||
StylesheetDestinationSub.prototype._handleKeywordCommon = function (member) {
|
||||
return function (keyword, param) {
|
||||
Helper.log("[stylesheet:sub]." + member + ": unhandled keyword: " + keyword + " param: " + param);
|
||||
return false;
|
||||
};
|
||||
};
|
||||
StylesheetDestinationSub.prototype.handleKeyword = function (keyword, param) {
|
||||
switch (keyword) {
|
||||
case "s":
|
||||
@@ -8471,6 +8465,12 @@ var StylesheetDestinationSub = /** @class */ (function (_super) {
|
||||
});
|
||||
delete this._stylesheet;
|
||||
};
|
||||
StylesheetDestinationSub.prototype._handleKeywordCommon = function (member) {
|
||||
return function (keyword, param) {
|
||||
Helper.log("[stylesheet:sub]." + member + ": unhandled keyword: " + keyword + " param: " + param);
|
||||
return false;
|
||||
};
|
||||
};
|
||||
return StylesheetDestinationSub;
|
||||
}(DestinationBase));
|
||||
var StylesheetDestination = /** @class */ (function (_super) {
|
||||
@@ -8855,17 +8855,6 @@ var PictDestination = /** @class */ (function (_super) {
|
||||
_this.inst = inst;
|
||||
return _this;
|
||||
}
|
||||
PictDestination.prototype._setPropValueRequired = function (member, prop) {
|
||||
var _this = this;
|
||||
return function (param) {
|
||||
if (param == null) {
|
||||
throw new RTFJSError("Picture property has no value");
|
||||
}
|
||||
Helper.log("[pict] set " + member + "." + prop + " = " + param);
|
||||
var obj = (member != null ? _this[member] : _this);
|
||||
obj[prop] = param;
|
||||
};
|
||||
};
|
||||
PictDestination.prototype.handleKeyword = function (keyword, param) {
|
||||
var handler = this._pictHandlers[keyword];
|
||||
if (handler != null) {
|
||||
@@ -9020,6 +9009,17 @@ var PictDestination = /** @class */ (function (_super) {
|
||||
}
|
||||
delete this.text;
|
||||
};
|
||||
PictDestination.prototype._setPropValueRequired = function (member, prop) {
|
||||
var _this = this;
|
||||
return function (param) {
|
||||
if (param == null) {
|
||||
throw new RTFJSError("Picture property has no value");
|
||||
}
|
||||
Helper.log("[pict] set " + member + "." + prop + " = " + param);
|
||||
var obj = (member != null ? _this[member] : _this);
|
||||
obj[prop] = param;
|
||||
};
|
||||
};
|
||||
return PictDestination;
|
||||
}(DestinationTextBase));
|
||||
var RequiredDestinationFactory = /** @class */ (function (_super) {
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+277
-283
@@ -1103,15 +1103,6 @@ var DIBitmap = /** @class */ (function (_super) {
|
||||
DIBitmap.prototype.getHeight = function () {
|
||||
return this._info.getHeight();
|
||||
};
|
||||
DIBitmap.prototype.makeBitmapFileHeader = function () {
|
||||
var buf = new ArrayBuffer(14);
|
||||
var view = new Uint8Array(buf);
|
||||
view[0] = 0x42;
|
||||
view[1] = 0x4d;
|
||||
Helper._writeUint32Val(view, 2, this._size + 14);
|
||||
Helper._writeUint32Val(view, 10, this._info.infosize() + 14);
|
||||
return Helper._blobToBinary(view);
|
||||
};
|
||||
DIBitmap.prototype.base64ref = function () {
|
||||
var prevpos = this._reader.pos;
|
||||
this._reader.seek(this._offset);
|
||||
@@ -1144,6 +1135,15 @@ var DIBitmap = /** @class */ (function (_super) {
|
||||
this._reader.seek(prevpos);
|
||||
return ref;
|
||||
};
|
||||
DIBitmap.prototype.makeBitmapFileHeader = function () {
|
||||
var buf = new ArrayBuffer(14);
|
||||
var view = new Uint8Array(buf);
|
||||
view[0] = 0x42;
|
||||
view[1] = 0x4d;
|
||||
Helper._writeUint32Val(view, 2, this._size + 14);
|
||||
Helper._writeUint32Val(view, 10, this._info.infosize() + 14);
|
||||
return Helper._blobToBinary(view);
|
||||
};
|
||||
return DIBitmap;
|
||||
}(BitmapBase));
|
||||
var Bitmap16 = /** @class */ (function (_super) {
|
||||
@@ -1605,184 +1605,6 @@ var GDIContext = /** @class */ (function () {
|
||||
this.statestack = [this.state];
|
||||
this.objects = {};
|
||||
}
|
||||
GDIContext.prototype._pushGroup = function () {
|
||||
if (this.state._svggroup == null || this.state._svgclipChanged) {
|
||||
this.state._svgclipChanged = false;
|
||||
this.state._svgtextbkfilter = null;
|
||||
var settings = {
|
||||
viewBox: [this.state.vx, this.state.vy, this.state.vw, this.state.vh].join(" "),
|
||||
preserveAspectRatio: "none",
|
||||
};
|
||||
if (this.state.clip != null) {
|
||||
Helper.log("[gdi] new svg x=" + this.state.vx + " y=" + this.state.vy
|
||||
+ " width=" + this.state.vw + " height=" + this.state.vh + " with clipping");
|
||||
settings["clip-path"] = "url(#" + this._getSvgClipPathForRegion(this.state.clip) + ")";
|
||||
}
|
||||
else {
|
||||
Helper.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, settings);
|
||||
}
|
||||
};
|
||||
GDIContext.prototype._storeObject = function (obj) {
|
||||
var i = 0;
|
||||
while (this.objects[i.toString()] != null && i <= 65535) {
|
||||
i++;
|
||||
}
|
||||
if (i > 65535) {
|
||||
Helper.log("[gdi] Too many objects!");
|
||||
return -1;
|
||||
}
|
||||
this.objects[i.toString()] = obj;
|
||||
return i;
|
||||
};
|
||||
GDIContext.prototype._getObject = function (objIdx) {
|
||||
var obj = this.objects[objIdx.toString()];
|
||||
if (obj == null) {
|
||||
Helper.log("[gdi] No object with handle " + objIdx);
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
GDIContext.prototype._getSvgDef = function () {
|
||||
if (this._svgdefs == null) {
|
||||
this._svgdefs = this._svg.defs();
|
||||
}
|
||||
return this._svgdefs;
|
||||
};
|
||||
GDIContext.prototype._getSvgClipPathForRegion = function (region) {
|
||||
for (var existingId in this._svgClipPaths) {
|
||||
var rgn = this._svgClipPaths[existingId];
|
||||
if (rgn === region) {
|
||||
return existingId;
|
||||
}
|
||||
}
|
||||
var id = Helper._makeUniqueId("c");
|
||||
var sclip = this._svg.clipPath(this._getSvgDef(), id, "userSpaceOnUse");
|
||||
switch (region.complexity) {
|
||||
case 1:
|
||||
this._svg.rect(sclip, this._todevX(region.bounds.left), this._todevY(region.bounds.top), this._todevW(region.bounds.right - region.bounds.left), this._todevH(region.bounds.bottom - region.bounds.top), { fill: "black", strokeWidth: 0 });
|
||||
break;
|
||||
case 2:
|
||||
for (var i = 0; i < region.scans.length; i++) {
|
||||
var scan = region.scans[i];
|
||||
for (var j = 0; j < scan.scanlines.length; j++) {
|
||||
var scanline = scan.scanlines[j];
|
||||
this._svg.rect(sclip, this._todevX(scanline.left), this._todevY(scan.top), this._todevW(scanline.right - scanline.left), this._todevH(scan.bottom - scan.top), { fill: "black", strokeWidth: 0 });
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
this._svgClipPaths[id] = region;
|
||||
return id;
|
||||
};
|
||||
GDIContext.prototype._getSvgPatternForBrush = function (brush) {
|
||||
for (var existingId in this._svgPatterns) {
|
||||
var pat = this._svgPatterns[existingId];
|
||||
if (pat === brush) {
|
||||
return existingId;
|
||||
}
|
||||
}
|
||||
var width;
|
||||
var height;
|
||||
var img;
|
||||
switch (brush.style) {
|
||||
case Helper.GDI.BrushStyle.BS_PATTERN:
|
||||
width = brush.pattern.getWidth();
|
||||
height = brush.pattern.getHeight();
|
||||
break;
|
||||
case Helper.GDI.BrushStyle.BS_DIBPATTERNPT:
|
||||
width = brush.dibpatternpt.getWidth();
|
||||
height = brush.dibpatternpt.getHeight();
|
||||
img = brush.dibpatternpt.base64ref();
|
||||
break;
|
||||
default:
|
||||
throw new WMFJSError("Invalid brush style");
|
||||
}
|
||||
var id = Helper._makeUniqueId("p");
|
||||
var spat = this._svg.pattern(this._getSvgDef(), id, 0, 0, width, height, { patternUnits: "userSpaceOnUse" });
|
||||
this._svg.image(spat, 0, 0, width, height, img);
|
||||
this._svgPatterns[id] = brush;
|
||||
return id;
|
||||
};
|
||||
GDIContext.prototype._selectObject = function (obj) {
|
||||
this.state.selected[obj.type] = obj;
|
||||
if (obj.type === "region") {
|
||||
this.state._svgclipChanged = true;
|
||||
}
|
||||
};
|
||||
GDIContext.prototype._deleteObject = function (objIdx) {
|
||||
var obj = this.objects[objIdx.toString()];
|
||||
if (obj != null) {
|
||||
for (var i = 0; i < this.statestack.length; i++) {
|
||||
var state = this.statestack[i];
|
||||
if (state.selected[obj.type] === obj) {
|
||||
state.selected[obj.type] = this.defObjects[obj.type].clone();
|
||||
}
|
||||
}
|
||||
delete this.objects[objIdx.toString()];
|
||||
return true;
|
||||
}
|
||||
Helper.log("[gdi] Cannot delete object with invalid handle " + objIdx);
|
||||
return false;
|
||||
};
|
||||
GDIContext.prototype._getClipRgn = function () {
|
||||
if (this.state.clip != null) {
|
||||
if (!this.state.ownclip) {
|
||||
this.state.clip = this.state.clip.clone();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.state.selected.region != null) {
|
||||
this.state.clip = this.state.selected.region.clone();
|
||||
}
|
||||
else {
|
||||
this.state.clip = CreateSimpleRegion(this.state.wx, this.state.wy, this.state.wx + this.state.ww, this.state.wy + this.state.wh);
|
||||
}
|
||||
}
|
||||
this.state.ownclip = true;
|
||||
return this.state.clip;
|
||||
};
|
||||
GDIContext.prototype._todevX = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.wx) * (this.state.vw / this.state.ww)) + this.state.vx;
|
||||
};
|
||||
GDIContext.prototype._todevY = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.wy) * (this.state.vh / this.state.wh)) + this.state.vy;
|
||||
};
|
||||
GDIContext.prototype._todevW = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val * (this.state.vw / this.state.ww)) + this.state.vx;
|
||||
};
|
||||
GDIContext.prototype._todevH = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val * (this.state.vh / this.state.wh)) + this.state.vy;
|
||||
};
|
||||
GDIContext.prototype._tologicalX = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.vx) / (this.state.vw / this.state.ww)) + this.state.wx;
|
||||
};
|
||||
GDIContext.prototype._tologicalY = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.vy) / (this.state.vh / this.state.wh)) + this.state.wy;
|
||||
};
|
||||
GDIContext.prototype._tologicalW = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val / (this.state.vw / this.state.ww)) + this.state.wx;
|
||||
};
|
||||
GDIContext.prototype._tologicalH = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val / (this.state.vh / this.state.wh)) + this.state.wy;
|
||||
};
|
||||
GDIContext.prototype.setMapMode = function (mode) {
|
||||
Helper.log("[gdi] setMapMode: mode=" + mode);
|
||||
this.state.mapmode = mode;
|
||||
@@ -1892,82 +1714,6 @@ var GDIContext = /** @class */ (function () {
|
||||
this._pushGroup();
|
||||
this._svg.image(this.state._svggroup, dstX, dstY, dstW, dstH, dib.base64ref());
|
||||
};
|
||||
GDIContext.prototype._applyOpts = function (opts, usePen, useBrush, useFont) {
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
if (usePen) {
|
||||
var pen = this.state.selected.pen;
|
||||
if (pen.style !== Helper.GDI.PenStyle.PS_NULL) {
|
||||
opts.stroke = "#" + pen.color.toHex(), opts.strokeWidth = this._todevW(pen.width.x); // TODO: is .y ever used?
|
||||
var dotWidth = void 0;
|
||||
if ((pen.linecap & Helper.GDI.PenStyle.PS_ENDCAP_SQUARE) !== 0) {
|
||||
opts["stroke-linecap"] = "square";
|
||||
dotWidth = 1;
|
||||
}
|
||||
else if ((pen.linecap & Helper.GDI.PenStyle.PS_ENDCAP_FLAT) !== 0) {
|
||||
opts["stroke-linecap"] = "butt";
|
||||
dotWidth = opts.strokeWidth;
|
||||
}
|
||||
else {
|
||||
opts["stroke-linecap"] = "round";
|
||||
dotWidth = 1;
|
||||
}
|
||||
if ((pen.join & Helper.GDI.PenStyle.PS_JOIN_BEVEL) !== 0) {
|
||||
opts["stroke-linejoin"] = "bevel";
|
||||
}
|
||||
else if ((pen.join & Helper.GDI.PenStyle.PS_JOIN_MITER) !== 0) {
|
||||
opts["stroke-linejoin"] = "miter";
|
||||
}
|
||||
else {
|
||||
opts["stroke-linejoin"] = "round";
|
||||
}
|
||||
var dashWidth = opts.strokeWidth * 4;
|
||||
var dotSpacing = opts.strokeWidth * 2;
|
||||
switch (pen.style) {
|
||||
case Helper.GDI.PenStyle.PS_DASH:
|
||||
opts["stroke-dasharray"] = [dashWidth, dotSpacing].toString();
|
||||
break;
|
||||
case Helper.GDI.PenStyle.PS_DOT:
|
||||
opts["stroke-dasharray"] = [dotWidth, dotSpacing].toString();
|
||||
break;
|
||||
case Helper.GDI.PenStyle.PS_DASHDOT:
|
||||
opts["stroke-dasharray"] = [dashWidth, dotSpacing, dotWidth, dotSpacing].toString();
|
||||
break;
|
||||
case Helper.GDI.PenStyle.PS_DASHDOTDOT:
|
||||
opts["stroke-dasharray"]
|
||||
= [dashWidth, dotSpacing, dotWidth, dotSpacing, dotWidth, dotSpacing].toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (useBrush) {
|
||||
var brush = this.state.selected.brush;
|
||||
switch (brush.style) {
|
||||
case Helper.GDI.BrushStyle.BS_SOLID:
|
||||
opts.fill = "#" + brush.color.toHex();
|
||||
break;
|
||||
case Helper.GDI.BrushStyle.BS_PATTERN:
|
||||
case Helper.GDI.BrushStyle.BS_DIBPATTERNPT:
|
||||
opts.fill = "url(#" + this._getSvgPatternForBrush(brush) + ")";
|
||||
break;
|
||||
case Helper.GDI.BrushStyle.BS_NULL:
|
||||
opts.fill = "none";
|
||||
break;
|
||||
default:
|
||||
Helper.log("[gdi] unsupported brush style: " + brush.style);
|
||||
opts.fill = "none";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (useFont) {
|
||||
var font = this.state.selected.font;
|
||||
opts["font-family"] = font.facename;
|
||||
opts["font-size"] = this._todevH(Math.abs(font.height));
|
||||
opts.fill = "#" + this.state.textcolor.toHex();
|
||||
}
|
||||
return opts;
|
||||
};
|
||||
GDIContext.prototype.rectangle = function (rect, rw, rh) {
|
||||
Helper.log("[gdi] rectangle: rect=" + rect.toString() + " with pen " + this.state.selected.pen.toString()
|
||||
+ " and brush " + this.state.selected.brush.toString());
|
||||
@@ -2176,6 +1922,260 @@ var GDIContext = /** @class */ (function () {
|
||||
var ret = this._deleteObject(objIdx);
|
||||
Helper.log("[gdi] deleteObject: objIdx=" + objIdx + (ret ? " deleted object" : "[invalid index]"));
|
||||
};
|
||||
GDIContext.prototype._pushGroup = function () {
|
||||
if (this.state._svggroup == null || this.state._svgclipChanged) {
|
||||
this.state._svgclipChanged = false;
|
||||
this.state._svgtextbkfilter = null;
|
||||
var settings = {
|
||||
viewBox: [this.state.vx, this.state.vy, this.state.vw, this.state.vh].join(" "),
|
||||
preserveAspectRatio: "none",
|
||||
};
|
||||
if (this.state.clip != null) {
|
||||
Helper.log("[gdi] new svg x=" + this.state.vx + " y=" + this.state.vy
|
||||
+ " width=" + this.state.vw + " height=" + this.state.vh + " with clipping");
|
||||
settings["clip-path"] = "url(#" + this._getSvgClipPathForRegion(this.state.clip) + ")";
|
||||
}
|
||||
else {
|
||||
Helper.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, settings);
|
||||
}
|
||||
};
|
||||
GDIContext.prototype._storeObject = function (obj) {
|
||||
var i = 0;
|
||||
while (this.objects[i.toString()] != null && i <= 65535) {
|
||||
i++;
|
||||
}
|
||||
if (i > 65535) {
|
||||
Helper.log("[gdi] Too many objects!");
|
||||
return -1;
|
||||
}
|
||||
this.objects[i.toString()] = obj;
|
||||
return i;
|
||||
};
|
||||
GDIContext.prototype._getObject = function (objIdx) {
|
||||
var obj = this.objects[objIdx.toString()];
|
||||
if (obj == null) {
|
||||
Helper.log("[gdi] No object with handle " + objIdx);
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
GDIContext.prototype._getSvgDef = function () {
|
||||
if (this._svgdefs == null) {
|
||||
this._svgdefs = this._svg.defs();
|
||||
}
|
||||
return this._svgdefs;
|
||||
};
|
||||
GDIContext.prototype._getSvgClipPathForRegion = function (region) {
|
||||
for (var existingId in this._svgClipPaths) {
|
||||
var rgn = this._svgClipPaths[existingId];
|
||||
if (rgn === region) {
|
||||
return existingId;
|
||||
}
|
||||
}
|
||||
var id = Helper._makeUniqueId("c");
|
||||
var sclip = this._svg.clipPath(this._getSvgDef(), id, "userSpaceOnUse");
|
||||
switch (region.complexity) {
|
||||
case 1:
|
||||
this._svg.rect(sclip, this._todevX(region.bounds.left), this._todevY(region.bounds.top), this._todevW(region.bounds.right - region.bounds.left), this._todevH(region.bounds.bottom - region.bounds.top), { fill: "black", strokeWidth: 0 });
|
||||
break;
|
||||
case 2:
|
||||
for (var i = 0; i < region.scans.length; i++) {
|
||||
var scan = region.scans[i];
|
||||
for (var j = 0; j < scan.scanlines.length; j++) {
|
||||
var scanline = scan.scanlines[j];
|
||||
this._svg.rect(sclip, this._todevX(scanline.left), this._todevY(scan.top), this._todevW(scanline.right - scanline.left), this._todevH(scan.bottom - scan.top), { fill: "black", strokeWidth: 0 });
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
this._svgClipPaths[id] = region;
|
||||
return id;
|
||||
};
|
||||
GDIContext.prototype._getSvgPatternForBrush = function (brush) {
|
||||
for (var existingId in this._svgPatterns) {
|
||||
var pat = this._svgPatterns[existingId];
|
||||
if (pat === brush) {
|
||||
return existingId;
|
||||
}
|
||||
}
|
||||
var width;
|
||||
var height;
|
||||
var img;
|
||||
switch (brush.style) {
|
||||
case Helper.GDI.BrushStyle.BS_PATTERN:
|
||||
width = brush.pattern.getWidth();
|
||||
height = brush.pattern.getHeight();
|
||||
break;
|
||||
case Helper.GDI.BrushStyle.BS_DIBPATTERNPT:
|
||||
width = brush.dibpatternpt.getWidth();
|
||||
height = brush.dibpatternpt.getHeight();
|
||||
img = brush.dibpatternpt.base64ref();
|
||||
break;
|
||||
default:
|
||||
throw new WMFJSError("Invalid brush style");
|
||||
}
|
||||
var id = Helper._makeUniqueId("p");
|
||||
var spat = this._svg.pattern(this._getSvgDef(), id, 0, 0, width, height, { patternUnits: "userSpaceOnUse" });
|
||||
this._svg.image(spat, 0, 0, width, height, img);
|
||||
this._svgPatterns[id] = brush;
|
||||
return id;
|
||||
};
|
||||
GDIContext.prototype._selectObject = function (obj) {
|
||||
this.state.selected[obj.type] = obj;
|
||||
if (obj.type === "region") {
|
||||
this.state._svgclipChanged = true;
|
||||
}
|
||||
};
|
||||
GDIContext.prototype._deleteObject = function (objIdx) {
|
||||
var obj = this.objects[objIdx.toString()];
|
||||
if (obj != null) {
|
||||
for (var i = 0; i < this.statestack.length; i++) {
|
||||
var state = this.statestack[i];
|
||||
if (state.selected[obj.type] === obj) {
|
||||
state.selected[obj.type] = this.defObjects[obj.type].clone();
|
||||
}
|
||||
}
|
||||
delete this.objects[objIdx.toString()];
|
||||
return true;
|
||||
}
|
||||
Helper.log("[gdi] Cannot delete object with invalid handle " + objIdx);
|
||||
return false;
|
||||
};
|
||||
GDIContext.prototype._getClipRgn = function () {
|
||||
if (this.state.clip != null) {
|
||||
if (!this.state.ownclip) {
|
||||
this.state.clip = this.state.clip.clone();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.state.selected.region != null) {
|
||||
this.state.clip = this.state.selected.region.clone();
|
||||
}
|
||||
else {
|
||||
this.state.clip = CreateSimpleRegion(this.state.wx, this.state.wy, this.state.wx + this.state.ww, this.state.wy + this.state.wh);
|
||||
}
|
||||
}
|
||||
this.state.ownclip = true;
|
||||
return this.state.clip;
|
||||
};
|
||||
GDIContext.prototype._todevX = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.wx) * (this.state.vw / this.state.ww)) + this.state.vx;
|
||||
};
|
||||
GDIContext.prototype._todevY = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.wy) * (this.state.vh / this.state.wh)) + this.state.vy;
|
||||
};
|
||||
GDIContext.prototype._todevW = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val * (this.state.vw / this.state.ww)) + this.state.vx;
|
||||
};
|
||||
GDIContext.prototype._todevH = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val * (this.state.vh / this.state.wh)) + this.state.vy;
|
||||
};
|
||||
GDIContext.prototype._tologicalX = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.vx) / (this.state.vw / this.state.ww)) + this.state.wx;
|
||||
};
|
||||
GDIContext.prototype._tologicalY = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.vy) / (this.state.vh / this.state.wh)) + this.state.wy;
|
||||
};
|
||||
GDIContext.prototype._tologicalW = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val / (this.state.vw / this.state.ww)) + this.state.wx;
|
||||
};
|
||||
GDIContext.prototype._tologicalH = function (val) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val / (this.state.vh / this.state.wh)) + this.state.wy;
|
||||
};
|
||||
GDIContext.prototype._applyOpts = function (opts, usePen, useBrush, useFont) {
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
if (usePen) {
|
||||
var pen = this.state.selected.pen;
|
||||
if (pen.style !== Helper.GDI.PenStyle.PS_NULL) {
|
||||
opts.stroke = "#" + pen.color.toHex(), opts.strokeWidth = this._todevW(pen.width.x); // TODO: is .y ever used?
|
||||
var dotWidth = void 0;
|
||||
if ((pen.linecap & Helper.GDI.PenStyle.PS_ENDCAP_SQUARE) !== 0) {
|
||||
opts["stroke-linecap"] = "square";
|
||||
dotWidth = 1;
|
||||
}
|
||||
else if ((pen.linecap & Helper.GDI.PenStyle.PS_ENDCAP_FLAT) !== 0) {
|
||||
opts["stroke-linecap"] = "butt";
|
||||
dotWidth = opts.strokeWidth;
|
||||
}
|
||||
else {
|
||||
opts["stroke-linecap"] = "round";
|
||||
dotWidth = 1;
|
||||
}
|
||||
if ((pen.join & Helper.GDI.PenStyle.PS_JOIN_BEVEL) !== 0) {
|
||||
opts["stroke-linejoin"] = "bevel";
|
||||
}
|
||||
else if ((pen.join & Helper.GDI.PenStyle.PS_JOIN_MITER) !== 0) {
|
||||
opts["stroke-linejoin"] = "miter";
|
||||
}
|
||||
else {
|
||||
opts["stroke-linejoin"] = "round";
|
||||
}
|
||||
var dashWidth = opts.strokeWidth * 4;
|
||||
var dotSpacing = opts.strokeWidth * 2;
|
||||
switch (pen.style) {
|
||||
case Helper.GDI.PenStyle.PS_DASH:
|
||||
opts["stroke-dasharray"] = [dashWidth, dotSpacing].toString();
|
||||
break;
|
||||
case Helper.GDI.PenStyle.PS_DOT:
|
||||
opts["stroke-dasharray"] = [dotWidth, dotSpacing].toString();
|
||||
break;
|
||||
case Helper.GDI.PenStyle.PS_DASHDOT:
|
||||
opts["stroke-dasharray"] = [dashWidth, dotSpacing, dotWidth, dotSpacing].toString();
|
||||
break;
|
||||
case Helper.GDI.PenStyle.PS_DASHDOTDOT:
|
||||
opts["stroke-dasharray"]
|
||||
= [dashWidth, dotSpacing, dotWidth, dotSpacing, dotWidth, dotSpacing].toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (useBrush) {
|
||||
var brush = this.state.selected.brush;
|
||||
switch (brush.style) {
|
||||
case Helper.GDI.BrushStyle.BS_SOLID:
|
||||
opts.fill = "#" + brush.color.toHex();
|
||||
break;
|
||||
case Helper.GDI.BrushStyle.BS_PATTERN:
|
||||
case Helper.GDI.BrushStyle.BS_DIBPATTERNPT:
|
||||
opts.fill = "url(#" + this._getSvgPatternForBrush(brush) + ")";
|
||||
break;
|
||||
case Helper.GDI.BrushStyle.BS_NULL:
|
||||
opts.fill = "none";
|
||||
break;
|
||||
default:
|
||||
Helper.log("[gdi] unsupported brush style: " + brush.style);
|
||||
opts.fill = "none";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (useFont) {
|
||||
var font = this.state.selected.font;
|
||||
opts["font-family"] = font.facename;
|
||||
opts["font-size"] = this._todevH(Math.abs(font.height));
|
||||
opts.fill = "#" + this.state.textcolor.toHex();
|
||||
}
|
||||
return opts;
|
||||
};
|
||||
return GDIContext;
|
||||
}());
|
||||
|
||||
@@ -2702,16 +2702,25 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
var RendererSettings = /** @class */ (function () {
|
||||
function RendererSettings() {
|
||||
}
|
||||
return RendererSettings;
|
||||
}());
|
||||
var Renderer = /** @class */ (function () {
|
||||
function Renderer(blob) {
|
||||
this.parse(blob);
|
||||
Helper.log("WMFJS.Renderer instantiated");
|
||||
}
|
||||
Renderer.prototype.render = function (info) {
|
||||
var _this = this;
|
||||
var img = $("<div>").svg({
|
||||
onLoad: function (svg) {
|
||||
return _this._render(svg, info.mapMode, info.xExt, info.yExt);
|
||||
},
|
||||
settings: {
|
||||
viewBox: [0, 0, info.xExt, info.yExt].join(" "),
|
||||
preserveAspectRatio: "none",
|
||||
},
|
||||
});
|
||||
var svgContainer = $(img[0]).svg("get");
|
||||
return $(svgContainer.root()).attr("width", info.width).attr("height", info.height);
|
||||
};
|
||||
Renderer.prototype.parse = function (blob) {
|
||||
this._img = null;
|
||||
var reader = new Blob(blob);
|
||||
@@ -2758,20 +2767,6 @@ var Renderer = /** @class */ (function () {
|
||||
this._img.render(gdi);
|
||||
Helper.log("[WMF] <--- DONE RENDERING");
|
||||
};
|
||||
Renderer.prototype.render = function (info) {
|
||||
var _this = this;
|
||||
var img = $("<div>").svg({
|
||||
onLoad: function (svg) {
|
||||
return _this._render(svg, info.mapMode, info.xExt, info.yExt);
|
||||
},
|
||||
settings: {
|
||||
viewBox: [0, 0, info.xExt, info.yExt].join(" "),
|
||||
preserveAspectRatio: "none",
|
||||
},
|
||||
});
|
||||
var svgContainer = $(img[0]).svg("get");
|
||||
return $(svgContainer.root()).attr("width", info.width).attr("height", info.height);
|
||||
};
|
||||
return Renderer;
|
||||
}());
|
||||
var WMFRect16 = /** @class */ (function () {
|
||||
@@ -2840,7 +2835,6 @@ SOFTWARE.
|
||||
|
||||
exports.Error = WMFJSError;
|
||||
exports.loggingEnabled = loggingEnabled;
|
||||
exports.RendererSettings = RendererSettings;
|
||||
exports.Renderer = Renderer;
|
||||
exports.WMFRect16 = WMFRect16;
|
||||
exports.WMFPlacable = WMFPlacable;
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+36
-36
@@ -29,19 +29,19 @@ import { Blob } from "./Blob";
|
||||
import { EMFJSError, Helper } from "./Helper";
|
||||
|
||||
export class BitmapBase {
|
||||
getWidth() {
|
||||
public getWidth() {
|
||||
throw new EMFJSError("getWidth not implemented");
|
||||
}
|
||||
|
||||
getHeight() {
|
||||
public getHeight() {
|
||||
throw new EMFJSError("getHeight not implemented");
|
||||
}
|
||||
}
|
||||
export class BitmapCoreHeader {
|
||||
width: number;
|
||||
height: number;
|
||||
planes: number;
|
||||
bitcount: number;
|
||||
public width: number;
|
||||
public height: number;
|
||||
public planes: number;
|
||||
public bitcount: number;
|
||||
|
||||
constructor(reader: Blob, skipsize: boolean) {
|
||||
if (skipsize) {
|
||||
@@ -53,22 +53,22 @@ export class BitmapCoreHeader {
|
||||
this.bitcount = reader.readUint16();
|
||||
}
|
||||
|
||||
colors() {
|
||||
public colors() {
|
||||
return this.bitcount <= 8 ? 1 << this.bitcount : 0;
|
||||
}
|
||||
}
|
||||
|
||||
export class BitmapInfoHeader {
|
||||
width: number;
|
||||
height: number;
|
||||
planes: number;
|
||||
bitcount: number;
|
||||
compression: number;
|
||||
sizeimage: number;
|
||||
xpelspermeter: number;
|
||||
ypelspermeter: number;
|
||||
clrused: number;
|
||||
clrimportant: number;
|
||||
public width: number;
|
||||
public height: number;
|
||||
public planes: number;
|
||||
public bitcount: number;
|
||||
public compression: number;
|
||||
public sizeimage: number;
|
||||
public xpelspermeter: number;
|
||||
public ypelspermeter: number;
|
||||
public clrused: number;
|
||||
public clrimportant: number;
|
||||
|
||||
constructor(reader: Blob, skipsize: boolean) {
|
||||
if (skipsize) {
|
||||
@@ -86,7 +86,7 @@ export class BitmapInfoHeader {
|
||||
this.clrimportant = reader.readUint32();
|
||||
}
|
||||
|
||||
colors() {
|
||||
public colors() {
|
||||
if (this.clrused !== 0) {
|
||||
return this.clrused < 256 ? this.clrused : 256;
|
||||
} else {
|
||||
@@ -96,11 +96,11 @@ export class BitmapInfoHeader {
|
||||
}
|
||||
|
||||
export class BitmapInfo extends BitmapBase {
|
||||
_reader: Blob;
|
||||
_offset: number;
|
||||
_usergb: boolean;
|
||||
_infosize: number;
|
||||
_header: BitmapCoreHeader | BitmapInfoHeader;
|
||||
private _reader: Blob;
|
||||
private _offset: number;
|
||||
private _usergb: boolean;
|
||||
private _infosize: number;
|
||||
private _header: BitmapCoreHeader | BitmapInfoHeader;
|
||||
|
||||
constructor(reader: Blob, usergb: boolean) {
|
||||
super();
|
||||
@@ -123,28 +123,28 @@ export class BitmapInfo extends BitmapBase {
|
||||
}
|
||||
}
|
||||
|
||||
getWidth() {
|
||||
public getWidth() {
|
||||
return this._header.width;
|
||||
}
|
||||
|
||||
getHeight() {
|
||||
public getHeight() {
|
||||
return Math.abs(this._header.height);
|
||||
}
|
||||
|
||||
infosize() {
|
||||
public infosize() {
|
||||
return this._infosize;
|
||||
}
|
||||
|
||||
header() {
|
||||
public header() {
|
||||
return this._header;
|
||||
}
|
||||
}
|
||||
|
||||
export class DIBitmap extends BitmapBase {
|
||||
_reader: Blob;
|
||||
_offset: number;
|
||||
_location: any;
|
||||
_info: BitmapInfo;
|
||||
private _reader: Blob;
|
||||
private _offset: number;
|
||||
private _location: any;
|
||||
private _info: BitmapInfo;
|
||||
|
||||
constructor(reader: Blob, bitmapInfo?: any) {
|
||||
super();
|
||||
@@ -154,19 +154,19 @@ export class DIBitmap extends BitmapBase {
|
||||
this._info = new BitmapInfo(reader, true);
|
||||
}
|
||||
|
||||
getWidth() {
|
||||
public getWidth() {
|
||||
return this._info.getWidth();
|
||||
}
|
||||
|
||||
getHeight() {
|
||||
public getHeight() {
|
||||
return this._info.getHeight();
|
||||
}
|
||||
|
||||
totalSize() {
|
||||
public totalSize() {
|
||||
return this._location.header.size + this._location.data.size;
|
||||
}
|
||||
|
||||
makeBitmapFileHeader() {
|
||||
public makeBitmapFileHeader() {
|
||||
const buf = new ArrayBuffer(14);
|
||||
const view = new Uint8Array(buf);
|
||||
view[0] = 0x42;
|
||||
@@ -176,7 +176,7 @@ export class DIBitmap extends BitmapBase {
|
||||
return Helper._blobToBinary(view);
|
||||
}
|
||||
|
||||
base64ref() {
|
||||
public base64ref() {
|
||||
const prevpos = this._reader.pos;
|
||||
this._reader.seek(this._offset);
|
||||
let mime = "image/bmp";
|
||||
|
||||
+16
-16
@@ -28,9 +28,9 @@ SOFTWARE.
|
||||
import { EMFJSError } from "./Helper";
|
||||
|
||||
export class Blob {
|
||||
blob: Blob | ArrayBuffer;
|
||||
data: Uint8Array;
|
||||
pos: number;
|
||||
public pos: number;
|
||||
private blob: Blob | ArrayBuffer;
|
||||
private data: Uint8Array;
|
||||
|
||||
constructor(blob: Blob | ArrayBuffer, offset?: number) {
|
||||
if (blob instanceof Blob) {
|
||||
@@ -44,18 +44,18 @@ export class Blob {
|
||||
}
|
||||
}
|
||||
|
||||
eof() {
|
||||
public eof() {
|
||||
return this.pos >= this.data.length;
|
||||
}
|
||||
|
||||
seek(newpos: number) {
|
||||
public seek(newpos: number) {
|
||||
if (newpos < 0 || newpos > this.data.length) {
|
||||
throw new EMFJSError("Invalid seek position");
|
||||
}
|
||||
this.pos = newpos;
|
||||
}
|
||||
|
||||
skip(cnt: number) {
|
||||
public skip(cnt: number) {
|
||||
const newPos = this.pos + cnt;
|
||||
if (newPos > this.data.length) {
|
||||
throw new EMFJSError("Unexpected end of file");
|
||||
@@ -63,7 +63,7 @@ export class Blob {
|
||||
this.pos = newPos;
|
||||
}
|
||||
|
||||
readBinary(cnt: number) {
|
||||
public readBinary(cnt: number) {
|
||||
const end = this.pos + cnt;
|
||||
if (end > this.data.length) {
|
||||
throw new EMFJSError("Unexpected end of file");
|
||||
@@ -75,18 +75,18 @@ export class Blob {
|
||||
return ret;
|
||||
}
|
||||
|
||||
readInt8() {
|
||||
public readInt8() {
|
||||
if (this.pos + 1 > this.data.length) {
|
||||
throw new EMFJSError("Unexpected end of file");
|
||||
}
|
||||
return this.data[this.pos++];
|
||||
}
|
||||
|
||||
readUint8() {
|
||||
public readUint8() {
|
||||
return this.readInt8() >>> 0;
|
||||
}
|
||||
|
||||
readInt32() {
|
||||
public readInt32() {
|
||||
if (this.pos + 4 > this.data.length) {
|
||||
throw new EMFJSError("Unexpected end of file");
|
||||
}
|
||||
@@ -97,11 +97,11 @@ export class Blob {
|
||||
return val;
|
||||
}
|
||||
|
||||
readUint32() {
|
||||
public readUint32() {
|
||||
return this.readInt32() >>> 0;
|
||||
}
|
||||
|
||||
readUint16() {
|
||||
public readUint16() {
|
||||
if (this.pos + 2 > this.data.length) {
|
||||
throw new EMFJSError("Unexpected end of file");
|
||||
}
|
||||
@@ -110,7 +110,7 @@ export class Blob {
|
||||
return val;
|
||||
}
|
||||
|
||||
readInt16() {
|
||||
public readInt16() {
|
||||
let val = this.readUint16();
|
||||
if (val > 32767) {
|
||||
val -= 65536;
|
||||
@@ -118,7 +118,7 @@ export class Blob {
|
||||
return val;
|
||||
}
|
||||
|
||||
readString(length: number) {
|
||||
public readString(length: number) {
|
||||
if (this.pos + length > this.data.length) {
|
||||
throw new EMFJSError("Unexpected end of file");
|
||||
}
|
||||
@@ -129,7 +129,7 @@ export class Blob {
|
||||
return ret;
|
||||
}
|
||||
|
||||
readNullTermString(maxSize: number) {
|
||||
public readNullTermString(maxSize: number) {
|
||||
let ret = "";
|
||||
if (maxSize > 0) {
|
||||
maxSize--;
|
||||
@@ -147,7 +147,7 @@ export class Blob {
|
||||
return ret;
|
||||
}
|
||||
|
||||
readFixedSizeUnicodeString(fixedSizeChars: number) {
|
||||
public readFixedSizeUnicodeString(fixedSizeChars: number) {
|
||||
let ret = "";
|
||||
for (let i = 0; i < fixedSizeChars; i++) {
|
||||
const charCode = this.readUint16();
|
||||
|
||||
+15
-15
@@ -33,17 +33,17 @@ import { Region } from "./Region";
|
||||
import { Brush, ColorRef, Pen } from "./Style";
|
||||
|
||||
export class EmfHeader {
|
||||
size: number;
|
||||
bounds: RectL;
|
||||
frame: RectL;
|
||||
nPalEntries: number;
|
||||
refDevCx: number;
|
||||
refDevCy: number;
|
||||
refDevCxMm: number;
|
||||
refDevCyMm: number;
|
||||
description: string;
|
||||
displayDevCxUm: number;
|
||||
displayDevCyUm: number;
|
||||
private size: number;
|
||||
private bounds: RectL;
|
||||
private frame: RectL;
|
||||
private nPalEntries: number;
|
||||
private refDevCx: number;
|
||||
private refDevCy: number;
|
||||
private refDevCxMm: number;
|
||||
private refDevCyMm: number;
|
||||
private description: string;
|
||||
private displayDevCxUm: number;
|
||||
private displayDevCyUm: number;
|
||||
|
||||
constructor(reader: Blob, headerSize: number) {
|
||||
const recordStart = reader.pos - 8;
|
||||
@@ -116,15 +116,15 @@ export class EmfHeader {
|
||||
}
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{bounds: " + this.bounds.toString() + ", frame: " + this.frame.toString()
|
||||
+ ", description: " + this.description + "}";
|
||||
}
|
||||
}
|
||||
|
||||
export class EMFRecords {
|
||||
_records: Array<(gdi: GDIContext) => void>;
|
||||
_header: EmfHeader;
|
||||
private _records: Array<(gdi: GDIContext) => void>;
|
||||
private _header: EmfHeader;
|
||||
|
||||
constructor(reader: Blob, first: number) {
|
||||
this._records = [];
|
||||
@@ -584,7 +584,7 @@ export class EMFRecords {
|
||||
}
|
||||
}
|
||||
|
||||
play(gdi: GDIContext) {
|
||||
public play(gdi: GDIContext) {
|
||||
const len = this._records.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
this._records[i](gdi);
|
||||
|
||||
+428
-430
@@ -40,7 +40,7 @@ export interface ISelectedStyle {
|
||||
}
|
||||
|
||||
export class Path extends Obj {
|
||||
svgPath: any;
|
||||
public svgPath: any;
|
||||
|
||||
constructor(svgPath: any, copy?: Path) {
|
||||
super("path");
|
||||
@@ -51,11 +51,11 @@ export class Path extends Obj {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new Path(null, this.svgPath);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{[path]}";
|
||||
}
|
||||
}
|
||||
@@ -105,34 +105,34 @@ function createStockObjects(): {[key: string]: Obj} {
|
||||
export const _StockObjects = createStockObjects();
|
||||
|
||||
export class GDIContextState {
|
||||
_svggroup: any;
|
||||
_svgclipChanged: boolean;
|
||||
_svgtextbkfilter: any;
|
||||
mapmode: number;
|
||||
stretchmode: number;
|
||||
textalign: number;
|
||||
bkmode: number;
|
||||
textcolor: ColorRef;
|
||||
bkcolor: ColorRef;
|
||||
polyfillmode: number;
|
||||
miterlimit: number;
|
||||
wx: number;
|
||||
wy: number;
|
||||
ww: number;
|
||||
wh: number;
|
||||
vx: number;
|
||||
vy: number;
|
||||
vw: number;
|
||||
vh: number;
|
||||
x: number;
|
||||
y: number;
|
||||
nextbrx: number;
|
||||
nextbry: number;
|
||||
brx: number;
|
||||
bry: number;
|
||||
clip: Region;
|
||||
ownclip: boolean;
|
||||
selected: ISelectedStyle;
|
||||
public _svggroup: any;
|
||||
public _svgclipChanged: boolean;
|
||||
public _svgtextbkfilter: any;
|
||||
public mapmode: number;
|
||||
public stretchmode: number;
|
||||
public textalign: number;
|
||||
public bkmode: number;
|
||||
public textcolor: ColorRef;
|
||||
public bkcolor: ColorRef;
|
||||
public polyfillmode: number;
|
||||
public miterlimit: number;
|
||||
public wx: number;
|
||||
public wy: number;
|
||||
public ww: number;
|
||||
public wh: number;
|
||||
public vx: number;
|
||||
public vy: number;
|
||||
public vw: number;
|
||||
public vh: number;
|
||||
public x: number;
|
||||
public y: number;
|
||||
public nextbrx: number;
|
||||
public nextbry: number;
|
||||
public brx: number;
|
||||
public bry: number;
|
||||
public clip: Region;
|
||||
public ownclip: boolean;
|
||||
public selected: ISelectedStyle;
|
||||
|
||||
constructor(copy: GDIContextState, defObjects?: ISelectedStyle) {
|
||||
if (copy != null) {
|
||||
@@ -209,15 +209,15 @@ export class GDIContextState {
|
||||
}
|
||||
|
||||
export class GDIContext {
|
||||
_svg: any;
|
||||
_svgdefs: any;
|
||||
_svgPatterns: {[key: string]: Brush};
|
||||
_svgClipPaths: {[key: string]: Region};
|
||||
_svgPath: any;
|
||||
defObjects: ISelectedStyle;
|
||||
state: GDIContextState;
|
||||
statestack: GDIContextState[];
|
||||
objects: {[key: string]: Obj};
|
||||
private _svg: any;
|
||||
private _svgdefs: any;
|
||||
private _svgPatterns: {[key: string]: Brush};
|
||||
private _svgClipPaths: {[key: string]: Region};
|
||||
private _svgPath: any;
|
||||
private defObjects: ISelectedStyle;
|
||||
private state: GDIContextState;
|
||||
private statestack: GDIContextState[];
|
||||
private objects: {[key: string]: Obj};
|
||||
|
||||
constructor(svg: any) {
|
||||
this._svg = svg;
|
||||
@@ -242,7 +242,374 @@ export class GDIContext {
|
||||
this.objects = {};
|
||||
}
|
||||
|
||||
_pushGroup() {
|
||||
public setMapMode(mode: number) {
|
||||
Helper.log("[gdi] setMapMode: mode=" + mode);
|
||||
this.state.mapmode = mode;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public setWindowOrgEx(x: number, y: number) {
|
||||
Helper.log("[gdi] setWindowOrgEx: x=" + x + " y=" + y);
|
||||
this.state.wx = x;
|
||||
this.state.wy = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public setWindowExtEx(x: number, y: number) {
|
||||
Helper.log("[gdi] setWindowExtEx: x=" + x + " y=" + y);
|
||||
this.state.ww = x;
|
||||
this.state.wh = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public setViewportOrgEx(x: number, y: number) {
|
||||
Helper.log("[gdi] setViewportOrgEx: x=" + x + " y=" + y);
|
||||
this.state.vx = x;
|
||||
this.state.vy = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public setViewportExtEx(x: number, y: number) {
|
||||
Helper.log("[gdi] setViewportExtEx: x=" + x + " y=" + y);
|
||||
this.state.vw = x;
|
||||
this.state.vh = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public setBrushOrgEx(origin: PointL) {
|
||||
Helper.log("[gdi] setBrushOrgEx: x=" + origin.x + " y=" + origin.y);
|
||||
this.state.nextbrx = origin.x;
|
||||
this.state.nextbry = origin.y;
|
||||
}
|
||||
|
||||
public saveDC() {
|
||||
Helper.log("[gdi] saveDC");
|
||||
const prevstate = this.state;
|
||||
this.state = new GDIContextState(this.state);
|
||||
this.statestack.push(prevstate);
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public restoreDC(saved: number) {
|
||||
Helper.log("[gdi] restoreDC: saved=" + saved);
|
||||
if (this.statestack.length > 1) {
|
||||
if (saved === -1) {
|
||||
this.state = this.statestack.pop();
|
||||
} else if (saved < -1) {
|
||||
throw new EMFJSError("restoreDC: relative restore not implemented");
|
||||
} else if (saved > 1) {
|
||||
throw new EMFJSError("restoreDC: absolute restore not implemented");
|
||||
}
|
||||
} else {
|
||||
throw new EMFJSError("No saved contexts");
|
||||
}
|
||||
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public setStretchBltMode(stretchMode: number) {
|
||||
Helper.log("[gdi] setStretchBltMode: stretchMode=" + stretchMode);
|
||||
}
|
||||
|
||||
public rectangle(rect: RectL, rw: number, rh: number) {
|
||||
Helper.log("[gdi] rectangle: rect=" + rect.toString() + " with pen " + this.state.selected.pen.toString()
|
||||
+ " and brush " + this.state.selected.brush.toString());
|
||||
const bottom = this._todevY(rect.bottom);
|
||||
const right = this._todevX(rect.right);
|
||||
const top = this._todevY(rect.top);
|
||||
const left = this._todevX(rect.left);
|
||||
rw = this._todevH(rw);
|
||||
rh = this._todevH(rh);
|
||||
Helper.log("[gdi] rectangle: TRANSLATED: bottom=" + bottom + " right=" + right + " top=" + top
|
||||
+ " left=" + left + " rh=" + rh + " rw=" + rw);
|
||||
this._pushGroup();
|
||||
|
||||
const opts = this._applyOpts(null, true, true, false);
|
||||
this._svg.rect(this.state._svggroup, left, top, right - left, bottom - top, rw / 2, rh / 2, opts);
|
||||
}
|
||||
|
||||
public lineTo(x: number, y: number) {
|
||||
Helper.log("[gdi] lineTo: x=" + x + " y=" + y + " with pen " + this.state.selected.pen.toString());
|
||||
const toX = this._todevX(x);
|
||||
const toY = this._todevY(y);
|
||||
const fromX = this._todevX(this.state.x);
|
||||
const fromY = this._todevY(this.state.y);
|
||||
|
||||
// Update position
|
||||
this.state.x = x;
|
||||
this.state.y = y;
|
||||
|
||||
Helper.log("[gdi] lineTo: TRANSLATED: toX=" + toX + " toY=" + toY + " fromX=" + fromX + " fromY=" + fromY);
|
||||
this._pushGroup();
|
||||
|
||||
const opts = this._applyOpts(null, true, false, false);
|
||||
this._svg.line(this.state._svggroup, fromX, fromY, toX, toY, opts);
|
||||
}
|
||||
|
||||
public moveToEx(x: number, y: number) {
|
||||
Helper.log("[gdi] moveToEx: x=" + x + " y=" + y);
|
||||
this.state.x = x;
|
||||
this.state.y = y;
|
||||
if (this._svgPath != null) {
|
||||
this._svgPath.move(this.state.x, this.state.y);
|
||||
Helper.log("[gdi] new path: " + this._svgPath.path());
|
||||
}
|
||||
}
|
||||
|
||||
public polygon(points: PointS[] | PointL[], bounds: RectL, first: boolean) {
|
||||
Helper.log("[gdi] polygon: points=" + points + " with pen " + this.state.selected.pen.toString()
|
||||
+ " and brush " + this.state.selected.brush.toString());
|
||||
const pts = [];
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const point = points[i];
|
||||
pts.push([this._todevX(point.x), this._todevY(point.y)]);
|
||||
}
|
||||
if (first) {
|
||||
this._pushGroup();
|
||||
}
|
||||
const opts = {
|
||||
"fill-rule": this.state.polyfillmode === Helper.GDI.PolygonFillMode.ALTERNATE ? "evenodd" : "nonzero",
|
||||
};
|
||||
this._applyOpts(opts, true, true, false);
|
||||
this._svg.polygon(this.state._svggroup, pts, opts);
|
||||
}
|
||||
|
||||
public polyPolygon(polygons: PointS[][] | PointL[][], bounds: RectL) {
|
||||
Helper.log("[gdi] polyPolygon: polygons.length=" + polygons.length
|
||||
+ " with pen " + this.state.selected.pen.toString() + " and brush " + this.state.selected.brush.toString());
|
||||
|
||||
const cnt = polygons.length;
|
||||
for (let i = 0; i < cnt; i++) {
|
||||
this.polygon(polygons[i], bounds, i === 0);
|
||||
}
|
||||
}
|
||||
|
||||
public polyline(isLineTo: boolean, points: PointS[], bounds: RectL) {
|
||||
Helper.log("[gdi] polyline: isLineTo=" + isLineTo.toString() + ", points=" + points
|
||||
+ ", bounds=" + bounds.toString() + " with pen " + this.state.selected.pen.toString());
|
||||
const pts = [];
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const point = points[i];
|
||||
pts.push([this._todevX(point.x), this._todevY(point.y)]);
|
||||
}
|
||||
|
||||
if (this._svgPath != null) {
|
||||
if (!isLineTo || pts.length === 0) {
|
||||
this._svgPath.move(this._todevX(this.state.x), this._todevY(this.state.y));
|
||||
} else {
|
||||
const firstPts = pts[0];
|
||||
this._svgPath.move(firstPts[0], firstPts[1]);
|
||||
}
|
||||
this._svgPath.line(pts);
|
||||
Helper.log("[gdi] new path: " + this._svgPath.path());
|
||||
} else {
|
||||
this._pushGroup();
|
||||
const opts = this._applyOpts(null, true, false, false);
|
||||
if (isLineTo && points.length > 0) {
|
||||
const firstPt = points[0];
|
||||
if (firstPt.x !== this.state.x || firstPt.y !== this.state.y) {
|
||||
pts.unshift([this._todevX(this.state.x), this._todevY(this.state.y)]);
|
||||
}
|
||||
}
|
||||
this._svg.polyline(this.state._svggroup, pts, opts);
|
||||
}
|
||||
|
||||
if (points.length > 0) {
|
||||
const lastPt = points[points.length - 1];
|
||||
this.state.x = lastPt.x;
|
||||
this.state.y = lastPt.y;
|
||||
}
|
||||
}
|
||||
|
||||
public polybezier(isPolyBezierTo: boolean, points: PointS[], bounds: RectL) {
|
||||
Helper.log("[gdi] polybezier: isPolyBezierTo=" + isPolyBezierTo.toString() + ", points=" + points
|
||||
+ ", bounds=" + bounds.toString() + " with pen " + this.state.selected.pen.toString());
|
||||
const pts = [];
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const point = points[i];
|
||||
pts.push({ x: this._todevX(point.x), y: this._todevY(point.y)});
|
||||
}
|
||||
|
||||
if (this._svgPath != null) {
|
||||
if (isPolyBezierTo && pts.length > 0) {
|
||||
const firstPts = pts[0];
|
||||
this._svgPath.move(firstPts.x, firstPts.y);
|
||||
} else {
|
||||
this._svgPath.move(this._todevX(this.state.x), this._todevY(this.state.y));
|
||||
}
|
||||
|
||||
if (pts.length < (isPolyBezierTo ? 3 : 4)) {
|
||||
throw new EMFJSError("Not enough points to draw bezier");
|
||||
}
|
||||
|
||||
for (let i = isPolyBezierTo ? 1 : 0; i + 3 <= pts.length; i += 3) {
|
||||
const cp1 = pts[i];
|
||||
const cp2 = pts[i + 1];
|
||||
const ep = pts[i + 2];
|
||||
this._svgPath.curveC(cp1.x, cp1.y, cp2.x, cp2.y, ep.x, ep.y);
|
||||
}
|
||||
|
||||
Helper.log("[gdi] new path: " + this._svgPath.path());
|
||||
} else {
|
||||
throw new EMFJSError("polybezier not implemented (not a path)");
|
||||
}
|
||||
|
||||
if (points.length > 0) {
|
||||
const lastPt = points[points.length - 1];
|
||||
this.state.x = lastPt.x;
|
||||
this.state.y = lastPt.y;
|
||||
}
|
||||
}
|
||||
|
||||
public selectClipPath(rgnMode: number) {
|
||||
Helper.log("[gdi] selectClipPath: rgnMode=0x" + rgnMode.toString(16));
|
||||
}
|
||||
|
||||
public selectClipRgn(rgnMode: number, region: Region) {
|
||||
Helper.log("[gdi] selectClipRgn: rgnMode=0x" + rgnMode.toString(16));
|
||||
if (rgnMode === Helper.GDI.RegionMode.RGN_COPY) {
|
||||
this.state.selected.region = region;
|
||||
this.state.clip = null;
|
||||
this.state.ownclip = false;
|
||||
} else {
|
||||
if (region == null) {
|
||||
throw new EMFJSError("No clip region to select");
|
||||
}
|
||||
|
||||
throw new EMFJSError("Not implemented: rgnMode=0x" + rgnMode.toString(16));
|
||||
}
|
||||
this.state._svgclipChanged = true;
|
||||
}
|
||||
|
||||
public offsetClipRgn(offset: PointL) {
|
||||
Helper.log("[gdi] offsetClipRgn: offset=" + offset.toString());
|
||||
this._getClipRgn().offset(offset.x, offset.y);
|
||||
}
|
||||
|
||||
public setTextAlign(textAlignmentMode: number) {
|
||||
Helper.log("[gdi] setTextAlign: textAlignmentMode=0x" + textAlignmentMode.toString(16));
|
||||
this.state.textalign = textAlignmentMode;
|
||||
}
|
||||
|
||||
public setMiterLimit(miterLimit: number) {
|
||||
Helper.log("[gdi] setMiterLimit: miterLimit=" + miterLimit);
|
||||
this.state.miterlimit = miterLimit;
|
||||
}
|
||||
|
||||
public setBkMode(bkMode: number) {
|
||||
Helper.log("[gdi] setBkMode: bkMode=0x" + bkMode.toString(16));
|
||||
this.state.bkmode = bkMode;
|
||||
}
|
||||
|
||||
public setBkColor(bkColor: ColorRef) {
|
||||
Helper.log("[gdi] setBkColor: bkColor=" + bkColor.toString());
|
||||
this.state.bkcolor = bkColor;
|
||||
this.state._svgtextbkfilter = null;
|
||||
}
|
||||
|
||||
public setPolyFillMode(polyFillMode: number) {
|
||||
Helper.log("[gdi] setPolyFillMode: polyFillMode=" + polyFillMode);
|
||||
this.state.polyfillmode = polyFillMode;
|
||||
}
|
||||
|
||||
public createBrush(index: number, brush: Brush) {
|
||||
const idx = this._storeObject(brush, index);
|
||||
Helper.log("[gdi] createBrush: brush=" + brush.toString() + " with handle " + idx);
|
||||
}
|
||||
|
||||
public createPen(index: number, pen: Pen) {
|
||||
const idx = this._storeObject(pen, index);
|
||||
Helper.log("[gdi] createPen: pen=" + pen.toString() + " width handle " + idx);
|
||||
}
|
||||
|
||||
public createPenEx(index: number, pen: Pen) {
|
||||
const idx = this._storeObject(pen, index);
|
||||
Helper.log("[gdi] createPenEx: pen=" + pen.toString() + " width handle " + idx);
|
||||
}
|
||||
|
||||
public selectObject(objIdx: number, checkType: string) {
|
||||
const obj = this._getObject(objIdx);
|
||||
if (obj != null && (checkType == null || obj.type === checkType)) {
|
||||
this._selectObject(obj);
|
||||
Helper.log("[gdi] selectObject: objIdx=" + objIdx
|
||||
+ (obj ? " selected " + obj.type + ": " + obj.toString() : "[invalid index]"));
|
||||
} else {
|
||||
Helper.log("[gdi] selectObject: objIdx=" + objIdx
|
||||
+ (obj ? " invalid object type: " + obj.type : "[invalid index]"));
|
||||
}
|
||||
}
|
||||
|
||||
public abortPath() {
|
||||
Helper.log("[gdi] abortPath");
|
||||
if (this._svgPath != null) {
|
||||
this._svgPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
public beginPath() {
|
||||
Helper.log("[gdi] beginPath");
|
||||
|
||||
if (this._svgPath != null) {
|
||||
this._svgPath = null;
|
||||
}
|
||||
|
||||
this._svgPath = this._svg.createPath();
|
||||
}
|
||||
|
||||
public closeFigure() {
|
||||
Helper.log("[gdi] closeFigure");
|
||||
if (this._svgPath == null) {
|
||||
throw new EMFJSError("No path bracket: cannot close figure");
|
||||
}
|
||||
|
||||
this._svgPath.close();
|
||||
}
|
||||
|
||||
public fillPath(bounds: RectL) {
|
||||
Helper.log("[gdi] fillPath");
|
||||
if (this.state.selected.path == null) {
|
||||
throw new EMFJSError("No path selected");
|
||||
}
|
||||
|
||||
const selPath = this.state.selected.path;
|
||||
const opts = this._applyOpts(null, true, true, false);
|
||||
this._svg.path(this.state._svggroup, selPath.svgPath, opts);
|
||||
|
||||
this._pushGroup();
|
||||
this.state.selected.path = null;
|
||||
}
|
||||
|
||||
public strokePath(bounds: RectL) {
|
||||
Helper.log("[gdi] strokePath");
|
||||
if (this.state.selected.path == null) {
|
||||
throw new EMFJSError("No path selected");
|
||||
}
|
||||
|
||||
const selPath = this.state.selected.path;
|
||||
const opts = this._applyOpts({fill: "none"}, true, false, false);
|
||||
this._svg.path(this.state._svggroup, selPath.svgPath, opts);
|
||||
|
||||
this._pushGroup();
|
||||
this.state.selected.path = null;
|
||||
}
|
||||
|
||||
public endPath() {
|
||||
Helper.log("[gdi] endPath");
|
||||
if (this._svgPath == null) {
|
||||
throw new EMFJSError("No path bracket: cannot end path");
|
||||
}
|
||||
|
||||
this._pushGroup();
|
||||
this._selectObject(new Path(this._svgPath));
|
||||
this._svgPath = null;
|
||||
}
|
||||
|
||||
public deleteObject(objIdx: number) {
|
||||
const ret = this._deleteObject(objIdx);
|
||||
Helper.log("[gdi] deleteObject: objIdx=" + objIdx + (ret ? " deleted object" : "[invalid index]"));
|
||||
}
|
||||
|
||||
private _pushGroup() {
|
||||
if (this.state._svggroup == null || this.state._svgclipChanged) {
|
||||
this.state._svgclipChanged = false;
|
||||
this.state._svgtextbkfilter = null;
|
||||
@@ -264,18 +631,18 @@ export class GDIContext {
|
||||
}
|
||||
}
|
||||
|
||||
_getStockObject(idx: number) {
|
||||
private _getStockObject(idx: number) {
|
||||
if (idx >= 0x80000000 && idx <= 0x80000011) {
|
||||
return _StockObjects[(idx - 0x80000000).toString()];
|
||||
} else if (idx === Helper.GDI.StockObject.DC_BRUSH) {
|
||||
return this.state.selected.brush;
|
||||
} else if (idx === Helper.GDI.StockObject.DC_PEN) {
|
||||
} else if (idx === Helper.GDI.StockObject.DC_PEN) {
|
||||
return this.state.selected.pen;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
_storeObject(obj: Obj, idx: number) {
|
||||
private _storeObject(obj: Obj, idx: number) {
|
||||
if (!idx) {
|
||||
idx = 0;
|
||||
while (this.objects[idx.toString()] != null && idx <= 65535) {
|
||||
@@ -291,7 +658,7 @@ export class GDIContext {
|
||||
return idx;
|
||||
}
|
||||
|
||||
_getObject(objIdx: number) {
|
||||
private _getObject(objIdx: number) {
|
||||
let obj = this.objects[objIdx.toString()];
|
||||
if (obj == null) {
|
||||
obj = this._getStockObject(objIdx);
|
||||
@@ -302,14 +669,14 @@ export class GDIContext {
|
||||
return obj;
|
||||
}
|
||||
|
||||
_getSvgDef() {
|
||||
private _getSvgDef() {
|
||||
if (this._svgdefs == null) {
|
||||
this._svgdefs = this._svg.defs();
|
||||
}
|
||||
return this._svgdefs;
|
||||
}
|
||||
|
||||
_getSvgClipPathForRegion(region: Region) {
|
||||
private _getSvgClipPathForRegion(region: Region) {
|
||||
for (const existingId in this._svgClipPaths) {
|
||||
const rgn = this._svgClipPaths[existingId];
|
||||
if (rgn === region) {
|
||||
@@ -344,7 +711,7 @@ export class GDIContext {
|
||||
return id;
|
||||
}
|
||||
|
||||
_getSvgPatternForBrush(brush: Brush) {
|
||||
private _getSvgPatternForBrush(brush: Brush) {
|
||||
for (const existingId in this._svgPatterns) {
|
||||
const pat = this._svgPatterns[existingId];
|
||||
if (pat === brush) {
|
||||
@@ -377,7 +744,7 @@ export class GDIContext {
|
||||
return id;
|
||||
}
|
||||
|
||||
_selectObject(obj: Obj) {
|
||||
private _selectObject(obj: Obj) {
|
||||
this.state.selected[obj.type] = obj;
|
||||
switch (obj.type) {
|
||||
case "region":
|
||||
@@ -390,7 +757,7 @@ export class GDIContext {
|
||||
}
|
||||
}
|
||||
|
||||
_deleteObject(objIdx: number) {
|
||||
private _deleteObject(objIdx: number) {
|
||||
const obj = this.objects[objIdx.toString()];
|
||||
if (obj != null) {
|
||||
for (let i = 0; i < this.statestack.length; i++) {
|
||||
@@ -407,7 +774,7 @@ export class GDIContext {
|
||||
return false;
|
||||
}
|
||||
|
||||
_getClipRgn() {
|
||||
private _getClipRgn() {
|
||||
if (this.state.clip != null) {
|
||||
if (!this.state.ownclip) {
|
||||
this.state.clip = this.state.clip.clone();
|
||||
@@ -424,124 +791,55 @@ export class GDIContext {
|
||||
return this.state.clip;
|
||||
}
|
||||
|
||||
_todevX(val: number) {
|
||||
private _todevX(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.wx) * (this.state.vw / this.state.ww)) + this.state.vx;
|
||||
}
|
||||
|
||||
_todevY(val: number) {
|
||||
private _todevY(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.wy) * (this.state.vh / this.state.wh)) + this.state.vy;
|
||||
}
|
||||
|
||||
_todevW(val: number) {
|
||||
private _todevW(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val * (this.state.vw / this.state.ww)) + this.state.vx;
|
||||
}
|
||||
|
||||
_todevH(val: number) {
|
||||
private _todevH(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val * (this.state.vh / this.state.wh)) + this.state.vy;
|
||||
}
|
||||
|
||||
_tologicalX(val: number) {
|
||||
private _tologicalX(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.vx) / (this.state.vw / this.state.ww)) + this.state.wx;
|
||||
}
|
||||
|
||||
_tologicalY(val: number) {
|
||||
private _tologicalY(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.vy) / (this.state.vh / this.state.wh)) + this.state.wy;
|
||||
}
|
||||
|
||||
_tologicalW(val: number) {
|
||||
private _tologicalW(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val / (this.state.vw / this.state.ww)) + this.state.wx;
|
||||
}
|
||||
|
||||
_tologicalH(val: number) {
|
||||
private _tologicalH(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val / (this.state.vh / this.state.wh)) + this.state.wy;
|
||||
}
|
||||
|
||||
setMapMode(mode: number) {
|
||||
Helper.log("[gdi] setMapMode: mode=" + mode);
|
||||
this.state.mapmode = mode;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
setWindowOrgEx(x: number, y: number) {
|
||||
Helper.log("[gdi] setWindowOrgEx: x=" + x + " y=" + y);
|
||||
this.state.wx = x;
|
||||
this.state.wy = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
setWindowExtEx(x: number, y: number) {
|
||||
Helper.log("[gdi] setWindowExtEx: x=" + x + " y=" + y);
|
||||
this.state.ww = x;
|
||||
this.state.wh = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
setViewportOrgEx(x: number, y: number) {
|
||||
Helper.log("[gdi] setViewportOrgEx: x=" + x + " y=" + y);
|
||||
this.state.vx = x;
|
||||
this.state.vy = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
setViewportExtEx(x: number, y: number) {
|
||||
Helper.log("[gdi] setViewportExtEx: x=" + x + " y=" + y);
|
||||
this.state.vw = x;
|
||||
this.state.vh = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
setBrushOrgEx(origin: PointL) {
|
||||
Helper.log("[gdi] setBrushOrgEx: x=" + origin.x + " y=" + origin.y);
|
||||
this.state.nextbrx = origin.x;
|
||||
this.state.nextbry = origin.y;
|
||||
}
|
||||
|
||||
saveDC() {
|
||||
Helper.log("[gdi] saveDC");
|
||||
const prevstate = this.state;
|
||||
this.state = new GDIContextState(this.state);
|
||||
this.statestack.push(prevstate);
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
restoreDC(saved: number) {
|
||||
Helper.log("[gdi] restoreDC: saved=" + saved);
|
||||
if (this.statestack.length > 1) {
|
||||
if (saved === -1) {
|
||||
this.state = this.statestack.pop();
|
||||
} else if (saved < -1) {
|
||||
throw new EMFJSError("restoreDC: relative restore not implemented");
|
||||
} else if (saved > 1) {
|
||||
throw new EMFJSError("restoreDC: absolute restore not implemented");
|
||||
}
|
||||
} else {
|
||||
throw new EMFJSError("No saved contexts");
|
||||
}
|
||||
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
setStretchBltMode(stretchMode: number) {
|
||||
Helper.log("[gdi] setStretchBltMode: stretchMode=" + stretchMode);
|
||||
}
|
||||
|
||||
_applyOpts(opts: any, usePen: boolean, useBrush: boolean, useFont: boolean) {
|
||||
private _applyOpts(opts: any, usePen: boolean, useBrush: boolean, useFont: boolean) {
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
@@ -605,304 +903,4 @@ export class GDIContext {
|
||||
}
|
||||
return opts;
|
||||
}
|
||||
|
||||
rectangle(rect: RectL, rw: number, rh: number) {
|
||||
Helper.log("[gdi] rectangle: rect=" + rect.toString() + " with pen " + this.state.selected.pen.toString()
|
||||
+ " and brush " + this.state.selected.brush.toString());
|
||||
const bottom = this._todevY(rect.bottom);
|
||||
const right = this._todevX(rect.right);
|
||||
const top = this._todevY(rect.top);
|
||||
const left = this._todevX(rect.left);
|
||||
rw = this._todevH(rw);
|
||||
rh = this._todevH(rh);
|
||||
Helper.log("[gdi] rectangle: TRANSLATED: bottom=" + bottom + " right=" + right + " top=" + top
|
||||
+ " left=" + left + " rh=" + rh + " rw=" + rw);
|
||||
this._pushGroup();
|
||||
|
||||
const opts = this._applyOpts(null, true, true, false);
|
||||
this._svg.rect(this.state._svggroup, left, top, right - left, bottom - top, rw / 2, rh / 2, opts);
|
||||
}
|
||||
|
||||
lineTo(x: number, y: number) {
|
||||
Helper.log("[gdi] lineTo: x=" + x + " y=" + y + " with pen " + this.state.selected.pen.toString());
|
||||
const toX = this._todevX(x);
|
||||
const toY = this._todevY(y);
|
||||
const fromX = this._todevX(this.state.x);
|
||||
const fromY = this._todevY(this.state.y);
|
||||
|
||||
// Update position
|
||||
this.state.x = x;
|
||||
this.state.y = y;
|
||||
|
||||
Helper.log("[gdi] lineTo: TRANSLATED: toX=" + toX + " toY=" + toY + " fromX=" + fromX + " fromY=" + fromY);
|
||||
this._pushGroup();
|
||||
|
||||
const opts = this._applyOpts(null, true, false, false);
|
||||
this._svg.line(this.state._svggroup, fromX, fromY, toX, toY, opts);
|
||||
}
|
||||
|
||||
moveToEx(x: number, y: number) {
|
||||
Helper.log("[gdi] moveToEx: x=" + x + " y=" + y);
|
||||
this.state.x = x;
|
||||
this.state.y = y;
|
||||
if (this._svgPath != null) {
|
||||
this._svgPath.move(this.state.x, this.state.y);
|
||||
Helper.log("[gdi] new path: " + this._svgPath.path());
|
||||
}
|
||||
}
|
||||
|
||||
polygon(points: PointS[] | PointL[], bounds: RectL, first: boolean) {
|
||||
Helper.log("[gdi] polygon: points=" + points + " with pen " + this.state.selected.pen.toString()
|
||||
+ " and brush " + this.state.selected.brush.toString());
|
||||
const pts = [];
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const point = points[i];
|
||||
pts.push([this._todevX(point.x), this._todevY(point.y)]);
|
||||
}
|
||||
if (first) {
|
||||
this._pushGroup();
|
||||
}
|
||||
const opts = {
|
||||
"fill-rule": this.state.polyfillmode === Helper.GDI.PolygonFillMode.ALTERNATE ? "evenodd" : "nonzero",
|
||||
};
|
||||
this._applyOpts(opts, true, true, false);
|
||||
this._svg.polygon(this.state._svggroup, pts, opts);
|
||||
}
|
||||
|
||||
polyPolygon(polygons: PointS[][] | PointL[][], bounds: RectL) {
|
||||
Helper.log("[gdi] polyPolygon: polygons.length=" + polygons.length
|
||||
+ " with pen " + this.state.selected.pen.toString() + " and brush " + this.state.selected.brush.toString());
|
||||
|
||||
const cnt = polygons.length;
|
||||
for (let i = 0; i < cnt; i++) {
|
||||
this.polygon(polygons[i], bounds, i === 0);
|
||||
}
|
||||
}
|
||||
|
||||
polyline(isLineTo: boolean, points: PointS[], bounds: RectL) {
|
||||
Helper.log("[gdi] polyline: isLineTo=" + isLineTo.toString() + ", points=" + points
|
||||
+ ", bounds=" + bounds.toString() + " with pen " + this.state.selected.pen.toString());
|
||||
const pts = [];
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const point = points[i];
|
||||
pts.push([this._todevX(point.x), this._todevY(point.y)]);
|
||||
}
|
||||
|
||||
if (this._svgPath != null) {
|
||||
if (!isLineTo || pts.length === 0) {
|
||||
this._svgPath.move(this._todevX(this.state.x), this._todevY(this.state.y));
|
||||
} else {
|
||||
const firstPts = pts[0];
|
||||
this._svgPath.move(firstPts[0], firstPts[1]);
|
||||
}
|
||||
this._svgPath.line(pts);
|
||||
Helper.log("[gdi] new path: " + this._svgPath.path());
|
||||
} else {
|
||||
this._pushGroup();
|
||||
const opts = this._applyOpts(null, true, false, false);
|
||||
if (isLineTo && points.length > 0) {
|
||||
const firstPt = points[0];
|
||||
if (firstPt.x !== this.state.x || firstPt.y !== this.state.y) {
|
||||
pts.unshift([this._todevX(this.state.x), this._todevY(this.state.y)]);
|
||||
}
|
||||
}
|
||||
this._svg.polyline(this.state._svggroup, pts, opts);
|
||||
}
|
||||
|
||||
if (points.length > 0) {
|
||||
const lastPt = points[points.length - 1];
|
||||
this.state.x = lastPt.x;
|
||||
this.state.y = lastPt.y;
|
||||
}
|
||||
}
|
||||
|
||||
polybezier(isPolyBezierTo: boolean, points: PointS[], bounds: RectL) {
|
||||
Helper.log("[gdi] polybezier: isPolyBezierTo=" + isPolyBezierTo.toString() + ", points=" + points
|
||||
+ ", bounds=" + bounds.toString() + " with pen " + this.state.selected.pen.toString());
|
||||
const pts = [];
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const point = points[i];
|
||||
pts.push({ x: this._todevX(point.x), y: this._todevY(point.y)});
|
||||
}
|
||||
|
||||
if (this._svgPath != null) {
|
||||
if (isPolyBezierTo && pts.length > 0) {
|
||||
const firstPts = pts[0];
|
||||
this._svgPath.move(firstPts.x, firstPts.y);
|
||||
} else {
|
||||
this._svgPath.move(this._todevX(this.state.x), this._todevY(this.state.y));
|
||||
}
|
||||
|
||||
if (pts.length < (isPolyBezierTo ? 3 : 4)) {
|
||||
throw new EMFJSError("Not enough points to draw bezier");
|
||||
}
|
||||
|
||||
for (let i = isPolyBezierTo ? 1 : 0; i + 3 <= pts.length; i += 3) {
|
||||
const cp1 = pts[i];
|
||||
const cp2 = pts[i + 1];
|
||||
const ep = pts[i + 2];
|
||||
this._svgPath.curveC(cp1.x, cp1.y, cp2.x, cp2.y, ep.x, ep.y);
|
||||
}
|
||||
|
||||
Helper.log("[gdi] new path: " + this._svgPath.path());
|
||||
} else {
|
||||
throw new EMFJSError("polybezier not implemented (not a path)");
|
||||
}
|
||||
|
||||
if (points.length > 0) {
|
||||
const lastPt = points[points.length - 1];
|
||||
this.state.x = lastPt.x;
|
||||
this.state.y = lastPt.y;
|
||||
}
|
||||
}
|
||||
|
||||
selectClipPath(rgnMode: number) {
|
||||
Helper.log("[gdi] selectClipPath: rgnMode=0x" + rgnMode.toString(16));
|
||||
}
|
||||
|
||||
selectClipRgn(rgnMode: number, region: Region) {
|
||||
Helper.log("[gdi] selectClipRgn: rgnMode=0x" + rgnMode.toString(16));
|
||||
if (rgnMode === Helper.GDI.RegionMode.RGN_COPY) {
|
||||
this.state.selected.region = region;
|
||||
this.state.clip = null;
|
||||
this.state.ownclip = false;
|
||||
} else {
|
||||
if (region == null) {
|
||||
throw new EMFJSError("No clip region to select");
|
||||
}
|
||||
|
||||
throw new EMFJSError("Not implemented: rgnMode=0x" + rgnMode.toString(16));
|
||||
}
|
||||
this.state._svgclipChanged = true;
|
||||
}
|
||||
|
||||
offsetClipRgn(offset: PointL) {
|
||||
Helper.log("[gdi] offsetClipRgn: offset=" + offset.toString());
|
||||
this._getClipRgn().offset(offset.x, offset.y);
|
||||
}
|
||||
|
||||
setTextAlign(textAlignmentMode: number) {
|
||||
Helper.log("[gdi] setTextAlign: textAlignmentMode=0x" + textAlignmentMode.toString(16));
|
||||
this.state.textalign = textAlignmentMode;
|
||||
}
|
||||
|
||||
setMiterLimit(miterLimit: number) {
|
||||
Helper.log("[gdi] setMiterLimit: miterLimit=" + miterLimit);
|
||||
this.state.miterlimit = miterLimit;
|
||||
}
|
||||
|
||||
setBkMode(bkMode: number) {
|
||||
Helper.log("[gdi] setBkMode: bkMode=0x" + bkMode.toString(16));
|
||||
this.state.bkmode = bkMode;
|
||||
}
|
||||
|
||||
setBkColor(bkColor: ColorRef) {
|
||||
Helper.log("[gdi] setBkColor: bkColor=" + bkColor.toString());
|
||||
this.state.bkcolor = bkColor;
|
||||
this.state._svgtextbkfilter = null;
|
||||
}
|
||||
|
||||
setPolyFillMode(polyFillMode: number) {
|
||||
Helper.log("[gdi] setPolyFillMode: polyFillMode=" + polyFillMode);
|
||||
this.state.polyfillmode = polyFillMode;
|
||||
}
|
||||
|
||||
createBrush(index: number, brush: Brush) {
|
||||
const idx = this._storeObject(brush, index);
|
||||
Helper.log("[gdi] createBrush: brush=" + brush.toString() + " with handle " + idx);
|
||||
}
|
||||
|
||||
createPen(index: number, pen: Pen) {
|
||||
const idx = this._storeObject(pen, index);
|
||||
Helper.log("[gdi] createPen: pen=" + pen.toString() + " width handle " + idx);
|
||||
}
|
||||
|
||||
createPenEx(index: number, pen: Pen) {
|
||||
const idx = this._storeObject(pen, index);
|
||||
Helper.log("[gdi] createPenEx: pen=" + pen.toString() + " width handle " + idx);
|
||||
}
|
||||
|
||||
selectObject(objIdx: number, checkType: string) {
|
||||
const obj = this._getObject(objIdx);
|
||||
if (obj != null && (checkType == null || obj.type === checkType)) {
|
||||
this._selectObject(obj);
|
||||
Helper.log("[gdi] selectObject: objIdx=" + objIdx
|
||||
+ (obj ? " selected " + obj.type + ": " + obj.toString() : "[invalid index]"));
|
||||
} else {
|
||||
Helper.log("[gdi] selectObject: objIdx=" + objIdx
|
||||
+ (obj ? " invalid object type: " + obj.type : "[invalid index]"));
|
||||
}
|
||||
}
|
||||
|
||||
_abortPath() {
|
||||
if (this._svgPath != null) {
|
||||
this._svgPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
abortPath() {
|
||||
Helper.log("[gdi] abortPath");
|
||||
this._abortPath();
|
||||
}
|
||||
|
||||
beginPath() {
|
||||
Helper.log("[gdi] beginPath");
|
||||
|
||||
this._abortPath();
|
||||
|
||||
this._svgPath = this._svg.createPath();
|
||||
}
|
||||
|
||||
closeFigure() {
|
||||
Helper.log("[gdi] closeFigure");
|
||||
if (this._svgPath == null) {
|
||||
throw new EMFJSError("No path bracket: cannot close figure");
|
||||
}
|
||||
|
||||
this._svgPath.close();
|
||||
}
|
||||
|
||||
fillPath(bounds: RectL) {
|
||||
Helper.log("[gdi] fillPath");
|
||||
if (this.state.selected.path == null) {
|
||||
throw new EMFJSError("No path selected");
|
||||
}
|
||||
|
||||
const selPath = this.state.selected.path;
|
||||
const opts = this._applyOpts(null, true, true, false);
|
||||
this._svg.path(this.state._svggroup, selPath.svgPath, opts);
|
||||
|
||||
this._pushGroup();
|
||||
this.state.selected.path = null;
|
||||
}
|
||||
|
||||
strokePath(bounds: RectL) {
|
||||
Helper.log("[gdi] strokePath");
|
||||
if (this.state.selected.path == null) {
|
||||
throw new EMFJSError("No path selected");
|
||||
}
|
||||
|
||||
const selPath = this.state.selected.path;
|
||||
const opts = this._applyOpts({fill: "none"}, true, false, false);
|
||||
this._svg.path(this.state._svggroup, selPath.svgPath, opts);
|
||||
|
||||
this._pushGroup();
|
||||
this.state.selected.path = null;
|
||||
}
|
||||
|
||||
endPath() {
|
||||
Helper.log("[gdi] endPath");
|
||||
if (this._svgPath == null) {
|
||||
throw new EMFJSError("No path bracket: cannot end path");
|
||||
}
|
||||
|
||||
this._pushGroup();
|
||||
this._selectObject(new Path(this._svgPath));
|
||||
this._svgPath = null;
|
||||
}
|
||||
|
||||
deleteObject(objIdx: number) {
|
||||
const ret = this._deleteObject(objIdx);
|
||||
Helper.log("[gdi] deleteObject: objIdx=" + objIdx + (ret ? " deleted object" : "[invalid index]"));
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -46,7 +46,7 @@ export function loggingEnabled(enabled: boolean) {
|
||||
}
|
||||
|
||||
export class Helper {
|
||||
static GDI = {
|
||||
public static GDI = {
|
||||
FormatSignature: {
|
||||
ENHMETA_SIGNATURE: 0x464D4520,
|
||||
EPS_SIGNATURE: 0x46535045,
|
||||
@@ -328,27 +328,27 @@ export class Helper {
|
||||
},
|
||||
};
|
||||
|
||||
static _uniqueId = 0;
|
||||
public static _uniqueId = 0;
|
||||
|
||||
static log(message: string) {
|
||||
public static log(message: string) {
|
||||
if (isLoggingEnabled) {
|
||||
// tslint:disable-next-line:no-console
|
||||
console.log(message);
|
||||
}
|
||||
}
|
||||
|
||||
static _makeUniqueId(prefix: string) {
|
||||
public static _makeUniqueId(prefix: string) {
|
||||
return "EMFJS_" + prefix + (this._uniqueId++);
|
||||
}
|
||||
|
||||
static _writeUint32Val(uint8arr: Uint8Array, pos: number, val: number) {
|
||||
public static _writeUint32Val(uint8arr: Uint8Array, pos: number, val: number) {
|
||||
uint8arr[pos++] = val & 0xff;
|
||||
uint8arr[pos++] = (val >>> 8) & 0xff;
|
||||
uint8arr[pos++] = (val >>> 16) & 0xff;
|
||||
uint8arr[pos++] = (val >>> 24) & 0xff;
|
||||
}
|
||||
|
||||
static _blobToBinary(blob: Uint8Array) {
|
||||
public static _blobToBinary(blob: Uint8Array) {
|
||||
let ret = "";
|
||||
const len = blob.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
|
||||
+23
-23
@@ -29,8 +29,8 @@ import { Blob } from "./Blob";
|
||||
import { EMFJSError } from "./Helper";
|
||||
|
||||
export class PointS {
|
||||
x: number;
|
||||
y: number;
|
||||
public x: number;
|
||||
public y: number;
|
||||
|
||||
constructor(reader: Blob, x?: number, y?: number) {
|
||||
if (reader != null) {
|
||||
@@ -42,18 +42,18 @@ export class PointS {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new PointS(null, this.x, this.y);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{x: " + this.x + ", y: " + this.y + "}";
|
||||
}
|
||||
}
|
||||
|
||||
export class PointL {
|
||||
x: number;
|
||||
y: number;
|
||||
public x: number;
|
||||
public y: number;
|
||||
|
||||
constructor(reader: Blob, x?: number, y?: number) {
|
||||
if (reader != null) {
|
||||
@@ -65,20 +65,20 @@ export class PointL {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new PointL(null, this.x, this.y);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{x: " + this.x + ", y: " + this.y + "}";
|
||||
}
|
||||
}
|
||||
|
||||
export class RectL {
|
||||
left: number;
|
||||
top: number;
|
||||
right: number;
|
||||
bottom: number;
|
||||
public left: number;
|
||||
public top: number;
|
||||
public right: number;
|
||||
public bottom: number;
|
||||
|
||||
constructor(reader: Blob, left?: number, top?: number, right?: number, bottom?: number) {
|
||||
if (reader != null) {
|
||||
@@ -94,20 +94,20 @@ export class RectL {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new RectL(null, this.left, this.top, this.right, this.bottom);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{left: " + this.left + ", top: " + this.top + ", right: " + this.right
|
||||
+ ", bottom: " + this.bottom + "}";
|
||||
}
|
||||
|
||||
empty() {
|
||||
public empty() {
|
||||
return this.left >= this.right || this.top >= this.bottom;
|
||||
}
|
||||
|
||||
intersect(rectL: RectL) {
|
||||
public intersect(rectL: RectL) {
|
||||
if (this.empty() || rectL.empty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -121,8 +121,8 @@ export class RectL {
|
||||
}
|
||||
|
||||
export class SizeL {
|
||||
cx: number;
|
||||
cy: number;
|
||||
public cx: number;
|
||||
public cy: number;
|
||||
|
||||
constructor(reader: Blob, cx?: number, cy?: number) {
|
||||
if (reader != null) {
|
||||
@@ -134,27 +134,27 @@ export class SizeL {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new SizeL(null, this.cx, this.cy);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{cx: " + this.cx + ", cy: " + this.cy + "}";
|
||||
}
|
||||
}
|
||||
|
||||
export class Obj {
|
||||
type: string;
|
||||
public type: string;
|
||||
|
||||
constructor(type: string) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
clone(): Obj {
|
||||
public clone(): Obj {
|
||||
throw new EMFJSError("clone not implemented");
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
throw new EMFJSError("toString not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
+16
-16
@@ -30,9 +30,9 @@ import { EMFJSError, Helper } from "./Helper";
|
||||
import { Obj, RectL } from "./Primitives";
|
||||
|
||||
export class Region extends Obj {
|
||||
bounds: RectL;
|
||||
scans: Scan[];
|
||||
complexity: number;
|
||||
public bounds: RectL;
|
||||
public scans: Scan[];
|
||||
public complexity: number;
|
||||
|
||||
constructor(reader: Blob, copy?: Region) {
|
||||
super("region");
|
||||
@@ -79,18 +79,18 @@ export class Region extends Obj {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new Region(null, this);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
const _complexity = ["null", "simple", "complex"];
|
||||
return "{complexity: " + _complexity[this.complexity]
|
||||
+ " bounds: " + (this.bounds != null ? this.bounds.toString() : "[none]")
|
||||
+ " #scans: " + (this.scans != null ? this.scans.length : "[none]") + "}";
|
||||
}
|
||||
|
||||
_updateComplexity() {
|
||||
public _updateComplexity() {
|
||||
if (this.bounds == null) {
|
||||
this.complexity = 0;
|
||||
this.scans = null;
|
||||
@@ -115,7 +115,7 @@ export class Region extends Obj {
|
||||
}
|
||||
}
|
||||
|
||||
subtract(rect: RectL) {
|
||||
public subtract(rect: RectL) {
|
||||
Helper.log("[emf] Region " + this.toString() + " subtract " + rect.toString());
|
||||
|
||||
if (this.bounds != null) {
|
||||
@@ -242,7 +242,7 @@ export class Region extends Obj {
|
||||
Helper.log("[emf] Region subtraction -> " + this.toString());
|
||||
}
|
||||
|
||||
intersect(rect: RectL) {
|
||||
public intersect(rect: RectL) {
|
||||
Helper.log("[emf] Region " + this.toString() + " intersect with " + rect.toString());
|
||||
if (this.bounds != null) {
|
||||
this.bounds = this.bounds.intersect(rect);
|
||||
@@ -302,7 +302,7 @@ export class Region extends Obj {
|
||||
Helper.log("[emf] Region intersection -> " + this.toString());
|
||||
}
|
||||
|
||||
offset(offX: number, offY: number) {
|
||||
public offset(offX: number, offY: number) {
|
||||
if (this.bounds != null) {
|
||||
this.bounds.left += offX;
|
||||
this.bounds.top += offY;
|
||||
@@ -336,9 +336,9 @@ export function CreateSimpleRegion(left: number, top: number, right: number, bot
|
||||
}
|
||||
|
||||
export class Scan {
|
||||
top: number;
|
||||
bottom: number;
|
||||
scanlines: Array<{left: number, right: number}>;
|
||||
public top: number;
|
||||
public bottom: number;
|
||||
public scanlines: Array<{left: number, right: number}>;
|
||||
|
||||
constructor(r: RectL, copy?: Scan) {
|
||||
if (r != null) {
|
||||
@@ -356,15 +356,15 @@ export class Scan {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new Scan(null, this);
|
||||
}
|
||||
|
||||
append(r: RectL) {
|
||||
public append(r: RectL) {
|
||||
this.scanlines.push({left: r.left, right: r.right});
|
||||
}
|
||||
|
||||
subtract(left: number, right: number) {
|
||||
public subtract(left: number, right: number) {
|
||||
let i;
|
||||
|
||||
// Keep everything on the left side
|
||||
@@ -409,7 +409,7 @@ export class Scan {
|
||||
return this.scanlines.length > 0;
|
||||
}
|
||||
|
||||
intersect(left: number, right: number) {
|
||||
public intersect(left: number, right: number) {
|
||||
// Get rid of anything that falls entirely outside to the left
|
||||
for (let i = 0; i < this.scanlines.length; i++) {
|
||||
const scanline = this.scanlines[i];
|
||||
|
||||
+22
-22
@@ -30,7 +30,7 @@ import { EMFRecords } from "./EMFRecords";
|
||||
import { GDIContext } from "./GDIContext";
|
||||
import { EMFJSError, Helper } from "./Helper";
|
||||
|
||||
export class RendererSettings {
|
||||
export interface IRendererSettings {
|
||||
width: string;
|
||||
height: string;
|
||||
wExt: number;
|
||||
@@ -41,14 +41,28 @@ export class RendererSettings {
|
||||
}
|
||||
|
||||
export class Renderer {
|
||||
_img: EMF;
|
||||
private _img: EMF;
|
||||
|
||||
constructor(blob: ArrayBuffer) {
|
||||
this.parse(blob);
|
||||
Helper.log("EMFJS.Renderer instantiated");
|
||||
}
|
||||
|
||||
parse(blob: ArrayBuffer) {
|
||||
public render(info: IRendererSettings) {
|
||||
const img = ($("<div>") as any).svg({
|
||||
onLoad: (svg: any) => {
|
||||
return this._render(svg, info.mapMode, info.wExt, info.hExt, info.xExt, info.yExt);
|
||||
},
|
||||
settings: {
|
||||
viewBox: [0, 0, info.xExt, info.yExt].join(" "),
|
||||
preserveAspectRatio: "none", // TODO: MM_ISOTROPIC vs MM_ANISOTROPIC
|
||||
},
|
||||
});
|
||||
const svgContainer = ($(img[0]) as any).svg("get");
|
||||
return $(svgContainer.root()).attr("width", info.width).attr("height", info.height);
|
||||
}
|
||||
|
||||
private parse(blob: ArrayBuffer) {
|
||||
this._img = null;
|
||||
|
||||
const reader = new Blob(blob);
|
||||
@@ -69,7 +83,7 @@ export class Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
_render(svg: any, mapMode: number, w: number, h: number, xExt: number, yExt: number) {
|
||||
private _render(svg: any, mapMode: number, w: number, h: number, xExt: number, yExt: number) {
|
||||
const gdi = new GDIContext(svg);
|
||||
gdi.setWindowExtEx(w, h);
|
||||
gdi.setViewportExtEx(xExt, yExt);
|
||||
@@ -78,26 +92,12 @@ export class Renderer {
|
||||
this._img.render(gdi);
|
||||
Helper.log("[EMF] <--- DONE RENDERING");
|
||||
}
|
||||
|
||||
render(info: RendererSettings) {
|
||||
const img = ($("<div>") as any).svg({
|
||||
onLoad: (svg: any) => {
|
||||
return this._render(svg, info.mapMode, info.wExt, info.hExt, info.xExt, info.yExt);
|
||||
},
|
||||
settings: {
|
||||
viewBox: [0, 0, info.xExt, info.yExt].join(" "),
|
||||
preserveAspectRatio: "none", // TODO: MM_ISOTROPIC vs MM_ANISOTROPIC
|
||||
},
|
||||
});
|
||||
const svgContainer = ($(img[0]) as any).svg("get");
|
||||
return $(svgContainer.root()).attr("width", info.width).attr("height", info.height);
|
||||
}
|
||||
}
|
||||
|
||||
export class EMF {
|
||||
_reader: Blob;
|
||||
_hdrsize: number;
|
||||
_records: EMFRecords;
|
||||
private _reader: Blob;
|
||||
private _hdrsize: number;
|
||||
private _records: EMFRecords;
|
||||
|
||||
constructor(reader: Blob, hdrsize: number) {
|
||||
this._reader = reader;
|
||||
@@ -105,7 +105,7 @@ export class EMF {
|
||||
this._records = new EMFRecords(reader, this._hdrsize);
|
||||
}
|
||||
|
||||
render(gdi: GDIContext) {
|
||||
public render(gdi: GDIContext) {
|
||||
this._records.play(gdi);
|
||||
}
|
||||
}
|
||||
|
||||
+36
-36
@@ -31,9 +31,9 @@ import { Helper } from "./Helper";
|
||||
import { Obj, PointL } from "./Primitives";
|
||||
|
||||
export class ColorRef {
|
||||
r: number;
|
||||
g: number;
|
||||
b: number;
|
||||
public r: number;
|
||||
public g: number;
|
||||
public b: number;
|
||||
|
||||
constructor(reader: Blob, r?: number, g?: number, b?: number) {
|
||||
if (reader != null) {
|
||||
@@ -48,36 +48,36 @@ export class ColorRef {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new ColorRef(null, this.r, this.g, this.b);
|
||||
}
|
||||
|
||||
toHex() {
|
||||
public toHex() {
|
||||
const rgb = (this.r << 16) | (this.g << 8) | this.b;
|
||||
return (0x1000000 + rgb).toString(16).slice(1);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{r: " + this.r + ", g: " + this.g + ", b: " + this.b + "}";
|
||||
}
|
||||
}
|
||||
|
||||
export class Font extends Obj {
|
||||
height: number;
|
||||
width: number;
|
||||
escapement: number;
|
||||
orientation: number;
|
||||
weight: number;
|
||||
italic: number;
|
||||
underline: number;
|
||||
strikeout: number;
|
||||
charset: number;
|
||||
outprecision: number;
|
||||
clipprecision: number;
|
||||
quality: number;
|
||||
pitch: number;
|
||||
family: number;
|
||||
facename: string;
|
||||
public height: number;
|
||||
public width: number;
|
||||
public escapement: number;
|
||||
public orientation: number;
|
||||
public weight: number;
|
||||
public italic: number;
|
||||
public underline: number;
|
||||
public strikeout: number;
|
||||
public charset: number;
|
||||
public outprecision: number;
|
||||
public clipprecision: number;
|
||||
public quality: number;
|
||||
public pitch: number;
|
||||
public family: number;
|
||||
public facename: string;
|
||||
|
||||
constructor(reader: Blob, copy: Font | number) {
|
||||
super("font");
|
||||
@@ -138,21 +138,21 @@ export class Font extends Obj {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new Font(null, this);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
}
|
||||
|
||||
export class Brush extends Obj {
|
||||
style: number;
|
||||
color: ColorRef;
|
||||
pattern: DIBitmap;
|
||||
dibpatternpt: DIBitmap;
|
||||
hatchstyle: number;
|
||||
public style: number;
|
||||
public color: ColorRef;
|
||||
public pattern: DIBitmap;
|
||||
public dibpatternpt: DIBitmap;
|
||||
public hatchstyle: number;
|
||||
|
||||
constructor(reader: Blob, copy?: {style?: number, color?: ColorRef, pattern?: DIBitmap,
|
||||
dibpatternpt?: DIBitmap, hatchstyle?: number}) {
|
||||
@@ -198,11 +198,11 @@ export class Brush extends Obj {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new Brush(null, this);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
let ret = "{style: " + this.style;
|
||||
switch (this.style) {
|
||||
case Helper.GDI.BrushStyle.BS_SOLID:
|
||||
@@ -217,10 +217,10 @@ export class Brush extends Obj {
|
||||
}
|
||||
|
||||
export class Pen extends Obj {
|
||||
style: number | {header: {off: number, size: number}, data: {off: number, size: number}};
|
||||
width: number;
|
||||
brush: Brush;
|
||||
color: ColorRef;
|
||||
public style: number | {header: {off: number, size: number}, data: {off: number, size: number}};
|
||||
public width: number;
|
||||
public brush: Brush;
|
||||
public color: ColorRef;
|
||||
|
||||
constructor(reader: Blob, style?: number | {header: {off: number, size: number}, data: {off: number, size: number}},
|
||||
width?: number, color?: ColorRef, brush?: Brush) {
|
||||
@@ -253,12 +253,12 @@ export class Pen extends Obj {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new Pen(null, this.style, this.width, this.color != null ? this.color.clone() : null,
|
||||
this.brush != null ? this.brush.clone() : null);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{style: " + this.style + ", width: " + this.width
|
||||
+ ", color: " + (this.color != null ? this.color.toString() : "none") + "}";
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@ export interface ISettings {
|
||||
width?: number, height?: number}) => void): void;
|
||||
}
|
||||
export class Document {
|
||||
_settings: ISettings;
|
||||
_meta: {[key: string]: any};
|
||||
_fonts: FonttblDestinationSub[];
|
||||
_colors: IColor[];
|
||||
_autoColor: number;
|
||||
_stylesheets: Array<{index: number, name: string}>;
|
||||
_ins: Array<string | ((this: Renderer) => void)>;
|
||||
public _settings: ISettings;
|
||||
public _meta: {[key: string]: any};
|
||||
public _fonts: FonttblDestinationSub[];
|
||||
public _colors: IColor[];
|
||||
public _autoColor: number;
|
||||
public _stylesheets: Array<{index: number, name: string}>;
|
||||
public _ins: Array<string | ((this: Renderer) => void)>;
|
||||
|
||||
constructor(settings: ISettings) {
|
||||
this._settings = settings || {};
|
||||
@@ -53,7 +53,7 @@ export class Document {
|
||||
this._ins = [];
|
||||
}
|
||||
|
||||
_lookupColor(idx: number) {
|
||||
public _lookupColor(idx: number) {
|
||||
if (idx === 0) {
|
||||
if (this._autoColor == null) {
|
||||
return null;
|
||||
@@ -66,7 +66,7 @@ export class Document {
|
||||
return this._colors[idx];
|
||||
}
|
||||
|
||||
addIns(ins: string | ((this: Renderer) => void)) {
|
||||
public addIns(ins: string | ((this: Renderer) => void)) {
|
||||
this._ins.push(ins);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ import { Parser } from "./parser/Parser";
|
||||
import { Renderer } from "./Renderer";
|
||||
|
||||
export class DocumentFacade {
|
||||
_document: Document;
|
||||
_renderer: Renderer;
|
||||
_parsed: Promise<void>;
|
||||
private _document: Document;
|
||||
private _renderer: Renderer;
|
||||
private _parsed: Promise<void>;
|
||||
|
||||
constructor(blob: ArrayBuffer, settings: ISettings) {
|
||||
this._document = new Document(settings);
|
||||
@@ -41,11 +41,11 @@ export class DocumentFacade {
|
||||
this._parsed = parser.parse();
|
||||
}
|
||||
|
||||
metadata() {
|
||||
public metadata() {
|
||||
return this._document._meta;
|
||||
}
|
||||
|
||||
render(): Promise<JQuery[]> {
|
||||
public render(): Promise<JQuery[]> {
|
||||
return this._parsed
|
||||
.then(() => {
|
||||
return this._renderer.buildDom();
|
||||
|
||||
+125
-125
@@ -47,36 +47,27 @@ export function loggingEnabled(enabled: boolean) {
|
||||
}
|
||||
|
||||
export class Helper {
|
||||
static _A = "A".charCodeAt(0);
|
||||
static _a = "a".charCodeAt(0);
|
||||
static _F = "F".charCodeAt(0);
|
||||
static _f = "f".charCodeAt(0);
|
||||
static _Z = "Z".charCodeAt(0);
|
||||
static _z = "z".charCodeAt(0);
|
||||
static _0 = "0".charCodeAt(0);
|
||||
static _9 = "9".charCodeAt(0);
|
||||
|
||||
static JUSTIFICATION = {
|
||||
public static JUSTIFICATION = {
|
||||
LEFT: "left",
|
||||
CENTER: "center",
|
||||
RIGHT: "right",
|
||||
JUSTIFY: "justify",
|
||||
};
|
||||
static BREAKTYPE = {
|
||||
public static BREAKTYPE = {
|
||||
NONE: "none",
|
||||
COL: "col", // TODO: ???
|
||||
EVEN: "even",
|
||||
ODD: "odd",
|
||||
PAGE: "page",
|
||||
};
|
||||
static PAGENUMBER = {
|
||||
public static PAGENUMBER = {
|
||||
DECIMAL: "decimal",
|
||||
UROM: "urom", // TODO: ???
|
||||
LROM: "lrom", // TODO: ???
|
||||
ULTR: "ultr", // TODO: ???
|
||||
LLTR: "lltr", // TODO: ???
|
||||
};
|
||||
static UNDERLINE = {
|
||||
public static UNDERLINE = {
|
||||
NONE: "none",
|
||||
CONTINUOUS: "continuous",
|
||||
DOTTED: "dotted",
|
||||
@@ -96,18 +87,135 @@ export class Helper {
|
||||
WORD: "word",
|
||||
WAVE: "wave",
|
||||
};
|
||||
static FONTPITCH = {
|
||||
public static FONTPITCH = {
|
||||
DEFAULT: 0,
|
||||
FIXED: 1,
|
||||
VARIABLE: 2,
|
||||
};
|
||||
static CHARACTER_TYPE = {
|
||||
public static CHARACTER_TYPE = {
|
||||
LOWANSI: "loch",
|
||||
HIGHANSI: "hich",
|
||||
DOUBLE: "dbch",
|
||||
};
|
||||
|
||||
static _charsetMap: {[key: string]: number} = {
|
||||
public static log(message: string) {
|
||||
if (isLoggingEnabled) {
|
||||
// tslint:disable-next-line:no-console
|
||||
console.log(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static _isalpha(str: string): boolean {
|
||||
const len = str.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const ch = str.charCodeAt(i);
|
||||
if (!((ch >= this._A && ch <= this._Z) ||
|
||||
(ch >= this._a && ch <= this._z))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return len > 0;
|
||||
}
|
||||
|
||||
public static _isdigit(str: string): boolean {
|
||||
const len = str.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const ch = str.charCodeAt(i);
|
||||
if (ch < this._0 || ch > this._9) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return len > 0;
|
||||
}
|
||||
|
||||
public static _parseHex(str: string): number {
|
||||
const len = str.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const ch = str.charCodeAt(i);
|
||||
if (!((ch >= this._0 && ch <= this._9) ||
|
||||
(ch >= this._a && ch <= this._f) ||
|
||||
(ch >= this._A && ch <= this._F))) {
|
||||
return NaN;
|
||||
}
|
||||
}
|
||||
if (len > 0) {
|
||||
return parseInt(str, 16);
|
||||
}
|
||||
return NaN;
|
||||
}
|
||||
|
||||
public static _blobToBinary(blob: ArrayBuffer): string {
|
||||
const view = new Uint8Array(blob);
|
||||
let ret = "";
|
||||
const len = view.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
ret += String.fromCharCode(view[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static _hexToBlob(str: string): ArrayBuffer {
|
||||
let len = str.length;
|
||||
const buf = new ArrayBuffer(Math.floor(len-- / 2));
|
||||
const view = new Uint8Array(buf);
|
||||
let d = 0;
|
||||
for (let i = 0; i < len; i += 2) {
|
||||
const val = this._parseHex(str.substr(i, 2));
|
||||
if (isNaN(val)) {
|
||||
return null;
|
||||
}
|
||||
view[d++] = val;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
public static _hexToBinary(str: string): string {
|
||||
let bin = "";
|
||||
const len = str.length - 1;
|
||||
for (let i = 0; i < len; i += 2) {
|
||||
const val = this._parseHex(str.substr(i, 2));
|
||||
if (isNaN(val)) {
|
||||
return null;
|
||||
}
|
||||
bin += String.fromCharCode(val);
|
||||
}
|
||||
return bin;
|
||||
}
|
||||
|
||||
public static _mapCharset(idx: number): number {
|
||||
return this._charsetMap[idx.toString()];
|
||||
}
|
||||
|
||||
public static _mapColorTheme(name: string) {
|
||||
return this._colorThemeMap[name];
|
||||
}
|
||||
|
||||
public static _colorToStr(color: IColor) {
|
||||
return "rgb(" + color.r + "," + color.g + "," + color.b + ")";
|
||||
}
|
||||
|
||||
public static _twipsToPt(twips: number) {
|
||||
return Math.floor(twips / 20);
|
||||
}
|
||||
|
||||
public static _twipsToPx(twips: number) {
|
||||
return Math.floor(twips / 20 * 96 / 72);
|
||||
}
|
||||
|
||||
public static _pxToTwips(px: number) {
|
||||
return Math.floor(px * 20 * 72 / 96);
|
||||
}
|
||||
|
||||
private static _A = "A".charCodeAt(0);
|
||||
private static _a = "a".charCodeAt(0);
|
||||
private static _F = "F".charCodeAt(0);
|
||||
private static _f = "f".charCodeAt(0);
|
||||
private static _Z = "Z".charCodeAt(0);
|
||||
private static _z = "z".charCodeAt(0);
|
||||
private static _0 = "0".charCodeAt(0);
|
||||
private static _9 = "9".charCodeAt(0);
|
||||
|
||||
private static _charsetMap: {[key: string]: number} = {
|
||||
0: 1252, // ANSI_CHARSET
|
||||
77: 10000, // Mac Roman
|
||||
78: 10001, // Mac Shift Jis
|
||||
@@ -139,7 +247,7 @@ export class Helper {
|
||||
255: 850, // OEM
|
||||
};
|
||||
|
||||
static _colorThemeMap: {[key: string]: null} = {
|
||||
private static _colorThemeMap: {[key: string]: null} = {
|
||||
// TODO
|
||||
maindarkone: null,
|
||||
mainlightone: null,
|
||||
@@ -158,112 +266,4 @@ export class Helper {
|
||||
backgroundtwo: null,
|
||||
texttwo: null,
|
||||
};
|
||||
|
||||
static log(message: string) {
|
||||
if (isLoggingEnabled) {
|
||||
// tslint:disable-next-line:no-console
|
||||
console.log(message);
|
||||
}
|
||||
}
|
||||
|
||||
static _isalpha(str: string): boolean {
|
||||
const len = str.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const ch = str.charCodeAt(i);
|
||||
if (!((ch >= this._A && ch <= this._Z) ||
|
||||
(ch >= this._a && ch <= this._z))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return len > 0;
|
||||
}
|
||||
|
||||
static _isdigit(str: string): boolean {
|
||||
const len = str.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const ch = str.charCodeAt(i);
|
||||
if (ch < this._0 || ch > this._9) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return len > 0;
|
||||
}
|
||||
|
||||
static _parseHex(str: string): number {
|
||||
const len = str.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const ch = str.charCodeAt(i);
|
||||
if (!((ch >= this._0 && ch <= this._9) ||
|
||||
(ch >= this._a && ch <= this._f) ||
|
||||
(ch >= this._A && ch <= this._F))) {
|
||||
return NaN;
|
||||
}
|
||||
}
|
||||
if (len > 0) {
|
||||
return parseInt(str, 16);
|
||||
}
|
||||
return NaN;
|
||||
}
|
||||
|
||||
static _blobToBinary(blob: ArrayBuffer): string {
|
||||
const view = new Uint8Array(blob);
|
||||
let ret = "";
|
||||
const len = view.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
ret += String.fromCharCode(view[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static _hexToBlob(str: string): ArrayBuffer {
|
||||
let len = str.length;
|
||||
const buf = new ArrayBuffer(Math.floor(len-- / 2));
|
||||
const view = new Uint8Array(buf);
|
||||
let d = 0;
|
||||
for (let i = 0; i < len; i += 2) {
|
||||
const val = this._parseHex(str.substr(i, 2));
|
||||
if (isNaN(val)) {
|
||||
return null;
|
||||
}
|
||||
view[d++] = val;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static _hexToBinary(str: string): string {
|
||||
let bin = "";
|
||||
const len = str.length - 1;
|
||||
for (let i = 0; i < len; i += 2) {
|
||||
const val = this._parseHex(str.substr(i, 2));
|
||||
if (isNaN(val)) {
|
||||
return null;
|
||||
}
|
||||
bin += String.fromCharCode(val);
|
||||
}
|
||||
return bin;
|
||||
}
|
||||
|
||||
static _mapCharset(idx: number): number {
|
||||
return this._charsetMap[idx.toString()];
|
||||
}
|
||||
|
||||
static _mapColorTheme(name: string) {
|
||||
return this._colorThemeMap[name];
|
||||
}
|
||||
|
||||
static _colorToStr(color: IColor) {
|
||||
return "rgb(" + color.r + "," + color.g + "," + color.b + ")";
|
||||
}
|
||||
|
||||
static _twipsToPt(twips: number) {
|
||||
return Math.floor(twips / 20);
|
||||
}
|
||||
|
||||
static _twipsToPx(twips: number) {
|
||||
return Math.floor(twips / 20 * 96 / 72);
|
||||
}
|
||||
|
||||
static _pxToTwips(px: number) {
|
||||
return Math.floor(px * 20 * 72 / 96);
|
||||
}
|
||||
}
|
||||
|
||||
+21
-21
@@ -35,14 +35,14 @@ export interface IContainerElement {
|
||||
}
|
||||
|
||||
export class Renderer {
|
||||
_doc: Document;
|
||||
_dom: JQuery[];
|
||||
public _doc: Document;
|
||||
private _dom: JQuery[];
|
||||
|
||||
_curRChp: RenderChp;
|
||||
_curRPap: RenderPap;
|
||||
_curpar: JQuery;
|
||||
_cursubpar: JQuery;
|
||||
_curcont: IContainerElement[];
|
||||
private _curRChp: RenderChp;
|
||||
private _curRPap: RenderPap;
|
||||
private _curpar: JQuery;
|
||||
private _cursubpar: JQuery;
|
||||
private _curcont: IContainerElement[];
|
||||
|
||||
constructor(doc: Document) {
|
||||
this._doc = doc;
|
||||
@@ -55,7 +55,7 @@ export class Renderer {
|
||||
this._curcont = [];
|
||||
}
|
||||
|
||||
pushContainer(contel: IContainerElement) {
|
||||
public pushContainer(contel: IContainerElement) {
|
||||
if (this._curpar == null) {
|
||||
this.startPar();
|
||||
}
|
||||
@@ -73,18 +73,18 @@ export class Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
popContainer() {
|
||||
public popContainer() {
|
||||
const contel = this._curcont.pop();
|
||||
if (contel == null) {
|
||||
throw new RTFJSError("No container on rendering stack");
|
||||
}
|
||||
}
|
||||
|
||||
buildHyperlinkElement(url: string): JQuery {
|
||||
public buildHyperlinkElement(url: string): JQuery {
|
||||
return $("<a>").attr("href", url);
|
||||
}
|
||||
|
||||
_appendToPar(el: JQuery, newsubpar?: boolean) {
|
||||
public _appendToPar(el: JQuery, newsubpar?: boolean) {
|
||||
if (this._curpar == null) {
|
||||
this.startPar();
|
||||
}
|
||||
@@ -116,7 +116,7 @@ export class Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
startPar() {
|
||||
public startPar() {
|
||||
this._curpar = $("<div>");
|
||||
if (this._curRPap != null) {
|
||||
this._curRPap.apply(this._doc, this._curpar, this._curRChp, true);
|
||||
@@ -127,15 +127,15 @@ export class Renderer {
|
||||
this._dom.push(this._curpar);
|
||||
}
|
||||
|
||||
lineBreak() {
|
||||
public lineBreak() {
|
||||
this._appendToPar(null, true);
|
||||
}
|
||||
|
||||
setChp(rchp: RenderChp) {
|
||||
public setChp(rchp: RenderChp) {
|
||||
this._curRChp = rchp;
|
||||
}
|
||||
|
||||
setPap(rpap: RenderPap) {
|
||||
public setPap(rpap: RenderPap) {
|
||||
this._curRPap = rpap;
|
||||
if (this._cursubpar != null) {
|
||||
this._curRPap.apply(this._doc, this._cursubpar, null, false);
|
||||
@@ -146,22 +146,22 @@ export class Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
appendElement(element: JQuery) {
|
||||
public appendElement(element: JQuery) {
|
||||
this._appendToPar(element);
|
||||
}
|
||||
|
||||
buildRenderedPicture(element: JQuery): JQuery {
|
||||
public buildRenderedPicture(element: JQuery): JQuery {
|
||||
if (element == null) {
|
||||
element = $("<span>").text("[failed to render image]");
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
renderedPicture(element: JQuery) {
|
||||
public renderedPicture(element: JQuery) {
|
||||
this._appendToPar(this.buildRenderedPicture(element));
|
||||
}
|
||||
|
||||
buildPicture(mime: string, data: string): JQuery {
|
||||
public buildPicture(mime: string, data: string): JQuery {
|
||||
if (data != null) {
|
||||
return $("<img>", {
|
||||
src: "data:" + mime + ";base64," + btoa(data),
|
||||
@@ -175,11 +175,11 @@ export class Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
picture(mime: string, data: string) {
|
||||
public picture(mime: string, data: string) {
|
||||
this._appendToPar(this.buildPicture(mime, data));
|
||||
}
|
||||
|
||||
buildDom(): JQuery[] {
|
||||
public buildDom(): JQuery[] {
|
||||
if (this._dom != null) {
|
||||
return this._dom;
|
||||
}
|
||||
|
||||
@@ -29,14 +29,14 @@ import { Renderer } from "../Renderer";
|
||||
import { IDestination } from "./Destinations";
|
||||
|
||||
export class Chp {
|
||||
bold: boolean;
|
||||
underline: string;
|
||||
italic: boolean;
|
||||
strikethrough: boolean;
|
||||
dblstrikethrough: boolean;
|
||||
colorindex: number;
|
||||
fontsize: number;
|
||||
fontfamily: number;
|
||||
public bold: boolean;
|
||||
public underline: string;
|
||||
public italic: boolean;
|
||||
public strikethrough: boolean;
|
||||
public dblstrikethrough: boolean;
|
||||
public colorindex: number;
|
||||
public fontsize: number;
|
||||
public fontfamily: number;
|
||||
|
||||
constructor(parent: Chp) {
|
||||
if (parent != null) {
|
||||
@@ -61,11 +61,11 @@ export class Chp {
|
||||
}
|
||||
|
||||
export class Pap {
|
||||
indent: {left: number, right: number, firstline: number};
|
||||
justification: string;
|
||||
spacebefore: number;
|
||||
spaceafter: number;
|
||||
charactertype: string;
|
||||
public indent: {left: number, right: number, firstline: number};
|
||||
public justification: string;
|
||||
public spacebefore: number;
|
||||
public spaceafter: number;
|
||||
public charactertype: string;
|
||||
|
||||
constructor(parent: Pap) {
|
||||
if (parent != null) {
|
||||
@@ -92,10 +92,10 @@ export class Pap {
|
||||
}
|
||||
|
||||
export class Sep {
|
||||
columns: number;
|
||||
breaktype: string;
|
||||
pagenumber: {x: number, y: number};
|
||||
pagenumberformat: string;
|
||||
public columns: number;
|
||||
public breaktype: string;
|
||||
public pagenumber: {x: number, y: number};
|
||||
public pagenumberformat: string;
|
||||
|
||||
constructor(parent: Sep) {
|
||||
if (parent != null) {
|
||||
@@ -119,12 +119,12 @@ export class Sep {
|
||||
}
|
||||
|
||||
export class Dop {
|
||||
width: number;
|
||||
height: number;
|
||||
margin: {left: number, top: number, right: number, bottom: number};
|
||||
pagenumberstart: number;
|
||||
facingpages: boolean;
|
||||
landscape: boolean;
|
||||
public width: number;
|
||||
public height: number;
|
||||
public margin: {left: number, top: number, right: number, bottom: number};
|
||||
public pagenumberstart: number;
|
||||
public facingpages: boolean;
|
||||
public landscape: boolean;
|
||||
|
||||
constructor(parent: Dop) {
|
||||
if (parent != null) {
|
||||
@@ -156,18 +156,18 @@ export class Dop {
|
||||
}
|
||||
|
||||
export class State {
|
||||
parent: State;
|
||||
first: boolean;
|
||||
skipchars: number;
|
||||
bindata: number;
|
||||
chp: Chp;
|
||||
pap: Pap;
|
||||
sep: Sep;
|
||||
dop: Dop;
|
||||
destination: IDestination;
|
||||
skipunknowndestination: boolean;
|
||||
skipdestination: boolean;
|
||||
ucn: number;
|
||||
public parent: State;
|
||||
public first: boolean;
|
||||
public skipchars: number;
|
||||
public bindata: number;
|
||||
public chp: Chp;
|
||||
public pap: Pap;
|
||||
public sep: Sep;
|
||||
public dop: Dop;
|
||||
public destination: IDestination;
|
||||
public skipunknowndestination: boolean;
|
||||
public skipdestination: boolean;
|
||||
public ucn: number;
|
||||
[key: string]: any;
|
||||
|
||||
constructor(parent: State) {
|
||||
@@ -198,16 +198,16 @@ export class State {
|
||||
}
|
||||
|
||||
export class GlobalState {
|
||||
data: Uint8Array;
|
||||
pos: number;
|
||||
line: number;
|
||||
column: number;
|
||||
state: State;
|
||||
version: number;
|
||||
text: string;
|
||||
codepage: number;
|
||||
_asyncTasks: Array<Promise<any>>;
|
||||
renderer: Renderer;
|
||||
public data: Uint8Array;
|
||||
public pos: number;
|
||||
public line: number;
|
||||
public column: number;
|
||||
public state: State;
|
||||
public version: number;
|
||||
public text: string;
|
||||
public codepage: number;
|
||||
public _asyncTasks: Array<Promise<any>>;
|
||||
public renderer: Renderer;
|
||||
|
||||
constructor(blob: ArrayBuffer, renderer: Renderer) {
|
||||
this.data = new Uint8Array(blob);
|
||||
|
||||
+190
-189
@@ -34,9 +34,9 @@ import { RenderChp } from "./RenderChp";
|
||||
import { RenderPap } from "./RenderPap";
|
||||
|
||||
export abstract class DestinationFactory<T extends IDestination> {
|
||||
class: { new (parser: GlobalState, inst: Document, name: string, param: number): T; };
|
||||
public class: { new (parser: GlobalState, inst: Document, name: string, param: number): T; };
|
||||
|
||||
newDestination(parser: GlobalState, inst: Document, name: string, param: number): T {
|
||||
public newDestination(parser: GlobalState, inst: Document, name: string, param: number): T {
|
||||
return new this.class(parser, inst, name, param);
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ const findParentDestination = (parser: GlobalState, dest: string) => {
|
||||
};
|
||||
|
||||
export class DestinationBase implements IDestination {
|
||||
_name: string;
|
||||
public _name: string;
|
||||
|
||||
constructor(name: string) {
|
||||
this._name = name;
|
||||
@@ -75,23 +75,23 @@ export class DestinationBase implements IDestination {
|
||||
}
|
||||
|
||||
export class DestinationTextBase implements IDestination {
|
||||
_name: string;
|
||||
text: string;
|
||||
public _name: string;
|
||||
public text: string;
|
||||
|
||||
constructor(name: string) {
|
||||
this._name = name;
|
||||
this.text = "";
|
||||
}
|
||||
|
||||
appendText(text: string) {
|
||||
public appendText(text: string) {
|
||||
this.text += text;
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class DestinationFormattedTextBase implements IDestination {
|
||||
parser: GlobalState;
|
||||
_name: string;
|
||||
_records: Array<(rtf: RtfDestination) => void>;
|
||||
public _name: string;
|
||||
protected parser: GlobalState;
|
||||
private _records: Array<(rtf: RtfDestination) => void>;
|
||||
|
||||
constructor(parser: GlobalState, name: string) {
|
||||
this.parser = parser;
|
||||
@@ -99,19 +99,19 @@ export abstract class DestinationFormattedTextBase implements IDestination {
|
||||
this._records = [];
|
||||
}
|
||||
|
||||
appendText(text: string) {
|
||||
public appendText(text: string) {
|
||||
this._records.push((rtf: RtfDestination) => {
|
||||
rtf.appendText(text);
|
||||
});
|
||||
}
|
||||
|
||||
handleKeyword(keyword: string, param: number) {
|
||||
public handleKeyword(keyword: string, param: number) {
|
||||
this._records.push((rtf: RtfDestination) => {
|
||||
return rtf.handleKeyword(keyword, param);
|
||||
});
|
||||
}
|
||||
|
||||
apply() {
|
||||
public apply() {
|
||||
const rtf = findParentDestination(this.parser, "rtf") as any as RtfDestination;
|
||||
if (rtf == null) {
|
||||
throw new RTFJSError("IDestination " + this._name + " is not child of rtf destination");
|
||||
@@ -134,16 +134,16 @@ export abstract class DestinationFormattedTextBase implements IDestination {
|
||||
delete this._records;
|
||||
}
|
||||
|
||||
abstract renderBegin(rtf: RtfDestination, records: number): boolean;
|
||||
public abstract renderBegin(rtf: RtfDestination, records: number): boolean;
|
||||
|
||||
abstract renderEnd(rtf: RtfDestination, records: number): void;
|
||||
public abstract renderEnd(rtf: RtfDestination, records: number): void;
|
||||
}
|
||||
|
||||
export class RtfDestination extends DestinationBase {
|
||||
_metadata: {[key: string]: any};
|
||||
parser: GlobalState;
|
||||
inst: Document;
|
||||
_charFormatHandlers: {[key: string]: (param: number) => void} = {
|
||||
private _metadata: {[key: string]: any};
|
||||
private parser: GlobalState;
|
||||
private inst: Document;
|
||||
private _charFormatHandlers: {[key: string]: (param: number) => void} = {
|
||||
ansicpg: (param: number) => {
|
||||
// if the value is 0, use the default charset as 0 is not valid
|
||||
if (param > 0) {
|
||||
@@ -248,26 +248,47 @@ export class RtfDestination extends DestinationBase {
|
||||
this.inst = inst;
|
||||
}
|
||||
|
||||
addIns(func: (this: Renderer) => void) {
|
||||
public addIns(func: (this: Renderer) => void) {
|
||||
this.inst.addIns(func);
|
||||
}
|
||||
|
||||
appendText(text: string) {
|
||||
public appendText(text: string) {
|
||||
Helper.log("[rtf] output: " + text);
|
||||
this.inst.addIns(text);
|
||||
}
|
||||
|
||||
sub() {
|
||||
public sub() {
|
||||
Helper.log("[rtf].sub()");
|
||||
}
|
||||
|
||||
_addInsHandler(func: (this: Renderer) => void) {
|
||||
public handleKeyword(keyword: string, param: number) {
|
||||
const handler = this._charFormatHandlers[keyword];
|
||||
if (handler != null) {
|
||||
handler(param);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public apply() {
|
||||
Helper.log("[rtf] apply()");
|
||||
for (const prop in this._metadata) {
|
||||
this.inst._meta[prop] = this._metadata[prop];
|
||||
}
|
||||
delete this._metadata;
|
||||
}
|
||||
|
||||
public setMetadata(prop: string, val: any) {
|
||||
this._metadata[prop] = val;
|
||||
}
|
||||
|
||||
private _addInsHandler(func: (this: Renderer) => void) {
|
||||
return (param: number) => {
|
||||
this.inst.addIns(func);
|
||||
};
|
||||
}
|
||||
|
||||
_addFormatIns(ptype: string, props: Chp | Pap) {
|
||||
private _addFormatIns(ptype: string, props: Chp | Pap) {
|
||||
switch (ptype) {
|
||||
case "chp":
|
||||
const rchp = new RenderChp(new Chp(props as Chp));
|
||||
@@ -284,7 +305,7 @@ export class RtfDestination extends DestinationBase {
|
||||
}
|
||||
}
|
||||
|
||||
_genericFormatSetNoParam(ptype: string, prop: string, val: any) {
|
||||
private _genericFormatSetNoParam(ptype: string, prop: string, val: any) {
|
||||
return (param: number) => {
|
||||
const props = this.parser.state[ptype];
|
||||
props[prop] = val;
|
||||
@@ -293,7 +314,7 @@ export class RtfDestination extends DestinationBase {
|
||||
};
|
||||
}
|
||||
|
||||
_genericFormatOnOff(ptype: string, prop: string, onval?: string, offval?: string) {
|
||||
private _genericFormatOnOff(ptype: string, prop: string, onval?: string, offval?: string) {
|
||||
return (param: number) => {
|
||||
const props = this.parser.state[ptype];
|
||||
props[prop] = (param == null || param !== 0)
|
||||
@@ -302,7 +323,7 @@ export class RtfDestination extends DestinationBase {
|
||||
this._addFormatIns(ptype, props);
|
||||
};
|
||||
}
|
||||
_genericFormatSetVal(ptype: string, prop: string, defaultval: number) {
|
||||
private _genericFormatSetVal(ptype: string, prop: string, defaultval: number) {
|
||||
return (param: number) => {
|
||||
const props = this.parser.state[ptype];
|
||||
props[prop] = (param == null) ? defaultval : param;
|
||||
@@ -310,7 +331,7 @@ export class RtfDestination extends DestinationBase {
|
||||
this._addFormatIns(ptype, props);
|
||||
};
|
||||
}
|
||||
_genericFormatSetValRequired(ptype: string, prop: string) {
|
||||
private _genericFormatSetValRequired(ptype: string, prop: string) {
|
||||
return (param: number) => {
|
||||
if (param == null) {
|
||||
throw new RTFJSError("Keyword without required param");
|
||||
@@ -321,7 +342,7 @@ export class RtfDestination extends DestinationBase {
|
||||
this._addFormatIns(ptype, props);
|
||||
};
|
||||
}
|
||||
_genericFormatSetMemberVal(ptype: string, prop: string, member: string, defaultval: number) {
|
||||
private _genericFormatSetMemberVal(ptype: string, prop: string, member: string, defaultval: number) {
|
||||
return (param: number) => {
|
||||
const props = this.parser.state[ptype];
|
||||
const members = props[prop];
|
||||
@@ -330,48 +351,28 @@ export class RtfDestination extends DestinationBase {
|
||||
this._addFormatIns(ptype, props);
|
||||
};
|
||||
}
|
||||
|
||||
handleKeyword(keyword: string, param: number) {
|
||||
const handler = this._charFormatHandlers[keyword];
|
||||
if (handler != null) {
|
||||
handler(param);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
apply() {
|
||||
Helper.log("[rtf] apply()");
|
||||
for (const prop in this._metadata) {
|
||||
this.inst._meta[prop] = this._metadata[prop];
|
||||
}
|
||||
delete this._metadata;
|
||||
}
|
||||
setMetadata(prop: string, val: any) {
|
||||
this._metadata[prop] = val;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IGenericPropertyDestination extends IDestination {
|
||||
apply(): void;
|
||||
}
|
||||
export class GenericPropertyDestinationFactory extends DestinationFactory<IGenericPropertyDestination> {
|
||||
parentdest: string;
|
||||
metaprop: string;
|
||||
private parentdest: string;
|
||||
private metaprop: string;
|
||||
|
||||
constructor(parentdest: string, metaprop: string) {
|
||||
super();
|
||||
this.parentdest = parentdest;
|
||||
this.metaprop = metaprop;
|
||||
this.class = class extends DestinationTextBase implements IGenericPropertyDestination {
|
||||
parser: GlobalState;
|
||||
private parser: GlobalState;
|
||||
|
||||
constructor(parser: GlobalState, inst: Document, name: string) {
|
||||
super(name);
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
apply() {
|
||||
public apply() {
|
||||
const dest = findParentDestination(this.parser, parentdest);
|
||||
if (dest == null) {
|
||||
throw new RTFJSError("IDestination " + this._name + " must be within "
|
||||
@@ -387,8 +388,8 @@ export class GenericPropertyDestinationFactory extends DestinationFactory<IGener
|
||||
}
|
||||
|
||||
export class InfoDestination extends DestinationBase {
|
||||
_metadata: {[key: string]: any};
|
||||
inst: Document;
|
||||
private _metadata: {[key: string]: any};
|
||||
private inst: Document;
|
||||
|
||||
constructor(parser: GlobalState, inst: Document, name: string) {
|
||||
super(name);
|
||||
@@ -396,14 +397,14 @@ export class InfoDestination extends DestinationBase {
|
||||
this.inst = inst;
|
||||
}
|
||||
|
||||
apply() {
|
||||
public apply() {
|
||||
for (const prop in this._metadata) {
|
||||
this.inst._meta[prop] = this._metadata[prop];
|
||||
}
|
||||
delete this._metadata;
|
||||
}
|
||||
|
||||
setMetadata(prop: string, val: any) {
|
||||
public setMetadata(prop: string, val: any) {
|
||||
this._metadata[prop] = val;
|
||||
}
|
||||
}
|
||||
@@ -412,20 +413,20 @@ export interface IMetaPropertyDestination extends IDestination {
|
||||
apply(): void;
|
||||
}
|
||||
export class MetaPropertyDestinationFactory extends DestinationFactory<IMetaPropertyDestination> {
|
||||
metaprop: string;
|
||||
private metaprop: string;
|
||||
|
||||
constructor(metaprop: string) {
|
||||
super();
|
||||
this.metaprop = metaprop;
|
||||
this.class = class extends DestinationTextBase implements IMetaPropertyDestination {
|
||||
parser: GlobalState;
|
||||
private parser: GlobalState;
|
||||
|
||||
constructor(parser: GlobalState, inst: Document, name: string) {
|
||||
super(name);
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
apply() {
|
||||
public apply() {
|
||||
const info = findParentDestination(this.parser, "info");
|
||||
if (info == null) {
|
||||
throw new RTFJSError("IDestination " + this._name + " must be within info destination");
|
||||
@@ -441,19 +442,19 @@ export interface IMetaPropertyTimeDestination extends IDestination {
|
||||
apply(): void;
|
||||
}
|
||||
export class MetaPropertyTimeDestinationFactory extends DestinationFactory<IMetaPropertyTimeDestination> {
|
||||
metaprop: string;
|
||||
private metaprop: string;
|
||||
|
||||
constructor(metaprop: string) {
|
||||
super();
|
||||
this.metaprop = metaprop;
|
||||
this.class = class extends DestinationBase implements IMetaPropertyTimeDestination {
|
||||
_yr: number;
|
||||
_mo: number;
|
||||
_dy: number;
|
||||
_hr: number;
|
||||
_min: number;
|
||||
_sec: number;
|
||||
parser: GlobalState;
|
||||
private _yr: number;
|
||||
private _mo: number;
|
||||
private _dy: number;
|
||||
private _hr: number;
|
||||
private _min: number;
|
||||
private _sec: number;
|
||||
private parser: GlobalState;
|
||||
|
||||
constructor(parser: GlobalState, inst: Document, name: string) {
|
||||
super(name);
|
||||
@@ -466,7 +467,7 @@ export class MetaPropertyTimeDestinationFactory extends DestinationFactory<IMeta
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
handleKeyword(keyword: string, param: number) {
|
||||
public handleKeyword(keyword: string, param: number) {
|
||||
switch (keyword) {
|
||||
case "yr":
|
||||
this._yr = param;
|
||||
@@ -496,7 +497,7 @@ export class MetaPropertyTimeDestinationFactory extends DestinationFactory<IMeta
|
||||
return true;
|
||||
}
|
||||
|
||||
apply() {
|
||||
public apply() {
|
||||
const info = findParentDestination(this.parser, "info");
|
||||
if (info == null) {
|
||||
throw new RTFJSError("IDestination " + this._name + " must be within info destination");
|
||||
@@ -516,14 +517,14 @@ export class MetaPropertyTimeDestinationFactory extends DestinationFactory<IMeta
|
||||
}
|
||||
|
||||
export class FonttblDestinationSub extends DestinationBase {
|
||||
_fonttbl: FonttblDestination;
|
||||
index: number;
|
||||
fontname: string;
|
||||
altfontname: string;
|
||||
family: string;
|
||||
pitch: number;
|
||||
bias: number;
|
||||
charset: number;
|
||||
public index: number;
|
||||
public fontname: string;
|
||||
public altfontname: string;
|
||||
public family: string;
|
||||
public pitch: number;
|
||||
public bias: number;
|
||||
public charset: number;
|
||||
private _fonttbl: FonttblDestination;
|
||||
|
||||
constructor(fonttbl: FonttblDestination) {
|
||||
super("fonttbl:sub");
|
||||
@@ -537,7 +538,7 @@ export class FonttblDestinationSub extends DestinationBase {
|
||||
this.charset = null;
|
||||
}
|
||||
|
||||
handleKeyword(keyword: string, param: number) {
|
||||
public handleKeyword(keyword: string, param: number) {
|
||||
switch (keyword) {
|
||||
case "f":
|
||||
this.index = param;
|
||||
@@ -596,7 +597,7 @@ export class FonttblDestinationSub extends DestinationBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
appendText(text: string) {
|
||||
public appendText(text: string) {
|
||||
if (this.fontname == null) {
|
||||
this.fontname = text;
|
||||
} else {
|
||||
@@ -604,7 +605,7 @@ export class FonttblDestinationSub extends DestinationBase {
|
||||
}
|
||||
}
|
||||
|
||||
apply() {
|
||||
public apply() {
|
||||
if (this.index == null) {
|
||||
throw new RTFJSError("No font index provided");
|
||||
}
|
||||
@@ -615,15 +616,15 @@ export class FonttblDestinationSub extends DestinationBase {
|
||||
delete this._fonttbl;
|
||||
}
|
||||
|
||||
setAltFontName(name: string) {
|
||||
public setAltFontName(name: string) {
|
||||
this.altfontname = name;
|
||||
}
|
||||
}
|
||||
|
||||
export class FonttblDestination extends DestinationBase {
|
||||
_fonts: FonttblDestinationSub[];
|
||||
_sub: FonttblDestinationSub;
|
||||
inst: Document;
|
||||
private _fonts: FonttblDestinationSub[];
|
||||
private _sub: FonttblDestinationSub;
|
||||
private inst: Document;
|
||||
|
||||
constructor(parser: GlobalState, inst: Document) {
|
||||
super("fonttbl");
|
||||
@@ -632,11 +633,11 @@ export class FonttblDestination extends DestinationBase {
|
||||
this.inst = inst;
|
||||
}
|
||||
|
||||
sub() {
|
||||
public sub() {
|
||||
return new FonttblDestinationSub(this);
|
||||
}
|
||||
|
||||
apply() {
|
||||
public apply() {
|
||||
Helper.log("[fonttbl] apply()");
|
||||
for (const idx in this._fonts) {
|
||||
Helper.log("[fonttbl][" + idx + "] index = " + this._fonts[idx].fontname
|
||||
@@ -646,19 +647,19 @@ export class FonttblDestination extends DestinationBase {
|
||||
delete this._fonts;
|
||||
}
|
||||
|
||||
appendText(text: string) {
|
||||
public appendText(text: string) {
|
||||
this._sub.appendText(text);
|
||||
this._sub.apply();
|
||||
}
|
||||
|
||||
handleKeyword(keyword: string, param: number) {
|
||||
public handleKeyword(keyword: string, param: number) {
|
||||
if (keyword === "f") {
|
||||
this._sub = this.sub();
|
||||
}
|
||||
this._sub.handleKeyword(keyword, param);
|
||||
}
|
||||
|
||||
addSub(sub: FonttblDestinationSub) {
|
||||
public addSub(sub: FonttblDestinationSub) {
|
||||
this._fonts[sub.index] = sub;
|
||||
}
|
||||
}
|
||||
@@ -667,9 +668,9 @@ export interface IGenericSubTextPropertyDestination extends IDestination {
|
||||
apply(): void;
|
||||
}
|
||||
export class GenericSubTextPropertyDestinationFactory extends DestinationFactory<IGenericSubTextPropertyDestination> {
|
||||
name: string;
|
||||
parentDest: string;
|
||||
propOrFunc: string;
|
||||
private name: string;
|
||||
private parentDest: string;
|
||||
private propOrFunc: string;
|
||||
|
||||
constructor(name: string, parentDest: string, propOrFunc: string) {
|
||||
super();
|
||||
@@ -677,14 +678,14 @@ export class GenericSubTextPropertyDestinationFactory extends DestinationFactory
|
||||
this.parentDest = parentDest;
|
||||
this.propOrFunc = propOrFunc;
|
||||
this.class = class extends DestinationTextBase implements IGenericSubTextPropertyDestination {
|
||||
parser: GlobalState;
|
||||
private parser: GlobalState;
|
||||
|
||||
constructor(parser: GlobalState) {
|
||||
super(name);
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
apply() {
|
||||
public apply() {
|
||||
const dest = findParentDestination(this.parser, parentDest);
|
||||
if (dest == null) {
|
||||
throw new RTFJSError(this._name + " destination must be child of " + parentDest + " destination");
|
||||
@@ -713,10 +714,10 @@ export interface IColor {
|
||||
}
|
||||
|
||||
export class ColortblDestination extends DestinationBase {
|
||||
_colors: IColor[];
|
||||
_current: IColor;
|
||||
_autoIndex: number;
|
||||
inst: Document;
|
||||
private _colors: IColor[];
|
||||
private _current: IColor;
|
||||
private _autoIndex: number;
|
||||
private inst: Document;
|
||||
|
||||
constructor(parser: GlobalState, inst: Document) {
|
||||
super("colortbl");
|
||||
@@ -726,19 +727,7 @@ export class ColortblDestination extends DestinationBase {
|
||||
this.inst = inst;
|
||||
}
|
||||
|
||||
_startNewColor() {
|
||||
this._current = {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
tint: 255,
|
||||
shade: 255,
|
||||
theme: null,
|
||||
};
|
||||
return this._current;
|
||||
}
|
||||
|
||||
appendText(text: string) {
|
||||
public appendText(text: string) {
|
||||
const len = text.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (text[i] !== ";") {
|
||||
@@ -760,17 +749,7 @@ export class ColortblDestination extends DestinationBase {
|
||||
}
|
||||
}
|
||||
|
||||
_validateColorValueRange(keyword: string, param: number) {
|
||||
if (param == null) {
|
||||
throw new RTFJSError(keyword + " has no param");
|
||||
}
|
||||
if (param < 0 || param > 255) {
|
||||
throw new RTFJSError(keyword + " has invalid param value");
|
||||
}
|
||||
return param;
|
||||
}
|
||||
|
||||
handleKeyword(keyword: string, param: number) {
|
||||
public handleKeyword(keyword: string, param: number) {
|
||||
if (this._current == null) {
|
||||
this._startNewColor();
|
||||
}
|
||||
@@ -803,7 +782,7 @@ export class ColortblDestination extends DestinationBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
apply() {
|
||||
public apply() {
|
||||
Helper.log("[colortbl] apply()");
|
||||
if (this._autoIndex == null) {
|
||||
this._autoIndex = 0;
|
||||
@@ -820,14 +799,36 @@ export class ColortblDestination extends DestinationBase {
|
||||
this.inst._autoColor = this._autoIndex;
|
||||
delete this._colors;
|
||||
}
|
||||
|
||||
private _startNewColor() {
|
||||
this._current = {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
tint: 255,
|
||||
shade: 255,
|
||||
theme: null,
|
||||
};
|
||||
return this._current;
|
||||
}
|
||||
|
||||
private _validateColorValueRange(keyword: string, param: number) {
|
||||
if (param == null) {
|
||||
throw new RTFJSError(keyword + " has no param");
|
||||
}
|
||||
if (param < 0 || param > 255) {
|
||||
throw new RTFJSError(keyword + " has invalid param value");
|
||||
}
|
||||
return param;
|
||||
}
|
||||
}
|
||||
|
||||
export class StylesheetDestinationSub extends DestinationBase {
|
||||
_stylesheet: StylesheetDestination;
|
||||
index: number;
|
||||
name: string;
|
||||
handler: (keyword: string, param: number) => boolean;
|
||||
paragraph?: null;
|
||||
private _stylesheet: StylesheetDestination;
|
||||
private index: number;
|
||||
private name: string;
|
||||
private handler: (keyword: string, param: number) => boolean;
|
||||
private paragraph?: null;
|
||||
|
||||
constructor(stylesheet: StylesheetDestination) {
|
||||
super("stylesheet:sub");
|
||||
@@ -837,14 +838,7 @@ export class StylesheetDestinationSub extends DestinationBase {
|
||||
this.handler = this._handleKeywordCommon("paragraph");
|
||||
}
|
||||
|
||||
_handleKeywordCommon(member: string) {
|
||||
return (keyword: string, param: number) => {
|
||||
Helper.log("[stylesheet:sub]." + member + ": unhandled keyword: " + keyword + " param: " + param);
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
handleKeyword(keyword: string, param: number) {
|
||||
public handleKeyword(keyword: string, param: number) {
|
||||
switch (keyword) {
|
||||
case "s":
|
||||
this.index = param;
|
||||
@@ -869,7 +863,7 @@ export class StylesheetDestinationSub extends DestinationBase {
|
||||
return this.handler(keyword, param);
|
||||
}
|
||||
|
||||
appendText(text: string) {
|
||||
public appendText(text: string) {
|
||||
if (this.name == null) {
|
||||
this.name = text;
|
||||
} else {
|
||||
@@ -877,18 +871,25 @@ export class StylesheetDestinationSub extends DestinationBase {
|
||||
}
|
||||
}
|
||||
|
||||
apply() {
|
||||
public apply() {
|
||||
this._stylesheet.addSub({
|
||||
index: this.index,
|
||||
name: this.name,
|
||||
});
|
||||
delete this._stylesheet;
|
||||
}
|
||||
|
||||
private _handleKeywordCommon(member: string) {
|
||||
return (keyword: string, param: number) => {
|
||||
Helper.log("[stylesheet:sub]." + member + ": unhandled keyword: " + keyword + " param: " + param);
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class StylesheetDestination extends DestinationBase {
|
||||
_stylesheets: Array<{index: number, name: string}>;
|
||||
inst: Document;
|
||||
private _stylesheets: Array<{index: number, name: string}>;
|
||||
private inst: Document;
|
||||
|
||||
constructor(parser: GlobalState, inst: Document) {
|
||||
super("stylesheet");
|
||||
@@ -896,11 +897,11 @@ export class StylesheetDestination extends DestinationBase {
|
||||
this.inst = inst;
|
||||
}
|
||||
|
||||
sub() {
|
||||
public sub() {
|
||||
return new StylesheetDestinationSub(this);
|
||||
}
|
||||
|
||||
apply() {
|
||||
public apply() {
|
||||
Helper.log("[stylesheet] apply()");
|
||||
for (const idx in this._stylesheets) {
|
||||
Helper.log("[stylesheet] [" + idx + "] name: " + this._stylesheets[idx].name);
|
||||
@@ -909,7 +910,7 @@ export class StylesheetDestination extends DestinationBase {
|
||||
delete this._stylesheets;
|
||||
}
|
||||
|
||||
addSub(sub: {index: number, name: string}) {
|
||||
public addSub(sub: {index: number, name: string}) {
|
||||
// Some documents will redefine stylesheets
|
||||
// if (this._stylesheets[sub.index] != null)
|
||||
// throw new RTFJSError("Cannot redefine stylesheet with index " + sub.index);
|
||||
@@ -923,9 +924,9 @@ export interface IField {
|
||||
}
|
||||
|
||||
export class FieldDestination extends DestinationBase {
|
||||
_haveInst: boolean;
|
||||
_parsedInst: IField;
|
||||
_result: FldrsltDestination;
|
||||
private _haveInst: boolean;
|
||||
private _parsedInst: IField;
|
||||
private _result: FldrsltDestination;
|
||||
|
||||
constructor() {
|
||||
super("field");
|
||||
@@ -934,7 +935,7 @@ export class FieldDestination extends DestinationBase {
|
||||
this._result = null;
|
||||
}
|
||||
|
||||
apply() {
|
||||
public apply() {
|
||||
if (!this._haveInst) {
|
||||
throw new RTFJSError("IField has no fldinst destination");
|
||||
}
|
||||
@@ -943,7 +944,7 @@ export class FieldDestination extends DestinationBase {
|
||||
// throw new RTFJSError("IField has no fldrslt destination");
|
||||
}
|
||||
|
||||
setInst(inst: IField | Promise<IField | null>) {
|
||||
public setInst(inst: IField | Promise<IField | null>) {
|
||||
this._haveInst = true;
|
||||
if (this._parsedInst != null) {
|
||||
throw new RTFJSError("IField cannot have multiple fldinst destinations");
|
||||
@@ -960,11 +961,11 @@ export class FieldDestination extends DestinationBase {
|
||||
}
|
||||
}
|
||||
|
||||
getInst() {
|
||||
public getInst() {
|
||||
return this._parsedInst;
|
||||
}
|
||||
|
||||
setResult(inst: FldrsltDestination) {
|
||||
public setResult(inst: FldrsltDestination) {
|
||||
if (this._result != null) {
|
||||
throw new RTFJSError("IField cannot have multiple fldrslt destinations");
|
||||
}
|
||||
@@ -973,13 +974,13 @@ export class FieldDestination extends DestinationBase {
|
||||
}
|
||||
|
||||
export class FieldBase {
|
||||
_fldinst: FldinstDestination;
|
||||
private _fldinst: FldinstDestination;
|
||||
|
||||
constructor(fldinst: FldinstDestination) {
|
||||
this._fldinst = fldinst;
|
||||
}
|
||||
|
||||
renderFieldEnd(field: FieldDestination, rtf: RtfDestination, records: number) {
|
||||
public renderFieldEnd(field: FieldDestination, rtf: RtfDestination, records: number) {
|
||||
if (records > 0) {
|
||||
rtf.addIns(function() {
|
||||
this.popContainer();
|
||||
@@ -989,8 +990,8 @@ export class FieldBase {
|
||||
}
|
||||
|
||||
export class FieldHyperlink extends FieldBase {
|
||||
_url: string;
|
||||
inst: Document;
|
||||
private _url: string;
|
||||
private inst: Document;
|
||||
|
||||
constructor(inst: Document, fldinst: FldinstDestination, data: string) {
|
||||
super(fldinst);
|
||||
@@ -998,11 +999,11 @@ export class FieldHyperlink extends FieldBase {
|
||||
this.inst = inst;
|
||||
}
|
||||
|
||||
url() {
|
||||
public url() {
|
||||
return this._url;
|
||||
}
|
||||
|
||||
renderFieldBegin(field: FieldDestination, rtf: RtfDestination, records: number) {
|
||||
public renderFieldBegin(field: FieldDestination, rtf: RtfDestination, records: number) {
|
||||
const self = this;
|
||||
if (records > 0) {
|
||||
rtf.addIns(function() {
|
||||
@@ -1031,8 +1032,8 @@ export class FieldHyperlink extends FieldBase {
|
||||
}
|
||||
|
||||
export class FldinstDestination extends DestinationTextBase {
|
||||
parser: GlobalState;
|
||||
inst: Document;
|
||||
private parser: GlobalState;
|
||||
private inst: Document;
|
||||
|
||||
constructor(parser: GlobalState, inst: Document) {
|
||||
super("fldinst");
|
||||
@@ -1040,7 +1041,7 @@ export class FldinstDestination extends DestinationTextBase {
|
||||
this.inst = inst;
|
||||
}
|
||||
|
||||
apply() {
|
||||
public apply() {
|
||||
const field = findParentDestination(this.parser, "field") as FieldDestination;
|
||||
if (field == null) {
|
||||
throw new RTFJSError("fldinst destination must be child of field destination");
|
||||
@@ -1048,7 +1049,7 @@ export class FldinstDestination extends DestinationTextBase {
|
||||
field.setInst(this.parseType());
|
||||
}
|
||||
|
||||
parseType() {
|
||||
private parseType() {
|
||||
const sep = this.text.indexOf(" ");
|
||||
if (sep > 0) {
|
||||
let data = this.text.substr(sep + 1);
|
||||
@@ -1143,7 +1144,7 @@ export class FldrsltDestination extends DestinationFormattedTextBase {
|
||||
super(parser, "fldrslt");
|
||||
}
|
||||
|
||||
apply() {
|
||||
public apply() {
|
||||
const field = findParentDestination(this.parser, "field") as FieldDestination;
|
||||
if (field != null) {
|
||||
field.setResult(this);
|
||||
@@ -1152,7 +1153,7 @@ export class FldrsltDestination extends DestinationFormattedTextBase {
|
||||
super.apply();
|
||||
}
|
||||
|
||||
renderBegin(rtf: RtfDestination, records: number) {
|
||||
public renderBegin(rtf: RtfDestination, records: number) {
|
||||
const field = findParentDestination(this.parser, "field") as FieldDestination;
|
||||
if (field != null) {
|
||||
const inst = field.getInst();
|
||||
@@ -1163,7 +1164,7 @@ export class FldrsltDestination extends DestinationFormattedTextBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
renderEnd(rtf: RtfDestination, records: number) {
|
||||
public renderEnd(rtf: RtfDestination, records: number) {
|
||||
const field = findParentDestination(this.parser, "field") as FieldDestination;
|
||||
if (field != null) {
|
||||
const inst = field.getInst();
|
||||
@@ -1178,20 +1179,20 @@ export interface IPictGroupDestination extends IDestination {
|
||||
isLegacy(): boolean;
|
||||
}
|
||||
export class PictGroupDestinationFactory extends DestinationFactory<IPictGroupDestination> {
|
||||
legacy: boolean;
|
||||
private legacy: boolean;
|
||||
|
||||
constructor(legacy: boolean) {
|
||||
super();
|
||||
this.legacy = legacy;
|
||||
this.class = class extends DestinationTextBase implements IPictGroupDestination {
|
||||
_legacy: boolean;
|
||||
private _legacy: boolean;
|
||||
|
||||
constructor() {
|
||||
super("pict-group");
|
||||
this._legacy = legacy;
|
||||
}
|
||||
|
||||
isLegacy() {
|
||||
public isLegacy() {
|
||||
return this._legacy;
|
||||
}
|
||||
};
|
||||
@@ -1199,22 +1200,22 @@ export class PictGroupDestinationFactory extends DestinationFactory<IPictGroupDe
|
||||
}
|
||||
|
||||
export class PictDestination extends DestinationTextBase {
|
||||
_type: string | (() => any);
|
||||
_blob: ArrayBuffer;
|
||||
_displaysize: {width: number, height: number};
|
||||
_size: {width: number, height: number};
|
||||
parser: GlobalState;
|
||||
inst: Document;
|
||||
public _displaysize: {width: number, height: number};
|
||||
public _size: {width: number, height: number};
|
||||
private _type: string | (() => any);
|
||||
private _blob: ArrayBuffer;
|
||||
private parser: GlobalState;
|
||||
private inst: Document;
|
||||
[key: string]: any;
|
||||
|
||||
_pictHandlers: {[key: string]: (param: number) => void} = {
|
||||
private _pictHandlers: {[key: string]: (param: number) => void} = {
|
||||
picw: this._setPropValueRequired("_size", "width"),
|
||||
pich: this._setPropValueRequired("_size", "height"),
|
||||
picwgoal: this._setPropValueRequired("_displaysize", "width"),
|
||||
pichgoal: this._setPropValueRequired("_displaysize", "height"),
|
||||
};
|
||||
|
||||
_pictTypeHandler
|
||||
private _pictTypeHandler
|
||||
: {[key: string]: string | ((param?: number) => {load: () => any, render: (img: any) => JQuery})} = {
|
||||
emfblip: (() => {
|
||||
if (typeof EMFJS !== "undefined") {
|
||||
@@ -1305,18 +1306,7 @@ export class PictDestination extends DestinationTextBase {
|
||||
this.inst = inst;
|
||||
}
|
||||
|
||||
_setPropValueRequired(member: string, prop: string) {
|
||||
return (param: number) => {
|
||||
if (param == null) {
|
||||
throw new RTFJSError("Picture property has no value");
|
||||
}
|
||||
Helper.log("[pict] set " + member + "." + prop + " = " + param);
|
||||
const obj = (member != null ? this[member] : this);
|
||||
obj[prop] = param;
|
||||
};
|
||||
}
|
||||
|
||||
handleKeyword(keyword: string, param: number) {
|
||||
public handleKeyword(keyword: string, param: number) {
|
||||
const handler = this._pictHandlers[keyword];
|
||||
if (handler != null) {
|
||||
handler(param);
|
||||
@@ -1349,11 +1339,11 @@ export class PictDestination extends DestinationTextBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
handleBlob(blob: ArrayBuffer) {
|
||||
public handleBlob(blob: ArrayBuffer) {
|
||||
this._blob = blob;
|
||||
}
|
||||
|
||||
apply(rendering= false) {
|
||||
public apply(rendering= false) {
|
||||
if (this._type == null) {
|
||||
throw new RTFJSError("Picture type unknown or not specified");
|
||||
}
|
||||
@@ -1468,13 +1458,24 @@ export class PictDestination extends DestinationTextBase {
|
||||
|
||||
delete this.text;
|
||||
}
|
||||
|
||||
private _setPropValueRequired(member: string, prop: string) {
|
||||
return (param: number) => {
|
||||
if (param == null) {
|
||||
throw new RTFJSError("Picture property has no value");
|
||||
}
|
||||
Helper.log("[pict] set " + member + "." + prop + " = " + param);
|
||||
const obj = (member != null ? this[member] : this);
|
||||
obj[prop] = param;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
export interface IRequiredDestination extends IDestination {
|
||||
}
|
||||
export class RequiredDestinationFactory extends DestinationFactory<IRequiredDestination> {
|
||||
name: string;
|
||||
private name: string;
|
||||
|
||||
constructor(name: string) {
|
||||
super();
|
||||
|
||||
@@ -29,13 +29,13 @@ import { Helper } from "../Helper";
|
||||
import { Chp } from "./Containers";
|
||||
|
||||
export class RenderChp {
|
||||
_chp: Chp;
|
||||
public _chp: Chp;
|
||||
|
||||
constructor(chp: Chp) {
|
||||
this._chp = chp;
|
||||
}
|
||||
|
||||
apply(doc: Document, el: JQuery) {
|
||||
public apply(doc: Document, el: JQuery) {
|
||||
if (this._chp.bold) {
|
||||
el.css("font-weight", "bold");
|
||||
}
|
||||
|
||||
@@ -30,13 +30,13 @@ import { Pap } from "./Containers";
|
||||
import { RenderChp } from "./RenderChp";
|
||||
|
||||
export class RenderPap {
|
||||
_pap: Pap;
|
||||
private _pap: Pap;
|
||||
|
||||
constructor(pap: Pap) {
|
||||
this._pap = pap;
|
||||
}
|
||||
|
||||
apply(doc: Document, el: JQuery, rchp: RenderChp, ismaindiv: boolean) {
|
||||
public apply(doc: Document, el: JQuery, rchp: RenderChp, ismaindiv: boolean) {
|
||||
if (ismaindiv) {
|
||||
if (this._pap.spacebefore !== 0) {
|
||||
el.css("margin-top", Helper._twipsToPt(this._pap.spacebefore) + "pt");
|
||||
|
||||
+60
-59
@@ -28,20 +28,20 @@ import { Blob } from "./Blob";
|
||||
import { Helper, WMFJSError } from "./Helper";
|
||||
|
||||
export class BitmapBase {
|
||||
getWidth() {
|
||||
public getWidth() {
|
||||
throw new WMFJSError("getWidth not implemented");
|
||||
}
|
||||
|
||||
getHeight() {
|
||||
public getHeight() {
|
||||
throw new WMFJSError("getHeight not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
export class BitmapCoreHeader {
|
||||
width: number;
|
||||
height: number;
|
||||
planes: number;
|
||||
bitcount: number;
|
||||
public width: number;
|
||||
public height: number;
|
||||
public planes: number;
|
||||
public bitcount: number;
|
||||
|
||||
constructor(reader: Blob, skipsize: boolean) {
|
||||
if (skipsize) {
|
||||
@@ -53,22 +53,22 @@ export class BitmapCoreHeader {
|
||||
this.bitcount = reader.readUint16();
|
||||
}
|
||||
|
||||
colors() {
|
||||
public colors() {
|
||||
return this.bitcount <= 8 ? 1 << this.bitcount : 0;
|
||||
}
|
||||
}
|
||||
|
||||
export class BitmapInfoHeader {
|
||||
width: number;
|
||||
height: number;
|
||||
planes: number;
|
||||
bitcount: number;
|
||||
compression: number;
|
||||
sizeimage: number;
|
||||
xpelspermeter: number;
|
||||
ypelspermeter: number;
|
||||
clrused: number;
|
||||
clrimportant: number;
|
||||
public width: number;
|
||||
public height: number;
|
||||
public planes: number;
|
||||
public bitcount: number;
|
||||
public compression: number;
|
||||
public sizeimage: number;
|
||||
public xpelspermeter: number;
|
||||
public ypelspermeter: number;
|
||||
public clrused: number;
|
||||
public clrimportant: number;
|
||||
|
||||
constructor(reader: Blob, skipsize: boolean) {
|
||||
if (skipsize) {
|
||||
@@ -86,7 +86,7 @@ export class BitmapInfoHeader {
|
||||
this.clrimportant = reader.readUint32();
|
||||
}
|
||||
|
||||
colors() {
|
||||
public colors() {
|
||||
if (this.clrused !== 0) {
|
||||
return this.clrused < 256 ? this.clrused : 256;
|
||||
} else {
|
||||
@@ -96,11 +96,11 @@ export class BitmapInfoHeader {
|
||||
}
|
||||
|
||||
export class BitmapInfo extends BitmapBase {
|
||||
_reader: Blob;
|
||||
_offset: number;
|
||||
_usergb: boolean;
|
||||
_infosize: number;
|
||||
_header: BitmapCoreHeader | BitmapInfoHeader;
|
||||
private _reader: Blob;
|
||||
private _offset: number;
|
||||
private _usergb: boolean;
|
||||
private _infosize: number;
|
||||
private _header: BitmapCoreHeader | BitmapInfoHeader;
|
||||
|
||||
constructor(reader: Blob, usergb: boolean) {
|
||||
super();
|
||||
@@ -123,28 +123,28 @@ export class BitmapInfo extends BitmapBase {
|
||||
}
|
||||
}
|
||||
|
||||
getWidth() {
|
||||
public getWidth() {
|
||||
return this._header.width;
|
||||
}
|
||||
|
||||
getHeight() {
|
||||
public getHeight() {
|
||||
return Math.abs(this._header.height);
|
||||
}
|
||||
|
||||
infosize() {
|
||||
public infosize() {
|
||||
return this._infosize;
|
||||
}
|
||||
|
||||
header() {
|
||||
public header() {
|
||||
return this._header;
|
||||
}
|
||||
}
|
||||
|
||||
export class DIBitmap extends BitmapBase {
|
||||
_reader: Blob;
|
||||
_offset: number;
|
||||
_size: number;
|
||||
_info: BitmapInfo;
|
||||
private _reader: Blob;
|
||||
private _offset: number;
|
||||
private _size: number;
|
||||
private _info: BitmapInfo;
|
||||
|
||||
constructor(reader: Blob, size: number) {
|
||||
super();
|
||||
@@ -154,25 +154,15 @@ export class DIBitmap extends BitmapBase {
|
||||
this._info = new BitmapInfo(reader, true);
|
||||
}
|
||||
|
||||
getWidth() {
|
||||
public getWidth() {
|
||||
return this._info.getWidth();
|
||||
}
|
||||
|
||||
getHeight() {
|
||||
public getHeight() {
|
||||
return this._info.getHeight();
|
||||
}
|
||||
|
||||
makeBitmapFileHeader() {
|
||||
const buf = new ArrayBuffer(14);
|
||||
const view = new Uint8Array(buf);
|
||||
view[0] = 0x42;
|
||||
view[1] = 0x4d;
|
||||
Helper._writeUint32Val(view, 2, this._size + 14);
|
||||
Helper._writeUint32Val(view, 10, this._info.infosize() + 14);
|
||||
return Helper._blobToBinary(view);
|
||||
}
|
||||
|
||||
base64ref() {
|
||||
public base64ref() {
|
||||
const prevpos = this._reader.pos;
|
||||
this._reader.seek(this._offset);
|
||||
let mime = "image/bmp";
|
||||
@@ -204,20 +194,31 @@ export class DIBitmap extends BitmapBase {
|
||||
this._reader.seek(prevpos);
|
||||
return ref;
|
||||
}
|
||||
|
||||
private makeBitmapFileHeader() {
|
||||
const buf = new ArrayBuffer(14);
|
||||
const view = new Uint8Array(buf);
|
||||
view[0] = 0x42;
|
||||
view[1] = 0x4d;
|
||||
Helper._writeUint32Val(view, 2, this._size + 14);
|
||||
Helper._writeUint32Val(view, 10, this._info.infosize() + 14);
|
||||
return Helper._blobToBinary(view);
|
||||
}
|
||||
}
|
||||
|
||||
export class Bitmap16 extends BitmapBase {
|
||||
_reader: Blob;
|
||||
_offset: number;
|
||||
_size: number;
|
||||
type: number;
|
||||
width: number;
|
||||
height: number;
|
||||
widthBytes: number;
|
||||
planes: number;
|
||||
bitsPixel: number;
|
||||
bitsOffset: number;
|
||||
bitsSize: number;
|
||||
public type: number;
|
||||
public width: number;
|
||||
public height: number;
|
||||
public widthBytes: number;
|
||||
public planes: number;
|
||||
public bitsPixel: number;
|
||||
public bitsOffset: number;
|
||||
public bitsSize: number;
|
||||
private _reader: Blob;
|
||||
private _offset: number;
|
||||
private _size: number;
|
||||
|
||||
constructor(reader: Blob, size: number | Bitmap16) {
|
||||
super();
|
||||
if (reader != null) {
|
||||
@@ -252,15 +253,15 @@ export class Bitmap16 extends BitmapBase {
|
||||
}
|
||||
}
|
||||
|
||||
getWidth() {
|
||||
public getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
getHeight() {
|
||||
public getHeight() {
|
||||
return this.height;
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new Bitmap16(null, this);
|
||||
}
|
||||
}
|
||||
@@ -273,7 +274,7 @@ export class PatternBitmap16 extends Bitmap16 {
|
||||
}
|
||||
}
|
||||
|
||||
clone(): PatternBitmap16 {
|
||||
public clone(): PatternBitmap16 {
|
||||
return new PatternBitmap16(null, this);
|
||||
}
|
||||
}
|
||||
|
||||
+15
-15
@@ -27,9 +27,9 @@ SOFTWARE.
|
||||
import { WMFJSError } from "./Helper";
|
||||
|
||||
export class Blob {
|
||||
blob: Blob | ArrayBuffer;
|
||||
data: Uint8Array;
|
||||
pos: number;
|
||||
public pos: number;
|
||||
private blob: Blob | ArrayBuffer;
|
||||
private data: Uint8Array;
|
||||
|
||||
constructor(blob: Blob | ArrayBuffer, offset?: number) {
|
||||
if (blob instanceof Blob) {
|
||||
@@ -43,18 +43,18 @@ export class Blob {
|
||||
}
|
||||
}
|
||||
|
||||
eof() {
|
||||
public eof() {
|
||||
return this.pos >= this.data.length;
|
||||
}
|
||||
|
||||
seek(newpos: number) {
|
||||
public seek(newpos: number) {
|
||||
if (newpos < 0 || newpos > this.data.length) {
|
||||
throw new WMFJSError("Invalid seek position");
|
||||
}
|
||||
this.pos = newpos;
|
||||
}
|
||||
|
||||
skip(cnt: number) {
|
||||
public skip(cnt: number) {
|
||||
const newPos = this.pos + cnt;
|
||||
if (newPos > this.data.length) {
|
||||
throw new WMFJSError("Unexpected end of file");
|
||||
@@ -62,7 +62,7 @@ export class Blob {
|
||||
this.pos = newPos;
|
||||
}
|
||||
|
||||
readBinary(cnt: number) {
|
||||
public readBinary(cnt: number) {
|
||||
const end = this.pos + cnt;
|
||||
if (end > this.data.length) {
|
||||
throw new WMFJSError("Unexpected end of file");
|
||||
@@ -74,18 +74,18 @@ export class Blob {
|
||||
return ret;
|
||||
}
|
||||
|
||||
readInt8() {
|
||||
public readInt8() {
|
||||
if (this.pos + 1 > this.data.length) {
|
||||
throw new WMFJSError("Unexpected end of file");
|
||||
}
|
||||
return this.data[this.pos++];
|
||||
}
|
||||
|
||||
readUint8() {
|
||||
public readUint8() {
|
||||
return this.readInt8() >>> 0;
|
||||
}
|
||||
|
||||
readInt32() {
|
||||
public readInt32() {
|
||||
if (this.pos + 4 > this.data.length) {
|
||||
throw new WMFJSError("Unexpected end of file");
|
||||
}
|
||||
@@ -96,11 +96,11 @@ export class Blob {
|
||||
return val;
|
||||
}
|
||||
|
||||
readUint32() {
|
||||
public readUint32() {
|
||||
return this.readInt32() >>> 0;
|
||||
}
|
||||
|
||||
readUint16() {
|
||||
public readUint16() {
|
||||
if (this.pos + 2 > this.data.length) {
|
||||
throw new WMFJSError("Unexpected end of file");
|
||||
}
|
||||
@@ -109,7 +109,7 @@ export class Blob {
|
||||
return val;
|
||||
}
|
||||
|
||||
readInt16() {
|
||||
public readInt16() {
|
||||
let val = this.readUint16();
|
||||
if (val > 32767) {
|
||||
val -= 65536;
|
||||
@@ -117,7 +117,7 @@ export class Blob {
|
||||
return val;
|
||||
}
|
||||
|
||||
readString(length: number) {
|
||||
public readString(length: number) {
|
||||
if (this.pos + length > this.data.length) {
|
||||
throw new WMFJSError("Unexpected end of file");
|
||||
}
|
||||
@@ -128,7 +128,7 @@ export class Blob {
|
||||
return ret;
|
||||
}
|
||||
|
||||
readNullTermString(maxSize: number) {
|
||||
public readNullTermString(maxSize: number) {
|
||||
let ret = "";
|
||||
if (maxSize > 0) {
|
||||
maxSize--;
|
||||
|
||||
+416
-416
@@ -41,29 +41,29 @@ export interface ISelectedStyle {
|
||||
}
|
||||
|
||||
export class GDIContextState {
|
||||
_svggroup: any;
|
||||
_svgclipChanged: boolean;
|
||||
_svgtextbkfilter: any;
|
||||
mapmode: number;
|
||||
stretchmode: number;
|
||||
textalign: number;
|
||||
bkmode: number;
|
||||
textcolor: ColorRef;
|
||||
bkcolor: ColorRef;
|
||||
polyfillmode: number;
|
||||
wx: number;
|
||||
wy: number;
|
||||
ww: number;
|
||||
wh: number;
|
||||
vx: number;
|
||||
vy: number;
|
||||
vw: number;
|
||||
vh: number;
|
||||
x: number;
|
||||
y: number;
|
||||
clip: Region;
|
||||
ownclip: boolean;
|
||||
selected: ISelectedStyle;
|
||||
public _svggroup: any;
|
||||
public _svgclipChanged: boolean;
|
||||
public _svgtextbkfilter: any;
|
||||
public mapmode: number;
|
||||
public stretchmode: number;
|
||||
public textalign: number;
|
||||
public bkmode: number;
|
||||
public textcolor: ColorRef;
|
||||
public bkcolor: ColorRef;
|
||||
public polyfillmode: number;
|
||||
public wx: number;
|
||||
public wy: number;
|
||||
public ww: number;
|
||||
public wh: number;
|
||||
public vx: number;
|
||||
public vy: number;
|
||||
public vw: number;
|
||||
public vh: number;
|
||||
public x: number;
|
||||
public y: number;
|
||||
public clip: Region;
|
||||
public ownclip: boolean;
|
||||
public selected: ISelectedStyle;
|
||||
|
||||
constructor(copy: GDIContextState, defObjects?: ISelectedStyle) {
|
||||
if (copy != null) {
|
||||
@@ -130,14 +130,14 @@ export class GDIContextState {
|
||||
}
|
||||
|
||||
export class GDIContext {
|
||||
_svg: any;
|
||||
_svgdefs: any;
|
||||
_svgPatterns: {[key: string]: Brush};
|
||||
_svgClipPaths: {[key: string]: Region};
|
||||
defObjects: ISelectedStyle;
|
||||
state: GDIContextState;
|
||||
statestack: GDIContextState[];
|
||||
objects: {[key: string]: Obj};
|
||||
private _svg: any;
|
||||
private _svgdefs: any;
|
||||
private _svgPatterns: {[key: string]: Brush};
|
||||
private _svgClipPaths: {[key: string]: Region};
|
||||
private defObjects: ISelectedStyle;
|
||||
private state: GDIContextState;
|
||||
private statestack: GDIContextState[];
|
||||
private objects: {[key: string]: Obj};
|
||||
|
||||
constructor(svg: any) {
|
||||
this._svg = svg;
|
||||
@@ -158,7 +158,372 @@ export class GDIContext {
|
||||
this.objects = {};
|
||||
}
|
||||
|
||||
_pushGroup() {
|
||||
public setMapMode(mode: number) {
|
||||
Helper.log("[gdi] setMapMode: mode=" + mode);
|
||||
this.state.mapmode = mode;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public setWindowOrg(x: number, y: number) {
|
||||
Helper.log("[gdi] setWindowOrg: x=" + x + " y=" + y);
|
||||
this.state.wx = x;
|
||||
this.state.wy = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public setWindowExt(x: number, y: number) {
|
||||
Helper.log("[gdi] setWindowExt: x=" + x + " y=" + y);
|
||||
this.state.ww = x;
|
||||
this.state.wh = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public offsetWindowOrg(offX: number, offY: number) {
|
||||
Helper.log("[gdi] offsetWindowOrg: offX=" + offX + " offY=" + offY);
|
||||
this.state.wx += offX;
|
||||
this.state.wy += offY;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public setViewportOrg(x: number, y: number) {
|
||||
Helper.log("[gdi] setViewportOrg: x=" + x + " y=" + y);
|
||||
this.state.vx = x;
|
||||
this.state.vy = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public setViewportExt(x: number, y: number) {
|
||||
Helper.log("[gdi] setViewportExt: x=" + x + " y=" + y);
|
||||
this.state.vw = x;
|
||||
this.state.vh = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public offsetViewportOrg(offX: number, offY: number) {
|
||||
Helper.log("[gdi] offsetViewportOrg: offX=" + offX + " offY=" + offY);
|
||||
this.state.vx += offX;
|
||||
this.state.vy += offY;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public saveDC() {
|
||||
Helper.log("[gdi] saveDC");
|
||||
const prevstate = this.state;
|
||||
this.state = new GDIContextState(this.state);
|
||||
this.statestack.push(prevstate);
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public restoreDC(saved: number) {
|
||||
Helper.log("[gdi] restoreDC: saved=" + saved);
|
||||
if (this.statestack.length > 1) {
|
||||
if (saved === -1) {
|
||||
this.state = this.statestack.pop();
|
||||
} else if (saved < -1) {
|
||||
throw new WMFJSError("restoreDC: relative restore not implemented");
|
||||
} else if (saved > 1) {
|
||||
throw new WMFJSError("restoreDC: absolute restore not implemented");
|
||||
}
|
||||
} else {
|
||||
throw new WMFJSError("No saved contexts");
|
||||
}
|
||||
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
public escape(func: number, blob: Blob, offset: number, count: number) {
|
||||
Helper.log("[gdi] escape: func=" + func + " offset=" + offset + " count=" + count);
|
||||
}
|
||||
|
||||
public setStretchBltMode(stretchMode: number) {
|
||||
Helper.log("[gdi] setStretchBltMode: stretchMode=" + stretchMode);
|
||||
}
|
||||
|
||||
public stretchDib(srcX: number, srcY: number, srcW: number, srcH: number,
|
||||
dstX: number, dstY: number, dstW: number, dstH: number,
|
||||
rasterOp: number, colorUsage: number, dib: DIBitmap) {
|
||||
Helper.log("[gdi] stretchDib: srcX=" + srcX + " srcY=" + srcY + " srcW=" + srcW + " srcH=" + srcH
|
||||
+ " dstX=" + dstX + " dstY=" + dstY + " dstW=" + dstW + " dstH=" + dstH
|
||||
+ " rasterOp=0x" + rasterOp.toString(16));
|
||||
srcX = this._todevX(srcX);
|
||||
srcY = this._todevY(srcY);
|
||||
srcW = this._todevW(srcW);
|
||||
srcH = this._todevH(srcH);
|
||||
dstX = this._todevX(dstX);
|
||||
dstY = this._todevY(dstY);
|
||||
dstW = this._todevW(dstW);
|
||||
dstH = this._todevH(dstH);
|
||||
Helper.log("[gdi] stretchDib: TRANSLATED: srcX=" + srcX + " srcY=" + srcY + " srcW=" + srcW + " srcH=" + srcH
|
||||
+ " dstX=" + dstX + " dstY=" + dstY + " dstW=" + dstW + " dstH=" + dstH
|
||||
+ " rasterOp=0x" + rasterOp.toString(16) + " colorUsage=0x" + colorUsage.toString(16));
|
||||
this._pushGroup();
|
||||
this._svg.image(this.state._svggroup, dstX, dstY, dstW, dstH, dib.base64ref());
|
||||
}
|
||||
|
||||
public stretchDibBits(srcX: number, srcY: number, srcW: number, srcH: number,
|
||||
dstX: number, dstY: number, dstW: number, dstH: number,
|
||||
rasterOp: number, dib: DIBitmap) {
|
||||
Helper.log("[gdi] stretchDibBits: srcX=" + srcX + " srcY=" + srcY + " srcW=" + srcW + " srcH=" + srcH
|
||||
+ " dstX=" + dstX + " dstY=" + dstY + " dstW=" + dstW + " dstH=" + dstH
|
||||
+ " rasterOp=0x" + rasterOp.toString(16));
|
||||
srcX = this._todevX(srcX);
|
||||
srcY = this._todevY(srcY);
|
||||
srcW = this._todevW(srcW);
|
||||
srcH = this._todevH(srcH);
|
||||
dstX = this._todevX(dstX);
|
||||
dstY = this._todevY(dstY);
|
||||
dstW = this._todevW(dstW);
|
||||
dstH = this._todevH(dstH);
|
||||
Helper.log("[gdi] stretchDibBits: TRANSLATED:"
|
||||
+ " srcX=" + srcX + " srcY=" + srcY + " srcW=" + srcW + " srcH=" + srcH
|
||||
+ " dstX=" + dstX + " dstY=" + dstY + " dstW=" + dstW + " dstH=" + dstH
|
||||
+ " rasterOp=0x" + rasterOp.toString(16));
|
||||
this._pushGroup();
|
||||
this._svg.image(this.state._svggroup, dstX, dstY, dstW, dstH, dib.base64ref());
|
||||
}
|
||||
|
||||
public rectangle(rect: Rect, rw: number, rh: number) {
|
||||
Helper.log("[gdi] rectangle: rect=" + rect.toString() + " with pen " + this.state.selected.pen.toString()
|
||||
+ " and brush " + this.state.selected.brush.toString());
|
||||
const bottom = this._todevY(rect.bottom);
|
||||
const right = this._todevX(rect.right);
|
||||
const top = this._todevY(rect.top);
|
||||
const left = this._todevX(rect.left);
|
||||
rw = this._todevH(rw);
|
||||
rh = this._todevH(rh);
|
||||
Helper.log("[gdi] rectangle: TRANSLATED: bottom=" + bottom + " right=" + right + " top=" + top
|
||||
+ " left=" + left + " rh=" + rh + " rw=" + rw);
|
||||
this._pushGroup();
|
||||
|
||||
const opts = this._applyOpts(null, true, true, false);
|
||||
this._svg.rect(this.state._svggroup, left, top, right - left, bottom - top, rw / 2, rh / 2, opts);
|
||||
}
|
||||
|
||||
public textOut(x: number, y: number, text: string) {
|
||||
Helper.log("[gdi] textOut: x=" + x + " y=" + y + " text=" + text
|
||||
+ " with font " + this.state.selected.font.toString());
|
||||
x = this._todevX(x);
|
||||
y = this._todevY(y);
|
||||
Helper.log("[gdi] textOut: TRANSLATED: x=" + x + " y=" + y);
|
||||
this._pushGroup();
|
||||
|
||||
const opts = this._applyOpts(null, false, false, true);
|
||||
if (this.state.selected.font.escapement !== 0) {
|
||||
opts.transform = "rotate(" + [(-this.state.selected.font.escapement / 10), x, y] + ")";
|
||||
opts.style = "dominant-baseline: middle; text-anchor: start;";
|
||||
}
|
||||
if (this.state.bkmode === Helper.GDI.MixMode.OPAQUE) {
|
||||
if (this.state._svgtextbkfilter == null) {
|
||||
const filterId = Helper._makeUniqueId("f");
|
||||
const filter = this._svg.filter(this._getSvgDef(), filterId, 0, 0, 1, 1);
|
||||
this._svg.filters.flood(filter, null, "#" + this.state.bkcolor.toHex(), 1.0);
|
||||
this._svg.filters.composite(filter, null, null, "SourceGraphic");
|
||||
this.state._svgtextbkfilter = filter;
|
||||
}
|
||||
|
||||
opts.filter = "url(#" + $(this.state._svgtextbkfilter).attr("id") + ")";
|
||||
}
|
||||
this._svg.text(this.state._svggroup, x, y, text, opts);
|
||||
}
|
||||
|
||||
public extTextOut(x: number, y: number, text: string, fwOpts: number, rect: Rect, dx: number[]) {
|
||||
Helper.log("[gdi] extTextOut: x=" + x + " y=" + y + " text=" + text
|
||||
+ " with font " + this.state.selected.font.toString());
|
||||
x = this._todevX(x);
|
||||
y = this._todevY(y);
|
||||
Helper.log("[gdi] extTextOut: TRANSLATED: x=" + x + " y=" + y);
|
||||
this._pushGroup();
|
||||
|
||||
const opts = this._applyOpts(null, false, false, true);
|
||||
if (this.state.selected.font.escapement !== 0) {
|
||||
opts.transform = "rotate(" + [(-this.state.selected.font.escapement / 10), x, y] + ")";
|
||||
opts.style = "dominant-baseline: middle; text-anchor: start;";
|
||||
}
|
||||
if (this.state.bkmode === Helper.GDI.MixMode.OPAQUE) {
|
||||
if (this.state._svgtextbkfilter == null) {
|
||||
const filterId = Helper._makeUniqueId("f");
|
||||
const filter = this._svg.filter(this._getSvgDef(), filterId, 0, 0, 1, 1);
|
||||
this._svg.filters.flood(filter, null, "#" + this.state.bkcolor.toHex(), 1.0);
|
||||
this._svg.filters.composite(filter, null, null, "SourceGraphic");
|
||||
this.state._svgtextbkfilter = filter;
|
||||
}
|
||||
|
||||
opts.filter = "url(#" + $(this.state._svgtextbkfilter).attr("id") + ")";
|
||||
}
|
||||
this._svg.text(this.state._svggroup, x, y, text, opts);
|
||||
}
|
||||
|
||||
public lineTo(x: number, y: number) {
|
||||
Helper.log("[gdi] lineTo: x=" + x + " y=" + y + " with pen " + this.state.selected.pen.toString());
|
||||
const toX = this._todevX(x);
|
||||
const toY = this._todevY(y);
|
||||
const fromX = this._todevX(this.state.x);
|
||||
const fromY = this._todevY(this.state.y);
|
||||
|
||||
// Update position
|
||||
this.state.x = x;
|
||||
this.state.y = y;
|
||||
|
||||
Helper.log("[gdi] lineTo: TRANSLATED: toX=" + toX + " toY=" + toY + " fromX=" + fromX + " fromY=" + fromY);
|
||||
this._pushGroup();
|
||||
|
||||
const opts = this._applyOpts(null, true, false, false);
|
||||
this._svg.line(this.state._svggroup, fromX, fromY, toX, toY, opts);
|
||||
}
|
||||
|
||||
public moveTo(x: number, y: number) {
|
||||
Helper.log("[gdi] moveTo: x=" + x + " y=" + y);
|
||||
this.state.x = x;
|
||||
this.state.y = y;
|
||||
}
|
||||
|
||||
public polygon(points: PointS[], first: boolean) {
|
||||
Helper.log("[gdi] polygon: points=" + points + " with pen " + this.state.selected.pen.toString()
|
||||
+ " and brush " + this.state.selected.brush.toString());
|
||||
const pts = [];
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const point = points[i];
|
||||
pts.push([this._todevX(point.x), this._todevY(point.y)]);
|
||||
}
|
||||
Helper.log("[gdi] polygon: TRANSLATED: pts=" + pts);
|
||||
if (first) {
|
||||
this._pushGroup();
|
||||
}
|
||||
const opts = {
|
||||
"fill-rule": this.state.polyfillmode === Helper.GDI.PolyFillMode.ALTERNATE ? "evenodd" : "nonzero",
|
||||
};
|
||||
this._applyOpts(opts, true, true, false);
|
||||
this._svg.polygon(this.state._svggroup, pts, opts);
|
||||
}
|
||||
|
||||
public polyPolygon(polygons: PointS[][]) {
|
||||
Helper.log("[gdi] polyPolygon: polygons.length=" + polygons.length
|
||||
+ " with pen " + this.state.selected.pen.toString()
|
||||
+ " and brush " + this.state.selected.brush.toString());
|
||||
|
||||
const cnt = polygons.length;
|
||||
for (let i = 0; i < cnt; i++) {
|
||||
this.polygon(polygons[i], i === 0);
|
||||
}
|
||||
}
|
||||
|
||||
public polyline(points: PointS[]) {
|
||||
Helper.log("[gdi] polyline: points=" + points + " with pen " + this.state.selected.pen.toString());
|
||||
const pts = [];
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const point = points[i];
|
||||
pts.push([this._todevX(point.x), this._todevY(point.y)]);
|
||||
}
|
||||
Helper.log("[gdi] polyline: TRANSLATED: pts=" + pts);
|
||||
this._pushGroup();
|
||||
const opts = this._applyOpts({fill: "none"}, true, false, false);
|
||||
this._svg.polyline(this.state._svggroup, pts, opts);
|
||||
}
|
||||
|
||||
public ellipse(rect: Rect) {
|
||||
Helper.log("[gdi] ellipse: rect=" + rect.toString() + " with pen " + this.state.selected.pen.toString()
|
||||
+ " and brush " + this.state.selected.brush.toString());
|
||||
const bottom = this._todevY(rect.bottom);
|
||||
const right = this._todevX(rect.right);
|
||||
const top = this._todevY(rect.top);
|
||||
const left = this._todevX(rect.left);
|
||||
Helper.log("[gdi] ellipse: TRANSLATED: bottom=" + bottom + " right=" + right + " top=" + top + " left=" + left);
|
||||
this._pushGroup();
|
||||
const width2 = (right - left) / 2;
|
||||
const height2 = (bottom - top) / 2;
|
||||
const opts = this._applyOpts(null, true, true, false);
|
||||
this._svg.ellipse(this.state._svggroup, left + width2, top + height2, width2, height2, opts);
|
||||
}
|
||||
|
||||
public excludeClipRect(rect: Rect) {
|
||||
Helper.log("[gdi] excludeClipRect: rect=" + rect.toString());
|
||||
this._getClipRgn().subtract(rect);
|
||||
}
|
||||
|
||||
public intersectClipRect(rect: Rect) {
|
||||
Helper.log("[gdi] intersectClipRect: rect=" + rect.toString());
|
||||
this._getClipRgn().intersect(rect);
|
||||
}
|
||||
|
||||
public offsetClipRgn(offX: number, offY: number) {
|
||||
Helper.log("[gdi] offsetClipRgn: offX=" + offX + " offY=" + offY);
|
||||
this._getClipRgn().offset(offX, offY);
|
||||
}
|
||||
|
||||
public setTextAlign(textAlignmentMode: number) {
|
||||
Helper.log("[gdi] setTextAlign: textAlignmentMode=0x" + textAlignmentMode.toString(16));
|
||||
this.state.textalign = textAlignmentMode;
|
||||
}
|
||||
|
||||
public setBkMode(bkMode: number) {
|
||||
Helper.log("[gdi] setBkMode: bkMode=0x" + bkMode.toString(16));
|
||||
this.state.bkmode = bkMode;
|
||||
}
|
||||
|
||||
public setTextColor(textColor: ColorRef) {
|
||||
Helper.log("[gdi] setTextColor: textColor=" + textColor.toString());
|
||||
this.state.textcolor = textColor;
|
||||
}
|
||||
|
||||
public setBkColor(bkColor: ColorRef) {
|
||||
Helper.log("[gdi] setBkColor: bkColor=" + bkColor.toString());
|
||||
this.state.bkcolor = bkColor;
|
||||
this.state._svgtextbkfilter = null;
|
||||
}
|
||||
|
||||
public setPolyFillMode(polyFillMode: number) {
|
||||
Helper.log("[gdi] setPolyFillMode: polyFillMode=" + polyFillMode);
|
||||
this.state.polyfillmode = polyFillMode;
|
||||
}
|
||||
|
||||
public createBrush(brush: Brush) {
|
||||
const idx = this._storeObject(brush);
|
||||
Helper.log("[gdi] createBrush: brush=" + brush.toString() + " with handle " + idx);
|
||||
}
|
||||
|
||||
public createFont(font: Font) {
|
||||
const idx = this._storeObject(font);
|
||||
Helper.log("[gdi] createFont: font=" + font.toString() + " with handle " + idx);
|
||||
}
|
||||
|
||||
public createPen(pen: Pen) {
|
||||
const idx = this._storeObject(pen);
|
||||
Helper.log("[gdi] createPen: pen=" + pen.toString() + " width handle " + idx);
|
||||
}
|
||||
|
||||
public createPalette(palette: Palette) {
|
||||
const idx = this._storeObject(palette);
|
||||
Helper.log("[gdi] createPalette: palette=" + palette.toString() + " width handle " + idx);
|
||||
}
|
||||
|
||||
public createRegion(region: Region) {
|
||||
const idx = this._storeObject(region);
|
||||
Helper.log("[gdi] createRegion: region=" + region.toString() + " width handle " + idx);
|
||||
}
|
||||
|
||||
public createPatternBrush(patternBrush: Brush) {
|
||||
const idx = this._storeObject(patternBrush);
|
||||
Helper.log("[gdi] createRegion: region=" + patternBrush.toString() + " width handle " + idx);
|
||||
}
|
||||
|
||||
public selectObject(objIdx: number, checkType: string) {
|
||||
const obj = this._getObject(objIdx);
|
||||
if (obj != null && (checkType == null || obj.type === checkType)) {
|
||||
this._selectObject(obj);
|
||||
Helper.log("[gdi] selectObject: objIdx=" + objIdx
|
||||
+ (obj ? " selected " + obj.type + ": " + obj.toString() : "[invalid index]"));
|
||||
} else {
|
||||
Helper.log("[gdi] selectObject: objIdx=" + objIdx
|
||||
+ (obj ? " invalid object type: " + obj.type : "[invalid index]"));
|
||||
}
|
||||
}
|
||||
|
||||
public deleteObject(objIdx: number) {
|
||||
const ret = this._deleteObject(objIdx);
|
||||
Helper.log("[gdi] deleteObject: objIdx=" + objIdx + (ret ? " deleted object" : "[invalid index]"));
|
||||
}
|
||||
|
||||
private _pushGroup() {
|
||||
if (this.state._svggroup == null || this.state._svgclipChanged) {
|
||||
this.state._svgclipChanged = false;
|
||||
this.state._svgtextbkfilter = null;
|
||||
@@ -180,7 +545,7 @@ export class GDIContext {
|
||||
}
|
||||
}
|
||||
|
||||
_storeObject(obj: Obj) {
|
||||
private _storeObject(obj: Obj) {
|
||||
let i = 0;
|
||||
while (this.objects[i.toString()] != null && i <= 65535) {
|
||||
i++;
|
||||
@@ -194,7 +559,7 @@ export class GDIContext {
|
||||
return i;
|
||||
}
|
||||
|
||||
_getObject(objIdx: number) {
|
||||
private _getObject(objIdx: number) {
|
||||
const obj = this.objects[objIdx.toString()];
|
||||
if (obj == null) {
|
||||
Helper.log("[gdi] No object with handle " + objIdx);
|
||||
@@ -202,14 +567,14 @@ export class GDIContext {
|
||||
return obj;
|
||||
}
|
||||
|
||||
_getSvgDef() {
|
||||
private _getSvgDef() {
|
||||
if (this._svgdefs == null) {
|
||||
this._svgdefs = this._svg.defs();
|
||||
}
|
||||
return this._svgdefs;
|
||||
}
|
||||
|
||||
_getSvgClipPathForRegion(region: Region) {
|
||||
private _getSvgClipPathForRegion(region: Region) {
|
||||
for (const existingId in this._svgClipPaths) {
|
||||
const rgn = this._svgClipPaths[existingId];
|
||||
if (rgn === region) {
|
||||
@@ -242,7 +607,7 @@ export class GDIContext {
|
||||
return id;
|
||||
}
|
||||
|
||||
_getSvgPatternForBrush(brush: Brush) {
|
||||
private _getSvgPatternForBrush(brush: Brush) {
|
||||
for (const existingId in this._svgPatterns) {
|
||||
const pat = this._svgPatterns[existingId];
|
||||
if (pat === brush) {
|
||||
@@ -274,14 +639,14 @@ export class GDIContext {
|
||||
return id;
|
||||
}
|
||||
|
||||
_selectObject(obj: Obj) {
|
||||
private _selectObject(obj: Obj) {
|
||||
this.state.selected[obj.type] = obj;
|
||||
if (obj.type === "region") {
|
||||
this.state._svgclipChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
_deleteObject(objIdx: number) {
|
||||
private _deleteObject(objIdx: number) {
|
||||
const obj = this.objects[objIdx.toString()];
|
||||
if (obj != null) {
|
||||
for (let i = 0; i < this.statestack.length; i++) {
|
||||
@@ -298,7 +663,7 @@ export class GDIContext {
|
||||
return false;
|
||||
}
|
||||
|
||||
_getClipRgn() {
|
||||
private _getClipRgn() {
|
||||
if (this.state.clip != null) {
|
||||
if (!this.state.ownclip) {
|
||||
this.state.clip = this.state.clip.clone();
|
||||
@@ -315,179 +680,55 @@ export class GDIContext {
|
||||
return this.state.clip;
|
||||
}
|
||||
|
||||
_todevX(val: number) {
|
||||
private _todevX(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.wx) * (this.state.vw / this.state.ww)) + this.state.vx;
|
||||
}
|
||||
|
||||
_todevY(val: number) {
|
||||
private _todevY(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.wy) * (this.state.vh / this.state.wh)) + this.state.vy;
|
||||
}
|
||||
|
||||
_todevW(val: number) {
|
||||
private _todevW(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val * (this.state.vw / this.state.ww)) + this.state.vx;
|
||||
}
|
||||
|
||||
_todevH(val: number) {
|
||||
private _todevH(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val * (this.state.vh / this.state.wh)) + this.state.vy;
|
||||
}
|
||||
|
||||
_tologicalX(val: number) {
|
||||
private _tologicalX(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.vx) / (this.state.vw / this.state.ww)) + this.state.wx;
|
||||
}
|
||||
|
||||
_tologicalY(val: number) {
|
||||
private _tologicalY(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor((val - this.state.vy) / (this.state.vh / this.state.wh)) + this.state.wy;
|
||||
}
|
||||
|
||||
_tologicalW(val: number) {
|
||||
private _tologicalW(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val / (this.state.vw / this.state.ww)) + this.state.wx;
|
||||
}
|
||||
|
||||
_tologicalH(val: number) {
|
||||
private _tologicalH(val: number) {
|
||||
// http://wvware.sourceforge.net/caolan/mapmode.html
|
||||
// logical -> device
|
||||
return Math.floor(val / (this.state.vh / this.state.wh)) + this.state.wy;
|
||||
}
|
||||
|
||||
setMapMode(mode: number) {
|
||||
Helper.log("[gdi] setMapMode: mode=" + mode);
|
||||
this.state.mapmode = mode;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
setWindowOrg(x: number, y: number) {
|
||||
Helper.log("[gdi] setWindowOrg: x=" + x + " y=" + y);
|
||||
this.state.wx = x;
|
||||
this.state.wy = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
setWindowExt(x: number, y: number) {
|
||||
Helper.log("[gdi] setWindowExt: x=" + x + " y=" + y);
|
||||
this.state.ww = x;
|
||||
this.state.wh = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
offsetWindowOrg(offX: number, offY: number) {
|
||||
Helper.log("[gdi] offsetWindowOrg: offX=" + offX + " offY=" + offY);
|
||||
this.state.wx += offX;
|
||||
this.state.wy += offY;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
setViewportOrg(x: number, y: number) {
|
||||
Helper.log("[gdi] setViewportOrg: x=" + x + " y=" + y);
|
||||
this.state.vx = x;
|
||||
this.state.vy = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
setViewportExt(x: number, y: number) {
|
||||
Helper.log("[gdi] setViewportExt: x=" + x + " y=" + y);
|
||||
this.state.vw = x;
|
||||
this.state.vh = y;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
offsetViewportOrg(offX: number, offY: number) {
|
||||
Helper.log("[gdi] offsetViewportOrg: offX=" + offX + " offY=" + offY);
|
||||
this.state.vx += offX;
|
||||
this.state.vy += offY;
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
saveDC() {
|
||||
Helper.log("[gdi] saveDC");
|
||||
const prevstate = this.state;
|
||||
this.state = new GDIContextState(this.state);
|
||||
this.statestack.push(prevstate);
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
restoreDC(saved: number) {
|
||||
Helper.log("[gdi] restoreDC: saved=" + saved);
|
||||
if (this.statestack.length > 1) {
|
||||
if (saved === -1) {
|
||||
this.state = this.statestack.pop();
|
||||
} else if (saved < -1) {
|
||||
throw new WMFJSError("restoreDC: relative restore not implemented");
|
||||
} else if (saved > 1) {
|
||||
throw new WMFJSError("restoreDC: absolute restore not implemented");
|
||||
}
|
||||
} else {
|
||||
throw new WMFJSError("No saved contexts");
|
||||
}
|
||||
|
||||
this.state._svggroup = null;
|
||||
}
|
||||
|
||||
escape(func: number, blob: Blob, offset: number, count: number) {
|
||||
Helper.log("[gdi] escape: func=" + func + " offset=" + offset + " count=" + count);
|
||||
}
|
||||
|
||||
setStretchBltMode(stretchMode: number) {
|
||||
Helper.log("[gdi] setStretchBltMode: stretchMode=" + stretchMode);
|
||||
}
|
||||
|
||||
stretchDib(srcX: number, srcY: number, srcW: number, srcH: number,
|
||||
dstX: number, dstY: number, dstW: number, dstH: number,
|
||||
rasterOp: number, colorUsage: number, dib: DIBitmap) {
|
||||
Helper.log("[gdi] stretchDib: srcX=" + srcX + " srcY=" + srcY + " srcW=" + srcW + " srcH=" + srcH
|
||||
+ " dstX=" + dstX + " dstY=" + dstY + " dstW=" + dstW + " dstH=" + dstH
|
||||
+ " rasterOp=0x" + rasterOp.toString(16));
|
||||
srcX = this._todevX(srcX);
|
||||
srcY = this._todevY(srcY);
|
||||
srcW = this._todevW(srcW);
|
||||
srcH = this._todevH(srcH);
|
||||
dstX = this._todevX(dstX);
|
||||
dstY = this._todevY(dstY);
|
||||
dstW = this._todevW(dstW);
|
||||
dstH = this._todevH(dstH);
|
||||
Helper.log("[gdi] stretchDib: TRANSLATED: srcX=" + srcX + " srcY=" + srcY + " srcW=" + srcW + " srcH=" + srcH
|
||||
+ " dstX=" + dstX + " dstY=" + dstY + " dstW=" + dstW + " dstH=" + dstH
|
||||
+ " rasterOp=0x" + rasterOp.toString(16) + " colorUsage=0x" + colorUsage.toString(16));
|
||||
this._pushGroup();
|
||||
this._svg.image(this.state._svggroup, dstX, dstY, dstW, dstH, dib.base64ref());
|
||||
}
|
||||
|
||||
stretchDibBits(srcX: number, srcY: number, srcW: number, srcH: number,
|
||||
dstX: number, dstY: number, dstW: number, dstH: number,
|
||||
rasterOp: number, dib: DIBitmap) {
|
||||
Helper.log("[gdi] stretchDibBits: srcX=" + srcX + " srcY=" + srcY + " srcW=" + srcW + " srcH=" + srcH
|
||||
+ " dstX=" + dstX + " dstY=" + dstY + " dstW=" + dstW + " dstH=" + dstH
|
||||
+ " rasterOp=0x" + rasterOp.toString(16));
|
||||
srcX = this._todevX(srcX);
|
||||
srcY = this._todevY(srcY);
|
||||
srcW = this._todevW(srcW);
|
||||
srcH = this._todevH(srcH);
|
||||
dstX = this._todevX(dstX);
|
||||
dstY = this._todevY(dstY);
|
||||
dstW = this._todevW(dstW);
|
||||
dstH = this._todevH(dstH);
|
||||
Helper.log("[gdi] stretchDibBits: TRANSLATED:"
|
||||
+ " srcX=" + srcX + " srcY=" + srcY + " srcW=" + srcW + " srcH=" + srcH
|
||||
+ " dstX=" + dstX + " dstY=" + dstY + " dstW=" + dstW + " dstH=" + dstH
|
||||
+ " rasterOp=0x" + rasterOp.toString(16));
|
||||
this._pushGroup();
|
||||
this._svg.image(this.state._svggroup, dstX, dstY, dstW, dstH, dib.base64ref());
|
||||
}
|
||||
|
||||
_applyOpts(opts: any, usePen: boolean, useBrush: boolean, useFont: boolean) {
|
||||
private _applyOpts(opts: any, usePen: boolean, useBrush: boolean, useFont: boolean) {
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
@@ -513,9 +754,9 @@ export class GDIContext {
|
||||
opts["stroke-linejoin"] = "bevel";
|
||||
} else if ((pen.join & Helper.GDI.PenStyle.PS_JOIN_MITER) !== 0) {
|
||||
opts["stroke-linejoin"] = "miter";
|
||||
} else {
|
||||
} else {
|
||||
opts["stroke-linejoin"] = "round";
|
||||
}
|
||||
}
|
||||
|
||||
const dashWidth = opts.strokeWidth * 4;
|
||||
const dotSpacing = opts.strokeWidth * 2;
|
||||
@@ -563,245 +804,4 @@ export class GDIContext {
|
||||
}
|
||||
return opts;
|
||||
}
|
||||
|
||||
rectangle(rect: Rect, rw: number, rh: number) {
|
||||
Helper.log("[gdi] rectangle: rect=" + rect.toString() + " with pen " + this.state.selected.pen.toString()
|
||||
+ " and brush " + this.state.selected.brush.toString());
|
||||
const bottom = this._todevY(rect.bottom);
|
||||
const right = this._todevX(rect.right);
|
||||
const top = this._todevY(rect.top);
|
||||
const left = this._todevX(rect.left);
|
||||
rw = this._todevH(rw);
|
||||
rh = this._todevH(rh);
|
||||
Helper.log("[gdi] rectangle: TRANSLATED: bottom=" + bottom + " right=" + right + " top=" + top
|
||||
+ " left=" + left + " rh=" + rh + " rw=" + rw);
|
||||
this._pushGroup();
|
||||
|
||||
const opts = this._applyOpts(null, true, true, false);
|
||||
this._svg.rect(this.state._svggroup, left, top, right - left, bottom - top, rw / 2, rh / 2, opts);
|
||||
}
|
||||
|
||||
textOut(x: number, y: number, text: string) {
|
||||
Helper.log("[gdi] textOut: x=" + x + " y=" + y + " text=" + text
|
||||
+ " with font " + this.state.selected.font.toString());
|
||||
x = this._todevX(x);
|
||||
y = this._todevY(y);
|
||||
Helper.log("[gdi] textOut: TRANSLATED: x=" + x + " y=" + y);
|
||||
this._pushGroup();
|
||||
|
||||
const opts = this._applyOpts(null, false, false, true);
|
||||
if (this.state.selected.font.escapement !== 0) {
|
||||
opts.transform = "rotate(" + [(-this.state.selected.font.escapement / 10), x, y] + ")";
|
||||
opts.style = "dominant-baseline: middle; text-anchor: start;";
|
||||
}
|
||||
if (this.state.bkmode === Helper.GDI.MixMode.OPAQUE) {
|
||||
if (this.state._svgtextbkfilter == null) {
|
||||
const filterId = Helper._makeUniqueId("f");
|
||||
const filter = this._svg.filter(this._getSvgDef(), filterId, 0, 0, 1, 1);
|
||||
this._svg.filters.flood(filter, null, "#" + this.state.bkcolor.toHex(), 1.0);
|
||||
this._svg.filters.composite(filter, null, null, "SourceGraphic");
|
||||
this.state._svgtextbkfilter = filter;
|
||||
}
|
||||
|
||||
opts.filter = "url(#" + $(this.state._svgtextbkfilter).attr("id") + ")";
|
||||
}
|
||||
this._svg.text(this.state._svggroup, x, y, text, opts);
|
||||
}
|
||||
|
||||
extTextOut(x: number, y: number, text: string, fwOpts: number, rect: Rect, dx: number[]) {
|
||||
Helper.log("[gdi] extTextOut: x=" + x + " y=" + y + " text=" + text
|
||||
+ " with font " + this.state.selected.font.toString());
|
||||
x = this._todevX(x);
|
||||
y = this._todevY(y);
|
||||
Helper.log("[gdi] extTextOut: TRANSLATED: x=" + x + " y=" + y);
|
||||
this._pushGroup();
|
||||
|
||||
const opts = this._applyOpts(null, false, false, true);
|
||||
if (this.state.selected.font.escapement !== 0) {
|
||||
opts.transform = "rotate(" + [(-this.state.selected.font.escapement / 10), x, y] + ")";
|
||||
opts.style = "dominant-baseline: middle; text-anchor: start;";
|
||||
}
|
||||
if (this.state.bkmode === Helper.GDI.MixMode.OPAQUE) {
|
||||
if (this.state._svgtextbkfilter == null) {
|
||||
const filterId = Helper._makeUniqueId("f");
|
||||
const filter = this._svg.filter(this._getSvgDef(), filterId, 0, 0, 1, 1);
|
||||
this._svg.filters.flood(filter, null, "#" + this.state.bkcolor.toHex(), 1.0);
|
||||
this._svg.filters.composite(filter, null, null, "SourceGraphic");
|
||||
this.state._svgtextbkfilter = filter;
|
||||
}
|
||||
|
||||
opts.filter = "url(#" + $(this.state._svgtextbkfilter).attr("id") + ")";
|
||||
}
|
||||
this._svg.text(this.state._svggroup, x, y, text, opts);
|
||||
}
|
||||
|
||||
lineTo(x: number, y: number) {
|
||||
Helper.log("[gdi] lineTo: x=" + x + " y=" + y + " with pen " + this.state.selected.pen.toString());
|
||||
const toX = this._todevX(x);
|
||||
const toY = this._todevY(y);
|
||||
const fromX = this._todevX(this.state.x);
|
||||
const fromY = this._todevY(this.state.y);
|
||||
|
||||
// Update position
|
||||
this.state.x = x;
|
||||
this.state.y = y;
|
||||
|
||||
Helper.log("[gdi] lineTo: TRANSLATED: toX=" + toX + " toY=" + toY + " fromX=" + fromX + " fromY=" + fromY);
|
||||
this._pushGroup();
|
||||
|
||||
const opts = this._applyOpts(null, true, false, false);
|
||||
this._svg.line(this.state._svggroup, fromX, fromY, toX, toY, opts);
|
||||
}
|
||||
|
||||
moveTo(x: number, y: number) {
|
||||
Helper.log("[gdi] moveTo: x=" + x + " y=" + y);
|
||||
this.state.x = x;
|
||||
this.state.y = y;
|
||||
}
|
||||
|
||||
polygon(points: PointS[], first: boolean) {
|
||||
Helper.log("[gdi] polygon: points=" + points + " with pen " + this.state.selected.pen.toString()
|
||||
+ " and brush " + this.state.selected.brush.toString());
|
||||
const pts = [];
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const point = points[i];
|
||||
pts.push([this._todevX(point.x), this._todevY(point.y)]);
|
||||
}
|
||||
Helper.log("[gdi] polygon: TRANSLATED: pts=" + pts);
|
||||
if (first) {
|
||||
this._pushGroup();
|
||||
}
|
||||
const opts = {
|
||||
"fill-rule": this.state.polyfillmode === Helper.GDI.PolyFillMode.ALTERNATE ? "evenodd" : "nonzero",
|
||||
};
|
||||
this._applyOpts(opts, true, true, false);
|
||||
this._svg.polygon(this.state._svggroup, pts, opts);
|
||||
}
|
||||
|
||||
polyPolygon(polygons: PointS[][]) {
|
||||
Helper.log("[gdi] polyPolygon: polygons.length=" + polygons.length
|
||||
+ " with pen " + this.state.selected.pen.toString()
|
||||
+ " and brush " + this.state.selected.brush.toString());
|
||||
|
||||
const cnt = polygons.length;
|
||||
for (let i = 0; i < cnt; i++) {
|
||||
this.polygon(polygons[i], i === 0);
|
||||
}
|
||||
}
|
||||
|
||||
polyline(points: PointS[]) {
|
||||
Helper.log("[gdi] polyline: points=" + points + " with pen " + this.state.selected.pen.toString());
|
||||
const pts = [];
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const point = points[i];
|
||||
pts.push([this._todevX(point.x), this._todevY(point.y)]);
|
||||
}
|
||||
Helper.log("[gdi] polyline: TRANSLATED: pts=" + pts);
|
||||
this._pushGroup();
|
||||
const opts = this._applyOpts({fill: "none"}, true, false, false);
|
||||
this._svg.polyline(this.state._svggroup, pts, opts);
|
||||
}
|
||||
|
||||
ellipse(rect: Rect) {
|
||||
Helper.log("[gdi] ellipse: rect=" + rect.toString() + " with pen " + this.state.selected.pen.toString()
|
||||
+ " and brush " + this.state.selected.brush.toString());
|
||||
const bottom = this._todevY(rect.bottom);
|
||||
const right = this._todevX(rect.right);
|
||||
const top = this._todevY(rect.top);
|
||||
const left = this._todevX(rect.left);
|
||||
Helper.log("[gdi] ellipse: TRANSLATED: bottom=" + bottom + " right=" + right + " top=" + top + " left=" + left);
|
||||
this._pushGroup();
|
||||
const width2 = (right - left) / 2;
|
||||
const height2 = (bottom - top) / 2;
|
||||
const opts = this._applyOpts(null, true, true, false);
|
||||
this._svg.ellipse(this.state._svggroup, left + width2, top + height2, width2, height2, opts);
|
||||
}
|
||||
|
||||
excludeClipRect(rect: Rect) {
|
||||
Helper.log("[gdi] excludeClipRect: rect=" + rect.toString());
|
||||
this._getClipRgn().subtract(rect);
|
||||
}
|
||||
|
||||
intersectClipRect(rect: Rect) {
|
||||
Helper.log("[gdi] intersectClipRect: rect=" + rect.toString());
|
||||
this._getClipRgn().intersect(rect);
|
||||
}
|
||||
|
||||
offsetClipRgn(offX: number, offY: number) {
|
||||
Helper.log("[gdi] offsetClipRgn: offX=" + offX + " offY=" + offY);
|
||||
this._getClipRgn().offset(offX, offY);
|
||||
}
|
||||
|
||||
setTextAlign(textAlignmentMode: number) {
|
||||
Helper.log("[gdi] setTextAlign: textAlignmentMode=0x" + textAlignmentMode.toString(16));
|
||||
this.state.textalign = textAlignmentMode;
|
||||
}
|
||||
|
||||
setBkMode(bkMode: number) {
|
||||
Helper.log("[gdi] setBkMode: bkMode=0x" + bkMode.toString(16));
|
||||
this.state.bkmode = bkMode;
|
||||
}
|
||||
|
||||
setTextColor(textColor: ColorRef) {
|
||||
Helper.log("[gdi] setTextColor: textColor=" + textColor.toString());
|
||||
this.state.textcolor = textColor;
|
||||
}
|
||||
|
||||
setBkColor(bkColor: ColorRef) {
|
||||
Helper.log("[gdi] setBkColor: bkColor=" + bkColor.toString());
|
||||
this.state.bkcolor = bkColor;
|
||||
this.state._svgtextbkfilter = null;
|
||||
}
|
||||
|
||||
setPolyFillMode(polyFillMode: number) {
|
||||
Helper.log("[gdi] setPolyFillMode: polyFillMode=" + polyFillMode);
|
||||
this.state.polyfillmode = polyFillMode;
|
||||
}
|
||||
|
||||
createBrush(brush: Brush) {
|
||||
const idx = this._storeObject(brush);
|
||||
Helper.log("[gdi] createBrush: brush=" + brush.toString() + " with handle " + idx);
|
||||
}
|
||||
|
||||
createFont(font: Font) {
|
||||
const idx = this._storeObject(font);
|
||||
Helper.log("[gdi] createFont: font=" + font.toString() + " with handle " + idx);
|
||||
}
|
||||
|
||||
createPen(pen: Pen) {
|
||||
const idx = this._storeObject(pen);
|
||||
Helper.log("[gdi] createPen: pen=" + pen.toString() + " width handle " + idx);
|
||||
}
|
||||
|
||||
createPalette(palette: Palette) {
|
||||
const idx = this._storeObject(palette);
|
||||
Helper.log("[gdi] createPalette: palette=" + palette.toString() + " width handle " + idx);
|
||||
}
|
||||
|
||||
createRegion(region: Region) {
|
||||
const idx = this._storeObject(region);
|
||||
Helper.log("[gdi] createRegion: region=" + region.toString() + " width handle " + idx);
|
||||
}
|
||||
|
||||
createPatternBrush(patternBrush: Brush) {
|
||||
const idx = this._storeObject(patternBrush);
|
||||
Helper.log("[gdi] createRegion: region=" + patternBrush.toString() + " width handle " + idx);
|
||||
}
|
||||
|
||||
selectObject(objIdx: number, checkType: string) {
|
||||
const obj = this._getObject(objIdx);
|
||||
if (obj != null && (checkType == null || obj.type === checkType)) {
|
||||
this._selectObject(obj);
|
||||
Helper.log("[gdi] selectObject: objIdx=" + objIdx
|
||||
+ (obj ? " selected " + obj.type + ": " + obj.toString() : "[invalid index]"));
|
||||
} else {
|
||||
Helper.log("[gdi] selectObject: objIdx=" + objIdx
|
||||
+ (obj ? " invalid object type: " + obj.type : "[invalid index]"));
|
||||
}
|
||||
}
|
||||
|
||||
deleteObject(objIdx: number) {
|
||||
const ret = this._deleteObject(objIdx);
|
||||
Helper.log("[gdi] deleteObject: objIdx=" + objIdx + (ret ? " deleted object" : "[invalid index]"));
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -45,7 +45,7 @@ export function loggingEnabled(enabled: boolean) {
|
||||
}
|
||||
|
||||
export class Helper {
|
||||
static GDI = {
|
||||
public static GDI = {
|
||||
METAHEADER_SIZE: 18,
|
||||
BITMAPINFOHEADER_SIZE: 40,
|
||||
BITMAPCOREHEADER_SIZE: 12,
|
||||
@@ -275,27 +275,27 @@ export class Helper {
|
||||
BI_PNG: 5,
|
||||
},
|
||||
};
|
||||
static _uniqueId = 0;
|
||||
public static _uniqueId = 0;
|
||||
|
||||
static log(message: string) {
|
||||
public static log(message: string) {
|
||||
if (isLoggingEnabled) {
|
||||
// tslint:disable-next-line:no-console
|
||||
console.log(message);
|
||||
}
|
||||
}
|
||||
|
||||
static _makeUniqueId(prefix: string) {
|
||||
public static _makeUniqueId(prefix: string) {
|
||||
return "wmfjs_" + prefix + (this._uniqueId++);
|
||||
}
|
||||
|
||||
static _writeUint32Val(uint8arr: Uint8Array, pos: number, val: number) {
|
||||
public static _writeUint32Val(uint8arr: Uint8Array, pos: number, val: number) {
|
||||
uint8arr[pos++] = val & 0xff;
|
||||
uint8arr[pos++] = (val >>> 8) & 0xff;
|
||||
uint8arr[pos++] = (val >>> 16) & 0xff;
|
||||
uint8arr[pos++] = (val >>> 24) & 0xff;
|
||||
}
|
||||
|
||||
static _blobToBinary(blob: Uint8Array) {
|
||||
public static _blobToBinary(blob: Uint8Array) {
|
||||
let ret = "";
|
||||
const len = blob.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
|
||||
+15
-15
@@ -28,8 +28,8 @@ import { Blob } from "./Blob";
|
||||
import { WMFJSError } from "./Helper";
|
||||
|
||||
export class PointS {
|
||||
x: number;
|
||||
y: number;
|
||||
public x: number;
|
||||
public y: number;
|
||||
|
||||
constructor(reader: Blob, x?: number, y?: number) {
|
||||
if (reader != null) {
|
||||
@@ -41,20 +41,20 @@ export class PointS {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new PointS(null, this.x, this.y);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{x: " + this.x + ", y: " + this.y + "}";
|
||||
}
|
||||
}
|
||||
|
||||
export class Rect {
|
||||
bottom: number;
|
||||
right: number;
|
||||
top: number;
|
||||
left: number;
|
||||
public bottom: number;
|
||||
public right: number;
|
||||
public top: number;
|
||||
public left: number;
|
||||
|
||||
constructor(reader: Blob, left?: number, top?: number, right?: number, bottom?: number) {
|
||||
if (reader != null) {
|
||||
@@ -70,20 +70,20 @@ export class Rect {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new Rect(null, this.left, this.top, this.right, this.bottom);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{left: " + this.left + ", top: " + this.top + ", right: " + this.right
|
||||
+ ", bottom: " + this.bottom + "}";
|
||||
}
|
||||
|
||||
empty() {
|
||||
public empty() {
|
||||
return this.left >= this.right || this.top >= this.bottom;
|
||||
}
|
||||
|
||||
intersect(rect: Rect) {
|
||||
public intersect(rect: Rect) {
|
||||
if (this.empty() || rect.empty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -97,17 +97,17 @@ export class Rect {
|
||||
}
|
||||
|
||||
export class Obj {
|
||||
type: string;
|
||||
public type: string;
|
||||
|
||||
constructor(type: string) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
clone(): Obj {
|
||||
public clone(): Obj {
|
||||
throw new WMFJSError("clone not implemented");
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
throw new WMFJSError("toString not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
+16
-16
@@ -29,9 +29,9 @@ import { Helper, WMFJSError } from "./Helper";
|
||||
import { Obj, Rect } from "./Primitives";
|
||||
|
||||
export class Region extends Obj {
|
||||
bounds: Rect;
|
||||
scans: Scan[];
|
||||
complexity: number;
|
||||
public bounds: Rect;
|
||||
public scans: Scan[];
|
||||
public complexity: number;
|
||||
|
||||
constructor(reader: Blob, copy?: Region) {
|
||||
super("region");
|
||||
@@ -73,18 +73,18 @@ export class Region extends Obj {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new Region(null, this);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
const _complexity = ["null", "simple", "complex"];
|
||||
return "{complexity: " + _complexity[this.complexity]
|
||||
+ " bounds: " + (this.bounds != null ? this.bounds.toString() : "[none]")
|
||||
+ " #scans: " + (this.scans != null ? this.scans.length : "[none]") + "}";
|
||||
}
|
||||
|
||||
_updateComplexity() {
|
||||
public _updateComplexity() {
|
||||
if (this.bounds == null) {
|
||||
this.complexity = 0;
|
||||
this.scans = null;
|
||||
@@ -109,7 +109,7 @@ export class Region extends Obj {
|
||||
}
|
||||
}
|
||||
|
||||
subtract(rect: Rect) {
|
||||
public subtract(rect: Rect) {
|
||||
Helper.log("[wmf] Region " + this.toString() + " subtract " + rect.toString());
|
||||
|
||||
if (this.bounds != null) {
|
||||
@@ -236,7 +236,7 @@ export class Region extends Obj {
|
||||
Helper.log("[wmf] Region subtraction -> " + this.toString());
|
||||
}
|
||||
|
||||
intersect(rect: Rect) {
|
||||
public intersect(rect: Rect) {
|
||||
Helper.log("[wmf] Region " + this.toString() + " intersect with " + rect.toString());
|
||||
if (this.bounds != null) {
|
||||
this.bounds = this.bounds.intersect(rect);
|
||||
@@ -296,7 +296,7 @@ export class Region extends Obj {
|
||||
Helper.log("[wmf] Region intersection -> " + this.toString());
|
||||
}
|
||||
|
||||
offset(offX: number, offY: number) {
|
||||
public offset(offX: number, offY: number) {
|
||||
if (this.bounds != null) {
|
||||
this.bounds.left += offX;
|
||||
this.bounds.top += offY;
|
||||
@@ -330,9 +330,9 @@ export function CreateSimpleRegion(left: number, top: number, right: number, bot
|
||||
}
|
||||
|
||||
export class Scan {
|
||||
top: number;
|
||||
bottom: number;
|
||||
scanlines: Array<{left: number, right: number}>;
|
||||
public top: number;
|
||||
public bottom: number;
|
||||
public scanlines: Array<{left: number, right: number}>;
|
||||
|
||||
constructor(reader: Blob, copy?: Scan, top?: number, bottom?: number,
|
||||
scanlines?: Array<{left: number, right: number}>) {
|
||||
@@ -362,11 +362,11 @@ export class Scan {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new Scan(null, this);
|
||||
}
|
||||
|
||||
subtract(left: number, right: number) {
|
||||
public subtract(left: number, right: number) {
|
||||
let i;
|
||||
|
||||
// Keep everything on the left side
|
||||
@@ -411,7 +411,7 @@ export class Scan {
|
||||
return this.scanlines.length > 0;
|
||||
}
|
||||
|
||||
intersect(left: number, right: number) {
|
||||
public intersect(left: number, right: number) {
|
||||
// Get rid of anything that falls entirely outside to the left
|
||||
for (let i = 0; i < this.scanlines.length; i++) {
|
||||
const scanline = this.scanlines[i];
|
||||
@@ -450,7 +450,7 @@ export class Scan {
|
||||
return this.scanlines.length > 0;
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{ #scanlines: " + this.scanlines.length + "}";
|
||||
}
|
||||
}
|
||||
|
||||
+31
-32
@@ -29,7 +29,7 @@ import { GDIContext } from "./GDIContext";
|
||||
import { Helper, WMFJSError } from "./Helper";
|
||||
import { WMFRecords } from "./WMFRecords";
|
||||
|
||||
export class RendererSettings {
|
||||
export interface IRendererSettings {
|
||||
width: string;
|
||||
height: string;
|
||||
xExt: number;
|
||||
@@ -38,14 +38,28 @@ export class RendererSettings {
|
||||
}
|
||||
|
||||
export class Renderer {
|
||||
_img: WMF;
|
||||
private _img: WMF;
|
||||
|
||||
constructor(blob: ArrayBuffer) {
|
||||
this.parse(blob);
|
||||
Helper.log("WMFJS.Renderer instantiated");
|
||||
}
|
||||
|
||||
parse(blob: ArrayBuffer) {
|
||||
public render(info: IRendererSettings) {
|
||||
const img = ($("<div>") as any).svg({
|
||||
onLoad: (svg: any) => {
|
||||
return this._render(svg, info.mapMode, info.xExt, info.yExt);
|
||||
},
|
||||
settings: {
|
||||
viewBox: [0, 0, info.xExt, info.yExt].join(" "),
|
||||
preserveAspectRatio: "none", // TODO: MM_ISOTROPIC vs MM_ANISOTROPIC
|
||||
},
|
||||
});
|
||||
const svgContainer = ($(img[0]) as any).svg("get");
|
||||
return $(svgContainer.root()).attr("width", info.width).attr("height", info.height);
|
||||
}
|
||||
|
||||
private parse(blob: ArrayBuffer) {
|
||||
this._img = null;
|
||||
|
||||
const reader = new Blob(blob);
|
||||
@@ -85,7 +99,7 @@ export class Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
_render(svg: any, mapMode: number, xExt: number, yExt: number) {
|
||||
private _render(svg: any, mapMode: number, xExt: number, yExt: number) {
|
||||
// See https://www-user.tu-chemnitz.de/~ygu/petzold/ch18b.htm
|
||||
const gdi = new GDIContext(svg);
|
||||
gdi.setViewportExt(xExt, yExt);
|
||||
@@ -94,28 +108,13 @@ export class Renderer {
|
||||
this._img.render(gdi);
|
||||
Helper.log("[WMF] <--- DONE RENDERING");
|
||||
}
|
||||
|
||||
render(info: RendererSettings) {
|
||||
const inst = this;
|
||||
const img = ($("<div>") as any).svg({
|
||||
onLoad: (svg: any) => {
|
||||
return this._render(svg, info.mapMode, info.xExt, info.yExt);
|
||||
},
|
||||
settings: {
|
||||
viewBox: [0, 0, info.xExt, info.yExt].join(" "),
|
||||
preserveAspectRatio: "none", // TODO: MM_ISOTROPIC vs MM_ANISOTROPIC
|
||||
},
|
||||
});
|
||||
const svgContainer = ($(img[0]) as any).svg("get");
|
||||
return $(svgContainer.root()).attr("width", info.width).attr("height", info.height);
|
||||
}
|
||||
}
|
||||
|
||||
export class WMFRect16 {
|
||||
left: number;
|
||||
top: number;
|
||||
right: number;
|
||||
bottom: number;
|
||||
private left: number;
|
||||
private top: number;
|
||||
private right: number;
|
||||
private bottom: number;
|
||||
|
||||
constructor(reader: Blob) {
|
||||
this.left = reader.readInt16();
|
||||
@@ -124,15 +123,15 @@ export class WMFRect16 {
|
||||
this.bottom = reader.readInt16();
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{left: " + this.left + ", top: " + this.top + ", right: " + this.right
|
||||
+ ", bottom: " + this.bottom + "}";
|
||||
}
|
||||
}
|
||||
|
||||
export class WMFPlacable {
|
||||
boundingBox: WMFRect16;
|
||||
unitsPerInch: number;
|
||||
private boundingBox: WMFRect16;
|
||||
private unitsPerInch: number;
|
||||
|
||||
constructor(reader: Blob) {
|
||||
reader.skip(2);
|
||||
@@ -145,11 +144,11 @@ export class WMFPlacable {
|
||||
}
|
||||
|
||||
export class WMF {
|
||||
_reader: Blob;
|
||||
_version: number;
|
||||
_hdrsize: number;
|
||||
_placable: WMFPlacable;
|
||||
_records: WMFRecords;
|
||||
private _reader: Blob;
|
||||
private _version: number;
|
||||
private _hdrsize: number;
|
||||
private _placable: WMFPlacable;
|
||||
private _records: WMFRecords;
|
||||
|
||||
constructor(reader: Blob, placable: WMFPlacable, version: number, hdrsize: number) {
|
||||
this._reader = reader;
|
||||
@@ -159,7 +158,7 @@ export class WMF {
|
||||
this._records = new WMFRecords(reader, this._hdrsize);
|
||||
}
|
||||
|
||||
render(gdi: GDIContext) {
|
||||
public render(gdi: GDIContext) {
|
||||
this._records.play(gdi);
|
||||
}
|
||||
}
|
||||
|
||||
+47
-47
@@ -30,9 +30,9 @@ import { Helper } from "./Helper";
|
||||
import { Obj, PointS } from "./Primitives";
|
||||
|
||||
export class ColorRef {
|
||||
r: number;
|
||||
g: number;
|
||||
b: number;
|
||||
public r: number;
|
||||
public g: number;
|
||||
public b: number;
|
||||
|
||||
constructor(reader: Blob, r?: number, g?: number, b?: number) {
|
||||
if (reader != null) {
|
||||
@@ -47,36 +47,36 @@ export class ColorRef {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new ColorRef(null, this.r, this.g, this.b);
|
||||
}
|
||||
|
||||
toHex() {
|
||||
public toHex() {
|
||||
const rgb = (this.r << 16) | (this.g << 8) | this.b;
|
||||
return (0x1000000 + rgb).toString(16).slice(1);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{r: " + this.r + ", g: " + this.g + ", b: " + this.b + "}";
|
||||
}
|
||||
}
|
||||
|
||||
export class Font extends Obj {
|
||||
height: number;
|
||||
width: number;
|
||||
escapement: number;
|
||||
orientation: number;
|
||||
weight: number;
|
||||
italic: number;
|
||||
underline: number;
|
||||
strikeout: number;
|
||||
charset: number;
|
||||
outprecision: number;
|
||||
clipprecision: number;
|
||||
quality: number;
|
||||
pitch: number;
|
||||
family: number;
|
||||
facename: string;
|
||||
public height: number;
|
||||
public width: number;
|
||||
public escapement: number;
|
||||
public orientation: number;
|
||||
public weight: number;
|
||||
public italic: number;
|
||||
public underline: number;
|
||||
public strikeout: number;
|
||||
public charset: number;
|
||||
public outprecision: number;
|
||||
public clipprecision: number;
|
||||
public quality: number;
|
||||
public pitch: number;
|
||||
public family: number;
|
||||
public facename: string;
|
||||
|
||||
constructor(reader: Blob, copy: Font | number) {
|
||||
super("font");
|
||||
@@ -137,22 +137,22 @@ export class Font extends Obj {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new Font(null, this);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
}
|
||||
|
||||
export class Brush extends Obj {
|
||||
style: number;
|
||||
color: ColorRef;
|
||||
pattern: Bitmap16;
|
||||
colorusage: number;
|
||||
dibpatternpt: DIBitmap;
|
||||
hatchstyle: number;
|
||||
public style: number;
|
||||
public color: ColorRef;
|
||||
public pattern: Bitmap16;
|
||||
public colorusage: number;
|
||||
public dibpatternpt: DIBitmap;
|
||||
public hatchstyle: number;
|
||||
|
||||
constructor(reader: Blob, copy: Brush | number, forceDibPattern?: boolean | PatternBitmap16) {
|
||||
super("brush");
|
||||
@@ -211,11 +211,11 @@ export class Brush extends Obj {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new Brush(null, this);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
let ret = "{style: " + this.style;
|
||||
switch (this.style) {
|
||||
case Helper.GDI.BrushStyle.BS_SOLID:
|
||||
@@ -233,11 +233,11 @@ export class Brush extends Obj {
|
||||
}
|
||||
|
||||
export class Pen extends Obj {
|
||||
style: number;
|
||||
width: PointS;
|
||||
color: ColorRef;
|
||||
linecap: number;
|
||||
join: number;
|
||||
public style: number;
|
||||
public width: PointS;
|
||||
public color: ColorRef;
|
||||
public linecap: number;
|
||||
public join: number;
|
||||
|
||||
constructor(reader: Blob, style?: number, width?: PointS, color?: ColorRef, linecap?: number, join?: number) {
|
||||
super("pen");
|
||||
@@ -257,21 +257,21 @@ export class Pen extends Obj {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new Pen(null, this.style, this.width.clone(), this.color.clone(), this.linecap, this.join);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{style: " + this.style + ", width: " + this.width.toString() + ", color: " + this.color.toString()
|
||||
+ ", linecap: " + this.linecap + ", join: " + this.join + "}";
|
||||
}
|
||||
}
|
||||
|
||||
export class PaletteEntry {
|
||||
flag: number;
|
||||
b: number;
|
||||
g: number;
|
||||
r: number;
|
||||
public flag: number;
|
||||
public b: number;
|
||||
public g: number;
|
||||
public r: number;
|
||||
|
||||
constructor(reader: Blob, copy?: PaletteEntry) {
|
||||
if (reader != null) {
|
||||
@@ -287,14 +287,14 @@ export class PaletteEntry {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new PaletteEntry(null, this);
|
||||
}
|
||||
}
|
||||
|
||||
export class Palette extends Obj {
|
||||
start: number;
|
||||
entries: PaletteEntry[];
|
||||
public start: number;
|
||||
public entries: PaletteEntry[];
|
||||
|
||||
constructor(reader: Blob, copy?: Palette) {
|
||||
super("palette");
|
||||
@@ -315,11 +315,11 @@ export class Palette extends Obj {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
public clone() {
|
||||
return new Palette(null, this);
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return "{ #entries: " + this.entries.length + "}"; // TODO
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import { Region } from "./Region";
|
||||
import { Brush, ColorRef, Font, Palette, Pen } from "./Style";
|
||||
|
||||
export class WMFRecords {
|
||||
_records: Array<(gdi: GDIContext) => void>;
|
||||
private _records: Array<(gdi: GDIContext) => void>;
|
||||
|
||||
constructor(reader: Blob, first: number) {
|
||||
this._records = [];
|
||||
@@ -502,7 +502,7 @@ export class WMFRecords {
|
||||
}
|
||||
}
|
||||
|
||||
play(gdi: GDIContext) {
|
||||
public play(gdi: GDIContext) {
|
||||
const len = this._records.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
this._records[i](gdi);
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
"prefer-for-of": false,
|
||||
|
||||
// to be enabled eventually
|
||||
"member-access": false,
|
||||
"forin": false
|
||||
},
|
||||
"defaultSeverity": "error"
|
||||
|
||||
Reference in New Issue
Block a user