Skip to content

Commit

Permalink
Support supplying mobile fallback fonts by style with caching
Browse files Browse the repository at this point in the history
This pull request builds on top of fallback font support on iOS by including the ability to provide fallback fonts based on the styling of the missing character. Currently, the style information only contains weight. This weight is grabbed by calling `getAxisValue`. According to Luigi, this is a linear search, so perhaps there's room for a performance optimization later on.

There is one lower-level C++ change: `gFallbackProc` returns the font for the missing character, in addition _to_ the missing character (as a second parameter). This font will be used to generate the requested styling within the iOS runtime.

This adds a new class property to `RiveFont`: `fallbackFontCallback` (whose name I'm open to changing). This is a block (i.e closure) that will be called when a fallback font is requested. It supplies the styling of the missing character so that, for example, different fonts can be used based on the weight of the missing character. For example usage, see `SwiftFallbackFonts.swift`. This provider is what's used under-the-hood, and utilizes the pre-existing `fallbackFonts` class property

The "trickiest" bit here is the caching. NSDictionary requires equatable / hashable types as keys, and we want to minimize additional generation of a Rive font, so we cache any used fonts in a wrapper type, used as the value. When new fallback fonts are provided, either directly or when a new provider block is set, the cache will be reset. Once the weight is determined, generating the right key is as simple as calling the right initializer, and when set, generating the right value is simple as calling the right initializer with the created Rive font.

Finally, `RiveFactory` was getting a little bloated, so I did a little file cleanup.

This pull requests also includes Android support from #8621

Diffs=
7986d64d83 Support supplying mobile fallback fonts by style with caching (#8396)
fb8ecf3552 fixed url for canddiates and goldens in not pack mode (#8649)
4b82cf2e91 treat remapped animations as always settled (#8643)
d7db032e08 update measure function to use its text wrap and max size (#8640)
406e938c3d add support for standalone custom properties to bind values to (#8634)
8f3b760a6c Dx11 support (#8577)

Co-authored-by: David Skuza <david@rive.app>
Co-authored-by: Umberto <usonnino@gmail.com>
Co-authored-by: Umberto Sonnino <umberto@rive.app>
  • Loading branch information
4 people committed Nov 27, 2024
1 parent 5a1d9a3 commit 1848316
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
de19b09fb38710fae823049192108cae2e56001e
7986d64d8371531716ea3f038dcbec5da187e6cd
3 changes: 2 additions & 1 deletion premake5_rive_plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ do
'HB_NO_BITMAP',
'HB_NO_BUFFER_SERIALIZE',
'HB_NO_SETLOCALE',
'HB_NO_STYLE',
'HB_NO_VERTICAL',
'HB_NO_LAYOUT_COLLECT_GLYPHS',
'HB_NO_LAYOUT_RARELY_USED',
Expand Down Expand Up @@ -197,6 +196,8 @@ do
harfbuzz .. '/src/hb-subset.cc',
harfbuzz .. '/src/hb-ucd.cc',
harfbuzz .. '/src/hb-unicode.cc',
harfbuzz .. '/src/hb-style.h',
harfbuzz .. '/src/hb-style.cc',
})

links({ 'rive_sheenbidi' })
Expand Down

0 comments on commit 1848316

Please sign in to comment.