From d40edeff479f2924b441801b9edd9924a3222bb8 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Wed, 5 May 2021 19:51:20 -0400 Subject: [PATCH] Use my fork of hersheytextjs with experimental multiline support --- sticky/.gitignore | 3 ++- sticky/package-lock.json | 27 ++++++++++++++++++++------- sticky/package.json | 2 +- sticky/sticky.js | 14 ++------------ sticky/test.js | 15 +++++++++++++++ 5 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 sticky/test.js diff --git a/sticky/.gitignore b/sticky/.gitignore index b512c09..1f4f0ee 100644 --- a/sticky/.gitignore +++ b/sticky/.gitignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +test.svg \ No newline at end of file diff --git a/sticky/package-lock.json b/sticky/package-lock.json index a1d58ba..93f1626 100644 --- a/sticky/package-lock.json +++ b/sticky/package-lock.json @@ -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" } diff --git a/sticky/package.json b/sticky/package.json index 8167169..c0ca1f9 100644 --- a/sticky/package.json +++ b/sticky/package.json @@ -11,6 +11,6 @@ "dependencies": { "argparse": "^2.0.1", "fs-extra": "^9.1.0", - "hersheytext": "^2.0.0" + "hersheytext": "github:mattmcw/hersheytextjs" } } diff --git a/sticky/sticky.js b/sticky/sticky.js index 6a335f4..07db756 100755 --- a/sticky/sticky.js +++ b/sticky/sticky.js @@ -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}`) diff --git a/sticky/test.js b/sticky/test.js new file mode 100644 index 0000000..cb8d154 --- /dev/null +++ b/sticky/test.js @@ -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 = ''; +const data = hershey.renderTextSVG('Take a Look, if you Will.\nNew line', options); +const footer = ''; + +fs.writeFileSync('test.svg', `${header}\n${data}\n${footer}`); \ No newline at end of file