Make loading differently weighted fonts from one .ttf file easier. Hopefully this will be supported in Compose Multiplatform natively sometime in the future.
- Put a single variable .ttf font file in
composeResources/font
. val fontFamily by loadFont(Res.font.your_font, FontWeight(500))
Text("The quick brown fox jumps over the lazy dog", fontFamily = fontFamily)
- JVM
- Android
val commonMain by getting {
dependencies {
implementation("com.dshatz.compose-mpp:compose-font:<version>")
}
}
On JVM, jetbrains skia api is used.
On Android, the font will be written to app filesDir
once and then loaded into memory and copied with variationSettings
whenever the fontWeight
changes.
Unfortunately there is no way to directly load a font on android from composeResources/ folder while also applying variationSettings
.
Merge requests welcome, especially for adding iOS support.