Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for data-url fonts? #40

Open
kaldrenon opened this issue Oct 18, 2018 · 1 comment
Open

Support for data-url fonts? #40

kaldrenon opened this issue Oct 18, 2018 · 1 comment

Comments

@kaldrenon
Copy link

I don't see anything in the documentation about loading a font via data-url, so my guess is that this isn't supported, but I would like to confirm that.

If that is true, is there a suggestion for how I could convert text to a path when I only have the data-url of a font?

If data-urls can be used, could the Readme include an example for how to use it?

@GuiRitter
Copy link

They can be used, at least for a browser environment. I use it like this (based on README snippet):

// First argument is URL on web browsers, but it is file path on Node.js.
TextToSVG.load('data:application/font-ttf;base64,SGVsbG8sIFdvcmxkIQ==', function(err, textToSVG) {
    const svg = textToSVG.getSVG('hello');
    console.log(svg);
});

According to what I read around, only TTF works. Also, if you're on Node, you can use this, but you need to do some hacking:

  1. Locate your project's node_modules folder;
  2. Locate the opentype.js folder;
  3. Open opentype.js/src/opentype.js;
  4. Locate this part of the code: function load(url, callback);
  5. Change const loadFn to always be loadFromUrl;
  6. Save;
  7. Have a terminal in the opentype.js folder and run npm i then npm run build;
  8. If you had used npm start, stop it and run it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants