diff --git a/compose/ui/ui-text/src/desktopTest/kotlin/androidx/compose/ui/text/DesktopParagraphTest.kt b/compose/ui/ui-text/src/desktopTest/kotlin/androidx/compose/ui/text/DesktopParagraphTest.kt index 20e9b7a8e5339..3e2b1e23d6006 100644 --- a/compose/ui/ui-text/src/desktopTest/kotlin/androidx/compose/ui/text/DesktopParagraphTest.kt +++ b/compose/ui/ui-text/src/desktopTest/kotlin/androidx/compose/ui/text/DesktopParagraphTest.kt @@ -27,7 +27,9 @@ import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.platform.Font import androidx.compose.ui.text.style.BaselineShift +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDirection +import androidx.compose.ui.text.style.TextIndent import androidx.compose.ui.unit.Constraints import androidx.compose.ui.unit.Density import androidx.compose.ui.unit.sp @@ -318,6 +320,35 @@ class DesktopParagraphTest { Truth.assertThat(paragraphWithoutStyles.getLineBottom(1)).isNotEqualTo(secondLineBottom) } + @Test + fun `applies text indent for paragraph`() { + fun measureLines(alignment: TextAlign, direction: TextDirection): List { + val paragraph = simpleParagraph( + text = "sample\ntext", + style = TextStyle( + fontSize = 20.sp, + textIndent = TextIndent(50.sp, 20.sp), + textAlign = alignment, + textDirection = direction, + ) + ) + return listOf( + paragraph.getLineLeft(0), + paragraph.getLineRight(0), + paragraph.getLineLeft(1), + paragraph.getLineRight(1) + ) + } + Truth.assertThat(measureLines(TextAlign.Left, TextDirection.Ltr)).isEqualTo(listOf(50f, 170f, 20f, 100f)) + Truth.assertThat(measureLines(TextAlign.Center, TextDirection.Ltr)).isEqualTo(listOf(965f, 1085f, 970f, 1050f)) + Truth.assertThat(measureLines(TextAlign.Right, TextDirection.Ltr)).isEqualTo(listOf(1830f, 1950f, 1900f, 1980f)) + Truth.assertThat(measureLines(TextAlign.Justify, TextDirection.Ltr)).isEqualTo(listOf(50f, 170f, 20f, 100f)) + Truth.assertThat(measureLines(TextAlign.Left, TextDirection.Rtl)).isEqualTo(listOf(50f, 170f, 20f, 100f)) + Truth.assertThat(measureLines(TextAlign.Center, TextDirection.Rtl)).isEqualTo(listOf(915f, 1035f, 950f, 1030f)) + Truth.assertThat(measureLines(TextAlign.Right, TextDirection.Rtl)).isEqualTo(listOf(1830f, 1950f, 1900f, 1980f)) + Truth.assertThat(measureLines(TextAlign.Justify, TextDirection.Rtl)).isEqualTo(listOf(1830f, 1950f, 1900f, 1980f)) + } + private fun simpleParagraph( text: String = "", style: TextStyle? = null, diff --git a/compose/ui/ui-text/src/skikoMain/kotlin/androidx/compose/ui/text/platform/SkiaParagraph.skiko.kt b/compose/ui/ui-text/src/skikoMain/kotlin/androidx/compose/ui/text/platform/SkiaParagraph.skiko.kt index 9c2e21803da53..054672f8d38b8 100644 --- a/compose/ui/ui-text/src/skikoMain/kotlin/androidx/compose/ui/text/platform/SkiaParagraph.skiko.kt +++ b/compose/ui/ui-text/src/skikoMain/kotlin/androidx/compose/ui/text/platform/SkiaParagraph.skiko.kt @@ -73,6 +73,7 @@ import kotlin.math.floor import org.jetbrains.skia.Rect as SkRect import org.jetbrains.skia.paragraph.Paragraph as SkParagraph import org.jetbrains.skia.paragraph.TextStyle as SkTextStyle +import org.jetbrains.skia.paragraph.TextIndent as SkTextIndent import org.jetbrains.skia.FontStyle as SkFontStyle import org.jetbrains.skia.Font as SkFont import org.jetbrains.skia.paragraph.DecorationLineStyle as SkDecorationLineStyle @@ -826,6 +827,11 @@ internal class ParagraphBuilder( pStyle.strutStyle = strutStyle } pStyle.direction = textDirection.toSkDirection() + textStyle.textIndent?.run { + with(density) { + pStyle.textIndent = SkTextIndent(firstLine.toPx(), restLine.toPx()) + } + } return pStyle } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 95cc2ed24b324..cb1f6cba3d031 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -40,7 +40,7 @@ leakcanary = "2.8.1" metalava = "1.0.0-alpha06" mockito = "2.25.0" protobuf = "3.19.4" -skiko = "0.7.11" +skiko = "0.7.14" sqldelight = "1.3.0" wire = "3.6.0"