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

FontFamily

Source set: Common
public sealed class FontFamily protected constructor(canLoadSynchronously: Boolean)

Properties

canLoadSynchronously

Source set: Common
@Suppress("CanBePrimaryConstructorProperty") // for deprecation
    @get:Deprecated(
        message = "Unused property that has no meaning. Do not use.",
        level = DeprecationLevel.ERROR,
    )
    public val canLoadSynchronously: Boolean = canLoadSynchronously

Members

Resolver

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

Companion

Source set: Common
public companion object

Properties

Default

Source set: Common
public val Default: SystemFontFamily = DefaultFontFamily()

The platform default font.

SansSerif

Source set: Common
public val SansSerif: GenericFontFamily =
            GenericFontFamily("sans-serif", "FontFamily.SansSerif")

Font family with low contrast and plain stroke endings.

See CSS sans-serif

Serif

Source set: Common
public val Serif: GenericFontFamily = GenericFontFamily("serif", "FontFamily.Serif")

The formal text style for scripts.

See CSS serif

Monospace

Source set: Common
public val Monospace: GenericFontFamily =
            GenericFontFamily("monospace", "FontFamily.Monospace")

Font family where glyphs have the same fixed width.

See CSS monospace

Cursive

Source set: Common
public val Cursive: GenericFontFamily = GenericFontFamily("cursive", "FontFamily.Cursive")

Cursive, hand-written like font family.

If the device doesn't support this font family, the system will fallback to the default font.

See CSS cursive