androidx.compose.ui.text.font
Interfaces
Font |
The interface of the font resource. |
Typeface |
A class that can be used for changing the font used in text. |
Classes
FileBasedFontFamily |
A base class of FontFamilys that is created from file sources. |
FontFamily |
The base class of the font families. |
FontListFontFamily |
Defines a font family with list of Font. |
FontWeight |
The thickness of the glyphs, in a range of 1,1000. |
GenericFontFamily |
Defines a font family with an generic font family name. |
LoadedFontFamily |
Defines a font family that is already loaded Typeface. |
ResourceFont |
Defines a font to be used while rendering text with resource ID. |
SystemFontFamily |
A base class of FontFamilys installed on the system. |
Enums
FontStyle | |
FontSynthesis |
Possible options for font synthesis. |
Top-level functions summary
Font |
font(resId: Int, weight: FontWeight = FontWeight.Normal, style: FontStyle = FontStyle.Normal) Creates a Font with using resource ID. |
FontFamily |
fontFamily(typeface: Typeface) Creates a FontFamily from Android Typeface. |
FontListFontFamily |
fontFamily(fonts: List<Font>) Construct a font family that contains list of custom font files. |
FontListFontFamily |
fontFamily(vararg fonts: Font) Construct a font family that contains list of custom font files. |
LoadedFontFamily |
fontFamily(typeface: Typeface) Construct a font family that contains loaded font family: Typeface. |
FontWeight |
lerp(start: FontWeight, stop: FontWeight, fraction: Float) Linearly interpolate between two font weights. |
Typeface |
typeface(context: Context, fontFamily: FontFamily, necessaryStyles: List<Pair<FontWeight, FontStyle>>? = null) Android specific Typeface builder function from FontFamily. |
Typeface |
Returns a Compose androidx.compose.ui.text.font.Typeface from Android Typeface. |
Extension functions summary
For Font | |
FontListFontFamily |
Create a FontFamily from this single font. |
Top-level functions
font
@Stable fun font(
resId: Int,
weight: FontWeight = FontWeight.Normal,
style: FontStyle = FontStyle.Normal
): Font
Creates a Font with using resource ID.
Parameters | |
---|---|
resId: Int | The resource ID of the font file in font resources. i.e. "R.font.myfont". |
weight: FontWeight = FontWeight.Normal | The weight of the font. The system uses this to match a font to a font request that is given in a androidx.compose.ui.text.SpanStyle. |
style: FontStyle = FontStyle.Normal | The style of the font, normal or italic. The system uses this to match a font to a font request that is given in a androidx.compose.ui.text.SpanStyle. |
See Also
fontFamily
fun fontFamily(typeface: Typeface): FontFamily
Creates a FontFamily from Android Typeface.
Parameters | |
---|---|
typeface: Typeface | Android Typeface instance |
fontFamily
@Stable fun fontFamily(fonts: List<Font>): FontListFontFamily
Construct a font family that contains list of custom font files.
Parameters | |
---|---|
fonts: List<Font> | list of font files |
fontFamily
@Stable fun fontFamily(vararg fonts: Font): FontListFontFamily
Construct a font family that contains list of custom font files.
Parameters | |
---|---|
vararg fonts: Font | list of font files |
fontFamily
fun fontFamily(typeface: Typeface): LoadedFontFamily
Construct a font family that contains loaded font family: Typeface.
Parameters | |
---|---|
typeface: Typeface | A typeface instance. |
lerp
fun lerp(
start: FontWeight,
stop: FontWeight,
fraction: Float
): FontWeight
Linearly interpolate between two font weights.
The fraction argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning start (or something equivalent to start), 1.0 meaning that the interpolation has finished, returning stop (or something equivalent to stop), and values in between meaning that the interpolation is at the relevant point on the timeline between start and stop. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid (and can easily be generated by curves).
Values for fraction are usually obtained from an Animation, such as
an AnimationController
.
typeface
fun typeface(
context: Context,
fontFamily: FontFamily,
necessaryStyles: List<Pair<FontWeight, FontStyle>>? = null
): Typeface
Android specific Typeface builder function from FontFamily.
You can pass necessaryStyles for loading only specific styles. The font style matching happens only with the loaded Typeface.
This function caches the internal native Typeface but always create the new Typeface object. Caller should cache if necessary.
Parameters | |
---|---|
context: Context | the context to be used for loading Typeface. |
fontFamily: FontFamily | the font family to be loaded |
necessaryStyles: List<Pair<FontWeight, FontStyle>>? = null | optional style filter for loading subset of fontFamily. null means load all fonts in fontFamily. |
Return | |
---|---|
A loaded Typeface. |
typeface
fun typeface(typeface: Typeface): Typeface
Returns a Compose androidx.compose.ui.text.font.Typeface from Android Typeface.
Parameters | |
---|---|
typeface: Typeface | Android Typeface instance |
Extension functions
asFontFamily
@Stable fun Font.asFontFamily(): FontListFontFamily
Create a FontFamily from this single font.