pdfmake 0.2.12 → 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.
@@ -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) {
package/src/printer.js CHANGED
@@ -125,7 +125,7 @@ PdfPrinter.prototype.createPdfKitDocument = function (docDefinition, options) {
125
125
  userPassword: docDefinition.userPassword,
126
126
  ownerPassword: docDefinition.ownerPassword,
127
127
  permissions: docDefinition.permissions,
128
- lang: docDefinition.language,
128
+ lang: docDefinition.language,
129
129
  fontLayoutCache: isBoolean(options.fontLayoutCache) ? options.fontLayoutCache : true,
130
130
  bufferPages: options.bufferPages || false,
131
131
  autoFirstPage: false,
@@ -43,21 +43,25 @@ TableProcessor.prototype.beginTable = function (writer) {
43
43
  const keepWithHeaderRows = tableNode.table.keepWithHeaderRows;
44
44
 
45
45
  if (isPositiveInteger(keepWithHeaderRows)) {
46
- this.rowsWithoutPageBreak += keepWithHeaderRows;
46
+ this.rowsWithoutPageBreak += keepWithHeaderRows;
47
47
  }
48
48
  }
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;
@@ -476,7 +504,9 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks) {
476
504
  h: bgHeight,
477
505
  lineWidth: 0,
478
506
  color: fillColor,
479
- fillOpacity: fillOpacity
507
+ fillOpacity: fillOpacity,
508
+ // mark if we are in an unbreakable block
509
+ _isFillColorFromUnbreakable: !!writer.transactionLevel
480
510
  }, false, true, writer.context().backgroundLength[writer.context().page]);
481
511
  }
482
512
 
@@ -495,13 +525,6 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks) {
495
525
  }
496
526
  }
497
527
  }
498
-
499
- if (willBreak && this.layout.hLineWhenBroken !== false) {
500
- this.drawHorizontalLine(rowIndex + 1, writer, y2);
501
- }
502
- if (rowBreakWithoutHeader && this.layout.hLineWhenBroken !== false) {
503
- this.drawHorizontalLine(rowIndex, writer, y1);
504
- }
505
528
  }
506
529
 
507
530
  writer.context().page = endingPage;
@@ -540,7 +563,8 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks) {
540
563
  if (this.dontBreakRows) {
541
564
  writer.tracker.auto('pageChanged',
542
565
  function () {
543
- 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
544
568
  self.drawHorizontalLine(rowIndex, writer);
545
569
  }
546
570
  },
package/src/textTools.js CHANGED
@@ -112,7 +112,7 @@ TextTools.prototype.sizeOfRotatedText = function (text, angle, styleContextStack
112
112
  width: Math.abs(size.height * Math.sin(angleRad)) + Math.abs(size.width * Math.cos(angleRad)),
113
113
  height: Math.abs(size.width * Math.sin(angleRad)) + Math.abs(size.height * Math.cos(angleRad))
114
114
  };
115
- }
115
+ };
116
116
 
117
117
  TextTools.prototype.widthOfString = function (text, font, fontSize, characterSpacing, fontFeatures) {
118
118
  return widthOfString(text, font, fontSize, characterSpacing, fontFeatures);
@@ -320,7 +320,7 @@ function measure(fontProvider, textArray, styleContextStack) {
320
320
 
321
321
  if ((sup || sub) && item.fontSize === undefined) {
322
322
  // font size reduction taken from here: https://en.wikipedia.org/wiki/Subscript_and_superscript#Desktop_publishing
323
- fontSize *= 0.58
323
+ fontSize *= 0.58;
324
324
  }
325
325
 
326
326
  var font = fontProvider.provideFont(fontName, bold, italics);