I’m encountering a weird issue. Text is higher whe...
# compose
f
I’m encountering a weird issue. Text is higher when displaying Chinese character and Japanese kanji than latin letter. This only appears in my company’s app when running on device which is API 33. And it disappears when running on a device of API 30. I’ve tried to reproduce this with a sample project. But the sample works fine in the same device (API 33). Does anyone know the reason?
This is the code I’m running:
Copy code
@Preview
@Composable
fun Preview() = Row {
    val fontSize = 48.sp
    val modifier = Modifier.border(1.dp, Color.Blue)
    Text(text = "Function", modifier, fontSize = fontSize)
    Text(text = "功能", modifier, fontSize = fontSize)
    Text(text = "機能", modifier, fontSize = fontSize)
}
s
f
Thanks, Stylianos. I’ve read them before. After encountering this issue, I resorted to
includeFontPadding
and
lineHeightStyle
at once, but didn’t help. Maybe it’s the opportunity to re-read them to find the missing clue.
s
Hey if you do find that re-reading this and applying its changes fixes your problem please do take the time to share what you did here, would be very interesting to hear about it 😊 Good luck!
j
@Ale Stamato
a
didnt help? would’ve expected lineHeightStyle Alignment Center and Trim Both (or none depending on what u need) + includeFontPadding = false should’ve given the same output FYI @Siyamed
f
Yes. I’m guessing that some logic in my company’s app affects the calculation of line height or something else (font metric?), as the sample app works fine.
I’ve figured out the reason why I couldn’t reproduce this issue with sample before. They use different versions of ‘androidx.core:core’ package. The one used by the real app is 1.8.0 and the other is 1.7.0. This two versions have different
BuildCompat.isAtLeastT
implementations. When running on Android 33, they return different results, thus
BoringLayoutFactory.measure
returns different results:
Copy code
internal object BoringLayoutFactory {

    fun measure(
        text: CharSequence,
        paint: TextPaint,
        textDir: TextDirectionHeuristic
    ): Metrics? {
        return if (BuildCompat.isAtLeastT()) {
            BoringLayoutFactory33.isBoring(text, paint, textDir)
        } else {
            BoringLayoutFactoryDefault.isBoring(text, paint, textDir)
        }
    }
...
}
This issue is relayed to the first branch.
a
maybe im getting smth wrong but this is even weirder… either you’re running in at least T or you’re not, no matter the version of androidx.core:core
i mean, it shoudnt matter..
f
Since I can reproduce it now, I’ll provide a minimal repo sample soon.
a
legend, thanks!
f
s
Thanks Feng, can you please create a bug about this? Will check it out as soon as possible but it seems like framework changes in 33 works different than i was expecting , or the font padding behaved weird here.
f
s
thanks will take a look