Alex Styl
06/11/2025, 1:59 PMAlex Styl
06/11/2025, 2:02 PMFrank Bouwens
06/12/2025, 9:26 PMAlex Styl
06/13/2025, 7:07 AMOleksandr Karpovich [JB]
06/13/2025, 10:03 AMAlex Styl
06/13/2025, 10:18 AMvariationSettings = FontVariation.Settings(FontVariation.weight(400))
parameter to make it work?
right now i am getting squares without itAlex Styl
06/13/2025, 10:18 AMOleksandr Karpovich [JB]
06/13/2025, 11:33 AMdo i have to use theyes, it looks correct. Here is a code of the example in our demo project: https://github.com/JetBrains/compose-multiplatform-core/blob/367bb867d66f0f1d2ce7d[…]tlin/androidx/compose/mpp/demo/components/text/VariableFonts.ktvariationSettings = FontVariation.Settings(FontVariation.weight(400))
I am also getting squares for non variable fontsHow do you set a font? Do you use Compose Resources?
Alex Styl
06/13/2025, 11:37 AMAlex Styl
06/13/2025, 11:37 AMAlex Styl
06/13/2025, 2:21 PMAlex Styl
06/13/2025, 2:30 PMOleksandr Karpovich [JB]
06/13/2025, 2:37 PMAlex Styl
06/13/2025, 2:39 PMOleksandr Karpovich [JB]
06/13/2025, 2:40 PMAlex Styl
06/13/2025, 2:45 PMwiktor
07/11/2025, 10:04 AM@Composable
fun AppTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable() () -> Unit
) {
val colorScheme = when {
darkTheme -> darkScheme
else -> lightScheme
}
val interFontFamily = FontFamily(
Font(
Res.font.inter_var,
variationSettings = FontVariation.Settings(FontVariation.weight(400))
)
)
val typography = Typography(
bodyLarge = TextStyle(fontFamily = interFontFamily),
bodyMedium = TextStyle(fontFamily = interFontFamily),
bodySmall = TextStyle(fontFamily = interFontFamily),
titleLarge = TextStyle(fontFamily = interFontFamily),
titleMedium = TextStyle(fontFamily = interFontFamily),
titleSmall = TextStyle(fontFamily = interFontFamily),
labelLarge = TextStyle(fontFamily = interFontFamily),
labelMedium = TextStyle(fontFamily = interFontFamily),
labelSmall = TextStyle(fontFamily = interFontFamily),
displayLarge = TextStyle(fontFamily = interFontFamily),
displayMedium = TextStyle(fontFamily = interFontFamily),
displaySmall = TextStyle(fontFamily = interFontFamily)
)
MaterialTheme(
colorScheme = colorScheme,
typography = typography,
content = content
)
}
Oleksandr Karpovich [JB]
07/11/2025, 3:33 PMAppTheme
would recompose after the font file has been loaded.
And I expect that Typography
instance would be recreated too. But maybe it doesn't happen.
I think it's worth trying to preload the font on web: https://github.com/JetBrains/compose-multiplatform/blob/master/components/resources/demo/shared/src/wasmJsMain/kotlin/main.wasm.kt#L31 and proceed to the rest of the app only after the font is ready.
_
In your case:
// somewhere in your web main.kt
if (font1 != null && font2 != null && emojiFont != null && fontsFallbackInitialiazed) {
AppTheme(..., content)
}
I think you don't need fontFamilyResolver.preload
in this case. Only val font1 by preloadFont(Res.font.Workbench_Regular)
,
use the overload with variationSettings - https://github.com/JetBrains/compose-multiplatform/blob/master/components/resource[…]/webMain/kotlin/org/jetbrains/compose/resources/Resource.web.ktwiktor
07/12/2025, 8:56 AM@OptIn(ExperimentalComposeUiApi::class, ExperimentalResourceApi::class)
fun main() {
ComposeViewport(document.body!!) {
val font by preloadFont(Res.font.inter_var)
if (font != null) {
App()
} else {
println("Font not loaded")
}
}
}
but still no luck, I see this in logs:wiktor
07/12/2025, 9:07 AM