The sample code is below, but as you can see in the image that is included the roboto font provided by the system using jetpack compose typography API's (last character) has a greater line height than the roboto font configured using default Typography (GenericFontFamily/first character).
Row {
MaterialTheme {
Column {
Box(
modifier = Modifier.border(
1.dp, color = Color.Black
)
) {
Text(
testText,
style = MaterialTheme.typography.headlineLarge.copy(
// fontSynthesis = FontSynthesis.None
),
maxLines = 1,
)
}
}
}
MaterialTheme(
typography = proximaTypography(),
) {
Column {
Box(
modifier = Modifier.border(
1.dp, color = Color.Black
)
) {
Text(
testText,
style = MaterialTheme.typography.headlineLarge.copy(
// fontSynthesis = FontSynthesis.None
),
maxLines = 1,
)
}
}
}
MaterialTheme(
typography = robotoTypography(),
) {
Column {
Box(
modifier = Modifier.border(
1.dp, color = Color.Black
)
) {
Text(
testText,
style = MaterialTheme.typography.headlineLarge.copy(
// fontSynthesis = FontSynthesis.None
),
maxLines = 1,
)
}
}
}
}
Full source:
https://github.com/dazza5000/fontsforever/tree/master
Note:
Setting includeFontPadding to false results in a more consistent rendering as seen below
From what I discoverd this is due to font padding. In future versions of jetpack compose material 3 components font padding is disabled by default
Source:
https://github.com/androidx/androidx/blob/5adfd65a71104d049c05c6cd845420ec28018a57/compose/material/material/src/androidMain/kotlin/androidx/compose/material/DefaultPlatformTextStyle.android.kt#L21
In the meantime we can manually disable it using the following
https://developer.android.com/reference/kotlin/androidx/compose/ui/text/ParagraphStyle#platformStyle()