Introduce NativeLineBreaker.Builder and ParagraphConstraint
To make NativeLineBreaker public API, introduce
NativeLineBreaker.Builder and ParagraphConstraint.
Here is a performance differences:
android.text.StaticLayoutPerfTest:
PrecomputedText Balanced Hyphenation : 635 -> 684: ( +49, +7.7%)
PrecomputedText Balanced NoHyphenation: 477 -> 523: ( +46, +9.6%)
PrecomputedText Greedy Hyphenation : 413 -> 463: ( +50, +12.1%)
PrecomputedText Greedy NoHyphenation : 413 -> 463: ( +50, +12.1%)
RandomText Balanced Hyphenation : 18,030 -> 18,157: (+127, +0.7%)
RandomText Balanced NoHyphenation : 7,390 -> 7,388: ( -2, -0.0%)
RandomText Greedy Hyphenation : 7,319 -> 7,331: ( +12, +0.2%)
RandomText Greedy NoHyphenation : 7,316 -> 7,375: ( +59, +0.8%)
draw
PrecomputedText NoStyle : 631 -> 627: ( -4, -0.6%)
PrecomputedText Style : 842 -> 847: ( +5, +0.6%)
RandomText NoStyle : 531 -> 547: ( +16, +3.0%)
RandomText Style : 754 -> 758: ( +4, +0.5%)
Bug: 112327179
Test: atest CtsWidgetTestCases:EditTextTest
CtsWidgetTestCases:TextViewFadingEdgeTest
FrameworksCoreTests:TextViewFallbackLineSpacingTest
FrameworksCoreTests:TextViewTest FrameworksCoreTests:TypefaceTest
CtsGraphicsTestCases:TypefaceTest CtsWidgetTestCases:TextViewTest
CtsTextTestCases FrameworksCoreTests:android.text
CtsWidgetTestCases:TextViewPrecomputedTextTest
CtsGraphicsTestCases:android.graphics.fonts
Change-Id: I5b817bbc9f00e5806efa98f239ee20ff3d688c50
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java
index ca952da..33c977b 100644
--- a/core/java/android/text/Layout.java
+++ b/core/java/android/text/Layout.java
@@ -50,9 +50,9 @@
public abstract class Layout {
/** @hide */
@IntDef(prefix = { "BREAK_STRATEGY_" }, value = {
- BREAK_STRATEGY_SIMPLE,
- BREAK_STRATEGY_HIGH_QUALITY,
- BREAK_STRATEGY_BALANCED
+ NativeLineBreaker.BREAK_STRATEGY_SIMPLE,
+ NativeLineBreaker.BREAK_STRATEGY_HIGH_QUALITY,
+ NativeLineBreaker.BREAK_STRATEGY_BALANCED
})
@Retention(RetentionPolicy.SOURCE)
public @interface BreakStrategy {}
@@ -63,19 +63,20 @@
* before it (which yields a more consistent user experience when editing), but layout may not
* be the highest quality.
*/
- public static final int BREAK_STRATEGY_SIMPLE = 0;
+ public static final int BREAK_STRATEGY_SIMPLE = NativeLineBreaker.BREAK_STRATEGY_SIMPLE;
/**
* Value for break strategy indicating high quality line breaking, including automatic
* hyphenation and doing whole-paragraph optimization of line breaks.
*/
- public static final int BREAK_STRATEGY_HIGH_QUALITY = 1;
+ public static final int BREAK_STRATEGY_HIGH_QUALITY =
+ NativeLineBreaker.BREAK_STRATEGY_HIGH_QUALITY;
/**
* Value for break strategy indicating balanced line breaking. The breaks are chosen to
* make all lines as close to the same length as possible, including automatic hyphenation.
*/
- public static final int BREAK_STRATEGY_BALANCED = 2;
+ public static final int BREAK_STRATEGY_BALANCED = NativeLineBreaker.BREAK_STRATEGY_BALANCED;
/** @hide */
@IntDef(prefix = { "HYPHENATION_FREQUENCY_" }, value = {
@@ -93,29 +94,32 @@
* layout and there is otherwise no valid break. Soft hyphens are ignored and will not be used
* as suggestions for potential line breaks.
*/
- public static final int HYPHENATION_FREQUENCY_NONE = 0;
+ public static final int HYPHENATION_FREQUENCY_NONE =
+ NativeLineBreaker.HYPHENATION_FREQUENCY_NONE;
/**
* Value for hyphenation frequency indicating a light amount of automatic hyphenation, which
* is a conservative default. Useful for informal cases, such as short sentences or chat
* messages.
*/
- public static final int HYPHENATION_FREQUENCY_NORMAL = 1;
+ public static final int HYPHENATION_FREQUENCY_NORMAL =
+ NativeLineBreaker.HYPHENATION_FREQUENCY_NORMAL;
/**
* Value for hyphenation frequency indicating the full amount of automatic hyphenation, typical
* in typography. Useful for running text and where it's important to put the maximum amount of
* text in a screen with limited space.
*/
- public static final int HYPHENATION_FREQUENCY_FULL = 2;
+ public static final int HYPHENATION_FREQUENCY_FULL =
+ NativeLineBreaker.HYPHENATION_FREQUENCY_FULL;
private static final ParagraphStyle[] NO_PARA_SPANS =
ArrayUtils.emptyArray(ParagraphStyle.class);
/** @hide */
@IntDef(prefix = { "JUSTIFICATION_MODE_" }, value = {
- JUSTIFICATION_MODE_NONE,
- JUSTIFICATION_MODE_INTER_WORD
+ NativeLineBreaker.JUSTIFICATION_MODE_NONE,
+ NativeLineBreaker.JUSTIFICATION_MODE_INTER_WORD
})
@Retention(RetentionPolicy.SOURCE)
public @interface JustificationMode {}
@@ -123,12 +127,13 @@
/**
* Value for justification mode indicating no justification.
*/
- public static final int JUSTIFICATION_MODE_NONE = 0;
+ public static final int JUSTIFICATION_MODE_NONE = NativeLineBreaker.JUSTIFICATION_MODE_NONE;
/**
* Value for justification mode indicating the text is justified by stretching word spacing.
*/
- public static final int JUSTIFICATION_MODE_INTER_WORD = 1;
+ public static final int JUSTIFICATION_MODE_INTER_WORD =
+ NativeLineBreaker.JUSTIFICATION_MODE_INTER_WORD;
/*
* Line spacing multiplier for default line spacing.