https://github.com/dshatz/compose-font
Load TTF variable fonts in Compose Multiplatform
https://github.com/dshatz/compose-font
android compose jvm kotlin multiplatform multiplatform-kotlin-library
Last synced: 3 months ago
JSON representation
Load TTF variable fonts in Compose Multiplatform
- Host: GitHub
- URL: https://github.com/dshatz/compose-font
- Owner: dshatz
- License: gpl-3.0
- Created: 2024-06-25T09:16:38.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-26T08:52:30.000Z (12 months ago)
- Last Synced: 2025-01-22T19:45:59.701Z (5 months ago)
- Topics: android, compose, jvm, kotlin, multiplatform, multiplatform-kotlin-library
- Language: Kotlin
- Homepage:
- Size: 219 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Load TTF variable font from Compose Multiplatform
Make loading differently weighted fonts from one .ttf file easier. Hopefully this will be supported in Compose Multiplatform natively sometime in the future.
1. Put a single variable .ttf font file in `composeResources/font`.
2. `val fontFamily by loadFont(Res.font.your_font, FontWeight(500))`
3. `Text("The quick brown fox jumps over the lazy dog", fontFamily = fontFamily)`## Supported platforms
- JVM
- Android## Usage

```kotlin
val commonMain by getting {
dependencies {
implementation("com.dshatz.compose-mpp:compose-font:")
}
}
```## Implementation notes
### JVM
On JVM, jetbrains skia api is used.
### Android
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`.## Contributing
Merge requests welcome, especially for adding iOS support.