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.
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
To avoid missing or invisible glyphs, some platforms support fallback fonts. A fallback font is used automatically when the primary font cannot render a specific glyph. These are typically system fonts, which generally provide broad Unicode coverage.
Fallback fonts are not supported on the web.For security reasons, browsers do not allow the canvas to access local system files, including fonts. As a result, only fonts explicitly provided to Rive can be used.
On iOS and Android, font sizes specified for fallback fonts are ignored. Instead, the platform selects system fonts that best match the styling and animation of the text run at runtime.
React Native
Apple
Android
View the full example
See the complete fallback font example used in the React Native sample app.
To remove previously configured fallback fonts, call:
Copy
await RiveFonts.clearFallbackFonts();
This is useful if your app needs to fully reset font configuration before recreating a RiveView.
As of v6.1, on iOS and macOS, various options for fallbacks can be used. The Apple runtime provides helpers for selecting system fonts based on requested styling. Additionally, UIFonts / NSFonts can be used directly.
A default system font of regular weight and width will be used if no fallbacks have been registered.
Copy
// Early in your app lifecycle, call something similar to the following:RiveFont.fallbackFonts = [ RiveFallbackFontDescriptor(), // Use a default system font RiveFallbackFontDescriptor(design: .default, weight: .bold, width: .expanded), // Use a bold, expanded system font UIFont(name: "...", size: 20)!]// Alternatively, you can supply different fonts based on style at runtime
As of v6.4, on iOS and macOS, you can utilize a more dynamic callback-based API for returning various fonts depending on the style of any missing characters, as styled in a text run.
Copy
// As with the similar fallbackFonts API, you utilize Rive helper types// or native UIFont/NSFont typesRiveFont.fallbackFontsCallback = { style in switch style.weight { case .thin: return [ RiveFallbackFontDescriptor(weight: .thin), UIFont.systemFont(ofSize: 20, weight: .thin) ] case .bold: return [ RiveFallbackFontDescriptor(weight: .bold), UIFont.systemFont(ofSize: 20, weight: .bold) ] default: return [ RiveFallbackFontDescriptor(), UIFont.systemFont(ofSize: 20) ] }}// Alternatively, you can use the raw weight to return various fonts as wellRiveFont.fallbackFontsCallback = { style in switch style.rawWeight { case 100: return [ RiveFallbackFontDescriptor(weight: .thin), UIFont.systemFont(ofSize: 20, weight: .thin) ] case 700: return [ RiveFallbackFontDescriptor(weight: .bold), UIFont.systemFont(ofSize: 20, weight: .bold) ] default: return [ RiveFallbackFontDescriptor(), UIFont.systemFont(ofSize: 20) ] }}
As of v9.12.0, various options for fallback fonts can be used on Android.
If no fallback fonts are registered, a default system font (“sans-serif”) with a regular weight (400, NORMAL) and normal style will be used.
The Fonts class provides ways to handle and customize fonts, including retrieving system fonts, defining font options, and finding fallback fonts based on specific characteristics.
With v9.12.0, the runtime provides a new API to match missing fonts against a specific weight by extending the FontFallbackStrategy interface.This interface contains a single method:
Copy
fun getFont(weight: Fonts.Weight): List<FontBytes>
Implementers need to override this method. The user’s implementation must then be set as the current fallback strategy via FontFallbackStrategy.stylePicker.Example:
Copy
class FontFallback : AppCompatActivity(), FontFallbackStrategy { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Set the fallback strategy FontFallbackStrategy.stylePicker = this } override fun getFont(weight: Fonts.Weight): List<FontBytes> { val desiredWeight = weight.weight val fonts = listOf( Fonts.FontOpts( familyName = "sans-serif", weight = Fonts.Weight(weight = desiredWeight) // Find a matching weight font ), // Non-Latin Unicode fallback Fonts.FontOpts("NotoSansThai-Regular.ttf") ) return fonts.mapNotNull { // Filter out fonts that cannot be found on the system FontHelper.getFallbackFontBytes(it) } }}
The method returns a list of FontBytes (`ByteArray`). The runtime attempts to match the character using the fonts in the list in a first-in, first-out (FIFO) order.Fallback fonts can also be set using Rive.setFallbackFont(), with optional font preferences defined in Fonts.FontOpts. These fonts are tried only after attempting the ones returned by FontFallbackStrategy.getFont().
Use FontHelper.getFallbackFont() to find a suitable fallback font based on specified options. Returns a Fonts.Font object or null if no match is found.Example: