{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

FontSynthesis

value public final class FontSynthesis


Possible options for font synthesis.

FontSynthesis is used to specify whether the system should fake bold or slanted glyphs when the FontFamily used does not contain bold or oblique Fonts.

If the font family does not include a requested FontWeight or FontStyle, the system fakes bold or slanted glyphs when the Weight or Style, respectively, or both when All is set. If this is not desired, use None to disable font synthesis.

It is possible to fake an increase of FontWeight but not a decrease. It is possible to fake a regular font slanted, but not vice versa.

FontSynthesis works the same way as the CSS font-synthesis property.

import androidx.compose.material.Text
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontSynthesis
import androidx.compose.ui.text.font.FontWeight

// The font family contains a single font, with normal weight
val fontFamily = FontFamily(
    Font(resId = R.font.myfont, weight = FontWeight.Normal)
)
// Configuring the Text composable to be bold
// Using FontSynthesis.Weight to have the system render the font bold my making the glyphs
// thicker
Text(
    text = "Demo Text",
    style = TextStyle(
        fontFamily = fontFamily,
        fontWeight = FontWeight.Bold,
        fontSynthesis = FontSynthesis.Weight
    )
)

Summary

Nested types

public static class FontSynthesis.Companion

Public methods

@NonNull String

Public methods

toString

public @NonNull String toString()