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,620 @@
1
+ import ColumnCalculator from './columnCalculator';
2
+ import { isNumber, isPositiveInteger } from './helpers/variableType';
3
+
4
+ class TableProcessor {
5
+ constructor(tableNode) {
6
+ this.tableNode = tableNode;
7
+ }
8
+
9
+ beginTable(writer) {
10
+ const getTableInnerContentWidth = () => {
11
+ let width = 0;
12
+
13
+ tableNode.table.widths.forEach(w => {
14
+ width += w._calcWidth;
15
+ });
16
+
17
+ return width;
18
+ };
19
+
20
+ const prepareRowSpanData = () => {
21
+ let rsd = [];
22
+ let x = 0;
23
+ let lastWidth = 0;
24
+
25
+ rsd.push({ left: 0, rowSpan: 0 });
26
+
27
+ for (let i = 0, l = this.tableNode.table.body[0].length; i < l; i++) {
28
+ let paddings = this.layout.paddingLeft(i, this.tableNode) + this.layout.paddingRight(i, this.tableNode);
29
+ let lBorder = this.layout.vLineWidth(i, this.tableNode);
30
+ lastWidth = paddings + lBorder + this.tableNode.table.widths[i]._calcWidth;
31
+ rsd[rsd.length - 1].width = lastWidth;
32
+ x += lastWidth;
33
+ rsd.push({ left: x, rowSpan: 0, width: 0 });
34
+ }
35
+
36
+ return rsd;
37
+ };
38
+
39
+ // Iterate through all cells. If the current cell is the start of a
40
+ // rowSpan/colSpan, update the border property of the cells on its
41
+ // bottom/right accordingly. This is needed since each iteration of the
42
+ // line-drawing loops draws lines for a single cell, not for an entire
43
+ // rowSpan/colSpan.
44
+ const prepareCellBorders = body => {
45
+ for (let rowIndex = 0; rowIndex < body.length; rowIndex++) {
46
+ let row = body[rowIndex];
47
+
48
+ for (let colIndex = 0; colIndex < row.length; colIndex++) {
49
+ let cell = row[colIndex];
50
+
51
+ if (cell.border) {
52
+ let rowSpan = cell.rowSpan || 1;
53
+ let colSpan = cell.colSpan || 1;
54
+
55
+ for (let rowOffset = 0; rowOffset < rowSpan; rowOffset++) {
56
+ // set left border
57
+ if (cell.border[0] !== undefined && rowOffset > 0) {
58
+ setBorder(rowIndex + rowOffset, colIndex, 0, cell.border[0]);
59
+ }
60
+
61
+ // set right border
62
+ if (cell.border[2] !== undefined) {
63
+ setBorder(rowIndex + rowOffset, colIndex + colSpan - 1, 2, cell.border[2]);
64
+ }
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
+
90
+ let tableNode;
91
+ let availableWidth;
92
+
93
+ tableNode = this.tableNode;
94
+ this.offsets = tableNode._offsets;
95
+ this.layout = tableNode._layout;
96
+
97
+ availableWidth = writer.context().availableWidth - this.offsets.total;
98
+ ColumnCalculator.buildColumnWidths(tableNode.table.widths, availableWidth, this.offsets.total, tableNode);
99
+
100
+ this.tableWidth = tableNode._offsets.total + getTableInnerContentWidth();
101
+ this.rowSpanData = prepareRowSpanData();
102
+ this.cleanUpRepeatables = false;
103
+
104
+ // headersRows and rowsWithoutPageBreak (headerRows + keepWithHeaderRows)
105
+ this.headerRows = 0;
106
+ this.rowsWithoutPageBreak = 0;
107
+
108
+ const headerRows = tableNode.table.headerRows;
109
+
110
+ if (isPositiveInteger(headerRows)) {
111
+ this.headerRows = headerRows;
112
+
113
+ if (this.headerRows > tableNode.table.body.length) {
114
+ throw new Error(`Too few rows in the table. Property headerRows requires at least ${this.headerRows}, contains only ${tableNode.table.body.length}`);
115
+ }
116
+
117
+ this.rowsWithoutPageBreak = this.headerRows;
118
+
119
+ const keepWithHeaderRows = tableNode.table.keepWithHeaderRows;
120
+
121
+ if (isPositiveInteger(keepWithHeaderRows)) {
122
+ this.rowsWithoutPageBreak += keepWithHeaderRows;
123
+ }
124
+ }
125
+
126
+ this.dontBreakRows = tableNode.table.dontBreakRows || false;
127
+
128
+ if (this.rowsWithoutPageBreak || this.dontBreakRows) {
129
+ writer.beginUnbreakableBlock();
130
+ // Draw the top border of the table
131
+ this.drawHorizontalLine(0, writer);
132
+ if (this.rowsWithoutPageBreak && this.dontBreakRows) {
133
+ // We just increase the value of transactionLevel
134
+ writer.beginUnbreakableBlock();
135
+ }
136
+ }
137
+
138
+ // update the border properties of all cells before drawing any lines
139
+ prepareCellBorders(this.tableNode.table.body);
140
+ }
141
+
142
+ onRowBreak(rowIndex, writer) {
143
+ return () => {
144
+ let offset = this.rowPaddingTop + (!this.headerRows ? this.topLineWidth : 0);
145
+ writer.context().availableHeight -= this.reservedAtBottom;
146
+ writer.context().moveDown(offset);
147
+ };
148
+ }
149
+
150
+ beginRow(rowIndex, writer) {
151
+ this.topLineWidth = this.layout.hLineWidth(rowIndex, this.tableNode);
152
+ this.rowPaddingTop = this.layout.paddingTop(rowIndex, this.tableNode);
153
+ this.bottomLineWidth = this.layout.hLineWidth(rowIndex + 1, this.tableNode);
154
+ this.rowPaddingBottom = this.layout.paddingBottom(rowIndex, this.tableNode);
155
+
156
+ this.rowCallback = this.onRowBreak(rowIndex, writer);
157
+ writer.addListener('pageChanged', this.rowCallback);
158
+ if (rowIndex == 0 && !this.dontBreakRows && !this.rowsWithoutPageBreak) {
159
+ // We store the 'y' to draw later and if necessary the top border of the table
160
+ this._tableTopBorderY = writer.context().y;
161
+ writer.context().moveDown(this.topLineWidth);
162
+ }
163
+
164
+ this.rowTopPageY = writer.context().y + this.rowPaddingTop;
165
+
166
+ if (this.dontBreakRows && rowIndex > 0) {
167
+ writer.beginUnbreakableBlock();
168
+ }
169
+ this.rowTopY = writer.context().y;
170
+ this.reservedAtBottom = this.bottomLineWidth + this.rowPaddingBottom;
171
+
172
+ writer.context().availableHeight -= this.reservedAtBottom;
173
+
174
+ writer.context().moveDown(this.rowPaddingTop);
175
+ }
176
+
177
+ drawHorizontalLine(lineIndex, writer, overrideY, moveDown = true, forcePage) {
178
+ let lineWidth = this.layout.hLineWidth(lineIndex, this.tableNode);
179
+ if (lineWidth) {
180
+ let style = this.layout.hLineStyle(lineIndex, this.tableNode);
181
+ let dash;
182
+ if (style && style.dash) {
183
+ dash = style.dash;
184
+ }
185
+
186
+ let offset = lineWidth / 2;
187
+ let currentLine = null;
188
+ let body = this.tableNode.table.body;
189
+ let cellAbove;
190
+ let currentCell;
191
+ let rowCellAbove;
192
+
193
+ for (let i = 0, l = this.rowSpanData.length; i < l; i++) {
194
+ let data = this.rowSpanData[i];
195
+ let shouldDrawLine = !data.rowSpan;
196
+ let borderColor = null;
197
+
198
+ // draw only if the current cell requires a top border or the cell in the
199
+ // row above requires a bottom border
200
+ if (shouldDrawLine && i < l - 1) {
201
+ var topBorder = false, bottomBorder = false, rowBottomBorder = false;
202
+
203
+ // the cell in the row above
204
+ if (lineIndex > 0) {
205
+ cellAbove = body[lineIndex - 1][i];
206
+ bottomBorder = cellAbove.border ? cellAbove.border[3] : this.layout.defaultBorder;
207
+ if (bottomBorder && cellAbove.borderColor) {
208
+ borderColor = cellAbove.borderColor[3];
209
+ }
210
+ }
211
+
212
+ // the current cell
213
+ if (lineIndex < body.length) {
214
+ currentCell = body[lineIndex][i];
215
+ topBorder = currentCell.border ? currentCell.border[1] : this.layout.defaultBorder;
216
+ if (topBorder && borderColor == null && currentCell.borderColor) {
217
+ borderColor = currentCell.borderColor[1];
218
+ }
219
+ }
220
+
221
+ shouldDrawLine = topBorder || bottomBorder;
222
+ }
223
+
224
+ if (cellAbove && cellAbove._rowSpanCurrentOffset) {
225
+ rowCellAbove = body[lineIndex - 1 - cellAbove._rowSpanCurrentOffset][i];
226
+ rowBottomBorder = rowCellAbove && rowCellAbove.border ? rowCellAbove.border[3] : this.layout.defaultBorder;
227
+ if (rowBottomBorder && rowCellAbove && rowCellAbove.borderColor) {
228
+ borderColor = rowCellAbove.borderColor[3];
229
+ }
230
+ }
231
+
232
+ if (borderColor == null) {
233
+ borderColor = typeof this.layout.hLineColor === 'function' ? this.layout.hLineColor(lineIndex, this.tableNode, i) : this.layout.hLineColor;
234
+ }
235
+
236
+ if (!currentLine && shouldDrawLine) {
237
+ currentLine = { left: data.left, width: 0 };
238
+ }
239
+
240
+ if (shouldDrawLine) {
241
+ let colSpanIndex = 0;
242
+ if (rowCellAbove && rowCellAbove.colSpan && rowBottomBorder) {
243
+ while (rowCellAbove.colSpan > colSpanIndex) {
244
+ currentLine.width += (this.rowSpanData[i + colSpanIndex++].width || 0);
245
+ }
246
+ i += colSpanIndex - 1;
247
+ } else if (cellAbove && cellAbove.colSpan && bottomBorder) {
248
+ while (cellAbove.colSpan > colSpanIndex) {
249
+ currentLine.width += (this.rowSpanData[i + colSpanIndex++].width || 0);
250
+ }
251
+ i += colSpanIndex - 1;
252
+ } else if (currentCell && currentCell.colSpan && topBorder) {
253
+ while (currentCell.colSpan > colSpanIndex) {
254
+ currentLine.width += (this.rowSpanData[i + colSpanIndex++].width || 0);
255
+ }
256
+ i += colSpanIndex - 1;
257
+ } else {
258
+ currentLine.width += (this.rowSpanData[i].width || 0);
259
+ }
260
+ }
261
+
262
+ let y = (overrideY || 0) + offset;
263
+
264
+ if (shouldDrawLine) {
265
+ if (currentLine && currentLine.width) {
266
+ writer.addVector({
267
+ type: 'line',
268
+ x1: currentLine.left,
269
+ x2: currentLine.left + currentLine.width,
270
+ y1: y,
271
+ y2: y,
272
+ lineWidth: lineWidth,
273
+ dash: dash,
274
+ lineColor: borderColor
275
+ }, false, isNumber(overrideY), null, forcePage);
276
+ currentLine = null;
277
+ borderColor = null;
278
+ cellAbove = null;
279
+ currentCell = null;
280
+ rowCellAbove = null;
281
+ }
282
+ }
283
+ }
284
+
285
+ if (moveDown) {
286
+ writer.context().moveDown(lineWidth);
287
+ }
288
+ }
289
+ }
290
+
291
+ drawVerticalLine(x, y0, y1, vLineColIndex, writer, vLineRowIndex, beforeVLineColIndex) {
292
+ let width = this.layout.vLineWidth(vLineColIndex, this.tableNode);
293
+ if (width === 0) {
294
+ return;
295
+ }
296
+ let style = this.layout.vLineStyle(vLineColIndex, this.tableNode);
297
+ let dash;
298
+ if (style && style.dash) {
299
+ dash = style.dash;
300
+ }
301
+
302
+ let body = this.tableNode.table.body;
303
+ let cellBefore;
304
+ let currentCell;
305
+ let borderColor;
306
+
307
+ // the cell in the col before
308
+ if (vLineColIndex > 0) {
309
+ cellBefore = body[vLineRowIndex][beforeVLineColIndex];
310
+ if (cellBefore && cellBefore.borderColor) {
311
+ if (cellBefore.border ? cellBefore.border[2] : this.layout.defaultBorder) {
312
+ borderColor = cellBefore.borderColor[2];
313
+ }
314
+ }
315
+ }
316
+
317
+ // the current cell
318
+ if (borderColor == null && vLineColIndex < body.length) {
319
+ currentCell = body[vLineRowIndex][vLineColIndex];
320
+ if (currentCell && currentCell.borderColor) {
321
+ if (currentCell.border ? currentCell.border[0] : this.layout.defaultBorder) {
322
+ borderColor = currentCell.borderColor[0];
323
+ }
324
+ }
325
+ }
326
+
327
+ if (borderColor == null && cellBefore && cellBefore._rowSpanCurrentOffset) {
328
+ let rowCellBeforeAbove = body[vLineRowIndex - cellBefore._rowSpanCurrentOffset][beforeVLineColIndex];
329
+ if (rowCellBeforeAbove.borderColor) {
330
+ if (rowCellBeforeAbove.border ? rowCellBeforeAbove.border[2] : this.layout.defaultBorder) {
331
+ borderColor = rowCellBeforeAbove.borderColor[2];
332
+ }
333
+ }
334
+ }
335
+
336
+ if (borderColor == null && currentCell && currentCell._rowSpanCurrentOffset) {
337
+ let rowCurrentCellAbove = body[vLineRowIndex - currentCell._rowSpanCurrentOffset][vLineColIndex];
338
+ if (rowCurrentCellAbove.borderColor) {
339
+ if (rowCurrentCellAbove.border ? rowCurrentCellAbove.border[2] : this.layout.defaultBorder) {
340
+ borderColor = rowCurrentCellAbove.borderColor[2];
341
+ }
342
+ }
343
+ }
344
+
345
+ if (borderColor == null) {
346
+ borderColor = typeof this.layout.vLineColor === 'function' ? this.layout.vLineColor(vLineColIndex, this.tableNode, vLineRowIndex) : this.layout.vLineColor;
347
+ }
348
+
349
+ writer.addVector({
350
+ type: 'line',
351
+ x1: x + width / 2,
352
+ x2: x + width / 2,
353
+ y1: y0,
354
+ y2: y1,
355
+ lineWidth: width,
356
+ dash: dash,
357
+ lineColor: borderColor
358
+ }, false, true);
359
+ cellBefore = null;
360
+ currentCell = null;
361
+ borderColor = null;
362
+ }
363
+
364
+ endTable(writer) {
365
+ if (this.cleanUpRepeatables) {
366
+ writer.popFromRepeatables();
367
+ }
368
+ }
369
+
370
+ endRow(rowIndex, writer, pageBreaks) {
371
+ const getLineXs = () => {
372
+ let result = [];
373
+ let cols = 0;
374
+
375
+ for (let i = 0, l = this.tableNode.table.body[rowIndex].length; i < l; i++) {
376
+ if (!cols) {
377
+ result.push({ x: this.rowSpanData[i].left, index: i });
378
+
379
+ let item = this.tableNode.table.body[rowIndex][i];
380
+ cols = (item._colSpan || item.colSpan || 0);
381
+ }
382
+ if (cols > 0) {
383
+ cols--;
384
+ }
385
+ }
386
+
387
+ result.push({ x: this.rowSpanData[this.rowSpanData.length - 1].left, index: this.rowSpanData.length - 1 });
388
+
389
+ return result;
390
+ };
391
+
392
+ writer.removeListener('pageChanged', this.rowCallback);
393
+ writer.context().moveDown(this.layout.paddingBottom(rowIndex, this.tableNode));
394
+ writer.context().availableHeight += this.reservedAtBottom;
395
+
396
+ let endingPage = writer.context().page;
397
+ let endingY = writer.context().y;
398
+
399
+ let xs = getLineXs();
400
+
401
+ let ys = [];
402
+
403
+ let hasBreaks = pageBreaks && pageBreaks.length > 0;
404
+ let body = this.tableNode.table.body;
405
+
406
+ ys.push({
407
+ y0: this.rowTopY,
408
+ page: hasBreaks ? pageBreaks[0].prevPage : endingPage
409
+ });
410
+
411
+ if (hasBreaks) {
412
+ for (let i = 0, l = pageBreaks.length; i < l; i++) {
413
+ let pageBreak = pageBreaks[i];
414
+ ys[ys.length - 1].y1 = pageBreak.prevY;
415
+
416
+ ys.push({ y0: pageBreak.y, page: pageBreak.prevPage + 1 });
417
+ }
418
+ }
419
+
420
+ ys[ys.length - 1].y1 = endingY;
421
+
422
+ let skipOrphanePadding = (ys[0].y1 - ys[0].y0 === this.rowPaddingTop);
423
+ if (rowIndex === 0 && !skipOrphanePadding && !this.rowsWithoutPageBreak && !this.dontBreakRows) {
424
+ // Draw the top border of the table
425
+ let pageTableStartedAt = null;
426
+ if (pageBreaks && pageBreaks.length > 0) {
427
+ // Get the page where table started at
428
+ pageTableStartedAt = pageBreaks[0].prevPage;
429
+ }
430
+ this.drawHorizontalLine(0, writer, this._tableTopBorderY, false, pageTableStartedAt);
431
+ }
432
+ for (let yi = (skipOrphanePadding ? 1 : 0), yl = ys.length; yi < yl; yi++) {
433
+ let willBreak = yi < ys.length - 1;
434
+ let rowBreakWithoutHeader = (yi > 0 && !this.headerRows);
435
+ let hzLineOffset = rowBreakWithoutHeader ? 0 : this.topLineWidth;
436
+ let y1 = ys[yi].y0;
437
+ let y2 = ys[yi].y1;
438
+
439
+ if (willBreak) {
440
+ y2 = y2 + this.rowPaddingBottom;
441
+ }
442
+
443
+ if (writer.context().page != ys[yi].page) {
444
+ writer.context().page = ys[yi].page;
445
+
446
+ //TODO: buggy, availableHeight should be updated on every pageChanged event
447
+ // TableProcessor should be pageChanged listener, instead of processRow
448
+ this.reservedAtBottom = 0;
449
+ }
450
+
451
+ // Draw horizontal lines before the vertical lines so they are not overridden
452
+ if (willBreak && this.layout.hLineWhenBroken !== false) {
453
+ this.drawHorizontalLine(rowIndex + 1, writer, y2);
454
+ }
455
+ if (rowBreakWithoutHeader && this.layout.hLineWhenBroken !== false) {
456
+ this.drawHorizontalLine(rowIndex, writer, y1);
457
+ }
458
+
459
+ for (let i = 0, l = xs.length; i < l; i++) {
460
+ let leftCellBorder = false;
461
+ let rightCellBorder = false;
462
+ let colIndex = xs[i].index;
463
+
464
+ // current cell
465
+ if (colIndex < body[rowIndex].length) {
466
+ let cell = body[rowIndex][colIndex];
467
+ leftCellBorder = cell.border ? cell.border[0] : this.layout.defaultBorder;
468
+ rightCellBorder = cell.border ? cell.border[2] : this.layout.defaultBorder;
469
+ }
470
+
471
+ // before cell
472
+ if (colIndex > 0 && !leftCellBorder) {
473
+ let cell = body[rowIndex][colIndex - 1];
474
+ leftCellBorder = cell.border ? cell.border[2] : this.layout.defaultBorder;
475
+ }
476
+
477
+ // after cell
478
+ if (colIndex + 1 < body[rowIndex].length && !rightCellBorder) {
479
+ let cell = body[rowIndex][colIndex + 1];
480
+ rightCellBorder = cell.border ? cell.border[0] : this.layout.defaultBorder;
481
+ }
482
+
483
+ if (leftCellBorder) {
484
+ this.drawVerticalLine(xs[i].x, y1 - hzLineOffset, y2 + this.bottomLineWidth, xs[i].index, writer, rowIndex, xs[i - 1] ? xs[i - 1].index : null);
485
+ }
486
+
487
+ if (i < l - 1) {
488
+ body[rowIndex][colIndex]._willBreak = body[rowIndex][colIndex]._willBreak ?? willBreak;
489
+ if (body[rowIndex][colIndex]._bottomY === undefined) {
490
+ let bottomY = this.dontBreakRows ? y2 + this.bottomLineWidth : y2 + (this.bottomLineWidth / 2);
491
+ if (willBreak || this.dontBreakRows) {
492
+ bottomY = bottomY - this.rowPaddingBottom;
493
+ }
494
+ body[rowIndex][colIndex]._bottomY = bottomY - this.reservedAtBottom;
495
+ }
496
+ body[rowIndex][colIndex]._rowTopPageY = this.rowTopPageY;
497
+ if (this.dontBreakRows) {
498
+ body[rowIndex][colIndex]._rowTopPageYPadding = this.rowPaddingTop;
499
+ }
500
+
501
+ body[rowIndex][colIndex]._lastPageNumber = ys[yi].page + 1;
502
+
503
+ let fillColor = body[rowIndex][colIndex].fillColor;
504
+ let fillOpacity = body[rowIndex][colIndex].fillOpacity;
505
+ if (!fillColor) {
506
+ fillColor = typeof this.layout.fillColor === 'function' ? this.layout.fillColor(rowIndex, this.tableNode, colIndex) : this.layout.fillColor;
507
+ }
508
+ if (!isNumber(fillOpacity)) {
509
+ fillOpacity = typeof this.layout.fillOpacity === 'function' ? this.layout.fillOpacity(rowIndex, this.tableNode, colIndex) : this.layout.fillOpacity;
510
+ }
511
+ var overlayPattern = body[rowIndex][colIndex].overlayPattern;
512
+ var overlayOpacity = body[rowIndex][colIndex].overlayOpacity;
513
+ if (fillColor || overlayPattern) {
514
+ let widthLeftBorder = leftCellBorder ? this.layout.vLineWidth(colIndex, this.tableNode) : 0;
515
+ let widthRightBorder;
516
+ if ((colIndex === 0 || colIndex + 1 == body[rowIndex].length) && !rightCellBorder) {
517
+ widthRightBorder = this.layout.vLineWidth(colIndex + 1, this.tableNode);
518
+ } else if (rightCellBorder) {
519
+ widthRightBorder = this.layout.vLineWidth(colIndex + 1, this.tableNode) / 2;
520
+ } else {
521
+ widthRightBorder = 0;
522
+ }
523
+
524
+ let x1f = this.dontBreakRows ? xs[i].x + widthLeftBorder : xs[i].x + (widthLeftBorder / 2);
525
+ let y1f = this.dontBreakRows ? y1 : y1 - (hzLineOffset / 2);
526
+ let x2f = xs[i + 1].x + widthRightBorder;
527
+ let y2f = this.dontBreakRows ? y2 + this.bottomLineWidth : y2 + (this.bottomLineWidth / 2);
528
+ var bgWidth = x2f - x1f;
529
+ var bgHeight = y2f - y1f;
530
+ if (fillColor) {
531
+ writer.addVector({
532
+ type: 'rect',
533
+ x: x1f,
534
+ y: y1f,
535
+ w: bgWidth,
536
+ h: bgHeight,
537
+ lineWidth: 0,
538
+ color: fillColor,
539
+ fillOpacity: fillOpacity,
540
+ // mark if we are in an unbreakable block
541
+ _isFillColorFromUnbreakable: !!writer.transactionLevel
542
+ }, false, true, writer.context().backgroundLength[writer.context().page]);
543
+ }
544
+
545
+ if (overlayPattern) {
546
+ writer.addVector({
547
+ type: 'rect',
548
+ x: x1f,
549
+ y: y1f,
550
+ w: bgWidth,
551
+ h: bgHeight,
552
+ lineWidth: 0,
553
+ color: overlayPattern,
554
+ fillOpacity: overlayOpacity
555
+ }, false, true);
556
+ }
557
+ }
558
+ }
559
+ }
560
+ }
561
+
562
+ writer.context().page = endingPage;
563
+ writer.context().y = endingY;
564
+
565
+ let row = this.tableNode.table.body[rowIndex];
566
+ for (let i = 0, l = row.length; i < l; i++) {
567
+ if (row[i].rowSpan) {
568
+ this.rowSpanData[i].rowSpan = row[i].rowSpan;
569
+
570
+ // fix colSpans
571
+ if (row[i].colSpan && row[i].colSpan > 1) {
572
+ for (let j = 1; j < row[i].rowSpan; j++) {
573
+ this.tableNode.table.body[rowIndex + j][i]._colSpan = row[i].colSpan;
574
+ }
575
+ }
576
+
577
+ // fix rowSpans
578
+ if (row[i].rowSpan && row[i].rowSpan > 1) {
579
+ for (let j = 1; j < row[i].rowSpan; j++) {
580
+ this.tableNode.table.body[rowIndex + j][i]._rowSpanCurrentOffset = j;
581
+ }
582
+ }
583
+ }
584
+
585
+ if (this.rowSpanData[i].rowSpan > 0) {
586
+ this.rowSpanData[i].rowSpan--;
587
+ }
588
+ }
589
+
590
+ this.drawHorizontalLine(rowIndex + 1, writer);
591
+
592
+ if (this.headerRows && rowIndex === this.headerRows - 1) {
593
+ this.headerRepeatable = writer.currentBlockToRepeatable();
594
+ }
595
+
596
+ if (this.dontBreakRows) {
597
+ const pageChangedCallback = () => {
598
+ if (rowIndex > 0 && !this.headerRows && this.layout.hLineWhenBroken !== false) {
599
+ // Draw the top border of the row after a page break
600
+ this.drawHorizontalLine(rowIndex, writer);
601
+ }
602
+ };
603
+
604
+ writer.addListener('pageChanged', pageChangedCallback);
605
+
606
+ writer.commitUnbreakableBlock();
607
+
608
+ writer.removeListener('pageChanged', pageChangedCallback);
609
+ }
610
+
611
+ if (this.headerRepeatable && (rowIndex === (this.rowsWithoutPageBreak - 1) || rowIndex === this.tableNode.table.body.length - 1)) {
612
+ writer.commitUnbreakableBlock();
613
+ writer.pushToRepeatables(this.headerRepeatable);
614
+ this.cleanUpRepeatables = true;
615
+ this.headerRepeatable = null;
616
+ }
617
+ }
618
+ }
619
+
620
+ export default TableProcessor;