pdfmake 0.2.13 → 0.2.14

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdfmake",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "Client/server side PDF printing in pure JavaScript",
5
5
  "main": "src/printer.js",
6
6
  "browser": "build/pdfmake.js",
@@ -186,10 +186,13 @@ ElementWriter.prototype.alignCanvas = function (node) {
186
186
  }
187
187
  };
188
188
 
189
- ElementWriter.prototype.addVector = function (vector, ignoreContextX, ignoreContextY, index) {
189
+ ElementWriter.prototype.addVector = function (vector, ignoreContextX, ignoreContextY, index, forcePage) {
190
190
  var context = this.context;
191
- var page = context.getCurrentPage(),
192
- position = this.getCurrentPositionOnPage();
191
+ var page = context.getCurrentPage();
192
+ if (isNumber(forcePage)) {
193
+ page = context.pages[forcePage];
194
+ }
195
+ var position = this.getCurrentPositionOnPage();
193
196
 
194
197
  if (page) {
195
198
  offsetVector(vector, ignoreContextX ? 0 : context.x, ignoreContextY ? 0 : context.y);
@@ -635,7 +635,7 @@ LayoutBuilder.prototype.processRow = function ({ marginX = [0, 0], dontBreakRows
635
635
  var discountY = 0;
636
636
  if (dontBreakRows) {
637
637
  // Calculate how many points we have to discount to Y when dontBreakRows and rowSpan are combined
638
- const ctxBeforeRowSpanLastRow = self.writer.contextStack[self.writer.contextStack.length - 1];
638
+ const ctxBeforeRowSpanLastRow = self.writer.writer.contextStack[self.writer.writer.contextStack.length - 1];
639
639
  discountY = ctxBeforeRowSpanLastRow.y - column._startingRowSpanY;
640
640
  }
641
641
  var originalXOffset = 0;
@@ -52,8 +52,8 @@ PageElementWriter.prototype.addQr = function (qr, index) {
52
52
  });
53
53
  };
54
54
 
55
- PageElementWriter.prototype.addVector = function (vector, ignoreContextX, ignoreContextY, index) {
56
- return this.writer.addVector(vector, ignoreContextX, ignoreContextY, index);
55
+ PageElementWriter.prototype.addVector = function (vector, ignoreContextX, ignoreContextY, index, forcePage) {
56
+ return this.writer.addVector(vector, ignoreContextX, ignoreContextY, index, forcePage);
57
57
  };
58
58
 
59
59
  PageElementWriter.prototype.beginClip = function (width, height) {
@@ -49,15 +49,19 @@ TableProcessor.prototype.beginTable = function (writer) {
49
49
 
50
50
  this.dontBreakRows = tableNode.table.dontBreakRows || false;
51
51
 
52
- if (this.rowsWithoutPageBreak) {
52
+ if (this.rowsWithoutPageBreak || this.dontBreakRows) {
53
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
+ }
54
60
  }
55
61
 
56
62
  // update the border properties of all cells before drawing any lines
57
63
  prepareCellBorders(this.tableNode.table.body);
58
64
 
59
- this.drawHorizontalLine(0, writer);
60
-
61
65
  function getTableInnerContentWidth() {
62
66
  var width = 0;
63
67
 
@@ -156,7 +160,12 @@ TableProcessor.prototype.beginRow = function (rowIndex, writer) {
156
160
 
157
161
  this.rowCallback = this.onRowBreak(rowIndex, writer);
158
162
  writer.tracker.startTracking('pageChanged', this.rowCallback);
159
- if (this.dontBreakRows) {
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) {
160
169
  writer.beginUnbreakableBlock();
161
170
  }
162
171
  this.rowTopY = writer.context().y;
@@ -167,7 +176,7 @@ TableProcessor.prototype.beginRow = function (rowIndex, writer) {
167
176
  writer.context().moveDown(this.rowPaddingTop);
168
177
  };
169
178
 
170
- TableProcessor.prototype.drawHorizontalLine = function (lineIndex, writer, overrideY) {
179
+ TableProcessor.prototype.drawHorizontalLine = function (lineIndex, writer, overrideY, moveDown = true, forcePage) {
171
180
  var lineWidth = this.layout.hLineWidth(lineIndex, this.tableNode);
172
181
  if (lineWidth) {
173
182
  var style = this.layout.hLineStyle(lineIndex, this.tableNode);
@@ -266,7 +275,7 @@ TableProcessor.prototype.drawHorizontalLine = function (lineIndex, writer, overr
266
275
  lineWidth: lineWidth,
267
276
  dash: dash,
268
277
  lineColor: borderColor
269
- }, false, overrideY);
278
+ }, false, isNumber(overrideY), null, forcePage);
270
279
  currentLine = null;
271
280
  borderColor = null;
272
281
  cellAbove = null;
@@ -276,7 +285,9 @@ TableProcessor.prototype.drawHorizontalLine = function (lineIndex, writer, overr
276
285
  }
277
286
  }
278
287
 
279
- writer.context().moveDown(lineWidth);
288
+ if (moveDown) {
289
+ writer.context().moveDown(lineWidth);
290
+ }
280
291
  }
281
292
  };
282
293
 
@@ -392,6 +403,15 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks) {
392
403
  ys[ys.length - 1].y1 = endingY;
393
404
 
394
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
+ }
395
415
  for (var yi = (skipOrphanePadding ? 1 : 0), yl = ys.length; yi < yl; yi++) {
396
416
  var willBreak = yi < ys.length - 1;
397
417
  var rowBreakWithoutHeader = (yi > 0 && !this.headerRows);
@@ -411,6 +431,14 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks) {
411
431
  this.reservedAtBottom = 0;
412
432
  }
413
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
+
414
442
  for (i = 0, l = xs.length; i < l; i++) {
415
443
  var leftCellBorder = false;
416
444
  var rightCellBorder = false;
@@ -497,13 +525,6 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks) {
497
525
  }
498
526
  }
499
527
  }
500
-
501
- if (willBreak && this.layout.hLineWhenBroken !== false) {
502
- this.drawHorizontalLine(rowIndex + 1, writer, y2);
503
- }
504
- if (rowBreakWithoutHeader && this.layout.hLineWhenBroken !== false) {
505
- this.drawHorizontalLine(rowIndex, writer, y1);
506
- }
507
528
  }
508
529
 
509
530
  writer.context().page = endingPage;
@@ -542,7 +563,8 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks) {
542
563
  if (this.dontBreakRows) {
543
564
  writer.tracker.auto('pageChanged',
544
565
  function () {
545
- if (!self.headerRows && self.layout.hLineWhenBroken !== false) {
566
+ if (rowIndex > 0 && !self.headerRows && self.layout.hLineWhenBroken !== false) {
567
+ // Draw the top border of the row after a page break
546
568
  self.drawHorizontalLine(rowIndex, writer);
547
569
  }
548
570
  },
@@ -1,7 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <code_scheme name="Project" version="173">
3
- <JSCodeStyleSettings version="0">
4
- <option name="FORCE_SEMICOLON_STYLE" value="true" />
5
- </JSCodeStyleSettings>
6
- </code_scheme>
7
- </component>
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="USE_PER_PROJECT_SETTINGS" value="true" />
4
- </state>
5
- </component>