pdfmake 0.2.13 → 0.3.0-beta.10

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