AndroidFont
abstract class AndroidFont
constructor(
final override val loadingStrategy: FontLoadingStrategy,
val typefaceLoader: TypefaceLoader,
variationSettings: FontVariation.Settings,
) : Font
Font for use on Android.
All AndroidFont
produce an android.graphics.Typeface
which may be used to draw text on
Android. This is the main low-level API for introducing a new Font description to Compose on
Android for both blocking and async load.
You may subclass this to add new types of font descriptions that may be used in
FontListFontFamily
. For example, you can add a FontLoadingStrategy.Blocking
font that returns
a Typeface from a local resource not supported by an existing Font
. Or, you can create an
FontLoadingStrategy.Async
font that loads a font file from your server.
When introducing new font descriptors, it is recommended to follow the patterns of providing a public Font constructor and a private implementation class:
- Declare an internal or private subclass of AndroidFont
- Expose a public Font(...) constructor that returns your new type.
Font constructors are
- Regular functions named
Font
that return typeFont
- The first argument is the font name, or similar object that describes the font uniquely
- If the font has a provider, loader, or similar argument, put it after the font name.
- The last two arguments are FontWeight and FontStyle.
Examples of Font constructors:
fun Font("myIdentifier", MyFontLoader, FontWeight, FontStyle): Font
fun Font(CustomFontDescription(...), MyFontLoader, FontWeight, FontStyle): Font
fun Font(CustomFontDescription(...), FontWeight, FontStyle): Font
Parameters
loadingStrategy | loadingStrategy this font will provide in fallback chains |
typefaceLoader | a loader that knows how to load this AndroidFont , may be shared between several fonts |
Secondary Constructors
constructor(
loadingStrategy: FontLoadingStrategy,
typefaceLoader: TypefaceLoader,
) : this(loadingStrategy, typefaceLoader, FontVariation.Settings())
Properties
val : FontVariation.Settings
The settings that will be applied to this font, if supported by the font.
If the font does not support a FontVariation.Setting
, it has no effect.
Subclasses are required to apply these variation settings during font loading path on
appropriate API levels, for example by using Typeface.Builder.setFontVariationSettings
.
Subclasses may safely apply all variation settings without querying the font file. Android will ignore any unsupported axis.