# androidx.compose.ui.text.googlefonts

## Classes

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont` | A downloadable font from fonts.google.com |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont.Provider` | Attributes used to create a `https://developer.android.com/reference/kotlin/androidx/core/provider/FontRequest` for a `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont` based `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/Font`. |

## Top-level functions summary

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/Font` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/package-summary#Font(androidx.compose.ui.text.googlefonts.GoogleFont,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontVariation.Settings)( googleFont: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont, weight: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight, style: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle, variationSettings: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontVariation.Settings )` Load a font from Google Fonts via Downloadable Fonts using the default `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont.Provider`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/Font` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/package-summary#Font(androidx.compose.ui.text.googlefonts.GoogleFont,androidx.compose.ui.text.googlefonts.GoogleFont.Provider,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontVariation.Settings)( googleFont: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont, fontProvider: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont.Provider, weight: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight, style: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle, variationSettings: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontVariation.Settings )` Load a font from Google Fonts via Downloadable Fonts. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/package-summary#GoogleFont(android.content.Context,kotlin.Int)(context: https://developer.android.com/reference/android/content/Context.html, fontXml: @https://developer.android.com/reference/kotlin/androidx/annotation/FontRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Load a Google Font from XML |

## Extension functions summary

|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/WorkerThread https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont.Provider.https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/package-summary#(androidx.compose.ui.text.googlefonts.GoogleFont.Provider).isAvailableOnDevice(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)` Check if the downloadable fonts provider is available on device. |

## Top-level functions

### Font

Artifact: [androidx.compose.ui:ui-text-google-fonts](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/text/googlefonts/GoogleFont.kt+function:Font) Added in [1.12.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.12.0)

```
fun Font(
    googleFont: GoogleFont,
    weight: FontWeight = FontWeight.Normal,
    style: FontStyle = FontStyle.Normal,
    variationSettings: FontVariation.Settings = FontVariation.Settings(weight, style)
): Font
```

Load a font from Google Fonts via Downloadable Fonts using the default `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont.Provider`.

If the requested `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont` is available as a variable font in Google Fonts and the non-empty `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontVariation.Settings` is provided for `variationSettings`, the returned `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/package-summary#Font(androidx.compose.ui.text.googlefonts.GoogleFont,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontVariation.Settings)` will be a variable font. Variable font settings are only applied on API level 26 and above.

This overload function simplifies the setup by automatically configuring the `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont.Provider` with the default font certificates required to fetch fonts from Google Play Services.

```kotlin
import androidx.compose.material3.Text
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontVariation
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.googlefonts.Font
import androidx.compose.ui.text.googlefonts.GoogleFont

val fontFamily =
    FontFamily(
        Font(
            googleFont = GoogleFont("Lobster Two"),
            weight = FontWeight.W600,
            style = FontStyle.Italic,
            variationSettings = FontVariation.Settings(),
        )
    )

Text("Hello World", style = TextStyle(fontFamily = fontFamily))
```

```kotlin
import androidx.compose.material3.Text
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontVariation
import androidx.compose.ui.text.googlefonts.Font
import androidx.compose.ui.text.googlefonts.GoogleFont

val fontVariationSettings =
    FontVariation.Settings(
        FontVariation.grade(0),
        FontVariation.weight(900),
        FontVariation.slant(0f),
        FontVariation.width(100f),
    )

val fontFamily =
    FontFamily(
        Font(
            googleFont = GoogleFont("Google Sans Flex"),
            variationSettings = fontVariationSettings,
        )
    )

Text("Hello World", style = TextStyle(fontFamily = fontFamily))
```

| Parameters |
|---|---|
| `googleFont: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont` | A font to load from fonts.google.com |
| `weight: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight = FontWeight.Normal` | font weight to load |
| `style: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle = FontStyle.Normal` | italic or normal font |
| `variationSettings: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontVariation.Settings = FontVariation.Settings(weight, style)` | The `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontVariation.Settings` to apply to the variable font. |

### Font

Artifact: [androidx.compose.ui:ui-text-google-fonts](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/text/googlefonts/GoogleFont.kt+function:Font) Added in [1.12.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.12.0)

```
fun Font(
    googleFont: GoogleFont,
    fontProvider: GoogleFont.Provider,
    weight: FontWeight = FontWeight.Normal,
    style: FontStyle = FontStyle.Normal,
    variationSettings: FontVariation.Settings = FontVariation.Settings()
): Font
```

Load a font from Google Fonts via Downloadable Fonts.

This function allows specifying a custom font provider. For most common use cases with Google Play Services, consider using the overload that omits the `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/package-summary#Font(androidx.compose.ui.text.googlefonts.GoogleFont,androidx.compose.ui.text.googlefonts.GoogleFont.Provider,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontVariation.Settings)` parameter.

If the requested `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont` is available as a variable font in Google Fonts and the non-empty `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontVariation.Settings` is provided for `variationSettings`, the returned `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/package-summary#Font(androidx.compose.ui.text.googlefonts.GoogleFont,androidx.compose.ui.text.googlefonts.GoogleFont.Provider,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontVariation.Settings)` will be a variable font. Variable font settings are only applied on API level 26 and above.

```kotlin
import androidx.compose.material3.Text
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.googlefonts.Font
import androidx.compose.ui.text.googlefonts.GoogleFont
import androidx.compose.ui.text.googlefonts.R

val fontProvider =
    GoogleFont.Provider(
        providerAuthority = "com.google.android.gms.fonts",
        providerPackage = "com.google.android.gms",
        certificates = R.array.com_google_android_gms_fonts_certs,
    )

val fontFamily =
    FontFamily(
        Font(
            googleFont = GoogleFont("Google Sans Flex"),
            weight = FontWeight.W600,
            fontProvider = fontProvider,
        )
    )

Text("Hello World", style = TextStyle(fontFamily = fontFamily))
```

```kotlin
import androidx.compose.material3.Text
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontVariation
import androidx.compose.ui.text.googlefonts.Font
import androidx.compose.ui.text.googlefonts.GoogleFont
import androidx.compose.ui.text.googlefonts.R

val fontVariationSettings =
    FontVariation.Settings(
        FontVariation.grade(0),
        FontVariation.weight(900),
        FontVariation.slant(0f),
        FontVariation.width(100f),
    )

val fontProvider =
    GoogleFont.Provider(
        providerAuthority = "com.google.android.gms.fonts",
        providerPackage = "com.google.android.gms",
        certificates = R.array.com_google_android_gms_fonts_certs,
    )

val fontFamily =
    FontFamily(
        Font(
            googleFont = GoogleFont("Google Sans Flex"),
            fontProvider = fontProvider,
            variationSettings = fontVariationSettings,
        )
    )

Text("Hello World", style = TextStyle(fontFamily = fontFamily))
```

| Parameters |
|---|---|
| `googleFont: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont` | A font to load from fonts.google.com |
| `fontProvider: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/googlefonts/GoogleFont.Provider` | configuration for downloadable font provider |
| `weight: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight = FontWeight.Normal` | font weight to load |
| `style: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle = FontStyle.Normal` | italic or normal font |
| `variationSettings: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontVariation.Settings = FontVariation.Settings()` | The `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontVariation.Settings` to apply to the variable font. |

### GoogleFont

Artifact: [androidx.compose.ui:ui-text-google-fonts](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/text/googlefonts/XmlLoader.kt+function:GoogleFont) Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.6.0)

```
fun GoogleFont(context: Context, fontXml: @FontRes Int): GoogleFont
```

Load a Google Font from XML

This will load only the name and besteffort parameters.

Compared to the string constructor, this loader adds additional overhead. New code should prefer to use `GoogleFont(name: String)`.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | to load font from |
| `fontXml: @https://developer.android.com/reference/kotlin/androidx/annotation/FontRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | fontRes to load |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the fontRes does not exist or is not an xml GoogleFont |

## Extension functions

### GoogleFont.Provider.isAvailableOnDevice

Artifact: [androidx.compose.ui:ui-text-google-fonts](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/text/googlefonts/GoogleFont.kt+function:isAvailableOnDevice) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
@WorkerThread
fun GoogleFont.Provider.isAvailableOnDevice(context: Context): Boolean
```

Check if the downloadable fonts provider is available on device.

This is not necessary for normal usage, but may be useful in debugging downloadable fonts behavior.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | for looking up font provider in |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the provider is usable for downloadable fonts, false if it's not found |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if the provider is on device, but certificates don't match |