@flowaccount/pdfmake 1.0.3 → 1.0.4-staging.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowaccount/pdfmake",
3
- "version": "1.0.3",
3
+ "version": "1.0.4-staging.2",
4
4
  "description": "Client/server side PDF printing in pure JavaScript",
5
5
  "main": "src/printer.js",
6
6
  "browser": "build/pdfmake.js",
@@ -1441,27 +1441,6 @@ LayoutBuilder.prototype.buildNextLine = function (textNode) {
1441
1441
  return newInline;
1442
1442
  }
1443
1443
 
1444
- function findMaxFitLength(text, maxWidth, measureFn) {
1445
- let low = 1;
1446
- let high = text.length;
1447
- let bestFit = 1;
1448
-
1449
- while (low <= high) {
1450
- const mid = Math.floor((low + high) / 2);
1451
- const part = text.substring(0, mid);
1452
- const width = measureFn(part);
1453
-
1454
- if (width <= maxWidth) {
1455
- bestFit = mid;
1456
- low = mid + 1;
1457
- } else {
1458
- high = mid - 1;
1459
- }
1460
- }
1461
-
1462
- return bestFit;
1463
- }
1464
-
1465
1444
  if (!textNode._inlines || textNode._inlines.length === 0) {
1466
1445
  return null;
1467
1446
  }
@@ -1469,34 +1448,29 @@ LayoutBuilder.prototype.buildNextLine = function (textNode) {
1469
1448
  var line = new Line(this.writer.context().availableWidth);
1470
1449
  var textTools = new TextTools(null);
1471
1450
 
1472
- var isForceContinue = false;
1473
- while (textNode._inlines && textNode._inlines.length > 0 &&
1474
- (line.hasEnoughSpaceForInline(textNode._inlines[0], textNode._inlines.slice(1)) || isForceContinue)) {
1475
- var isHardWrap = false;
1451
+ while (textNode._inlines && textNode._inlines.length > 0 && line.hasEnoughSpaceForInline(textNode._inlines[0])) {
1476
1452
  var inline = textNode._inlines.shift();
1477
- isForceContinue = false;
1478
1453
 
1479
- if (!inline.noWrap && inline.text.length > 1 && inline.width > line.getAvailableWidth()) {
1480
- var maxChars = findMaxFitLength(inline.text, line.getAvailableWidth(), function (txt) {
1481
- return textTools.widthOfString(txt, inline.font, inline.fontSize, inline.characterSpacing, inline.fontFeatures);
1482
- });
1454
+ if (!inline.noWrap && inline.text.length > 1 && inline.width > line.maxWidth) {
1455
+ var widthPerChar = inline.width / inline.text.length;
1456
+ var maxChars = Math.floor(line.maxWidth / widthPerChar);
1457
+ if (maxChars < 1) {
1458
+ maxChars = 1;
1459
+ }
1483
1460
  if (maxChars < inline.text.length) {
1484
1461
  var newInline = cloneInline(inline);
1485
1462
 
1486
1463
  newInline.text = inline.text.substr(maxChars);
1487
1464
  inline.text = inline.text.substr(0, maxChars);
1488
1465
 
1489
- newInline.width = textTools.widthOfString(newInline.text, newInline.font, newInline.fontSize, newInline.characterSpacing, newInline.fontFeatures);
1490
- inline.width = textTools.widthOfString(inline.text, inline.font, inline.fontSize, inline.characterSpacing, inline.fontFeatures);
1466
+ newInline.width = textTools.widthOfString(newInline.text, newInline.font, newInline.fontSize, newInline.characterSpacing);
1467
+ inline.width = textTools.widthOfString(inline.text, inline.font, inline.fontSize, inline.characterSpacing);
1491
1468
 
1492
1469
  textNode._inlines.unshift(newInline);
1493
- isHardWrap = true;
1494
1470
  }
1495
1471
  }
1496
1472
 
1497
1473
  line.addInline(inline);
1498
-
1499
- isForceContinue = inline.noNewLine && !isHardWrap;
1500
1474
  }
1501
1475
 
1502
1476
  line.lastLineInParagraph = textNode._inlines.length === 0;
@@ -241,6 +241,13 @@ PageElementWriter.prototype.endVerticalAlign = function (verticalAlign) {
241
241
 
242
242
  PageElementWriter.prototype.moveToNextPage = function (pageOrientation) {
243
243
 
244
+ var currentPage = this.writer.context.pages[this.writer.context.page];
245
+ this.writer.tracker.emit('beforePageChanged', {
246
+ prevPage: currentPage.prevPage,
247
+ prevY: currentPage.prevY,
248
+ y: currentPage.y
249
+ });
250
+
244
251
  var nextPage = this.writer.context.moveToNextPage(pageOrientation);
245
252
 
246
253
  // moveToNextPage is called multiple times for table, because is called for each column
@@ -177,6 +177,14 @@ TableProcessor.prototype.beginRow = function (rowIndex, writer) {
177
177
  this.rowPaddingBottom = this.layout.paddingBottom(rowIndex, this.tableNode);
178
178
 
179
179
  this.rowCallback = this.onRowBreak(rowIndex, writer);
180
+
181
+ if(this.tableNode.eventHandle && this.tableNode.eventHandle.beforePageChanged)
182
+ {
183
+
184
+ this.beforePageChanged = this.tableNode.eventHandle.beforePageChanged(this, rowIndex, writer);
185
+ writer.tracker.startTracking('beforePageChanged', this.beforePageChanged);
186
+ }
187
+
180
188
  writer.tracker.startTracking('pageChanged', this.rowCallback);
181
189
  if (rowIndex == 0 && !this.dontBreakRows && !this.rowsWithoutPageBreak) {
182
190
  // We store the 'y' to draw later and if necessary the top border of the table