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