# FontFamily.Resolver

Artifact: [androidx.compose.ui:ui-text](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/text/font/FontFamily.kt+class:androidx.compose.ui.text.font.FontFamily.Resolver) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0) Common/AllAndroid/JVM
- Cmn

  ```
  sealed interface FontFamily.Resolver
  ```

*** ** * ** ***

Main interface for resolving `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily` into a platform-specific typeface for use in Compose-based applications.

Fonts are loaded via `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily.Resolver#resolve(androidx.compose.ui.text.font.FontFamily,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis)` from a FontFamily and a type request, and return a platform-specific typeface.

Fonts may be preloaded by calling `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily.Resolver#preload(androidx.compose.ui.text.font.FontFamily)` to avoid text reflow when async fonts load.

## Summary

| ### Public functions |
|---|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily.Resolver#preload(androidx.compose.ui.text.font.FontFamily)(fontFamily: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily)` Preloading resolves and caches all fonts reachable in a `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html>` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily.Resolver#resolve(androidx.compose.ui.text.font.FontFamily,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis)( fontFamily: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily?, fontWeight: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight, fontStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle, fontSynthesis: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontSynthesis )` Resolves a typeface using any appropriate logic for the `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily`. | Cmn |

| ### Extension functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<https://developer.android.com/reference/android/graphics/Typeface.html>` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily.Resolver.https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily.Resolver#(androidx.compose.ui.text.font.FontFamily.Resolver).resolveAsTypeface(androidx.compose.ui.text.font.FontFamily,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis)( fontFamily: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily?, fontWeight: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight, fontStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle, fontSynthesis: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontSynthesis )` Resolve a font to an Android Typeface | android |

## Public functions

### preload

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
suspend fun preload(fontFamily: FontFamily): Unit
```

Preloading resolves and caches all fonts reachable in a `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/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 `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily.Resolver#resolve(androidx.compose.ui.text.font.FontFamily,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis)`.

This method will suspend until:

1. All `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontLoadingStrategy#Async()` fonts that are reachable have completed loading, or failed to load

2. All reachable fonts in the fallback chain have been loaded and inserted into the cache

After returning, all fonts with `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontLoadingStrategy#Async()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontLoadingStrategy#OptionalLocal()` will be permanently cached. In contrast to `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily.Resolver#resolve(androidx.compose.ui.text.font.FontFamily,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis)` this method will throw when a reachable `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontLoadingStrategy#Async()` font fails to resolve.

All fonts with `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontLoadingStrategy#Blocking()` will be cached with normal eviction rules.

| Parameters |
|---|---|
| `fontFamily: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily` | the family to resolve all fonts from |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if any reachable font fails to load |

### resolve

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
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 `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily`.

`https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontListFontFamily` will always resolve using fallback chains and load using `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/Font.ResourceLoader`.

Platform specific `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily` will resolve according to platform behavior, as documented for each `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily`.

| Parameters |
|---|---|
| `fontFamily: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily? = null` | family to resolve. If `null` will use `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily#Default()` |
| `fontWeight: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight = FontWeight.Normal` | desired font weight |
| `fontStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle = FontStyle.Normal` | desired font style |
| `fontSynthesis: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontSynthesis = FontSynthesis.All` | configuration for font synthesis |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html>` | platform-specific Typeface such as android.graphics.Typeface |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if the FontFamily cannot resolve a to a typeface |

## Extension functions

### FontFamily.Resolver.resolveAsTypeface

android Artifact: [androidx.compose.ui:ui-text](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/text/font/FontFamilyResolver.android.kt+function: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 `https://developer.android.com/reference/android/graphics/Typeface.html`.

This convenience method converts State to State to avoid casting the result.

| Parameters |
|---|---|
| `fontFamily: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily? = null` | fontFamily to resolve from |
| `fontWeight: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight = FontWeight.Normal` | font weight to resolve in `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/package-summary#(androidx.compose.ui.text.font.FontFamily.Resolver).resolveAsTypeface(androidx.compose.ui.text.font.FontFamily,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis)`, will use closest match if not exact |
| `fontStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle = FontStyle.Normal` | italic or upright text, to resolve in `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/package-summary#(androidx.compose.ui.text.font.FontFamily.Resolver).resolveAsTypeface(androidx.compose.ui.text.font.FontFamily,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis)` |
| `fontSynthesis: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontSynthesis = FontSynthesis.All` | allow font synthesis if `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/package-summary#(androidx.compose.ui.text.font.FontFamily.Resolver).resolveAsTypeface(androidx.compose.ui.text.font.FontFamily,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis)` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/package-summary#(androidx.compose.ui.text.font.FontFamily.Resolver).resolveAsTypeface(androidx.compose.ui.text.font.FontFamily,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis)` don't have an exact match. This will allow "fake bold" (drawing with too wide a brush) and "fake italic" (drawing then skewing) to be applied when no exact match is present for the weight and style. |