@wirabyte/w-pdfmaker 0.0.0-stage → 1.0.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 +53 -0
- package/LICENSE +22 -0
- package/NOTICE.md +39 -0
- package/README.md +106 -2
- package/build/fonts/Roboto/Roboto-Italic.ttf +0 -0
- package/build/fonts/Roboto/Roboto-Medium.ttf +0 -0
- package/build/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
- package/build/fonts/Roboto/Roboto-Regular.ttf +0 -0
- package/build/fonts/Roboto.js +27 -0
- package/build/pdfmake.js +103161 -0
- package/build/pdfmake.js.map +1 -0
- package/build/pdfmake.min.js +3 -0
- package/build/pdfmake.min.js.map +1 -0
- package/build/standard-fonts/Courier.js +9 -0
- package/build/standard-fonts/Helvetica.js +9 -0
- package/build/standard-fonts/Symbol.js +9 -0
- package/build/standard-fonts/Times.js +9 -0
- package/build/standard-fonts/ZapfDingbats.js +9 -0
- package/build/vfs_fonts.js +6 -0
- package/build-vfs.js +44 -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/fonts/Roboto.js +8 -0
- package/fonts/THSarabunIT9/LICENSE.txt +7 -0
- package/fonts/THSarabunIT9/THSarabunIT9-Bold.ttf +0 -0
- package/fonts/THSarabunIT9/THSarabunIT9-BoldItalic.ttf +0 -0
- package/fonts/THSarabunIT9/THSarabunIT9-Italic.ttf +0 -0
- package/fonts/THSarabunIT9/THSarabunIT9.ttf +0 -0
- package/fonts/THSarabunNew/COPYING.GPLv2 +339 -0
- package/fonts/THSarabunNew/LICENSE.txt +13 -0
- package/fonts/THSarabunNew/THSarabunNew-Bold.ttf +0 -0
- package/fonts/THSarabunNew/THSarabunNew-BoldItalic.ttf +0 -0
- package/fonts/THSarabunNew/THSarabunNew-Italic.ttf +0 -0
- package/fonts/THSarabunNew/THSarabunNew.ttf +0 -0
- package/index.d.ts +167 -0
- package/interfaces.d.ts +2779 -0
- package/js/DocMeasure.js +695 -0
- package/js/DocPreprocessor.js +263 -0
- package/js/DocumentContext.js +563 -0
- package/js/ElementWriter.js +488 -0
- package/js/LayoutBuilder.js +1525 -0
- package/js/Line.js +105 -0
- package/js/OutputDocument.js +73 -0
- package/js/OutputDocumentServer.js +34 -0
- package/js/PDFDocument.js +322 -0
- package/js/PageElementWriter.js +302 -0
- package/js/PageSize.js +74 -0
- package/js/Printer.js +275 -0
- package/js/Renderer.js +439 -0
- package/js/SVGMeasure.js +94 -0
- package/js/StyleContextStack.js +191 -0
- package/js/TableProcessor.js +658 -0
- package/js/TextBreaker.js +164 -0
- package/js/TextDecorator.js +164 -0
- package/js/TextInlines.js +212 -0
- package/js/URLResolver.js +122 -0
- package/js/base.js +125 -0
- package/js/browser-extensions/OutputDocumentBrowser.js +82 -0
- package/js/browser-extensions/fonts/Roboto.js +38 -0
- package/js/browser-extensions/fonts/thai.js +28 -0
- package/js/browser-extensions/index.js +88 -0
- package/js/browser-extensions/pageUrls.js +79 -0
- package/js/browser-extensions/pdfMake.js +3 -0
- package/js/browser-extensions/standard-fonts/Courier.js +20 -0
- package/js/browser-extensions/standard-fonts/Helvetica.js +20 -0
- package/js/browser-extensions/standard-fonts/Symbol.js +17 -0
- package/js/browser-extensions/standard-fonts/Times.js +20 -0
- package/js/browser-extensions/standard-fonts/ZapfDingbats.js +17 -0
- package/js/browser-extensions/virtual-fs-cjs.js +3 -0
- package/js/columnCalculator.js +159 -0
- package/js/helpers/node.js +122 -0
- package/js/helpers/tools.js +46 -0
- package/js/helpers/variableType.js +59 -0
- package/js/imageFallback.js +23 -0
- package/js/index.js +45 -0
- package/js/mergeStamp.js +194 -0
- package/js/pageNumbering.js +48 -0
- package/js/qrEnc.js +721 -0
- package/js/standardPageSizes.js +56 -0
- package/js/tableLayouts.js +98 -0
- package/js/thai.js +201 -0
- package/js/virtual-fs.js +82 -0
- package/package.json +93 -4
- package/skills/w-pdfmaker/SKILL.md +171 -0
- package/skills/w-pdfmaker/references/browser.md +36 -0
- package/skills/w-pdfmaker/references/document-definition.md +241 -0
- package/skills/w-pdfmaker/references/images.md +90 -0
- package/skills/w-pdfmaker/references/merge-stamp.md +94 -0
- package/skills/w-pdfmaker/references/thai.md +67 -0
- package/src/DocMeasure.js +780 -0
- package/src/DocPreprocessor.js +293 -0
- package/src/DocumentContext.js +605 -0
- package/src/ElementWriter.js +550 -0
- package/src/LayoutBuilder.js +1689 -0
- package/src/Line.js +114 -0
- package/src/OutputDocument.js +75 -0
- package/src/OutputDocumentServer.js +38 -0
- package/src/PDFDocument.js +352 -0
- package/src/PageElementWriter.js +343 -0
- package/src/PageSize.js +53 -0
- package/src/Printer.js +289 -0
- package/src/Renderer.js +468 -0
- package/src/SVGMeasure.js +109 -0
- package/src/StyleContextStack.js +208 -0
- package/src/TableProcessor.js +719 -0
- package/src/TextBreaker.js +166 -0
- package/src/TextDecorator.js +191 -0
- package/src/TextInlines.js +229 -0
- package/src/URLResolver.js +122 -0
- package/src/base.js +143 -0
- package/src/browser-extensions/OutputDocumentBrowser.js +80 -0
- package/src/browser-extensions/fonts/Roboto.js +27 -0
- package/src/browser-extensions/fonts/thai.js +23 -0
- package/src/browser-extensions/index.js +91 -0
- package/src/browser-extensions/pageUrls.js +67 -0
- package/src/browser-extensions/pdfMake.js +1 -0
- package/src/browser-extensions/standard-fonts/Courier.js +25 -0
- package/src/browser-extensions/standard-fonts/Helvetica.js +25 -0
- package/src/browser-extensions/standard-fonts/Symbol.js +17 -0
- package/src/browser-extensions/standard-fonts/Times.js +25 -0
- package/src/browser-extensions/standard-fonts/ZapfDingbats.js +17 -0
- package/src/browser-extensions/virtual-fs-cjs.js +1 -0
- package/src/columnCalculator.js +160 -0
- package/src/helpers/node.js +134 -0
- package/src/helpers/tools.js +44 -0
- package/src/helpers/variableType.js +50 -0
- package/src/imageFallback.js +18 -0
- package/src/index.js +45 -0
- package/src/mergeStamp.js +132 -0
- package/src/pageNumbering.js +45 -0
- package/src/qrEnc.js +796 -0
- package/src/standardPageSizes.js +52 -0
- package/src/tableLayouts.js +100 -0
- package/src/thai.js +170 -0
- package/src/virtual-fs.js +92 -0
- package/standard-fonts/Courier.js +8 -0
- package/standard-fonts/Helvetica.js +8 -0
- package/standard-fonts/Symbol.js +5 -0
- package/standard-fonts/Times.js +8 -0
- package/standard-fonts/ZapfDingbats.js +5 -0
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
import ColumnCalculator from './columnCalculator';
|
|
2
|
+
import { isNumber, isPositiveInteger } from './helpers/variableType';
|
|
3
|
+
|
|
4
|
+
const PAGE_BREAK_VALUES = new Set(['before', 'beforeOdd', 'beforeEven', 'after', 'afterOdd', 'afterEven']);
|
|
5
|
+
|
|
6
|
+
const hasExplicitPageBreak = cell => {
|
|
7
|
+
if (!cell || typeof cell !== 'object') {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return PAGE_BREAK_VALUES.has(cell.pageBreak);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
class TableProcessor {
|
|
15
|
+
constructor(tableNode, breakableBlocks = new Set()) {
|
|
16
|
+
this.tableNode = tableNode;
|
|
17
|
+
this.breakableBlocks = breakableBlocks;
|
|
18
|
+
this._isCurrentRowUnbreakable = false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
beginTable(writer) {
|
|
22
|
+
const getTableInnerContentWidth = () => {
|
|
23
|
+
let width = 0;
|
|
24
|
+
|
|
25
|
+
tableNode.table.widths.forEach(w => {
|
|
26
|
+
width += w._calcWidth;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return width;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const prepareRowSpanData = () => {
|
|
33
|
+
let rsd = [];
|
|
34
|
+
let x = 0;
|
|
35
|
+
let lastWidth;
|
|
36
|
+
|
|
37
|
+
rsd.push({ left: 0, rowSpan: 0 });
|
|
38
|
+
|
|
39
|
+
for (let i = 0, l = this.tableNode.table.body[0].length; i < l; i++) {
|
|
40
|
+
let paddings = this.layout.paddingLeft(i, this.tableNode) + this.layout.paddingRight(i, this.tableNode);
|
|
41
|
+
let lBorder = this.layout.vLineWidth(i, this.tableNode);
|
|
42
|
+
lastWidth = paddings + lBorder + this.tableNode.table.widths[i]._calcWidth;
|
|
43
|
+
rsd[rsd.length - 1].width = lastWidth;
|
|
44
|
+
x += lastWidth;
|
|
45
|
+
rsd.push({ left: x, rowSpan: 0, width: 0 });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return rsd;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Iterate through all cells. If the current cell is the start of a
|
|
52
|
+
// rowSpan/colSpan, update the border property of the cells on its
|
|
53
|
+
// bottom/right accordingly. This is needed since each iteration of the
|
|
54
|
+
// line-drawing loops draws lines for a single cell, not for an entire
|
|
55
|
+
// rowSpan/colSpan.
|
|
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
|
+
}
|
|
72
|
+
|
|
73
|
+
// set right border
|
|
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
|
+
}
|
|
84
|
+
|
|
85
|
+
// set bottom border
|
|
86
|
+
if (cell.border[3] !== undefined) {
|
|
87
|
+
setBorder(rowIndex + rowSpan - 1, colIndex + colOffset, 3, cell.border[3]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// helper function to set the border for a given cell
|
|
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
|
+
|
|
105
|
+
tableNode = this.tableNode;
|
|
106
|
+
this.offsets = tableNode._offsets;
|
|
107
|
+
this.layout = tableNode._layout;
|
|
108
|
+
|
|
109
|
+
availableWidth = writer.context().availableWidth - this.offsets.total;
|
|
110
|
+
ColumnCalculator.buildColumnWidths(tableNode.table.widths, availableWidth, this.offsets.total, tableNode);
|
|
111
|
+
|
|
112
|
+
this.tableWidth = tableNode._offsets.total + getTableInnerContentWidth();
|
|
113
|
+
this.alignTable(writer.context());
|
|
114
|
+
this.rowSpanData = prepareRowSpanData();
|
|
115
|
+
this.cleanUpRepeatables = false;
|
|
116
|
+
|
|
117
|
+
// headersRows and rowsWithoutPageBreak (headerRows + keepWithHeaderRows)
|
|
118
|
+
this.headerRows = 0;
|
|
119
|
+
this.rowsWithoutPageBreak = 0;
|
|
120
|
+
|
|
121
|
+
const headerRows = tableNode.table.headerRows;
|
|
122
|
+
|
|
123
|
+
if (isPositiveInteger(headerRows)) {
|
|
124
|
+
this.headerRows = headerRows;
|
|
125
|
+
|
|
126
|
+
if (this.headerRows > tableNode.table.body.length) {
|
|
127
|
+
throw new Error(`Too few rows in the table. Property headerRows requires at least ${this.headerRows}, contains only ${tableNode.table.body.length}`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.rowsWithoutPageBreak = this.headerRows;
|
|
131
|
+
|
|
132
|
+
const keepWithHeaderRows = tableNode.table.keepWithHeaderRows;
|
|
133
|
+
|
|
134
|
+
if (isPositiveInteger(keepWithHeaderRows) && !this.breakableBlocks.has(tableNode.table)) {
|
|
135
|
+
this.rowsWithoutPageBreak += keepWithHeaderRows;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
this.dontBreakRows = !!tableNode.table.dontBreakRows && !this.breakableBlocks.has(tableNode.table.body[0]);
|
|
140
|
+
this.headerInUnbreakableBlock = writer.transactionLevel > 0;
|
|
141
|
+
|
|
142
|
+
if (this.rowsWithoutPageBreak || this.dontBreakRows) {
|
|
143
|
+
writer.beginUnbreakableBlock();
|
|
144
|
+
// Draw the top border of the table
|
|
145
|
+
this.drawHorizontalLine(0, writer);
|
|
146
|
+
if (this.rowsWithoutPageBreak && this.dontBreakRows) {
|
|
147
|
+
// We just increase the value of transactionLevel
|
|
148
|
+
writer.beginUnbreakableBlock();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// update the border properties of all cells before drawing any lines
|
|
153
|
+
prepareCellBorders(this.tableNode.table.body);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
alignTable(context) {
|
|
157
|
+
const freeWidth = Math.max(0, context.availableWidth - this.tableWidth);
|
|
158
|
+
this.alignmentOffset = this.tableNode.tableAlignment === 'center' ? freeWidth / 2 :
|
|
159
|
+
(this.tableNode.tableAlignment === 'right' ? freeWidth : 0);
|
|
160
|
+
if (this.alignmentOffset) {
|
|
161
|
+
// Keep the container width intact: column widths have already been resolved.
|
|
162
|
+
// Row snapshots preserve this origin across page breaks.
|
|
163
|
+
context.addMargin(this.alignmentOffset, -this.alignmentOffset);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
onRowBreak(rowIndex, writer) {
|
|
168
|
+
const detachedBlock = writer.context().detachedBlock;
|
|
169
|
+
return () => {
|
|
170
|
+
if (writer.context().detachedBlock !== detachedBlock) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
let offset = this.rowPaddingTop + (!this.headerRows ? this.topLineWidth : 0);
|
|
174
|
+
writer.context().availableHeight -= this.reservedAtBottom;
|
|
175
|
+
writer.context().moveDown(offset);
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
beginRow(rowIndex, writer) {
|
|
180
|
+
this.dontBreakRows = !!this.tableNode.table.dontBreakRows && !this.breakableBlocks.has(this.tableNode.table.body[rowIndex]);
|
|
181
|
+
this.topLineWidth = this.layout.hLineWidth(rowIndex, this.tableNode);
|
|
182
|
+
this.rowPaddingTop = this.layout.paddingTop(rowIndex, this.tableNode);
|
|
183
|
+
this.bottomLineWidth = this.layout.hLineWidth(rowIndex + 1, this.tableNode);
|
|
184
|
+
this.rowPaddingBottom = this.layout.paddingBottom(rowIndex, this.tableNode);
|
|
185
|
+
|
|
186
|
+
this.rowCallback = this.onRowBreak(rowIndex, writer);
|
|
187
|
+
writer.addListener('pageChanged', this.rowCallback);
|
|
188
|
+
if (rowIndex == 0 && !this.dontBreakRows && !this.rowsWithoutPageBreak) {
|
|
189
|
+
// We store the 'y' to draw later and if necessary the top border of the table
|
|
190
|
+
this._tableTopBorderY = writer.context().y;
|
|
191
|
+
writer.context().moveDown(this.topLineWidth);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
this.rowTopPageY = writer.context().y + this.rowPaddingTop;
|
|
195
|
+
|
|
196
|
+
const rowCells = this.tableNode.table.body[rowIndex] || [];
|
|
197
|
+
const rowHasPageBreak = rowCells.some(hasExplicitPageBreak);
|
|
198
|
+
if (this.dontBreakRows && rowHasPageBreak) {
|
|
199
|
+
writer.checkUnbreakableOverflow(true);
|
|
200
|
+
}
|
|
201
|
+
this._isCurrentRowUnbreakable = this.dontBreakRows && rowIndex > 0 && !rowHasPageBreak;
|
|
202
|
+
|
|
203
|
+
if (this._isCurrentRowUnbreakable) {
|
|
204
|
+
writer.beginUnbreakableBlock();
|
|
205
|
+
}
|
|
206
|
+
this.rowTopY = writer.context().y;
|
|
207
|
+
this.reservedAtBottom = this.bottomLineWidth + this.rowPaddingBottom;
|
|
208
|
+
|
|
209
|
+
writer.context().availableHeight -= this.reservedAtBottom;
|
|
210
|
+
|
|
211
|
+
writer.context().moveDown(this.rowPaddingTop);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
drawHorizontalLine(lineIndex, writer, overrideY, moveDown = true, forcePage) {
|
|
215
|
+
let lineWidth = this.layout.hLineWidth(lineIndex, this.tableNode);
|
|
216
|
+
if (lineWidth) {
|
|
217
|
+
let style = this.layout.hLineStyle(lineIndex, this.tableNode);
|
|
218
|
+
let dash;
|
|
219
|
+
if (style && style.dash) {
|
|
220
|
+
dash = style.dash;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
let offset = lineWidth / 2;
|
|
224
|
+
let currentLine = null;
|
|
225
|
+
let body = this.tableNode.table.body;
|
|
226
|
+
let cellAbove;
|
|
227
|
+
let currentCell;
|
|
228
|
+
let rowCellAbove;
|
|
229
|
+
|
|
230
|
+
for (let i = 0, l = this.rowSpanData.length; i < l; i++) {
|
|
231
|
+
let data = this.rowSpanData[i];
|
|
232
|
+
let shouldDrawLine = !data.rowSpan;
|
|
233
|
+
let borderColor = null;
|
|
234
|
+
|
|
235
|
+
// draw only if the current cell requires a top border or the cell in the
|
|
236
|
+
// row above requires a bottom border
|
|
237
|
+
if (shouldDrawLine && i < l - 1) {
|
|
238
|
+
var topBorder = false, bottomBorder = false, rowBottomBorder = false;
|
|
239
|
+
|
|
240
|
+
// the cell in the row above
|
|
241
|
+
if (lineIndex > 0) {
|
|
242
|
+
cellAbove = body[lineIndex - 1][i];
|
|
243
|
+
bottomBorder = cellAbove.border ? cellAbove.border[3] : this.layout.defaultBorder;
|
|
244
|
+
if (bottomBorder && cellAbove.borderColor) {
|
|
245
|
+
borderColor = cellAbove.borderColor[3];
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// the current cell
|
|
250
|
+
if (lineIndex < body.length) {
|
|
251
|
+
currentCell = body[lineIndex][i];
|
|
252
|
+
topBorder = currentCell.border ? currentCell.border[1] : this.layout.defaultBorder;
|
|
253
|
+
if (topBorder && borderColor == null && currentCell.borderColor) {
|
|
254
|
+
borderColor = currentCell.borderColor[1];
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
shouldDrawLine = topBorder || bottomBorder;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (cellAbove && cellAbove._rowSpanCurrentOffset) {
|
|
262
|
+
rowCellAbove = body[lineIndex - 1 - cellAbove._rowSpanCurrentOffset][i];
|
|
263
|
+
rowBottomBorder = rowCellAbove && rowCellAbove.border ? rowCellAbove.border[3] : this.layout.defaultBorder;
|
|
264
|
+
if (rowBottomBorder && rowCellAbove && rowCellAbove.borderColor) {
|
|
265
|
+
borderColor = rowCellAbove.borderColor[3];
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (borderColor == null) {
|
|
270
|
+
borderColor = typeof this.layout.hLineColor === 'function' ? this.layout.hLineColor(lineIndex, this.tableNode, i) : this.layout.hLineColor;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (!currentLine && shouldDrawLine) {
|
|
274
|
+
currentLine = { left: data.left, width: 0 };
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (shouldDrawLine) {
|
|
278
|
+
let colSpanIndex = 0;
|
|
279
|
+
if (rowCellAbove && rowCellAbove.colSpan && rowBottomBorder) {
|
|
280
|
+
while (rowCellAbove.colSpan > colSpanIndex) {
|
|
281
|
+
currentLine.width += (this.rowSpanData[i + colSpanIndex++].width || 0);
|
|
282
|
+
}
|
|
283
|
+
i += colSpanIndex - 1;
|
|
284
|
+
} else if (cellAbove && cellAbove.colSpan && bottomBorder) {
|
|
285
|
+
while (cellAbove.colSpan > colSpanIndex) {
|
|
286
|
+
currentLine.width += (this.rowSpanData[i + colSpanIndex++].width || 0);
|
|
287
|
+
}
|
|
288
|
+
i += colSpanIndex - 1;
|
|
289
|
+
} else if (currentCell && currentCell.colSpan && topBorder) {
|
|
290
|
+
while (currentCell.colSpan > colSpanIndex) {
|
|
291
|
+
currentLine.width += (this.rowSpanData[i + colSpanIndex++].width || 0);
|
|
292
|
+
}
|
|
293
|
+
i += colSpanIndex - 1;
|
|
294
|
+
} else {
|
|
295
|
+
currentLine.width += (this.rowSpanData[i].width || 0);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
let y = (overrideY || 0) + offset;
|
|
300
|
+
|
|
301
|
+
if (shouldDrawLine) {
|
|
302
|
+
if (currentLine && currentLine.width) {
|
|
303
|
+
writer.addVector({
|
|
304
|
+
type: 'line',
|
|
305
|
+
x1: currentLine.left,
|
|
306
|
+
x2: currentLine.left + currentLine.width,
|
|
307
|
+
y1: y,
|
|
308
|
+
y2: y,
|
|
309
|
+
lineWidth: lineWidth,
|
|
310
|
+
dash: dash,
|
|
311
|
+
lineColor: borderColor
|
|
312
|
+
}, false, isNumber(overrideY), null, forcePage);
|
|
313
|
+
currentLine = null;
|
|
314
|
+
cellAbove = null;
|
|
315
|
+
currentCell = null;
|
|
316
|
+
rowCellAbove = null;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (moveDown) {
|
|
322
|
+
writer.context().moveDown(lineWidth);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
drawVerticalLine(x, y0, y1, vLineColIndex, writer, vLineRowIndex, beforeVLineColIndex) {
|
|
328
|
+
let width = this.layout.vLineWidth(vLineColIndex, this.tableNode);
|
|
329
|
+
if (width === 0) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
let style = this.layout.vLineStyle(vLineColIndex, this.tableNode);
|
|
333
|
+
let dash;
|
|
334
|
+
if (style && style.dash) {
|
|
335
|
+
dash = style.dash;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
let body = this.tableNode.table.body;
|
|
339
|
+
let cellBefore;
|
|
340
|
+
let currentCell;
|
|
341
|
+
let borderColor;
|
|
342
|
+
|
|
343
|
+
// the cell in the col before
|
|
344
|
+
if (vLineColIndex > 0) {
|
|
345
|
+
cellBefore = body[vLineRowIndex][beforeVLineColIndex];
|
|
346
|
+
if (cellBefore && cellBefore.borderColor) {
|
|
347
|
+
if (cellBefore.border ? cellBefore.border[2] : this.layout.defaultBorder) {
|
|
348
|
+
borderColor = cellBefore.borderColor[2];
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (borderColor == null && cellBefore && cellBefore._rowSpanCurrentOffset) {
|
|
354
|
+
let rowCellBeforeAbove = body[vLineRowIndex - cellBefore._rowSpanCurrentOffset][beforeVLineColIndex];
|
|
355
|
+
if (rowCellBeforeAbove.borderColor) {
|
|
356
|
+
if (rowCellBeforeAbove.border ? rowCellBeforeAbove.border[2] : this.layout.defaultBorder) {
|
|
357
|
+
borderColor = rowCellBeforeAbove.borderColor[2];
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// the current cell
|
|
363
|
+
if (borderColor == null && vLineColIndex < body[vLineRowIndex].length) {
|
|
364
|
+
currentCell = body[vLineRowIndex][vLineColIndex];
|
|
365
|
+
if (currentCell && currentCell.borderColor) {
|
|
366
|
+
if (currentCell.border ? currentCell.border[0] : this.layout.defaultBorder) {
|
|
367
|
+
borderColor = currentCell.borderColor[0];
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (borderColor == null && currentCell && currentCell._rowSpanCurrentOffset) {
|
|
373
|
+
let rowCurrentCellAbove = body[vLineRowIndex - currentCell._rowSpanCurrentOffset][vLineColIndex];
|
|
374
|
+
if (rowCurrentCellAbove.borderColor) {
|
|
375
|
+
if (rowCurrentCellAbove.border ? rowCurrentCellAbove.border[0] : this.layout.defaultBorder) {
|
|
376
|
+
borderColor = rowCurrentCellAbove.borderColor[0];
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (borderColor == null) {
|
|
382
|
+
borderColor = typeof this.layout.vLineColor === 'function' ? this.layout.vLineColor(vLineColIndex, this.tableNode, vLineRowIndex) : this.layout.vLineColor;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
writer.addVector({
|
|
386
|
+
type: 'line',
|
|
387
|
+
x1: x + width / 2,
|
|
388
|
+
x2: x + width / 2,
|
|
389
|
+
y1: y0,
|
|
390
|
+
y2: y1,
|
|
391
|
+
lineWidth: width,
|
|
392
|
+
dash: dash,
|
|
393
|
+
lineColor: borderColor
|
|
394
|
+
}, false, true);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
endTable(writer) {
|
|
398
|
+
if (this.cleanUpRepeatables) {
|
|
399
|
+
writer.popFromRepeatables();
|
|
400
|
+
}
|
|
401
|
+
if (this.alignmentOffset) {
|
|
402
|
+
writer.context().addMargin(-this.alignmentOffset, this.alignmentOffset);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
releaseRowSpans(rowIndex) {
|
|
407
|
+
const body = this.tableNode.table.body;
|
|
408
|
+
if (!this.rowSpanGroups) {
|
|
409
|
+
// Index connected spans once per table layout, including transitive overlaps.
|
|
410
|
+
this.rowSpanGroups = new Array(body.length);
|
|
411
|
+
for (let firstRow = 0; firstRow < body.length;) {
|
|
412
|
+
let lastRow = firstRow;
|
|
413
|
+
for (let i = firstRow; i <= lastRow; i++) {
|
|
414
|
+
body[i].forEach(cell => {
|
|
415
|
+
lastRow = Math.max(lastRow, i + (cell.rowSpan || 1) - 1);
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
const group = { firstRow, lastRow };
|
|
419
|
+
for (let i = firstRow; i <= lastRow; i++) {
|
|
420
|
+
this.rowSpanGroups[i] = group;
|
|
421
|
+
}
|
|
422
|
+
firstRow = lastRow + 1;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
const { firstRow, lastRow } = this.rowSpanGroups[rowIndex];
|
|
426
|
+
if (firstRow === lastRow) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
for (let i = firstRow; i <= lastRow; i++) {
|
|
430
|
+
this.breakableBlocks.add(body[i]);
|
|
431
|
+
// Discard temporary contexts only within this connected span group.
|
|
432
|
+
body[i].forEach(cell => delete cell._columnEndingContext);
|
|
433
|
+
}
|
|
434
|
+
delete this.tableNode._breaksBySpan;
|
|
435
|
+
delete this.tableNode._bottomByPage;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
endRow(rowIndex, writer, pageBreaks) {
|
|
439
|
+
const getLineXs = () => {
|
|
440
|
+
let result = [];
|
|
441
|
+
let cols = 0;
|
|
442
|
+
|
|
443
|
+
for (let i = 0, l = this.tableNode.table.body[rowIndex].length; i < l; i++) {
|
|
444
|
+
if (!cols) {
|
|
445
|
+
result.push({ x: this.rowSpanData[i].left, index: i });
|
|
446
|
+
|
|
447
|
+
let item = this.tableNode.table.body[rowIndex][i];
|
|
448
|
+
cols = (item._colSpan || item.colSpan || 0);
|
|
449
|
+
}
|
|
450
|
+
if (cols > 0) {
|
|
451
|
+
cols--;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
result.push({ x: this.rowSpanData[this.rowSpanData.length - 1].left, index: this.rowSpanData.length - 1 });
|
|
456
|
+
|
|
457
|
+
return result;
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
writer.removeListener('pageChanged', this.rowCallback);
|
|
461
|
+
writer.context().moveDown(this.layout.paddingBottom(rowIndex, this.tableNode));
|
|
462
|
+
writer.context().availableHeight += this.reservedAtBottom;
|
|
463
|
+
|
|
464
|
+
let endingPage = writer.context().page;
|
|
465
|
+
let endingY = writer.context().y;
|
|
466
|
+
|
|
467
|
+
let xs = getLineXs();
|
|
468
|
+
|
|
469
|
+
let ys = [];
|
|
470
|
+
|
|
471
|
+
let hasBreaks = pageBreaks && pageBreaks.length > 0;
|
|
472
|
+
let body = this.tableNode.table.body;
|
|
473
|
+
|
|
474
|
+
ys.push({
|
|
475
|
+
y0: this.rowTopY,
|
|
476
|
+
page: hasBreaks ? pageBreaks[0].prevPage : endingPage
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
if (hasBreaks) {
|
|
480
|
+
for (let i = 0, l = pageBreaks.length; i < l; i++) {
|
|
481
|
+
let pageBreak = pageBreaks[i];
|
|
482
|
+
ys[ys.length - 1].y1 = pageBreak.prevY;
|
|
483
|
+
|
|
484
|
+
ys.push({ y0: pageBreak.y, page: pageBreak.prevPage + 1 });
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
ys[ys.length - 1].y1 = endingY;
|
|
489
|
+
|
|
490
|
+
let skipOrphanePadding = (ys[0].y1 - ys[0].y0 === this.rowPaddingTop);
|
|
491
|
+
if (rowIndex === 0 && !skipOrphanePadding && !this.rowsWithoutPageBreak && !this.dontBreakRows) {
|
|
492
|
+
// Draw the top border of the table
|
|
493
|
+
let pageTableStartedAt = null;
|
|
494
|
+
if (pageBreaks && pageBreaks.length > 0) {
|
|
495
|
+
// Get the page where table started at
|
|
496
|
+
pageTableStartedAt = pageBreaks[0].prevPage;
|
|
497
|
+
}
|
|
498
|
+
this.drawHorizontalLine(0, writer, this._tableTopBorderY, false, pageTableStartedAt);
|
|
499
|
+
}
|
|
500
|
+
for (let yi = (skipOrphanePadding ? 1 : 0), yl = ys.length; yi < yl; yi++) {
|
|
501
|
+
let willBreak = yi < ys.length - 1;
|
|
502
|
+
let rowBreakWithoutHeader = (yi > 0 && !this.headerRows);
|
|
503
|
+
let hzLineOffset = rowBreakWithoutHeader ? 0 : this.topLineWidth;
|
|
504
|
+
let y1 = ys[yi].y0;
|
|
505
|
+
let y2 = ys[yi].y1;
|
|
506
|
+
|
|
507
|
+
if (willBreak) {
|
|
508
|
+
y2 = y2 + this.rowPaddingBottom;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (writer.context().page != ys[yi].page) {
|
|
512
|
+
writer.context().page = ys[yi].page;
|
|
513
|
+
|
|
514
|
+
//TODO: buggy, availableHeight should be updated on every pageChanged event
|
|
515
|
+
// TableProcessor should be pageChanged listener, instead of processRow
|
|
516
|
+
this.reservedAtBottom = 0;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// Draw horizontal lines before the vertical lines so they are not overridden
|
|
520
|
+
if (willBreak && this.layout.hLineWhenBroken !== false) {
|
|
521
|
+
this.drawHorizontalLine(rowIndex + 1, writer, y2);
|
|
522
|
+
}
|
|
523
|
+
if (rowBreakWithoutHeader && this.layout.hLineWhenBroken !== false) {
|
|
524
|
+
this.drawHorizontalLine(rowIndex, writer, y1);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
let alignmentBottomPosition;
|
|
528
|
+
for (let i = 0, l = xs.length; i < l; i++) {
|
|
529
|
+
let leftCellBorder = false;
|
|
530
|
+
let rightCellBorder = false;
|
|
531
|
+
let colIndex = xs[i].index;
|
|
532
|
+
|
|
533
|
+
// current cell
|
|
534
|
+
if (colIndex < body[rowIndex].length) {
|
|
535
|
+
let cell = body[rowIndex][colIndex];
|
|
536
|
+
leftCellBorder = cell.border ? cell.border[0] : this.layout.defaultBorder;
|
|
537
|
+
rightCellBorder = cell.border ? cell.border[2] : this.layout.defaultBorder;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// before cell
|
|
541
|
+
if (colIndex > 0 && !leftCellBorder) {
|
|
542
|
+
let cell = body[rowIndex][colIndex - 1];
|
|
543
|
+
leftCellBorder = cell.border ? cell.border[2] : this.layout.defaultBorder;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// after cell
|
|
547
|
+
if (colIndex + 1 < body[rowIndex].length && !rightCellBorder) {
|
|
548
|
+
let cell = body[rowIndex][colIndex + 1];
|
|
549
|
+
rightCellBorder = cell.border ? cell.border[0] : this.layout.defaultBorder;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
if (leftCellBorder) {
|
|
553
|
+
this.drawVerticalLine(xs[i].x, y1 - hzLineOffset, y2 + this.bottomLineWidth, xs[i].index, writer, rowIndex, xs[i - 1] ? xs[i - 1].index : null);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
if (i < l - 1) {
|
|
557
|
+
body[rowIndex][colIndex]._willBreak = body[rowIndex][colIndex]._willBreak ?? willBreak;
|
|
558
|
+
let bottomY = this.dontBreakRows ? y2 + this.bottomLineWidth : y2 + (this.bottomLineWidth / 2);
|
|
559
|
+
if (willBreak || this.dontBreakRows) {
|
|
560
|
+
bottomY = bottomY - this.rowPaddingBottom;
|
|
561
|
+
}
|
|
562
|
+
bottomY -= this.reservedAtBottom;
|
|
563
|
+
if (body[rowIndex][colIndex]._bottomY === undefined) {
|
|
564
|
+
body[rowIndex][colIndex]._bottomY = bottomY;
|
|
565
|
+
}
|
|
566
|
+
const spanOffset = body[rowIndex][colIndex]._rowSpanCurrentOffset || 0;
|
|
567
|
+
const firstPage = body[rowIndex - spanOffset][colIndex]._verticalAlignmentFirstPage;
|
|
568
|
+
if (firstPage) {
|
|
569
|
+
firstPage.hasPageBreak = firstPage.hasPageBreak || hasBreaks;
|
|
570
|
+
if (!alignmentBottomPosition) {
|
|
571
|
+
alignmentBottomPosition = writer.getCurrentPositionOnPage();
|
|
572
|
+
// Whole rows end before their bottom padding; split rows use the break boundary.
|
|
573
|
+
alignmentBottomPosition.top = this.dontBreakRows && !hasBreaks ? y2 - this.rowPaddingBottom : bottomY;
|
|
574
|
+
}
|
|
575
|
+
firstPage.ends.push(alignmentBottomPosition);
|
|
576
|
+
}
|
|
577
|
+
body[rowIndex][colIndex]._rowTopPageY = this.rowTopPageY;
|
|
578
|
+
if (this.dontBreakRows) {
|
|
579
|
+
body[rowIndex][colIndex]._rowTopPageYPadding = this.rowPaddingTop;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
body[rowIndex][colIndex]._lastPageNumber = ys[yi].page + 1;
|
|
583
|
+
|
|
584
|
+
let fillColor = body[rowIndex][colIndex]._fillColor;
|
|
585
|
+
let fillOpacity = body[rowIndex][colIndex]._fillOpacity;
|
|
586
|
+
if (!fillColor) {
|
|
587
|
+
fillColor = typeof this.layout.fillColor === 'function' ? this.layout.fillColor(rowIndex, this.tableNode, colIndex) : this.layout.fillColor;
|
|
588
|
+
}
|
|
589
|
+
if (!isNumber(fillOpacity)) {
|
|
590
|
+
fillOpacity = typeof this.layout.fillOpacity === 'function' ? this.layout.fillOpacity(rowIndex, this.tableNode, colIndex) : this.layout.fillOpacity;
|
|
591
|
+
}
|
|
592
|
+
var overlayPattern = body[rowIndex][colIndex].overlayPattern;
|
|
593
|
+
var overlayOpacity = body[rowIndex][colIndex].overlayOpacity;
|
|
594
|
+
if (fillColor || overlayPattern) {
|
|
595
|
+
let widthLeftBorder = leftCellBorder ? this.layout.vLineWidth(colIndex, this.tableNode) : 0;
|
|
596
|
+
let widthRightBorder;
|
|
597
|
+
if ((colIndex === 0 || colIndex + 1 == body[rowIndex].length) && !rightCellBorder) {
|
|
598
|
+
widthRightBorder = this.layout.vLineWidth(colIndex + 1, this.tableNode);
|
|
599
|
+
} else if (rightCellBorder) {
|
|
600
|
+
widthRightBorder = this.layout.vLineWidth(colIndex + 1, this.tableNode) / 2;
|
|
601
|
+
} else {
|
|
602
|
+
widthRightBorder = 0;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
let x1f = this.dontBreakRows ? xs[i].x + widthLeftBorder : xs[i].x + (widthLeftBorder / 2);
|
|
606
|
+
let y1f = this.dontBreakRows ? y1 : y1 - (hzLineOffset / 2);
|
|
607
|
+
let x2f = xs[i + 1].x + widthRightBorder;
|
|
608
|
+
let y2f = this.dontBreakRows ? y2 + this.bottomLineWidth : y2 + (this.bottomLineWidth / 2);
|
|
609
|
+
var bgWidth = x2f - x1f;
|
|
610
|
+
var bgHeight = y2f - y1f;
|
|
611
|
+
if (fillColor) {
|
|
612
|
+
writer.addVector({
|
|
613
|
+
type: 'rect',
|
|
614
|
+
x: x1f,
|
|
615
|
+
y: y1f,
|
|
616
|
+
w: bgWidth,
|
|
617
|
+
h: bgHeight,
|
|
618
|
+
lineWidth: 0,
|
|
619
|
+
color: fillColor,
|
|
620
|
+
fillOpacity: fillOpacity,
|
|
621
|
+
// mark if we are in an unbreakable block,
|
|
622
|
+
// fills inside a vertical alignment block of this unbreakable block keep their position
|
|
623
|
+
_isFillColorFromUnbreakable: !!writer.transactionLevel && !writer.getOpenVerticalAlignment()
|
|
624
|
+
}, false, true, writer.getBackgroundInsertIndex());
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
if (overlayPattern) {
|
|
628
|
+
writer.addVector({
|
|
629
|
+
type: 'rect',
|
|
630
|
+
x: x1f,
|
|
631
|
+
y: y1f,
|
|
632
|
+
w: bgWidth,
|
|
633
|
+
h: bgHeight,
|
|
634
|
+
lineWidth: 0,
|
|
635
|
+
color: overlayPattern,
|
|
636
|
+
fillOpacity: overlayOpacity
|
|
637
|
+
}, false, true);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
writer.context().page = endingPage;
|
|
645
|
+
writer.context().y = endingY;
|
|
646
|
+
|
|
647
|
+
let row = this.tableNode.table.body[rowIndex];
|
|
648
|
+
for (let i = 0, l = row.length; i < l; i++) {
|
|
649
|
+
if (row[i].rowSpan) {
|
|
650
|
+
this.rowSpanData[i].rowSpan = row[i].rowSpan;
|
|
651
|
+
|
|
652
|
+
// fix colSpans
|
|
653
|
+
if (row[i].colSpan && row[i].colSpan > 1) {
|
|
654
|
+
for (let j = 1; j < row[i].rowSpan; j++) {
|
|
655
|
+
this.tableNode.table.body[rowIndex + j][i]._colSpan = row[i].colSpan;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// fix rowSpans
|
|
660
|
+
if (row[i].rowSpan && row[i].rowSpan > 1) {
|
|
661
|
+
for (let j = 1; j < row[i].rowSpan; j++) {
|
|
662
|
+
this.tableNode.table.body[rowIndex + j][i]._rowSpanCurrentOffset = j;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
if (this.rowSpanData[i].rowSpan > 0) {
|
|
668
|
+
this.rowSpanData[i].rowSpan--;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
this.drawHorizontalLine(rowIndex + 1, writer);
|
|
673
|
+
|
|
674
|
+
if (this.headerRows && rowIndex === this.headerRows - 1) {
|
|
675
|
+
this.headerRepeatable = writer.currentBlockToRepeatable();
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
const shouldCommitCurrentRowUnbreakable = this.dontBreakRows && (rowIndex === 0 || this._isCurrentRowUnbreakable);
|
|
679
|
+
|
|
680
|
+
if (shouldCommitCurrentRowUnbreakable) {
|
|
681
|
+
const pageChangedCallback = () => {
|
|
682
|
+
if (rowIndex > 0 && !this.headerRows && this.layout.hLineWhenBroken !== false) {
|
|
683
|
+
// Draw the top border of the row after a page break
|
|
684
|
+
this.drawHorizontalLine(rowIndex, writer);
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
writer.addListener('pageChanged', pageChangedCallback);
|
|
689
|
+
|
|
690
|
+
if (writer.commitUnbreakableBlock()) {
|
|
691
|
+
this.breakableBlocks.add(this.tableNode.table.body[rowIndex]);
|
|
692
|
+
this.releaseRowSpans(rowIndex);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
writer.removeListener('pageChanged', pageChangedCallback);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
this._isCurrentRowUnbreakable = false;
|
|
699
|
+
|
|
700
|
+
if (this.headerRepeatable && (rowIndex === (this.rowsWithoutPageBreak - 1) || rowIndex === this.tableNode.table.body.length - 1)) {
|
|
701
|
+
if (writer.commitUnbreakableBlock()) {
|
|
702
|
+
if (this.rowsWithoutPageBreak === this.headerRows) {
|
|
703
|
+
throw new Error('Table header cannot fit on a page within the available space.');
|
|
704
|
+
}
|
|
705
|
+
// Release keepWithHeaderRows, but always preserve the repeating header.
|
|
706
|
+
this.breakableBlocks.add(this.tableNode.table);
|
|
707
|
+
this.releaseRowSpans(rowIndex);
|
|
708
|
+
}
|
|
709
|
+
// Nested headers are measured with their enclosing block and repeated after it is released.
|
|
710
|
+
if (!this.headerInUnbreakableBlock) {
|
|
711
|
+
writer.pushToRepeatables(this.headerRepeatable);
|
|
712
|
+
this.cleanUpRepeatables = true;
|
|
713
|
+
}
|
|
714
|
+
this.headerRepeatable = null;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
export default TableProcessor;
|