pdfkit 0.19.1 → 0.20.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/.yarn/install-state.gz +0 -0
- package/CHANGELOG.md +25 -0
- package/README.md +97 -25
- package/js/output.cjs +53 -0
- package/js/output.mjs +50 -0
- package/js/pdfkit.browser.js +7524 -0
- package/js/pdfkit.browser.js.map +1 -0
- package/js/pdfkit.browser.mjs +7344 -0
- package/js/pdfkit.browser.mjs.map +1 -0
- package/js/pdfkit.browser.old.js +7517 -0
- package/js/pdfkit.browser.old.mjs +7342 -0
- package/js/pdfkit.js +1419 -487
- package/js/pdfkit.js.map +1 -1
- package/js/{pdfkit.es.js → pdfkit.node.mjs} +1410 -488
- package/js/pdfkit.node.mjs.map +1 -0
- package/js/pdfkit.old.js +7276 -0
- package/js/pdfkit.standalone.js +23432 -35943
- package/js/standard-fonts/Courier.cjs +17 -0
- package/js/standard-fonts/Courier.mjs +15 -0
- package/js/standard-fonts/CourierBold.cjs +17 -0
- package/js/standard-fonts/CourierBold.mjs +15 -0
- package/js/standard-fonts/CourierBoldOblique.cjs +17 -0
- package/js/standard-fonts/CourierBoldOblique.mjs +15 -0
- package/js/standard-fonts/CourierOblique.cjs +17 -0
- package/js/standard-fonts/CourierOblique.mjs +15 -0
- package/js/standard-fonts/Helvetica.cjs +17 -0
- package/js/standard-fonts/Helvetica.mjs +15 -0
- package/js/standard-fonts/HelveticaBold.cjs +17 -0
- package/js/standard-fonts/HelveticaBold.mjs +15 -0
- package/js/standard-fonts/HelveticaBoldOblique.cjs +17 -0
- package/js/standard-fonts/HelveticaBoldOblique.mjs +15 -0
- package/js/standard-fonts/HelveticaOblique.cjs +17 -0
- package/js/standard-fonts/HelveticaOblique.mjs +15 -0
- package/js/standard-fonts/Symbol.cjs +15 -0
- package/js/standard-fonts/Symbol.mjs +13 -0
- package/js/standard-fonts/TimesBold.cjs +17 -0
- package/js/standard-fonts/TimesBold.mjs +15 -0
- package/js/standard-fonts/TimesBoldItalic.cjs +17 -0
- package/js/standard-fonts/TimesBoldItalic.mjs +15 -0
- package/js/standard-fonts/TimesItalic.cjs +17 -0
- package/js/standard-fonts/TimesItalic.mjs +15 -0
- package/js/standard-fonts/TimesRoman.cjs +17 -0
- package/js/standard-fonts/TimesRoman.mjs +15 -0
- package/js/standard-fonts/ZapfDingbats.cjs +15 -0
- package/js/standard-fonts/ZapfDingbats.mjs +13 -0
- package/js/standard-fonts/chunks/standardGlyphNames-DNHAb7rp.cjs +5 -0
- package/js/standard-fonts/chunks/standardGlyphNames-w3QlG7PW.mjs +3 -0
- package/package.json +110 -28
- package/rollup.config.mjs +126 -57
- package/tools/README.md +124 -0
- package/tools/afm-converter.js +317 -0
- package/tools/asset-plugin.mjs +17 -0
- package/tools/binary-plugin.mjs +18 -0
- package/tools/convert-afm-parsed.js +8 -0
- package/tools/convert-afm-runtime.js +8 -0
- package/vitest.config.js +2 -0
- package/js/pdfkit.es.js.map +0 -1
- package/js/virtual-fs.js +0 -49
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { g as glyphNames } from './chunks/standardGlyphNames-w3QlG7PW.mjs';
|
|
2
|
+
|
|
3
|
+
var TimesRoman = {
|
|
4
|
+
name: 'Times-Roman',
|
|
5
|
+
bbox: [-168, -218, 1000, 898],
|
|
6
|
+
ascender: 683,
|
|
7
|
+
descender: -217,
|
|
8
|
+
xHeight: 450,
|
|
9
|
+
capHeight: 662,
|
|
10
|
+
glyphNames,
|
|
11
|
+
glyphWidths: [250, 333, 408, 500, 500, 833, 778, 180, 333, 333, 500, 564, 250, 333, 250, 278, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 278, 278, 564, 564, 564, 444, 921, 722, 667, 667, 722, 611, 556, 722, 722, 333, 389, 722, 611, 889, 722, 722, 556, 722, 667, 556, 611, 722, 722, 944, 722, 722, 611, 333, 278, 333, 469, 500, 333, 444, 500, 444, 500, 444, 333, 500, 500, 278, 278, 500, 278, 778, 500, 500, 500, 500, 333, 389, 278, 500, 500, 722, 500, 500, 444, 480, 200, 480, 541, 500, 333, 500, 444, 1000, 500, 500, 333, 1000, 556, 333, 889, 611, 333, 333, 444, 444, 350, 500, 1000, 333, 980, 389, 333, 722, 444, 500, 333, 500, 500, 500, 500, 200, 500, 333, 760, 276, 500, 564, 760, 333, 400, 564, 300, 300, 333, 500, 453, 250, 333, 300, 310, 500, 750, 750, 750, 444, 722, 722, 722, 722, 722, 722, 889, 667, 611, 611, 611, 611, 333, 333, 333, 333, 722, 722, 722, 722, 722, 722, 722, 564, 722, 722, 722, 722, 722, 722, 556, 500, 444, 444, 444, 444, 444, 444, 667, 444, 444, 444, 444, 444, 278, 278, 278, 278, 500, 500, 500, 500, 500, 500, 500, 564, 500, 500, 500, 500, 500, 500, 500],
|
|
12
|
+
kernPairs: [-135, [7149, 4494, 119, 1, 1, 1, 1, 1, 20967, 215, 215, 215, 215, 215], -129, [11622, 2, 65, 124, 1, 4, 449, 2, 26658, 2], -120, [11858, 119, 1, 1, 1, 1, 1, 306, 119, 1, 1, 1, 1, 1, 26536, 119, 1, 1, 1, 1, 1], -111, [7147, 57, 3128, 2, 1341, 4, 116, 4, 4, 465, 72, 125, 1, 20266, 57, 158, 57, 158, 57, 158, 57, 158, 57, 158, 57, 5064, 72, 125, 1], -110, [12334, 124, 1, 4, 26531, 124, 1, 4], -105, [7152, 124, 25461, 124, 91, 124, 91, 124, 91, 124, 91, 124, 91, 124], -100, [9514, 3, 124, 1982, 697, 4, 116, 1, 3, 4, 1, 26531, 4, 116, 1, 3, 4, 1], -93, [11213, 119, 1, 1, 1, 1, 1], -92, [7182, 2, 32, 92, 2204, 57, 784, 119, 1, 1, 1, 1, 1, 716, 644, 2, 442, 1, 20485, 2, 32, 92, 89, 2, 32, 92, 89, 2, 32, 92, 89, 2, 32, 92, 89, 2, 32, 92, 89, 2, 32, 92, 4973, 1], -90, [57, 124, 6969, 25585, 215, 215, 215, 215, 215], -89, [11812, 3, 1], -80, [8182, 2, 2620, 441, 14, 8, 2, 32, 64, 1, 3, 13, 1, 1, 1, 1, 2, 5, 497, 4, 10, 105, 1, 1, 1, 1, 1, 4, 1, 8, 1, 1, 1, 1, 2, 11220, 119, 1, 1, 1, 1, 1, 306, 119, 1, 1, 1, 1, 1], -75, [11695, 124, 1, 1, 1], -74, [7181, 1022, 119, 1, 1, 1, 1, 1, 1188, 1677, 2, 442, 1, 11691, 107, 109, 9222, 215, 215, 215, 215, 215], -73, [11914, 32, 92], -71, [11794, 2, 1, 1, 4, 2, 1, 659, 3, 26657, 3], -70, [2689, 2, 428, 2, 8128, 123, 1, 1, 1083, 3, 1, 26656, 3, 1], -65, [10807, 124, 907, 6664, 2, 213, 2, 428, 2, 6878, 2, 19778, 2], -60, [9063, 119, 1, 1, 1, 1, 1, 1615, 881, 124, 632, 3, 1, 4, 3, 26649, 3, 1, 4, 3], -55, [33, 119, 1, 1, 1, 1, 1, 6985, 2, 4, 117, 1, 1, 1, 1, 2, 1, 1, 1, 1, 522, 124, 1628, 32, 92, 1132, 402, 1121, 124, 5192, 5874, 34, 9175, 2, 4, 117, 1, 1, 1, 1, 2, 1, 1, 1, 1, 82, 2, 4, 117, 1, 1, 1, 1, 2, 1, 1, 1, 1, 82, 2, 4, 117, 1, 1, 1, 1, 2, 1, 1, 1, 1, 82, 2, 4, 117, 1, 1, 1, 1, 2, 1, 1, 1, 1, 82, 2, 4, 117, 1, 1, 1, 1, 2, 1, 1, 1, 1, 82, 2, 4, 117, 1, 1, 1, 1, 2, 1, 1, 1, 1, 5053, 124], -50, [54, 10105, 3, 124, 920, 704, 124, 1, 1, 1, 11466, 14, 4, 13083, 3, 124, 88, 3, 124, 88, 3, 124, 88, 3, 124, 88, 3, 124, 303, 3, 124], -45, [11265, 124, 1, 1, 1], -40, [7130, 4, 120, 519, 21, 98, 1, 1, 1, 1, 1, 2260, 4, 636, 6, 117, 1, 1, 1, 1, 2, 1, 1, 1, 1, 434, 3, 1, 60, 119, 1, 1, 1, 1, 1, 105, 123, 1, 1, 1, 1, 2, 112, 119, 3, 2, 2182, 2652, 786, 15073, 4, 120, 91, 4, 120, 91, 4, 120, 91, 4, 120, 91, 4, 120, 91, 4, 120, 2688, 4, 211, 4, 211, 4, 211, 4, 211, 4, 426, 4, 192, 119, 1, 1, 1, 1, 1, 91, 119, 1, 1, 1, 1, 1, 91, 119, 1, 1, 1, 1, 1, 91, 119, 1, 1, 1, 1, 1, 4444], -37, [11851, 1], -35, [7343, 119, 1, 1, 1, 1, 1, 1857, 123, 1, 1, 1, 1, 2, 470, 119, 1, 1, 1, 1, 1, 91, 22, 97, 1, 1, 1, 1, 1, 991, 9, 115, 24991, 119, 1, 1, 1, 1, 1, 91, 22, 97, 1, 1, 1, 1, 1, 91, 22, 97, 1, 1, 1, 1, 1, 91, 22, 97, 1, 1, 1, 1, 1, 91, 22, 97, 1, 1, 1, 1, 1, 91, 22, 97, 1, 1, 1, 1, 1, 306, 22, 97, 1, 1, 1, 1, 1], -30, [55, 7740, 1497, 123, 1, 1, 1, 1, 2, 1954, 927, 123, 1, 1, 1, 1, 2, 26531, 123, 1, 1, 1, 1, 2], -25, [9314, 20, 32, 71, 1, 1, 1, 18, 5463, 1, 198, 661, 1291, 1483, 119, 1, 1, 1, 1, 1, 22687, 1, 214, 1, 214, 1, 214, 1, 214, 215, 215, 215, 646, 215, 215, 215, 215, 430], -20, [11806, 2, 1, 2252, 214, 124, 1, 1, 1, 721, 124, 2396, 926, 123, 1, 1, 1, 1, 2, 20948, 215, 215, 215, 215, 215], -18, [52, 11175, 123, 1, 1, 1, 1, 2, 6345, 5818], -15, [8235, 14, 105, 1, 1, 1, 1, 1, 13, 1, 1, 1, 1, 2, 952, 124, 1, 1, 1, 928, 119, 1, 1, 1, 1, 1, 1140, 2413, 214, 218, 32, 92, 288, 17, 1, 32, 92, 1166, 32, 92, 521, 32, 92, 88, 1488, 123, 1, 1, 1, 304, 123, 1, 1, 1, 20532, 215, 215, 215, 215, 215, 432, 32, 92, 73, 17, 1, 32, 92, 73, 17, 1, 32, 92, 73, 17, 1, 32, 92, 73, 17, 1, 32, 92, 1166, 32, 92, 88, 215, 215, 215, 215, 430], -10, [7363, 124, 1, 1, 1, 3098, 124, 1, 1, 1, 1157, 123, 1, 1, 1, 1, 2, 3114, 119, 1, 1, 1, 1, 1, 955, 10, 113, 1, 1, 1, 7, 1, 1, 1, 1, 2, 94, 647, 32, 92, 91, 32, 92, 1357, 14, 105, 1, 1, 1, 1, 1, 13, 1, 1, 1, 1, 2, 4598, 20008, 32, 92, 91, 32, 92, 91, 32, 92, 91, 32, 92, 91, 32, 92, 306, 32, 92], -5, [15330, 119, 1, 1, 1, 1, 1, 115, 32, 92], 55, [15159]]
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { TimesRoman as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZapfDingbats = {
|
|
4
|
+
name: 'ZapfDingbats',
|
|
5
|
+
bbox: [-1, -143, 981, 820],
|
|
6
|
+
ascender: 0,
|
|
7
|
+
descender: 0,
|
|
8
|
+
xHeight: 0,
|
|
9
|
+
capHeight: 0,
|
|
10
|
+
glyphNames: 'space',
|
|
11
|
+
glyphWidths: [278],
|
|
12
|
+
kernPairs: []
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
module.exports = ZapfDingbats;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var glyphNames = 'space exclam quotedbl numbersign dollar percent ampersand quotesingle parenleft parenright asterisk plus comma hyphen period slash zero one two three four five six seven eight nine colon semicolon less equal greater question at A B C D E F G H I J K L M N O P Q R S T U V W X Y Z bracketleft backslash bracketright asciicircum underscore grave a b c d e f g h i j k l m n o p q r s t u v w x y z braceleft bar braceright asciitilde Euro quotesinglbase florin quotedblbase ellipsis dagger daggerdbl circumflex perthousand Scaron guilsinglleft OE Zcaron quoteleft quoteright quotedblleft quotedblright bullet endash emdash tilde trademark scaron guilsinglright oe zcaron ydieresis exclamdown cent sterling currency yen brokenbar section dieresis copyright ordfeminine guillemotleft logicalnot registered macron degree plusminus twosuperior threesuperior acute mu paragraph periodcentered cedilla onesuperior ordmasculine guillemotright onequarter onehalf threequarters questiondown Agrave Aacute Acircumflex Atilde Adieresis Aring AE Ccedilla Egrave Eacute Ecircumflex Edieresis Igrave Iacute Icircumflex Idieresis Eth Ntilde Ograve Oacute Ocircumflex Otilde Odieresis multiply Oslash Ugrave Uacute Ucircumflex Udieresis Yacute Thorn germandbls agrave aacute acircumflex atilde adieresis aring ae ccedilla egrave eacute ecircumflex edieresis igrave iacute icircumflex idieresis eth ntilde ograve oacute ocircumflex otilde odieresis divide oslash ugrave uacute ucircumflex udieresis yacute thorn';
|
|
4
|
+
|
|
5
|
+
exports.glyphNames = glyphNames;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var glyphNames = 'space exclam quotedbl numbersign dollar percent ampersand quotesingle parenleft parenright asterisk plus comma hyphen period slash zero one two three four five six seven eight nine colon semicolon less equal greater question at A B C D E F G H I J K L M N O P Q R S T U V W X Y Z bracketleft backslash bracketright asciicircum underscore grave a b c d e f g h i j k l m n o p q r s t u v w x y z braceleft bar braceright asciitilde Euro quotesinglbase florin quotedblbase ellipsis dagger daggerdbl circumflex perthousand Scaron guilsinglleft OE Zcaron quoteleft quoteright quotedblleft quotedblright bullet endash emdash tilde trademark scaron guilsinglright oe zcaron ydieresis exclamdown cent sterling currency yen brokenbar section dieresis copyright ordfeminine guillemotleft logicalnot registered macron degree plusminus twosuperior threesuperior acute mu paragraph periodcentered cedilla onesuperior ordmasculine guillemotright onequarter onehalf threequarters questiondown Agrave Aacute Acircumflex Atilde Adieresis Aring AE Ccedilla Egrave Eacute Ecircumflex Edieresis Igrave Iacute Icircumflex Idieresis Eth Ntilde Ograve Oacute Ocircumflex Otilde Odieresis multiply Oslash Ugrave Uacute Ucircumflex Udieresis Yacute Thorn germandbls agrave aacute acircumflex atilde adieresis aring ae ccedilla egrave eacute ecircumflex edieresis igrave iacute icircumflex idieresis eth ntilde ograve oacute ocircumflex otilde odieresis divide oslash ugrave uacute ucircumflex udieresis yacute thorn';
|
|
2
|
+
|
|
3
|
+
export { glyphNames as g };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdfkit",
|
|
3
|
-
"description": "A PDF generation library
|
|
3
|
+
"description": "A JavaScript PDF generation library",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"pdf",
|
|
6
6
|
"pdf writer",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"document",
|
|
10
10
|
"vector"
|
|
11
11
|
],
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.20.1",
|
|
13
13
|
"homepage": "http://pdfkit.org/",
|
|
14
14
|
"author": {
|
|
15
15
|
"name": "Devon Govett",
|
|
@@ -23,59 +23,141 @@
|
|
|
23
23
|
},
|
|
24
24
|
"bugs": "https://github.com/foliojs/pdfkit/issues",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@babel/core": "^
|
|
27
|
-
"@babel/plugin-external-helpers": "^
|
|
28
|
-
"@babel/preset-env": "^
|
|
26
|
+
"@babel/core": "^8.0.1",
|
|
27
|
+
"@babel/plugin-external-helpers": "^8.0.1",
|
|
28
|
+
"@babel/preset-env": "^8.0.2",
|
|
29
29
|
"@eslint/js": "^10.0.1",
|
|
30
30
|
"@rollup/plugin-babel": "^7.1.0",
|
|
31
|
-
"
|
|
31
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
32
32
|
"brace": "^0.11.1",
|
|
33
|
-
"brfs": "~2.0.2",
|
|
34
33
|
"browserify": "^17.0.1",
|
|
35
34
|
"canvas": "^3.2.3",
|
|
36
35
|
"codemirror": "~5.65.21",
|
|
37
|
-
"eslint": "^10.
|
|
36
|
+
"eslint": "^10.8.1",
|
|
38
37
|
"gh-pages": "^6.3.0",
|
|
39
|
-
"globals": "^17.
|
|
38
|
+
"globals": "^17.11.0",
|
|
40
39
|
"jest-diff": "^30.4.1",
|
|
41
40
|
"jest-image-snapshot": "^6.5.2",
|
|
42
41
|
"markdown": "~0.5.0",
|
|
43
42
|
"pdfjs-dist": "^5.7.284",
|
|
44
|
-
"prettier": "3.
|
|
43
|
+
"prettier": "3.9.6",
|
|
45
44
|
"pug": "^3.0.4",
|
|
46
|
-
"rollup": "^4.
|
|
47
|
-
"
|
|
48
|
-
"vitest": "^4.1.
|
|
45
|
+
"rollup": "^4.62.4",
|
|
46
|
+
"sharp": "^0.35.3",
|
|
47
|
+
"vitest": "^4.1.10"
|
|
49
48
|
},
|
|
50
49
|
"dependencies": {
|
|
51
|
-
"@noble/ciphers": "^1.
|
|
52
|
-
"@noble/hashes": "^1.
|
|
50
|
+
"@noble/ciphers": "^1.3.0",
|
|
51
|
+
"@noble/hashes": "^1.8.0",
|
|
52
|
+
"fflate": "^0.8.3",
|
|
53
53
|
"fontkit": "^2.0.4",
|
|
54
|
-
"js-md5": "^0.8.3",
|
|
55
54
|
"linebreak": "^1.1.0",
|
|
56
|
-
"png-js": "^
|
|
55
|
+
"png-js": "^2.0.0"
|
|
57
56
|
},
|
|
58
57
|
"scripts": {
|
|
59
58
|
"prepublishOnly": "npm run build",
|
|
60
|
-
"build": "rollup -c
|
|
61
|
-
"build-standalone": "browserify --standalone PDFDocument --ignore crypto js/pdfkit.js
|
|
59
|
+
"build": "rollup -c",
|
|
60
|
+
"build-standalone": "browserify --standalone PDFDocument --ignore crypto js/pdfkit.browser.js -o js/pdfkit.standalone.js",
|
|
62
61
|
"browserify-example": "browserify examples/browserify/browser.js > examples/browserify/bundle.js",
|
|
63
62
|
"pdf-guide": "node docs/generate.js",
|
|
64
63
|
"website": "node docs/generate_website.js",
|
|
65
64
|
"publish-website": "node docs/publish_website.js",
|
|
66
65
|
"docs": "npm run pdf-guide && npm run website && npm run browserify-example",
|
|
67
|
-
"lint": "eslint {lib,tests}/**/*.js",
|
|
68
|
-
"prettier": "prettier --check lib tests docs",
|
|
69
|
-
"
|
|
66
|
+
"lint": "eslint {lib,tests,tools}/**/*.js",
|
|
67
|
+
"prettier": "prettier --check lib tests docs tools",
|
|
68
|
+
"format": "prettier --write lib tests docs tools",
|
|
69
|
+
"test": "vitest --testTimeout 8000 run --exclude \"tests/tools/**\"",
|
|
70
|
+
"test:package": "node tests/package-resolution.cjs && node tests/package-resolution.mjs",
|
|
71
|
+
"test:tools": "vitest --testTimeout 8000 run tests/tools",
|
|
70
72
|
"test:visual": "vitest --testTimeout 8000 run tests/visual",
|
|
71
73
|
"test:unit": "vitest run tests/unit"
|
|
72
74
|
},
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
"exports": {
|
|
76
|
+
".": {
|
|
77
|
+
"node": {
|
|
78
|
+
"import": "./js/pdfkit.node.mjs",
|
|
79
|
+
"require": "./js/pdfkit.js"
|
|
80
|
+
},
|
|
81
|
+
"default": "./js/pdfkit.browser.mjs"
|
|
82
|
+
},
|
|
83
|
+
"./output": {
|
|
84
|
+
"require": "./js/output.cjs",
|
|
85
|
+
"default": "./js/output.mjs"
|
|
86
|
+
},
|
|
87
|
+
"./standard-fonts/Courier": {
|
|
88
|
+
"require": "./js/standard-fonts/Courier.cjs",
|
|
89
|
+
"default": "./js/standard-fonts/Courier.mjs"
|
|
90
|
+
},
|
|
91
|
+
"./standard-fonts/CourierBold": {
|
|
92
|
+
"require": "./js/standard-fonts/CourierBold.cjs",
|
|
93
|
+
"default": "./js/standard-fonts/CourierBold.mjs"
|
|
94
|
+
},
|
|
95
|
+
"./standard-fonts/CourierBoldOblique": {
|
|
96
|
+
"require": "./js/standard-fonts/CourierBoldOblique.cjs",
|
|
97
|
+
"default": "./js/standard-fonts/CourierBoldOblique.mjs"
|
|
98
|
+
},
|
|
99
|
+
"./standard-fonts/CourierOblique": {
|
|
100
|
+
"require": "./js/standard-fonts/CourierOblique.cjs",
|
|
101
|
+
"default": "./js/standard-fonts/CourierOblique.mjs"
|
|
102
|
+
},
|
|
103
|
+
"./standard-fonts/Helvetica": {
|
|
104
|
+
"require": "./js/standard-fonts/Helvetica.cjs",
|
|
105
|
+
"default": "./js/standard-fonts/Helvetica.mjs"
|
|
106
|
+
},
|
|
107
|
+
"./standard-fonts/HelveticaBold": {
|
|
108
|
+
"require": "./js/standard-fonts/HelveticaBold.cjs",
|
|
109
|
+
"default": "./js/standard-fonts/HelveticaBold.mjs"
|
|
110
|
+
},
|
|
111
|
+
"./standard-fonts/HelveticaBoldOblique": {
|
|
112
|
+
"require": "./js/standard-fonts/HelveticaBoldOblique.cjs",
|
|
113
|
+
"default": "./js/standard-fonts/HelveticaBoldOblique.mjs"
|
|
114
|
+
},
|
|
115
|
+
"./standard-fonts/HelveticaOblique": {
|
|
116
|
+
"require": "./js/standard-fonts/HelveticaOblique.cjs",
|
|
117
|
+
"default": "./js/standard-fonts/HelveticaOblique.mjs"
|
|
118
|
+
},
|
|
119
|
+
"./standard-fonts/Symbol": {
|
|
120
|
+
"require": "./js/standard-fonts/Symbol.cjs",
|
|
121
|
+
"default": "./js/standard-fonts/Symbol.mjs"
|
|
122
|
+
},
|
|
123
|
+
"./standard-fonts/TimesBold": {
|
|
124
|
+
"require": "./js/standard-fonts/TimesBold.cjs",
|
|
125
|
+
"default": "./js/standard-fonts/TimesBold.mjs"
|
|
126
|
+
},
|
|
127
|
+
"./standard-fonts/TimesBoldItalic": {
|
|
128
|
+
"require": "./js/standard-fonts/TimesBoldItalic.cjs",
|
|
129
|
+
"default": "./js/standard-fonts/TimesBoldItalic.mjs"
|
|
130
|
+
},
|
|
131
|
+
"./standard-fonts/TimesItalic": {
|
|
132
|
+
"require": "./js/standard-fonts/TimesItalic.cjs",
|
|
133
|
+
"default": "./js/standard-fonts/TimesItalic.mjs"
|
|
134
|
+
},
|
|
135
|
+
"./standard-fonts/TimesRoman": {
|
|
136
|
+
"require": "./js/standard-fonts/TimesRoman.cjs",
|
|
137
|
+
"default": "./js/standard-fonts/TimesRoman.mjs"
|
|
138
|
+
},
|
|
139
|
+
"./standard-fonts/ZapfDingbats": {
|
|
140
|
+
"require": "./js/standard-fonts/ZapfDingbats.cjs",
|
|
141
|
+
"default": "./js/standard-fonts/ZapfDingbats.mjs"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
"imports": {
|
|
145
|
+
"#fs": {
|
|
146
|
+
"node": "./lib/fs/node.js",
|
|
147
|
+
"default": "./lib/fs/browser.js"
|
|
148
|
+
},
|
|
149
|
+
"#zlib": {
|
|
150
|
+
"node": "./lib/zlib/node.js",
|
|
151
|
+
"default": "./lib/zlib/browser.js"
|
|
152
|
+
},
|
|
153
|
+
"#stream": {
|
|
154
|
+
"node": "./lib/stream/node.js",
|
|
155
|
+
"default": "./lib/stream/browser.js"
|
|
156
|
+
},
|
|
157
|
+
"#standard-fonts/*": {
|
|
158
|
+
"require": "./js/standard-fonts/*.cjs",
|
|
159
|
+
"default": "./js/standard-fonts/*.mjs"
|
|
160
|
+
}
|
|
79
161
|
},
|
|
80
162
|
"engine": [
|
|
81
163
|
"node >= v20.0.0"
|
package/rollup.config.mjs
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import pkg from './package.json' with { type: 'json' };
|
|
2
1
|
import { babel } from '@rollup/plugin-babel';
|
|
3
|
-
import
|
|
2
|
+
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
3
|
+
import asset from './tools/asset-plugin.mjs';
|
|
4
|
+
import binary from './tools/binary-plugin.mjs';
|
|
5
|
+
|
|
6
|
+
const iccProfilePath = 'lib/mixins/data/sRGB_IEC61966_2_1.icc';
|
|
4
7
|
|
|
5
8
|
const external = [
|
|
9
|
+
'module',
|
|
6
10
|
'stream',
|
|
7
11
|
'fs',
|
|
8
12
|
'zlib',
|
|
13
|
+
'fflate',
|
|
9
14
|
'fontkit',
|
|
10
15
|
'events',
|
|
11
16
|
'linebreak',
|
|
@@ -24,20 +29,80 @@ const supportedBrowsers = [
|
|
|
24
29
|
'Safari 16', // from 2022
|
|
25
30
|
];
|
|
26
31
|
|
|
32
|
+
const standardFontInputs = {
|
|
33
|
+
Courier: 'lib/font/generated/Courier.js',
|
|
34
|
+
CourierBold: 'lib/font/generated/CourierBold.js',
|
|
35
|
+
CourierBoldOblique: 'lib/font/generated/CourierBoldOblique.js',
|
|
36
|
+
CourierOblique: 'lib/font/generated/CourierOblique.js',
|
|
37
|
+
Helvetica: 'lib/font/generated/Helvetica.js',
|
|
38
|
+
HelveticaBold: 'lib/font/generated/HelveticaBold.js',
|
|
39
|
+
HelveticaBoldOblique: 'lib/font/generated/HelveticaBoldOblique.js',
|
|
40
|
+
HelveticaOblique: 'lib/font/generated/HelveticaOblique.js',
|
|
41
|
+
Symbol: 'lib/font/generated/Symbol.js',
|
|
42
|
+
TimesBold: 'lib/font/generated/TimesBold.js',
|
|
43
|
+
TimesBoldItalic: 'lib/font/generated/TimesBoldItalic.js',
|
|
44
|
+
TimesItalic: 'lib/font/generated/TimesItalic.js',
|
|
45
|
+
TimesRoman: 'lib/font/generated/TimesRoman.js',
|
|
46
|
+
ZapfDingbats: 'lib/font/generated/ZapfDingbats.js',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const browserPlugins = () => [
|
|
50
|
+
binary('.icc'),
|
|
51
|
+
nodeResolve({
|
|
52
|
+
exportConditions: ['default'],
|
|
53
|
+
}),
|
|
54
|
+
babel({
|
|
55
|
+
babelHelpers: 'bundled',
|
|
56
|
+
babelrc: false,
|
|
57
|
+
targets: {
|
|
58
|
+
browsers: supportedBrowsers,
|
|
59
|
+
},
|
|
60
|
+
presets: [
|
|
61
|
+
[
|
|
62
|
+
'@babel/preset-env',
|
|
63
|
+
{
|
|
64
|
+
modules: false,
|
|
65
|
+
targets: {
|
|
66
|
+
browsers: supportedBrowsers,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
],
|
|
71
|
+
comments: false,
|
|
72
|
+
}),
|
|
73
|
+
];
|
|
74
|
+
|
|
27
75
|
export default [
|
|
28
|
-
// CommonJS
|
|
76
|
+
// CommonJS and ES builds for Node
|
|
29
77
|
{
|
|
30
|
-
input: 'lib/document.js',
|
|
78
|
+
input: 'lib/document.node.js',
|
|
31
79
|
external,
|
|
32
|
-
output:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
80
|
+
output: [
|
|
81
|
+
{
|
|
82
|
+
name: 'pdfkit',
|
|
83
|
+
file: 'js/pdfkit.js',
|
|
84
|
+
format: 'cjs',
|
|
85
|
+
sourcemap: true,
|
|
86
|
+
interop: 'default',
|
|
87
|
+
exports: 'named',
|
|
88
|
+
footer:
|
|
89
|
+
'module.exports = exports.default;\nmodule.exports.PDFDocument = exports.PDFDocument;\nmodule.exports.LineWrapper = exports.LineWrapper;\nmodule.exports.registerFile = exports.registerFile;',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
file: 'js/pdfkit.node.mjs',
|
|
93
|
+
format: 'es',
|
|
94
|
+
sourcemap: true,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
39
97
|
plugins: [
|
|
98
|
+
asset(iccProfilePath, 'data/sRGB_IEC61966_2_1.icc'),
|
|
99
|
+
nodeResolve({
|
|
100
|
+
exportConditions: ['node'],
|
|
101
|
+
}),
|
|
40
102
|
babel({
|
|
103
|
+
targets: {
|
|
104
|
+
node: '20',
|
|
105
|
+
},
|
|
41
106
|
babelHelpers: 'bundled',
|
|
42
107
|
babelrc: false,
|
|
43
108
|
presets: [
|
|
@@ -53,71 +118,75 @@ export default [
|
|
|
53
118
|
],
|
|
54
119
|
comments: false,
|
|
55
120
|
}),
|
|
56
|
-
copy({
|
|
57
|
-
targets: [
|
|
58
|
-
{
|
|
59
|
-
src: ['lib/font/data/*.afm', 'lib/mixins/data/*.icc'],
|
|
60
|
-
dest: 'js/data',
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
}),
|
|
64
121
|
],
|
|
65
122
|
},
|
|
66
123
|
// ES for green browsers
|
|
67
124
|
{
|
|
68
|
-
input: 'lib/document.js',
|
|
125
|
+
input: 'lib/document.browser.js',
|
|
69
126
|
external,
|
|
70
127
|
output: {
|
|
71
128
|
name: 'pdfkit.es',
|
|
72
|
-
file:
|
|
129
|
+
file: 'js/pdfkit.browser.mjs',
|
|
73
130
|
format: 'es',
|
|
74
131
|
sourcemap: true,
|
|
75
132
|
},
|
|
76
|
-
plugins:
|
|
77
|
-
babel({
|
|
78
|
-
babelHelpers: 'bundled',
|
|
79
|
-
babelrc: false,
|
|
80
|
-
presets: [
|
|
81
|
-
[
|
|
82
|
-
'@babel/preset-env',
|
|
83
|
-
{
|
|
84
|
-
modules: false,
|
|
85
|
-
bugfixes: true,
|
|
86
|
-
targets: {
|
|
87
|
-
browsers: supportedBrowsers,
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
],
|
|
92
|
-
comments: false,
|
|
93
|
-
}),
|
|
94
|
-
],
|
|
133
|
+
plugins: browserPlugins(),
|
|
95
134
|
},
|
|
135
|
+
// CommonJS browser build consumed by Browserify for the standalone bundle.
|
|
96
136
|
{
|
|
97
|
-
input: 'lib/
|
|
137
|
+
input: 'lib/document.browser.standalone.js',
|
|
98
138
|
external,
|
|
99
139
|
output: {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
140
|
+
file: 'js/pdfkit.browser.js',
|
|
141
|
+
format: 'cjs',
|
|
142
|
+
sourcemap: true,
|
|
143
|
+
interop: 'default',
|
|
144
|
+
exports: 'named',
|
|
145
|
+
footer:
|
|
146
|
+
'module.exports = exports.default;\nmodule.exports.PDFDocument = exports.PDFDocument;',
|
|
104
147
|
},
|
|
148
|
+
plugins: browserPlugins(),
|
|
149
|
+
},
|
|
150
|
+
// Experimental helpers for collecting document output.
|
|
151
|
+
{
|
|
152
|
+
input: 'lib/output.js',
|
|
153
|
+
output: [
|
|
154
|
+
{
|
|
155
|
+
file: 'js/output.cjs',
|
|
156
|
+
format: 'cjs',
|
|
157
|
+
exports: 'named',
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
file: 'js/output.mjs',
|
|
161
|
+
format: 'es',
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
plugins: browserPlugins(),
|
|
165
|
+
},
|
|
166
|
+
// Standard font data is kept outside the main bundles so it can be loaded
|
|
167
|
+
// individually on demand.
|
|
168
|
+
{
|
|
169
|
+
input: standardFontInputs,
|
|
170
|
+
output: [
|
|
171
|
+
{
|
|
172
|
+
dir: 'js/standard-fonts',
|
|
173
|
+
format: 'cjs',
|
|
174
|
+
entryFileNames: '[name].cjs',
|
|
175
|
+
chunkFileNames: 'chunks/[name]-[hash].cjs',
|
|
176
|
+
exports: 'default',
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
dir: 'js/standard-fonts',
|
|
180
|
+
format: 'es',
|
|
181
|
+
entryFileNames: '[name].mjs',
|
|
182
|
+
chunkFileNames: 'chunks/[name]-[hash].mjs',
|
|
183
|
+
},
|
|
184
|
+
],
|
|
105
185
|
plugins: [
|
|
106
186
|
babel({
|
|
107
187
|
babelHelpers: 'bundled',
|
|
108
188
|
babelrc: false,
|
|
109
|
-
|
|
110
|
-
[
|
|
111
|
-
'@babel/preset-env',
|
|
112
|
-
{
|
|
113
|
-
loose: true,
|
|
114
|
-
modules: false,
|
|
115
|
-
targets: {
|
|
116
|
-
browsers: supportedBrowsers,
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
],
|
|
189
|
+
comments: false,
|
|
121
190
|
}),
|
|
122
191
|
],
|
|
123
192
|
},
|
package/tools/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# AFM conversion tools
|
|
2
|
+
|
|
3
|
+
The AFM conversion tools generate one ECMAScript module per input font. Runtime
|
|
4
|
+
conversion also generates a shared glyph-name module when Courier, Helvetica,
|
|
5
|
+
or Times is present. PDFKit emits each generated runtime module as separate CJS
|
|
6
|
+
and ESM artifacts. Node loads them on demand, while browser applications import
|
|
7
|
+
and register only the standard fonts they use.
|
|
8
|
+
|
|
9
|
+
Raw AFM files remain the source of truth and are retained in distributions.
|
|
10
|
+
The runtime modules in `lib/font/generated` are committed build inputs. Do not
|
|
11
|
+
edit them directly; regenerate them from the AFM sources and format the result.
|
|
12
|
+
|
|
13
|
+
## Commands
|
|
14
|
+
|
|
15
|
+
Generate compact runtime data:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
node tools/convert-afm-runtime.js --output-dir /tmp/pdfkit-afm-runtime
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Generate the complete parsed AFM state used for converter verification:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
node tools/convert-afm-parsed.js --output-dir /tmp/pdfkit-afm-parsed
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
With no input paths, each command converts all bundled AFMs. Pass one or more
|
|
28
|
+
AFM paths after `--output-dir` to convert only selected fonts. Both converters
|
|
29
|
+
use the same normalized filenames, such as `Helvetica.js`,
|
|
30
|
+
`HelveticaBold.js`, and `TimesBoldItalic.js`, so use separate output
|
|
31
|
+
directories when retaining both formats.
|
|
32
|
+
|
|
33
|
+
Runtime conversion also creates `standardGlyphNames.js` when a font uses the
|
|
34
|
+
standard Roman glyph table. Each font file is an importable ES module with a
|
|
35
|
+
default export.
|
|
36
|
+
|
|
37
|
+
## Parsed-data schema
|
|
38
|
+
|
|
39
|
+
The parsed-data module exports the parser's three data structures without
|
|
40
|
+
normalizing their values:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
export default {
|
|
44
|
+
attributes: { FontName: 'Helvetica' },
|
|
45
|
+
glyphWidths: { space: 278 },
|
|
46
|
+
kernPairs: { 'A\0V': -70 },
|
|
47
|
+
};
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
This format is immediately usable after JavaScript module parsing and serves
|
|
51
|
+
as the low-decoding-cost baseline. Because glyph names are repeated in the
|
|
52
|
+
large kerning maps, it is only modestly smaller than AFM for proportional
|
|
53
|
+
fonts.
|
|
54
|
+
|
|
55
|
+
## Runtime schema
|
|
56
|
+
|
|
57
|
+
The runtime module keeps the font-level values PDFKit consumes and only the
|
|
58
|
+
glyphs reachable through its current 256-entry character mapping:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import glyphNames from './standardGlyphNames.js';
|
|
62
|
+
|
|
63
|
+
export default {
|
|
64
|
+
name: 'Helvetica',
|
|
65
|
+
bbox: [-166, -225, 1000, 931],
|
|
66
|
+
ascender: 718,
|
|
67
|
+
descender: -207,
|
|
68
|
+
xHeight: 523,
|
|
69
|
+
capHeight: 718,
|
|
70
|
+
glyphNames,
|
|
71
|
+
glyphWidths: [278, 278, 355],
|
|
72
|
+
kernPairs: [-70, [12, 4, 9]],
|
|
73
|
+
};
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`standardGlyphNames.js` exports the identical space-separated 215-name table
|
|
77
|
+
used by all Courier, Helvetica, and Times variants. Bundlers include this
|
|
78
|
+
dependency once when one or more of those fonts are used. Symbol, ZapfDingbats,
|
|
79
|
+
and nonmatching AFMs keep their glyph-name strings inline.
|
|
80
|
+
|
|
81
|
+
`glyphWidths` uses indexes matching `glyphNames`. `kernPairs` alternates a
|
|
82
|
+
kerning amount and an array of delta-encoded pair IDs. A pair ID is
|
|
83
|
+
`leftIndex * glyphCount + rightIndex`. Pair IDs are sorted within each amount
|
|
84
|
+
group before delta encoding.
|
|
85
|
+
|
|
86
|
+
Decoder pseudocode:
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
const names = data.glyphNames.split(' ');
|
|
90
|
+
const widths = Object.fromEntries(
|
|
91
|
+
names.map((name, index) => [name, data.glyphWidths[index]]),
|
|
92
|
+
);
|
|
93
|
+
const kernPairs = {};
|
|
94
|
+
|
|
95
|
+
for (let index = 0; index < data.kernPairs.length; index += 2) {
|
|
96
|
+
const amount = data.kernPairs[index];
|
|
97
|
+
let pairId = 0;
|
|
98
|
+
|
|
99
|
+
for (const delta of data.kernPairs[index + 1]) {
|
|
100
|
+
pairId += delta;
|
|
101
|
+
const left = Math.floor(pairId / names.length);
|
|
102
|
+
const right = pairId % names.length;
|
|
103
|
+
kernPairs[`${names[left]}\0${names[right]}`] = amount;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Format rationale
|
|
109
|
+
|
|
110
|
+
Across PDFKit's 14 AFMs, the raw sources are about 619 KB. Generated output,
|
|
111
|
+
including license headers, is about 550 KB for direct parsed data and 52 KB for
|
|
112
|
+
compact runtime data. Sharing the 1,492-byte Roman glyph-name string removes 11
|
|
113
|
+
duplicate copies from a complete runtime conversion. These size limits are
|
|
114
|
+
also guarded by the converter tests.
|
|
115
|
+
|
|
116
|
+
[`@pdf-lib/standard-fonts`](https://github.com/Hopding/standard-fonts) deflates
|
|
117
|
+
base64-encoded JSON, which is compact but requires inflation and JSON parsing
|
|
118
|
+
at runtime. [jsPDF](https://raw.githubusercontent.com/parallax/jsPDF/master/src/modules/standard_fonts_metrics.js)
|
|
119
|
+
uses custom numeric packing and a character-level decoder. The runtime format
|
|
120
|
+
here borrows numeric indexing and value grouping while retaining native
|
|
121
|
+
JavaScript numbers and arrays, avoiding an inflate dependency or custom token
|
|
122
|
+
parser. The source fields and `KPX` behavior follow the
|
|
123
|
+
[Adobe AFM specification](https://www.adobe.com/content/dam/acom/en/devnet/font/pdfs/5004.AFM_Spec.pdf)
|
|
124
|
+
and PDFKit's existing parser.
|