Closed edouard-lopez closed 7 years ago
text-to-svg
seems a straight-forward solution to position and add rotation:
const TextToSVG = require('text-to-svg');
const textToSVG = TextToSVG.loadSync();
const attributes = {fill: 'red', stroke: 'black'};
const options = {x: 0, y: 0, fontSize: 72, anchor: 'top', attributes: attributes};
const svg = textToSVG.getSVG('hello', options);
console.log(svg);
See
It works quite quickly, basic js and svg :
I used absolute positioning and text-anchor
but translation()
could be nice as well.
We could do vertical text as well.
Key methods of the module are the following :
const textToSVG = TextToSVG.loadSync(); // load default font
const textToSVG = TextToSVG.loadSync('/fonts/Noto-Sans.otf'); // local custom font
.getD(text, options = {}) : Get the path data for d attribute of path.
.getPath(text, options = {}) : Get the path element of SVG.
.getSVG(text, options = {}) : Get the SVG.
I pushed some tests I had written.
Please add a ./fonts/ directory and your base open font to the repository. I would like to give it a try this weekend, at least to output nice svg with balanced, etlegant sinograms and phonetic.
Solved.
Check out branch hugo
: https://github.com/edouard-lopez/Hanzi-Pinyin-Font/tree/hugo
Thanks I improved the method annotation()
to use
--export-text-to-path
option ;