dompdf.js 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +5 -0
- package/README.md +168 -79
- package/dist/dom/element-container.d.ts +4 -2
- package/dist/dompdf.esm.js +614 -462
- package/dist/dompdf.esm.js.map +1 -1
- package/dist/dompdf.js +614 -462
- package/dist/dompdf.js.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/lib/__tests__/index.js.map +1 -1
- package/dist/lib/css/property-descriptors/border-style.js.map +1 -1
- package/dist/lib/css/types/color.js.map +1 -1
- package/dist/lib/dom/element-container.js +3 -1
- package/dist/lib/dom/element-container.js.map +1 -1
- package/dist/lib/dom/node-parser.js +15 -7
- package/dist/lib/dom/node-parser.js.map +1 -1
- package/dist/lib/dom/replaced-elements/iframe-element-container.js.map +1 -1
- package/dist/lib/index.js +107 -42
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/render/canvas/foreignobject-renderer.js.map +1 -1
- package/dist/lib/render/canvas/pdf-renderer.js +276 -472
- package/dist/lib/render/canvas/pdf-renderer.js.map +1 -1
- package/dist/lib/render/page-format-map.js +54 -0
- package/dist/lib/render/page-format-map.js.map +1 -0
- package/dist/lib/render/paginate.js +172 -0
- package/dist/lib/render/paginate.js.map +1 -0
- package/dist/render/canvas/pdf-renderer.d.ts +41 -16
- package/dist/render/page-format-map.d.ts +4 -0
- package/dist/render/paginate.d.ts +3 -0
- package/dist/types/dom/element-container.d.ts +4 -2
- package/dist/types/index.d.ts +1 -3
- package/dist/types/render/canvas/pdf-renderer.d.ts +41 -16
- package/dist/types/render/page-format-map.d.ts +4 -0
- package/dist/types/render/paginate.d.ts +3 -0
- package/package.json +135 -134
- package/dist/lib/render/canvas/canvas-renderer2.js +0 -1415
- package/dist/lib/render/canvas/canvas-renderer2.js.map +0 -1
- package/dist/render/canvas/canvas-renderer2.d.ts +0 -81
- package/dist/types/render/canvas/canvas-renderer2.d.ts +0 -81
package/dist/dompdf.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* dompdf.js 1.0
|
|
2
|
+
* dompdf.js 1.1.0 <https://dompdfjs.lisky.com.cn>
|
|
3
3
|
* Copyright (c) 2025 lfc <https://dompdfjs.lisky.com.cn/>
|
|
4
4
|
* Released under MIT License
|
|
5
5
|
*/
|
|
@@ -3497,6 +3497,27 @@
|
|
|
3497
3497
|
return await capture.download({ format, filename, backgroundColor });
|
|
3498
3498
|
};
|
|
3499
3499
|
|
|
3500
|
+
var elementDebuggerAttribute$1 = 'data-html2canvas-debug';
|
|
3501
|
+
var getElementDebugType$1 = function (element) {
|
|
3502
|
+
var attribute = element.getAttribute(elementDebuggerAttribute$1);
|
|
3503
|
+
switch (attribute) {
|
|
3504
|
+
case 'all':
|
|
3505
|
+
return 1 /* DebuggerType.ALL */;
|
|
3506
|
+
case 'clone':
|
|
3507
|
+
return 2 /* DebuggerType.CLONE */;
|
|
3508
|
+
case 'parse':
|
|
3509
|
+
return 3 /* DebuggerType.PARSE */;
|
|
3510
|
+
case 'render':
|
|
3511
|
+
return 4 /* DebuggerType.RENDER */;
|
|
3512
|
+
default:
|
|
3513
|
+
return 0 /* DebuggerType.NONE */;
|
|
3514
|
+
}
|
|
3515
|
+
};
|
|
3516
|
+
var isDebugging$1 = function (element, type) {
|
|
3517
|
+
var elementType = getElementDebugType$1(element);
|
|
3518
|
+
return elementType === 1 /* DebuggerType.ALL */ || type === elementType;
|
|
3519
|
+
};
|
|
3520
|
+
|
|
3500
3521
|
var backgroundClip$1 = {
|
|
3501
3522
|
name: 'background-clip',
|
|
3502
3523
|
initialValue: 'border-box',
|
|
@@ -3788,12 +3809,6 @@
|
|
|
3788
3809
|
return { size: size, shape: shape, stops: stops, position: position, type: 2 /* CSSImageType.RADIAL_GRADIENT */ };
|
|
3789
3810
|
};
|
|
3790
3811
|
|
|
3791
|
-
var isLinearGradient$1 = function (background) {
|
|
3792
|
-
return background.type === 1 /* CSSImageType.LINEAR_GRADIENT */;
|
|
3793
|
-
};
|
|
3794
|
-
var isRadialGradient$1 = function (background) {
|
|
3795
|
-
return background.type === 2 /* CSSImageType.RADIAL_GRADIENT */;
|
|
3796
|
-
};
|
|
3797
3812
|
var image$1 = {
|
|
3798
3813
|
name: 'image',
|
|
3799
3814
|
parse: function (context, value) {
|
|
@@ -5118,27 +5133,6 @@
|
|
|
5118
5133
|
}
|
|
5119
5134
|
};
|
|
5120
5135
|
|
|
5121
|
-
var elementDebuggerAttribute$1 = 'data-html2canvas-debug';
|
|
5122
|
-
var getElementDebugType$1 = function (element) {
|
|
5123
|
-
var attribute = element.getAttribute(elementDebuggerAttribute$1);
|
|
5124
|
-
switch (attribute) {
|
|
5125
|
-
case 'all':
|
|
5126
|
-
return 1 /* DebuggerType.ALL */;
|
|
5127
|
-
case 'clone':
|
|
5128
|
-
return 2 /* DebuggerType.CLONE */;
|
|
5129
|
-
case 'parse':
|
|
5130
|
-
return 3 /* DebuggerType.PARSE */;
|
|
5131
|
-
case 'render':
|
|
5132
|
-
return 4 /* DebuggerType.RENDER */;
|
|
5133
|
-
default:
|
|
5134
|
-
return 0 /* DebuggerType.NONE */;
|
|
5135
|
-
}
|
|
5136
|
-
};
|
|
5137
|
-
var isDebugging$1 = function (element, type) {
|
|
5138
|
-
var elementType = getElementDebugType$1(element);
|
|
5139
|
-
return elementType === 1 /* DebuggerType.ALL */ || type === elementType;
|
|
5140
|
-
};
|
|
5141
|
-
|
|
5142
5136
|
var ElementContainer$1 = /** @class */ (function () {
|
|
5143
5137
|
function ElementContainer(context, element) {
|
|
5144
5138
|
this.context = context;
|
|
@@ -5147,6 +5141,8 @@
|
|
|
5147
5141
|
this.flags = 0;
|
|
5148
5142
|
this.foreignobjectrendering = false;
|
|
5149
5143
|
this.parentforeignobjectrendering = false;
|
|
5144
|
+
this.divisionDisable = false;
|
|
5145
|
+
this.offset = 0;
|
|
5150
5146
|
if (isDebugging$1(element, 3 /* DebuggerType.PARSE */)) {
|
|
5151
5147
|
debugger;
|
|
5152
5148
|
}
|
|
@@ -5916,7 +5912,9 @@
|
|
|
5916
5912
|
}
|
|
5917
5913
|
else if (isElementNode$1(childNode)) {
|
|
5918
5914
|
if (isSlotElement$1(childNode) && childNode.assignedNodes) {
|
|
5919
|
-
childNode
|
|
5915
|
+
childNode
|
|
5916
|
+
.assignedNodes()
|
|
5917
|
+
.forEach(function (childNode) { return parseNodeTree$1(context, childNode, parent, root, foreignObjectRendererList); });
|
|
5920
5918
|
}
|
|
5921
5919
|
else {
|
|
5922
5920
|
var container = createContainer$1(context, childNode);
|
|
@@ -5928,9 +5926,14 @@
|
|
|
5928
5926
|
else if (createsStackingContext$1(container.styles)) {
|
|
5929
5927
|
container.flags |= 2 /* FLAGS.CREATES_STACKING_CONTEXT */;
|
|
5930
5928
|
}
|
|
5931
|
-
if (isElementNode$1(childNode) &&
|
|
5929
|
+
if (isElementNode$1(childNode) &&
|
|
5930
|
+
(childNode.hasAttribute('foreignobjectrendering') || parent.foreignobjectrendering)) {
|
|
5932
5931
|
container.foreignobjectrendering = true;
|
|
5933
5932
|
}
|
|
5933
|
+
if (isElementNode$1(childNode) &&
|
|
5934
|
+
(childNode.hasAttribute('divisionDisable') || parent.divisionDisable)) {
|
|
5935
|
+
container.divisionDisable = true;
|
|
5936
|
+
}
|
|
5934
5937
|
if (LIST_OWNERS$1.indexOf(childNode.tagName) !== -1) {
|
|
5935
5938
|
container.flags |= 8 /* FLAGS.IS_LIST_OWNER */;
|
|
5936
5939
|
}
|
|
@@ -6010,11 +6013,12 @@
|
|
|
6010
6013
|
// 修改 parseNodeTree 调用,传入局部列表
|
|
6011
6014
|
parseNodeTree$1(context, element, container, container, foreignObjectRendererList);
|
|
6012
6015
|
uniqueList = foreignObjectRendererList.filter(function (item, index, self) {
|
|
6013
|
-
return index ===
|
|
6014
|
-
|
|
6015
|
-
|
|
6016
|
-
|
|
6016
|
+
return index ===
|
|
6017
|
+
self.findIndex(function (t) {
|
|
6018
|
+
return t === item;
|
|
6019
|
+
});
|
|
6017
6020
|
});
|
|
6021
|
+
screenshotPromises = uniqueList.map(function (item) { return renderForeignObject(item); });
|
|
6018
6022
|
return [4 /*yield*/, Promise.all(screenshotPromises)];
|
|
6019
6023
|
case 1:
|
|
6020
6024
|
screenshotResults = _a.sent();
|
|
@@ -6097,7 +6101,7 @@
|
|
|
6097
6101
|
case 2:
|
|
6098
6102
|
_a.trys.push([2, 4, , 5]);
|
|
6099
6103
|
return [4 /*yield*/, capture.toPng({
|
|
6100
|
-
quality: 0.1
|
|
6104
|
+
quality: 0.1
|
|
6101
6105
|
// width: Math.ceil(rect.width),
|
|
6102
6106
|
// height: Math.ceil(rect.height)
|
|
6103
6107
|
})];
|
|
@@ -8987,48 +8991,64 @@
|
|
|
8987
8991
|
return root;
|
|
8988
8992
|
};
|
|
8989
8993
|
|
|
8990
|
-
// 遮罩偏移常量
|
|
8991
|
-
// const MASK_OFFSET = 10000;
|
|
8992
|
-
// Canvas渲染器类,继承自Renderer
|
|
8993
8994
|
var CanvasRenderer$1 = /** @class */ (function (_super) {
|
|
8994
8995
|
__extends$1(CanvasRenderer, _super);
|
|
8995
|
-
// 构造函数
|
|
8996
8996
|
function CanvasRenderer(context, options) {
|
|
8997
|
-
var _this = this;
|
|
8998
|
-
|
|
8999
|
-
_this =
|
|
9000
|
-
_this._activeEffects = []; // 活动效果数组
|
|
8997
|
+
var _this = _super.call(this, context, options) || this;
|
|
8998
|
+
_this._activeEffects = [];
|
|
8999
|
+
_this.totalPages = 1;
|
|
9001
9000
|
_this.canvas = options.canvas ? options.canvas : document.createElement('canvas');
|
|
9002
9001
|
_this.ctx = _this.canvas.getContext('2d');
|
|
9003
|
-
// 计算页面尺寸并转换为 pt 单位 (1pt = 1/72 inch, 1px = 1/96 inch)
|
|
9004
9002
|
var pxToPt = function (px) { return px * (72 / 96); };
|
|
9005
|
-
//
|
|
9006
9003
|
var pageWidth = pxToPt(options.width);
|
|
9007
9004
|
var pageHeight = pxToPt(options.height);
|
|
9008
|
-
//
|
|
9005
|
+
// const enc =
|
|
9006
|
+
// this.options.encryption &&
|
|
9007
|
+
// (this.options.encryption.userPassword ||
|
|
9008
|
+
// this.options.encryption.ownerPassword ||
|
|
9009
|
+
// (this.options.encryption.userPermissions && this.options.encryption.userPermissions.length))
|
|
9010
|
+
// ? this.options.encryption
|
|
9011
|
+
// : [];
|
|
9012
|
+
var encOptions = _this.options.encryption
|
|
9013
|
+
? {
|
|
9014
|
+
userPassword: _this.options.encryption.userPassword,
|
|
9015
|
+
ownerPassword: _this.options.encryption.ownerPassword,
|
|
9016
|
+
userPermissions: _this.options.encryption.userPermissions
|
|
9017
|
+
}
|
|
9018
|
+
: undefined;
|
|
9009
9019
|
_this.jspdfCtx = new E$1({
|
|
9010
9020
|
orientation: pageWidth > pageHeight ? 'landscape' : 'portrait',
|
|
9011
9021
|
unit: 'pt',
|
|
9012
|
-
format: [
|
|
9013
|
-
hotfixes: [
|
|
9022
|
+
format: options.pagination && options.format ? options.format : [pageHeight, pageWidth],
|
|
9023
|
+
hotfixes: ['px_scaling'],
|
|
9024
|
+
putOnlyUsedFonts: options.putOnlyUsedFonts,
|
|
9025
|
+
compress: options.compress,
|
|
9026
|
+
precision: options.precision,
|
|
9027
|
+
floatPrecision: options.floatPrecision,
|
|
9028
|
+
encryption: encOptions
|
|
9014
9029
|
});
|
|
9015
|
-
//
|
|
9030
|
+
// orientation: pageWidth > pageHeight ? 'landscape' : 'portrait',
|
|
9031
|
+
// unit: 'pt',
|
|
9032
|
+
// format: options.pagination && options.format ? options.format : [pageHeight, pageWidth],
|
|
9033
|
+
// hotfixes: ['px_scaling'],
|
|
9034
|
+
// putOnlyUsedFonts: options.putOnlyUsedFonts,
|
|
9035
|
+
// compress: options.compress,
|
|
9036
|
+
// precision: options.precision,
|
|
9037
|
+
// floatPrecision: options.floatPrecision,
|
|
9038
|
+
// encryption: enc
|
|
9039
|
+
// });
|
|
9016
9040
|
_this.context2dCtx = _this.jspdfCtx.context2d;
|
|
9017
9041
|
_this.context2dCtx.scale(0.75, 0.75);
|
|
9018
9042
|
_this.context2dCtx.translate(-options.x, -options.y);
|
|
9019
|
-
// 确保字体已加载并注册到 jsPDF
|
|
9020
9043
|
if (options.fontConfig) {
|
|
9021
9044
|
try {
|
|
9022
9045
|
_this.loadFont();
|
|
9023
9046
|
}
|
|
9024
9047
|
catch (error) {
|
|
9025
9048
|
console.warn('Failed to set font:', error);
|
|
9026
|
-
// 如果设置失败,使用默认字体
|
|
9027
9049
|
_this.jspdfCtx.setFont('Helvetica');
|
|
9028
9050
|
}
|
|
9029
9051
|
}
|
|
9030
|
-
// this.jspdfCtx.setFont('SourceHanSansSC-Normal-Min');
|
|
9031
|
-
// 将 pxToPt 保存为实例属性,以便其他方法使用
|
|
9032
9052
|
_this.pxToPt = pxToPt;
|
|
9033
9053
|
if (!options.canvas) {
|
|
9034
9054
|
_this.canvas.width = 10;
|
|
@@ -9037,9 +9057,6 @@
|
|
|
9037
9057
|
_this.canvas.style.height = "10px";
|
|
9038
9058
|
}
|
|
9039
9059
|
_this.fontMetrics = new FontMetrics$1(document);
|
|
9040
|
-
// this.ctx.scale(this.options.scale, this.options.scale);
|
|
9041
|
-
// this.ctx.translate(-options.x, -options.y);
|
|
9042
|
-
// this.ctx.textBaseline = 'bottom';
|
|
9043
9060
|
_this.context2dCtx.textBaseline = 'bottom';
|
|
9044
9061
|
_this._activeEffects = [];
|
|
9045
9062
|
_this.context.logger.debug("Canvas renderer initialized (".concat(options.width, "x").concat(options.height, ") with scale ").concat(options.scale));
|
|
@@ -9049,67 +9066,23 @@
|
|
|
9049
9066
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
9050
9067
|
var fontData;
|
|
9051
9068
|
return __generator$1(this, function (_a) {
|
|
9052
|
-
|
|
9053
|
-
|
|
9054
|
-
if (!this.options.fontConfig.fontBase64) return [3 /*break*/, 1];
|
|
9055
|
-
// 直接使用 Base64 编码
|
|
9056
|
-
fontData = this.options.fontConfig.fontBase64;
|
|
9057
|
-
return [3 /*break*/, 3];
|
|
9058
|
-
case 1:
|
|
9059
|
-
if (!this.options.fontConfig.fontUrl) return [3 /*break*/, 3];
|
|
9060
|
-
return [4 /*yield*/, this.loadFontFromURL(this.options.fontConfig.fontUrl)];
|
|
9061
|
-
case 2:
|
|
9062
|
-
fontData = _a.sent();
|
|
9063
|
-
_a.label = 3;
|
|
9064
|
-
case 3:
|
|
9065
|
-
// console.log('fontData',fontData)
|
|
9066
|
-
// 将字体添加到 jsPDF
|
|
9067
|
-
this.addFontToJsPDF(fontData);
|
|
9068
|
-
return [2 /*return*/];
|
|
9069
|
-
}
|
|
9070
|
-
});
|
|
9071
|
-
});
|
|
9072
|
-
};
|
|
9073
|
-
CanvasRenderer.prototype.loadFontFromURL = function (url) {
|
|
9074
|
-
return __awaiter$1(this, void 0, void 0, function () {
|
|
9075
|
-
var response, blob;
|
|
9076
|
-
return __generator$1(this, function (_a) {
|
|
9077
|
-
switch (_a.label) {
|
|
9078
|
-
case 0: return [4 /*yield*/, fetch(url, {
|
|
9079
|
-
mode: 'no-cors',
|
|
9080
|
-
headers: {
|
|
9081
|
-
'Content-Type': 'font/ttf'
|
|
9082
|
-
}
|
|
9083
|
-
})];
|
|
9084
|
-
case 1:
|
|
9085
|
-
response = _a.sent();
|
|
9086
|
-
return [4 /*yield*/, response.blob()];
|
|
9087
|
-
case 2:
|
|
9088
|
-
blob = _a.sent();
|
|
9089
|
-
// const fontUrl = URL.createObjectURL(blob);
|
|
9090
|
-
// console.log('response', blob, fontUrl)
|
|
9091
|
-
// 注意:no-cors 模式下无法读取响应内容!
|
|
9092
|
-
// const blob = await response.blob();
|
|
9093
|
-
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
9094
|
-
var reader = new FileReader();
|
|
9095
|
-
reader.onload = function () { return resolve(reader.result.split(',')[1]); }; // 提取 Base64 数据
|
|
9096
|
-
reader.onerror = function () { return reject(new Error('字体文件读取失败')); };
|
|
9097
|
-
reader.readAsDataURL(blob);
|
|
9098
|
-
})];
|
|
9069
|
+
if (this.options.fontConfig.fontBase64) {
|
|
9070
|
+
fontData = this.options.fontConfig.fontBase64;
|
|
9099
9071
|
}
|
|
9072
|
+
this.addFontToJsPDF(fontData);
|
|
9073
|
+
return [2 /*return*/];
|
|
9100
9074
|
});
|
|
9101
9075
|
});
|
|
9102
9076
|
};
|
|
9103
9077
|
CanvasRenderer.prototype.addFontToJsPDF = function (fontData) {
|
|
9104
|
-
var
|
|
9078
|
+
var fontFamily = this.options.fontConfig.fontFamily;
|
|
9105
9079
|
if (!fontFamily) {
|
|
9106
9080
|
return;
|
|
9107
9081
|
}
|
|
9108
|
-
this.jspdfCtx.addFileToVFS("".concat(fontFamily, ".ttf"), fontData);
|
|
9109
|
-
this.jspdfCtx.addFont("".concat(fontFamily, ".ttf"), fontFamily,
|
|
9110
|
-
this.jspdfCtx.setFont(fontFamily);
|
|
9082
|
+
this.jspdfCtx.addFileToVFS("".concat(fontFamily, ".ttf"), fontData);
|
|
9083
|
+
this.jspdfCtx.addFont("".concat(fontFamily, ".ttf"), fontFamily, 'normal');
|
|
9084
|
+
this.jspdfCtx.setFont(fontFamily);
|
|
9111
9085
|
};
|
|
9112
|
-
// 应用效果数组
|
|
9113
9086
|
CanvasRenderer.prototype.applyEffects = function (effects) {
|
|
9114
9087
|
var _this = this;
|
|
9115
9088
|
while (this._activeEffects.length) {
|
|
@@ -9117,46 +9090,29 @@
|
|
|
9117
9090
|
}
|
|
9118
9091
|
effects.forEach(function (effect) { return _this.applyEffect(effect); });
|
|
9119
9092
|
};
|
|
9120
|
-
// 应用单个效果
|
|
9121
9093
|
CanvasRenderer.prototype.applyEffect = function (effect) {
|
|
9122
9094
|
this.ctx.save();
|
|
9123
|
-
// this.context2dCtx.save()
|
|
9124
9095
|
if (isOpacityEffect$1(effect)) {
|
|
9125
9096
|
this.ctx.globalAlpha = effect.opacity;
|
|
9126
|
-
// this.context2dCtx.globalAlpha = effect.opacity
|
|
9127
9097
|
}
|
|
9128
9098
|
if (isTransformEffect$1(effect)) {
|
|
9129
9099
|
this.ctx.translate(effect.offsetX, effect.offsetY);
|
|
9130
9100
|
this.ctx.transform(effect.matrix[0], effect.matrix[1], effect.matrix[2], effect.matrix[3], effect.matrix[4], effect.matrix[5]);
|
|
9131
9101
|
this.ctx.translate(-effect.offsetX, -effect.offsetY);
|
|
9132
|
-
// this.context2dCtx.translate(effect.offsetX, effect.offsetY);
|
|
9133
|
-
// this.context2dCtx.transform(
|
|
9134
|
-
// effect.matrix[0],
|
|
9135
|
-
// effect.matrix[1],
|
|
9136
|
-
// effect.matrix[2],
|
|
9137
|
-
// effect.matrix[3],
|
|
9138
|
-
// effect.matrix[4],
|
|
9139
|
-
// effect.matrix[5]
|
|
9140
|
-
// );
|
|
9141
|
-
// this.context2dCtx.translate(-effect.offsetX, -effect.offsetY);
|
|
9142
9102
|
}
|
|
9143
9103
|
if (isClipEffect$1(effect)) {
|
|
9144
9104
|
this.path(effect.path);
|
|
9145
9105
|
this.ctx.clip();
|
|
9146
|
-
// this.context2dCtx.clip()
|
|
9147
9106
|
}
|
|
9148
9107
|
this._activeEffects.push(effect);
|
|
9149
9108
|
};
|
|
9150
|
-
// 移除最后应用的效果
|
|
9151
9109
|
CanvasRenderer.prototype.popEffect = function () {
|
|
9152
9110
|
this._activeEffects.pop();
|
|
9153
|
-
// this.ctx.restore();
|
|
9154
9111
|
this.context2dCtx.restore();
|
|
9155
9112
|
if (this.options.fontConfig && this.options.fontConfig.fontFamily) {
|
|
9156
9113
|
this.jspdfCtx.setFont(this.options.fontConfig.fontFamily);
|
|
9157
9114
|
}
|
|
9158
9115
|
};
|
|
9159
|
-
// 渲染堆叠上下文
|
|
9160
9116
|
CanvasRenderer.prototype.renderStack = function (stack) {
|
|
9161
9117
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
9162
9118
|
var styles;
|
|
@@ -9168,13 +9124,12 @@
|
|
|
9168
9124
|
return [4 /*yield*/, this.renderStackContent(stack)];
|
|
9169
9125
|
case 1:
|
|
9170
9126
|
_a.sent();
|
|
9171
|
-
|
|
9127
|
+
_a.label = 2;
|
|
9172
9128
|
case 2: return [2 /*return*/];
|
|
9173
9129
|
}
|
|
9174
9130
|
});
|
|
9175
9131
|
});
|
|
9176
9132
|
};
|
|
9177
|
-
// 渲染节点
|
|
9178
9133
|
CanvasRenderer.prototype.renderNode = function (paint) {
|
|
9179
9134
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
9180
9135
|
return __generator$1(this, function (_a) {
|
|
@@ -9196,27 +9151,19 @@
|
|
|
9196
9151
|
});
|
|
9197
9152
|
});
|
|
9198
9153
|
};
|
|
9199
|
-
// 渲染带有字母间距的文本
|
|
9200
9154
|
CanvasRenderer.prototype.renderTextWithLetterSpacing = function (text, letterSpacing, baseline) {
|
|
9201
9155
|
var _this = this;
|
|
9202
9156
|
if (letterSpacing === 0) {
|
|
9203
|
-
// console.log(text.text, text.bounds.left,'绘制文字-没有letterSpacing')
|
|
9204
|
-
// this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + baseline);
|
|
9205
9157
|
this.context2dCtx.fillText(text.text, text.bounds.left, text.bounds.top + baseline);
|
|
9206
9158
|
}
|
|
9207
9159
|
else {
|
|
9208
9160
|
var letters = segmentGraphemes$1(text.text);
|
|
9209
9161
|
letters.reduce(function (left, letter) {
|
|
9210
|
-
// console.log(left, letter,'绘制文字')
|
|
9211
|
-
// this.ctx.fillText(letter, left, text.bounds.top + baseline);
|
|
9212
|
-
// this.context2dCtx.fillText(letter, left - leftMargin, text.bounds.top + baseline - topMargin);
|
|
9213
|
-
// 使用jspdf绘制文字
|
|
9214
9162
|
_this.context2dCtx.fillText(letter, left, text.bounds.top + baseline);
|
|
9215
9163
|
return left + _this.ctx.measureText(letter).width;
|
|
9216
9164
|
}, text.bounds.left);
|
|
9217
9165
|
}
|
|
9218
9166
|
};
|
|
9219
|
-
// 创建字体样式
|
|
9220
9167
|
CanvasRenderer.prototype.createFontStyle = function (styles) {
|
|
9221
9168
|
var fontVariant = styles.fontVariant
|
|
9222
9169
|
.filter(function (variant) { return variant === 'normal' || variant === 'small-caps'; })
|
|
@@ -9231,18 +9178,16 @@
|
|
|
9231
9178
|
fontSize
|
|
9232
9179
|
];
|
|
9233
9180
|
};
|
|
9234
|
-
// 添加一个新的颜色转换函数
|
|
9235
9181
|
CanvasRenderer.prototype.convertColor = function (color) {
|
|
9236
|
-
// 如果是透明色,返回白色
|
|
9237
9182
|
if (isTransparent$1(color)) {
|
|
9238
9183
|
return '#FFFFFF';
|
|
9239
9184
|
}
|
|
9240
|
-
// 将 rgba 转换为 rgb
|
|
9241
|
-
// 从32位整数中提取RGB分量
|
|
9242
9185
|
var r = 0xff & (color >> 24);
|
|
9243
9186
|
var g = 0xff & (color >> 16);
|
|
9244
9187
|
var b = 0xff & (color >> 8);
|
|
9245
|
-
return "#".concat(r.toString(16).padStart(2, '0')).concat(g.toString(16).padStart(2, '0')).concat(b
|
|
9188
|
+
return "#".concat(r.toString(16).padStart(2, '0')).concat(g.toString(16).padStart(2, '0')).concat(b
|
|
9189
|
+
.toString(16)
|
|
9190
|
+
.padStart(2, '0'));
|
|
9246
9191
|
};
|
|
9247
9192
|
CanvasRenderer.prototype.renderTextNode = function (text, styles) {
|
|
9248
9193
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
@@ -9250,15 +9195,12 @@
|
|
|
9250
9195
|
var _this = this;
|
|
9251
9196
|
return __generator$1(this, function (_c) {
|
|
9252
9197
|
_a = this.createFontStyle(styles), font = _a[0], fontFamily = _a[1], fontSize = _a[2];
|
|
9253
|
-
// ,
|
|
9254
|
-
// 设置 CanvasRenderingContext2D 的字体样式
|
|
9255
9198
|
this.ctx.font = font;
|
|
9256
|
-
|
|
9257
|
-
this.context2dCtx.font = this.options.fontConfig.fontFamily; // 通常不需要显式设置,jsPDF 会处理
|
|
9199
|
+
this.context2dCtx.font = this.options.fontConfig.fontFamily;
|
|
9258
9200
|
this.ctx.direction = styles.direction === 1 /* DIRECTION.RTL */ ? 'rtl' : 'ltr';
|
|
9259
|
-
this.context2dCtx.direction = styles.direction === 1 /* DIRECTION.RTL */ ? 'rtl' : 'ltr';
|
|
9201
|
+
this.context2dCtx.direction = styles.direction === 1 /* DIRECTION.RTL */ ? 'rtl' : 'ltr';
|
|
9260
9202
|
this.ctx.textAlign = 'left';
|
|
9261
|
-
this.context2dCtx.textAlign = 'left';
|
|
9203
|
+
this.context2dCtx.textAlign = 'left';
|
|
9262
9204
|
fontSizePt = styles.fontSize.number;
|
|
9263
9205
|
this.jspdfCtx.setFontSize(fontSizePt);
|
|
9264
9206
|
_b = this.fontMetrics.getMetrics(fontFamily, fontSize), baseline = _b.baseline, middle = _b.middle;
|
|
@@ -9267,15 +9209,9 @@
|
|
|
9267
9209
|
paintOrder.forEach(function (paintOrderLayer) {
|
|
9268
9210
|
switch (paintOrderLayer) {
|
|
9269
9211
|
case 0 /* PAINT_ORDER_LAYER.FILL */:
|
|
9270
|
-
// 设置 CanvasRenderingContext2D 的填充样式
|
|
9271
|
-
// this.ctx.fillStyle = asString(styles.color);
|
|
9272
|
-
// 设置 jsPDF context2d 的填充样式
|
|
9273
9212
|
_this.context2dCtx.fillStyle = asString$1(styles.color);
|
|
9274
9213
|
_this.renderTextWithLetterSpacing(textItem, styles.letterSpacing, baseline);
|
|
9275
9214
|
if (styles.textDecorationLine.length) {
|
|
9276
|
-
// 设置 CanvasRenderingContext2D 的填充样式
|
|
9277
|
-
// this.ctx.fillStyle = asString(styles.textDecorationColor || styles.color);
|
|
9278
|
-
// 设置 jsPDF context2d 的填充样式
|
|
9279
9215
|
_this.context2dCtx.fillStyle = asString$1(styles.textDecorationColor || styles.color);
|
|
9280
9216
|
styles.textDecorationLine.forEach(function (textDecorationLine) {
|
|
9281
9217
|
var x = textItem.bounds.left;
|
|
@@ -9283,18 +9219,15 @@
|
|
|
9283
9219
|
var y_underline = Math.round(textItem.bounds.top + baseline);
|
|
9284
9220
|
var y_overline = Math.round(textItem.bounds.top);
|
|
9285
9221
|
var y_line_through = Math.ceil(textItem.bounds.top + middle);
|
|
9286
|
-
var thickness = 1;
|
|
9222
|
+
var thickness = 1;
|
|
9287
9223
|
switch (textDecorationLine) {
|
|
9288
9224
|
case 1 /* TEXT_DECORATION_LINE.UNDERLINE */:
|
|
9289
|
-
// this.ctx.fillRect(x, y_underline, width, thickness);
|
|
9290
9225
|
_this.context2dCtx.fillRect(x, y_underline, width, thickness);
|
|
9291
9226
|
break;
|
|
9292
9227
|
case 2 /* TEXT_DECORATION_LINE.OVERLINE */:
|
|
9293
|
-
// this.ctx.fillRect(x, y_overline, width, thickness);
|
|
9294
9228
|
_this.context2dCtx.fillRect(x, y_overline, width, thickness);
|
|
9295
9229
|
break;
|
|
9296
9230
|
case 3 /* TEXT_DECORATION_LINE.LINE_THROUGH */:
|
|
9297
|
-
// this.ctx.fillRect(x, y_line_through, width, thickness);
|
|
9298
9231
|
_this.context2dCtx.fillRect(x, y_line_through, width, thickness);
|
|
9299
9232
|
break;
|
|
9300
9233
|
}
|
|
@@ -9303,24 +9236,10 @@
|
|
|
9303
9236
|
break;
|
|
9304
9237
|
case 1 /* PAINT_ORDER_LAYER.STROKE */:
|
|
9305
9238
|
if (styles.webkitTextStrokeWidth && textItem.text.trim().length) {
|
|
9306
|
-
// 设置 CanvasRenderingContext2D 的描边样式
|
|
9307
|
-
// this.ctx.strokeStyle = asString(styles.webkitTextStrokeColor);
|
|
9308
|
-
// this.ctx.lineWidth = styles.webkitTextStrokeWidth;
|
|
9309
|
-
// this.ctx.lineJoin = !!(window as any).chrome ? 'miter' : 'round';
|
|
9310
|
-
// 设置 jsPDF context2d 的描边样式
|
|
9311
9239
|
_this.context2dCtx.strokeStyle = asString$1(styles.webkitTextStrokeColor);
|
|
9312
9240
|
_this.context2dCtx.lineWidth = styles.webkitTextStrokeWidth;
|
|
9313
|
-
// this.context2dCtx.lineJoin = ...; // 根据 jsPDF API 调整
|
|
9314
|
-
// CanvasRenderingContext2D 描边
|
|
9315
|
-
// this.ctx.strokeText(textItem.text, textItem.bounds.left, textItem.bounds.top + baseline);
|
|
9316
|
-
// jsPDF context2d 描边
|
|
9317
9241
|
_this.context2dCtx.strokeText(textItem.text, textItem.bounds.left, textItem.bounds.top + baseline);
|
|
9318
9242
|
}
|
|
9319
|
-
// 清除 CanvasRenderingContext2D 的描边样式
|
|
9320
|
-
// this.ctx.strokeStyle = '';
|
|
9321
|
-
// this.ctx.lineWidth = 0;
|
|
9322
|
-
// this.ctx.lineJoin = 'miter';
|
|
9323
|
-
// 清除 jsPDF context2d 的描边样式
|
|
9324
9243
|
_this.context2dCtx.strokeStyle = '';
|
|
9325
9244
|
_this.context2dCtx.lineWidth = 0;
|
|
9326
9245
|
_this.context2dCtx.lineJoin = 'miter';
|
|
@@ -9341,31 +9260,14 @@
|
|
|
9341
9260
|
this.ctx.clip();
|
|
9342
9261
|
this.ctx.drawImage(image, 0, 0, container.intrinsicWidth, container.intrinsicHeight, box.left, box.top, box.width, box.height);
|
|
9343
9262
|
this.ctx.restore();
|
|
9344
|
-
// this.context2dCtx.save();
|
|
9345
|
-
// this.context2dCtx.clip();
|
|
9346
|
-
// this.context2dCtx.drawImage(
|
|
9347
|
-
// image,
|
|
9348
|
-
// 0,
|
|
9349
|
-
// 0,
|
|
9350
|
-
// container.intrinsicWidth,
|
|
9351
|
-
// container.intrinsicHeight,
|
|
9352
|
-
// box.left,
|
|
9353
|
-
// box.top,
|
|
9354
|
-
// box.width,
|
|
9355
|
-
// box.height
|
|
9356
|
-
// );
|
|
9357
|
-
// this.context2dCtx.restore();
|
|
9358
9263
|
}
|
|
9359
9264
|
};
|
|
9360
|
-
// 渲染节点内容
|
|
9361
|
-
// 渲染节点内容的异步方法
|
|
9362
9265
|
CanvasRenderer.prototype.renderNodeContent = function (paint) {
|
|
9363
9266
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
9364
|
-
var container, curves, styles, _i, _a, child, image, bounds, x, y, width, height, bounds, x, y, width, height, dataURL, image, bounds, x, y, width, height, canvas, ctx, dataURL, e_2,
|
|
9267
|
+
var container, curves, styles, _i, _a, child, image, bounds, x, y, width, height, bounds, x, y, width, height, dataURL, image, bounds, x, y, width, height, canvas, ctx, dataURL, e_2, size, _b, fontFamily, fontSize, baseline, bounds, x, textBounds, img, image, url, fontFamily, bounds;
|
|
9365
9268
|
return __generator$1(this, function (_c) {
|
|
9366
9269
|
switch (_c.label) {
|
|
9367
9270
|
case 0:
|
|
9368
|
-
// 应用内容效果
|
|
9369
9271
|
this.applyEffects(paint.getEffects(4 /* EffectTarget.CONTENT */));
|
|
9370
9272
|
container = paint.container;
|
|
9371
9273
|
curves = paint.curves;
|
|
@@ -9390,18 +9292,14 @@
|
|
|
9390
9292
|
return [4 /*yield*/, this.context.cache.match(container.src)];
|
|
9391
9293
|
case 6:
|
|
9392
9294
|
image = _c.sent();
|
|
9393
|
-
// 渲染到 Canvas
|
|
9394
9295
|
this.renderReplacedElement(container, curves, image);
|
|
9395
|
-
// 添加到 PDF
|
|
9396
9296
|
try {
|
|
9397
9297
|
bounds = contentBox$1(container);
|
|
9398
|
-
x = this.pxToPt(bounds.left);
|
|
9399
|
-
y = this.pxToPt(bounds.top);
|
|
9298
|
+
x = this.pxToPt(bounds.left - this.options.x);
|
|
9299
|
+
y = this.pxToPt(bounds.top - this.options.y);
|
|
9400
9300
|
width = this.pxToPt(bounds.width);
|
|
9401
9301
|
height = this.pxToPt(bounds.height);
|
|
9402
|
-
|
|
9403
|
-
this.jspdfCtx.addImage(image, 'JPEG', // 默认使用 JPEG 格式
|
|
9404
|
-
x, y, width, height);
|
|
9302
|
+
this.addImagePdf(image, 'JPEG', x, y, width, height);
|
|
9405
9303
|
}
|
|
9406
9304
|
catch (err) {
|
|
9407
9305
|
this.context.logger.error("Error adding image to PDF: ".concat(err));
|
|
@@ -9413,18 +9311,15 @@
|
|
|
9413
9311
|
return [3 /*break*/, 8];
|
|
9414
9312
|
case 8:
|
|
9415
9313
|
if (container instanceof CanvasElementContainer$1) {
|
|
9416
|
-
// 渲染到 Canvas
|
|
9417
9314
|
this.renderReplacedElement(container, curves, container.canvas);
|
|
9418
|
-
// 添加到 PDF
|
|
9419
9315
|
try {
|
|
9420
9316
|
bounds = contentBox$1(container);
|
|
9421
|
-
x = this.pxToPt(bounds.left);
|
|
9422
|
-
y = this.pxToPt(bounds.top);
|
|
9317
|
+
x = this.pxToPt(bounds.left - this.options.x);
|
|
9318
|
+
y = this.pxToPt(bounds.top - this.options.y);
|
|
9423
9319
|
width = this.pxToPt(bounds.width);
|
|
9424
9320
|
height = this.pxToPt(bounds.height);
|
|
9425
9321
|
dataURL = container.canvas.toDataURL('image/png', 0.95);
|
|
9426
|
-
|
|
9427
|
-
this.jspdfCtx.addImage(dataURL, 'PNG', x, y, width, height);
|
|
9322
|
+
this.addImagePdf(dataURL, 'PNG', x, y, width, height);
|
|
9428
9323
|
}
|
|
9429
9324
|
catch (err) {
|
|
9430
9325
|
this.context.logger.error("Error adding canvas to PDF: ".concat(err));
|
|
@@ -9437,13 +9332,11 @@
|
|
|
9437
9332
|
return [4 /*yield*/, this.context.cache.match(container.svg)];
|
|
9438
9333
|
case 10:
|
|
9439
9334
|
image = _c.sent();
|
|
9440
|
-
// 渲染到 Canvas
|
|
9441
9335
|
this.renderReplacedElement(container, curves, image);
|
|
9442
|
-
// 添加到 PDF
|
|
9443
9336
|
try {
|
|
9444
9337
|
bounds = contentBox$1(container);
|
|
9445
|
-
x = this.pxToPt(bounds.left);
|
|
9446
|
-
y = this.pxToPt(bounds.top);
|
|
9338
|
+
x = this.pxToPt(bounds.left - this.options.x);
|
|
9339
|
+
y = this.pxToPt(bounds.top - this.options.y);
|
|
9447
9340
|
width = this.pxToPt(bounds.width);
|
|
9448
9341
|
height = this.pxToPt(bounds.height);
|
|
9449
9342
|
canvas = document.createElement('canvas');
|
|
@@ -9451,13 +9344,10 @@
|
|
|
9451
9344
|
canvas.height = container.intrinsicHeight || image.height;
|
|
9452
9345
|
ctx = canvas.getContext('2d');
|
|
9453
9346
|
if (ctx) {
|
|
9454
|
-
// 设置白色背景或保持透明
|
|
9455
9347
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
9456
|
-
// 绘制SVG图像
|
|
9457
9348
|
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
9458
9349
|
dataURL = canvas.toDataURL('image/png');
|
|
9459
|
-
|
|
9460
|
-
this.jspdfCtx.addImage(dataURL, 'PNG', x, y, width, height);
|
|
9350
|
+
this.addImagePdf(dataURL, 'PNG', x, y, width, height);
|
|
9461
9351
|
}
|
|
9462
9352
|
}
|
|
9463
9353
|
catch (err) {
|
|
@@ -9469,42 +9359,11 @@
|
|
|
9469
9359
|
this.context.logger.error("Error loading svg ".concat(e_2));
|
|
9470
9360
|
return [3 /*break*/, 12];
|
|
9471
9361
|
case 12:
|
|
9472
|
-
if (
|
|
9473
|
-
iframeRenderer = new CanvasRenderer(this.context, {
|
|
9474
|
-
scale: this.options.scale,
|
|
9475
|
-
fontConfig: this.options.fontConfig,
|
|
9476
|
-
backgroundColor: container.backgroundColor,
|
|
9477
|
-
x: 0,
|
|
9478
|
-
y: 0,
|
|
9479
|
-
width: container.width,
|
|
9480
|
-
height: container.height
|
|
9481
|
-
});
|
|
9482
|
-
return [4 /*yield*/, iframeRenderer.render(container.tree)];
|
|
9483
|
-
case 13:
|
|
9484
|
-
canvas = _c.sent();
|
|
9485
|
-
if (container.width && container.height) {
|
|
9486
|
-
// this.ctx.drawImage(
|
|
9487
|
-
// canvas,
|
|
9488
|
-
// 0,
|
|
9489
|
-
// 0,
|
|
9490
|
-
// container.width,
|
|
9491
|
-
// container.height,
|
|
9492
|
-
// container.bounds.left,
|
|
9493
|
-
// container.bounds.top,
|
|
9494
|
-
// container.bounds.width,
|
|
9495
|
-
// container.bounds.height
|
|
9496
|
-
// );
|
|
9497
|
-
this.context2dCtx.drawImage(canvas, 0, 0, container.width, container.height, container.bounds.left, container.bounds.top, container.bounds.width, container.bounds.height);
|
|
9498
|
-
}
|
|
9499
|
-
_c.label = 14;
|
|
9500
|
-
case 14:
|
|
9501
|
-
// 处理Input元素
|
|
9362
|
+
if (container instanceof IFrameElementContainer$1 && container.tree) ;
|
|
9502
9363
|
if (container instanceof InputElementContainer$1) {
|
|
9503
9364
|
size = Math.min(container.bounds.width, container.bounds.height);
|
|
9504
|
-
// 渲染复选框
|
|
9505
9365
|
if (container.type === CHECKBOX$1) {
|
|
9506
9366
|
if (container.checked) {
|
|
9507
|
-
// this.ctx.save();
|
|
9508
9367
|
this.context2dCtx.save();
|
|
9509
9368
|
this.path([
|
|
9510
9369
|
new Vector$1(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79),
|
|
@@ -9515,9 +9374,6 @@
|
|
|
9515
9374
|
new Vector$1(container.bounds.left + size * 0.84, container.bounds.top + size * 0.34085),
|
|
9516
9375
|
new Vector$1(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79)
|
|
9517
9376
|
]);
|
|
9518
|
-
// this.ctx.fillStyle = this.convertColor(INPUT_COLOR);
|
|
9519
|
-
// this.ctx.fill();
|
|
9520
|
-
// this.ctx.restore();
|
|
9521
9377
|
this.context2dCtx.fillStyle = this.convertColor(INPUT_COLOR$1);
|
|
9522
9378
|
this.context2dCtx.fill();
|
|
9523
9379
|
this.context2dCtx.restore();
|
|
@@ -9526,47 +9382,25 @@
|
|
|
9526
9382
|
}
|
|
9527
9383
|
}
|
|
9528
9384
|
}
|
|
9529
|
-
// 渲染单选框
|
|
9530
9385
|
else if (container.type === RADIO$1) {
|
|
9531
9386
|
if (container.checked) {
|
|
9532
|
-
// this.ctx.save();
|
|
9533
|
-
// this.ctx.beginPath();
|
|
9534
|
-
// this.ctx.arc(
|
|
9535
|
-
// container.bounds.left + size / 2,
|
|
9536
|
-
// container.bounds.top + size / 2,
|
|
9537
|
-
// size / 4,
|
|
9538
|
-
// 0,
|
|
9539
|
-
// Math.PI * 2,
|
|
9540
|
-
// true
|
|
9541
|
-
// );
|
|
9542
|
-
// this.ctx.fillStyle = this.convertColor(INPUT_COLOR);
|
|
9543
|
-
// this.ctx.fill();
|
|
9544
|
-
// this.ctx.restore();
|
|
9545
9387
|
this.context2dCtx.save();
|
|
9546
9388
|
this.context2dCtx.beginPath();
|
|
9547
9389
|
this.context2dCtx.arc(container.bounds.left + size / 2, container.bounds.top + size / 2, size / 4, 0, Math.PI * 2, true);
|
|
9548
9390
|
this.context2dCtx.fillStyle = this.convertColor(INPUT_COLOR$1);
|
|
9549
9391
|
this.context2dCtx.fill();
|
|
9550
9392
|
this.context2dCtx.restore();
|
|
9551
|
-
// 在 restore 之后重新设置字体
|
|
9552
9393
|
}
|
|
9553
9394
|
}
|
|
9554
9395
|
}
|
|
9555
|
-
// 处理文本输入元素
|
|
9556
9396
|
if (isTextInputElement$1(container) && container.value.length) {
|
|
9557
9397
|
_b = this.createFontStyle(styles), fontFamily = _b[0], fontSize = _b[1];
|
|
9558
9398
|
baseline = this.fontMetrics.getMetrics(fontFamily, fontSize).baseline;
|
|
9559
|
-
// this.ctx.font = fontFamily;
|
|
9560
|
-
// this.ctx.fillStyle = this.convertColor(styles.color);
|
|
9561
|
-
// this.context2dCtx.font = fontFamily;
|
|
9562
9399
|
this.context2dCtx.fillStyle = this.convertColor(styles.color);
|
|
9563
|
-
// this.ctx.textBaseline = 'alphabetic';
|
|
9564
|
-
// this.ctx.textAlign = canvasTextAlign(container.styles.textAlign);
|
|
9565
9400
|
this.context2dCtx.textBaseline = 'alphabetic';
|
|
9566
9401
|
this.context2dCtx.textAlign = canvasTextAlign$1(container.styles.textAlign);
|
|
9567
9402
|
bounds = contentBox$1(container);
|
|
9568
9403
|
x = 0;
|
|
9569
|
-
// 根据文本对齐方式调整x坐标
|
|
9570
9404
|
switch (container.styles.textAlign) {
|
|
9571
9405
|
case 1 /* TEXT_ALIGN.CENTER */:
|
|
9572
9406
|
x += bounds.width / 2;
|
|
@@ -9576,7 +9410,6 @@
|
|
|
9576
9410
|
break;
|
|
9577
9411
|
}
|
|
9578
9412
|
textBounds = bounds.add(x, 0, 0, -bounds.height / 2 + 1);
|
|
9579
|
-
// this.ctx.save();
|
|
9580
9413
|
this.context2dCtx.save();
|
|
9581
9414
|
this.path([
|
|
9582
9415
|
new Vector$1(bounds.left, bounds.top),
|
|
@@ -9584,56 +9417,45 @@
|
|
|
9584
9417
|
new Vector$1(bounds.left + bounds.width, bounds.top + bounds.height),
|
|
9585
9418
|
new Vector$1(bounds.left, bounds.top + bounds.height)
|
|
9586
9419
|
]);
|
|
9587
|
-
// this.ctx.clip();
|
|
9588
9420
|
this.context2dCtx.clip();
|
|
9589
9421
|
this.renderTextWithLetterSpacing(new TextBounds$1(container.value, textBounds), styles.letterSpacing, baseline);
|
|
9590
|
-
// this.ctx.restore();
|
|
9591
|
-
// this.ctx.textBaseline = 'alphabetic';
|
|
9592
|
-
// this.ctx.textAlign = 'left';
|
|
9593
9422
|
this.context2dCtx.restore();
|
|
9594
9423
|
this.context2dCtx.textBaseline = 'alphabetic';
|
|
9595
9424
|
this.context2dCtx.textAlign = 'left';
|
|
9596
9425
|
}
|
|
9597
|
-
if (!contains$1(container.styles.display, 2048 /* DISPLAY.LIST_ITEM */)) return [3 /*break*/,
|
|
9598
|
-
if (!(container.styles.listStyleImage !== null)) return [3 /*break*/,
|
|
9426
|
+
if (!contains$1(container.styles.display, 2048 /* DISPLAY.LIST_ITEM */)) return [3 /*break*/, 18];
|
|
9427
|
+
if (!(container.styles.listStyleImage !== null)) return [3 /*break*/, 17];
|
|
9599
9428
|
img = container.styles.listStyleImage;
|
|
9600
|
-
if (!(img.type === 0 /* CSSImageType.URL */)) return [3 /*break*/,
|
|
9429
|
+
if (!(img.type === 0 /* CSSImageType.URL */)) return [3 /*break*/, 16];
|
|
9601
9430
|
image = void 0;
|
|
9602
9431
|
url = img.url;
|
|
9603
|
-
_c.label =
|
|
9604
|
-
case
|
|
9605
|
-
_c.trys.push([
|
|
9432
|
+
_c.label = 13;
|
|
9433
|
+
case 13:
|
|
9434
|
+
_c.trys.push([13, 15, , 16]);
|
|
9606
9435
|
return [4 /*yield*/, this.context.cache.match(url)];
|
|
9607
|
-
case
|
|
9436
|
+
case 14:
|
|
9608
9437
|
image = _c.sent();
|
|
9609
|
-
// this.ctx.drawImage(image, container.bounds.left - (image.width + 10), container.bounds.top);
|
|
9610
9438
|
this.context2dCtx.drawImage(image, container.bounds.left - (image.width + 10), container.bounds.top);
|
|
9611
|
-
return [3 /*break*/,
|
|
9612
|
-
case
|
|
9439
|
+
return [3 /*break*/, 16];
|
|
9440
|
+
case 15:
|
|
9613
9441
|
_c.sent();
|
|
9614
9442
|
this.context.logger.error("Error loading list-style-image ".concat(url));
|
|
9615
|
-
return [3 /*break*/,
|
|
9616
|
-
case
|
|
9617
|
-
case
|
|
9443
|
+
return [3 /*break*/, 16];
|
|
9444
|
+
case 16: return [3 /*break*/, 18];
|
|
9445
|
+
case 17:
|
|
9618
9446
|
if (paint.listValue && container.styles.listStyleType !== -1 /* LIST_STYLE_TYPE.NONE */) {
|
|
9619
9447
|
fontFamily = this.createFontStyle(styles)[0];
|
|
9620
|
-
// this.ctx.font = fontFamily;
|
|
9621
|
-
// this.ctx.fillStyle = this.convertColor(styles.color);
|
|
9622
9448
|
this.context2dCtx.font = fontFamily;
|
|
9623
9449
|
this.context2dCtx.fillStyle = this.convertColor(styles.color);
|
|
9624
|
-
// this.ctx.textBaseline = 'middle';
|
|
9625
|
-
// this.ctx.textAlign = 'right';
|
|
9626
9450
|
this.context2dCtx.textBaseline = 'middle';
|
|
9627
9451
|
this.context2dCtx.textAlign = 'right';
|
|
9628
9452
|
bounds = new Bounds$1(container.bounds.left, container.bounds.top + getAbsoluteValue$1(container.styles.paddingTop, container.bounds.width), container.bounds.width, computeLineHeight$1(styles.lineHeight, styles.fontSize.number) / 2 + 1);
|
|
9629
9453
|
this.renderTextWithLetterSpacing(new TextBounds$1(paint.listValue, bounds), styles.letterSpacing, computeLineHeight$1(styles.lineHeight, styles.fontSize.number) / 2 + 2);
|
|
9630
|
-
// this.ctx.textBaseline = 'bottom';
|
|
9631
|
-
// this.ctx.textAlign = 'left';
|
|
9632
9454
|
this.context2dCtx.textBaseline = 'bottom';
|
|
9633
9455
|
this.context2dCtx.textAlign = 'left';
|
|
9634
9456
|
}
|
|
9635
|
-
_c.label =
|
|
9636
|
-
case
|
|
9457
|
+
_c.label = 18;
|
|
9458
|
+
case 18:
|
|
9637
9459
|
if (this.options.fontConfig && this.options.fontConfig.fontFamily) {
|
|
9638
9460
|
this.jspdfCtx.setFont(this.options.fontConfig.fontFamily);
|
|
9639
9461
|
}
|
|
@@ -9642,7 +9464,6 @@
|
|
|
9642
9464
|
});
|
|
9643
9465
|
});
|
|
9644
9466
|
};
|
|
9645
|
-
// 渲染堆叠上下文内容
|
|
9646
9467
|
CanvasRenderer.prototype.renderStackContent = function (stack) {
|
|
9647
9468
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
9648
9469
|
var _i, _a, child, _b, _c, child, _d, _e, child, _f, _g, child, _h, _j, child, _k, _l, child, _m, _o, child;
|
|
@@ -9652,12 +9473,8 @@
|
|
|
9652
9473
|
if (contains$1(stack.element.container.flags, 16 /* FLAGS.DEBUG_RENDER */)) {
|
|
9653
9474
|
debugger;
|
|
9654
9475
|
}
|
|
9655
|
-
// https://www.w3.org/TR/css-position-3/#painting-order
|
|
9656
|
-
// 1. the background and borders of the element forming the stacking context.
|
|
9657
9476
|
return [4 /*yield*/, this.renderNodeBackgroundAndBorders(stack.element)];
|
|
9658
9477
|
case 1:
|
|
9659
|
-
// https://www.w3.org/TR/css-position-3/#painting-order
|
|
9660
|
-
// 1. the background and borders of the element forming the stacking context.
|
|
9661
9478
|
_p.sent();
|
|
9662
9479
|
_i = 0, _a = stack.negativeZIndex;
|
|
9663
9480
|
_p.label = 2;
|
|
@@ -9671,11 +9488,8 @@
|
|
|
9671
9488
|
case 4:
|
|
9672
9489
|
_i++;
|
|
9673
9490
|
return [3 /*break*/, 2];
|
|
9674
|
-
case 5:
|
|
9675
|
-
// 3. For all its in-flow, non-positioned, block-level descendants in tree order:
|
|
9676
|
-
return [4 /*yield*/, this.renderNodeContent(stack.element)];
|
|
9491
|
+
case 5: return [4 /*yield*/, this.renderNodeContent(stack.element)];
|
|
9677
9492
|
case 6:
|
|
9678
|
-
// 3. For all its in-flow, non-positioned, block-level descendants in tree order:
|
|
9679
9493
|
_p.sent();
|
|
9680
9494
|
_b = 0, _c = stack.nonInlineLevel;
|
|
9681
9495
|
_p.label = 7;
|
|
@@ -9759,16 +9573,7 @@
|
|
|
9759
9573
|
});
|
|
9760
9574
|
});
|
|
9761
9575
|
};
|
|
9762
|
-
// 创建遮罩
|
|
9763
9576
|
CanvasRenderer.prototype.mask = function (paths) {
|
|
9764
|
-
// this.ctx.beginPath();
|
|
9765
|
-
// this.ctx.moveTo(0, 0);
|
|
9766
|
-
// this.ctx.lineTo(this.canvas.width, 0);
|
|
9767
|
-
// this.ctx.lineTo(this.canvas.width, this.canvas.height);
|
|
9768
|
-
// this.ctx.lineTo(0, this.canvas.height);
|
|
9769
|
-
// this.ctx.lineTo(0, 0);
|
|
9770
|
-
// this.formatPath(paths.slice(0).reverse());
|
|
9771
|
-
// this.ctx.closePath();
|
|
9772
9577
|
this.context2dCtx.beginPath();
|
|
9773
9578
|
this.context2dCtx.moveTo(0, 0);
|
|
9774
9579
|
this.context2dCtx.lineTo(this.options.width, 0);
|
|
@@ -9778,54 +9583,33 @@
|
|
|
9778
9583
|
this.formatPath(paths.slice(0).reverse());
|
|
9779
9584
|
this.context2dCtx.closePath();
|
|
9780
9585
|
};
|
|
9781
|
-
// 创建路径
|
|
9782
9586
|
CanvasRenderer.prototype.path = function (paths) {
|
|
9783
|
-
// this.ctx.beginPath();
|
|
9784
|
-
// this.formatPath(paths);
|
|
9785
|
-
// this.ctx.closePath();
|
|
9786
9587
|
this.context2dCtx.beginPath();
|
|
9787
9588
|
this.formatPath(paths);
|
|
9788
9589
|
this.context2dCtx.closePath();
|
|
9789
9590
|
};
|
|
9790
|
-
// 格式化路径
|
|
9791
9591
|
CanvasRenderer.prototype.formatPath = function (paths) {
|
|
9792
9592
|
var _this = this;
|
|
9793
9593
|
paths.forEach(function (point, index) {
|
|
9794
9594
|
var start = isBezierCurve$1(point) ? point.start : point;
|
|
9795
9595
|
if (index === 0) {
|
|
9796
|
-
// this.ctx.moveTo(start.x, start.y);
|
|
9797
9596
|
_this.context2dCtx.moveTo(start.x, start.y);
|
|
9798
9597
|
}
|
|
9799
9598
|
else {
|
|
9800
|
-
// this.ctx.lineTo(start.x, start.y);
|
|
9801
9599
|
_this.context2dCtx.lineTo(start.x, start.y);
|
|
9802
9600
|
}
|
|
9803
9601
|
if (isBezierCurve$1(point)) {
|
|
9804
|
-
// this.ctx.bezierCurveTo(
|
|
9805
|
-
// point.startControl.x,
|
|
9806
|
-
// point.startControl.y,
|
|
9807
|
-
// point.endControl.x,
|
|
9808
|
-
// point.endControl.y,
|
|
9809
|
-
// point.end.x,
|
|
9810
|
-
// point.end.y
|
|
9811
|
-
// );
|
|
9812
9602
|
_this.context2dCtx.bezierCurveTo(point.startControl.x, point.startControl.y, point.endControl.x, point.endControl.y, point.end.x, point.end.y);
|
|
9813
9603
|
}
|
|
9814
9604
|
});
|
|
9815
9605
|
};
|
|
9816
|
-
// 渲染重复图案
|
|
9817
9606
|
CanvasRenderer.prototype.renderRepeat = function (path, pattern, offsetX, offsetY) {
|
|
9818
9607
|
this.path(path);
|
|
9819
9608
|
this.ctx.fillStyle = pattern;
|
|
9820
|
-
// this.ctx.translate(offsetX, offsetY);
|
|
9821
|
-
// this.ctx.fill();
|
|
9822
|
-
// this.ctx.translate(-offsetX, -offsetY);
|
|
9823
|
-
// this.context2dCtx.fillStyle =this.convertColor(pattern) ;
|
|
9824
9609
|
this.context2dCtx.translate(offsetX, offsetY);
|
|
9825
9610
|
this.context2dCtx.fill();
|
|
9826
9611
|
this.context2dCtx.translate(-offsetX, -offsetY);
|
|
9827
9612
|
};
|
|
9828
|
-
// 调整图片大小
|
|
9829
9613
|
CanvasRenderer.prototype.resizeImage = function (image, width, height) {
|
|
9830
9614
|
var _a;
|
|
9831
9615
|
if (image.width === width && image.height === height) {
|
|
@@ -9839,7 +9623,6 @@
|
|
|
9839
9623
|
ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, width, height);
|
|
9840
9624
|
return canvas;
|
|
9841
9625
|
};
|
|
9842
|
-
// 渲染背景图片
|
|
9843
9626
|
CanvasRenderer.prototype.renderBackgroundImage = function (container) {
|
|
9844
9627
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
9845
9628
|
var index, _i, _a, backgroundImage, image, url, _b, path, x, y, width, height, pattern, xPt, yPt, widthPt, heightPt;
|
|
@@ -9850,7 +9633,7 @@
|
|
|
9850
9633
|
_i = 0, _a = container.styles.backgroundImage.slice(0).reverse();
|
|
9851
9634
|
_c.label = 1;
|
|
9852
9635
|
case 1:
|
|
9853
|
-
if (!(_i < _a.length)) return [3 /*break*/,
|
|
9636
|
+
if (!(_i < _a.length)) return [3 /*break*/, 8];
|
|
9854
9637
|
backgroundImage = _a[_i];
|
|
9855
9638
|
if (!(backgroundImage.type === 0 /* CSSImageType.URL */)) return [3 /*break*/, 6];
|
|
9856
9639
|
image = void 0;
|
|
@@ -9875,55 +9658,35 @@
|
|
|
9875
9658
|
]), path = _b[0], x = _b[1], y = _b[2], width = _b[3], height = _b[4];
|
|
9876
9659
|
pattern = this.ctx.createPattern(this.resizeImage(image, width, height), 'repeat');
|
|
9877
9660
|
this.renderRepeat(path, pattern, x, y);
|
|
9878
|
-
xPt = this.pxToPt(x);
|
|
9879
|
-
yPt = this.pxToPt(y);
|
|
9661
|
+
xPt = this.pxToPt(x - this.options.x);
|
|
9662
|
+
yPt = this.pxToPt(y - this.options.y);
|
|
9880
9663
|
widthPt = this.pxToPt(width);
|
|
9881
9664
|
heightPt = this.pxToPt(height);
|
|
9882
|
-
|
|
9883
|
-
this.jspdfCtx.addImage(image, 'JPEG', xPt, yPt, widthPt, heightPt);
|
|
9665
|
+
this.addImagePdf(image, 'JPEG', xPt, yPt, widthPt, heightPt);
|
|
9884
9666
|
}
|
|
9885
|
-
|
|
9667
|
+
_c.label = 6;
|
|
9886
9668
|
case 6:
|
|
9887
|
-
|
|
9888
|
-
else if (isRadialGradient$1(backgroundImage)) ;
|
|
9669
|
+
index--;
|
|
9889
9670
|
_c.label = 7;
|
|
9890
9671
|
case 7:
|
|
9891
|
-
index--;
|
|
9892
|
-
_c.label = 8;
|
|
9893
|
-
case 8:
|
|
9894
9672
|
_i++;
|
|
9895
9673
|
return [3 /*break*/, 1];
|
|
9896
|
-
case
|
|
9674
|
+
case 8: return [2 /*return*/];
|
|
9897
9675
|
}
|
|
9898
9676
|
});
|
|
9899
9677
|
});
|
|
9900
9678
|
};
|
|
9901
|
-
/**
|
|
9902
|
-
* 渲染实线边框
|
|
9903
|
-
* @param color - 边框颜色
|
|
9904
|
-
* @param side - 边的位置(0-3,分别代表上右下左)
|
|
9905
|
-
* @param curvePoints - 边框曲线点
|
|
9906
|
-
*/
|
|
9907
9679
|
CanvasRenderer.prototype.renderSolidBorder = function (color, side, curvePoints) {
|
|
9908
9680
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
9909
9681
|
return __generator$1(this, function (_a) {
|
|
9910
|
-
// console.log('绘制边框')
|
|
9911
|
-
// 解析边框路径
|
|
9912
|
-
// console.log('Border curve points:', JSON.stringify(curvePoints));
|
|
9913
|
-
// console.log('Page height:', this.jspdf.internal.pageSize.height);
|
|
9914
9682
|
this.path(parsePathForBorder$1(curvePoints, side));
|
|
9915
|
-
// 设置填充颜色
|
|
9916
|
-
// this.ctx.fillStyle = this.convertColor(color);
|
|
9917
9683
|
this.context2dCtx.fillStyle = this.convertColor(color);
|
|
9918
|
-
// 填充路径
|
|
9919
|
-
// this.ctx.fill();
|
|
9920
9684
|
this.jspdfCtx.fill();
|
|
9921
9685
|
this.context2dCtx.fill();
|
|
9922
9686
|
return [2 /*return*/];
|
|
9923
9687
|
});
|
|
9924
9688
|
});
|
|
9925
9689
|
};
|
|
9926
|
-
// 渲染双线边框
|
|
9927
9690
|
CanvasRenderer.prototype.renderDoubleBorder = function (color, width, side, curvePoints) {
|
|
9928
9691
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
9929
9692
|
var outerPaths, innerPaths;
|
|
@@ -9938,27 +9701,22 @@
|
|
|
9938
9701
|
case 2:
|
|
9939
9702
|
outerPaths = parsePathForBorderDoubleOuter$1(curvePoints, side);
|
|
9940
9703
|
this.path(outerPaths);
|
|
9941
|
-
// this.ctx.fillStyle = this.convertColor(color);
|
|
9942
|
-
// this.ctx.fill();
|
|
9943
9704
|
this.context2dCtx.fillStyle = this.convertColor(color);
|
|
9944
9705
|
this.context2dCtx.fill();
|
|
9945
9706
|
innerPaths = parsePathForBorderDoubleInner$1(curvePoints, side);
|
|
9946
9707
|
this.path(innerPaths);
|
|
9947
|
-
// this.ctx.fill();
|
|
9948
9708
|
this.context2dCtx.fill();
|
|
9949
9709
|
return [2 /*return*/];
|
|
9950
9710
|
}
|
|
9951
9711
|
});
|
|
9952
9712
|
});
|
|
9953
9713
|
};
|
|
9954
|
-
// 渲染节点的背景和边框
|
|
9955
9714
|
CanvasRenderer.prototype.renderNodeBackgroundAndBorders = function (paint) {
|
|
9956
9715
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
9957
9716
|
var styles, hasBackground, borders, backgroundPaintingArea, foreignobjectrendering, side, _i, borders_1, border;
|
|
9958
9717
|
return __generator$1(this, function (_a) {
|
|
9959
9718
|
switch (_a.label) {
|
|
9960
9719
|
case 0:
|
|
9961
|
-
// 应用背景和边框的效果
|
|
9962
9720
|
this.applyEffects(paint.getEffects(2 /* EffectTarget.BACKGROUND_BORDERS */));
|
|
9963
9721
|
styles = paint.container.styles;
|
|
9964
9722
|
hasBackground = !isTransparent$1(styles.backgroundColor) || styles.backgroundImage.length;
|
|
@@ -9971,8 +9729,6 @@
|
|
|
9971
9729
|
backgroundPaintingArea = calculateBackgroundCurvedPaintingArea$1(getBackgroundValueForIndex$1(styles.backgroundClip, 0), paint.curves);
|
|
9972
9730
|
foreignobjectrendering = paint.container.foreignobjectrendering;
|
|
9973
9731
|
if (!(hasBackground || styles.boxShadow.length)) return [3 /*break*/, 2];
|
|
9974
|
-
// console.log(paint,foreignobjectrendering, 'paint边框')
|
|
9975
|
-
// 在 save 之前确保字体设置正确
|
|
9976
9732
|
if (this.options.fontConfig && this.options.fontConfig.fontFamily) {
|
|
9977
9733
|
this.jspdfCtx.setFont(this.options.fontConfig.fontFamily);
|
|
9978
9734
|
}
|
|
@@ -9980,12 +9736,7 @@
|
|
|
9980
9736
|
this.context2dCtx.save();
|
|
9981
9737
|
this.path(backgroundPaintingArea);
|
|
9982
9738
|
this.context2dCtx.clip();
|
|
9983
|
-
// this.ctx.save();
|
|
9984
|
-
// this.path(backgroundPaintingArea);
|
|
9985
|
-
// this.ctx.clip();
|
|
9986
9739
|
if (!isTransparent$1(styles.backgroundColor)) {
|
|
9987
|
-
// this.ctx.fillStyle = asString(styles.backgroundColor);
|
|
9988
|
-
// this.ctx.fill();
|
|
9989
9740
|
this.context2dCtx.fillStyle = this.convertColor(styles.backgroundColor);
|
|
9990
9741
|
this.context2dCtx.fill();
|
|
9991
9742
|
}
|
|
@@ -9993,9 +9744,7 @@
|
|
|
9993
9744
|
return [4 /*yield*/, this.renderBackgroundImage(paint.container)];
|
|
9994
9745
|
case 1:
|
|
9995
9746
|
_a.sent();
|
|
9996
|
-
// this.ctx.restore();
|
|
9997
9747
|
this.context2dCtx.restore();
|
|
9998
|
-
// 在 restore 之后重新设置字体
|
|
9999
9748
|
if (this.options.fontConfig && this.options.fontConfig.fontFamily) {
|
|
10000
9749
|
this.jspdfCtx.setFont(this.options.fontConfig.fontFamily);
|
|
10001
9750
|
}
|
|
@@ -10042,27 +9791,15 @@
|
|
|
10042
9791
|
});
|
|
10043
9792
|
});
|
|
10044
9793
|
};
|
|
10045
|
-
|
|
10046
|
-
CanvasRenderer.prototype.renderDashedDottedBorder = function (color, // 边框颜色
|
|
10047
|
-
width, // 边框宽度
|
|
10048
|
-
side, // 边的位置(0-3,分别代表上右下左)
|
|
10049
|
-
curvePoints, // 边框曲线点
|
|
10050
|
-
style // 边框样式(DASHED或DOTTED)
|
|
10051
|
-
) {
|
|
9794
|
+
CanvasRenderer.prototype.renderDashedDottedBorder = function (color, width, side, curvePoints, style) {
|
|
10052
9795
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
10053
9796
|
var strokePaths, boxPaths, startX, startY, endX, endY, length, dashLength, spaceLength, useLineDash, multiplier, numberOfDashes, minSpace, maxSpace, path1, path2, x1, y1, x2, y2, path1, path2;
|
|
10054
9797
|
return __generator$1(this, function (_a) {
|
|
10055
|
-
// this.ctx.save(); // 保存当前画布状态
|
|
10056
|
-
// this.jspdfCtx.saveGraphicsState(); // 保存PDF绘图状态
|
|
10057
9798
|
this.context2dCtx.save();
|
|
10058
9799
|
strokePaths = parsePathForBorderStroke$1(curvePoints, side);
|
|
10059
9800
|
boxPaths = parsePathForBorder$1(curvePoints, side);
|
|
10060
|
-
// 如果是虚线边框,需要先裁剪路径
|
|
10061
9801
|
if (style === 2 /* BORDER_STYLE.DASHED */) {
|
|
10062
9802
|
this.path(boxPaths);
|
|
10063
|
-
// this.ctx.clip();
|
|
10064
|
-
// // PDF裁剪路径
|
|
10065
|
-
// this.jspdfCtx.clip();
|
|
10066
9803
|
this.context2dCtx.clip();
|
|
10067
9804
|
}
|
|
10068
9805
|
if (isBezierCurve$1(boxPaths[0])) {
|
|
@@ -10087,10 +9824,8 @@
|
|
|
10087
9824
|
else {
|
|
10088
9825
|
length = Math.abs(startY - endY);
|
|
10089
9826
|
}
|
|
10090
|
-
// 开始绘制路径
|
|
10091
|
-
// this.ctx.beginPath();
|
|
10092
9827
|
this.context2dCtx.beginPath();
|
|
10093
|
-
this.jspdfCtx.setDrawColor(this.convertColor(color));
|
|
9828
|
+
this.jspdfCtx.setDrawColor(this.convertColor(color));
|
|
10094
9829
|
if (style === 3 /* BORDER_STYLE.DOTTED */) {
|
|
10095
9830
|
this.formatPath(strokePaths);
|
|
10096
9831
|
}
|
|
@@ -10121,34 +9856,23 @@
|
|
|
10121
9856
|
? minSpace
|
|
10122
9857
|
: maxSpace;
|
|
10123
9858
|
}
|
|
10124
|
-
// 设置虚线样式
|
|
10125
9859
|
if (useLineDash) {
|
|
10126
9860
|
if (style === 3 /* BORDER_STYLE.DOTTED */) {
|
|
10127
|
-
|
|
10128
|
-
this.jspdfCtx.setLineDashPattern([0, dashLength + spaceLength], 0); // PDF虚线样式
|
|
9861
|
+
this.jspdfCtx.setLineDashPattern([0, dashLength + spaceLength], 0);
|
|
10129
9862
|
}
|
|
10130
9863
|
else {
|
|
10131
|
-
|
|
10132
|
-
this.jspdfCtx.setLineDashPattern([dashLength, spaceLength], 0); // PDF虚线样式
|
|
9864
|
+
this.jspdfCtx.setLineDashPattern([dashLength, spaceLength], 0);
|
|
10133
9865
|
}
|
|
10134
9866
|
}
|
|
10135
|
-
// 设置线条样式并绘制
|
|
10136
9867
|
if (style === 3 /* BORDER_STYLE.DOTTED */) {
|
|
10137
|
-
|
|
10138
|
-
// this.ctx.lineWidth = width;
|
|
10139
|
-
this.jspdfCtx.setLineCap('round'); // PDF线帽样式
|
|
9868
|
+
this.jspdfCtx.setLineCap('round');
|
|
10140
9869
|
this.jspdfCtx.setLineWidth(width);
|
|
10141
9870
|
}
|
|
10142
9871
|
else {
|
|
10143
|
-
// this.ctx.lineWidth = width * 2 + 1.1;
|
|
10144
9872
|
this.jspdfCtx.setLineWidth(width * 2 + 1.1);
|
|
10145
9873
|
}
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
this.jspdfCtx.stroke(); // PDF绘制线条
|
|
10149
|
-
// this.ctx.setLineDash([]);
|
|
10150
|
-
this.jspdfCtx.setLineDashPattern([], 0); // 重置PDF虚线样式
|
|
10151
|
-
// 处理虚线边框的圆角连接处
|
|
9874
|
+
this.jspdfCtx.stroke();
|
|
9875
|
+
this.jspdfCtx.setLineDashPattern([], 0);
|
|
10152
9876
|
if (style === 2 /* BORDER_STYLE.DASHED */) {
|
|
10153
9877
|
if (isBezierCurve$1(boxPaths[0])) {
|
|
10154
9878
|
path1 = boxPaths[3];
|
|
@@ -10168,42 +9892,189 @@
|
|
|
10168
9892
|
if (isBezierCurve$1(boxPaths[1])) {
|
|
10169
9893
|
path1 = boxPaths[1];
|
|
10170
9894
|
path2 = boxPaths[2];
|
|
10171
|
-
|
|
10172
|
-
// this.formatPath([new Vector(path1.end.x, path1.end.y), new Vector(path2.start.x, path2.start.y)]);
|
|
10173
|
-
// this.ctx.stroke();
|
|
10174
|
-
this.jspdfCtx.lines([[path1.end.x, path1.end.y, path2.start.x, path2.start.y]], path1.end.x, path1.end.y); // PDF绘制连接线
|
|
9895
|
+
this.jspdfCtx.lines([[path1.end.x, path1.end.y, path2.start.x, path2.start.y]], path1.end.x, path1.end.y);
|
|
10175
9896
|
this.jspdfCtx.stroke();
|
|
10176
9897
|
}
|
|
10177
9898
|
}
|
|
10178
|
-
|
|
10179
|
-
|
|
9899
|
+
this.jspdfCtx.restoreGraphicsState();
|
|
9900
|
+
return [2 /*return*/];
|
|
9901
|
+
});
|
|
9902
|
+
});
|
|
9903
|
+
};
|
|
9904
|
+
CanvasRenderer.prototype.addPage = function (offsetY) {
|
|
9905
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
9906
|
+
return __generator$1(this, function (_a) {
|
|
9907
|
+
this.context2dCtx.translate(0, -offsetY);
|
|
9908
|
+
this.jspdfCtx.addPage();
|
|
10180
9909
|
return [2 /*return*/];
|
|
10181
9910
|
});
|
|
10182
9911
|
});
|
|
10183
9912
|
};
|
|
10184
|
-
CanvasRenderer.prototype.
|
|
9913
|
+
CanvasRenderer.prototype.renderPage = function (element, pageNum) {
|
|
10185
9914
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
10186
|
-
var stack,
|
|
9915
|
+
var cfg, pageW, pageH, mt, mb, bx, by, bw, bh, stack, headerText, headerPos, footerText, footerPos;
|
|
10187
9916
|
return __generator$1(this, function (_a) {
|
|
10188
9917
|
switch (_a.label) {
|
|
10189
9918
|
case 0:
|
|
9919
|
+
cfg = this.options.pageConfig;
|
|
9920
|
+
pageW = this.jspdfCtx.internal.pageSize.getWidth();
|
|
9921
|
+
pageH = this.jspdfCtx.internal.pageSize.getHeight();
|
|
9922
|
+
mt = 0;
|
|
9923
|
+
mb = 0;
|
|
10190
9924
|
if (this.options.backgroundColor) {
|
|
10191
|
-
|
|
10192
|
-
|
|
10193
|
-
this.
|
|
10194
|
-
|
|
9925
|
+
this.jspdfCtx.setFillColor(this.convertColor(this.options.backgroundColor));
|
|
9926
|
+
bx = this.safe(this.options.x);
|
|
9927
|
+
by = this.safe(this.options.y);
|
|
9928
|
+
bw = Math.max(1, this.safe(this.options.width, 1));
|
|
9929
|
+
bh = Math.max(1, this.safe(this.options.height, 1));
|
|
9930
|
+
this.jspdfCtx.rect(bx, by, bw, bh, 'F');
|
|
10195
9931
|
}
|
|
10196
9932
|
stack = parseStackingContexts$1(element);
|
|
10197
9933
|
return [4 /*yield*/, this.renderStack(stack)];
|
|
10198
9934
|
case 1:
|
|
10199
9935
|
_a.sent();
|
|
10200
9936
|
this.applyEffects([]);
|
|
10201
|
-
|
|
10202
|
-
|
|
9937
|
+
if (cfg === null || cfg === void 0 ? void 0 : cfg.header) {
|
|
9938
|
+
headerText = String(cfg.header.content)
|
|
9939
|
+
.replace('${currentPage}', String(pageNum))
|
|
9940
|
+
.replace('${totalPages}', String(this.totalPages));
|
|
9941
|
+
this.jspdfCtx.setFontSize(this.safe(this.pxToPt(cfg.header.contentFontSize), 1));
|
|
9942
|
+
this.setTextColorFromString(cfg.header.contentColor);
|
|
9943
|
+
headerPos = this.computeContentPosition(cfg.header.contentPosition, pageW, pageH, cfg.header.height, mt, mb, 'header', cfg.header.padding);
|
|
9944
|
+
this.textPdf(headerText, headerPos.x, headerPos.y, headerPos.align);
|
|
9945
|
+
}
|
|
9946
|
+
if (cfg === null || cfg === void 0 ? void 0 : cfg.footer) {
|
|
9947
|
+
footerText = String(cfg.footer.content)
|
|
9948
|
+
.replace('${currentPage}', String(pageNum))
|
|
9949
|
+
.replace('${totalPages}', String(this.totalPages));
|
|
9950
|
+
this.jspdfCtx.setFontSize(this.safe(this.pxToPt(cfg.footer.contentFontSize), 1));
|
|
9951
|
+
this.setTextColorFromString(cfg.footer.contentColor);
|
|
9952
|
+
footerPos = this.computeContentPosition(cfg.footer.contentPosition, pageW, pageH, cfg.footer.height, mt, mb, 'footer', cfg.footer.padding);
|
|
9953
|
+
this.textPdf(footerText, footerPos.x, footerPos.y, footerPos.align);
|
|
9954
|
+
}
|
|
9955
|
+
return [2 /*return*/];
|
|
10203
9956
|
}
|
|
10204
9957
|
});
|
|
10205
9958
|
});
|
|
10206
9959
|
};
|
|
9960
|
+
CanvasRenderer.prototype.setTotalPages = function (total) {
|
|
9961
|
+
this.totalPages = total;
|
|
9962
|
+
};
|
|
9963
|
+
CanvasRenderer.prototype.setTextColorFromString = function (color) {
|
|
9964
|
+
var _a;
|
|
9965
|
+
var named = {
|
|
9966
|
+
black: [0, 0, 0],
|
|
9967
|
+
white: [255, 255, 255],
|
|
9968
|
+
red: [255, 0, 0],
|
|
9969
|
+
green: [0, 128, 0],
|
|
9970
|
+
blue: [0, 0, 255],
|
|
9971
|
+
gray: [128, 128, 128]
|
|
9972
|
+
};
|
|
9973
|
+
var r = 0, g = 0, b = 0;
|
|
9974
|
+
var c = (color === null || color === void 0 ? void 0 : color.toLowerCase()) || 'black';
|
|
9975
|
+
if (c in named) {
|
|
9976
|
+
_a = named[c], r = _a[0], g = _a[1], b = _a[2];
|
|
9977
|
+
}
|
|
9978
|
+
else if (c.startsWith('#') && (c.length === 7 || c.length === 4)) {
|
|
9979
|
+
var hex = c.length === 4 ? "#".concat(c[1]).concat(c[1]).concat(c[2]).concat(c[2]).concat(c[3]).concat(c[3]) : c;
|
|
9980
|
+
r = parseInt(hex.slice(1, 3), 16);
|
|
9981
|
+
g = parseInt(hex.slice(3, 5), 16);
|
|
9982
|
+
b = parseInt(hex.slice(5, 7), 16);
|
|
9983
|
+
}
|
|
9984
|
+
this.jspdfCtx.setTextColor(r, g, b);
|
|
9985
|
+
};
|
|
9986
|
+
CanvasRenderer.prototype.safe = function (n, min) {
|
|
9987
|
+
if (min === void 0) { min = 0; }
|
|
9988
|
+
var v = Number(n);
|
|
9989
|
+
return Number.isFinite(v) ? v : min;
|
|
9990
|
+
};
|
|
9991
|
+
CanvasRenderer.prototype.textPdf = function (text, x, y, align) {
|
|
9992
|
+
var sx = this.safe(x);
|
|
9993
|
+
var sy = this.safe(y);
|
|
9994
|
+
this.jspdfCtx.text(String(text), sx, sy, { align: align });
|
|
9995
|
+
};
|
|
9996
|
+
CanvasRenderer.prototype.computeContentPosition = function (pos, pageW, pageH, areaH, mt, mb, area, paddingPx) {
|
|
9997
|
+
var _this = this;
|
|
9998
|
+
var _a = (paddingPx !== null && paddingPx !== void 0 ? paddingPx : [24, 24, 24, 24]).map(function (v) { return _this.pxToPt(v); }), pt = _a[0], pr = _a[1], pb = _a[2], pl = _a[3];
|
|
9999
|
+
var areaHPt = this.pxToPt(areaH);
|
|
10000
|
+
var mtPt = this.pxToPt(mt);
|
|
10001
|
+
var mbPt = this.pxToPt(mb);
|
|
10002
|
+
if (Array.isArray(pos) && pos.length >= 2) {
|
|
10003
|
+
return { x: this.pxToPt(pos[0]), y: this.pxToPt(pos[1]), align: 'left' };
|
|
10004
|
+
}
|
|
10005
|
+
if (area === 'header') {
|
|
10006
|
+
switch (pos) {
|
|
10007
|
+
case 'center':
|
|
10008
|
+
return {
|
|
10009
|
+
x: pageW / 2,
|
|
10010
|
+
y: mtPt + pt + (areaHPt - pt - pb) / 2,
|
|
10011
|
+
align: 'center'
|
|
10012
|
+
};
|
|
10013
|
+
case 'centerLeft':
|
|
10014
|
+
return { x: pl, y: mtPt + pt + (areaHPt - pt - pb) / 2, align: 'left' };
|
|
10015
|
+
case 'centerRight':
|
|
10016
|
+
return { x: pageW - pr, y: mtPt + pt + (areaHPt - pt - pb) / 2, align: 'right' };
|
|
10017
|
+
case 'centerTop':
|
|
10018
|
+
return { x: pageW / 2, y: mtPt + pt, align: 'center' };
|
|
10019
|
+
case 'centerBottom':
|
|
10020
|
+
return { x: pageW / 2, y: mtPt + areaHPt - pb, align: 'center' };
|
|
10021
|
+
case 'leftTop':
|
|
10022
|
+
return { x: pl, y: mtPt + pt, align: 'left' };
|
|
10023
|
+
case 'leftBottom':
|
|
10024
|
+
return { x: pl, y: mtPt + areaHPt - pb, align: 'left' };
|
|
10025
|
+
case 'rightTop':
|
|
10026
|
+
return { x: pageW - pr, y: mtPt + pt, align: 'right' };
|
|
10027
|
+
case 'rightBottom':
|
|
10028
|
+
return { x: pageW - pr, y: mtPt + areaHPt - pb, align: 'right' };
|
|
10029
|
+
default:
|
|
10030
|
+
return { x: pl, y: mtPt + pt, align: 'left' };
|
|
10031
|
+
}
|
|
10032
|
+
}
|
|
10033
|
+
else {
|
|
10034
|
+
switch (pos) {
|
|
10035
|
+
case 'center':
|
|
10036
|
+
return {
|
|
10037
|
+
x: pageW / 2,
|
|
10038
|
+
y: pageH - mbPt - areaHPt + pt + (areaHPt - pt - pb) / 2,
|
|
10039
|
+
align: 'center'
|
|
10040
|
+
};
|
|
10041
|
+
case 'centerLeft':
|
|
10042
|
+
return { x: pl, y: pageH - mbPt - areaHPt + pt + (areaHPt - pt - pb) / 2, align: 'left' };
|
|
10043
|
+
case 'centerRight':
|
|
10044
|
+
return { x: pageW - pr, y: pageH - mbPt - areaHPt + pt + (areaHPt - pt - pb) / 2, align: 'right' };
|
|
10045
|
+
case 'centerTop':
|
|
10046
|
+
return { x: pageW / 2, y: pageH - mbPt - areaHPt + pt, align: 'center' };
|
|
10047
|
+
case 'centerBottom':
|
|
10048
|
+
return { x: pageW / 2, y: pageH - mbPt - pb, align: 'center' };
|
|
10049
|
+
case 'leftTop':
|
|
10050
|
+
return { x: pl, y: pageH - mbPt - areaHPt + pt, align: 'left' };
|
|
10051
|
+
case 'leftBottom':
|
|
10052
|
+
return { x: pl, y: pageH - mbPt - pb, align: 'left' };
|
|
10053
|
+
case 'rightTop':
|
|
10054
|
+
return { x: pageW - pr, y: pageH - mbPt - areaHPt + pt, align: 'right' };
|
|
10055
|
+
case 'rightBottom':
|
|
10056
|
+
return { x: pageW - pr, y: pageH - mbPt - pb, align: 'right' };
|
|
10057
|
+
default:
|
|
10058
|
+
return { x: pl, y: pageH - mbPt - pb, align: 'left' };
|
|
10059
|
+
}
|
|
10060
|
+
}
|
|
10061
|
+
};
|
|
10062
|
+
CanvasRenderer.prototype.addImagePdf = function (img, format, x, y, w, h) {
|
|
10063
|
+
var sx = this.safe(x);
|
|
10064
|
+
var sy = this.safe(y);
|
|
10065
|
+
var sw = Math.max(1, this.safe(w, 1));
|
|
10066
|
+
var sh = Math.max(1, this.safe(h, 1));
|
|
10067
|
+
this.jspdfCtx.addImage(img, format, sx, sy, sw, sh);
|
|
10068
|
+
};
|
|
10069
|
+
CanvasRenderer.prototype.output = function () {
|
|
10070
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
10071
|
+
var pdfBlob;
|
|
10072
|
+
return __generator$1(this, function (_a) {
|
|
10073
|
+
pdfBlob = this.jspdfCtx.output('blob');
|
|
10074
|
+
return [2 /*return*/, pdfBlob];
|
|
10075
|
+
});
|
|
10076
|
+
});
|
|
10077
|
+
};
|
|
10207
10078
|
return CanvasRenderer;
|
|
10208
10079
|
}(Renderer$1));
|
|
10209
10080
|
var isTextInputElement$1 = function (container) {
|
|
@@ -10248,19 +10119,258 @@
|
|
|
10248
10119
|
: fontFamilies;
|
|
10249
10120
|
};
|
|
10250
10121
|
|
|
10122
|
+
// 96 DPI pixel values
|
|
10123
|
+
var PAGE_FORMAT_MAP = {
|
|
10124
|
+
// A Series
|
|
10125
|
+
a0: { width: 3179, height: 4494 },
|
|
10126
|
+
a1: { width: 2245, height: 3179 },
|
|
10127
|
+
a2: { width: 1587, height: 2245 },
|
|
10128
|
+
a3: { width: 1123, height: 1587 },
|
|
10129
|
+
a4: { width: 794, height: 1123 },
|
|
10130
|
+
a5: { width: 559, height: 794 },
|
|
10131
|
+
a6: { width: 397, height: 559 },
|
|
10132
|
+
a7: { width: 280, height: 397 },
|
|
10133
|
+
a8: { width: 197, height: 280 },
|
|
10134
|
+
a9: { width: 140, height: 197 },
|
|
10135
|
+
a10: { width: 98, height: 140 },
|
|
10136
|
+
// B Series
|
|
10137
|
+
b0: { width: 3780, height: 5344 },
|
|
10138
|
+
b1: { width: 2672, height: 3780 },
|
|
10139
|
+
b2: { width: 1890, height: 2672 },
|
|
10140
|
+
b3: { width: 1334, height: 1890 },
|
|
10141
|
+
b4: { width: 945, height: 1334 },
|
|
10142
|
+
b5: { width: 665, height: 945 },
|
|
10143
|
+
b6: { width: 472, height: 665 },
|
|
10144
|
+
b7: { width: 333, height: 472 },
|
|
10145
|
+
b8: { width: 234, height: 333 },
|
|
10146
|
+
b9: { width: 166, height: 234 },
|
|
10147
|
+
b10: { width: 117, height: 166 },
|
|
10148
|
+
// C Series
|
|
10149
|
+
c0: { width: 3466, height: 4902 },
|
|
10150
|
+
c1: { width: 2449, height: 3466 },
|
|
10151
|
+
c2: { width: 1731, height: 2449 },
|
|
10152
|
+
c3: { width: 1225, height: 1731 },
|
|
10153
|
+
c4: { width: 865, height: 1225 },
|
|
10154
|
+
c5: { width: 612, height: 865 },
|
|
10155
|
+
c6: { width: 431, height: 612 },
|
|
10156
|
+
c7: { width: 306, height: 431 },
|
|
10157
|
+
c8: { width: 215, height: 306 },
|
|
10158
|
+
c9: { width: 151, height: 215 },
|
|
10159
|
+
c10: { width: 106, height: 151 },
|
|
10160
|
+
// Others
|
|
10161
|
+
dl: { width: 416, height: 832 },
|
|
10162
|
+
letter: { width: 816, height: 1056 },
|
|
10163
|
+
'government-letter': { width: 768, height: 1008 },
|
|
10164
|
+
legal: { width: 816, height: 1344 },
|
|
10165
|
+
'junior-legal': { width: 480, height: 768 },
|
|
10166
|
+
ledger: { width: 1632, height: 1056 },
|
|
10167
|
+
tabloid: { width: 1056, height: 1632 },
|
|
10168
|
+
'credit-card': { width: 204, height: 324 },
|
|
10169
|
+
// Aliases / Compatibility
|
|
10170
|
+
A4: { width: 794, height: 1123 }
|
|
10171
|
+
};
|
|
10172
|
+
|
|
10173
|
+
var offSetPageObj = {};
|
|
10174
|
+
var offSetTotal = 0;
|
|
10175
|
+
var activePageHeight = 1123;
|
|
10176
|
+
var pageMarginTop = 0;
|
|
10177
|
+
var pageMarginBottom = 0;
|
|
10178
|
+
var cloneContainerShallow = function (src) {
|
|
10179
|
+
var c = Object.create(Object.getPrototypeOf(src));
|
|
10180
|
+
var srcObj = src;
|
|
10181
|
+
for (var _i = 0, _a = Object.keys(srcObj); _i < _a.length; _i++) {
|
|
10182
|
+
var key = _a[_i];
|
|
10183
|
+
if (key === 'elements' || key === 'bounds' || key === 'styles' || key === 'textNodes')
|
|
10184
|
+
continue;
|
|
10185
|
+
c[key] = srcObj[key];
|
|
10186
|
+
}
|
|
10187
|
+
c.context = src.context;
|
|
10188
|
+
c.styles = Object.assign(Object.create(Object.getPrototypeOf(src.styles)), src.styles);
|
|
10189
|
+
c.textNodes = src.textNodes;
|
|
10190
|
+
c.flags = src.flags;
|
|
10191
|
+
c.bounds = new Bounds$1(src.bounds.left, src.bounds.top, src.bounds.width, src.bounds.height);
|
|
10192
|
+
c.elements = [];
|
|
10193
|
+
return c;
|
|
10194
|
+
};
|
|
10195
|
+
var cloneTextContainerShallow = function (src) {
|
|
10196
|
+
var c = Object.create(Object.getPrototypeOf(src));
|
|
10197
|
+
c.text = src.text;
|
|
10198
|
+
c.textBounds = [];
|
|
10199
|
+
return c;
|
|
10200
|
+
};
|
|
10201
|
+
var computeMaxBottom = function (node) {
|
|
10202
|
+
var maxBottom = node.bounds.top + node.bounds.height;
|
|
10203
|
+
for (var _i = 0, _a = node.textNodes; _i < _a.length; _i++) {
|
|
10204
|
+
var tn = _a[_i];
|
|
10205
|
+
for (var _b = 0, _c = tn.textBounds; _b < _c.length; _b++) {
|
|
10206
|
+
var tb = _c[_b];
|
|
10207
|
+
var b = tb.bounds.top + tb.bounds.height;
|
|
10208
|
+
if (b > maxBottom)
|
|
10209
|
+
maxBottom = b;
|
|
10210
|
+
}
|
|
10211
|
+
}
|
|
10212
|
+
for (var _d = 0, _e = node.elements; _d < _e.length; _d++) {
|
|
10213
|
+
var el = _e[_d];
|
|
10214
|
+
var b = computeMaxBottom(el);
|
|
10215
|
+
if (b > maxBottom)
|
|
10216
|
+
maxBottom = b;
|
|
10217
|
+
}
|
|
10218
|
+
return maxBottom;
|
|
10219
|
+
};
|
|
10220
|
+
var filterTextNodesForPage = function (container, pageStart, pageEnd) {
|
|
10221
|
+
var result = [];
|
|
10222
|
+
for (var _i = 0, _a = container.textNodes; _i < _a.length; _i++) {
|
|
10223
|
+
var tc = _a[_i];
|
|
10224
|
+
var filtered = [];
|
|
10225
|
+
for (var _b = 0, _c = tc.textBounds; _b < _c.length; _b++) {
|
|
10226
|
+
var tb = _c[_b];
|
|
10227
|
+
var pageIndex = Math.floor(pageEnd / activePageHeight);
|
|
10228
|
+
var maxKey = Math.max.apply(Math, Object.keys(offSetPageObj).map(function (k) { return +k; }));
|
|
10229
|
+
var activePageOffset = offSetPageObj[maxKey] || 0;
|
|
10230
|
+
var top_1 = tb.bounds.top + activePageOffset;
|
|
10231
|
+
var bottom = tb.bounds.top + tb.bounds.height + activePageOffset;
|
|
10232
|
+
var intersects = bottom > pageStart && top_1 < pageEnd;
|
|
10233
|
+
var crossesToNextPage = bottom > pageEnd;
|
|
10234
|
+
if (intersects && !crossesToNextPage) {
|
|
10235
|
+
var offsetNum = 0;
|
|
10236
|
+
if (top_1 < pageStart) {
|
|
10237
|
+
offsetNum = pageStart - top_1;
|
|
10238
|
+
if (!offSetPageObj[pageIndex] ||
|
|
10239
|
+
(offSetPageObj[pageIndex] && offSetPageObj[pageIndex] < offsetNum)) {
|
|
10240
|
+
if (offSetPageObj[pageIndex] && offSetPageObj[pageIndex] < offsetNum) {
|
|
10241
|
+
offSetTotal = offSetTotal - offSetPageObj[pageIndex] + offsetNum;
|
|
10242
|
+
}
|
|
10243
|
+
else {
|
|
10244
|
+
offSetTotal += offsetNum;
|
|
10245
|
+
}
|
|
10246
|
+
offSetPageObj[pageIndex] = offSetTotal;
|
|
10247
|
+
}
|
|
10248
|
+
}
|
|
10249
|
+
var visibleTop = Math.max(top_1, pageStart);
|
|
10250
|
+
var visibleBottom = Math.min(bottom, pageEnd);
|
|
10251
|
+
var newTop = visibleTop - pageStart;
|
|
10252
|
+
var newHeight = Math.max(0, visibleBottom - visibleTop);
|
|
10253
|
+
// 根据可见区域生成新的 Bounds
|
|
10254
|
+
var nb = new Bounds$1(tb.bounds.left, newTop + pageMarginTop, tb.bounds.width, newHeight);
|
|
10255
|
+
// if (pageIndex == 3) {
|
|
10256
|
+
// console.log(
|
|
10257
|
+
// 'nb',
|
|
10258
|
+
// nb,
|
|
10259
|
+
// 'pageStart',
|
|
10260
|
+
// pageStart,
|
|
10261
|
+
// 'tb.bounds.top',
|
|
10262
|
+
// tb.bounds.top,
|
|
10263
|
+
// 'activePageOffset',
|
|
10264
|
+
// activePageOffset,
|
|
10265
|
+
// (tb as any).text
|
|
10266
|
+
// );
|
|
10267
|
+
// }
|
|
10268
|
+
// 把文字内容和新的 bounds 一起放进 filtered
|
|
10269
|
+
filtered.push({ text: tb.text, bounds: nb });
|
|
10270
|
+
}
|
|
10271
|
+
}
|
|
10272
|
+
if (filtered.length > 0) {
|
|
10273
|
+
var clone = cloneTextContainerShallow(tc);
|
|
10274
|
+
clone.textBounds = filtered;
|
|
10275
|
+
result.push(clone);
|
|
10276
|
+
}
|
|
10277
|
+
}
|
|
10278
|
+
return result;
|
|
10279
|
+
};
|
|
10280
|
+
var filterElementForPage = function (container, pageStart, pageEnd) {
|
|
10281
|
+
var pageIndex = Math.floor(pageEnd / activePageHeight);
|
|
10282
|
+
var maxKey = Math.max.apply(Math, Object.keys(offSetPageObj).map(function (k) { return +k; }));
|
|
10283
|
+
var activePageOffset = offSetPageObj[maxKey] || 0;
|
|
10284
|
+
var top = container.bounds.top + activePageOffset;
|
|
10285
|
+
var bottom = container.bounds.top + container.bounds.height + activePageOffset;
|
|
10286
|
+
if (container.divisionDisable && bottom > pageEnd && top < pageEnd) {
|
|
10287
|
+
var offsetNum = pageEnd - top;
|
|
10288
|
+
var prev = offSetPageObj[pageIndex] || 0;
|
|
10289
|
+
if (!offSetPageObj[pageIndex] || prev < offsetNum) {
|
|
10290
|
+
offSetTotal += offsetNum - prev;
|
|
10291
|
+
offSetPageObj[pageIndex] = offSetTotal;
|
|
10292
|
+
}
|
|
10293
|
+
return null;
|
|
10294
|
+
}
|
|
10295
|
+
var children = [];
|
|
10296
|
+
for (var _i = 0, _a = container.elements; _i < _a.length; _i++) {
|
|
10297
|
+
var child = _a[_i];
|
|
10298
|
+
var part = filterElementForPage(child, pageStart, pageEnd);
|
|
10299
|
+
if (part)
|
|
10300
|
+
children.push(part);
|
|
10301
|
+
}
|
|
10302
|
+
var textNodes = filterTextNodesForPage(container, pageStart, pageEnd);
|
|
10303
|
+
var visibleTop = Math.max(top, pageStart);
|
|
10304
|
+
var visibleBottom = Math.min(bottom, pageEnd);
|
|
10305
|
+
var newHeight = Math.max(0, visibleBottom - visibleTop);
|
|
10306
|
+
var hasContent = children.length > 0 || textNodes.length > 0 || newHeight > 0;
|
|
10307
|
+
if (!hasContent)
|
|
10308
|
+
return null;
|
|
10309
|
+
var clone = cloneContainerShallow(container);
|
|
10310
|
+
clone.elements = children;
|
|
10311
|
+
clone.textNodes = textNodes;
|
|
10312
|
+
var newTop = visibleTop >= pageStart ? visibleTop - pageStart : 0;
|
|
10313
|
+
clone.bounds = new Bounds$1(container.bounds.left, newTop + pageMarginTop, container.bounds.width, newHeight);
|
|
10314
|
+
return clone;
|
|
10315
|
+
};
|
|
10316
|
+
var paginateNode = function (root, pageHeight, initialOffset, pageConfig) {
|
|
10317
|
+
var _a, _b;
|
|
10318
|
+
if (initialOffset === void 0) { initialOffset = 0; }
|
|
10319
|
+
if (initialOffset < 0)
|
|
10320
|
+
initialOffset = 0;
|
|
10321
|
+
offSetTotal = 0;
|
|
10322
|
+
Object.keys(offSetPageObj).forEach(function (key) { return delete offSetPageObj[key]; });
|
|
10323
|
+
var maxBottom = computeMaxBottom(root);
|
|
10324
|
+
pageMarginTop = ((_a = pageConfig === null || pageConfig === void 0 ? void 0 : pageConfig.header) === null || _a === void 0 ? void 0 : _a.height) || 0;
|
|
10325
|
+
pageMarginBottom = ((_b = pageConfig === null || pageConfig === void 0 ? void 0 : pageConfig.footer) === null || _b === void 0 ? void 0 : _b.height) || 0;
|
|
10326
|
+
activePageHeight = pageHeight - pageMarginTop - pageMarginBottom;
|
|
10327
|
+
var totalPages = Math.max(1, Math.ceil((maxBottom - initialOffset) / activePageHeight));
|
|
10328
|
+
var pages = [];
|
|
10329
|
+
for (var i = 0; i < totalPages; i++) {
|
|
10330
|
+
var pageStart = initialOffset + i * activePageHeight;
|
|
10331
|
+
var pageEnd = pageStart + activePageHeight;
|
|
10332
|
+
var pageRoot = filterElementForPage(root, pageStart, pageEnd);
|
|
10333
|
+
if (pageRoot)
|
|
10334
|
+
pages.push(pageRoot);
|
|
10335
|
+
}
|
|
10336
|
+
// console.log(offSetPageObj, '偏移量');
|
|
10337
|
+
return pages;
|
|
10338
|
+
};
|
|
10339
|
+
|
|
10251
10340
|
var dompdf = function (element, options) {
|
|
10252
|
-
// 移除元素的边框和阴影样式
|
|
10253
10341
|
if (options === void 0) { options = {}; }
|
|
10254
10342
|
return renderElement$1(element, options);
|
|
10255
10343
|
};
|
|
10256
10344
|
if (typeof window !== 'undefined') {
|
|
10257
10345
|
CacheStorage$1.setContext(window);
|
|
10258
10346
|
}
|
|
10347
|
+
var parseBackgroundColor$1 = function (context, element, backgroundColorOverride) {
|
|
10348
|
+
var ownerDocument = element.ownerDocument;
|
|
10349
|
+
// http://www.w3.org/TR/css3-background/#special-backgrounds
|
|
10350
|
+
var documentBackgroundColor = ownerDocument.documentElement
|
|
10351
|
+
? parseColor$1(context, getComputedStyle(ownerDocument.documentElement).backgroundColor)
|
|
10352
|
+
: COLORS$1.TRANSPARENT;
|
|
10353
|
+
var bodyBackgroundColor = ownerDocument.body
|
|
10354
|
+
? parseColor$1(context, getComputedStyle(ownerDocument.body).backgroundColor)
|
|
10355
|
+
: COLORS$1.TRANSPARENT;
|
|
10356
|
+
var defaultBackgroundColor = typeof backgroundColorOverride === 'string'
|
|
10357
|
+
? parseColor$1(context, backgroundColorOverride)
|
|
10358
|
+
: backgroundColorOverride === null
|
|
10359
|
+
? COLORS$1.TRANSPARENT
|
|
10360
|
+
: 0xffffffff;
|
|
10361
|
+
return element === ownerDocument.documentElement
|
|
10362
|
+
? isTransparent$1(documentBackgroundColor)
|
|
10363
|
+
? isTransparent$1(bodyBackgroundColor)
|
|
10364
|
+
? defaultBackgroundColor
|
|
10365
|
+
: bodyBackgroundColor
|
|
10366
|
+
: documentBackgroundColor
|
|
10367
|
+
: defaultBackgroundColor;
|
|
10368
|
+
};
|
|
10259
10369
|
var renderElement$1 = function (element, opts) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
10260
|
-
var ownerDocument, defaultView, resourceOptions, contextOptions, windowOptions, windowBounds, context, foreignObjectRendering, cloneOptions, documentCloner, clonedElement, container, _a, width, height, left, top, backgroundColor, renderOptions, canvas, renderer, root, renderer;
|
|
10261
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
10262
|
-
return __generator$1(this, function (
|
|
10263
|
-
switch (
|
|
10370
|
+
var ownerDocument, defaultView, resourceOptions, contextOptions, windowOptions, windowBounds, context, foreignObjectRendering, cloneOptions, documentCloner, clonedElement, container, _a, width, height, left, top, backgroundColor, renderOptions, canvas, renderer, root, pageHeight, offsetY, adjustTop_1, pageRoots, renderer, i;
|
|
10371
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
|
|
10372
|
+
return __generator$1(this, function (_2) {
|
|
10373
|
+
switch (_2.label) {
|
|
10264
10374
|
case 0:
|
|
10265
10375
|
if (!element || typeof element !== 'object') {
|
|
10266
10376
|
return [2 /*return*/, Promise.reject('Invalid element provided as first argument')];
|
|
@@ -10299,7 +10409,6 @@
|
|
|
10299
10409
|
context.logger.debug("Starting document clone with size ".concat(windowBounds.width, "x").concat(windowBounds.height, " scrolled to ").concat(-windowBounds.left, ",").concat(-windowBounds.top));
|
|
10300
10410
|
documentCloner = new DocumentCloner$1(context, element, cloneOptions);
|
|
10301
10411
|
clonedElement = documentCloner.clonedReferenceElement;
|
|
10302
|
-
// console.log('设置自定义字体',opts.fontConfig,clonedElement,clonedElement.style)
|
|
10303
10412
|
if (clonedElement && clonedElement.style) {
|
|
10304
10413
|
clonedElement.style.border = 'none';
|
|
10305
10414
|
clonedElement.style.boxShadow = 'none';
|
|
@@ -10312,7 +10421,7 @@
|
|
|
10312
10421
|
}
|
|
10313
10422
|
return [4 /*yield*/, documentCloner.toIFrame(ownerDocument, windowBounds)];
|
|
10314
10423
|
case 1:
|
|
10315
|
-
container =
|
|
10424
|
+
container = _2.sent();
|
|
10316
10425
|
_a = isBodyElement$1(clonedElement) || isHTMLElement$1(clonedElement)
|
|
10317
10426
|
? parseDocumentSize$1(clonedElement.ownerDocument)
|
|
10318
10427
|
: parseBounds$1(context, clonedElement), width = _a.width, height = _a.height, left = _a.left, top = _a.top;
|
|
@@ -10327,10 +10436,36 @@
|
|
|
10327
10436
|
height: (_s = opts.height) !== null && _s !== void 0 ? _s : Math.ceil(height),
|
|
10328
10437
|
fontConfig: (_t = opts.fontConfig) !== null && _t !== void 0 ? _t : {
|
|
10329
10438
|
fontFamily: '',
|
|
10330
|
-
fontBase64: ''
|
|
10331
|
-
|
|
10332
|
-
|
|
10333
|
-
|
|
10439
|
+
fontBase64: ''
|
|
10440
|
+
},
|
|
10441
|
+
encryption: {
|
|
10442
|
+
userPassword: '',
|
|
10443
|
+
ownerPassword: '',
|
|
10444
|
+
userPermissions: []
|
|
10445
|
+
},
|
|
10446
|
+
precision: (_u = opts.precision) !== null && _u !== void 0 ? _u : 16,
|
|
10447
|
+
floatPrecision: (_v = opts.floatPrecision) !== null && _v !== void 0 ? _v : 16,
|
|
10448
|
+
compress: (_w = opts.compress) !== null && _w !== void 0 ? _w : false,
|
|
10449
|
+
putOnlyUsedFonts: (_x = opts.putOnlyUsedFonts) !== null && _x !== void 0 ? _x : false,
|
|
10450
|
+
pagination: (_y = opts.pagination) !== null && _y !== void 0 ? _y : false,
|
|
10451
|
+
format: (_z = opts.format) !== null && _z !== void 0 ? _z : 'a4',
|
|
10452
|
+
pageConfig: (_0 = opts.pageConfig) !== null && _0 !== void 0 ? _0 : {
|
|
10453
|
+
header: {
|
|
10454
|
+
content: '',
|
|
10455
|
+
height: 50,
|
|
10456
|
+
contentPosition: 'centerRight',
|
|
10457
|
+
contentColor: '#333333',
|
|
10458
|
+
contentFontSize: 16,
|
|
10459
|
+
padding: [0, 24, 0, 24]
|
|
10460
|
+
},
|
|
10461
|
+
footer: {
|
|
10462
|
+
content: '${currentPage}/${totalPages}',
|
|
10463
|
+
height: 50,
|
|
10464
|
+
contentPosition: 'center',
|
|
10465
|
+
contentColor: '#333333',
|
|
10466
|
+
contentFontSize: 16,
|
|
10467
|
+
padding: [0, 24, 0, 24]
|
|
10468
|
+
}
|
|
10334
10469
|
}
|
|
10335
10470
|
};
|
|
10336
10471
|
if (!foreignObjectRendering) return [3 /*break*/, 3];
|
|
@@ -10338,28 +10473,67 @@
|
|
|
10338
10473
|
renderer = new ForeignObjectRenderer$1(context, renderOptions);
|
|
10339
10474
|
return [4 /*yield*/, renderer.render(clonedElement)];
|
|
10340
10475
|
case 2:
|
|
10341
|
-
canvas =
|
|
10342
|
-
return [3 /*break*/,
|
|
10476
|
+
canvas = _2.sent();
|
|
10477
|
+
return [3 /*break*/, 11];
|
|
10343
10478
|
case 3:
|
|
10344
10479
|
context.logger.debug("Document cloned, element located at ".concat(left, ",").concat(top, " with size ").concat(width, "x").concat(height, " using computed rendering"));
|
|
10345
10480
|
context.logger.debug("Starting DOM parsing", context, clonedElement);
|
|
10346
10481
|
return [4 /*yield*/, parseTree$1(context, clonedElement)];
|
|
10347
10482
|
case 4:
|
|
10348
|
-
root =
|
|
10483
|
+
root = _2.sent();
|
|
10484
|
+
pageHeight = PAGE_FORMAT_MAP[renderOptions.format || 'a4'].height;
|
|
10485
|
+
if (renderOptions.y !== 0) {
|
|
10486
|
+
offsetY = renderOptions.y;
|
|
10487
|
+
renderOptions.y = 0;
|
|
10488
|
+
adjustTop_1 = function (node, delta) {
|
|
10489
|
+
node.bounds.top = node.bounds.top - delta;
|
|
10490
|
+
for (var _i = 0, _a = node.textNodes; _i < _a.length; _i++) {
|
|
10491
|
+
var tn = _a[_i];
|
|
10492
|
+
for (var _b = 0, _c = tn.textBounds; _b < _c.length; _b++) {
|
|
10493
|
+
var tb = _c[_b];
|
|
10494
|
+
tb.bounds.top = tb.bounds.top - delta;
|
|
10495
|
+
}
|
|
10496
|
+
}
|
|
10497
|
+
for (var _d = 0, _e = node.elements; _d < _e.length; _d++) {
|
|
10498
|
+
var el = _e[_d];
|
|
10499
|
+
adjustTop_1(el, delta);
|
|
10500
|
+
}
|
|
10501
|
+
};
|
|
10502
|
+
adjustTop_1(root, offsetY);
|
|
10503
|
+
}
|
|
10504
|
+
pageRoots = paginateNode(root, pageHeight, renderOptions.y, renderOptions.pageConfig);
|
|
10349
10505
|
Reflect.deleteProperty(root, 'context');
|
|
10350
|
-
// Reflect.deleteProperty(root, 'elements')
|
|
10351
|
-
// =[];
|
|
10352
10506
|
if (backgroundColor === root.styles.backgroundColor) {
|
|
10353
10507
|
root.styles.backgroundColor = COLORS$1.TRANSPARENT;
|
|
10354
10508
|
}
|
|
10355
10509
|
context.logger.debug("Starting renderer for element at ".concat(renderOptions.x, ",").concat(renderOptions.y, " with size ").concat(renderOptions.width, "x").concat(renderOptions.height));
|
|
10510
|
+
// console.log('pageRootrenderOptions', root, renderOptions, pageRoots);
|
|
10511
|
+
// , pageRoots, paginationState
|
|
10512
|
+
renderOptions.y = 0;
|
|
10356
10513
|
renderer = new CanvasRenderer$1(context, renderOptions);
|
|
10357
|
-
|
|
10514
|
+
renderer.setTotalPages(pageRoots.length);
|
|
10515
|
+
if (!(pageRoots.length > 0)) return [3 /*break*/, 9];
|
|
10516
|
+
return [4 /*yield*/, renderer.renderPage(pageRoots[0], 1)];
|
|
10358
10517
|
case 5:
|
|
10359
|
-
|
|
10360
|
-
|
|
10518
|
+
_2.sent();
|
|
10519
|
+
i = 1;
|
|
10520
|
+
_2.label = 6;
|
|
10361
10521
|
case 6:
|
|
10362
|
-
if ((
|
|
10522
|
+
if (!(i < pageRoots.length)) return [3 /*break*/, 9];
|
|
10523
|
+
renderer.addPage(0);
|
|
10524
|
+
return [4 /*yield*/, renderer.renderPage(pageRoots[i], i + 1)];
|
|
10525
|
+
case 7:
|
|
10526
|
+
_2.sent();
|
|
10527
|
+
_2.label = 8;
|
|
10528
|
+
case 8:
|
|
10529
|
+
i++;
|
|
10530
|
+
return [3 /*break*/, 6];
|
|
10531
|
+
case 9: return [4 /*yield*/, renderer.output()];
|
|
10532
|
+
case 10:
|
|
10533
|
+
canvas = _2.sent();
|
|
10534
|
+
_2.label = 11;
|
|
10535
|
+
case 11:
|
|
10536
|
+
if ((_1 = opts.removeContainer) !== null && _1 !== void 0 ? _1 : true) {
|
|
10363
10537
|
if (!DocumentCloner$1.destroy(container)) {
|
|
10364
10538
|
context.logger.error("Cannot detach cloned iframe as it is not in the DOM anymore");
|
|
10365
10539
|
}
|
|
@@ -10368,29 +10542,7 @@
|
|
|
10368
10542
|
return [2 /*return*/, canvas];
|
|
10369
10543
|
}
|
|
10370
10544
|
});
|
|
10371
|
-
}); };
|
|
10372
|
-
var parseBackgroundColor$1 = function (context, element, backgroundColorOverride) {
|
|
10373
|
-
var ownerDocument = element.ownerDocument;
|
|
10374
|
-
// http://www.w3.org/TR/css3-background/#special-backgrounds
|
|
10375
|
-
var documentBackgroundColor = ownerDocument.documentElement
|
|
10376
|
-
? parseColor$1(context, getComputedStyle(ownerDocument.documentElement).backgroundColor)
|
|
10377
|
-
: COLORS$1.TRANSPARENT;
|
|
10378
|
-
var bodyBackgroundColor = ownerDocument.body
|
|
10379
|
-
? parseColor$1(context, getComputedStyle(ownerDocument.body).backgroundColor)
|
|
10380
|
-
: COLORS$1.TRANSPARENT;
|
|
10381
|
-
var defaultBackgroundColor = typeof backgroundColorOverride === 'string'
|
|
10382
|
-
? parseColor$1(context, backgroundColorOverride)
|
|
10383
|
-
: backgroundColorOverride === null
|
|
10384
|
-
? COLORS$1.TRANSPARENT
|
|
10385
|
-
: 0xffffffff;
|
|
10386
|
-
return element === ownerDocument.documentElement
|
|
10387
|
-
? isTransparent$1(documentBackgroundColor)
|
|
10388
|
-
? isTransparent$1(bodyBackgroundColor)
|
|
10389
|
-
? defaultBackgroundColor
|
|
10390
|
-
: bodyBackgroundColor
|
|
10391
|
-
: documentBackgroundColor
|
|
10392
|
-
: defaultBackgroundColor;
|
|
10393
|
-
};
|
|
10545
|
+
}); };
|
|
10394
10546
|
|
|
10395
10547
|
/*!
|
|
10396
10548
|
* html2canvas 1.4.1 <https://html2canvas.hertzen.com>
|