pdfmake 0.2.19 → 0.2.20

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.19",
3
+ "version": "0.2.20",
4
4
  "description": "Client/server side PDF printing in pure JavaScript",
5
5
  "main": "src/printer.js",
6
6
  "browser": "build/pdfmake.js",
@@ -11,26 +11,26 @@
11
11
  "@foliojs-fork/linebreak": "^1.1.2",
12
12
  "@foliojs-fork/pdfkit": "^0.15.3",
13
13
  "iconv-lite": "^0.6.3",
14
- "xmldoc": "^2.0.0"
14
+ "xmldoc": "^2.0.1"
15
15
  },
16
16
  "devDependencies": {
17
- "@babel/cli": "^7.27.0",
18
- "@babel/core": "^7.26.10",
19
- "@babel/plugin-transform-modules-commonjs": "^7.26.3",
20
- "@babel/preset-env": "^7.26.9",
21
- "@eslint/js": "^9.25.1",
17
+ "@babel/cli": "^7.27.2",
18
+ "@babel/core": "^7.27.1",
19
+ "@babel/plugin-transform-modules-commonjs": "^7.27.1",
20
+ "@babel/preset-env": "^7.27.2",
21
+ "@eslint/js": "^9.26.0",
22
22
  "assert": "^2.1.0",
23
23
  "babel-loader": "^10.0.0",
24
24
  "brfs": "^2.0.2",
25
25
  "browserify-zlib": "^0.2.0",
26
26
  "buffer": "^6.0.3",
27
27
  "core-js": "3.19.0",
28
- "eslint": "^9.25.1",
28
+ "eslint": "^9.26.0",
29
29
  "eslint-plugin-jsdoc": "^50.6.11",
30
30
  "expose-loader": "^5.0.1",
31
31
  "file-saver": "^2.0.5",
32
- "globals": "^16.0.0",
33
- "mocha": "^11.1.0",
32
+ "globals": "^16.1.0",
33
+ "mocha": "^11.2.2",
34
34
  "npm-run-all": "^4.1.5",
35
35
  "process": "^0.11.10",
36
36
  "rewire": "^7.0.0",
@@ -43,7 +43,7 @@
43
43
  "terser-webpack-plugin": "^5.3.14",
44
44
  "transform-loader": "^0.2.4",
45
45
  "util": "^0.12.5",
46
- "webpack": "^5.99.7",
46
+ "webpack": "^5.99.8",
47
47
  "webpack-cli": "^6.0.1"
48
48
  },
49
49
  "engines": {
@@ -1043,6 +1043,27 @@ LayoutBuilder.prototype.buildNextLine = function (textNode) {
1043
1043
  return newInline;
1044
1044
  }
1045
1045
 
1046
+ function findMaxFitLength(text, maxWidth, measureFn) {
1047
+ let low = 1;
1048
+ let high = text.length;
1049
+ let bestFit = 1;
1050
+
1051
+ while (low <= high) {
1052
+ const mid = Math.floor((low + high) / 2);
1053
+ const part = text.substring(0, mid);
1054
+ const width = measureFn(part);
1055
+
1056
+ if (width <= maxWidth) {
1057
+ bestFit = mid;
1058
+ low = mid + 1;
1059
+ } else {
1060
+ high = mid - 1;
1061
+ }
1062
+ }
1063
+
1064
+ return bestFit;
1065
+ }
1066
+
1046
1067
  if (!textNode._inlines || textNode._inlines.length === 0) {
1047
1068
  return null;
1048
1069
  }
@@ -1058,11 +1079,9 @@ LayoutBuilder.prototype.buildNextLine = function (textNode) {
1058
1079
  isForceContinue = false;
1059
1080
 
1060
1081
  if (!inline.noWrap && inline.text.length > 1 && inline.width > line.getAvailableWidth()) {
1061
- var widthPerChar = inline.width / inline.text.length;
1062
- var maxChars = Math.floor(line.getAvailableWidth() / widthPerChar);
1063
- if (maxChars < 1) {
1064
- maxChars = 1;
1065
- }
1082
+ var maxChars = findMaxFitLength(inline.text, line.getAvailableWidth(), function (txt) {
1083
+ return textTools.widthOfString(txt, inline.font, inline.fontSize, inline.characterSpacing, inline.fontFeatures)
1084
+ });
1066
1085
  if (maxChars < inline.text.length) {
1067
1086
  var newInline = cloneInline(inline);
1068
1087