hersheytextjs icon indicating copy to clipboard operation
hersheytextjs copied to clipboard

Add browser support for SVG fonts

Open jvolker opened this issue 4 years ago • 2 comments

I've developed a browser-based SVG font renderer: https://github.com/jvolker/svg-font-renderer It borrows a lot of code from this repository. Thanks for writing and sharing it. :)

Instead of using a modified version of this package, it would be great to use it as a dependency. Unfortunately, that's not possible at the moment, as hersheytextjs requires fs which is not available in the browser.

This is how I've adapted it to be used with SVG fonts in the browser: https://github.com/jvolker/svg-font-renderer/blob/master/src/lib/svgFontRenderer.js I've basically skipped fs and passed the SVG data directly from my main application.

Would be great to see this in the future. 👍

jvolker avatar Jan 24 '21 17:01 jvolker

I guess it would be okay to remove fs from this package entirely and let the user decide how to get the font data.

jvolker avatar Jan 26 '21 16:01 jvolker

I think support for SVG fonts would be great. I'm working on a project at https://github.com/markroland/axidraw-sketchpad where I'd like to use EMS Tech so I went ahead and wrote a script to parse the SVG XML to the JSON format used in this repo. I'm not using this repo directly because I prefer a vanilla Javascript approach. Thank you techninja for this repo!

Here's my script to convert SVG to JSON data. It scales the text down and flips vertically so that it should output code that matches the other JSON-based fonts in this repo. I have not evaluated it thoroughly though. Also, it's in PHP simply because that's how I could get this done the fastest. I hope it helps someone else, too.

https://gist.github.com/markroland/228352a6fdec1ab4190339b6e10d36be

markroland avatar Feb 07 '21 21:02 markroland