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