Swapping Fonts at Runtime
Fonts can be loaded dynamically at runtime. This allows you to localize your Rive content without increasing the file size of the exported .riv file. For more information, see Loading Assets. `Fallback Fonts
When rendering text, not all glyphs (characters) may be available in the active font. This commonly occurs when:- Using custom fonts that don’t support all languages or Unicode ranges
- The embedded font is a subset of the font
- User-generated or dynamic text contains unexpected characters
For security reasons, browsers do not allow direct access to a user’s system fonts. As a result, fallback fonts must be explicitly provided for this runtime.
v2.37.1, the JS runtime provides an API for supplying fallback fonts. When a glyph cannot be rendered with the default font, Rive will invoke a callback you provide to retrieve a list of decoded fonts to try instead. Importantly, this callback must be registered before Rive begins rendering.
To start, import the RiveFont named export from the JS package and call its static method setFallbackFontCallback(), passing in your callback. The callback receives the glyph that failed to render (as a Unicode code point) and the font weight, and should return a list of fallback fonts. It may be called multiple times if successive fallback fonts also lack support for the glyph.