pdfmake 0.3.0-beta.1 → 0.3.0-beta.10
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/CHANGELOG.md +61 -1
- package/LICENSE +1 -1
- package/README.md +3 -1
- package/build/pdfmake.js +65039 -73250
- 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 +38 -73
- 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 +12 -33
- 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 +58 -124
- 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 +41 -4
- package/src/LayoutBuilder.js +201 -18
- package/src/OutputDocument.js +1 -1
- package/src/PDFDocument.js +27 -1
- package/src/PageElementWriter.js +4 -0
- package/src/Printer.js +93 -7
- package/src/Renderer.js +35 -0
- package/src/StyleContextStack.js +3 -44
- package/src/TableProcessor.js +27 -5
- 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,90 @@ 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
|
|
|
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;
|
|
118
116
|
if (this.rowsWithoutPageBreak) {
|
|
119
117
|
writer.beginUnbreakableBlock();
|
|
120
|
-
}
|
|
121
|
-
|
|
118
|
+
}
|
|
122
119
|
|
|
120
|
+
// update the border properties of all cells before drawing any lines
|
|
123
121
|
prepareCellBorders(this.tableNode.table.body);
|
|
124
122
|
this.drawHorizontalLine(0, writer);
|
|
125
123
|
}
|
|
126
|
-
|
|
127
124
|
onRowBreak(rowIndex, writer) {
|
|
128
125
|
return () => {
|
|
129
126
|
let offset = this.rowPaddingTop + (!this.headerRows ? this.topLineWidth : 0);
|
|
@@ -131,7 +128,6 @@ class TableProcessor {
|
|
|
131
128
|
writer.context().moveDown(offset);
|
|
132
129
|
};
|
|
133
130
|
}
|
|
134
|
-
|
|
135
131
|
beginRow(rowIndex, writer) {
|
|
136
132
|
this.topLineWidth = this.layout.hLineWidth(rowIndex, this.tableNode);
|
|
137
133
|
this.rowPaddingTop = this.layout.paddingTop(rowIndex, this.tableNode);
|
|
@@ -139,116 +135,97 @@ class TableProcessor {
|
|
|
139
135
|
this.rowPaddingBottom = this.layout.paddingBottom(rowIndex, this.tableNode);
|
|
140
136
|
this.rowCallback = this.onRowBreak(rowIndex, writer);
|
|
141
137
|
writer.addListener('pageChanged', this.rowCallback);
|
|
142
|
-
|
|
143
138
|
if (this.dontBreakRows) {
|
|
144
139
|
writer.beginUnbreakableBlock();
|
|
145
140
|
}
|
|
146
|
-
|
|
147
141
|
this.rowTopY = writer.context().y;
|
|
148
142
|
this.reservedAtBottom = this.bottomLineWidth + this.rowPaddingBottom;
|
|
149
143
|
writer.context().availableHeight -= this.reservedAtBottom;
|
|
150
144
|
writer.context().moveDown(this.rowPaddingTop);
|
|
151
145
|
}
|
|
152
|
-
|
|
153
146
|
drawHorizontalLine(lineIndex, writer, overrideY) {
|
|
154
147
|
let lineWidth = this.layout.hLineWidth(lineIndex, this.tableNode);
|
|
155
|
-
|
|
156
148
|
if (lineWidth) {
|
|
157
149
|
let style = this.layout.hLineStyle(lineIndex, this.tableNode);
|
|
158
150
|
let dash;
|
|
159
|
-
|
|
160
151
|
if (style && style.dash) {
|
|
161
152
|
dash = style.dash;
|
|
162
153
|
}
|
|
163
|
-
|
|
164
154
|
let offset = lineWidth / 2;
|
|
165
155
|
let currentLine = null;
|
|
166
156
|
let body = this.tableNode.table.body;
|
|
167
157
|
let cellAbove;
|
|
168
158
|
let currentCell;
|
|
169
159
|
let rowCellAbove;
|
|
170
|
-
|
|
171
160
|
for (let i = 0, l = this.rowSpanData.length; i < l; i++) {
|
|
172
161
|
let data = this.rowSpanData[i];
|
|
173
162
|
let shouldDrawLine = !data.rowSpan;
|
|
174
|
-
let borderColor = null;
|
|
175
|
-
// row above requires a bottom border
|
|
163
|
+
let borderColor = null;
|
|
176
164
|
|
|
165
|
+
// draw only if the current cell requires a top border or the cell in the
|
|
166
|
+
// row above requires a bottom border
|
|
177
167
|
if (shouldDrawLine && i < l - 1) {
|
|
178
168
|
var topBorder = false,
|
|
179
|
-
|
|
180
|
-
|
|
169
|
+
bottomBorder = false,
|
|
170
|
+
rowBottomBorder = false;
|
|
181
171
|
|
|
172
|
+
// the cell in the row above
|
|
182
173
|
if (lineIndex > 0) {
|
|
183
174
|
cellAbove = body[lineIndex - 1][i];
|
|
184
175
|
bottomBorder = cellAbove.border ? cellAbove.border[3] : this.layout.defaultBorder;
|
|
185
|
-
|
|
186
176
|
if (bottomBorder && cellAbove.borderColor) {
|
|
187
177
|
borderColor = cellAbove.borderColor[3];
|
|
188
178
|
}
|
|
189
|
-
}
|
|
190
|
-
|
|
179
|
+
}
|
|
191
180
|
|
|
181
|
+
// the current cell
|
|
192
182
|
if (lineIndex < body.length) {
|
|
193
183
|
currentCell = body[lineIndex][i];
|
|
194
184
|
topBorder = currentCell.border ? currentCell.border[1] : this.layout.defaultBorder;
|
|
195
|
-
|
|
196
185
|
if (topBorder && borderColor == null && currentCell.borderColor) {
|
|
197
186
|
borderColor = currentCell.borderColor[1];
|
|
198
187
|
}
|
|
199
188
|
}
|
|
200
|
-
|
|
201
189
|
shouldDrawLine = topBorder || bottomBorder;
|
|
202
190
|
}
|
|
203
|
-
|
|
204
191
|
if (cellAbove && cellAbove._rowSpanCurrentOffset) {
|
|
205
192
|
rowCellAbove = body[lineIndex - 1 - cellAbove._rowSpanCurrentOffset][i];
|
|
206
193
|
rowBottomBorder = rowCellAbove && rowCellAbove.border ? rowCellAbove.border[3] : this.layout.defaultBorder;
|
|
207
|
-
|
|
208
194
|
if (rowBottomBorder && rowCellAbove && rowCellAbove.borderColor) {
|
|
209
195
|
borderColor = rowCellAbove.borderColor[3];
|
|
210
196
|
}
|
|
211
197
|
}
|
|
212
|
-
|
|
213
198
|
if (borderColor == null) {
|
|
214
199
|
borderColor = typeof this.layout.hLineColor === 'function' ? this.layout.hLineColor(lineIndex, this.tableNode, i) : this.layout.hLineColor;
|
|
215
200
|
}
|
|
216
|
-
|
|
217
201
|
if (!currentLine && shouldDrawLine) {
|
|
218
202
|
currentLine = {
|
|
219
203
|
left: data.left,
|
|
220
204
|
width: 0
|
|
221
205
|
};
|
|
222
206
|
}
|
|
223
|
-
|
|
224
207
|
if (shouldDrawLine) {
|
|
225
208
|
let colSpanIndex = 0;
|
|
226
|
-
|
|
227
209
|
if (rowCellAbove && rowCellAbove.colSpan && rowBottomBorder) {
|
|
228
210
|
while (rowCellAbove.colSpan > colSpanIndex) {
|
|
229
211
|
currentLine.width += this.rowSpanData[i + colSpanIndex++].width || 0;
|
|
230
212
|
}
|
|
231
|
-
|
|
232
213
|
i += colSpanIndex - 1;
|
|
233
214
|
} else if (cellAbove && cellAbove.colSpan && bottomBorder) {
|
|
234
215
|
while (cellAbove.colSpan > colSpanIndex) {
|
|
235
216
|
currentLine.width += this.rowSpanData[i + colSpanIndex++].width || 0;
|
|
236
217
|
}
|
|
237
|
-
|
|
238
218
|
i += colSpanIndex - 1;
|
|
239
219
|
} else if (currentCell && currentCell.colSpan && topBorder) {
|
|
240
220
|
while (currentCell.colSpan > colSpanIndex) {
|
|
241
221
|
currentLine.width += this.rowSpanData[i + colSpanIndex++].width || 0;
|
|
242
222
|
}
|
|
243
|
-
|
|
244
223
|
i += colSpanIndex - 1;
|
|
245
224
|
} else {
|
|
246
225
|
currentLine.width += this.rowSpanData[i].width || 0;
|
|
247
226
|
}
|
|
248
227
|
}
|
|
249
|
-
|
|
250
228
|
let y = (overrideY || 0) + offset;
|
|
251
|
-
|
|
252
229
|
if (shouldDrawLine) {
|
|
253
230
|
if (currentLine && currentLine.width) {
|
|
254
231
|
writer.addVector({
|
|
@@ -269,75 +246,62 @@ class TableProcessor {
|
|
|
269
246
|
}
|
|
270
247
|
}
|
|
271
248
|
}
|
|
272
|
-
|
|
273
249
|
writer.context().moveDown(lineWidth);
|
|
274
250
|
}
|
|
275
251
|
}
|
|
276
|
-
|
|
277
252
|
drawVerticalLine(x, y0, y1, vLineColIndex, writer, vLineRowIndex, beforeVLineColIndex) {
|
|
278
253
|
let width = this.layout.vLineWidth(vLineColIndex, this.tableNode);
|
|
279
|
-
|
|
280
254
|
if (width === 0) {
|
|
281
255
|
return;
|
|
282
256
|
}
|
|
283
|
-
|
|
284
257
|
let style = this.layout.vLineStyle(vLineColIndex, this.tableNode);
|
|
285
258
|
let dash;
|
|
286
|
-
|
|
287
259
|
if (style && style.dash) {
|
|
288
260
|
dash = style.dash;
|
|
289
261
|
}
|
|
290
|
-
|
|
291
262
|
let body = this.tableNode.table.body;
|
|
292
263
|
let cellBefore;
|
|
293
264
|
let currentCell;
|
|
294
|
-
let borderColor;
|
|
265
|
+
let borderColor;
|
|
295
266
|
|
|
267
|
+
// the cell in the col before
|
|
296
268
|
if (vLineColIndex > 0) {
|
|
297
269
|
cellBefore = body[vLineRowIndex][beforeVLineColIndex];
|
|
298
|
-
|
|
299
270
|
if (cellBefore && cellBefore.borderColor) {
|
|
300
271
|
if (cellBefore.border ? cellBefore.border[2] : this.layout.defaultBorder) {
|
|
301
272
|
borderColor = cellBefore.borderColor[2];
|
|
302
273
|
}
|
|
303
274
|
}
|
|
304
|
-
}
|
|
305
|
-
|
|
275
|
+
}
|
|
306
276
|
|
|
277
|
+
// the current cell
|
|
307
278
|
if (borderColor == null && vLineColIndex < body.length) {
|
|
308
279
|
currentCell = body[vLineRowIndex][vLineColIndex];
|
|
309
|
-
|
|
310
280
|
if (currentCell && currentCell.borderColor) {
|
|
311
281
|
if (currentCell.border ? currentCell.border[0] : this.layout.defaultBorder) {
|
|
312
282
|
borderColor = currentCell.borderColor[0];
|
|
313
283
|
}
|
|
314
284
|
}
|
|
315
285
|
}
|
|
316
|
-
|
|
317
286
|
if (borderColor == null && cellBefore && cellBefore._rowSpanCurrentOffset) {
|
|
318
287
|
let rowCellBeforeAbove = body[vLineRowIndex - cellBefore._rowSpanCurrentOffset][beforeVLineColIndex];
|
|
319
|
-
|
|
320
288
|
if (rowCellBeforeAbove.borderColor) {
|
|
321
289
|
if (rowCellBeforeAbove.border ? rowCellBeforeAbove.border[2] : this.layout.defaultBorder) {
|
|
322
290
|
borderColor = rowCellBeforeAbove.borderColor[2];
|
|
323
291
|
}
|
|
324
292
|
}
|
|
325
293
|
}
|
|
326
|
-
|
|
327
294
|
if (borderColor == null && currentCell && currentCell._rowSpanCurrentOffset) {
|
|
328
295
|
let rowCurrentCellAbove = body[vLineRowIndex - currentCell._rowSpanCurrentOffset][vLineColIndex];
|
|
329
|
-
|
|
330
296
|
if (rowCurrentCellAbove.borderColor) {
|
|
331
297
|
if (rowCurrentCellAbove.border ? rowCurrentCellAbove.border[2] : this.layout.defaultBorder) {
|
|
332
298
|
borderColor = rowCurrentCellAbove.borderColor[2];
|
|
333
299
|
}
|
|
334
300
|
}
|
|
335
301
|
}
|
|
336
|
-
|
|
337
302
|
if (borderColor == null) {
|
|
338
303
|
borderColor = typeof this.layout.vLineColor === 'function' ? this.layout.vLineColor(vLineColIndex, this.tableNode, vLineRowIndex) : this.layout.vLineColor;
|
|
339
304
|
}
|
|
340
|
-
|
|
341
305
|
writer.addVector({
|
|
342
306
|
type: 'line',
|
|
343
307
|
x1: x + width / 2,
|
|
@@ -352,18 +316,15 @@ class TableProcessor {
|
|
|
352
316
|
currentCell = null;
|
|
353
317
|
borderColor = null;
|
|
354
318
|
}
|
|
355
|
-
|
|
356
319
|
endTable(writer) {
|
|
357
320
|
if (this.cleanUpRepeatables) {
|
|
358
321
|
writer.popFromRepeatables();
|
|
359
322
|
}
|
|
360
323
|
}
|
|
361
|
-
|
|
362
324
|
endRow(rowIndex, writer, pageBreaks) {
|
|
363
325
|
const getLineXs = () => {
|
|
364
326
|
let result = [];
|
|
365
327
|
let cols = 0;
|
|
366
|
-
|
|
367
328
|
for (let i = 0, l = this.tableNode.table.body[rowIndex].length; i < l; i++) {
|
|
368
329
|
if (!cols) {
|
|
369
330
|
result.push({
|
|
@@ -373,19 +334,16 @@ class TableProcessor {
|
|
|
373
334
|
let item = this.tableNode.table.body[rowIndex][i];
|
|
374
335
|
cols = item._colSpan || item.colSpan || 0;
|
|
375
336
|
}
|
|
376
|
-
|
|
377
337
|
if (cols > 0) {
|
|
378
338
|
cols--;
|
|
379
339
|
}
|
|
380
340
|
}
|
|
381
|
-
|
|
382
341
|
result.push({
|
|
383
342
|
x: this.rowSpanData[this.rowSpanData.length - 1].left,
|
|
384
343
|
index: this.rowSpanData.length - 1
|
|
385
344
|
});
|
|
386
345
|
return result;
|
|
387
346
|
};
|
|
388
|
-
|
|
389
347
|
writer.removeListener('pageChanged', this.rowCallback);
|
|
390
348
|
writer.context().moveDown(this.layout.paddingBottom(rowIndex, this.tableNode));
|
|
391
349
|
writer.context().availableHeight += this.reservedAtBottom;
|
|
@@ -399,7 +357,6 @@ class TableProcessor {
|
|
|
399
357
|
y0: this.rowTopY,
|
|
400
358
|
page: hasBreaks ? pageBreaks[0].prevPage : endingPage
|
|
401
359
|
});
|
|
402
|
-
|
|
403
360
|
if (hasBreaks) {
|
|
404
361
|
for (let i = 0, l = pageBreaks.length; i < l; i++) {
|
|
405
362
|
let pageBreak = pageBreaks[i];
|
|
@@ -410,74 +367,64 @@ class TableProcessor {
|
|
|
410
367
|
});
|
|
411
368
|
}
|
|
412
369
|
}
|
|
413
|
-
|
|
414
370
|
ys[ys.length - 1].y1 = endingY;
|
|
415
371
|
let skipOrphanePadding = ys[0].y1 - ys[0].y0 === this.rowPaddingTop;
|
|
416
|
-
|
|
417
372
|
for (let yi = skipOrphanePadding ? 1 : 0, yl = ys.length; yi < yl; yi++) {
|
|
418
373
|
let willBreak = yi < ys.length - 1;
|
|
419
374
|
let rowBreakWithoutHeader = yi > 0 && !this.headerRows;
|
|
420
375
|
let hzLineOffset = rowBreakWithoutHeader ? 0 : this.topLineWidth;
|
|
421
376
|
let y1 = ys[yi].y0;
|
|
422
377
|
let y2 = ys[yi].y1;
|
|
423
|
-
|
|
424
378
|
if (willBreak) {
|
|
425
379
|
y2 = y2 + this.rowPaddingBottom;
|
|
426
380
|
}
|
|
427
|
-
|
|
428
381
|
if (writer.context().page != ys[yi].page) {
|
|
429
|
-
writer.context().page = ys[yi].page;
|
|
430
|
-
// TableProcessor should be pageChanged listener, instead of processRow
|
|
382
|
+
writer.context().page = ys[yi].page;
|
|
431
383
|
|
|
384
|
+
//TODO: buggy, availableHeight should be updated on every pageChanged event
|
|
385
|
+
// TableProcessor should be pageChanged listener, instead of processRow
|
|
432
386
|
this.reservedAtBottom = 0;
|
|
433
387
|
}
|
|
434
|
-
|
|
435
388
|
for (let i = 0, l = xs.length; i < l; i++) {
|
|
436
389
|
let leftCellBorder = false;
|
|
437
390
|
let rightCellBorder = false;
|
|
438
|
-
let colIndex = xs[i].index;
|
|
391
|
+
let colIndex = xs[i].index;
|
|
439
392
|
|
|
393
|
+
// current cell
|
|
440
394
|
if (colIndex < body[rowIndex].length) {
|
|
441
395
|
let cell = body[rowIndex][colIndex];
|
|
442
396
|
leftCellBorder = cell.border ? cell.border[0] : this.layout.defaultBorder;
|
|
443
397
|
rightCellBorder = cell.border ? cell.border[2] : this.layout.defaultBorder;
|
|
444
|
-
}
|
|
445
|
-
|
|
398
|
+
}
|
|
446
399
|
|
|
400
|
+
// before cell
|
|
447
401
|
if (colIndex > 0 && !leftCellBorder) {
|
|
448
402
|
let cell = body[rowIndex][colIndex - 1];
|
|
449
403
|
leftCellBorder = cell.border ? cell.border[2] : this.layout.defaultBorder;
|
|
450
|
-
}
|
|
451
|
-
|
|
404
|
+
}
|
|
452
405
|
|
|
406
|
+
// after cell
|
|
453
407
|
if (colIndex + 1 < body[rowIndex].length && !rightCellBorder) {
|
|
454
408
|
let cell = body[rowIndex][colIndex + 1];
|
|
455
409
|
rightCellBorder = cell.border ? cell.border[0] : this.layout.defaultBorder;
|
|
456
410
|
}
|
|
457
|
-
|
|
458
411
|
if (leftCellBorder) {
|
|
459
412
|
this.drawVerticalLine(xs[i].x, y1 - hzLineOffset, y2 + this.bottomLineWidth, xs[i].index, writer, rowIndex, xs[i - 1] ? xs[i - 1].index : null);
|
|
460
413
|
}
|
|
461
|
-
|
|
462
414
|
if (i < l - 1) {
|
|
463
415
|
let fillColor = body[rowIndex][colIndex].fillColor;
|
|
464
416
|
let fillOpacity = body[rowIndex][colIndex].fillOpacity;
|
|
465
|
-
|
|
466
417
|
if (!fillColor) {
|
|
467
418
|
fillColor = typeof this.layout.fillColor === 'function' ? this.layout.fillColor(rowIndex, this.tableNode, colIndex) : this.layout.fillColor;
|
|
468
419
|
}
|
|
469
|
-
|
|
470
420
|
if (!(0, _variableType.isNumber)(fillOpacity)) {
|
|
471
421
|
fillOpacity = typeof this.layout.fillOpacity === 'function' ? this.layout.fillOpacity(rowIndex, this.tableNode, colIndex) : this.layout.fillOpacity;
|
|
472
422
|
}
|
|
473
|
-
|
|
474
423
|
var overlayPattern = body[rowIndex][colIndex].overlayPattern;
|
|
475
424
|
var overlayOpacity = body[rowIndex][colIndex].overlayOpacity;
|
|
476
|
-
|
|
477
425
|
if (fillColor || overlayPattern) {
|
|
478
426
|
let widthLeftBorder = leftCellBorder ? this.layout.vLineWidth(colIndex, this.tableNode) : 0;
|
|
479
427
|
let widthRightBorder;
|
|
480
|
-
|
|
481
428
|
if ((colIndex === 0 || colIndex + 1 == body[rowIndex].length) && !rightCellBorder) {
|
|
482
429
|
widthRightBorder = this.layout.vLineWidth(colIndex + 1, this.tableNode);
|
|
483
430
|
} else if (rightCellBorder) {
|
|
@@ -485,14 +432,12 @@ class TableProcessor {
|
|
|
485
432
|
} else {
|
|
486
433
|
widthRightBorder = 0;
|
|
487
434
|
}
|
|
488
|
-
|
|
489
435
|
let x1f = this.dontBreakRows ? xs[i].x + widthLeftBorder : xs[i].x + widthLeftBorder / 2;
|
|
490
436
|
let y1f = this.dontBreakRows ? y1 : y1 - hzLineOffset / 2;
|
|
491
437
|
let x2f = xs[i + 1].x + widthRightBorder;
|
|
492
438
|
let y2f = this.dontBreakRows ? y2 + this.bottomLineWidth : y2 + this.bottomLineWidth / 2;
|
|
493
439
|
var bgWidth = x2f - x1f;
|
|
494
440
|
var bgHeight = y2f - y1f;
|
|
495
|
-
|
|
496
441
|
if (fillColor) {
|
|
497
442
|
writer.addVector({
|
|
498
443
|
type: 'rect',
|
|
@@ -502,10 +447,11 @@ class TableProcessor {
|
|
|
502
447
|
h: bgHeight,
|
|
503
448
|
lineWidth: 0,
|
|
504
449
|
color: fillColor,
|
|
505
|
-
fillOpacity: fillOpacity
|
|
450
|
+
fillOpacity: fillOpacity,
|
|
451
|
+
// mark if we are in an unbreakable block
|
|
452
|
+
_isFillColorFromUnbreakable: !!writer.transactionLevel
|
|
506
453
|
}, false, true, writer.context().backgroundLength[writer.context().page]);
|
|
507
454
|
}
|
|
508
|
-
|
|
509
455
|
if (overlayPattern) {
|
|
510
456
|
writer.addVector({
|
|
511
457
|
type: 'rect',
|
|
@@ -521,61 +467,52 @@ class TableProcessor {
|
|
|
521
467
|
}
|
|
522
468
|
}
|
|
523
469
|
}
|
|
524
|
-
|
|
525
470
|
if (willBreak && this.layout.hLineWhenBroken !== false) {
|
|
526
471
|
this.drawHorizontalLine(rowIndex + 1, writer, y2);
|
|
527
472
|
}
|
|
528
|
-
|
|
529
473
|
if (rowBreakWithoutHeader && this.layout.hLineWhenBroken !== false) {
|
|
530
474
|
this.drawHorizontalLine(rowIndex, writer, y1);
|
|
531
475
|
}
|
|
532
476
|
}
|
|
533
|
-
|
|
534
477
|
writer.context().page = endingPage;
|
|
535
478
|
writer.context().y = endingY;
|
|
536
479
|
let row = this.tableNode.table.body[rowIndex];
|
|
537
|
-
|
|
538
480
|
for (let i = 0, l = row.length; i < l; i++) {
|
|
539
481
|
if (row[i].rowSpan) {
|
|
540
|
-
this.rowSpanData[i].rowSpan = row[i].rowSpan;
|
|
482
|
+
this.rowSpanData[i].rowSpan = row[i].rowSpan;
|
|
541
483
|
|
|
484
|
+
// fix colSpans
|
|
542
485
|
if (row[i].colSpan && row[i].colSpan > 1) {
|
|
543
486
|
for (let j = 1; j < row[i].rowSpan; j++) {
|
|
544
487
|
this.tableNode.table.body[rowIndex + j][i]._colSpan = row[i].colSpan;
|
|
545
488
|
}
|
|
546
|
-
}
|
|
547
|
-
|
|
489
|
+
}
|
|
548
490
|
|
|
491
|
+
// fix rowSpans
|
|
549
492
|
if (row[i].rowSpan && row[i].rowSpan > 1) {
|
|
550
493
|
for (let j = 1; j < row[i].rowSpan; j++) {
|
|
551
494
|
this.tableNode.table.body[rowIndex + j][i]._rowSpanCurrentOffset = j;
|
|
552
495
|
}
|
|
553
496
|
}
|
|
554
497
|
}
|
|
555
|
-
|
|
556
498
|
if (this.rowSpanData[i].rowSpan > 0) {
|
|
557
499
|
this.rowSpanData[i].rowSpan--;
|
|
558
500
|
}
|
|
559
501
|
}
|
|
560
|
-
|
|
561
502
|
this.drawHorizontalLine(rowIndex + 1, writer);
|
|
562
|
-
|
|
563
503
|
if (this.headerRows && rowIndex === this.headerRows - 1) {
|
|
564
504
|
this.headerRepeatable = writer.currentBlockToRepeatable();
|
|
565
505
|
}
|
|
566
|
-
|
|
567
506
|
if (this.dontBreakRows) {
|
|
568
507
|
const pageChangedCallback = () => {
|
|
569
508
|
if (!this.headerRows && this.layout.hLineWhenBroken !== false) {
|
|
570
509
|
this.drawHorizontalLine(rowIndex, writer);
|
|
571
510
|
}
|
|
572
511
|
};
|
|
573
|
-
|
|
574
512
|
writer.addListener('pageChanged', pageChangedCallback);
|
|
575
513
|
writer.commitUnbreakableBlock();
|
|
576
514
|
writer.removeListener('pageChanged', pageChangedCallback);
|
|
577
515
|
}
|
|
578
|
-
|
|
579
516
|
if (this.headerRepeatable && (rowIndex === this.rowsWithoutPageBreak - 1 || rowIndex === this.tableNode.table.body.length - 1)) {
|
|
580
517
|
writer.commitUnbreakableBlock();
|
|
581
518
|
writer.pushToRepeatables(this.headerRepeatable);
|
|
@@ -583,8 +520,5 @@ class TableProcessor {
|
|
|
583
520
|
this.headerRepeatable = null;
|
|
584
521
|
}
|
|
585
522
|
}
|
|
586
|
-
|
|
587
523
|
}
|
|
588
|
-
|
|
589
|
-
var _default = TableProcessor;
|
|
590
|
-
exports.default = _default;
|
|
524
|
+
var _default = exports.default = TableProcessor;
|