Fonts
Loading custom fonts for use with the Canvas API
It is possible to load your own font files into an nx.js application, and then render your fonts using canvas rendering mode.
Loading a font
To load a font, you'll need to create an instance of the
FontFace
class,
by providing the name of the font and the font data as an ArrayBuffer
:
The FreeType 2 library is used to renders fonts,
so any font file format which is supported by FreeType 2 (typically .ttf
or .otf
) will work with nx.js.
Registering a font
Once you've loaded a font, you'll need to register it with the
FontFaceSet
registry.
The fonts
global is available for this purpose,
similar to how you would register a font in a "web worker" context.
The fonts
registry is a global object that contains all the fonts that have been
loaded into the application. You can use this registry to render text to the screen
using the Canvas API.