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,
                        )
                    }
                }
            }
        }

enter image description here

Full source:

https://github.com/dazza5000/fontsforever/tree/master

Note:

Setting includeFontPadding to false results in a more consistent rendering as seen below

enter image description here

1

There are 1 answers

0
dazza5000 On

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

    platformStyle = PlatformTextStyle(
    includeFontPadding = false
),

https://developer.android.com/reference/kotlin/androidx/compose/ui/text/ParagraphStyle#platformStyle()