pdfmake-acroforms 0.3.4

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