parlr / ruby-font-creator

Generate rich Unicode open fonts with custom annotations, transliterations, pronunciations.
21 stars 3 forks source link

Convert text to SVG path -- solved but to integrate #5

Closed edouard-lopez closed 7 years ago

edouard-lopez commented 8 years ago
edouard-lopez commented 8 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);
hugolpz commented 7 years ago

See

It works quite quickly, basic js and svg : screenshot from 2016-12-08 16-07-45

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.
edouard-lopez commented 7 years ago

I pushed some tests I had written.

hugolpz commented 7 years ago

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.

hugolpz commented 7 years ago

Solved. Check out branch hugo : https://github.com/edouard-lopez/Hanzi-Pinyin-Font/tree/hugo

edouard-lopez commented 7 years ago

Thanks I improved the method annotation() to use like you