Use my fork of hersheytextjs with experimental multiline support

This commit is contained in:
mmcwilliams 2021-05-05 19:51:20 -04:00
parent 50f515f49f
commit d40edeff47
5 changed files with 40 additions and 21 deletions

1
sticky/.gitignore vendored
View File

@ -1 +1,2 @@
node_modules
test.svg

View File

@ -10,7 +10,7 @@
"dependencies": {
"argparse": "^2.0.1",
"fs-extra": "^9.1.0",
"hersheytext": "^2.0.0"
"hersheytext": "github:mattmcw/hersheytextjs"
}
},
"node_modules/argparse": {
@ -133,8 +133,8 @@
},
"node_modules/hersheytext": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/hersheytext/-/hersheytext-2.0.0.tgz",
"integrity": "sha512-t8UPIWKpPKffT7QcGG8AWXen4zVpfMdlO5uq3cE8aNQGFxSEV/HoGAIFki6lioNi35WG73gaeW4VY3avxsJIrA==",
"resolved": "git+ssh://git@github.com/mattmcw/hersheytextjs.git#5aab4b86180419170157d36f14571605c587cb06",
"license": "MIT",
"dependencies": {
"cheerio": "^0.22.0"
},
@ -253,7 +253,21 @@
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"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/string_decoder": {
"version": "1.3.0",
@ -385,9 +399,8 @@
"integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw=="
},
"hersheytext": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/hersheytext/-/hersheytext-2.0.0.tgz",
"integrity": "sha512-t8UPIWKpPKffT7QcGG8AWXen4zVpfMdlO5uq3cE8aNQGFxSEV/HoGAIFki6lioNi35WG73gaeW4VY3avxsJIrA==",
"version": "git+ssh://git@github.com/mattmcw/hersheytextjs.git#5aab4b86180419170157d36f14571605c587cb06",
"from": "hersheytext@github:mattmcw/hersheytextjs",
"requires": {
"cheerio": "^0.22.0"
}

View File

@ -11,6 +11,6 @@
"dependencies": {
"argparse": "^2.0.1",
"fs-extra": "^9.1.0",
"hersheytext": "^2.0.0"
"hersheytext": "github:mattmcw/hersheytextjs"
}
}

View File

@ -40,16 +40,6 @@ async function loadFont (fontPath) {
}
*/
function textPos (str) {
const len = str.length;
const w = len * W;
const h = H;
const x = (75.0 - w) / 2.0;
const y = (75.0 - h) / 2.0;
return { x : x * UNIT, y : y * UNIT };
}
async function main () {
const fontPath = args.font;
const text = args.text;
@ -66,8 +56,8 @@ async function main () {
console.error(err);
}
//options.pos = { x: 0, y: 0 };
options.pos = textPos(text);
options.pos = { x: 10, y: 10 };
//options.pos = textPos(text);
data = hershey.renderTextSVG(text, options);
//console.log(`${header}\n${data}\n${footer}`)

15
sticky/test.js Normal file
View File

@ -0,0 +1,15 @@
const hershey = require('hersheytext');
const fs = require('fs');
const options = {
font: 'ems_nixish',
scale: 0.05,
pos : { x: 0, y: 0 },
lineHeight: 1000
};
const header = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="305mm" width="229mm" version="1.1">';
const data = hershey.renderTextSVG('Take a Look, if you Will.\nNew line', options);
const footer = '</svg>';
fs.writeFileSync('test.svg', `${header}\n${data}\n${footer}`);