@digicole/pdfmake-rtl 2.1.1 → 2.1.2

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