Denis
02/09/2021, 7:32 PMlineHeight
works? Why doesn't it affect the first line? What is the space below the first line? (Code in thread)Denis
02/09/2021, 7:33 PM@Preview(showBackground = true)
@Composable
fun LineHeightPreview(size: Int = 100) {
val dm = AmbientContext.current.resources.displayMetrics
val text = buildAnnotatedString {
pushStyle(ParagraphStyle(lineHeight = (4 * size).sp))
pushStyle(SpanStyle(fontSize = size.sp))
append("ABCfly\nABCfly")
}
val textDelegate = TextDelegate(text, TextStyle.Default, resourceLoader = AmbientFontLoader.current, density = Density(dm.density))
val r = textDelegate.layout(Constraints(), LayoutDirection.Ltr)
Canvas(modifier = Modifier.width((r.size.width / dm.density).dp).height((r.size.height / dm.density).dp)) {
val t0 = r.getLineTop(0)
drawLine(Color.Blue, start = Offset(y = t0, x = 0f), end = Offset(y = t0, x = r.size.width.toFloat()), strokeWidth = 20f)
val b0 = r.getLineBottom(0)
drawLine(Color.Magenta, start = Offset(y = b0, x = 0f), end = Offset(y = b0, x = r.size.width.toFloat()), strokeWidth = 40f)
val t1 = r.getLineTop(1)
drawLine(Color.Blue, start = Offset(y = t1, x = 0f), end = Offset(y = t1, x = r.size.width.toFloat()), strokeWidth = 20f)
drawIntoCanvas { TextDelegate.paint(canvas = it, r) }
}
}
Chris Sinco [G]
02/10/2021, 10:57 PMSiyamed
02/10/2021, 11:08 PMSiyamed
02/10/2021, 11:08 PM