pdfkit 0.17.0 → 0.17.1
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/CHANGELOG.md +6 -0
- package/js/pdfkit.es.js +20 -18
- package/js/pdfkit.es.js.map +1 -1
- package/js/pdfkit.js +20 -18
- package/js/pdfkit.js.map +1 -1
- package/js/pdfkit.standalone.js +20 -18
- package/package.json +2 -2
- package/.git-blame-ignore-revs +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
### Unreleased
|
|
4
4
|
|
|
5
|
+
### [v0.17.1] - 2025-05-02
|
|
6
|
+
|
|
7
|
+
- Fix null values in table cells rendering as `[object Object]`
|
|
8
|
+
- Fix further LineWrapper precision issues
|
|
9
|
+
- Optmize standard font handling. Less code, less memory usage
|
|
10
|
+
|
|
5
11
|
### [v0.17.0] - 2025-04-12
|
|
6
12
|
|
|
7
13
|
- Fix precision rounding issues in LineWrapper
|
package/js/pdfkit.es.js
CHANGED
|
@@ -222,8 +222,18 @@ class PDFReference extends PDFAbstractReference {
|
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
const fArray = new Float32Array(1);
|
|
226
|
+
const uArray = new Uint32Array(fArray.buffer);
|
|
225
227
|
function PDFNumber(n) {
|
|
226
|
-
|
|
228
|
+
const rounded = Math.fround(n);
|
|
229
|
+
if (rounded <= n) return rounded;
|
|
230
|
+
fArray[0] = n;
|
|
231
|
+
if (n <= 0) {
|
|
232
|
+
uArray[0] += 1;
|
|
233
|
+
} else {
|
|
234
|
+
uArray[0] -= 1;
|
|
235
|
+
}
|
|
236
|
+
return fArray[0];
|
|
227
237
|
}
|
|
228
238
|
function normalizeSides(sides) {
|
|
229
239
|
let defaultDefinition = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
@@ -2155,20 +2165,12 @@ oslash ugrave uacute ucircumflex
|
|
|
2155
2165
|
udieresis yacute thorn ydieresis\
|
|
2156
2166
|
`.split(/\s+/);
|
|
2157
2167
|
class AFMFont {
|
|
2158
|
-
static open(filename) {
|
|
2159
|
-
return new AFMFont(fs.readFileSync(filename, 'utf8'));
|
|
2160
|
-
}
|
|
2161
2168
|
constructor(contents) {
|
|
2162
|
-
this.contents = contents;
|
|
2163
2169
|
this.attributes = {};
|
|
2164
2170
|
this.glyphWidths = {};
|
|
2165
2171
|
this.boundingBoxes = {};
|
|
2166
2172
|
this.kernPairs = {};
|
|
2167
|
-
this.parse();
|
|
2168
|
-
this.charWidths = new Array(256);
|
|
2169
|
-
for (let char = 0; char <= 255; char++) {
|
|
2170
|
-
this.charWidths[char] = this.glyphWidths[characters[char]];
|
|
2171
|
-
}
|
|
2173
|
+
this.parse(contents);
|
|
2172
2174
|
this.bbox = this.attributes['FontBBox'].split(/\s+/).map(e => +e);
|
|
2173
2175
|
this.ascender = +(this.attributes['Ascender'] || 0);
|
|
2174
2176
|
this.descender = +(this.attributes['Descender'] || 0);
|
|
@@ -2176,9 +2178,9 @@ class AFMFont {
|
|
|
2176
2178
|
this.capHeight = +(this.attributes['CapHeight'] || 0);
|
|
2177
2179
|
this.lineGap = this.bbox[3] - this.bbox[1] - (this.ascender - this.descender);
|
|
2178
2180
|
}
|
|
2179
|
-
parse() {
|
|
2181
|
+
parse(contents) {
|
|
2180
2182
|
let section = '';
|
|
2181
|
-
for (let line of
|
|
2183
|
+
for (let line of contents.split('\n')) {
|
|
2182
2184
|
var match;
|
|
2183
2185
|
var a;
|
|
2184
2186
|
if (match = line.match(/^Start(\w+)/)) {
|
|
@@ -2838,7 +2840,7 @@ class LineWrapper extends EventEmitter {
|
|
|
2838
2840
|
});
|
|
2839
2841
|
}
|
|
2840
2842
|
wordWidth(word) {
|
|
2841
|
-
return this.document.widthOfString(word, this) + this.characterSpacing + this.wordSpacing;
|
|
2843
|
+
return PDFNumber(this.document.widthOfString(word, this) + this.characterSpacing + this.wordSpacing);
|
|
2842
2844
|
}
|
|
2843
2845
|
canFit(word, w) {
|
|
2844
2846
|
if (word[word.length - 1] != SOFT_HYPHEN) {
|
|
@@ -3762,8 +3764,8 @@ class PDFImage {
|
|
|
3762
3764
|
} else if (src instanceof ArrayBuffer) {
|
|
3763
3765
|
data = Buffer.from(new Uint8Array(src));
|
|
3764
3766
|
} else {
|
|
3765
|
-
|
|
3766
|
-
if (match
|
|
3767
|
+
const match = /^data:.+?;base64,(.*)$/.exec(src);
|
|
3768
|
+
if (match) {
|
|
3767
3769
|
data = Buffer.from(match[1], 'base64');
|
|
3768
3770
|
} else {
|
|
3769
3771
|
data = fs.readFileSync(src);
|
|
@@ -4884,8 +4886,8 @@ var AttachmentsMixin = {
|
|
|
4884
4886
|
} else if (src instanceof ArrayBuffer) {
|
|
4885
4887
|
data = Buffer.from(new Uint8Array(src));
|
|
4886
4888
|
} else {
|
|
4887
|
-
|
|
4888
|
-
if (match
|
|
4889
|
+
const match = /^data:(.*?);base64,(.*)$/.exec(src);
|
|
4890
|
+
if (match) {
|
|
4889
4891
|
if (match[1]) {
|
|
4890
4892
|
refBody.Subtype = match[1].replace('/', '#2F');
|
|
4891
4893
|
}
|
|
@@ -5085,7 +5087,7 @@ function deepMerge(target) {
|
|
|
5085
5087
|
}
|
|
5086
5088
|
function deepClone(obj) {
|
|
5087
5089
|
let result = obj;
|
|
5088
|
-
if (typeof obj == 'object') {
|
|
5090
|
+
if (obj && typeof obj == 'object') {
|
|
5089
5091
|
result = Array.isArray(obj) ? [] : {};
|
|
5090
5092
|
for (const key in obj) result[key] = deepClone(obj[key]);
|
|
5091
5093
|
}
|