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