FontFamily.Resolver
-
Cmn
sealed interface FontFamily.Resolver
Main interface for resolving FontFamily into a platform-specific typeface for use in Compose-based applications.
Fonts are loaded via Resolver.resolve from a FontFamily and a type request, and return a platform-specific typeface.
Fonts may be preloaded by calling Resolver.preload to avoid text reflow when async fonts load.
Summary
Public functions |
||
|---|---|---|
suspend Unit |
preload(fontFamily: FontFamily)Preloading resolves and caches all fonts reachable in a |
Cmn
|
State<Any> |
resolve(Resolves a typeface using any appropriate logic for the |
Cmn
|
Extension functions |
||
|---|---|---|
State<Typeface> |
FontFamily.Resolver.resolveAsTypeface(Resolve a font to an Android Typeface |
android
|
Public functions
preload
suspend fun preload(fontFamily: FontFamily): Unit
Preloading resolves and caches all fonts reachable in a FontFamily.
It checks the cache first, and if there is a miss, it will fetch from the network.
Fonts are consider reachable if they are the first entry in the fallback chain for any call to resolve.
This method will suspend until:
-
All
FontLoadingStrategy.Asyncfonts that are reachable have completed loading, or failed to load -
All reachable fonts in the fallback chain have been loaded and inserted into the cache
After returning, all fonts with FontLoadingStrategy.Async and FontLoadingStrategy.OptionalLocal will be permanently cached. In contrast to resolve this method will throw when a reachable FontLoadingStrategy.Async font fails to resolve.
All fonts with FontLoadingStrategy.Blocking will be cached with normal eviction rules.
| Parameters | |
|---|---|
fontFamily: FontFamily |
the family to resolve all fonts from |
| Throws | |
|---|---|
kotlin.IllegalStateException |
if any reachable font fails to load |
resolve
fun resolve(
fontFamily: FontFamily? = null,
fontWeight: FontWeight = FontWeight.Normal,
fontStyle: FontStyle = FontStyle.Normal,
fontSynthesis: FontSynthesis = FontSynthesis.All
): State<Any>
Resolves a typeface using any appropriate logic for the FontFamily.
FontListFontFamily will always resolve using fallback chains and load using Font.ResourceLoader.
Platform specific FontFamily will resolve according to platform behavior, as documented for each FontFamily.
| Parameters | |
|---|---|
fontFamily: FontFamily? = null |
family to resolve. If |
fontWeight: FontWeight = FontWeight.Normal |
desired font weight |
fontStyle: FontStyle = FontStyle.Normal |
desired font style |
fontSynthesis: FontSynthesis = FontSynthesis.All |
configuration for font synthesis |
| Throws | |
|---|---|
kotlin.IllegalStateException |
if the FontFamily cannot resolve a to a typeface |
Extension functions
resolveAsTypeface
fun FontFamily.Resolver.resolveAsTypeface(
fontFamily: FontFamily? = null,
fontWeight: FontWeight = FontWeight.Normal,
fontStyle: FontStyle = FontStyle.Normal,
fontSynthesis: FontSynthesis = FontSynthesis.All
): State<Typeface>
Resolve a font to an Android Typeface
On Android, font resolution always produces an android.graphics.Typeface.
This convenience method converts State
| Parameters | |
|---|---|
fontFamily: FontFamily? = null |
fontFamily to resolve from |
fontWeight: FontWeight = FontWeight.Normal |
font weight to resolve in |
fontStyle: FontStyle = FontStyle.Normal |
italic or upright text, to resolve in |
fontSynthesis: FontSynthesis = FontSynthesis.All |
allow font synthesis if |