add convert to font px

This commit is contained in:
Tan, Kian-ting 2023-11-06 00:59:25 +08:00
parent 5bf5f5cbe5
commit 830387283a
5 changed files with 384 additions and 178 deletions

12
b.js
View file

@ -9,17 +9,7 @@ let clo = new cloLib.Clo();
/* CLO: beginning of middle part*/
clo.mainStream = /* CLO: end of middle part*/
[`The`, ` `, `book`, ` `, `of`, ` `, `the`, ` `, `generation`, ` `, `of`, ` `, `Jesus`, ` `, `Christ,`, ` `, `the`, ` `, `son`, ` `, `of`, ` `, `David,`, ` `, `the`, ` `, `son`, ` `, `of`, ` `, `Abraham.`, `
`, `Abraham`, ` `, `begat`, ` `, `Isaac`, `;`, ` `, `and`, ` `, `Isaac`, ` `, `begat`, ` `, `Jacob`, `;`, ` `, `and`, ` `, `Jacob`, ` `, `begat`, ` `, `Judas`, ` `, `and`, ` `, `his`, ` `, `brethren`, `;`, ` `, `And`, ` `, `Judas`, ` `, `begat`, ` `, `Phares`, ` `, `and`, ` `, `Zara`, ` `, `of`, ` `, `Thamar`, `;`, ` `, `and`, ` `, `Phares`, ` `, `begat`, ` `, `Esrom`, `;`, ` `, `and`, ` `, `Esrom`, ` `, `begat`, ` `, `Aram`, `;`, ` `, `And`, ` `, `Aram`, ` `, `begat`, ` `, `Aminadab`, `;`, ` `, `and`, ` `, `Aminadab`, ` `, `begat`, ` `, `Naasson`, `;`, ` `, `and`, ` `, `Naasson`, ` `, `begat`, ` `, `Salmon`, `;`, ` `, `And`, ` `, `Salmon`, ` `, `begat`, ` `, `Booz`, ` `, `of`, ` `, `Rachab`, `;`, ` `, `and`, ` `, `Booz`, ` `, `begat`, ` `, `Obed`, ` `, `of`, ` `, `Ruth`, `;`, ` `, `and`, ` `, `Obed`, ` `, `begat`, ` `, `Jesse`, `;`, ` `, `And`, ` `, `Jesse`, ` `, `begat`, ` `, `David`, ` `, `the`, ` `, `king`, `;`, `
`, `and`, ` `, `David`, ` `, `the`, ` `, `king`, ` `, `begat`, ` `, `Solomon`, ` `, `of`, ` `, `her`, ` `, `that`, ` `, `had`, ` `, `been`, ` `, `the`, ` `, `wife`, ` `, `of`, ` `, `Urias`, `;`, ` `, `And`, ` `, `Solomon`, ` `, `begat`, ` `, `Roboam`, `;`, ` `, `and`, ` `, `Roboam`, ` `, `begat`, ` `, `Abia`, `;`, ` `, `and`, ` `, `Abia`, ` `, `begat`, ` `, `Asa`, `;`, ` `, `And`, ` `, `Asa`, ` `, `begat`, ` `, `Josaphat`, `;`, ` `, `and`, ` `, `Josaphat`, ` `, `begat`, ` `, `Joram`, `;`, ` `, `and`, ` `, `Joram`, ` `, `begat`, ` `, `Ozias`, `;`, ` `, `And`, ` `, `Ozias`, ` `, `begat`, ` `, `Joatham`, `;`, ` `, `and`, ` `, `Joatham`, ` `, `begat`, ` `, `Achaz`, `;`, ` `, `and`, ` `, `Achaz`, ` `, `begat`, ` `, `Ezekias`, `;`, ` `, `And`, ` `, `Ezekias`, ` `, `begat`, ` `, `Manasses`, `;`, ` `, `and`, ` `, `Manasses`, ` `, `begat`, ` `, `Amon`, `;`, ` `, `and`, ` `, `Amon`, ` `, `begat`, ` `, `Josias`, `;`, ` `, `And`, ` `, `Josias`, ` `, `begat`, ` `, `Jechonias`, ` `, `and`, ` `, `his`, ` `, `brethren,`, ` `, `about`, ` `, `the`, ` `, `time`, ` `, `they`, ` `, `were`, ` `, `carried`, ` `, `away`, ` `, `to`, ` `, `Babylon:`, ` `, `And`, ` `, `after`, ` `, `they`, ` `, `were`, ` `, `brought`, ` `, `to`, ` `, `Babylon,`, ` `, `Jechonias`, ` `, `begat`, ` `, `Salathiel`, `;`, ` `, `and`, ` `, `Salathiel`, ` `, `begat`, ` `, `Zorobabel`, `;`, ` `, `And`, ` `, `Zorobabel`, ` `, `begat`, ` `, `Abiud`, `;`, ` `, `and`, ` `, `Abiud`, ` `, `begat`, ` `, `Eliakim`, `;`, ` `, `and`, ` `, `Eliakim`, ` `, `begat`, ` `, `Azor`, `;`, ` `, `And`, ` `, `Azor`, ` `, `begat`, ` `, `Sadoc`, `;`, ` `, `and`, ` `, `Sadoc`, ` `, `begat`, ` `, `Achim`, `;`, ` `, `and`, ` `, `Achim`, ` `, `begat`, ` `, `Eliud`, `;`, ` `, `And`, ` `, `Eliud`, ` `, `begat`, ` `, `Eleazar`, `;`, ` `, `and`, ` `, `Eleazar`, ` `, `begat`, ` `, `Matthan`, `;`, ` `, `and`, ` `, `Matthan`, ` `, `begat`, ` `, `Jacob`, `;`, ` `, `And`, ` `, `Jacob`, ` `, `begat`, ` `, `Joseph`, ` `, `the`, ` `, `husband`, ` `, `of`, ` `, `Mary,`, ` `, `of`, ` `, `whom`, ` `, `was`, ` `, `born`, ` `, `Jesus,`, ` `, `who`, ` `, `is`, ` `, `called`, ` `, `Christ.`, `
`, `So`, ` `, `all`, ` `, `the`, ` `, `generations`, ` `, `from`, ` `, `Abraham`, ` `, `to`, ` `, `David`, ` `, `are`, ` `, `fourteen`, ` `, `generations`, `;`, ` `, `and`, ` `, `from`, ` `, `David`, ` `, `until`, ` `, `the`, ` `, `carrying`, ` `, `away`, ` `, `into`, ` `, `Babylon`, ` `, `are`, ` `, `fourteen`, ` `, `generations`, `;`, ` `, `and`, ` `, `from`, ` `, `the`, ` `, `carrying`, ` `, `away`, ` `, `into`, ` `, `Babylon`, ` `, `unto`, ` `, `Christ`, ` `, `are`, ` `, `fourteen`, ` `, `generations.`, `
`, `Now`, ` `, `the`, ` `, `birth`, ` `, `of`, ` `, `Jesus`, ` `, `Christ`, ` `, `was`, ` `, `on`, ` `, `this`, ` `, `wise:`, ` `, `When`, ` `, `as`, ` `, `his`, ` `, `mother`, ` `, `Mary`, ` `, `was`, ` `, `espoused`, ` `, `to`, ` `, `Joseph,`, ` `, `before`, ` `, `they`, ` `, `came`, ` `, `together,`, ` `, `she`, ` `, `was`, ` `, `found`, ` `, `with`, ` `, `child`, ` `, `of`, ` `, `the`, ` `, `Holy`, ` `, `Ghost.`, ` `, `Then`, ` `, `Joseph`, ` `, `her`, ` `, `husband,`, ` `, `being`, ` `, `a`, ` `, `just`, ` `, `man,`, ` `, `and`, ` `, `not`, ` `, `willing`, ` `, `to`, ` `, `make`, ` `, `her`, ` `, `a`, ` `, `publick`, ` `, `example,`, ` `, `was`, ` `, `minded`, ` `, `to`, ` `, `put`, ` `, `her`, ` `, `away`, ` `, `privily.`, ` `, `But`, ` `, `while`, ` `, `he`, ` `, `thought`, ` `, `on`, ` `, `these`, ` `, `things,`, ` `, `behold,`, ` `, `the`, ` `, `angel`, ` `, `of`, ` `, `the`, ` `, `Lord`, ` `, `appeared`, ` `, `unto`, ` `, `him`, ` `, `in`, ` `, `a`, ` `, `dream,`, ` `, `saying,`, ` `, `Joseph,`, ` `, `thou`, ` `, `son`, ` `, `of`, ` `, `David,`, ` `, `fear`, ` `, `not`, ` `, `to`, ` `, `take`, ` `, `unto`, ` `, `thee`, ` `, `Mary`, ` `, `thy`, ` `, `wife:`, ` `, `for`, ` `, `that`, ` `, `which`, ` `, `is`, ` `, `conceived`, ` `, `in`, ` `, `her`, ` `, `is`, ` `, `of`, ` `, `the`, ` `, `Holy`, ` `, `Ghost.`, ` `, `And`, ` `, `she`, ` `, `shall`, ` `, `bring`, ` `, `forth`, ` `, `a`, ` `, `son,`, ` `, `and`, ` `, `thou`, ` `, `shalt`, ` `, `call`, ` `, `his`, ` `, `name`, ` `, `JESUS:`, ` `, `for`, ` `, `he`, ` `, `shall`, ` `, `save`, ` `, `his`, ` `, `people`, ` `, `from`, ` `, `their`, ` `, `sins.`, ` `, `Now`, ` `, `all`, ` `, `this`, ` `, `was`, ` `, `done,`, ` `, `that`, ` `, `it`, ` `, `might`, ` `, `be`, ` `, `fulfilled`, ` `, `which`, ` `, `was`, ` `, `spoken`, ` `, `of`, ` `, `the`, ` `, `Lord`, ` `, `by`, ` `, `the`, ` `, `prophet,`, ` `, `saying,`, ` `, `Behold,`, ` `, `a`, ` `, `virgin`, ` `, `shall`, ` `, `be`, ` `, `with`, ` `, `child,`, ` `, `and`, ` `, `shall`, ` `, `bring`, ` `, `forth`, ` `, `a`, ` `, `son,`, ` `, `and`, ` `, `they`, ` `, `shall`, ` `, `call`, ` `, `his`, ` `, `name`, ` `, `Emmanuel,`, ` `, `which`, ` `, `being`, ` `, `interpreted`, ` `, `is,`, ` `, `God`, ` `, `with`, ` `, `us.`, `
`, `Then`, ` `, `Joseph`, ` `, `being`, ` `, `raised`, ` `, `from`, ` `, `sleep`, ` `, `did`, ` `, `as`, ` `, `the`, ` `, `angel`, ` `, `of`, ` `, `the`, ` `, `Lord`, ` `, `had`, ` `, `bidden`, ` `, `him,`, ` `, `and`, ` `, `took`, ` `, `unto`, ` `, `him`, ` `, `his`, ` `, `wife:`, ` `, `And`, ` `, `knew`, ` `, `her`, ` `, `not`, ` `, `till`, ` `, `she`, ` `, `had`, ` `, `brought`, ` `, `forth`, ` `, `her`, ` `, `firstborn`, ` `, `son:`, ` `, `and`, ` `, `he`, ` `, `called`, ` `, `his`, ` `, `name`, ` `, `JESUS.`, ` `, `Now`, ` `, `when`, ` `, `Jesus`, ` `, `was`, ` `, `born`, ` `, `in`, ` `, `Bethlehem`, ` `, `of`, ` `, `Judaea`, ` `, `in`, ` `, `the`, ` `, `days`, ` `, `of`, ` `, `Herod`, ` `, `the`, ` `, `king,`, ` `, `behold,`, ` `, `there`, ` `, `came`, ` `, `wise`, ` `, `men`, ` `, `from`, ` `, `the`, ` `, `east`, ` `, `to`, ` `, `Jerusalem,`, ` `, `Saying,`, ` `, `Where`, ` `, `is`, ` `, `he`, ` `, `that`, ` `, `is`, ` `, `born`, ` `, `King`, ` `, `of`, ` `, `the`, ` `, `Jews?`, ` `];
[`The`, ` `];
/* CLO: beginning of end part*/
clo.generatePdf();
/*CLO : end of end part*/

313
package-lock.json generated
View file

@ -10,6 +10,7 @@
"license": "MIT",
"dependencies": {
"canvas": "^2.11.2",
"fontkit": "^2.0.2",
"hyphen": "^1.7.0",
"jsdom": "^22.1.0",
"minimist": "^1.2.8",
@ -19,6 +20,7 @@
},
"devDependencies": {
"@types/chai": "^4.3.5",
"@types/fontkit": "^2.0.5",
"@types/jsdom": "^21.1.4",
"@types/mocha": "^10.0.1",
"@types/node": "^20.8.4",
@ -740,10 +742,11 @@
}
},
"node_modules/@swc/helpers": {
"version": "0.3.17",
"resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.3.17.tgz",
"integrity": "sha512-tb7Iu+oZ+zWJZ3HJqwx8oNwSDIU440hmVMDPhpACWQWnrZHK99Bxs70gT1L2dnr5Hg50ZRWEFkQCAnOVVV0z1Q==",
"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"
}
},
@ -790,6 +793,15 @@
"integrity": "sha512-mEo1sAde+UCE6b2hxn332f1g1E8WfYRu6p5SvTKr2ZKC1f7gFJXk4h5PyGP9Dt6gCaG8y8XhwnXWC6Iy2cmBng==",
"dev": true
},
"node_modules/@types/fontkit": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/@types/fontkit/-/fontkit-2.0.5.tgz",
"integrity": "sha512-zHrNPwQ9QKRBoXuWJc4mekQUvncAKugYo2URPVnqw7US0U0BxdykYMK+T2I/l2rmRpQ+mBkleBmoXRtkYdBCpw==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/jsdom": {
"version": "21.1.4",
"resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-21.1.4.tgz",
@ -1707,6 +1719,14 @@
"wrap-ansi": "^7.0.0"
}
},
"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": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
@ -1871,6 +1891,34 @@
"node": ">=6"
}
},
"node_modules/deep-equal": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.2.2.tgz",
"integrity": "sha512-xjVyBf0w5vH0I42jdAZzOKVldmPgSulmiyPRywoyq7HXC9qdgo17kxJE+rdnif5Tz6+pIrpJI8dCpMNLIGkUiA==",
"dependencies": {
"array-buffer-byte-length": "^1.0.0",
"call-bind": "^1.0.2",
"es-get-iterator": "^1.1.3",
"get-intrinsic": "^1.2.1",
"is-arguments": "^1.1.1",
"is-array-buffer": "^3.0.2",
"is-date-object": "^1.0.5",
"is-regex": "^1.1.4",
"is-shared-array-buffer": "^1.0.2",
"isarray": "^2.0.5",
"object-is": "^1.1.5",
"object-keys": "^1.1.1",
"object.assign": "^4.1.4",
"regexp.prototype.flags": "^1.5.0",
"side-channel": "^1.0.4",
"which-boxed-primitive": "^1.0.2",
"which-collection": "^1.0.1",
"which-typed-array": "^1.1.9"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/deep-is": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz",
@ -2626,8 +2674,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
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="
},
"node_modules/fast-glob": {
"version": "3.3.1",
@ -2765,57 +2812,21 @@
"dev": true
},
"node_modules/fontkit": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/fontkit/-/fontkit-1.9.0.tgz",
"integrity": "sha512-HkW/8Lrk8jl18kzQHvAw9aTHe1cqsyx5sDnxncx652+CIfhawokEPkeM3BoIC+z/Xv7a0yMr0f3pRRwhGH455g==",
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/fontkit/-/fontkit-2.0.2.tgz",
"integrity": "sha512-jc4k5Yr8iov8QfS6u8w2CnHWVmbOGtdBtOXMze5Y+QD966Rx6PEVWXSEGwXlsDlKtu1G12cJjcsybnqhSk/+LA==",
"dependencies": {
"@swc/helpers": "^0.3.13",
"@swc/helpers": "^0.4.2",
"brotli": "^1.3.2",
"clone": "^2.1.2",
"deep-equal": "^2.0.5",
"dfa": "^1.2.0",
"restructure": "^2.0.1",
"fast-deep-equal": "^3.1.3",
"restructure": "^3.0.0",
"tiny-inflate": "^1.0.3",
"unicode-properties": "^1.3.1",
"unicode-properties": "^1.4.0",
"unicode-trie": "^2.0.0"
}
},
"node_modules/fontkit/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/fontkit/node_modules/deep-equal": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.2.2.tgz",
"integrity": "sha512-xjVyBf0w5vH0I42jdAZzOKVldmPgSulmiyPRywoyq7HXC9qdgo17kxJE+rdnif5Tz6+pIrpJI8dCpMNLIGkUiA==",
"dependencies": {
"array-buffer-byte-length": "^1.0.0",
"call-bind": "^1.0.2",
"es-get-iterator": "^1.1.3",
"get-intrinsic": "^1.2.1",
"is-arguments": "^1.1.1",
"is-array-buffer": "^3.0.2",
"is-date-object": "^1.0.5",
"is-regex": "^1.1.4",
"is-shared-array-buffer": "^1.0.2",
"isarray": "^2.0.5",
"object-is": "^1.1.5",
"object-keys": "^1.1.1",
"object.assign": "^4.1.4",
"regexp.prototype.flags": "^1.5.0",
"side-channel": "^1.0.4",
"which-boxed-primitive": "^1.0.2",
"which-collection": "^1.0.1",
"which-typed-array": "^1.1.9"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/for-each": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz",
@ -3994,6 +4005,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",
@ -9628,6 +9653,40 @@
"png-js": "^1.0.0"
}
},
"node_modules/pdfkit/node_modules/@swc/helpers": {
"version": "0.3.17",
"resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.3.17.tgz",
"integrity": "sha512-tb7Iu+oZ+zWJZ3HJqwx8oNwSDIU440hmVMDPhpACWQWnrZHK99Bxs70gT1L2dnr5Hg50ZRWEFkQCAnOVVV0z1Q==",
"dependencies": {
"tslib": "^2.4.0"
}
},
"node_modules/pdfkit/node_modules/fontkit": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/fontkit/-/fontkit-1.9.0.tgz",
"integrity": "sha512-HkW/8Lrk8jl18kzQHvAw9aTHe1cqsyx5sDnxncx652+CIfhawokEPkeM3BoIC+z/Xv7a0yMr0f3pRRwhGH455g==",
"dependencies": {
"@swc/helpers": "^0.3.13",
"brotli": "^1.3.2",
"clone": "^2.1.2",
"deep-equal": "^2.0.5",
"dfa": "^1.2.0",
"restructure": "^2.0.1",
"tiny-inflate": "^1.0.3",
"unicode-properties": "^1.3.1",
"unicode-trie": "^2.0.0"
}
},
"node_modules/pdfkit/node_modules/restructure": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/restructure/-/restructure-2.0.1.tgz",
"integrity": "sha512-e0dOpjm5DseomnXx2M5lpdZ5zoHqF1+bqdMJUohoYVVQa7cBdnk7fdmeI6byNWP/kiME72EeTiSypTCVnpLiDg=="
},
"node_modules/pdfkit/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/picocolors": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
@ -9883,9 +9942,9 @@
}
},
"node_modules/restructure": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/restructure/-/restructure-2.0.1.tgz",
"integrity": "sha512-e0dOpjm5DseomnXx2M5lpdZ5zoHqF1+bqdMJUohoYVVQa7cBdnk7fdmeI6byNWP/kiME72EeTiSypTCVnpLiDg=="
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/restructure/-/restructure-3.0.0.tgz",
"integrity": "sha512-Xj8/MEIhhfj9X2rmD9iJ4Gga9EFqVlpMj3vfLnV2r/Mh5jRMryNV+6lWh9GdJtDBcBSPIqzRdfBQ3wDtNFv/uw=="
},
"node_modules/reusify": {
"version": "1.0.4",
@ -11678,10 +11737,11 @@
}
},
"@swc/helpers": {
"version": "0.3.17",
"resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.3.17.tgz",
"integrity": "sha512-tb7Iu+oZ+zWJZ3HJqwx8oNwSDIU440hmVMDPhpACWQWnrZHK99Bxs70gT1L2dnr5Hg50ZRWEFkQCAnOVVV0z1Q==",
"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": {
@ -11727,6 +11787,15 @@
"integrity": "sha512-mEo1sAde+UCE6b2hxn332f1g1E8WfYRu6p5SvTKr2ZKC1f7gFJXk4h5PyGP9Dt6gCaG8y8XhwnXWC6Iy2cmBng==",
"dev": true
},
"@types/fontkit": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/@types/fontkit/-/fontkit-2.0.5.tgz",
"integrity": "sha512-zHrNPwQ9QKRBoXuWJc4mekQUvncAKugYo2URPVnqw7US0U0BxdykYMK+T2I/l2rmRpQ+mBkleBmoXRtkYdBCpw==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"@types/jsdom": {
"version": "21.1.4",
"resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-21.1.4.tgz",
@ -12369,6 +12438,11 @@
"wrap-ansi": "^7.0.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": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
@ -12501,6 +12575,31 @@
"type-detect": "^4.0.0"
}
},
"deep-equal": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.2.2.tgz",
"integrity": "sha512-xjVyBf0w5vH0I42jdAZzOKVldmPgSulmiyPRywoyq7HXC9qdgo17kxJE+rdnif5Tz6+pIrpJI8dCpMNLIGkUiA==",
"requires": {
"array-buffer-byte-length": "^1.0.0",
"call-bind": "^1.0.2",
"es-get-iterator": "^1.1.3",
"get-intrinsic": "^1.2.1",
"is-arguments": "^1.1.1",
"is-array-buffer": "^3.0.2",
"is-date-object": "^1.0.5",
"is-regex": "^1.1.4",
"is-shared-array-buffer": "^1.0.2",
"isarray": "^2.0.5",
"object-is": "^1.1.5",
"object-keys": "^1.1.1",
"object.assign": "^4.1.4",
"regexp.prototype.flags": "^1.5.0",
"side-channel": "^1.0.4",
"which-boxed-primitive": "^1.0.2",
"which-collection": "^1.0.1",
"which-typed-array": "^1.1.9"
}
},
"deep-is": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz",
@ -13050,8 +13149,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
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="
},
"fast-glob": {
"version": "3.3.1",
@ -13161,51 +13259,19 @@
"dev": true
},
"fontkit": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/fontkit/-/fontkit-1.9.0.tgz",
"integrity": "sha512-HkW/8Lrk8jl18kzQHvAw9aTHe1cqsyx5sDnxncx652+CIfhawokEPkeM3BoIC+z/Xv7a0yMr0f3pRRwhGH455g==",
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/fontkit/-/fontkit-2.0.2.tgz",
"integrity": "sha512-jc4k5Yr8iov8QfS6u8w2CnHWVmbOGtdBtOXMze5Y+QD966Rx6PEVWXSEGwXlsDlKtu1G12cJjcsybnqhSk/+LA==",
"requires": {
"@swc/helpers": "^0.3.13",
"@swc/helpers": "^0.4.2",
"brotli": "^1.3.2",
"clone": "^2.1.2",
"deep-equal": "^2.0.5",
"dfa": "^1.2.0",
"restructure": "^2.0.1",
"fast-deep-equal": "^3.1.3",
"restructure": "^3.0.0",
"tiny-inflate": "^1.0.3",
"unicode-properties": "^1.3.1",
"unicode-properties": "^1.4.0",
"unicode-trie": "^2.0.0"
},
"dependencies": {
"clone": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz",
"integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w=="
},
"deep-equal": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.2.2.tgz",
"integrity": "sha512-xjVyBf0w5vH0I42jdAZzOKVldmPgSulmiyPRywoyq7HXC9qdgo17kxJE+rdnif5Tz6+pIrpJI8dCpMNLIGkUiA==",
"requires": {
"array-buffer-byte-length": "^1.0.0",
"call-bind": "^1.0.2",
"es-get-iterator": "^1.1.3",
"get-intrinsic": "^1.2.1",
"is-arguments": "^1.1.1",
"is-array-buffer": "^3.0.2",
"is-date-object": "^1.0.5",
"is-regex": "^1.1.4",
"is-shared-array-buffer": "^1.0.2",
"isarray": "^2.0.5",
"object-is": "^1.1.5",
"object-keys": "^1.1.1",
"object.assign": "^4.1.4",
"regexp.prototype.flags": "^1.5.0",
"side-channel": "^1.0.4",
"which-boxed-primitive": "^1.0.2",
"which-collection": "^1.0.1",
"which-typed-array": "^1.1.9"
}
}
}
},
"for-each": {
@ -14038,6 +14104,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",
@ -18299,6 +18380,42 @@
"fontkit": "^1.8.1",
"linebreak": "^1.0.2",
"png-js": "^1.0.0"
},
"dependencies": {
"@swc/helpers": {
"version": "0.3.17",
"resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.3.17.tgz",
"integrity": "sha512-tb7Iu+oZ+zWJZ3HJqwx8oNwSDIU440hmVMDPhpACWQWnrZHK99Bxs70gT1L2dnr5Hg50ZRWEFkQCAnOVVV0z1Q==",
"requires": {
"tslib": "^2.4.0"
}
},
"fontkit": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/fontkit/-/fontkit-1.9.0.tgz",
"integrity": "sha512-HkW/8Lrk8jl18kzQHvAw9aTHe1cqsyx5sDnxncx652+CIfhawokEPkeM3BoIC+z/Xv7a0yMr0f3pRRwhGH455g==",
"requires": {
"@swc/helpers": "^0.3.13",
"brotli": "^1.3.2",
"clone": "^2.1.2",
"deep-equal": "^2.0.5",
"dfa": "^1.2.0",
"restructure": "^2.0.1",
"tiny-inflate": "^1.0.3",
"unicode-properties": "^1.3.1",
"unicode-trie": "^2.0.0"
}
},
"restructure": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/restructure/-/restructure-2.0.1.tgz",
"integrity": "sha512-e0dOpjm5DseomnXx2M5lpdZ5zoHqF1+bqdMJUohoYVVQa7cBdnk7fdmeI6byNWP/kiME72EeTiSypTCVnpLiDg=="
},
"tslib": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
"integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q=="
}
}
},
"picocolors": {
@ -18484,9 +18601,9 @@
"dev": true
},
"restructure": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/restructure/-/restructure-2.0.1.tgz",
"integrity": "sha512-e0dOpjm5DseomnXx2M5lpdZ5zoHqF1+bqdMJUohoYVVQa7cBdnk7fdmeI6byNWP/kiME72EeTiSypTCVnpLiDg=="
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/restructure/-/restructure-3.0.0.tgz",
"integrity": "sha512-Xj8/MEIhhfj9X2rmD9iJ4Gga9EFqVlpMj3vfLnV2r/Mh5jRMryNV+6lWh9GdJtDBcBSPIqzRdfBQ3wDtNFv/uw=="
},
"reusify": {
"version": "1.0.4",

View file

@ -22,6 +22,7 @@
"homepage": "https://kianting.info/wiki/w/Project:Clo",
"devDependencies": {
"@types/chai": "^4.3.5",
"@types/fontkit": "^2.0.5",
"@types/jsdom": "^21.1.4",
"@types/mocha": "^10.0.1",
"@types/node": "^20.8.4",
@ -42,6 +43,7 @@
},
"dependencies": {
"canvas": "^2.11.2",
"fontkit": "^2.0.2",
"hyphen": "^1.7.0",
"jsdom": "^22.1.0",
"minimist": "^1.2.8",

View file

@ -1,8 +1,40 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Clo = exports.calculateTextWidthHeight = exports.hyphenTkTree = exports.filterEmptyString = exports.spacesToBreakpoint = exports.hyphenForClo = exports.splitCJKV = exports.twoReturnsToNewline = exports.ptToPx = exports.cjkvRegexPattern = exports.cjkvBlocksInRegex = exports.defaultFrameStyle = exports.defaultTextStyle = exports.A4_IN_PX = exports.Direction = void 0;
exports.Clo = exports.calculateTextWidthHeightAux = exports.calculateTextWidthHeight = exports.hyphenTkTree = exports.filterEmptyString = exports.spacesToBreakpoint = exports.hyphenForClo = exports.splitCJKV = exports.twoReturnsToNewline = exports.ptToPx = exports.cjkvRegexPattern = exports.cjkvBlocksInRegex = exports.defaultFrameStyle = exports.defaultTextStyle = exports.A4_IN_PX = exports.Direction = void 0;
const canva_1 = require("../canva");
const jsdom_1 = require("jsdom");
const fontkit = __importStar(require("fontkit"));
/**
* TYPES
*/
@ -206,38 +238,64 @@ exports.hyphenTkTree = hyphenTkTree;
* @param preprocessed
* @param defaultFontStyle
*/
function calculateTextWidthHeight(preprocessed, style) {
var dom = new jsdom_1.JSDOM(`<!DOCTYPE html><html><head></head>
<body><canvas id="canvas"></canvas></body></html>`);
try {
let canvas = dom.window.document.getElementById("canvas");
console.log(canvas);
/*if (!(canvas instanceof HTMLElement)){
throw new Error('the <canvas="canvas"> in the jsdom\'s DOM is not found.');
}*/
let context = canvas.getContext("2d");
console.log(context);
if (context == null) {
throw new Error('`canvas.getContext("2d");` can\'t be executed.');
function calculateTextWidthHeight(element, style) {
return __awaiter(this, void 0, void 0, function* () {
var res = [];
for (var i = 0; i < element.length; i++) {
res.push(yield calculateTextWidthHeightAux(element[i], style));
}
context.font = `normal normal 10pt ${style.family}`;
console.log(context.font);
let txt = `Hello john`;
console.log(txt);
let measured = context.measureText(txt);
let width = measured.width;
let height = measured.actualBoundingBoxAscent;
let depth = measured.actualBoundingBoxDescent;
console.log("width: " + width);
console.log("height: " + height);
console.log("depth: " + depth);
}
catch (error) {
console.log("Exception " + error);
}
console.log(res);
return res;
});
}
exports.calculateTextWidthHeight = calculateTextWidthHeight;
/**
* calculate the text width and Height with a given `TextStyle`
* @param preprocessed
* @param defaultFontStyle
*/
function calculateTextWidthHeightAux(element, style) {
return __awaiter(this, void 0, void 0, function* () {
var result = [];
let fontPair = (0, canva_1.fontStyleTofont)(style);
if (fontPair.path.match(/\.ttc$/)) {
var font = yield fontkit.openSync(fontPair.path, fontPair.psName);
}
else {
var font = yield fontkit.openSync(fontPair.path);
}
if (!Array.isArray(element)) {
var run = font.layout(element, undefined, undefined, undefined, "ltr");
for (var j = 0; j < run.glyphs.length; j++) {
let runGlyphsItem = run.glyphs[j];
let item = {
x: null,
y: null,
textStyle: style,
direction: Direction.LTR,
width: (runGlyphsItem.advanceWidth) * (style.size) / 1000,
height: (runGlyphsItem.bbox.maxY - runGlyphsItem.bbox.minY) * (style.size) / 1000,
content: element[j],
minX: runGlyphsItem.bbox.minX,
maxX: runGlyphsItem.bbox.maxX,
minY: runGlyphsItem.bbox.minY,
maxY: runGlyphsItem.bbox.maxY
};
result.push(item);
}
return result;
}
else if (element[0] == "bp") {
let beforeNewLine = yield calculateTextWidthHeightAux(element[1], style);
let afterNewLine = yield calculateTextWidthHeightAux(element[2], style);
return ["bp", beforeNewLine, afterNewLine];
}
else {
return calculateTextWidthHeight(element[1], style);
}
});
}
exports.calculateTextWidthHeightAux = calculateTextWidthHeightAux;
/**
* whole document-representing class
*/

View file

@ -1,7 +1,8 @@
import { isKeyObject, isStringObject } from "util/types";
import { isBoxedPrimitive, isKeyObject, isStringObject } from "util/types";
import {tkTree} from "../parser";
import {FontStyle, TextStyle, TextWeight} from "../canva";
import {FontStyle, TextStyle, TextWeight, fontStyleTofont} from "../canva";
import { JSDOM } from "jsdom";
import * as fontkit from "fontkit";
/**
* TYPES
@ -30,13 +31,21 @@ export interface FrameBox extends Box{
baseLineskip : number | null,
}
export interface CharBox extends Box{
minX: number,
maxX: number,
minY: number,
maxY: number,
}
/**
* a basic Box
* - x :
* - y :
* - textStyle :
* - direction :
* - width :
* - width : x_advance
* - content :
*/
export interface Box{
@ -257,45 +266,75 @@ export function hyphenTkTree(arr : tkTree, lang: string) : tkTree{
* @param preprocessed
* @param defaultFontStyle
*/
export function calculateTextWidthHeight(preprocessed : tkTree, style : TextStyle): void {
var dom = new JSDOM(`<!DOCTYPE html><html><head></head>
<body><canvas id="canvas"></canvas></body></html>`);
export async function calculateTextWidthHeight(element : tkTree, style : TextStyle): Promise<any> {
var res = [];
try {
let canvas = dom.window.document.getElementById("canvas");
console.log(canvas);
/*if (!(canvas instanceof HTMLElement)){
throw new Error('the <canvas="canvas"> in the jsdom\'s DOM is not found.');
}*/
let context = (<HTMLCanvasElement>canvas).getContext("2d");
console.log(context);
if (context == null){
throw new Error('`canvas.getContext("2d");` can\'t be executed.');
}
context.font = `normal normal ${style.size}px ${style.family}`;
console.log(context.font);
let txt = `Hello john`;
console.log(txt);
let measured = context.measureText(txt);
let width = measured.width;
let height = measured.actualBoundingBoxAscent;
let depth = measured.actualBoundingBoxDescent;
console.log("width: "+width);
console.log("height: "+height);
console.log("depth: "+depth);
} catch (error) {
console.log("Exception "+error);
for (var i=0; i<element.length; i++){
res.push(await calculateTextWidthHeightAux(element[i], style));
}
console.log(res);
return res;
}
/**
* calculate the text width and Height with a given `TextStyle`
* @param preprocessed
* @param defaultFontStyle
*/
export async function calculateTextWidthHeightAux(element : tkTree, style : TextStyle): Promise<any> {
var result : any = [];
let fontPair = fontStyleTofont(style);
if (fontPair.path.match(/\.ttc$/)){
var font = await fontkit.openSync(fontPair.path, fontPair.psName);
}
else{
var font = await fontkit.openSync(fontPair.path);
}
if (!Array.isArray(element)){
var run = font.layout(element, undefined, undefined, undefined, "ltr");
for (var j=0;j<run.glyphs.length;j++){
let runGlyphsItem = run.glyphs[j];
let item : CharBox = {
x : null,
y : null,
textStyle : style,
direction : Direction.LTR,
width : (runGlyphsItem.advanceWidth)*(style.size)/1000,
height : (runGlyphsItem.bbox.maxY - runGlyphsItem.bbox.minY)*(style.size)/1000,
content : element[j],
minX : runGlyphsItem.bbox.minX,
maxX : runGlyphsItem.bbox.maxX,
minY : runGlyphsItem.bbox.minY,
maxY : runGlyphsItem.bbox.maxY
}
result.push(item);
}
return result;
}else if(element[0] == "bp"){
let beforeNewLine = await calculateTextWidthHeightAux(element[1], style);
let afterNewLine = await calculateTextWidthHeightAux(element[2], style);
return ["bp", beforeNewLine, afterNewLine];
}else{
return calculateTextWidthHeight(element[1], style);
}
}