pdfmake 0.3.0-beta.8 → 0.3.0

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