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

Allow registering custom fonts from a buffer #386

Open
mitar opened this issue Feb 13, 2014 · 4 comments
Open

Allow registering custom fonts from a buffer #386

mitar opened this issue Feb 13, 2014 · 4 comments

Comments

@mitar
Copy link
Contributor

mitar commented Feb 13, 2014

For use with jsdom package which simulates browser DOM in node.js and use node-canvas for canvas implementation a support to load fonts (truetype and openfont) from a buffer/content is needed. Because in HTML a custom font face can be specified as an URL, jsdom resolves this URL to a buffer/content by itself. So registration with buffer/content should be possible.

See jsdom/jsdom#744 for more details.

@6uliver
Copy link

6uliver commented Apr 9, 2016

Hi!

I have the same problem, but another use case.

I take a look at the code and in FontFace.cc there's a line that loads font face with FreeType:
ftError = FT_New_Face(library, *filePath, faceIdx, &ftFace);

FreeType can load font faces another way too: http://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_Open_Face

Here we can pass open arguments:
http://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_Open_Args

In this struct if we set FT_OPEN_MEMORY flag then FreeType will read memory_size bytes starting from memory_base as a font.

As soon as I have some time, I'll try to implement and test it.

@chearon
Copy link
Collaborator

chearon commented Apr 10, 2016

@6uliver if/when #715 gets merged in, you will have to use a different method. It will use Pango to lookup and draw the fonts, and FreeType isn't in the picture. You would want to send the buffer to an OS-specific call that registers the font with the operating system: CoreText, Fontconfig, or win32 APIs. Here is where I'm doing that on my PR. I haven't found a way to send a buffer to FontConfig but there are ways of doing it on both OSX and Windows

@ludbek
Copy link

ludbek commented Apr 8, 2019

Has this feature landed in node-canvas 2?

@chearon
Copy link
Collaborator

chearon commented Apr 8, 2019

No, not from a buffer. To do that on Linux we'd have to replace Pango with our own selection and font fallback code. I'd still love to do it at some point but it'd be another big overhaul.

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

No branches or pull requests

6 participants