summaryrefslogtreecommitdiff
path: root/graphics/java/android
diff options
context:
space:
mode:
author James.cf Lin <jamescflin@google.com> 2022-01-19 16:56:34 +0800
committer James.cf Lin <jamescflin@google.com> 2022-01-22 12:27:51 +0800
commit664a75b40770dcea0a56b5763f3e27fe9553fd74 (patch)
treef4cb98b5dc57919732d7e101137a722dd35221a6 /graphics/java/android
parent20ba147a1138be3ea40d7e20651ac5dd83afab1e (diff)
Add line break word style parameter in the LineBreakConfig
The line break word style(lw) provides the phrase-based breaking opportunities. When the line break word style is set, it will be brought to ICU for calculation. Bug: 183780874 Test: atest minikin_tests; atest TextViewTest; atest MeasuredTextTest; atest PrecomputedTextTest Change-Id: Idd851497e46c1fca87ff590230d93f8bb5c9afae
Diffstat (limited to 'graphics/java/android')
-rw-r--r--graphics/java/android/graphics/text/LineBreakConfig.java58
-rw-r--r--graphics/java/android/graphics/text/MeasuredText.java10
2 files changed, 55 insertions, 13 deletions
diff --git a/graphics/java/android/graphics/text/LineBreakConfig.java b/graphics/java/android/graphics/text/LineBreakConfig.java
index 4d818583fd23..cffdf28dbc27 100644
--- a/graphics/java/android/graphics/text/LineBreakConfig.java
+++ b/graphics/java/android/graphics/text/LineBreakConfig.java
@@ -17,7 +17,7 @@
package android.graphics.text;
import android.annotation.IntDef;
-import android.annotation.Nullable;
+import android.annotation.NonNull;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -58,7 +58,28 @@ public final class LineBreakConfig {
@Retention(RetentionPolicy.SOURCE)
public @interface LineBreakStyle {}
+ /**
+ * No line break word style specified.
+ */
+ public static final int LINE_BREAK_WORD_STYLE_NONE = 0;
+
+ /**
+ * Indicates the line breaking is based on the phrased. This makes text wrapping only on
+ * meaningful words. The support of the text wrapping word style varies depending on the
+ * locales. If the locale does not support the phrase based text wrapping,
+ * there will be no effect.
+ */
+ public static final int LINE_BREAK_WORD_STYLE_PHRASE = 1;
+
+ /** @hide */
+ @IntDef(prefix = { "LINE_BREAK_WORD_STYLE_" }, value = {
+ LINE_BREAK_WORD_STYLE_NONE, LINE_BREAK_WORD_STYLE_PHRASE
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface LineBreakWordStyle {}
+
private @LineBreakStyle int mLineBreakStyle = LINE_BREAK_STYLE_NONE;
+ private @LineBreakWordStyle int mLineBreakWordStyle = LINE_BREAK_WORD_STYLE_NONE;
public LineBreakConfig() {
}
@@ -66,14 +87,12 @@ public final class LineBreakConfig {
/**
* Set the line break configuration.
*
- * @param config the new line break configuration.
+ * @param lineBreakConfig the new line break configuration.
*/
- public void set(@Nullable LineBreakConfig config) {
- if (config != null) {
- mLineBreakStyle = config.getLineBreakStyle();
- } else {
- mLineBreakStyle = LineBreakConfig.LINE_BREAK_STYLE_NONE;
- }
+ public void set(@NonNull LineBreakConfig lineBreakConfig) {
+ Objects.requireNonNull(lineBreakConfig);
+ mLineBreakStyle = lineBreakConfig.getLineBreakStyle();
+ mLineBreakWordStyle = lineBreakConfig.getLineBreakWordStyle();
}
/**
@@ -94,17 +113,36 @@ public final class LineBreakConfig {
mLineBreakStyle = lineBreakStyle;
}
+ /**
+ * Get the line break word style.
+ *
+ * @return The current line break word style to be used for the text wrapping.
+ */
+ public @LineBreakWordStyle int getLineBreakWordStyle() {
+ return mLineBreakWordStyle;
+ }
+
+ /**
+ * Set the line break word style.
+ *
+ * @param lineBreakWordStyle the new line break word style.
+ */
+ public void setLineBreakWordStyle(@LineBreakWordStyle int lineBreakWordStyle) {
+ mLineBreakWordStyle = lineBreakWordStyle;
+ }
+
@Override
public boolean equals(Object o) {
if (o == null) return false;
if (this == o) return true;
if (!(o instanceof LineBreakConfig)) return false;
LineBreakConfig that = (LineBreakConfig) o;
- return mLineBreakStyle == that.mLineBreakStyle;
+ return (mLineBreakStyle == that.mLineBreakStyle)
+ && (mLineBreakWordStyle == that.mLineBreakWordStyle);
}
@Override
public int hashCode() {
- return Objects.hash(mLineBreakStyle);
+ return Objects.hash(mLineBreakStyle, mLineBreakWordStyle);
}
}
diff --git a/graphics/java/android/graphics/text/MeasuredText.java b/graphics/java/android/graphics/text/MeasuredText.java
index 5f4afb7b9888..6d691c122576 100644
--- a/graphics/java/android/graphics/text/MeasuredText.java
+++ b/graphics/java/android/graphics/text/MeasuredText.java
@@ -264,8 +264,10 @@ public class MeasuredText {
Preconditions.checkArgument(end <= mText.length, "Style exceeds the text length");
int lbStyle = (lineBreakConfig != null) ? lineBreakConfig.getLineBreakStyle() :
LineBreakConfig.LINE_BREAK_STYLE_NONE;
- nAddStyleRun(mNativePtr, paint.getNativeInstance(), lbStyle, mCurrentOffset, end,
- isRtl);
+ int lbWordStyle = (lineBreakConfig != null) ? lineBreakConfig.getLineBreakWordStyle() :
+ LineBreakConfig.LINE_BREAK_WORD_STYLE_NONE;
+ nAddStyleRun(mNativePtr, paint.getNativeInstance(), lbStyle, lbWordStyle,
+ mCurrentOffset, end, isRtl);
mCurrentOffset = end;
return this;
}
@@ -445,7 +447,8 @@ public class MeasuredText {
*
* @param nativeBuilderPtr The native MeasuredParagraph builder pointer.
* @param paintPtr The native paint pointer to be applied.
- * @param lineBreakStyle The line break style of the text.
+ * @param lineBreakStyle The line break style(lb) of the text.
+ * @param lineBreakWordStyle The line break word style(lw) of the text.
* @param start The start offset in the copied buffer.
* @param end The end offset in the copied buffer.
* @param isRtl True if the text is RTL.
@@ -453,6 +456,7 @@ public class MeasuredText {
private static native void nAddStyleRun(/* Non Zero */ long nativeBuilderPtr,
/* Non Zero */ long paintPtr,
int lineBreakStyle,
+ int lineBreakWordStyle,
@IntRange(from = 0) int start,
@IntRange(from = 0) int end,
boolean isRtl);