🌈 Create new beautiful Compose Gradients with our new wesite ->
Interface

FontFamily.Resolver

Main interface for resolving FontFamily into a platform-specific typeface for use in Compose-based applications.

Source set: Common
public sealed interface 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.

Functions

preload

Source set: Common
public suspend fun preload(fontFamily: FontFamily)

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:

    failed to load

  1. All FontLoadingStrategy.Async fonts that are reachable have completed loading, or
  2. 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 the family to resolve all fonts from

Throws: IllegalStateException

if any reachable font fails to load

resolve

Source set: Common
public 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 family to resolve. If null will use FontFamily.Default
fontWeight desired font weight
fontStyle desired font style
fontSynthesis configuration for font synthesis

Return

platform-specific Typeface such as android.graphics.Typeface

Throws: IllegalStateException

if the FontFamily cannot resolve a to a typeface