pdfmake 0.3.0-beta.1 → 0.3.0-beta.11
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/.idea/workspace.xml +20 -0
- package/CHANGELOG.md +65 -1
- package/LICENSE +1 -1
- package/README.md +3 -1
- package/build/pdfmake.js +65069 -73247
- package/build/pdfmake.js.map +1 -1
- package/build/pdfmake.min.js +2 -2
- package/build/pdfmake.min.js.map +1 -1
- package/build/vfs_fonts.js +4 -4
- package/eslint.config.mjs +52 -0
- package/fonts/Roboto/Roboto-Italic.ttf +0 -0
- package/fonts/Roboto/Roboto-Medium.ttf +0 -0
- package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
- package/fonts/Roboto/Roboto-Regular.ttf +0 -0
- package/js/3rd-party/svg-to-pdfkit/source.js +247 -922
- package/js/3rd-party/svg-to-pdfkit.js +2 -6
- package/js/DocMeasure.js +24 -148
- package/js/DocPreprocessor.js +8 -55
- package/js/DocumentContext.js +44 -62
- package/js/ElementWriter.js +42 -74
- package/js/LayoutBuilder.js +225 -177
- package/js/Line.js +7 -27
- package/js/OutputDocument.js +6 -16
- package/js/OutputDocumentServer.js +2 -9
- package/js/PDFDocument.js +24 -43
- package/js/PageElementWriter.js +14 -35
- package/js/PageSize.js +3 -17
- package/js/Printer.js +102 -49
- package/js/Renderer.js +37 -95
- package/js/SVGMeasure.js +3 -23
- package/js/StyleContextStack.js +13 -55
- package/js/TableProcessor.js +94 -136
- package/js/TextBreaker.js +4 -47
- package/js/TextDecorator.js +3 -41
- package/js/TextInlines.js +10 -52
- package/js/URLResolver.js +18 -24
- package/js/base.js +3 -20
- package/js/browser-extensions/OutputDocumentBrowser.js +7 -20
- package/js/browser-extensions/URLBrowserResolver.js +7 -20
- package/js/browser-extensions/fonts/Roboto.js +0 -4
- package/js/browser-extensions/index.js +2 -19
- package/js/browser-extensions/pdfMake.js +0 -14
- package/js/browser-extensions/standard-fonts/Courier.js +0 -4
- package/js/browser-extensions/standard-fonts/Helvetica.js +0 -4
- package/js/browser-extensions/standard-fonts/Symbol.js +0 -4
- package/js/browser-extensions/standard-fonts/Times.js +0 -4
- package/js/browser-extensions/standard-fonts/ZapfDingbats.js +0 -4
- package/js/columnCalculator.js +30 -24
- package/js/helpers/node.js +3 -27
- package/js/helpers/tools.js +0 -8
- package/js/helpers/variableType.js +15 -8
- package/js/index.js +0 -6
- package/js/qrEnc.js +133 -222
- package/js/standardPageSizes.js +2 -3
- package/js/tableLayouts.js +4 -33
- package/js/virtual-fs.js +4 -21
- package/package.json +25 -22
- package/src/DocMeasure.js +19 -6
- package/src/DocPreprocessor.js +6 -0
- package/src/DocumentContext.js +35 -20
- package/src/ElementWriter.js +45 -5
- package/src/LayoutBuilder.js +201 -18
- package/src/OutputDocument.js +1 -1
- package/src/PDFDocument.js +27 -1
- package/src/PageElementWriter.js +6 -2
- package/src/Printer.js +93 -7
- package/src/Renderer.js +35 -0
- package/src/StyleContextStack.js +3 -44
- package/src/TableProcessor.js +64 -20
- package/src/TextDecorator.js +1 -1
- package/src/URLResolver.js +16 -8
- package/src/browser-extensions/URLBrowserResolver.js +6 -3
- package/src/browser-extensions/index.js +1 -1
- package/src/browser-extensions/pdfMake.js +0 -14
- package/src/columnCalculator.js +24 -3
- package/src/helpers/variableType.js +11 -0
- package/src/qrEnc.js +5 -3
package/js/TableProcessor.js
CHANGED
|
@@ -2,18 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.default = void 0;
|
|
5
|
-
|
|
6
5
|
var _columnCalculator = _interopRequireDefault(require("./columnCalculator"));
|
|
7
|
-
|
|
8
6
|
var _variableType = require("./helpers/variableType");
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
8
|
class TableProcessor {
|
|
13
9
|
constructor(tableNode) {
|
|
14
10
|
this.tableNode = tableNode;
|
|
15
11
|
}
|
|
16
|
-
|
|
17
12
|
beginTable(writer) {
|
|
18
13
|
const getTableInnerContentWidth = () => {
|
|
19
14
|
let width = 0;
|
|
@@ -22,7 +17,6 @@ class TableProcessor {
|
|
|
22
17
|
});
|
|
23
18
|
return width;
|
|
24
19
|
};
|
|
25
|
-
|
|
26
20
|
const prepareRowSpanData = () => {
|
|
27
21
|
let rsd = [];
|
|
28
22
|
let x = 0;
|
|
@@ -31,7 +25,6 @@ class TableProcessor {
|
|
|
31
25
|
left: 0,
|
|
32
26
|
rowSpan: 0
|
|
33
27
|
});
|
|
34
|
-
|
|
35
28
|
for (let i = 0, l = this.tableNode.table.body[0].length; i < l; i++) {
|
|
36
29
|
let paddings = this.layout.paddingLeft(i, this.tableNode) + this.layout.paddingRight(i, this.tableNode);
|
|
37
30
|
let lBorder = this.layout.vLineWidth(i, this.tableNode);
|
|
@@ -44,86 +37,95 @@ class TableProcessor {
|
|
|
44
37
|
width: 0
|
|
45
38
|
});
|
|
46
39
|
}
|
|
47
|
-
|
|
48
40
|
return rsd;
|
|
49
|
-
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Iterate through all cells. If the current cell is the start of a
|
|
50
44
|
// rowSpan/colSpan, update the border property of the cells on its
|
|
51
45
|
// bottom/right accordingly. This is needed since each iteration of the
|
|
52
46
|
// line-drawing loops draws lines for a single cell, not for an entire
|
|
53
47
|
// rowSpan/colSpan.
|
|
54
|
-
|
|
55
|
-
|
|
56
48
|
const prepareCellBorders = body => {
|
|
57
49
|
for (let rowIndex = 0; rowIndex < body.length; rowIndex++) {
|
|
58
50
|
let row = body[rowIndex];
|
|
59
|
-
|
|
60
51
|
for (let colIndex = 0; colIndex < row.length; colIndex++) {
|
|
61
52
|
let cell = row[colIndex];
|
|
62
|
-
|
|
63
53
|
if (cell.border) {
|
|
64
54
|
let rowSpan = cell.rowSpan || 1;
|
|
65
55
|
let colSpan = cell.colSpan || 1;
|
|
66
|
-
|
|
67
56
|
for (let rowOffset = 0; rowOffset < rowSpan; rowOffset++) {
|
|
68
57
|
// set left border
|
|
69
58
|
if (cell.border[0] !== undefined && rowOffset > 0) {
|
|
70
59
|
setBorder(rowIndex + rowOffset, colIndex, 0, cell.border[0]);
|
|
71
|
-
}
|
|
72
|
-
|
|
60
|
+
}
|
|
73
61
|
|
|
62
|
+
// set right border
|
|
74
63
|
if (cell.border[2] !== undefined) {
|
|
75
64
|
setBorder(rowIndex + rowOffset, colIndex + colSpan - 1, 2, cell.border[2]);
|
|
76
65
|
}
|
|
77
66
|
}
|
|
78
|
-
|
|
79
67
|
for (let colOffset = 0; colOffset < colSpan; colOffset++) {
|
|
80
68
|
// set top border
|
|
81
69
|
if (cell.border[1] !== undefined && colOffset > 0) {
|
|
82
70
|
setBorder(rowIndex, colIndex + colOffset, 1, cell.border[1]);
|
|
83
|
-
}
|
|
84
|
-
|
|
71
|
+
}
|
|
85
72
|
|
|
73
|
+
// set bottom border
|
|
86
74
|
if (cell.border[3] !== undefined) {
|
|
87
75
|
setBorder(rowIndex + rowSpan - 1, colIndex + colOffset, 3, cell.border[3]);
|
|
88
76
|
}
|
|
89
77
|
}
|
|
90
78
|
}
|
|
91
79
|
}
|
|
92
|
-
}
|
|
93
|
-
|
|
80
|
+
}
|
|
94
81
|
|
|
82
|
+
// helper function to set the border for a given cell
|
|
95
83
|
function setBorder(rowIndex, colIndex, borderIndex, borderValue) {
|
|
96
84
|
let cell = body[rowIndex][colIndex];
|
|
97
85
|
cell.border = cell.border || {};
|
|
98
86
|
cell.border[borderIndex] = borderValue;
|
|
99
87
|
}
|
|
100
88
|
};
|
|
101
|
-
|
|
102
89
|
let tableNode;
|
|
103
90
|
let availableWidth;
|
|
104
91
|
tableNode = this.tableNode;
|
|
105
92
|
this.offsets = tableNode._offsets;
|
|
106
93
|
this.layout = tableNode._layout;
|
|
107
94
|
availableWidth = writer.context().availableWidth - this.offsets.total;
|
|
108
|
-
|
|
109
|
-
_columnCalculator.default.buildColumnWidths(tableNode.table.widths, availableWidth);
|
|
110
|
-
|
|
95
|
+
_columnCalculator.default.buildColumnWidths(tableNode.table.widths, availableWidth, this.offsets.total, tableNode);
|
|
111
96
|
this.tableWidth = tableNode._offsets.total + getTableInnerContentWidth();
|
|
112
97
|
this.rowSpanData = prepareRowSpanData();
|
|
113
98
|
this.cleanUpRepeatables = false;
|
|
114
|
-
this.headerRows = tableNode.table.headerRows || 0;
|
|
115
|
-
this.rowsWithoutPageBreak = this.headerRows + (tableNode.table.keepWithHeaderRows || 0);
|
|
116
|
-
this.dontBreakRows = tableNode.table.dontBreakRows || false;
|
|
117
99
|
|
|
118
|
-
|
|
100
|
+
// headersRows and rowsWithoutPageBreak (headerRows + keepWithHeaderRows)
|
|
101
|
+
this.headerRows = 0;
|
|
102
|
+
this.rowsWithoutPageBreak = 0;
|
|
103
|
+
const headerRows = tableNode.table.headerRows;
|
|
104
|
+
if ((0, _variableType.isPositiveInteger)(headerRows)) {
|
|
105
|
+
this.headerRows = headerRows;
|
|
106
|
+
if (this.headerRows > tableNode.table.body.length) {
|
|
107
|
+
throw new Error(`Too few rows in the table. Property headerRows requires at least ${this.headerRows}, contains only ${tableNode.table.body.length}`);
|
|
108
|
+
}
|
|
109
|
+
this.rowsWithoutPageBreak = this.headerRows;
|
|
110
|
+
const keepWithHeaderRows = tableNode.table.keepWithHeaderRows;
|
|
111
|
+
if ((0, _variableType.isPositiveInteger)(keepWithHeaderRows)) {
|
|
112
|
+
this.rowsWithoutPageBreak += keepWithHeaderRows;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
this.dontBreakRows = tableNode.table.dontBreakRows || false;
|
|
116
|
+
if (this.rowsWithoutPageBreak || this.dontBreakRows) {
|
|
119
117
|
writer.beginUnbreakableBlock();
|
|
120
|
-
|
|
121
|
-
|
|
118
|
+
// Draw the top border of the table
|
|
119
|
+
this.drawHorizontalLine(0, writer);
|
|
120
|
+
if (this.rowsWithoutPageBreak && this.dontBreakRows) {
|
|
121
|
+
// We just increase the value of transactionLevel
|
|
122
|
+
writer.beginUnbreakableBlock();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
122
125
|
|
|
126
|
+
// update the border properties of all cells before drawing any lines
|
|
123
127
|
prepareCellBorders(this.tableNode.table.body);
|
|
124
|
-
this.drawHorizontalLine(0, writer);
|
|
125
128
|
}
|
|
126
|
-
|
|
127
129
|
onRowBreak(rowIndex, writer) {
|
|
128
130
|
return () => {
|
|
129
131
|
let offset = this.rowPaddingTop + (!this.headerRows ? this.topLineWidth : 0);
|
|
@@ -131,7 +133,6 @@ class TableProcessor {
|
|
|
131
133
|
writer.context().moveDown(offset);
|
|
132
134
|
};
|
|
133
135
|
}
|
|
134
|
-
|
|
135
136
|
beginRow(rowIndex, writer) {
|
|
136
137
|
this.topLineWidth = this.layout.hLineWidth(rowIndex, this.tableNode);
|
|
137
138
|
this.rowPaddingTop = this.layout.paddingTop(rowIndex, this.tableNode);
|
|
@@ -139,116 +140,102 @@ class TableProcessor {
|
|
|
139
140
|
this.rowPaddingBottom = this.layout.paddingBottom(rowIndex, this.tableNode);
|
|
140
141
|
this.rowCallback = this.onRowBreak(rowIndex, writer);
|
|
141
142
|
writer.addListener('pageChanged', this.rowCallback);
|
|
142
|
-
|
|
143
|
-
|
|
143
|
+
if (rowIndex == 0 && !this.dontBreakRows && !this.rowsWithoutPageBreak) {
|
|
144
|
+
// We store the 'y' to draw later and if necessary the top border of the table
|
|
145
|
+
this._tableTopBorderY = writer.context().y;
|
|
146
|
+
writer.context().moveDown(this.topLineWidth);
|
|
147
|
+
}
|
|
148
|
+
if (this.dontBreakRows && rowIndex > 0) {
|
|
144
149
|
writer.beginUnbreakableBlock();
|
|
145
150
|
}
|
|
146
|
-
|
|
147
151
|
this.rowTopY = writer.context().y;
|
|
148
152
|
this.reservedAtBottom = this.bottomLineWidth + this.rowPaddingBottom;
|
|
149
153
|
writer.context().availableHeight -= this.reservedAtBottom;
|
|
150
154
|
writer.context().moveDown(this.rowPaddingTop);
|
|
151
155
|
}
|
|
152
|
-
|
|
153
|
-
drawHorizontalLine(lineIndex, writer, overrideY) {
|
|
156
|
+
drawHorizontalLine(lineIndex, writer, overrideY, moveDown = true, forcePage) {
|
|
154
157
|
let lineWidth = this.layout.hLineWidth(lineIndex, this.tableNode);
|
|
155
|
-
|
|
156
158
|
if (lineWidth) {
|
|
157
159
|
let style = this.layout.hLineStyle(lineIndex, this.tableNode);
|
|
158
160
|
let dash;
|
|
159
|
-
|
|
160
161
|
if (style && style.dash) {
|
|
161
162
|
dash = style.dash;
|
|
162
163
|
}
|
|
163
|
-
|
|
164
164
|
let offset = lineWidth / 2;
|
|
165
165
|
let currentLine = null;
|
|
166
166
|
let body = this.tableNode.table.body;
|
|
167
167
|
let cellAbove;
|
|
168
168
|
let currentCell;
|
|
169
169
|
let rowCellAbove;
|
|
170
|
-
|
|
171
170
|
for (let i = 0, l = this.rowSpanData.length; i < l; i++) {
|
|
172
171
|
let data = this.rowSpanData[i];
|
|
173
172
|
let shouldDrawLine = !data.rowSpan;
|
|
174
|
-
let borderColor = null;
|
|
175
|
-
// row above requires a bottom border
|
|
173
|
+
let borderColor = null;
|
|
176
174
|
|
|
175
|
+
// draw only if the current cell requires a top border or the cell in the
|
|
176
|
+
// row above requires a bottom border
|
|
177
177
|
if (shouldDrawLine && i < l - 1) {
|
|
178
178
|
var topBorder = false,
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
bottomBorder = false,
|
|
180
|
+
rowBottomBorder = false;
|
|
181
181
|
|
|
182
|
+
// the cell in the row above
|
|
182
183
|
if (lineIndex > 0) {
|
|
183
184
|
cellAbove = body[lineIndex - 1][i];
|
|
184
185
|
bottomBorder = cellAbove.border ? cellAbove.border[3] : this.layout.defaultBorder;
|
|
185
|
-
|
|
186
186
|
if (bottomBorder && cellAbove.borderColor) {
|
|
187
187
|
borderColor = cellAbove.borderColor[3];
|
|
188
188
|
}
|
|
189
|
-
}
|
|
190
|
-
|
|
189
|
+
}
|
|
191
190
|
|
|
191
|
+
// the current cell
|
|
192
192
|
if (lineIndex < body.length) {
|
|
193
193
|
currentCell = body[lineIndex][i];
|
|
194
194
|
topBorder = currentCell.border ? currentCell.border[1] : this.layout.defaultBorder;
|
|
195
|
-
|
|
196
195
|
if (topBorder && borderColor == null && currentCell.borderColor) {
|
|
197
196
|
borderColor = currentCell.borderColor[1];
|
|
198
197
|
}
|
|
199
198
|
}
|
|
200
|
-
|
|
201
199
|
shouldDrawLine = topBorder || bottomBorder;
|
|
202
200
|
}
|
|
203
|
-
|
|
204
201
|
if (cellAbove && cellAbove._rowSpanCurrentOffset) {
|
|
205
202
|
rowCellAbove = body[lineIndex - 1 - cellAbove._rowSpanCurrentOffset][i];
|
|
206
203
|
rowBottomBorder = rowCellAbove && rowCellAbove.border ? rowCellAbove.border[3] : this.layout.defaultBorder;
|
|
207
|
-
|
|
208
204
|
if (rowBottomBorder && rowCellAbove && rowCellAbove.borderColor) {
|
|
209
205
|
borderColor = rowCellAbove.borderColor[3];
|
|
210
206
|
}
|
|
211
207
|
}
|
|
212
|
-
|
|
213
208
|
if (borderColor == null) {
|
|
214
209
|
borderColor = typeof this.layout.hLineColor === 'function' ? this.layout.hLineColor(lineIndex, this.tableNode, i) : this.layout.hLineColor;
|
|
215
210
|
}
|
|
216
|
-
|
|
217
211
|
if (!currentLine && shouldDrawLine) {
|
|
218
212
|
currentLine = {
|
|
219
213
|
left: data.left,
|
|
220
214
|
width: 0
|
|
221
215
|
};
|
|
222
216
|
}
|
|
223
|
-
|
|
224
217
|
if (shouldDrawLine) {
|
|
225
218
|
let colSpanIndex = 0;
|
|
226
|
-
|
|
227
219
|
if (rowCellAbove && rowCellAbove.colSpan && rowBottomBorder) {
|
|
228
220
|
while (rowCellAbove.colSpan > colSpanIndex) {
|
|
229
221
|
currentLine.width += this.rowSpanData[i + colSpanIndex++].width || 0;
|
|
230
222
|
}
|
|
231
|
-
|
|
232
223
|
i += colSpanIndex - 1;
|
|
233
224
|
} else if (cellAbove && cellAbove.colSpan && bottomBorder) {
|
|
234
225
|
while (cellAbove.colSpan > colSpanIndex) {
|
|
235
226
|
currentLine.width += this.rowSpanData[i + colSpanIndex++].width || 0;
|
|
236
227
|
}
|
|
237
|
-
|
|
238
228
|
i += colSpanIndex - 1;
|
|
239
229
|
} else if (currentCell && currentCell.colSpan && topBorder) {
|
|
240
230
|
while (currentCell.colSpan > colSpanIndex) {
|
|
241
231
|
currentLine.width += this.rowSpanData[i + colSpanIndex++].width || 0;
|
|
242
232
|
}
|
|
243
|
-
|
|
244
233
|
i += colSpanIndex - 1;
|
|
245
234
|
} else {
|
|
246
235
|
currentLine.width += this.rowSpanData[i].width || 0;
|
|
247
236
|
}
|
|
248
237
|
}
|
|
249
|
-
|
|
250
238
|
let y = (overrideY || 0) + offset;
|
|
251
|
-
|
|
252
239
|
if (shouldDrawLine) {
|
|
253
240
|
if (currentLine && currentLine.width) {
|
|
254
241
|
writer.addVector({
|
|
@@ -260,7 +247,7 @@ class TableProcessor {
|
|
|
260
247
|
lineWidth: lineWidth,
|
|
261
248
|
dash: dash,
|
|
262
249
|
lineColor: borderColor
|
|
263
|
-
}, false, overrideY);
|
|
250
|
+
}, false, (0, _variableType.isNumber)(overrideY), null, forcePage);
|
|
264
251
|
currentLine = null;
|
|
265
252
|
borderColor = null;
|
|
266
253
|
cellAbove = null;
|
|
@@ -269,75 +256,64 @@ class TableProcessor {
|
|
|
269
256
|
}
|
|
270
257
|
}
|
|
271
258
|
}
|
|
272
|
-
|
|
273
|
-
|
|
259
|
+
if (moveDown) {
|
|
260
|
+
writer.context().moveDown(lineWidth);
|
|
261
|
+
}
|
|
274
262
|
}
|
|
275
263
|
}
|
|
276
|
-
|
|
277
264
|
drawVerticalLine(x, y0, y1, vLineColIndex, writer, vLineRowIndex, beforeVLineColIndex) {
|
|
278
265
|
let width = this.layout.vLineWidth(vLineColIndex, this.tableNode);
|
|
279
|
-
|
|
280
266
|
if (width === 0) {
|
|
281
267
|
return;
|
|
282
268
|
}
|
|
283
|
-
|
|
284
269
|
let style = this.layout.vLineStyle(vLineColIndex, this.tableNode);
|
|
285
270
|
let dash;
|
|
286
|
-
|
|
287
271
|
if (style && style.dash) {
|
|
288
272
|
dash = style.dash;
|
|
289
273
|
}
|
|
290
|
-
|
|
291
274
|
let body = this.tableNode.table.body;
|
|
292
275
|
let cellBefore;
|
|
293
276
|
let currentCell;
|
|
294
|
-
let borderColor;
|
|
277
|
+
let borderColor;
|
|
295
278
|
|
|
279
|
+
// the cell in the col before
|
|
296
280
|
if (vLineColIndex > 0) {
|
|
297
281
|
cellBefore = body[vLineRowIndex][beforeVLineColIndex];
|
|
298
|
-
|
|
299
282
|
if (cellBefore && cellBefore.borderColor) {
|
|
300
283
|
if (cellBefore.border ? cellBefore.border[2] : this.layout.defaultBorder) {
|
|
301
284
|
borderColor = cellBefore.borderColor[2];
|
|
302
285
|
}
|
|
303
286
|
}
|
|
304
|
-
}
|
|
305
|
-
|
|
287
|
+
}
|
|
306
288
|
|
|
289
|
+
// the current cell
|
|
307
290
|
if (borderColor == null && vLineColIndex < body.length) {
|
|
308
291
|
currentCell = body[vLineRowIndex][vLineColIndex];
|
|
309
|
-
|
|
310
292
|
if (currentCell && currentCell.borderColor) {
|
|
311
293
|
if (currentCell.border ? currentCell.border[0] : this.layout.defaultBorder) {
|
|
312
294
|
borderColor = currentCell.borderColor[0];
|
|
313
295
|
}
|
|
314
296
|
}
|
|
315
297
|
}
|
|
316
|
-
|
|
317
298
|
if (borderColor == null && cellBefore && cellBefore._rowSpanCurrentOffset) {
|
|
318
299
|
let rowCellBeforeAbove = body[vLineRowIndex - cellBefore._rowSpanCurrentOffset][beforeVLineColIndex];
|
|
319
|
-
|
|
320
300
|
if (rowCellBeforeAbove.borderColor) {
|
|
321
301
|
if (rowCellBeforeAbove.border ? rowCellBeforeAbove.border[2] : this.layout.defaultBorder) {
|
|
322
302
|
borderColor = rowCellBeforeAbove.borderColor[2];
|
|
323
303
|
}
|
|
324
304
|
}
|
|
325
305
|
}
|
|
326
|
-
|
|
327
306
|
if (borderColor == null && currentCell && currentCell._rowSpanCurrentOffset) {
|
|
328
307
|
let rowCurrentCellAbove = body[vLineRowIndex - currentCell._rowSpanCurrentOffset][vLineColIndex];
|
|
329
|
-
|
|
330
308
|
if (rowCurrentCellAbove.borderColor) {
|
|
331
309
|
if (rowCurrentCellAbove.border ? rowCurrentCellAbove.border[2] : this.layout.defaultBorder) {
|
|
332
310
|
borderColor = rowCurrentCellAbove.borderColor[2];
|
|
333
311
|
}
|
|
334
312
|
}
|
|
335
313
|
}
|
|
336
|
-
|
|
337
314
|
if (borderColor == null) {
|
|
338
315
|
borderColor = typeof this.layout.vLineColor === 'function' ? this.layout.vLineColor(vLineColIndex, this.tableNode, vLineRowIndex) : this.layout.vLineColor;
|
|
339
316
|
}
|
|
340
|
-
|
|
341
317
|
writer.addVector({
|
|
342
318
|
type: 'line',
|
|
343
319
|
x1: x + width / 2,
|
|
@@ -352,18 +328,15 @@ class TableProcessor {
|
|
|
352
328
|
currentCell = null;
|
|
353
329
|
borderColor = null;
|
|
354
330
|
}
|
|
355
|
-
|
|
356
331
|
endTable(writer) {
|
|
357
332
|
if (this.cleanUpRepeatables) {
|
|
358
333
|
writer.popFromRepeatables();
|
|
359
334
|
}
|
|
360
335
|
}
|
|
361
|
-
|
|
362
336
|
endRow(rowIndex, writer, pageBreaks) {
|
|
363
337
|
const getLineXs = () => {
|
|
364
338
|
let result = [];
|
|
365
339
|
let cols = 0;
|
|
366
|
-
|
|
367
340
|
for (let i = 0, l = this.tableNode.table.body[rowIndex].length; i < l; i++) {
|
|
368
341
|
if (!cols) {
|
|
369
342
|
result.push({
|
|
@@ -373,19 +346,16 @@ class TableProcessor {
|
|
|
373
346
|
let item = this.tableNode.table.body[rowIndex][i];
|
|
374
347
|
cols = item._colSpan || item.colSpan || 0;
|
|
375
348
|
}
|
|
376
|
-
|
|
377
349
|
if (cols > 0) {
|
|
378
350
|
cols--;
|
|
379
351
|
}
|
|
380
352
|
}
|
|
381
|
-
|
|
382
353
|
result.push({
|
|
383
354
|
x: this.rowSpanData[this.rowSpanData.length - 1].left,
|
|
384
355
|
index: this.rowSpanData.length - 1
|
|
385
356
|
});
|
|
386
357
|
return result;
|
|
387
358
|
};
|
|
388
|
-
|
|
389
359
|
writer.removeListener('pageChanged', this.rowCallback);
|
|
390
360
|
writer.context().moveDown(this.layout.paddingBottom(rowIndex, this.tableNode));
|
|
391
361
|
writer.context().availableHeight += this.reservedAtBottom;
|
|
@@ -399,7 +369,6 @@ class TableProcessor {
|
|
|
399
369
|
y0: this.rowTopY,
|
|
400
370
|
page: hasBreaks ? pageBreaks[0].prevPage : endingPage
|
|
401
371
|
});
|
|
402
|
-
|
|
403
372
|
if (hasBreaks) {
|
|
404
373
|
for (let i = 0, l = pageBreaks.length; i < l; i++) {
|
|
405
374
|
let pageBreak = pageBreaks[i];
|
|
@@ -410,74 +379,81 @@ class TableProcessor {
|
|
|
410
379
|
});
|
|
411
380
|
}
|
|
412
381
|
}
|
|
413
|
-
|
|
414
382
|
ys[ys.length - 1].y1 = endingY;
|
|
415
383
|
let skipOrphanePadding = ys[0].y1 - ys[0].y0 === this.rowPaddingTop;
|
|
416
|
-
|
|
384
|
+
if (rowIndex === 0 && !skipOrphanePadding && !this.rowsWithoutPageBreak && !this.dontBreakRows) {
|
|
385
|
+
// Draw the top border of the table
|
|
386
|
+
let pageTableStartedAt = null;
|
|
387
|
+
if (pageBreaks && pageBreaks.length > 0) {
|
|
388
|
+
// Get the page where table started at
|
|
389
|
+
pageTableStartedAt = pageBreaks[0].prevPage;
|
|
390
|
+
}
|
|
391
|
+
this.drawHorizontalLine(0, writer, this._tableTopBorderY, false, pageTableStartedAt);
|
|
392
|
+
}
|
|
417
393
|
for (let yi = skipOrphanePadding ? 1 : 0, yl = ys.length; yi < yl; yi++) {
|
|
418
394
|
let willBreak = yi < ys.length - 1;
|
|
419
395
|
let rowBreakWithoutHeader = yi > 0 && !this.headerRows;
|
|
420
396
|
let hzLineOffset = rowBreakWithoutHeader ? 0 : this.topLineWidth;
|
|
421
397
|
let y1 = ys[yi].y0;
|
|
422
398
|
let y2 = ys[yi].y1;
|
|
423
|
-
|
|
424
399
|
if (willBreak) {
|
|
425
400
|
y2 = y2 + this.rowPaddingBottom;
|
|
426
401
|
}
|
|
427
|
-
|
|
428
402
|
if (writer.context().page != ys[yi].page) {
|
|
429
|
-
writer.context().page = ys[yi].page;
|
|
430
|
-
// TableProcessor should be pageChanged listener, instead of processRow
|
|
403
|
+
writer.context().page = ys[yi].page;
|
|
431
404
|
|
|
405
|
+
//TODO: buggy, availableHeight should be updated on every pageChanged event
|
|
406
|
+
// TableProcessor should be pageChanged listener, instead of processRow
|
|
432
407
|
this.reservedAtBottom = 0;
|
|
433
408
|
}
|
|
434
409
|
|
|
410
|
+
// Draw horizontal lines before the vertical lines so they are not overridden
|
|
411
|
+
if (willBreak && this.layout.hLineWhenBroken !== false) {
|
|
412
|
+
this.drawHorizontalLine(rowIndex + 1, writer, y2);
|
|
413
|
+
}
|
|
414
|
+
if (rowBreakWithoutHeader && this.layout.hLineWhenBroken !== false) {
|
|
415
|
+
this.drawHorizontalLine(rowIndex, writer, y1);
|
|
416
|
+
}
|
|
435
417
|
for (let i = 0, l = xs.length; i < l; i++) {
|
|
436
418
|
let leftCellBorder = false;
|
|
437
419
|
let rightCellBorder = false;
|
|
438
|
-
let colIndex = xs[i].index;
|
|
420
|
+
let colIndex = xs[i].index;
|
|
439
421
|
|
|
422
|
+
// current cell
|
|
440
423
|
if (colIndex < body[rowIndex].length) {
|
|
441
424
|
let cell = body[rowIndex][colIndex];
|
|
442
425
|
leftCellBorder = cell.border ? cell.border[0] : this.layout.defaultBorder;
|
|
443
426
|
rightCellBorder = cell.border ? cell.border[2] : this.layout.defaultBorder;
|
|
444
|
-
}
|
|
445
|
-
|
|
427
|
+
}
|
|
446
428
|
|
|
429
|
+
// before cell
|
|
447
430
|
if (colIndex > 0 && !leftCellBorder) {
|
|
448
431
|
let cell = body[rowIndex][colIndex - 1];
|
|
449
432
|
leftCellBorder = cell.border ? cell.border[2] : this.layout.defaultBorder;
|
|
450
|
-
}
|
|
451
|
-
|
|
433
|
+
}
|
|
452
434
|
|
|
435
|
+
// after cell
|
|
453
436
|
if (colIndex + 1 < body[rowIndex].length && !rightCellBorder) {
|
|
454
437
|
let cell = body[rowIndex][colIndex + 1];
|
|
455
438
|
rightCellBorder = cell.border ? cell.border[0] : this.layout.defaultBorder;
|
|
456
439
|
}
|
|
457
|
-
|
|
458
440
|
if (leftCellBorder) {
|
|
459
441
|
this.drawVerticalLine(xs[i].x, y1 - hzLineOffset, y2 + this.bottomLineWidth, xs[i].index, writer, rowIndex, xs[i - 1] ? xs[i - 1].index : null);
|
|
460
442
|
}
|
|
461
|
-
|
|
462
443
|
if (i < l - 1) {
|
|
463
444
|
let fillColor = body[rowIndex][colIndex].fillColor;
|
|
464
445
|
let fillOpacity = body[rowIndex][colIndex].fillOpacity;
|
|
465
|
-
|
|
466
446
|
if (!fillColor) {
|
|
467
447
|
fillColor = typeof this.layout.fillColor === 'function' ? this.layout.fillColor(rowIndex, this.tableNode, colIndex) : this.layout.fillColor;
|
|
468
448
|
}
|
|
469
|
-
|
|
470
449
|
if (!(0, _variableType.isNumber)(fillOpacity)) {
|
|
471
450
|
fillOpacity = typeof this.layout.fillOpacity === 'function' ? this.layout.fillOpacity(rowIndex, this.tableNode, colIndex) : this.layout.fillOpacity;
|
|
472
451
|
}
|
|
473
|
-
|
|
474
452
|
var overlayPattern = body[rowIndex][colIndex].overlayPattern;
|
|
475
453
|
var overlayOpacity = body[rowIndex][colIndex].overlayOpacity;
|
|
476
|
-
|
|
477
454
|
if (fillColor || overlayPattern) {
|
|
478
455
|
let widthLeftBorder = leftCellBorder ? this.layout.vLineWidth(colIndex, this.tableNode) : 0;
|
|
479
456
|
let widthRightBorder;
|
|
480
|
-
|
|
481
457
|
if ((colIndex === 0 || colIndex + 1 == body[rowIndex].length) && !rightCellBorder) {
|
|
482
458
|
widthRightBorder = this.layout.vLineWidth(colIndex + 1, this.tableNode);
|
|
483
459
|
} else if (rightCellBorder) {
|
|
@@ -485,14 +461,12 @@ class TableProcessor {
|
|
|
485
461
|
} else {
|
|
486
462
|
widthRightBorder = 0;
|
|
487
463
|
}
|
|
488
|
-
|
|
489
464
|
let x1f = this.dontBreakRows ? xs[i].x + widthLeftBorder : xs[i].x + widthLeftBorder / 2;
|
|
490
465
|
let y1f = this.dontBreakRows ? y1 : y1 - hzLineOffset / 2;
|
|
491
466
|
let x2f = xs[i + 1].x + widthRightBorder;
|
|
492
467
|
let y2f = this.dontBreakRows ? y2 + this.bottomLineWidth : y2 + this.bottomLineWidth / 2;
|
|
493
468
|
var bgWidth = x2f - x1f;
|
|
494
469
|
var bgHeight = y2f - y1f;
|
|
495
|
-
|
|
496
470
|
if (fillColor) {
|
|
497
471
|
writer.addVector({
|
|
498
472
|
type: 'rect',
|
|
@@ -502,10 +476,11 @@ class TableProcessor {
|
|
|
502
476
|
h: bgHeight,
|
|
503
477
|
lineWidth: 0,
|
|
504
478
|
color: fillColor,
|
|
505
|
-
fillOpacity: fillOpacity
|
|
479
|
+
fillOpacity: fillOpacity,
|
|
480
|
+
// mark if we are in an unbreakable block
|
|
481
|
+
_isFillColorFromUnbreakable: !!writer.transactionLevel
|
|
506
482
|
}, false, true, writer.context().backgroundLength[writer.context().page]);
|
|
507
483
|
}
|
|
508
|
-
|
|
509
484
|
if (overlayPattern) {
|
|
510
485
|
writer.addVector({
|
|
511
486
|
type: 'rect',
|
|
@@ -521,61 +496,47 @@ class TableProcessor {
|
|
|
521
496
|
}
|
|
522
497
|
}
|
|
523
498
|
}
|
|
524
|
-
|
|
525
|
-
if (willBreak && this.layout.hLineWhenBroken !== false) {
|
|
526
|
-
this.drawHorizontalLine(rowIndex + 1, writer, y2);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
if (rowBreakWithoutHeader && this.layout.hLineWhenBroken !== false) {
|
|
530
|
-
this.drawHorizontalLine(rowIndex, writer, y1);
|
|
531
|
-
}
|
|
532
499
|
}
|
|
533
|
-
|
|
534
500
|
writer.context().page = endingPage;
|
|
535
501
|
writer.context().y = endingY;
|
|
536
502
|
let row = this.tableNode.table.body[rowIndex];
|
|
537
|
-
|
|
538
503
|
for (let i = 0, l = row.length; i < l; i++) {
|
|
539
504
|
if (row[i].rowSpan) {
|
|
540
|
-
this.rowSpanData[i].rowSpan = row[i].rowSpan;
|
|
505
|
+
this.rowSpanData[i].rowSpan = row[i].rowSpan;
|
|
541
506
|
|
|
507
|
+
// fix colSpans
|
|
542
508
|
if (row[i].colSpan && row[i].colSpan > 1) {
|
|
543
509
|
for (let j = 1; j < row[i].rowSpan; j++) {
|
|
544
510
|
this.tableNode.table.body[rowIndex + j][i]._colSpan = row[i].colSpan;
|
|
545
511
|
}
|
|
546
|
-
}
|
|
547
|
-
|
|
512
|
+
}
|
|
548
513
|
|
|
514
|
+
// fix rowSpans
|
|
549
515
|
if (row[i].rowSpan && row[i].rowSpan > 1) {
|
|
550
516
|
for (let j = 1; j < row[i].rowSpan; j++) {
|
|
551
517
|
this.tableNode.table.body[rowIndex + j][i]._rowSpanCurrentOffset = j;
|
|
552
518
|
}
|
|
553
519
|
}
|
|
554
520
|
}
|
|
555
|
-
|
|
556
521
|
if (this.rowSpanData[i].rowSpan > 0) {
|
|
557
522
|
this.rowSpanData[i].rowSpan--;
|
|
558
523
|
}
|
|
559
524
|
}
|
|
560
|
-
|
|
561
525
|
this.drawHorizontalLine(rowIndex + 1, writer);
|
|
562
|
-
|
|
563
526
|
if (this.headerRows && rowIndex === this.headerRows - 1) {
|
|
564
527
|
this.headerRepeatable = writer.currentBlockToRepeatable();
|
|
565
528
|
}
|
|
566
|
-
|
|
567
529
|
if (this.dontBreakRows) {
|
|
568
530
|
const pageChangedCallback = () => {
|
|
569
|
-
if (!this.headerRows && this.layout.hLineWhenBroken !== false) {
|
|
531
|
+
if (rowIndex > 0 && !this.headerRows && this.layout.hLineWhenBroken !== false) {
|
|
532
|
+
// Draw the top border of the row after a page break
|
|
570
533
|
this.drawHorizontalLine(rowIndex, writer);
|
|
571
534
|
}
|
|
572
535
|
};
|
|
573
|
-
|
|
574
536
|
writer.addListener('pageChanged', pageChangedCallback);
|
|
575
537
|
writer.commitUnbreakableBlock();
|
|
576
538
|
writer.removeListener('pageChanged', pageChangedCallback);
|
|
577
539
|
}
|
|
578
|
-
|
|
579
540
|
if (this.headerRepeatable && (rowIndex === this.rowsWithoutPageBreak - 1 || rowIndex === this.tableNode.table.body.length - 1)) {
|
|
580
541
|
writer.commitUnbreakableBlock();
|
|
581
542
|
writer.pushToRepeatables(this.headerRepeatable);
|
|
@@ -583,8 +544,5 @@ class TableProcessor {
|
|
|
583
544
|
this.headerRepeatable = null;
|
|
584
545
|
}
|
|
585
546
|
}
|
|
586
|
-
|
|
587
547
|
}
|
|
588
|
-
|
|
589
|
-
var _default = TableProcessor;
|
|
590
|
-
exports.default = _default;
|
|
548
|
+
var _default = exports.default = TableProcessor;
|