From: Tan Kian-ting Date: Sun, 21 Apr 2024 17:34:49 +0000 (+0800) Subject: 解決不了PDF-lib的問題 X-Git-Url: https://git.kianting.info/?a=commitdiff_plain;h=ca192e89a4cb1b6948489ab9bc029fa9c156e48a;p=anotherTypesetter 解決不了PDF-lib的問題 --- diff --git a/README.md b/README.md index db3f025..259861b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ ## Just another interpretation of typesetting ## TODO +**現在問題:需要遷移到PDFKit,以及使用標準的fontkit,避免ttc無法支援的問題。PDF-lib試過了,不能用。** - [v] apply - 240403 - [v] letrec - 240405 - [v] car - 240403 @@ -7,11 +8,11 @@ - [v] concat string (++) - [v] set! - [v] list ref by index - - [ ] dict ref by id + - [v] dict ref by id - [v] map 20240410 - [v] add pdf page 240410 (addPDFPages) - [v] create pdf 240410 - - [ ] close pdf + - [v] close pdf - [v] add character - [ ] add path - [ ] basic typesetting format diff --git a/package-lock.json b/package-lock.json index f83f9f3..2331242 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,11 +10,15 @@ "license": "MIT", "dependencies": { "@pdf-lib/fontkit": "^1.1.1", + "fontkit": "^2.0.2", "harfbuzzjs": "^0.3.5", + "memfs": "^4.8.2", + "pdf-fontkit": "^1.8.9", "pdf-lib": "^1.17.1", "typescript-parsec": "^0.3.4" }, "devDependencies": { + "@types/fontkit": "^2.0.7", "@types/node": "^20.11.30", "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", @@ -184,6 +188,29 @@ "pako": "^1.0.10" } }, + "node_modules/@swc/helpers": { + "version": "0.4.36", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.36.tgz", + "integrity": "sha512-5lxnyLEYFskErRPenYItLRSge5DjrJngYKdVjRSrWfza9G6KkgHEXi0vUZiyUeMU5JfXH1YnvXZzSp8ul88o2Q==", + "dependencies": { + "legacy-swc-helpers": "npm:@swc/helpers@=0.4.14", + "tslib": "^2.4.0" + } + }, + "node_modules/@swc/helpers/node_modules/tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" + }, + "node_modules/@types/fontkit": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/@types/fontkit/-/fontkit-2.0.7.tgz", + "integrity": "sha512-f5BjGam6y3FrfEY2JxXwba66SYzqP+FREZh4UuBN1WDePl8EhTKjba3ZZQ2iORUufkrFt/c/UIugj0Uv/HEdRg==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -514,6 +541,25 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -537,6 +583,14 @@ "node": ">=8" } }, + "node_modules/brotli": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/brotli/-/brotli-1.3.3.tgz", + "integrity": "sha512-oTKjJdShmDuGW94SyyaoQvAjf30dZaHnjJ8uAF+u2/vGJkJbJPJAT1gDiOJP5v1Zb6f9KEyW/1HpuaWIXtGHPg==", + "dependencies": { + "base64-js": "^1.1.2" + } + }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -564,6 +618,14 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/clone": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", + "integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==", + "engines": { + "node": ">=0.8" + } + }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -630,6 +692,11 @@ "dev": true, "peer": true }, + "node_modules/dfa": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/dfa/-/dfa-1.2.0.tgz", + "integrity": "sha512-ED3jP8saaweFTjeGX8HQPjeC1YYyZs98jGNZx6IiBvxW7JG5v492kamAQB3m2wop07CvU/RQmzcKr6bgcC5D/Q==" + }, "node_modules/dir-glob": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", @@ -820,9 +887,7 @@ "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true, - "peer": true + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, "node_modules/fast-glob": { "version": "3.3.2", @@ -939,6 +1004,22 @@ "dev": true, "peer": true }, + "node_modules/fontkit": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/fontkit/-/fontkit-2.0.2.tgz", + "integrity": "sha512-jc4k5Yr8iov8QfS6u8w2CnHWVmbOGtdBtOXMze5Y+QD966Rx6PEVWXSEGwXlsDlKtu1G12cJjcsybnqhSk/+LA==", + "dependencies": { + "@swc/helpers": "^0.4.2", + "brotli": "^1.3.2", + "clone": "^2.1.2", + "dfa": "^1.2.0", + "fast-deep-equal": "^3.1.3", + "restructure": "^3.0.0", + "tiny-inflate": "^1.0.3", + "unicode-properties": "^1.4.0", + "unicode-trie": "^2.0.0" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -1182,6 +1263,20 @@ "json-buffer": "3.0.1" } }, + "node_modules/legacy-swc-helpers": { + "name": "@swc/helpers", + "version": "0.4.14", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.14.tgz", + "integrity": "sha512-4C7nX/dvpzB7za4Ql9K81xK3HPxCpHMgwTZVyf+9JQ6VUbn9jjZVN7/Nkdz/Ugzs2CSjqnL/UPXroiVBVHUWUw==", + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/legacy-swc-helpers/node_modules/tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" + }, "node_modules/levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -1231,6 +1326,26 @@ "node": ">=10" } }, + "node_modules/memfs": { + "version": "4.8.2", + "resolved": "https://registry.npmjs.org/memfs/-/memfs-4.8.2.tgz", + "integrity": "sha512-j4WKth315edViMBGkHW6NTF0QBjsTrcRDmYNcGsPq+ozMEyCCCIlX2d2mJ5wuh6iHvJ3FevUrr48v58YRqVdYg==", + "dependencies": { + "tslib": "^2.0.0" + }, + "engines": { + "node": ">= 4.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/streamich" + } + }, + "node_modules/memfs/node_modules/tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" + }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -1395,6 +1510,14 @@ "node": ">=8" } }, + "node_modules/pdf-fontkit": { + "version": "1.8.9", + "resolved": "https://registry.npmjs.org/pdf-fontkit/-/pdf-fontkit-1.8.9.tgz", + "integrity": "sha512-TTq+umfhlFjUuQYOq6dCKT/wLslCrX4zVr5gqrIvrGHfo+vJ3ETapZTb4YLOCErohX7pF+HxlXSZuiToSRhNmA==", + "dependencies": { + "pako": "^1.0.6" + } + }, "node_modules/pdf-lib": { "version": "1.17.1", "resolved": "https://registry.npmjs.org/pdf-lib/-/pdf-lib-1.17.1.tgz", @@ -1468,6 +1591,11 @@ "node": ">=4" } }, + "node_modules/restructure": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/restructure/-/restructure-3.0.1.tgz", + "integrity": "sha512-6neDpI/yE9eogQo22qmWwKIA9wFPRyYjQleDEh6zaNAf2ZPqLJYUvNBJBWEWNoBlCeQMQkvIOe2YI/K2GOag+g==" + }, "node_modules/reusify": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", @@ -1610,6 +1738,11 @@ "dev": true, "peer": true }, + "node_modules/tiny-inflate": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tiny-inflate/-/tiny-inflate-1.0.3.tgz", + "integrity": "sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw==" + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -1689,6 +1822,29 @@ "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", "dev": true }, + "node_modules/unicode-properties": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/unicode-properties/-/unicode-properties-1.4.1.tgz", + "integrity": "sha512-CLjCCLQ6UuMxWnbIylkisbRj31qxHPAurvena/0iwSVbQ2G1VY5/HjV0IRabOEbDHlzZlRdCrD4NhB0JtU40Pg==", + "dependencies": { + "base64-js": "^1.3.0", + "unicode-trie": "^2.0.0" + } + }, + "node_modules/unicode-trie": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/unicode-trie/-/unicode-trie-2.0.0.tgz", + "integrity": "sha512-x7bc76x0bm4prf1VLg79uhAzKw8DVboClSN5VxJuQ+LKDOVEW9CdH+VY7SP+vX7xCYQqzzgQpFqz15zeLvAtZQ==", + "dependencies": { + "pako": "^0.2.5", + "tiny-inflate": "^1.0.0" + } + }, + "node_modules/unicode-trie/node_modules/pako": { + "version": "0.2.9", + "resolved": "https://registry.npmjs.org/pako/-/pako-0.2.9.tgz", + "integrity": "sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA==" + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -1866,6 +2022,31 @@ "pako": "^1.0.10" } }, + "@swc/helpers": { + "version": "0.4.36", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.36.tgz", + "integrity": "sha512-5lxnyLEYFskErRPenYItLRSge5DjrJngYKdVjRSrWfza9G6KkgHEXi0vUZiyUeMU5JfXH1YnvXZzSp8ul88o2Q==", + "requires": { + "legacy-swc-helpers": "npm:@swc/helpers@=0.4.14", + "tslib": "^2.4.0" + }, + "dependencies": { + "tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" + } + } + }, + "@types/fontkit": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/@types/fontkit/-/fontkit-2.0.7.tgz", + "integrity": "sha512-f5BjGam6y3FrfEY2JxXwba66SYzqP+FREZh4UuBN1WDePl8EhTKjba3ZZQ2iORUufkrFt/c/UIugj0Uv/HEdRg==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -2079,6 +2260,11 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, + "base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -2099,6 +2285,14 @@ "fill-range": "^7.0.1" } }, + "brotli": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/brotli/-/brotli-1.3.3.tgz", + "integrity": "sha512-oTKjJdShmDuGW94SyyaoQvAjf30dZaHnjJ8uAF+u2/vGJkJbJPJAT1gDiOJP5v1Zb6f9KEyW/1HpuaWIXtGHPg==", + "requires": { + "base64-js": "^1.1.2" + } + }, "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -2117,6 +2311,11 @@ "supports-color": "^7.1.0" } }, + "clone": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", + "integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==" + }, "color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -2169,6 +2368,11 @@ "dev": true, "peer": true }, + "dfa": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/dfa/-/dfa-1.2.0.tgz", + "integrity": "sha512-ED3jP8saaweFTjeGX8HQPjeC1YYyZs98jGNZx6IiBvxW7JG5v492kamAQB3m2wop07CvU/RQmzcKr6bgcC5D/Q==" + }, "dir-glob": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", @@ -2308,9 +2512,7 @@ "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true, - "peer": true + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, "fast-glob": { "version": "3.3.2", @@ -2408,6 +2610,22 @@ "dev": true, "peer": true }, + "fontkit": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/fontkit/-/fontkit-2.0.2.tgz", + "integrity": "sha512-jc4k5Yr8iov8QfS6u8w2CnHWVmbOGtdBtOXMze5Y+QD966Rx6PEVWXSEGwXlsDlKtu1G12cJjcsybnqhSk/+LA==", + "requires": { + "@swc/helpers": "^0.4.2", + "brotli": "^1.3.2", + "clone": "^2.1.2", + "dfa": "^1.2.0", + "fast-deep-equal": "^3.1.3", + "restructure": "^3.0.0", + "tiny-inflate": "^1.0.3", + "unicode-properties": "^1.4.0", + "unicode-trie": "^2.0.0" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -2600,6 +2818,21 @@ "json-buffer": "3.0.1" } }, + "legacy-swc-helpers": { + "version": "npm:@swc/helpers@0.4.14", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.14.tgz", + "integrity": "sha512-4C7nX/dvpzB7za4Ql9K81xK3HPxCpHMgwTZVyf+9JQ6VUbn9jjZVN7/Nkdz/Ugzs2CSjqnL/UPXroiVBVHUWUw==", + "requires": { + "tslib": "^2.4.0" + }, + "dependencies": { + "tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" + } + } + }, "levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -2637,6 +2870,21 @@ "yallist": "^4.0.0" } }, + "memfs": { + "version": "4.8.2", + "resolved": "https://registry.npmjs.org/memfs/-/memfs-4.8.2.tgz", + "integrity": "sha512-j4WKth315edViMBGkHW6NTF0QBjsTrcRDmYNcGsPq+ozMEyCCCIlX2d2mJ5wuh6iHvJ3FevUrr48v58YRqVdYg==", + "requires": { + "tslib": "^2.0.0" + }, + "dependencies": { + "tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" + } + } + }, "merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -2762,6 +3010,14 @@ "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", "dev": true }, + "pdf-fontkit": { + "version": "1.8.9", + "resolved": "https://registry.npmjs.org/pdf-fontkit/-/pdf-fontkit-1.8.9.tgz", + "integrity": "sha512-TTq+umfhlFjUuQYOq6dCKT/wLslCrX4zVr5gqrIvrGHfo+vJ3ETapZTb4YLOCErohX7pF+HxlXSZuiToSRhNmA==", + "requires": { + "pako": "^1.0.6" + } + }, "pdf-lib": { "version": "1.17.1", "resolved": "https://registry.npmjs.org/pdf-lib/-/pdf-lib-1.17.1.tgz", @@ -2806,6 +3062,11 @@ "dev": true, "peer": true }, + "restructure": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/restructure/-/restructure-3.0.1.tgz", + "integrity": "sha512-6neDpI/yE9eogQo22qmWwKIA9wFPRyYjQleDEh6zaNAf2ZPqLJYUvNBJBWEWNoBlCeQMQkvIOe2YI/K2GOag+g==" + }, "reusify": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", @@ -2897,6 +3158,11 @@ "dev": true, "peer": true }, + "tiny-inflate": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tiny-inflate/-/tiny-inflate-1.0.3.tgz", + "integrity": "sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw==" + }, "to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -2952,6 +3218,31 @@ "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", "dev": true }, + "unicode-properties": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/unicode-properties/-/unicode-properties-1.4.1.tgz", + "integrity": "sha512-CLjCCLQ6UuMxWnbIylkisbRj31qxHPAurvena/0iwSVbQ2G1VY5/HjV0IRabOEbDHlzZlRdCrD4NhB0JtU40Pg==", + "requires": { + "base64-js": "^1.3.0", + "unicode-trie": "^2.0.0" + } + }, + "unicode-trie": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/unicode-trie/-/unicode-trie-2.0.0.tgz", + "integrity": "sha512-x7bc76x0bm4prf1VLg79uhAzKw8DVboClSN5VxJuQ+LKDOVEW9CdH+VY7SP+vX7xCYQqzzgQpFqz15zeLvAtZQ==", + "requires": { + "pako": "^0.2.5", + "tiny-inflate": "^1.0.0" + }, + "dependencies": { + "pako": { + "version": "0.2.9", + "resolved": "https://registry.npmjs.org/pako/-/pako-0.2.9.tgz", + "integrity": "sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA==" + } + } + }, "uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/package.json b/package.json index f1cfa21..6651bb3 100644 --- a/package.json +++ b/package.json @@ -17,11 +17,15 @@ "license": "MIT", "dependencies": { "@pdf-lib/fontkit": "^1.1.1", + "fontkit": "^2.0.2", "harfbuzzjs": "^0.3.5", + "memfs": "^4.8.2", + "pdf-fontkit": "^1.8.9", "pdf-lib": "^1.17.1", "typescript-parsec": "^0.3.4" }, "devDependencies": { + "@types/fontkit": "^2.0.7", "@types/node": "^20.11.30", "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", diff --git a/src/index.js b/src/index.js index 2c6488f..9102311 100644 --- a/src/index.js +++ b/src/index.js @@ -24,7 +24,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const fs = __importStar(require("fs")); const pdf_lib_1 = require("pdf-lib"); -const fontkit_1 = __importDefault(require("@pdf-lib/fontkit")); +const pdf_fontkit_1 = __importDefault(require("pdf-fontkit")); // for pdflib usage +const memfs_1 = require("memfs"); const typescript_parsec_1 = require("typescript-parsec"); const typescript_parsec_2 = require("typescript-parsec"); /** input lisp file */ @@ -171,7 +172,7 @@ async function measureWidthPx(inputString, fontFamily, fontSizePt) { var hb = require('harfbuzzjs/hbjs'); hb = hb(wsm.instance); let fontName = (0, child_process_1.spawnSync)('fc-match', ['--format=%{file}', fontFamily]); - const fontPath = fontName.stdout.toString(); + let fontPath = fontName.stdout.toString(); let fontdata = fs.readFileSync(fontPath); var blob = hb.createBlob(fontdata); // Load the font data into something Harfbuzz can use var face = hb.createFace(blob, 0); // Select the first font in the file (there's normally only one!) @@ -406,9 +407,25 @@ async function drawText(pageIndex, fontFamily, textSize, color, x, y, text) { let currentPage = pdfPages[pageIndex]; const fcMatch = await (0, child_process_1.spawnSync)('fc-match', ['--format=%{file}', fontFamily]); const path = fcMatch.stdout.toString(); - pdfDoc.registerFontkit(fontkit_1.default); - const fontBytes = fs.readFileSync(path); - const customFont = await pdfDoc.embedFont(fontBytes); + pdfDoc.registerFontkit(pdf_fontkit_1.default); + let fontBytes; + // workaround for ttc + if (path.match(/[.]ttc$/)) { + let tmpfs = (0, memfs_1.memfs)(); + let psName = await (0, child_process_1.spawnSync)('fc-match', ['--format=%{postscriptname}', + fontFamily]) + .stdout.toString(); + console.log("===", psName); + let buffer = await fs.readFileSync("/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc"); + let coll = pdf_fontkit_1.default.create(buffer, "NotoSansCJKtc-Regular"); + //let collection = await (fontkitOrig.openSync(path, psName)); + fontBytes = coll; + // fs.writeFileSync("/tmp/a.ttf", fontBytes); + } + else { + fontBytes = fs.readFileSync(path); + } + const customFont = await pdfDoc.embedFont(fontBytes.stream.buffer, { subset: true }); const rgbColor = await hexColorToRGB(color); let _ = await currentPage.drawText(text, { x: x, diff --git a/src/index.ts b/src/index.ts index cfb1c1d..0c9d535 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,8 @@ import * as fs from 'fs'; -import { PDFDocument , RGB, rgb, StandardFonts} from 'pdf-lib'; -import fontkit from '@pdf-lib/fontkit'; +import { PDFDocument , RGB, rgb} from 'pdf-lib'; +import fontkit from 'pdf-fontkit'; // for pdflib usage +import * as fontkitOrig from 'fontkit'; // for ttc converting to ttf +import {memfs} from 'memfs'; import { Token } from "typescript-parsec"; import { buildLexer, @@ -280,7 +282,10 @@ async function measureWidthPx(inputString: string, fontFamily : string, fontSize hb = hb(wsm.instance); let fontName = spawnSync('fc-match', ['--format=%{file}', fontFamily]); - const fontPath = fontName.stdout.toString(); + let fontPath = fontName.stdout.toString(); + + + let fontdata = fs.readFileSync(fontPath); @@ -530,9 +535,27 @@ async function drawText(pageIndex : number, const fcMatch = await spawnSync('fc-match', ['--format=%{file}', fontFamily]); const path = fcMatch.stdout.toString(); pdfDoc.registerFontkit(fontkit); - const fontBytes = fs.readFileSync(path); + let fontBytes; + // workaround for ttc + if (path.match(/[.]ttc$/)){ + let tmpfs = memfs(); + let psName = await spawnSync('fc-match', + ['--format=%{postscriptname}', + fontFamily]) + .stdout.toString(); + console.log("===", psName); + + let buffer = await fs.readFileSync("/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc"); + let coll = fontkit.create(buffer, "NotoSansCJKtc-Regular"); + //let collection = await (fontkitOrig.openSync(path, psName)); + + fontBytes = coll; + // fs.writeFileSync("/tmp/a.ttf", fontBytes); +}else{ + fontBytes = fs.readFileSync(path); +} - const customFont = await pdfDoc.embedFont(fontBytes); + const customFont = await pdfDoc.embedFont((fontBytes).stream.buffer, {subset:true}); const rgbColor = await hexColorToRGB(color); @@ -1103,6 +1126,7 @@ async function evaluate(expr: string): Promise { import readline = require("node:readline"); import { exit } from "node:process"; import { spawnSync } from 'child_process'; +import { match } from 'assert'; const rl = readline.createInterface({ input: process.stdin, diff --git a/text.lisp b/text.lisp index f0e1b2e..72176a7 100644 --- a/text.lisp +++ b/text.lisp @@ -1,6 +1,6 @@ (begin (define defaultFontFormat - '(("fontFamily" "FreeSerif") + '(("fontFamily" "Noto Sans CJK TC") ("color" "#ff0000") ("fontSize" 12.0) ) @@ -89,7 +89,7 @@ //) (define x 0.0) -(define text '("abracabra" ("fontSize" 18.0 "cat") "foo")) +(define text '("abracabra" ("fontSize" 18.0 "貓") "foo")) (define putOnChar (lambda (boxDict x) (let diff --git a/text.lisp.pdf b/text.lisp.pdf index 3fef838..e97f7f9 100644 Binary files a/text.lisp.pdf and b/text.lisp.pdf differ