Combine SpanStyle and ParagraphStyle for ui-text
Since SpanStyle and ParagraphStyle has been used always together in
constructors of main ui-text classes such as Paragraph, TextDelegate etc,
this CL uses TextStyle instead for those constructors.
Test: ./gradlew ui:ui-text:test
Test: ./gradlew ui:ui-text:connectedAndroidTest
Test: ./gradlew ui:ui-framework:test
Test: ./gradlew ui:ui-framework:connectedAndroidTest
Test: Ran text benchmarks
Bug: 143466124
Change-Id: Ib14a7816b64da162e60563aa47653e63a2d239ae
diff --git a/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/text/ParagraphBenchmark.kt b/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/text/ParagraphBenchmark.kt
index 8bc2bd6..523d94e 100644
--- a/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/text/ParagraphBenchmark.kt
+++ b/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/text/ParagraphBenchmark.kt
@@ -105,8 +105,8 @@
return ParagraphIntrinsics(
text = text,
density = Density(density = 1f),
- spanStyle = SpanStyle(fontSize = 12.sp),
- paragraphStyle = ParagraphStyle(
+ style = TextStyle(
+ fontSize = 12.sp,
textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
),
resourceLoader = resourceLoader,
diff --git a/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/text/ParagraphMethodBenchmark.kt b/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/text/ParagraphMethodBenchmark.kt
index 2ac72bb..6fa0629 100644
--- a/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/text/ParagraphMethodBenchmark.kt
+++ b/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/text/ParagraphMethodBenchmark.kt
@@ -75,8 +75,8 @@
return ParagraphIntrinsics(
text = text,
density = Density(density = 1f),
- spanStyle = SpanStyle(fontSize = 12.sp),
- paragraphStyle = ParagraphStyle(
+ style = TextStyle(
+ fontSize = 12.sp,
textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
),
resourceLoader = resourceLoader,
diff --git a/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/text/TextDelegateBenchmark.kt b/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/text/TextDelegateBenchmark.kt
index 7a013ad..d5dca4d 100644
--- a/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/text/TextDelegateBenchmark.kt
+++ b/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/text/TextDelegateBenchmark.kt
@@ -80,7 +80,7 @@
return TextDelegate(
text = text,
density = Density(density = 1f),
- spanStyle = SpanStyle(fontSize = 12.sp),
+ style = TextStyle(fontSize = 12.sp),
layoutDirection = LayoutDirection.Ltr,
resourceLoader = resourceLoader
)
@@ -101,7 +101,7 @@
TextDelegate(
text = text,
density = Density(density = 1f),
- spanStyle = SpanStyle(fontSize = 12.sp),
+ style = TextStyle(fontSize = 12.sp),
layoutDirection = LayoutDirection.Ltr,
resourceLoader = resourceLoader
)
diff --git a/ui/ui-framework/src/androidTest/java/androidx/ui/core/selection/TextSelectionDelegateTest.kt b/ui/ui-framework/src/androidTest/java/androidx/ui/core/selection/TextSelectionDelegateTest.kt
index 7c88a4c..9d8bed7 100644
--- a/ui/ui-framework/src/androidTest/java/androidx/ui/core/selection/TextSelectionDelegateTest.kt
+++ b/ui/ui-framework/src/androidTest/java/androidx/ui/core/selection/TextSelectionDelegateTest.kt
@@ -30,7 +30,6 @@
import androidx.ui.core.sp
import androidx.ui.core.withDensity
import androidx.ui.text.AnnotatedString
-import androidx.ui.text.ParagraphStyle
import androidx.ui.text.SpanStyle
import androidx.ui.text.TextDelegate
import androidx.ui.text.font.Font
@@ -832,7 +831,6 @@
val annotatedString = AnnotatedString(text, spanStyle)
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
density = density,
layoutDirection = LayoutDirection.Ltr,
resourceLoader = resourceLoader
diff --git a/ui/ui-framework/src/main/java/androidx/ui/core/Text.kt b/ui/ui-framework/src/main/java/androidx/ui/core/Text.kt
index e3adc8e..b10d11c 100644
--- a/ui/ui-framework/src/main/java/androidx/ui/core/Text.kt
+++ b/ui/ui-framework/src/main/java/androidx/ui/core/Text.kt
@@ -177,8 +177,7 @@
) {
TextDelegate(
text = text,
- spanStyle = mergedStyle.toSpanStyle(),
- paragraphStyle = mergedStyle.toParagraphStyle(),
+ style = mergedStyle,
softWrap = softWrap,
overflow = overflow,
maxLines = maxLines,
diff --git a/ui/ui-framework/src/main/java/androidx/ui/core/TextField.kt b/ui/ui-framework/src/main/java/androidx/ui/core/TextField.kt
index 818950e..e6b7c61 100644
--- a/ui/ui-framework/src/main/java/androidx/ui/core/TextField.kt
+++ b/ui/ui-framework/src/main/java/androidx/ui/core/TextField.kt
@@ -368,8 +368,7 @@
val textDelegate = +memo(visualText, mergedStyle, density, resourceLoader) {
TextDelegate(
text = visualText,
- spanStyle = mergedStyle.toSpanStyle(),
- paragraphStyle = mergedStyle.toParagraphStyle(),
+ style = mergedStyle,
density = density,
layoutDirection = layoutDirection,
resourceLoader = resourceLoader
diff --git a/ui/ui-framework/src/main/java/androidx/ui/core/TextFieldDelegate.kt b/ui/ui-framework/src/main/java/androidx/ui/core/TextFieldDelegate.kt
index f74fa0a..1c81236 100644
--- a/ui/ui-framework/src/main/java/androidx/ui/core/TextFieldDelegate.kt
+++ b/ui/ui-framework/src/main/java/androidx/ui/core/TextFieldDelegate.kt
@@ -35,10 +35,10 @@
import androidx.ui.text.AnnotatedString
import androidx.ui.text.Paragraph
import androidx.ui.text.ParagraphConstraints
-import androidx.ui.text.ParagraphStyle
import androidx.ui.text.SpanStyle
import androidx.ui.text.TextDelegate
import androidx.ui.text.TextRange
+import androidx.ui.text.TextStyle
import androidx.ui.text.font.Font
import androidx.ui.text.style.TextDecoration
import androidx.ui.text.style.TextDirectionAlgorithm
@@ -60,16 +60,15 @@
* Until we have font metrics APIs, use the height of reference text as a workaround.
*/
private fun computeLineHeightForEmptyText(
- spanStyle: SpanStyle,
+ style: TextStyle,
density: Density,
resourceLoader: Font.ResourceLoader
): IntPx {
return Paragraph(
text = "H", // No meaning: just a reference character.
- spanStyle = spanStyle,
- paragraphStyle = ParagraphStyle(
+ style = TextStyle(
textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
- ),
+ ).merge(style),
spanStyles = listOf(),
maxLines = 1,
ellipsis = false,
@@ -107,7 +106,7 @@
val isEmptyText = textDelegate.text.text.isEmpty()
val height = if (isEmptyText) {
computeLineHeightForEmptyText(
- spanStyle = textDelegate.spanStyle,
+ style = textDelegate.style,
density = textDelegate.density,
resourceLoader = textDelegate.resourceLoader
)
@@ -187,7 +186,7 @@
offsetMap.originalToTransformed(value.selection.max) - 1)
} else {
val lineHeightForEmptyText = computeLineHeightForEmptyText(
- textDelegate.spanStyle,
+ textDelegate.style,
textDelegate.density,
textDelegate.resourceLoader
)
diff --git a/ui/ui-framework/src/test/java/androidx/ui/core/TextFieldDelegateTest.kt b/ui/ui-framework/src/test/java/androidx/ui/core/TextFieldDelegateTest.kt
index a076ab4..3a17ae7 100644
--- a/ui/ui-framework/src/test/java/androidx/ui/core/TextFieldDelegateTest.kt
+++ b/ui/ui-framework/src/test/java/androidx/ui/core/TextFieldDelegateTest.kt
@@ -35,6 +35,7 @@
import androidx.ui.text.SpanStyle
import androidx.ui.text.TextDelegate
import androidx.ui.text.TextRange
+import androidx.ui.text.TextStyle
import androidx.ui.text.style.TextDecoration
import com.google.common.truth.Truth.assertThat
import com.nhaarman.mockitokotlin2.any
@@ -315,7 +316,7 @@
val dummyText = AnnotatedString(text = "Hello, World")
whenever(mDelegate.text).thenReturn(dummyText)
- whenever(mDelegate.spanStyle).thenReturn(SpanStyle())
+ whenever(mDelegate.style).thenReturn(TextStyle())
whenever(mDelegate.density).thenReturn(Density(1.0f))
whenever(mDelegate.resourceLoader).thenReturn(mock())
whenever(mDelegate.height).thenReturn(512.ipx)
@@ -467,7 +468,7 @@
val dummyText = AnnotatedString(text = "Hello, World")
whenever(mDelegate.text).thenReturn(dummyText)
- whenever(mDelegate.spanStyle).thenReturn(SpanStyle())
+ whenever(mDelegate.style).thenReturn(TextStyle())
whenever(mDelegate.density).thenReturn(Density(1.0f))
whenever(mDelegate.resourceLoader).thenReturn(mock())
whenever(mDelegate.height).thenReturn(512.ipx)
diff --git a/ui/ui-text/api/0.1.0-dev04.txt b/ui/ui-text/api/0.1.0-dev04.txt
index 6d8d470..fa12e1d 100644
--- a/ui/ui-text/api/0.1.0-dev04.txt
+++ b/ui/ui-text/api/0.1.0-dev04.txt
@@ -286,7 +286,7 @@
public final class MultiParagraph {
ctor public MultiParagraph(androidx.ui.text.MultiParagraphIntrinsics intrinsics, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints);
- ctor public MultiParagraph(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ ctor public MultiParagraph(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.TextStyle style, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public androidx.ui.text.style.TextDirection getBidiRunDirection(int offset);
method public androidx.ui.engine.geometry.Rect getBoundingBox(int offset);
method public androidx.ui.engine.geometry.Rect getCursorRect(int offset);
@@ -323,7 +323,7 @@
}
public final class MultiParagraphIntrinsics implements androidx.ui.text.ParagraphIntrinsics {
- ctor public MultiParagraphIntrinsics(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ ctor public MultiParagraphIntrinsics(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.TextStyle style, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public androidx.ui.text.AnnotatedString getAnnotatedString();
method public float getMaxIntrinsicWidth();
method public float getMinIntrinsicWidth();
@@ -385,12 +385,12 @@
public final class ParagraphIntrinsicsKt {
ctor public ParagraphIntrinsicsKt();
- method public static androidx.ui.text.ParagraphIntrinsics ParagraphIntrinsics(String text, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ method public static androidx.ui.text.ParagraphIntrinsics ParagraphIntrinsics(String text, androidx.ui.text.TextStyle style, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles = listOf(), androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
}
public final class ParagraphKt {
ctor public ParagraphKt();
- method public static androidx.ui.text.Paragraph Paragraph(String text, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles, int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ method public static androidx.ui.text.Paragraph Paragraph(String text, androidx.ui.text.TextStyle style, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles = listOf(), int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public static androidx.ui.text.Paragraph Paragraph(androidx.ui.text.ParagraphIntrinsics paragraphIntrinsics, int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints);
}
@@ -549,6 +549,8 @@
method public androidx.ui.text.style.TextGeometricTransform? getTextGeometricTransform();
method public androidx.ui.text.style.TextIndent? getTextIndent();
method public androidx.ui.text.TextStyle merge(androidx.ui.text.TextStyle? other = null);
+ method public androidx.ui.text.TextStyle merge(androidx.ui.text.SpanStyle other);
+ method public androidx.ui.text.TextStyle merge(androidx.ui.text.ParagraphStyle other);
method public androidx.ui.text.ParagraphStyle toParagraphStyle();
method public androidx.ui.text.SpanStyle toSpanStyle();
}
diff --git a/ui/ui-text/api/current.txt b/ui/ui-text/api/current.txt
index 6d8d470..fa12e1d 100644
--- a/ui/ui-text/api/current.txt
+++ b/ui/ui-text/api/current.txt
@@ -286,7 +286,7 @@
public final class MultiParagraph {
ctor public MultiParagraph(androidx.ui.text.MultiParagraphIntrinsics intrinsics, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints);
- ctor public MultiParagraph(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ ctor public MultiParagraph(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.TextStyle style, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public androidx.ui.text.style.TextDirection getBidiRunDirection(int offset);
method public androidx.ui.engine.geometry.Rect getBoundingBox(int offset);
method public androidx.ui.engine.geometry.Rect getCursorRect(int offset);
@@ -323,7 +323,7 @@
}
public final class MultiParagraphIntrinsics implements androidx.ui.text.ParagraphIntrinsics {
- ctor public MultiParagraphIntrinsics(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ ctor public MultiParagraphIntrinsics(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.TextStyle style, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public androidx.ui.text.AnnotatedString getAnnotatedString();
method public float getMaxIntrinsicWidth();
method public float getMinIntrinsicWidth();
@@ -385,12 +385,12 @@
public final class ParagraphIntrinsicsKt {
ctor public ParagraphIntrinsicsKt();
- method public static androidx.ui.text.ParagraphIntrinsics ParagraphIntrinsics(String text, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ method public static androidx.ui.text.ParagraphIntrinsics ParagraphIntrinsics(String text, androidx.ui.text.TextStyle style, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles = listOf(), androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
}
public final class ParagraphKt {
ctor public ParagraphKt();
- method public static androidx.ui.text.Paragraph Paragraph(String text, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles, int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ method public static androidx.ui.text.Paragraph Paragraph(String text, androidx.ui.text.TextStyle style, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles = listOf(), int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public static androidx.ui.text.Paragraph Paragraph(androidx.ui.text.ParagraphIntrinsics paragraphIntrinsics, int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints);
}
@@ -549,6 +549,8 @@
method public androidx.ui.text.style.TextGeometricTransform? getTextGeometricTransform();
method public androidx.ui.text.style.TextIndent? getTextIndent();
method public androidx.ui.text.TextStyle merge(androidx.ui.text.TextStyle? other = null);
+ method public androidx.ui.text.TextStyle merge(androidx.ui.text.SpanStyle other);
+ method public androidx.ui.text.TextStyle merge(androidx.ui.text.ParagraphStyle other);
method public androidx.ui.text.ParagraphStyle toParagraphStyle();
method public androidx.ui.text.SpanStyle toSpanStyle();
}
diff --git a/ui/ui-text/api/public_plus_experimental_0.1.0-dev04.txt b/ui/ui-text/api/public_plus_experimental_0.1.0-dev04.txt
index 6d8d470..fa12e1d 100644
--- a/ui/ui-text/api/public_plus_experimental_0.1.0-dev04.txt
+++ b/ui/ui-text/api/public_plus_experimental_0.1.0-dev04.txt
@@ -286,7 +286,7 @@
public final class MultiParagraph {
ctor public MultiParagraph(androidx.ui.text.MultiParagraphIntrinsics intrinsics, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints);
- ctor public MultiParagraph(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ ctor public MultiParagraph(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.TextStyle style, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public androidx.ui.text.style.TextDirection getBidiRunDirection(int offset);
method public androidx.ui.engine.geometry.Rect getBoundingBox(int offset);
method public androidx.ui.engine.geometry.Rect getCursorRect(int offset);
@@ -323,7 +323,7 @@
}
public final class MultiParagraphIntrinsics implements androidx.ui.text.ParagraphIntrinsics {
- ctor public MultiParagraphIntrinsics(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ ctor public MultiParagraphIntrinsics(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.TextStyle style, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public androidx.ui.text.AnnotatedString getAnnotatedString();
method public float getMaxIntrinsicWidth();
method public float getMinIntrinsicWidth();
@@ -385,12 +385,12 @@
public final class ParagraphIntrinsicsKt {
ctor public ParagraphIntrinsicsKt();
- method public static androidx.ui.text.ParagraphIntrinsics ParagraphIntrinsics(String text, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ method public static androidx.ui.text.ParagraphIntrinsics ParagraphIntrinsics(String text, androidx.ui.text.TextStyle style, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles = listOf(), androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
}
public final class ParagraphKt {
ctor public ParagraphKt();
- method public static androidx.ui.text.Paragraph Paragraph(String text, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles, int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ method public static androidx.ui.text.Paragraph Paragraph(String text, androidx.ui.text.TextStyle style, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles = listOf(), int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public static androidx.ui.text.Paragraph Paragraph(androidx.ui.text.ParagraphIntrinsics paragraphIntrinsics, int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints);
}
@@ -549,6 +549,8 @@
method public androidx.ui.text.style.TextGeometricTransform? getTextGeometricTransform();
method public androidx.ui.text.style.TextIndent? getTextIndent();
method public androidx.ui.text.TextStyle merge(androidx.ui.text.TextStyle? other = null);
+ method public androidx.ui.text.TextStyle merge(androidx.ui.text.SpanStyle other);
+ method public androidx.ui.text.TextStyle merge(androidx.ui.text.ParagraphStyle other);
method public androidx.ui.text.ParagraphStyle toParagraphStyle();
method public androidx.ui.text.SpanStyle toSpanStyle();
}
diff --git a/ui/ui-text/api/public_plus_experimental_current.txt b/ui/ui-text/api/public_plus_experimental_current.txt
index 6d8d470..fa12e1d 100644
--- a/ui/ui-text/api/public_plus_experimental_current.txt
+++ b/ui/ui-text/api/public_plus_experimental_current.txt
@@ -286,7 +286,7 @@
public final class MultiParagraph {
ctor public MultiParagraph(androidx.ui.text.MultiParagraphIntrinsics intrinsics, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints);
- ctor public MultiParagraph(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ ctor public MultiParagraph(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.TextStyle style, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public androidx.ui.text.style.TextDirection getBidiRunDirection(int offset);
method public androidx.ui.engine.geometry.Rect getBoundingBox(int offset);
method public androidx.ui.engine.geometry.Rect getCursorRect(int offset);
@@ -323,7 +323,7 @@
}
public final class MultiParagraphIntrinsics implements androidx.ui.text.ParagraphIntrinsics {
- ctor public MultiParagraphIntrinsics(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ ctor public MultiParagraphIntrinsics(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.TextStyle style, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public androidx.ui.text.AnnotatedString getAnnotatedString();
method public float getMaxIntrinsicWidth();
method public float getMinIntrinsicWidth();
@@ -385,12 +385,12 @@
public final class ParagraphIntrinsicsKt {
ctor public ParagraphIntrinsicsKt();
- method public static androidx.ui.text.ParagraphIntrinsics ParagraphIntrinsics(String text, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ method public static androidx.ui.text.ParagraphIntrinsics ParagraphIntrinsics(String text, androidx.ui.text.TextStyle style, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles = listOf(), androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
}
public final class ParagraphKt {
ctor public ParagraphKt();
- method public static androidx.ui.text.Paragraph Paragraph(String text, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles, int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ method public static androidx.ui.text.Paragraph Paragraph(String text, androidx.ui.text.TextStyle style, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles = listOf(), int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public static androidx.ui.text.Paragraph Paragraph(androidx.ui.text.ParagraphIntrinsics paragraphIntrinsics, int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints);
}
@@ -549,6 +549,8 @@
method public androidx.ui.text.style.TextGeometricTransform? getTextGeometricTransform();
method public androidx.ui.text.style.TextIndent? getTextIndent();
method public androidx.ui.text.TextStyle merge(androidx.ui.text.TextStyle? other = null);
+ method public androidx.ui.text.TextStyle merge(androidx.ui.text.SpanStyle other);
+ method public androidx.ui.text.TextStyle merge(androidx.ui.text.ParagraphStyle other);
method public androidx.ui.text.ParagraphStyle toParagraphStyle();
method public androidx.ui.text.SpanStyle toSpanStyle();
}
diff --git a/ui/ui-text/api/restricted_0.1.0-dev04.txt b/ui/ui-text/api/restricted_0.1.0-dev04.txt
index a148272..654e12b 100644
--- a/ui/ui-text/api/restricted_0.1.0-dev04.txt
+++ b/ui/ui-text/api/restricted_0.1.0-dev04.txt
@@ -288,7 +288,7 @@
public final class MultiParagraph {
ctor public MultiParagraph(androidx.ui.text.MultiParagraphIntrinsics intrinsics, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints);
- ctor public MultiParagraph(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ ctor public MultiParagraph(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.TextStyle style, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public androidx.ui.text.style.TextDirection getBidiRunDirection(int offset);
method public androidx.ui.engine.geometry.Rect getBoundingBox(int offset);
method public androidx.ui.engine.geometry.Rect getCursorRect(int offset);
@@ -325,7 +325,7 @@
}
public final class MultiParagraphIntrinsics implements androidx.ui.text.ParagraphIntrinsics {
- ctor public MultiParagraphIntrinsics(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ ctor public MultiParagraphIntrinsics(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.TextStyle style, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public androidx.ui.text.AnnotatedString getAnnotatedString();
method public float getMaxIntrinsicWidth();
method public float getMinIntrinsicWidth();
@@ -387,12 +387,12 @@
public final class ParagraphIntrinsicsKt {
ctor public ParagraphIntrinsicsKt();
- method public static androidx.ui.text.ParagraphIntrinsics ParagraphIntrinsics(String text, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ method public static androidx.ui.text.ParagraphIntrinsics ParagraphIntrinsics(String text, androidx.ui.text.TextStyle style, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles = listOf(), androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
}
public final class ParagraphKt {
ctor public ParagraphKt();
- method public static androidx.ui.text.Paragraph Paragraph(String text, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles, int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ method public static androidx.ui.text.Paragraph Paragraph(String text, androidx.ui.text.TextStyle style, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles = listOf(), int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public static androidx.ui.text.Paragraph Paragraph(androidx.ui.text.ParagraphIntrinsics paragraphIntrinsics, int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints);
}
@@ -552,6 +552,8 @@
method public androidx.ui.text.style.TextGeometricTransform? getTextGeometricTransform();
method public androidx.ui.text.style.TextIndent? getTextIndent();
method public androidx.ui.text.TextStyle merge(androidx.ui.text.TextStyle? other = null);
+ method public androidx.ui.text.TextStyle merge(androidx.ui.text.SpanStyle other);
+ method public androidx.ui.text.TextStyle merge(androidx.ui.text.ParagraphStyle other);
method public androidx.ui.text.ParagraphStyle toParagraphStyle();
method public androidx.ui.text.SpanStyle toSpanStyle();
}
diff --git a/ui/ui-text/api/restricted_current.txt b/ui/ui-text/api/restricted_current.txt
index a148272..654e12b 100644
--- a/ui/ui-text/api/restricted_current.txt
+++ b/ui/ui-text/api/restricted_current.txt
@@ -288,7 +288,7 @@
public final class MultiParagraph {
ctor public MultiParagraph(androidx.ui.text.MultiParagraphIntrinsics intrinsics, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints);
- ctor public MultiParagraph(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ ctor public MultiParagraph(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.TextStyle style, int maxLines, boolean ellipsis, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public androidx.ui.text.style.TextDirection getBidiRunDirection(int offset);
method public androidx.ui.engine.geometry.Rect getBoundingBox(int offset);
method public androidx.ui.engine.geometry.Rect getCursorRect(int offset);
@@ -325,7 +325,7 @@
}
public final class MultiParagraphIntrinsics implements androidx.ui.text.ParagraphIntrinsics {
- ctor public MultiParagraphIntrinsics(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ ctor public MultiParagraphIntrinsics(androidx.ui.text.AnnotatedString annotatedString, androidx.ui.text.TextStyle style, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public androidx.ui.text.AnnotatedString getAnnotatedString();
method public float getMaxIntrinsicWidth();
method public float getMinIntrinsicWidth();
@@ -387,12 +387,12 @@
public final class ParagraphIntrinsicsKt {
ctor public ParagraphIntrinsicsKt();
- method public static androidx.ui.text.ParagraphIntrinsics ParagraphIntrinsics(String text, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ method public static androidx.ui.text.ParagraphIntrinsics ParagraphIntrinsics(String text, androidx.ui.text.TextStyle style, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles = listOf(), androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
}
public final class ParagraphKt {
ctor public ParagraphKt();
- method public static androidx.ui.text.Paragraph Paragraph(String text, androidx.ui.text.SpanStyle spanStyle, androidx.ui.text.ParagraphStyle paragraphStyle, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles, int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
+ method public static androidx.ui.text.Paragraph Paragraph(String text, androidx.ui.text.TextStyle style, java.util.List<androidx.ui.text.AnnotatedString.Item<androidx.ui.text.SpanStyle>> spanStyles = listOf(), int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
method public static androidx.ui.text.Paragraph Paragraph(androidx.ui.text.ParagraphIntrinsics paragraphIntrinsics, int maxLines = 2147483647, boolean ellipsis = false, androidx.ui.text.ParagraphConstraints constraints);
}
@@ -552,6 +552,8 @@
method public androidx.ui.text.style.TextGeometricTransform? getTextGeometricTransform();
method public androidx.ui.text.style.TextIndent? getTextIndent();
method public androidx.ui.text.TextStyle merge(androidx.ui.text.TextStyle? other = null);
+ method public androidx.ui.text.TextStyle merge(androidx.ui.text.SpanStyle other);
+ method public androidx.ui.text.TextStyle merge(androidx.ui.text.ParagraphStyle other);
method public androidx.ui.text.ParagraphStyle toParagraphStyle();
method public androidx.ui.text.SpanStyle toSpanStyle();
}
diff --git a/ui/ui-text/src/androidTest/java/androidx/ui/text/MultiParagraphIntegrationTest.kt b/ui/ui-text/src/androidTest/java/androidx/ui/text/MultiParagraphIntegrationTest.kt
index ccb2be1..9365a0c 100644
--- a/ui/ui-text/src/androidTest/java/androidx/ui/text/MultiParagraphIntegrationTest.kt
+++ b/ui/ui-text/src/androidTest/java/androidx/ui/text/MultiParagraphIntegrationTest.kt
@@ -318,7 +318,7 @@
val text = createAnnotatedString("a", "\u05D0", " ")
val paragraph = simpleMultiParagraph(
text = text,
- paragraphStyle = ParagraphStyle(
+ style = TextStyle(
textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
)
)
@@ -333,7 +333,7 @@
val text = createAnnotatedString("a", "\u05D0", " ")
val paragraph = simpleMultiParagraph(
text = text,
- paragraphStyle = ParagraphStyle(
+ style = TextStyle(
textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrRtl
)
)
@@ -348,7 +348,7 @@
val text = createAnnotatedString("a", "\u05D0", " ")
val paragraph = simpleMultiParagraph(
text = text,
- paragraphStyle = ParagraphStyle(
+ style = TextStyle(
textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr
)
)
@@ -364,7 +364,7 @@
val text = createAnnotatedString("a", "\u05D0", " ")
val paragraph = simpleMultiParagraph(
text = text,
- paragraphStyle = ParagraphStyle(
+ style = TextStyle(
textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl
)
)
@@ -747,7 +747,7 @@
val paragraph = simpleMultiParagraph(
text = text,
width = width,
- paragraphStyle = ParagraphStyle(textAlign = TextAlign.Left)
+ style = TextStyle(textAlign = TextAlign.Left)
)
// When text align to left, line left should be 0 for both Ltr and Rtl text.
@@ -767,7 +767,7 @@
val paragraph = simpleMultiParagraph(
text = text,
width = width,
- paragraphStyle = ParagraphStyle(textAlign = TextAlign.Right)
+ style = TextStyle(textAlign = TextAlign.Right)
)
// When text align to right, line right should be width for both Ltr and Rtl text.
@@ -792,7 +792,7 @@
text = text,
fontSize = fontSize,
width = width,
- paragraphStyle = ParagraphStyle(textAlign = TextAlign.Center)
+ style = TextStyle(textAlign = TextAlign.Center)
)
val expectedLineLeft = width / 2 - (fontSizeInPx * textLtr.length) / 2
@@ -819,7 +819,7 @@
val paragraph = simpleMultiParagraph(
text = text,
- paragraphStyle = ParagraphStyle(textAlign = TextAlign.Justify),
+ style = TextStyle(textAlign = TextAlign.Justify),
width = width
)
@@ -847,7 +847,7 @@
val paragraph = simpleMultiParagraph(
text = text,
fontSize = fontSize,
- paragraphStyle = ParagraphStyle(textAlign = TextAlign.Justify),
+ style = TextStyle(textAlign = TextAlign.Justify),
width = width
)
@@ -878,7 +878,7 @@
val paragraph = simpleMultiParagraph(
text = text,
- paragraphStyle = ParagraphStyle(textAlign = TextAlign.Start),
+ style = TextStyle(textAlign = TextAlign.Start),
width = width
)
// When text align to start, Ltr text aligns to left, line left should be 0.
@@ -898,7 +898,7 @@
val paragraph = simpleMultiParagraph(
text = text,
- paragraphStyle = ParagraphStyle(textAlign = TextAlign.End),
+ style = TextStyle(textAlign = TextAlign.End),
width = width
)
// When text align to start, Ltr text aligns to right, line right should be width.
@@ -954,9 +954,7 @@
val paragraph = simpleMultiParagraph(
text = text,
fontSize = fontSize,
- paragraphStyle = ParagraphStyle(
- textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
- ),
+ style = TextStyle(textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr),
width = width
)
@@ -988,9 +986,7 @@
val paragraph = simpleMultiParagraph(
text = text,
fontSize = fontSize,
- paragraphStyle = ParagraphStyle(
- textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrRtl
- ),
+ style = TextStyle(textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrRtl),
width = width
)
@@ -1022,9 +1018,7 @@
val paragraph = simpleMultiParagraph(
text = text,
fontSize = fontSize,
- paragraphStyle = ParagraphStyle(
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr
- ),
+ style = TextStyle(textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr),
width = width
)
@@ -1056,9 +1050,7 @@
val paragraph = simpleMultiParagraph(
text = text,
fontSize = fontSize,
- paragraphStyle = ParagraphStyle(
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl
- ),
+ style = TextStyle(textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl),
width = width
)
@@ -1088,7 +1080,7 @@
val paragraph = simpleMultiParagraph(
text = text,
fontSize = fontSize,
- paragraphStyle = ParagraphStyle(lineHeight = lineHeight)
+ style = TextStyle(lineHeight = lineHeight)
)
// Height of first and last line in each paragraph is influenced by includePadding.
@@ -1112,10 +1104,8 @@
val width = 2 * fontSizeInPx
val paragraph = simpleMultiParagraph(
text = text,
+ style = TextStyle(textIndent = TextIndent(firstLine = indent)),
fontSize = fontSize,
- paragraphStyle = ParagraphStyle(
- textIndent = TextIndent(firstLine = indent)
- ),
width = width
)
// The paragraph should be rendered as:
@@ -1145,9 +1135,7 @@
val paragraph = simpleMultiParagraph(
text = text,
fontSize = fontSize,
- paragraphStyle = ParagraphStyle(
- textIndent = TextIndent(restLine = indent)
- ),
+ style = TextStyle(textIndent = TextIndent(restLine = indent)),
width = width
)
// The paragraph should be rendered as:
@@ -1166,8 +1154,7 @@
fun constructor_throwsException_ifTextDirectionAlgorithmIsNotSet() {
MultiParagraph(
annotatedString = createAnnotatedString(""),
- spanStyle = SpanStyle(),
- paragraphStyle = ParagraphStyle(),
+ style = TextStyle(),
constraints = ParagraphConstraints(Float.MAX_VALUE),
density = defaultDensity,
resourceLoader = TestFontResourceLoader(context)
@@ -1200,8 +1187,7 @@
val paragraph = MultiParagraph(
annotatedString = text,
- spanStyle = SpanStyle(),
- paragraphStyle = ParagraphStyle(textDirectionAlgorithm = textDirectionAlgorithm),
+ style = TextStyle(textDirectionAlgorithm = textDirectionAlgorithm),
constraints = ParagraphConstraints(Float.MAX_VALUE),
density = defaultDensity,
resourceLoader = TestFontResourceLoader(context)
@@ -1239,11 +1225,9 @@
): MultiParagraphIntrinsics {
return MultiParagraphIntrinsics(
text,
- spanStyle = SpanStyle(
+ style = TextStyle(
fontFamily = fontFamilyMeasureFont,
- fontSize = fontSize
- ),
- paragraphStyle = ParagraphStyle(
+ fontSize = fontSize,
textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
),
density = defaultDensity,
@@ -1253,21 +1237,18 @@
private fun simpleMultiParagraph(
text: String,
+ style: TextStyle? = null,
fontSize: TextUnit = TextUnit.Inherit,
- paragraphStyle: ParagraphStyle = ParagraphStyle(),
maxLines: Int = Int.MAX_VALUE,
width: Float = Float.MAX_VALUE
): MultiParagraph {
return MultiParagraph(
annotatedString = createAnnotatedString(text),
- spanStyle = SpanStyle(
+ style = TextStyle(
fontFamily = fontFamilyMeasureFont,
- fontSize = fontSize
- ),
- paragraphStyle = paragraphStyle.textDirectionAlgorithm?.let { paragraphStyle }
- ?: paragraphStyle.copy(
- textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
- ),
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
+ ).merge(style),
maxLines = maxLines,
constraints = ParagraphConstraints(width),
density = defaultDensity,
@@ -1277,21 +1258,18 @@
private fun simpleMultiParagraph(
text: AnnotatedString,
+ style: TextStyle? = null,
fontSize: TextUnit = TextUnit.Inherit,
- paragraphStyle: ParagraphStyle = ParagraphStyle(),
maxLines: Int = Int.MAX_VALUE,
width: Float = Float.MAX_VALUE
): MultiParagraph {
return MultiParagraph(
annotatedString = text,
- spanStyle = SpanStyle(
+ style = TextStyle(
fontFamily = fontFamilyMeasureFont,
- fontSize = fontSize
- ),
- paragraphStyle = paragraphStyle.textDirectionAlgorithm?.let { paragraphStyle }
- ?: paragraphStyle.copy(
- textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
- ),
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
+ ).merge(style),
maxLines = maxLines,
constraints = ParagraphConstraints(width),
density = defaultDensity,
diff --git a/ui/ui-text/src/androidTest/java/androidx/ui/text/ParagraphIntegrationTest.kt b/ui/ui-text/src/androidTest/java/androidx/ui/text/ParagraphIntegrationTest.kt
index aed7b76..1332f0d 100644
--- a/ui/ui-text/src/androidTest/java/androidx/ui/text/ParagraphIntegrationTest.kt
+++ b/ui/ui-text/src/androidTest/java/androidx/ui/text/ParagraphIntegrationTest.kt
@@ -20,7 +20,6 @@
import androidx.test.platform.app.InstrumentationRegistry
import androidx.ui.core.Density
import androidx.ui.core.PxPosition
-import androidx.ui.core.TextUnit
import androidx.ui.core.em
import androidx.ui.core.px
import androidx.ui.core.sp
@@ -38,7 +37,6 @@
import androidx.ui.text.FontTestData.Companion.BASIC_MEASURE_FONT
import androidx.ui.text.FontTestData.Companion.FONT_100_REGULAR
import androidx.ui.text.FontTestData.Companion.FONT_200_REGULAR
-import androidx.ui.text.font.FontFamily
import androidx.ui.text.font.asFontFamily
import androidx.ui.text.matchers.assertThat
import androidx.ui.text.matchers.isZero
@@ -76,7 +74,7 @@
val text = ""
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = 100.0f)
)
@@ -100,7 +98,7 @@
for (text in arrayOf("xyz", "\u05D0\u05D1\u05D2")) {
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
// width greater than text width - 150
constraints = ParagraphConstraints(width = 200.0f)
)
@@ -127,7 +125,7 @@
for (text in arrayOf("abcdef", "\u05D0\u05D1\u05D2\u05D3\u05D4\u05D5")) {
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
// 3 chars width
constraints = ParagraphConstraints(width = 3 * fontSizeInPx)
)
@@ -160,7 +158,7 @@
for (text in arrayOf("abc\ndef", "\u05D0\u05D1\u05D2\n\u05D3\u05D4\u05D5")) {
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
// 3 chars width
constraints = ParagraphConstraints(width = 3 * fontSizeInPx)
)
@@ -191,7 +189,7 @@
for (text in arrayOf("abc\ndef", "\u05D0\u05D1\u05D2\n\u05D3\u05D4\u05D5")) {
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
// 2 chars width
constraints = ParagraphConstraints(width = 2 * fontSizeInPx)
)
@@ -222,7 +220,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = text.length * fontSizeInPx)
)
@@ -244,7 +242,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = text.length * fontSizeInPx)
)
@@ -268,7 +266,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = firstLine.length * fontSizeInPx)
)
@@ -294,7 +292,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = firstLine.length * fontSizeInPx)
)
@@ -318,7 +316,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = text.length * fontSizeInPx)
)
@@ -342,7 +340,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = text.length * fontSizeInPx)
)
@@ -366,7 +364,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = text.length * fontSizeInPx)
)
@@ -391,7 +389,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = firstLine.length * fontSizeInPx)
)
@@ -416,7 +414,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = text.length * fontSizeInPx)
)
@@ -438,7 +436,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = text.length * fontSizeInPx)
)
@@ -455,7 +453,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = text.length * fontSizeInPx)
)
@@ -471,7 +469,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = text.length * fontSizeInPx)
)
@@ -487,7 +485,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = text.length * fontSizeInPx)
)
@@ -515,7 +513,7 @@
val charsPerLine = 3
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = charsPerLine * fontSizeInPx)
)
@@ -553,7 +551,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize
+ style = TextStyle(fontSize = fontSize)
)
// Cursor before '\n'
@@ -586,7 +584,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize
+ style = TextStyle(fontSize = fontSize)
)
// Cursor before '\n'
@@ -619,7 +617,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = text.length * fontSizeInPx)
)
@@ -646,7 +644,7 @@
val charsPerLine = 3
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = charsPerLine * fontSizeInPx)
)
@@ -684,7 +682,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = 3 * fontSizeInPx)
)
@@ -719,7 +717,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = 3 * fontSizeInPx)
)
@@ -753,7 +751,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = text.length * fontSizeInPx)
)
@@ -773,7 +771,7 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width)
)
@@ -795,7 +793,7 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width)
)
@@ -823,8 +821,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl
+ ),
constraints = ParagraphConstraints(width)
)
@@ -848,8 +848,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr
+ ),
constraints = ParagraphConstraints(width)
)
@@ -876,8 +878,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr
+ ),
constraints = ParagraphConstraints(width)
)
@@ -907,8 +911,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl
+ ),
constraints = ParagraphConstraints(width)
)
@@ -935,7 +941,7 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width)
)
@@ -954,7 +960,7 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width)
)
@@ -971,8 +977,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl
+ ),
constraints = ParagraphConstraints(width)
)
@@ -990,8 +998,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1007,7 +1017,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = text.length * fontSizeInPx)
)
@@ -1027,7 +1037,7 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width)
)
@@ -1049,7 +1059,7 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width)
)
@@ -1074,8 +1084,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1100,8 +1112,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1127,8 +1141,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1158,8 +1174,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1187,7 +1205,7 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width)
)
@@ -1206,7 +1224,7 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width)
)
@@ -1223,8 +1241,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1242,8 +1262,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1260,7 +1282,7 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width)
)
@@ -1279,8 +1301,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1299,7 +1323,7 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width)
)
@@ -1318,8 +1342,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1340,7 +1366,7 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width)
)
@@ -1361,8 +1387,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1383,8 +1411,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1403,7 +1433,7 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width)
)
@@ -1422,8 +1452,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1442,7 +1474,7 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width)
)
@@ -1461,8 +1493,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1484,7 +1518,7 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width)
)
@@ -1509,8 +1543,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1535,8 +1571,10 @@
val width = text.length * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl
+ ),
constraints = ParagraphConstraints(width)
)
@@ -1568,11 +1606,9 @@
val paragraph = Paragraph(
text = text,
spanStyles = listOf(),
- spanStyle = SpanStyle(
+ style = TextStyle(
fontSize = fontSize,
- localeList = localeList
- ),
- paragraphStyle = ParagraphStyle(
+ localeList = localeList,
textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
),
density = defaultDensity,
@@ -1596,7 +1632,6 @@
fun maxLines_withMaxLineEqualsZero_throwsException() {
simpleParagraph(
text = "",
- fontSize = 10.sp,
maxLines = 0
)
}
@@ -1605,7 +1640,6 @@
fun maxLines_withMaxLineNegative_throwsException() {
simpleParagraph(
text = "",
- fontSize = 10.sp,
maxLines = -1
)
}
@@ -1620,7 +1654,7 @@
val maxLines = lineCount - 1
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
maxLines = maxLines
)
@@ -1639,7 +1673,7 @@
val maxLines = lineCount - 1
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
maxLines = maxLines
)
@@ -1660,7 +1694,7 @@
val maxLines = text.lines().size
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
maxLines = maxLines
)
@@ -1679,7 +1713,7 @@
val maxLines = lineCount + 1
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
maxLines = maxLines,
constraints = ParagraphConstraints(width = 200f)
)
@@ -1699,14 +1733,14 @@
val paragraphWithMaxLine = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
maxLines = maxLines,
constraints = ParagraphConstraints(width = fontSizeInPx)
)
val paragraphNoMaxLine = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = fontSizeInPx)
)
@@ -1776,7 +1810,7 @@
val maxLines = 1
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
maxLines = maxLines,
// One line can only contain 1 character
constraints = ParagraphConstraints(width = fontSizeInPx)
@@ -1792,7 +1826,6 @@
val maxLines = text.lines().size
val paragraph = simpleParagraph(
text = text,
- fontSize = 50.sp,
maxLines = maxLines
)
@@ -1808,7 +1841,7 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
maxLines = maxLines,
// One line can only contain 1 character
constraints = ParagraphConstraints(width = fontSizeInPx)
@@ -1829,14 +1862,14 @@
val layoutLTRWidth = (textLTR.length + 2) * fontSizeInPx
val paragraphLTR = simpleParagraph(
text = textLTR,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = layoutLTRWidth)
)
val layoutRTLWidth = (textRTL.length + 2) * fontSizeInPx
val paragraphRTL = simpleParagraph(
text = textRTL,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = layoutRTLWidth)
)
@@ -1857,8 +1890,10 @@
val layoutWidth = (text.length + 2) * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- textAlign = TextAlign.Left,
- fontSize = fontSize,
+ style = TextStyle(
+ fontSize = fontSize,
+ textAlign = TextAlign.Left
+ ),
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -1878,8 +1913,11 @@
val layoutWidth = (text.length + 2) * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- textAlign = TextAlign.Right,
- fontSize = fontSize,
+ style = TextStyle(
+ fontSize = fontSize,
+ textAlign = TextAlign.Right
+ ),
+
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -1899,8 +1937,10 @@
val layoutWidth = (text.length + 2) * fontSizeInPx
val paragraph = simpleParagraph(
text = text,
- textAlign = TextAlign.Center,
- fontSize = fontSize,
+ style = TextStyle(
+ fontSize = fontSize,
+ textAlign = TextAlign.Center
+ ),
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -1921,8 +1961,10 @@
val paragraph = simpleParagraph(
text = text,
- textAlign = TextAlign.Start,
- fontSize = fontSize,
+ style = TextStyle(
+ fontSize = fontSize,
+ textAlign = TextAlign.Start
+ ),
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -1940,8 +1982,10 @@
val paragraph = simpleParagraph(
text = text,
- textAlign = TextAlign.End,
- fontSize = fontSize,
+ style = TextStyle(
+ fontSize = fontSize,
+ textAlign = TextAlign.End
+ ),
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -1959,8 +2003,10 @@
val paragraph = simpleParagraph(
text = text,
- textAlign = TextAlign.Start,
- fontSize = fontSize,
+ style = TextStyle(
+ fontSize = fontSize,
+ textAlign = TextAlign.Start
+ ),
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -1978,8 +2024,11 @@
val paragraph = simpleParagraph(
text = text,
- textAlign = TextAlign.End,
- fontSize = fontSize,
+
+ style = TextStyle(
+ fontSize = fontSize,
+ textAlign = TextAlign.End
+ ),
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -2000,8 +2049,10 @@
val paragraph = simpleParagraph(
text = text,
- textAlign = TextAlign.Justify,
- fontSize = fontSize,
+ style = TextStyle(
+ fontSize = fontSize,
+ textAlign = TextAlign.Justify
+ ),
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -2022,8 +2073,10 @@
val paragraph = simpleParagraph(
text = text,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr,
- fontSize = fontSize,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceLtr
+ ),
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -2044,8 +2097,10 @@
val paragraph = simpleParagraph(
text = text,
- textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl,
- fontSize = fontSize,
+ style = TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ForceRtl
+ ),
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -2066,7 +2121,7 @@
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -2089,7 +2144,7 @@
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -2112,7 +2167,7 @@
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -2133,7 +2188,7 @@
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize
+ style = TextStyle(fontSize = fontSize)
)
assertThat(paragraph.getLineBottom(0)).isEqualTo(fontSizeInPx)
assertThat(paragraph.getLineBottom(1)).isEqualTo(fontSize.value * (2f + 1f / 5f))
@@ -2151,8 +2206,10 @@
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize.sp,
- lineHeight = lineHeight.sp,
+ style = TextStyle(
+ fontSize = fontSize.sp,
+ lineHeight = lineHeight.sp
+ ),
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -2178,8 +2235,7 @@
val paragraph = simpleParagraph(
text = text,
- fontSize = fontSize.sp,
- lineHeight = lineHeight.em,
+ style = TextStyle(fontSize = fontSize.sp, lineHeight = lineHeight.em),
constraints = ParagraphConstraints(width = layoutWidth)
)
@@ -2231,7 +2287,7 @@
val paragraph = simpleParagraph(
text = text,
spanStyles = listOf(AnnotatedString.Item(spanStyle, 0, "abc".length)),
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = paragraphWidth)
)
@@ -2286,7 +2342,7 @@
val paragraph = simpleParagraph(
text = text,
spanStyles = listOf(AnnotatedString.Item(spanStyle, 0, text.length)),
- fontSize = fontSize
+ style = TextStyle(fontSize = fontSize)
)
assertThat(paragraph.getLineRight(0))
@@ -2312,7 +2368,7 @@
AnnotatedString.Item(spanStyle, 0, text.length),
AnnotatedString.Item(spanStyleNested, 0, text.length)
),
- fontSize = fontSize
+ style = TextStyle(fontSize = fontSize)
)
assertThat(paragraph.getLineRight(0))
@@ -2339,7 +2395,7 @@
AnnotatedString.Item(fontSizeStyle, 0, text.length),
AnnotatedString.Item(fontSizeScaleStyle, 0, text.length)
),
- fontSize = paragraphFontSize
+ style = TextStyle(fontSize = paragraphFontSize)
)
assertThat(paragraph.getLineRight(0))
@@ -2366,7 +2422,7 @@
AnnotatedString.Item(fontSizeScaleStyle, 0, text.length),
AnnotatedString.Item(fontSizeStyle, 0, text.length)
),
- fontSize = paragraphFontSize
+ style = TextStyle(fontSize = paragraphFontSize)
)
assertThat(paragraph.getLineRight(0)).isEqualTo(text.length * fontSizeInPx)
@@ -2396,7 +2452,7 @@
AnnotatedString.Item(fontSizeStyle, 0, text.length),
AnnotatedString.Item(fontSizeScaleStyle2, 0, text.length)
),
- fontSize = paragraphFontSize
+ style = TextStyle(fontSize = paragraphFontSize)
)
assertThat(paragraph.getLineRight(0))
@@ -2417,7 +2473,7 @@
val paragraph = simpleParagraph(
text = text,
spanStyles = listOf(AnnotatedString.Item(spanStyle, 0, text.length)),
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = paragraphWidth)
)
@@ -2442,7 +2498,7 @@
val paragraph = simpleParagraph(
text = text,
spanStyles = listOf(AnnotatedString.Item(spanStyle, 0, "abc".length)),
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = paragraphWidth)
)
@@ -2473,7 +2529,7 @@
AnnotatedString.Item(spanStyle, 0, text.length),
AnnotatedString.Item(spanStyleOverwrite, 0, "abc".length)
),
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = paragraphWidth)
)
@@ -2497,9 +2553,11 @@
val paragraph = simpleParagraph(
text = text,
- textIndent = TextIndent(firstLine = indent),
- fontSize = fontSize,
- fontFamily = fontFamilyMeasureFont
+ style = TextStyle(
+ fontSize = fontSize,
+ textIndent = TextIndent(firstLine = indent),
+ fontFamily = fontFamilyMeasureFont
+ )
)
// This position should point to the first character 'a' if indent is applied.
@@ -2520,9 +2578,11 @@
val paragraph = simpleParagraph(
text = text,
- textIndent = TextIndent(firstLine = indent.sp),
- fontSize = fontSize.sp,
- fontFamily = fontFamilyMeasureFont,
+ style = TextStyle(
+ fontSize = fontSize.sp,
+ textIndent = TextIndent(firstLine = indent.sp),
+ fontFamily = fontFamilyMeasureFont
+ ),
constraints = ParagraphConstraints(width = paragraphWidth)
)
@@ -2541,9 +2601,11 @@
val paragraph = simpleParagraph(
text = text,
- textIndent = TextIndent(restLine = indent.sp),
- fontSize = fontSize.sp,
- fontFamily = fontFamilyMeasureFont,
+ style = TextStyle(
+ textIndent = TextIndent(restLine = indent.sp),
+ fontSize = fontSize.sp,
+ fontFamily = fontFamilyMeasureFont
+ ),
constraints = ParagraphConstraints(width = paragraphWidth)
)
@@ -2561,9 +2623,11 @@
val paragraph = simpleParagraph(
text = text,
- textIndent = TextIndent(firstLine = indent.em),
- fontSize = fontSize.sp,
- fontFamily = fontFamilyMeasureFont
+ style = TextStyle(
+ textIndent = TextIndent(firstLine = indent.em),
+ fontSize = fontSize.sp,
+ fontFamily = fontFamilyMeasureFont
+ )
)
assertThat(paragraph.getHorizontalPosition(0, true)).isEqualTo(indent * fontSize)
@@ -2581,9 +2645,11 @@
val paragraph = simpleParagraph(
text = text,
- textIndent = TextIndent(firstLine = indent.em),
- fontSize = fontSize.sp,
- fontFamily = fontFamilyMeasureFont,
+ style = TextStyle(
+ textIndent = TextIndent(firstLine = indent.em),
+ fontSize = fontSize.sp,
+ fontFamily = fontFamilyMeasureFont
+ ),
constraints = ParagraphConstraints(width = paragraphWidth)
)
@@ -2603,9 +2669,11 @@
val paragraph = simpleParagraph(
text = text,
- textIndent = TextIndent(restLine = indent.em),
- fontSize = fontSize.sp,
- fontFamily = fontFamilyMeasureFont,
+ style = TextStyle(
+ textIndent = TextIndent(restLine = indent.em),
+ fontSize = fontSize.sp,
+ fontFamily = fontFamilyMeasureFont
+ ),
constraints = ParagraphConstraints(width = paragraphWidth)
)
@@ -2632,8 +2700,10 @@
spanStyles = listOf(
AnnotatedString.Item(spanStyle, "a".length, text.length)
),
- fontSize = fontSize,
- fontFamily = fontFamilyCustom100
+ style = TextStyle(
+ fontSize = fontSize,
+ fontFamily = fontFamilyCustom100
+ )
)
assertThat(paragraph.lineCount).isEqualTo(1)
@@ -2655,8 +2725,10 @@
spanStyles = listOf(
AnnotatedString.Item(spanStyle, 0, "aA".length)
),
- fontSize = fontSize,
- fontFamily = fontFamilyKernFont
+ style = TextStyle(
+ fontSize = fontSize,
+ fontFamily = fontFamilyKernFont
+ )
)
// Two characters are kerning, so minus 0.4 * fontSize
@@ -2707,18 +2779,19 @@
val fontSize = 100.sp
val fontSizeInPx = fontSize.toPx().value
val paragraphWidth = fontSizeInPx * text.length
- val spanStyle = SpanStyle(color = Color.Red)
val paragraphWithoutColor = simpleParagraph(
text = text,
- fontSize = fontSize,
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(paragraphWidth)
)
val paragraphWithColor = simpleParagraph(
text = text,
- spanStyle = spanStyle,
- fontSize = fontSize,
+ style = TextStyle(
+ color = Color.Red,
+ fontSize = fontSize
+ ),
constraints = ParagraphConstraints(paragraphWidth)
)
@@ -2735,12 +2808,13 @@
val fontSize = 100.sp
val fontSizeInPx = fontSize.toPx().value
val letterSpacing = 1f
- val spanStyle = SpanStyle(letterSpacing = letterSpacing.em)
val paragraph = simpleParagraph(
text = text,
- spanStyle = spanStyle,
- fontSize = fontSize
+ style = TextStyle(
+ letterSpacing = letterSpacing.em,
+ fontSize = fontSize
+ )
)
assertThat(paragraph.getLineRight(0))
@@ -2756,8 +2830,10 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontFamily = fontFamilyMeasureFont,
- fontSize = fontSize
+ style = TextStyle(
+ fontFamily = fontFamilyMeasureFont,
+ fontSize = fontSize
+ )
)
val expectedPath = Path()
@@ -2788,8 +2864,10 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontFamily = fontFamilyMeasureFont,
- fontSize = fontSize
+ style = TextStyle(
+ fontFamily = fontFamilyMeasureFont,
+ fontSize = fontSize
+ )
)
val expectedPath = Path()
@@ -2834,8 +2912,10 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontFamily = fontFamilyMeasureFont,
- fontSize = fontSize
+ style = TextStyle(
+ fontFamily = fontFamilyMeasureFont,
+ fontSize = fontSize
+ )
)
val expectedPath = Path()
@@ -2872,8 +2952,10 @@
val text = "abc"
val paragraph = simpleParagraph(
text = text,
- fontFamily = fontFamilyMeasureFont,
- fontSize = 20.sp
+ style = TextStyle(
+ fontFamily = fontFamilyMeasureFont,
+ fontSize = 20.sp
+ )
)
val actualPath = paragraph.getPathForRange(1, 1)
@@ -2886,8 +2968,10 @@
val text = ""
val paragraph = simpleParagraph(
text = text,
- fontFamily = fontFamilyMeasureFont,
- fontSize = 20.sp
+ style = TextStyle(
+ fontFamily = fontFamilyMeasureFont,
+ fontSize = 20.sp
+ )
)
val actualPath = paragraph.getPathForRange(0, 0)
@@ -2903,8 +2987,10 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontFamily = fontFamilyMeasureFont,
- fontSize = fontSize
+ style = TextStyle(
+ fontFamily = fontFamilyMeasureFont,
+ fontSize = fontSize
+ )
)
val expectedPath = Path()
@@ -2927,8 +3013,10 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontFamily = fontFamilyMeasureFont,
- fontSize = fontSize
+ style = TextStyle(
+ fontFamily = fontFamilyMeasureFont,
+ fontSize = fontSize
+ )
)
val expectedPath = Path()
@@ -2951,8 +3039,10 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontFamily = fontFamilyMeasureFont,
- fontSize = fontSize
+ style = TextStyle(
+ fontFamily = fontFamilyMeasureFont,
+ fontSize = fontSize
+ )
)
val expectedPath = Path()
@@ -2975,8 +3065,10 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontFamily = fontFamilyMeasureFont,
- fontSize = fontSize
+ style = TextStyle(
+ fontFamily = fontFamilyMeasureFont,
+ fontSize = fontSize
+ )
)
val expectedPath = Path()
@@ -3007,8 +3099,10 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontFamily = fontFamilyMeasureFont,
- fontSize = fontSize
+ style = TextStyle(
+ fontFamily = fontFamilyMeasureFont,
+ fontSize = fontSize
+ )
)
val expectedPath = Path()
@@ -3032,8 +3126,10 @@
val fontSizeInPx = fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- fontFamily = fontFamilyMeasureFont,
- fontSize = fontSize
+ style = TextStyle(
+ fontFamily = fontFamilyMeasureFont,
+ fontSize = fontSize
+ )
)
val expectedPath = Path()
@@ -3054,8 +3150,10 @@
val text = "abc def"
val paragraph = simpleParagraph(
text = text,
- fontFamily = fontFamilyMeasureFont,
- fontSize = 20.sp
+ style = TextStyle(
+ fontFamily = fontFamilyMeasureFont,
+ fontSize = 20.sp
+ )
)
val result = paragraph.getWordBoundary(text.indexOf('a'))
@@ -3069,8 +3167,10 @@
val text = "abc \u05d0\u05d1\u05d2 def"
val paragraph = simpleParagraph(
text = text,
- fontFamily = fontFamilyMeasureFont,
- fontSize = 20.sp
+ style = TextStyle(
+ fontFamily = fontFamilyMeasureFont,
+ fontSize = 20.sp
+ )
)
val resultEnglish = paragraph.getWordBoundary(text.indexOf('a'))
@@ -3090,13 +3190,13 @@
val paragraph = simpleParagraph(
text = text,
- spanStyle = SpanStyle(fontSize = fontSize),
+ style = TextStyle(fontSize = fontSize),
density = Density(density = 1f, fontScale = 1f)
)
val doubleFontSizeParagraph = simpleParagraph(
text = text,
- spanStyle = SpanStyle(fontSize = fontSize),
+ style = TextStyle(fontSize = fontSize),
density = Density(density = 1f, fontScale = densityMultiplier)
)
@@ -3112,7 +3212,7 @@
val text = "b "
val paragraph = simpleParagraph(
text = text,
- spanStyle = SpanStyle(fontSize = fontSize)
+ style = TextStyle(fontSize = fontSize)
)
val expectedWidth = text.length * fontSize.toPx().value
@@ -3131,7 +3231,7 @@
val fontSize = 12.sp
val paragraph = simpleParagraph(
text = text,
- spanStyle = SpanStyle(fontSize = fontSize)
+ style = TextStyle(fontSize = fontSize)
)
// +1 is for the white space
@@ -3148,7 +3248,7 @@
val styledFontSize = fontSize * 2
val paragraph = simpleParagraph(
text = text,
- spanStyle = SpanStyle(fontSize = fontSize),
+ style = TextStyle(fontSize = fontSize),
spanStyles = listOf(
AnnotatedString.Item(
SpanStyle(fontSize = styledFontSize), "a".length, "a bb ".length
@@ -3200,11 +3300,9 @@
val paragraphIntrinsics = ParagraphIntrinsics(
text = text,
- spanStyle = SpanStyle(
+ style = TextStyle(
fontSize = fontSize,
- fontFamily = fontFamilyMeasureFont
- ),
- paragraphStyle = ParagraphStyle(
+ fontFamily = fontFamilyMeasureFont,
textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
),
spanStyles = listOf(),
@@ -3224,10 +3322,12 @@
@Test(expected = IllegalArgumentException::class)
fun nullTextDirectionAlgorithm_throwsException() {
- simpleParagraph(
+ Paragraph(
text = "",
- textDirectionAlgorithm = null,
- constraints = ParagraphConstraints(Float.MAX_VALUE)
+ style = TextStyle(textDirectionAlgorithm = null),
+ constraints = ParagraphConstraints(Float.MAX_VALUE),
+ density = defaultDensity,
+ resourceLoader = resourceLoader
)
}
@@ -3242,33 +3342,19 @@
private fun simpleParagraph(
text: String = "",
- textIndent: TextIndent? = null,
- textAlign: TextAlign? = null,
- fontSize: TextUnit = TextUnit.Inherit,
+ style: TextStyle? = null,
maxLines: Int = Int.MAX_VALUE,
- lineHeight: TextUnit = TextUnit.Inherit,
spanStyles: List<AnnotatedString.Item<SpanStyle>> = listOf(),
- fontFamily: FontFamily = fontFamilyMeasureFont,
- localeList: LocaleList? = null,
- spanStyle: SpanStyle? = null,
density: Density? = null,
- textDirectionAlgorithm: TextDirectionAlgorithm? = TextDirectionAlgorithm.ContentOrLtr,
constraints: ParagraphConstraints = ParagraphConstraints(Float.MAX_VALUE)
): Paragraph {
return Paragraph(
text = text,
spanStyles = spanStyles,
- spanStyle = SpanStyle(
- fontFamily = fontFamily,
- fontSize = fontSize,
- localeList = localeList
- ).merge(spanStyle),
- paragraphStyle = ParagraphStyle(
- textIndent = textIndent,
- textAlign = textAlign,
- textDirectionAlgorithm = textDirectionAlgorithm,
- lineHeight = lineHeight
- ),
+ style = TextStyle(
+ fontFamily = fontFamilyMeasureFont,
+ textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
+ ).merge(style),
maxLines = maxLines,
constraints = constraints,
density = density ?: defaultDensity,
diff --git a/ui/ui-text/src/androidTest/java/androidx/ui/text/ParagraphIntrinsicIntegrationTest.kt b/ui/ui-text/src/androidTest/java/androidx/ui/text/ParagraphIntrinsicIntegrationTest.kt
index 4eeff6f..c7a85bb 100644
--- a/ui/ui-text/src/androidTest/java/androidx/ui/text/ParagraphIntrinsicIntegrationTest.kt
+++ b/ui/ui-text/src/androidTest/java/androidx/ui/text/ParagraphIntrinsicIntegrationTest.kt
@@ -202,20 +202,18 @@
private fun paragraphIntrinsics(
text: String = "",
- style: SpanStyle? = null,
+ style: TextStyle? = null,
fontSize: TextUnit = 14.sp,
spanStyles: List<AnnotatedString.Item<SpanStyle>> = listOf()
): ParagraphIntrinsics {
return ParagraphIntrinsics(
text = text,
spanStyles = spanStyles,
- spanStyle = SpanStyle(
+ style = TextStyle(
fontFamily = fontFamilyMeasureFont,
- fontSize = fontSize
- ).merge(style),
- paragraphStyle = ParagraphStyle(
+ fontSize = fontSize,
textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
- ),
+ ).merge(style),
density = defaultDensity,
resourceLoader = TestFontResourceLoader(context)
)
diff --git a/ui/ui-text/src/androidTest/java/androidx/ui/text/TextDelegateIntegrationTest.kt b/ui/ui-text/src/androidTest/java/androidx/ui/text/TextDelegateIntegrationTest.kt
index 20bf3a8..6d0992a 100644
--- a/ui/ui-text/src/androidTest/java/androidx/ui/text/TextDelegateIntegrationTest.kt
+++ b/ui/ui-text/src/androidTest/java/androidx/ui/text/TextDelegateIntegrationTest.kt
@@ -59,7 +59,6 @@
val annotatedString = AnnotatedString(text, spanStyle)
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
density = density,
resourceLoader = resourceLoader,
layoutDirection = LayoutDirection.Ltr
@@ -80,7 +79,6 @@
val annotatedString = AnnotatedString(text, spanStyle)
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
density = density,
resourceLoader = resourceLoader,
layoutDirection = LayoutDirection.Ltr
@@ -102,7 +100,6 @@
val annotatedString = AnnotatedString(text, spanStyle)
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
density = density,
resourceLoader = resourceLoader,
layoutDirection = LayoutDirection.Ltr
@@ -124,7 +121,6 @@
val annotatedString = AnnotatedString(text, spanStyle)
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
density = density,
resourceLoader = resourceLoader,
layoutDirection = LayoutDirection.Ltr
@@ -144,7 +140,6 @@
val annotatedString = AnnotatedString(text, spanStyle)
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
density = density,
resourceLoader = resourceLoader,
layoutDirection = LayoutDirection.Ltr
@@ -160,7 +155,6 @@
fun layout_build_layoutResult() {
val textDelegate = TextDelegate(
text = AnnotatedString(text = "Hello"),
- paragraphStyle = ParagraphStyle(),
density = density,
resourceLoader = resourceLoader,
layoutDirection = LayoutDirection.Ltr
@@ -181,7 +175,6 @@
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
density = density,
resourceLoader = resourceLoader,
layoutDirection = LayoutDirection.Ltr
@@ -207,7 +200,6 @@
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
density = density,
resourceLoader = resourceLoader,
layoutDirection = LayoutDirection.Ltr
@@ -229,7 +221,6 @@
val annotatedString = AnnotatedString(text, spanStyle)
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
density = density,
resourceLoader = resourceLoader,
layoutDirection = LayoutDirection.Ltr
@@ -245,16 +236,12 @@
@Test
fun hasOverflowShaderFadeHorizontallyTrue() {
- var text = ""
- for (i in 1..15) {
- text += "Hello World"
- }
+ val text = "Hello World".repeat(15)
val spanStyle = SpanStyle(fontSize = 20.sp, fontFamily = fontFamily)
val annotatedString = AnnotatedString(text, spanStyle)
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
overflow = TextOverflow.Fade,
softWrap = false,
maxLines = 1,
@@ -273,15 +260,11 @@
@Test
fun hasOverflowShaderFadeVerticallyTrue() {
- var text = ""
- for (i in 1..30) {
- text += "Hello World"
- }
+ val text = "Hello World".repeat(30)
val spanStyle = SpanStyle(fontSize = 20.sp, fontFamily = fontFamily)
val annotatedString = AnnotatedString(text, spanStyle)
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
overflow = TextOverflow.Fade,
maxLines = 2,
density = density,
@@ -308,7 +291,6 @@
val annotatedString = AnnotatedString(text, spanStyle)
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
density = density,
resourceLoader = resourceLoader,
layoutDirection = LayoutDirection.Ltr
@@ -369,7 +351,6 @@
val annotatedString = AnnotatedString(text, spanStyle)
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
density = density,
resourceLoader = resourceLoader,
layoutDirection = LayoutDirection.Ltr
@@ -423,7 +404,6 @@
val annotatedString = AnnotatedString(text, spanStyle)
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
density = density,
resourceLoader = resourceLoader,
layoutDirection = LayoutDirection.Ltr
@@ -487,7 +467,6 @@
val selectionColor = Color(0x66AABB33)
val textDelegate = TextDelegate(
text = annotatedString,
- paragraphStyle = ParagraphStyle(),
density = density,
resourceLoader = resourceLoader,
layoutDirection = LayoutDirection.Ltr
diff --git a/ui/ui-text/src/androidTest/java/androidx/ui/text/platform/AndroidParagraphTest.kt b/ui/ui-text/src/androidTest/java/androidx/ui/text/platform/AndroidParagraphTest.kt
index ce1a346..174eb7e 100644
--- a/ui/ui-text/src/androidTest/java/androidx/ui/text/platform/AndroidParagraphTest.kt
+++ b/ui/ui-text/src/androidTest/java/androidx/ui/text/platform/AndroidParagraphTest.kt
@@ -33,9 +33,9 @@
import androidx.ui.text.FontTestData.Companion.BASIC_MEASURE_FONT
import androidx.ui.text.LocaleList
import androidx.ui.text.ParagraphConstraints
-import androidx.ui.text.ParagraphStyle
import androidx.ui.text.SpanStyle
import androidx.ui.text.TestFontResourceLoader
+import androidx.ui.text.TextStyle
import androidx.ui.text.font.FontFamily
import androidx.ui.text.font.FontStyle
import androidx.ui.text.font.FontSynthesis
@@ -79,7 +79,7 @@
for (text in arrayOf("abc\ndef", "\u05D0\u05D1\u05D2\n\u05D3\u05D4\u05D5")) {
val paragraphAndroid = simpleParagraph(
text = text,
- spanStyle = SpanStyle(
+ style = TextStyle(
fontSize = fontSize,
fontFamily = fontFamily
),
@@ -798,7 +798,7 @@
val paragraph = simpleParagraph(
text = "abc",
- spanStyle = SpanStyle(
+ style = TextStyle(
fontFamily = null,
fontWeight = FontWeight.Bold
),
@@ -824,7 +824,7 @@
val typefaceAdapter = spy(TypefaceAdapter())
val paragraph = simpleParagraph(
text = "abc",
- spanStyle = SpanStyle(
+ style = TextStyle(
fontFamily = null,
fontStyle = FontStyle.Italic
),
@@ -852,7 +852,7 @@
val paragraph = simpleParagraph(
text = "abc",
- spanStyle = SpanStyle(
+ style = TextStyle(
fontFamily = fontFamily
),
typefaceAdapter = typefaceAdapter,
@@ -877,7 +877,7 @@
val typefaceAdapter = spy(TypefaceAdapter())
val paragraph = simpleParagraph(
text = "abc",
- spanStyle = SpanStyle(
+ style = TextStyle(
fontFamily = fontFamily
),
typefaceAdapter = typefaceAdapter,
@@ -903,7 +903,7 @@
val paragraphWidth = (text.length - 1) * fontSize.toPx().value
val paragraph = simpleParagraph(
text = text,
- spanStyle = SpanStyle(
+ style = TextStyle(
fontFamily = fontFamily,
fontSize = fontSize
),
@@ -928,7 +928,7 @@
text = text,
ellipsis = true,
maxLines = 1,
- spanStyle = SpanStyle(
+ style = TextStyle(
fontFamily = fontFamily,
fontSize = fontSize
),
@@ -950,7 +950,7 @@
text = text,
ellipsis = true,
maxLines = maxLines,
- spanStyle = SpanStyle(
+ style = TextStyle(
fontFamily = fontFamily,
fontSize = fontSize
),
@@ -969,7 +969,7 @@
val fontSize = 100.sp
val paragraph = simpleParagraph(
text = "",
- spanStyle = SpanStyle(fontSize = fontSize),
+ style = TextStyle(fontSize = fontSize),
constraints = ParagraphConstraints(width = 0.0f)
)
@@ -984,7 +984,7 @@
val paragraph = simpleParagraph(
text = "",
- spanStyle = SpanStyle(localeList = localeList),
+ style = TextStyle(localeList = localeList),
constraints = ParagraphConstraints(width = 0.0f)
)
@@ -997,7 +997,7 @@
val color = Color(0x12345678)
val paragraph = simpleParagraph(
text = "",
- spanStyle = SpanStyle(color = color),
+ style = TextStyle(color = color),
constraints = ParagraphConstraints(width = 0.0f)
)
@@ -1009,7 +1009,7 @@
val letterSpacing = 2
val paragraph = simpleParagraph(
text = "",
- spanStyle = SpanStyle(letterSpacing = letterSpacing.em),
+ style = TextStyle(letterSpacing = letterSpacing.em),
constraints = ParagraphConstraints(width = 0.0f)
)
@@ -1021,7 +1021,7 @@
val fontFeatureSettings = "\"kern\" 0"
val paragraph = simpleParagraph(
text = "",
- spanStyle = SpanStyle(fontFeatureSettings = fontFeatureSettings),
+ style = TextStyle(fontFeatureSettings = fontFeatureSettings),
constraints = ParagraphConstraints(width = 0.0f)
)
@@ -1033,7 +1033,7 @@
val scaleX = 0.5f
val paragraph = simpleParagraph(
text = "",
- spanStyle = SpanStyle(
+ style = TextStyle(
textGeometricTransform = TextGeometricTransform(
scaleX = scaleX
)
@@ -1049,7 +1049,7 @@
val skewX = 0.5f
val paragraph = simpleParagraph(
text = "",
- spanStyle = SpanStyle(
+ style = TextStyle(
textGeometricTransform = TextGeometricTransform(
skewX = skewX
)
@@ -1064,7 +1064,7 @@
fun testSpanStyle_decoration_underline_appliedOnTextPaint() {
val paragraph = simpleParagraph(
text = "",
- spanStyle = SpanStyle(decoration = TextDecoration.Underline),
+ style = TextStyle(decoration = TextDecoration.Underline),
constraints = ParagraphConstraints(width = 0.0f)
)
@@ -1075,7 +1075,7 @@
fun testSpanStyle_decoration_lineThrough_appliedOnTextPaint() {
val paragraph = simpleParagraph(
text = "",
- spanStyle = SpanStyle(decoration = TextDecoration.LineThrough),
+ style = TextStyle(decoration = TextDecoration.LineThrough),
constraints = ParagraphConstraints(width = 0.0f)
)
@@ -1090,7 +1090,7 @@
val color = Color(0x12345678)
val paragraph = simpleParagraph(
text = text,
- spanStyle = SpanStyle(background = color),
+ style = TextStyle(background = color),
constraints = ParagraphConstraints(width = 0.0f)
)
@@ -1108,7 +1108,7 @@
val baselineShift = BaselineShift.Subscript
val paragraph = simpleParagraph(
text = text,
- spanStyle = SpanStyle(baselineShift = baselineShift),
+ style = TextStyle(baselineShift = baselineShift),
constraints = ParagraphConstraints(width = 0.0f)
)
@@ -1136,7 +1136,7 @@
val text = "abc"
val paragraph = simpleParagraph(
text = text,
- spanStyle = SpanStyle(localeList = localeList),
+ style = TextStyle(localeList = localeList),
constraints = ParagraphConstraints(width = Float.MAX_VALUE)
)
@@ -1149,7 +1149,7 @@
val text = "abc"
val paragraph = simpleParagraph(
text = text,
- spanStyle = SpanStyle(localeList = localeList),
+ style = TextStyle(localeList = localeList),
constraints = ParagraphConstraints(width = Float.MAX_VALUE)
)
@@ -1162,7 +1162,7 @@
val text = "abc"
val paragraph = simpleParagraph(
text = text,
- spanStyle = SpanStyle(localeList = localeList),
+ style = TextStyle(localeList = localeList),
constraints = ParagraphConstraints(width = Float.MAX_VALUE)
)
@@ -1189,19 +1189,18 @@
ellipsis: Boolean = false,
maxLines: Int = Int.MAX_VALUE,
constraints: ParagraphConstraints,
- spanStyle: SpanStyle? = null,
+ style: TextStyle? = null,
typefaceAdapter: TypefaceAdapter = TypefaceAdapter()
): AndroidParagraph {
return AndroidParagraph(
text = text,
spanStyles = spanStyles,
typefaceAdapter = typefaceAdapter,
- spanStyle = SpanStyle().merge(spanStyle),
- paragraphStyle = ParagraphStyle(
+ style = TextStyle(
textAlign = textAlign,
textIndent = textIndent,
textDirectionAlgorithm = textDirectionAlgorithm
- ),
+ ).merge(style),
maxLines = maxLines,
ellipsis = ellipsis,
constraints = constraints,
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/AnnotatedString.kt b/ui/ui-text/src/main/java/androidx/ui/text/AnnotatedString.kt
index 9391da4..0aa1bcb 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/AnnotatedString.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/AnnotatedString.kt
@@ -310,9 +310,7 @@
start: Int,
end: Int
): List<SpanStyleItem> {
- if (start == end) {
- return listOf()
- }
+ if (start == end) return listOf()
// If the given range covers the whole AnnotatedString, return SpanStyles without conversion.
if (start == 0 && end >= this.text.length) {
return spanStyles
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/MultiParagraph.kt b/ui/ui-text/src/main/java/androidx/ui/text/MultiParagraph.kt
index 2e7fa79..a1a9599 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/MultiParagraph.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/MultiParagraph.kt
@@ -48,8 +48,7 @@
* [MultiParagraph] can handle a text what has multiple paragraph styles.
*
* @param annotatedString the text to be laid out
- * @param spanStyle the [SpanStyle] to be applied to the whole text
- * @param paragraphStyle the [ParagraphStyle] to be applied to the whole text
+ * @param style the [TextStyle] to be applied to the whole text
* @param maxLines the maximum number of lines that the text can have
* @param ellipsis whether to ellipsize text, applied only when [maxLines] is set
* @param constraints how wide the text is allowed to be
@@ -60,8 +59,7 @@
*/
constructor(
annotatedString: AnnotatedString,
- spanStyle: SpanStyle,
- paragraphStyle: ParagraphStyle,
+ style: TextStyle,
maxLines: Int = Int.MAX_VALUE,
ellipsis: Boolean = false,
constraints: ParagraphConstraints,
@@ -70,8 +68,7 @@
) : this(
intrinsics = MultiParagraphIntrinsics(
annotatedString = annotatedString,
- spanStyle = spanStyle,
- paragraphStyle = paragraphStyle,
+ style = style,
density = density,
resourceLoader = resourceLoader
),
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/MultiParagraphIntrinsics.kt b/ui/ui-text/src/main/java/androidx/ui/text/MultiParagraphIntrinsics.kt
index eec8852..4a3b03a 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/MultiParagraphIntrinsics.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/MultiParagraphIntrinsics.kt
@@ -24,8 +24,7 @@
* Calculates and provides the intrinsic width and height of text that contains [ParagraphStyle].
*
* @param annotatedString the text to be laid out
- * @param spanStyle the [SpanStyle] to be applied to the whole text
- * @param paragraphStyle the [ParagraphStyle] to be applied to the whole text
+ * @param style the [TextStyle] to be applied to the whole text
* @param density density of the device
* @param resourceLoader [Font.ResourceLoader] to be used to load the font given in [SpanStyle]s
@@ -36,8 +35,7 @@
*/
class MultiParagraphIntrinsics(
val annotatedString: AnnotatedString,
- spanStyle: SpanStyle,
- paragraphStyle: ParagraphStyle,
+ style: TextStyle,
density: Density,
resourceLoader: Font.ResourceLoader
) : ParagraphIntrinsics {
@@ -53,21 +51,23 @@
internal val infoList: List<ParagraphIntrinsicInfo>
init {
- requireNotNull(paragraphStyle.textDirectionAlgorithm) {
+ requireNotNull(style.textDirectionAlgorithm) {
"ParagraphStyle.textDirectionAlgorithm should not be null"
}
+ val paragraphStyle = style.toParagraphStyle()
infoList = annotatedString
.mapEachParagraphStyle(paragraphStyle) { annotatedString, paragraphStyleItem ->
+ val currentParagraphStyle = resolveTextDirection(
+ paragraphStyleItem.item,
+ paragraphStyle
+ )
+
ParagraphIntrinsicInfo(
intrinsics = ParagraphIntrinsics(
text = annotatedString.text,
- paragraphStyle = resolveTextDirection(
- paragraphStyleItem.item,
- paragraphStyle
- ),
spanStyles = annotatedString.spanStyles,
- spanStyle = spanStyle,
+ style = style.merge(currentParagraphStyle),
density = density,
resourceLoader = resourceLoader
),
@@ -93,8 +93,10 @@
* @param style ParagraphStyle to be checked for [TextDirectionAlgorithm]
* @param defaultStyle [ParagraphStyle] passed to [MultiParagraphIntrinsics] as the main style
*/
- private fun resolveTextDirection(style: ParagraphStyle, defaultStyle: ParagraphStyle):
- ParagraphStyle {
+ private fun resolveTextDirection(
+ style: ParagraphStyle,
+ defaultStyle: ParagraphStyle
+ ): ParagraphStyle {
return style.textDirectionAlgorithm?.let { style } ?: style.copy(
textDirectionAlgorithm = defaultStyle.textDirectionAlgorithm
)
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/Paragraph.kt b/ui/ui-text/src/main/java/androidx/ui/text/Paragraph.kt
index 13fe320..fbe9a14 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/Paragraph.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/Paragraph.kt
@@ -207,8 +207,7 @@
* [ParagraphStyle].
*
* @param text the text to be laid out
- * @param spanStyle the [SpanStyle] to be applied to the whole text
- * @param paragraphStyle the [ParagraphStyle] to be applied to the whole text
+ * @param style the [TextStyle] to be applied to the whole text
* @param spanStyles [SpanStyle]s to be applied to parts of text
* @param maxLines the maximum number of lines that the text can have
* @param ellipsis whether to ellipsize text, applied only when [maxLines] is set
@@ -220,9 +219,8 @@
*/
/* actual */ fun Paragraph(
text: String,
- spanStyle: SpanStyle,
- paragraphStyle: ParagraphStyle,
- spanStyles: List<AnnotatedString.Item<SpanStyle>>,
+ style: TextStyle,
+ spanStyles: List<AnnotatedString.Item<SpanStyle>> = listOf(),
maxLines: Int = DefaultMaxLines,
ellipsis: Boolean = false,
constraints: ParagraphConstraints,
@@ -231,8 +229,7 @@
): Paragraph {
return AndroidParagraph(
text = text,
- spanStyle = spanStyle,
- paragraphStyle = paragraphStyle,
+ style = style,
spanStyles = spanStyles,
maxLines = maxLines,
ellipsis = ellipsis,
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/ParagraphIntrinsics.kt b/ui/ui-text/src/main/java/androidx/ui/text/ParagraphIntrinsics.kt
index 431e9e8..381d35b 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/ParagraphIntrinsics.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/ParagraphIntrinsics.kt
@@ -44,16 +44,14 @@
*/
/* actual */ fun ParagraphIntrinsics(
text: String,
- spanStyle: SpanStyle,
- paragraphStyle: ParagraphStyle,
- spanStyles: List<AnnotatedString.Item<SpanStyle>>,
+ style: TextStyle,
+ spanStyles: List<AnnotatedString.Item<SpanStyle>> = listOf(),
density: Density,
resourceLoader: Font.ResourceLoader
): ParagraphIntrinsics {
return AndroidParagraphIntrinsics(
text = text,
- spanStyle = spanStyle,
- paragraphStyle = paragraphStyle,
+ style = style,
typefaceAdapter = TypefaceAdapter(
resourceLoader = resourceLoader
),
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/TextDelegate.kt b/ui/ui-text/src/main/java/androidx/ui/text/TextDelegate.kt
index 264923d..f69a24e 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/TextDelegate.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/TextDelegate.kt
@@ -52,14 +52,25 @@
*
* We need to pass non-null font size to underlying paragraph.
*/
-private fun resolveSpanStyle(style: SpanStyle?) =
- if (style == null) {
- SpanStyle(fontSize = DefaultFontSize)
- } else if (style.fontSize.isInherit) {
- style.copy(fontSize = DefaultFontSize)
- } else {
- style
+private fun resolveTextStyle(style: TextStyle?, layoutDirection: LayoutDirection): TextStyle {
+ val textDirectionAlgorithm = style?.textDirectionAlgorithm
+ ?: resolveTextDirectionAlgorithm(layoutDirection, null)
+
+ val fontSize = style?.fontSize ?: DefaultFontSize
+
+ return when {
+ style == null -> TextStyle(
+ fontSize = fontSize,
+ textDirectionAlgorithm = textDirectionAlgorithm
+ )
+ style.textDirectionAlgorithm != textDirectionAlgorithm ||
+ style.fontSize != fontSize -> style.copy(
+ fontSize = fontSize,
+ textDirectionAlgorithm = textDirectionAlgorithm
+ )
+ else -> style
}
+}
/**
* An object that paints text onto a [Canvas].
@@ -77,14 +88,11 @@
*
* @param text the text to paint.
*
- * @param spanStyle The text style specified to render the text. Notice that you can also set text
+ * @param style The text style specified to render the text. Notice that you can also set text
* style on the given [AnnotatedString], and the style set on [text] always has higher priority
* than this setting. But if only one global text style is needed, passing it to [TextDelegate]
* is always preferred.
*
- * @param paragraphStyle style configuration that applies only to paragraphs such as text alignment,
- * or text direction.
- *
* @param maxLines An optional maximum number of lines for the text to span, wrapping if
* necessary. If the text exceeds the given number of lines, it is truncated such that subsequent
* lines are dropped.
@@ -104,8 +112,7 @@
@RestrictTo(RestrictTo.Scope.LIBRARY)
class TextDelegate(
val text: AnnotatedString,
- spanStyle: SpanStyle? = null,
- paragraphStyle: ParagraphStyle? = null,
+ style: TextStyle? = null,
val maxLines: Int = Int.MAX_VALUE,
val softWrap: Boolean = true,
val overflow: TextOverflow = TextOverflow.Clip,
@@ -145,25 +152,7 @@
val hasVisualOverflow: Boolean get() = didOverflowWidth || didOverflowHeight
}
- /**
- * The resolved text style.
- */
- val spanStyle: SpanStyle = resolveSpanStyle(spanStyle)
-
- /**
- * The paragraph style.
- *
- * If null is passed to constructor, use default paragraph style.
- */
- val paragraphStyle: ParagraphStyle = when {
- paragraphStyle == null -> ParagraphStyle(
- textDirectionAlgorithm = resolveTextDirectionAlgorithm(layoutDirection, null)
- )
- paragraphStyle.textDirectionAlgorithm == null -> paragraphStyle.copy(
- textDirectionAlgorithm = resolveTextDirectionAlgorithm(layoutDirection, null)
- )
- else -> paragraphStyle
- }
+ val style: TextStyle = resolveTextStyle(style, layoutDirection)
/**
* The text layout result. null if text layout is not computed.
@@ -233,8 +222,7 @@
fun layoutIntrinsics() {
var intrinsics = paragraphIntrinsics ?: MultiParagraphIntrinsics(
annotatedString = text,
- spanStyle = spanStyle,
- paragraphStyle = paragraphStyle,
+ style = style,
density = density,
resourceLoader = resourceLoader
)
@@ -445,9 +433,8 @@
return if (layoutResult.hasVisualOverflow && overflow == TextOverflow.Fade) {
val paragraph = Paragraph(
text = "\u2026", // horizontal ellipsis
- spanStyle = spanStyle,
- paragraphStyle = paragraphStyle,
spanStyles = listOf(),
+ style = style,
density = density,
resourceLoader = resourceLoader,
constraints = ParagraphConstraints(Float.POSITIVE_INFINITY)
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/TextStyle.kt b/ui/ui-text/src/main/java/androidx/ui/text/TextStyle.kt
index 2ced472..9344341 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/TextStyle.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/TextStyle.kt
@@ -154,6 +154,20 @@
paragraphStyle = toParagraphStyle().merge(other.toParagraphStyle())
)
}
+
+ fun merge(other: SpanStyle): TextStyle {
+ return TextStyle(
+ spanStyle = toSpanStyle().merge(other),
+ paragraphStyle = toParagraphStyle()
+ )
+ }
+
+ fun merge(other: ParagraphStyle): TextStyle {
+ return TextStyle(
+ spanStyle = toSpanStyle(),
+ paragraphStyle = toParagraphStyle().merge(other)
+ )
+ }
}
/**
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraph.kt b/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraph.kt
index 6954cd0..17feae8 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraph.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraph.kt
@@ -37,9 +37,9 @@
import androidx.ui.text.AnnotatedString
import androidx.ui.text.Paragraph
import androidx.ui.text.ParagraphConstraints
-import androidx.ui.text.ParagraphStyle
import androidx.ui.text.SpanStyle
import androidx.ui.text.TextRange
+import androidx.ui.text.TextStyle
import androidx.ui.text.style.TextAlign
import androidx.ui.text.style.TextDirection
import java.util.Locale as JavaLocale
@@ -56,8 +56,7 @@
constructor(
text: String,
- spanStyle: SpanStyle,
- paragraphStyle: ParagraphStyle,
+ style: TextStyle,
spanStyles: List<AnnotatedString.Item<SpanStyle>>,
maxLines: Int,
ellipsis: Boolean,
@@ -67,8 +66,7 @@
) : this(
paragraphIntrinsics = AndroidParagraphIntrinsics(
text = text,
- spanStyle = spanStyle,
- paragraphStyle = paragraphStyle,
+ style = style,
spanStyles = spanStyles,
typefaceAdapter = typefaceAdapter,
density = density
@@ -85,11 +83,11 @@
init {
require(maxLines >= 1) { "maxLines should be greater than 0" }
- val paragraphStyle = paragraphIntrinsics.paragraphStyle
+ val style = paragraphIntrinsics.style
- val alignment = toLayoutAlign(paragraphStyle.textAlign)
+ val alignment = toLayoutAlign(style.textAlign)
- val justificationMode = when (paragraphStyle.textAlign) {
+ val justificationMode = when (style.textAlign) {
TextAlign.Justify -> JUSTIFICATION_MODE_INTER_WORD
else -> DEFAULT_JUSTIFICATION_MODE
}
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraphHelper.kt b/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraphHelper.kt
index 13c926d..8c701e1 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraphHelper.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraphHelper.kt
@@ -62,26 +62,26 @@
import java.util.Locale as JavaLocale
internal fun TextPaint.applySpanStyle(
- spanStyle: SpanStyle,
+ style: SpanStyle,
typefaceAdapter: TypefaceAdapter,
density: Density
): SpanStyle {
- when (spanStyle.fontSize.type) {
+ when (style.fontSize.type) {
TextUnitType.Sp -> withDensity(density) {
- textSize = spanStyle.fontSize.toPx().value
+ textSize = style.fontSize.toPx().value
}
TextUnitType.Em -> {
- textSize *= spanStyle.fontSize.value
+ textSize *= style.fontSize.value
}
TextUnitType.Inherit -> {} // Do nothing
}
- if (spanStyle.hasFontAttributes()) {
- typeface = createTypeface(spanStyle, typefaceAdapter)
+ if (style.hasFontAttributes()) {
+ typeface = createTypeface(style, typefaceAdapter)
}
- spanStyle.localeList?.let {
+ style.localeList?.let {
if (Build.VERSION.SDK_INT >= 24) {
textLocales = it.toAndroidLocaleList()
} else {
@@ -90,34 +90,34 @@
}
}
- spanStyle.color?.let {
+ style.color?.let {
color = it.toArgb()
}
- when (spanStyle.letterSpacing.type) {
+ when (style.letterSpacing.type) {
TextUnitType.Sp -> withDensity(density) {
// Platform accept EM as a letter space. Convert Sp to Em
- letterSpacing = spanStyle.letterSpacing.toPx().value / textSize
+ letterSpacing = style.letterSpacing.toPx().value / textSize
}
TextUnitType.Em -> {
- letterSpacing = spanStyle.letterSpacing.value
+ letterSpacing = style.letterSpacing.value
}
TextUnitType.Inherit -> {} // Do nothing
}
- spanStyle.fontFeatureSettings?.let {
+ style.fontFeatureSettings?.let {
fontFeatureSettings = it
}
- spanStyle.textGeometricTransform?.let {
+ style.textGeometricTransform?.let {
textScaleX *= it.scaleX
}
- spanStyle.textGeometricTransform?.let {
+ style.textGeometricTransform?.let {
textSkewX += it.skewX
}
- spanStyle.shadow?.let {
+ style.shadow?.let {
setShadowLayer(
it.blurRadius.value,
it.offset.dx,
@@ -126,7 +126,7 @@
)
}
- spanStyle.decoration?.let {
+ style.decoration?.let {
if (it.contains(TextDecoration.Underline)) {
isUnderlineText = true
}
@@ -138,8 +138,8 @@
// baselineShift and bgColor is reset in the Android Layout constructor.
// therefore we cannot apply them on paint, have to use spans.
return SpanStyle(
- background = spanStyle.background,
- baselineShift = spanStyle.baselineShift
+ background = style.background,
+ baselineShift = style.baselineShift
)
}
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraphIntrinsics.kt b/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraphIntrinsics.kt
index 2fc807e..8bf967a 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraphIntrinsics.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraphIntrinsics.kt
@@ -22,13 +22,12 @@
import androidx.ui.core.Density
import androidx.ui.text.AnnotatedString
import androidx.ui.text.ParagraphIntrinsics
-import androidx.ui.text.ParagraphStyle
import androidx.ui.text.SpanStyle
+import androidx.ui.text.TextStyle
internal class AndroidParagraphIntrinsics(
val text: String,
- val spanStyle: SpanStyle,
- val paragraphStyle: ParagraphStyle,
+ val style: TextStyle,
val spanStyles: List<AnnotatedString.Item<SpanStyle>>,
val typefaceAdapter: TypefaceAdapter,
val density: Density
@@ -46,20 +45,24 @@
override val minIntrinsicWidth: Float
get() = layoutIntrinsics.minIntrinsicWidth
- internal val textDirectionHeuristic = paragraphStyle.textDirectionAlgorithm?.let {
- resolveTextDirectionHeuristics(paragraphStyle.textDirectionAlgorithm)
+ internal val textDirectionHeuristic = style.textDirectionAlgorithm?.let {
+ resolveTextDirectionHeuristics(style.textDirectionAlgorithm)
} ?: throw IllegalArgumentException(
- "ParagraphStyle.textDirectionAlgorithm should not be null"
+ "TextStyle.textDirectionAlgorithm should not be null"
)
init {
- val notAppliedStyle = textPaint.applySpanStyle(spanStyle, typefaceAdapter, density)
+ val notAppliedStyle = textPaint.applySpanStyle(
+ style.toSpanStyle(),
+ typefaceAdapter,
+ density
+ )
charSequence = createStyledText(
text = text,
contextFontSize = textPaint.textSize,
- lineHeight = paragraphStyle.lineHeight,
- textIndent = paragraphStyle.textIndent,
+ lineHeight = style.lineHeight,
+ textIndent = style.textIndent,
spanStyles = listOf(
AnnotatedString.Item(
notAppliedStyle,
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/style/TextDecoration.kt b/ui/ui-text/src/main/java/androidx/ui/text/style/TextDecoration.kt
index fa73392..7a5a2ba 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/style/TextDecoration.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/style/TextDecoration.kt
@@ -69,7 +69,7 @@
return "TextDecoration.None"
}
- var values: MutableList<String> = mutableListOf()
+ val values: MutableList<String> = mutableListOf()
if (!((mask and Underline.mask) == 0)) {
values.add("Underline")
}
@@ -77,7 +77,7 @@
values.add("LineThrough")
}
if ((values.size == 1)) {
- return "TextDecoration.${values.get(0)}"
+ return "TextDecoration.${values[0]}"
}
return "TextDecoration.combine([${values.joinToString(separator = ", ")}])"
}