]> git.kianting.info Git - anotherTypesetter/commitdiff
解決不了PDF-lib的問題
authorTan Kian-ting <chenjt30@gmail.com>
Sun, 21 Apr 2024 17:34:49 +0000 (01:34 +0800)
committerTan Kian-ting <chenjt30@gmail.com>
Sun, 21 Apr 2024 17:34:49 +0000 (01:34 +0800)
README.md
package-lock.json
package.json
src/index.js
src/index.ts
text.lisp
text.lisp.pdf

index db3f025eff5a33655ae17045e063e61892ec250e..259861b9ab9ae01295d19fdba2de32cc707e81d5 100644 (file)
--- 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
index f83f9f3c8a060780c34e3c6424782045471e5058..23312421b0d84129b1277f55a6f487a451a70b85 100644 (file)
       "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",
         "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",
       "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",
         "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",
         "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",
       "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",
     "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",
       "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",
         "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",
         "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",
         "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",
         "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",
       "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",
       "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",
         "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",
       "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",
         "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",
         "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",
       "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",
     "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",
       "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",
         "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",
         "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",
       "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",
       "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",
       "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",
       "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",
index f1cfa2114226c0a577de142e317c6dd7d55270a9..6651bb3192a6a7d2fcc59b10af17d594773c0a55 100644 (file)
   "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",
index 2c6488f927ace0119eaff32c2490eb8ff12d5e36..9102311b8f83cd153976debdb5cdb15f739dc103 100644 (file)
@@ -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 (<any>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,
index cfb1c1dc5c84703c344a2abaa56684fc50f1015f..0c9d535d2e419d30a2ebd2af34b65f01c41985bd 100644 (file)
@@ -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 (<any>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((<any>fontBytes).stream.buffer, {subset:true});
 
   const rgbColor = await hexColorToRGB(color);
 
@@ -1103,6 +1126,7 @@ async function evaluate(expr: string): Promise<string> {
 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,
index f0e1b2e50106c5789cec0cff5a4f53e6d6fbc71d..72176a7724286ed16e6fa71439998d5b1a0781d8 100644 (file)
--- 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
index 3fef8383e331f0c390319af5110d01b28a0c3d8f..e97f7f94b91c5957fac855bda16666398f01361f 100644 (file)
Binary files a/text.lisp.pdf and b/text.lisp.pdf differ