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/js/pdfkit.js
CHANGED
|
@@ -221,8 +221,18 @@ class PDFReference extends PDFAbstractReference {
|
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
const fArray = new Float32Array(1);
|
|
225
|
+
const uArray = new Uint32Array(fArray.buffer);
|
|
224
226
|
function PDFNumber(n) {
|
|
225
|
-
|
|
227
|
+
const rounded = Math.fround(n);
|
|
228
|
+
if (rounded <= n) return rounded;
|
|
229
|
+
fArray[0] = n;
|
|
230
|
+
if (n <= 0) {
|
|
231
|
+
uArray[0] += 1;
|
|
232
|
+
} else {
|
|
233
|
+
uArray[0] -= 1;
|
|
234
|
+
}
|
|
235
|
+
return fArray[0];
|
|
226
236
|
}
|
|
227
237
|
function normalizeSides(sides, defaultDefinition = undefined, transformer = v => v) {
|
|
228
238
|
if (sides == null || typeof sides === 'object' && Object.keys(sides).length === 0) {
|
|
@@ -2137,20 +2147,12 @@ oslash ugrave uacute ucircumflex
|
|
|
2137
2147
|
udieresis yacute thorn ydieresis\
|
|
2138
2148
|
`.split(/\s+/);
|
|
2139
2149
|
class AFMFont {
|
|
2140
|
-
static open(filename) {
|
|
2141
|
-
return new AFMFont(fs.readFileSync(filename, 'utf8'));
|
|
2142
|
-
}
|
|
2143
2150
|
constructor(contents) {
|
|
2144
|
-
this.contents = contents;
|
|
2145
2151
|
this.attributes = {};
|
|
2146
2152
|
this.glyphWidths = {};
|
|
2147
2153
|
this.boundingBoxes = {};
|
|
2148
2154
|
this.kernPairs = {};
|
|
2149
|
-
this.parse();
|
|
2150
|
-
this.charWidths = new Array(256);
|
|
2151
|
-
for (let char = 0; char <= 255; char++) {
|
|
2152
|
-
this.charWidths[char] = this.glyphWidths[characters[char]];
|
|
2153
|
-
}
|
|
2155
|
+
this.parse(contents);
|
|
2154
2156
|
this.bbox = this.attributes['FontBBox'].split(/\s+/).map(e => +e);
|
|
2155
2157
|
this.ascender = +(this.attributes['Ascender'] || 0);
|
|
2156
2158
|
this.descender = +(this.attributes['Descender'] || 0);
|
|
@@ -2158,9 +2160,9 @@ class AFMFont {
|
|
|
2158
2160
|
this.capHeight = +(this.attributes['CapHeight'] || 0);
|
|
2159
2161
|
this.lineGap = this.bbox[3] - this.bbox[1] - (this.ascender - this.descender);
|
|
2160
2162
|
}
|
|
2161
|
-
parse() {
|
|
2163
|
+
parse(contents) {
|
|
2162
2164
|
let section = '';
|
|
2163
|
-
for (let line of
|
|
2165
|
+
for (let line of contents.split('\n')) {
|
|
2164
2166
|
var match;
|
|
2165
2167
|
var a;
|
|
2166
2168
|
if (match = line.match(/^Start(\w+)/)) {
|
|
@@ -2813,7 +2815,7 @@ class LineWrapper extends events.EventEmitter {
|
|
|
2813
2815
|
});
|
|
2814
2816
|
}
|
|
2815
2817
|
wordWidth(word) {
|
|
2816
|
-
return this.document.widthOfString(word, this) + this.characterSpacing + this.wordSpacing;
|
|
2818
|
+
return PDFNumber(this.document.widthOfString(word, this) + this.characterSpacing + this.wordSpacing);
|
|
2817
2819
|
}
|
|
2818
2820
|
canFit(word, w) {
|
|
2819
2821
|
if (word[word.length - 1] != SOFT_HYPHEN) {
|
|
@@ -3731,8 +3733,8 @@ class PDFImage {
|
|
|
3731
3733
|
} else if (src instanceof ArrayBuffer) {
|
|
3732
3734
|
data = Buffer.from(new Uint8Array(src));
|
|
3733
3735
|
} else {
|
|
3734
|
-
|
|
3735
|
-
if (match
|
|
3736
|
+
const match = /^data:.+?;base64,(.*)$/.exec(src);
|
|
3737
|
+
if (match) {
|
|
3736
3738
|
data = Buffer.from(match[1], 'base64');
|
|
3737
3739
|
} else {
|
|
3738
3740
|
data = fs.readFileSync(src);
|
|
@@ -4819,8 +4821,8 @@ var AttachmentsMixin = {
|
|
|
4819
4821
|
} else if (src instanceof ArrayBuffer) {
|
|
4820
4822
|
data = Buffer.from(new Uint8Array(src));
|
|
4821
4823
|
} else {
|
|
4822
|
-
|
|
4823
|
-
if (match
|
|
4824
|
+
const match = /^data:(.*?);base64,(.*)$/.exec(src);
|
|
4825
|
+
if (match) {
|
|
4824
4826
|
if (match[1]) {
|
|
4825
4827
|
refBody.Subtype = match[1].replace('/', '#2F');
|
|
4826
4828
|
}
|
|
@@ -5017,7 +5019,7 @@ function deepMerge(target, ...sources) {
|
|
|
5017
5019
|
}
|
|
5018
5020
|
function deepClone(obj) {
|
|
5019
5021
|
let result = obj;
|
|
5020
|
-
if (typeof obj == 'object') {
|
|
5022
|
+
if (obj && typeof obj == 'object') {
|
|
5021
5023
|
result = Array.isArray(obj) ? [] : {};
|
|
5022
5024
|
for (const key in obj) result[key] = deepClone(obj[key]);
|
|
5023
5025
|
}
|