summaryrefslogtreecommitdiff
path: root/core/java/android/text/StaticLayout.java
diff options
context:
space:
mode:
authorSeigo Nonaka <nona@google.com>2017-10-09 11:10:24 -0700
committerSeigo Nonaka <nona@google.com>2017-10-13 15:57:48 -0700
commitf90c9b6437304d95344a1b29448ed1a0f2b95f76 (patch)
tree267f3ddd79a4313e4d95ef962339ae5e0135d48c /core/java/android/text/StaticLayout.java
parent35712aeaa85fb98d11f0a75cfbd25b0db14aa745 (diff)
Move hyphenator mapping to native code.
This CL contains the following changes: - Replace Hyphenator mapping in Java with minikin::HyphenatorMap. - Remove locale tracking code from StaticLayout.java - Stop creating Hyphenator pointer array in StaticLayout. Bug: 65024629 Bug: 67319341 Test: bit CtsTextTestCases:* Test: bit FrameworksCoreTests:android.text. Test: bit FrameworksCoreTests:android.widget.TextViewTest Change-Id: Ib88c8e816c70959057abe296cc434ddb70bc397a
Diffstat (limited to 'core/java/android/text/StaticLayout.java')
-rw-r--r--core/java/android/text/StaticLayout.java51
1 files changed, 8 insertions, 43 deletions
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java
index 4b6b6ae8bf83..5c60188db1e4 100644
--- a/core/java/android/text/StaticLayout.java
+++ b/core/java/android/text/StaticLayout.java
@@ -21,21 +21,18 @@ import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Paint;
-import android.os.LocaleList;
import android.text.style.LeadingMarginSpan;
import android.text.style.LeadingMarginSpan.LeadingMarginSpan2;
import android.text.style.LineHeightSpan;
import android.text.style.MetricAffectingSpan;
import android.text.style.TabStopSpan;
import android.util.Log;
-import android.util.Pair;
import android.util.Pools.SynchronizedPool;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.GrowingArrayUtils;
import java.util.Arrays;
-import java.util.Locale;
/**
* StaticLayout is a Layout for text that will not be edited after it
@@ -101,7 +98,6 @@ public class StaticLayout extends Layout {
b.mBreakStrategy = Layout.BREAK_STRATEGY_SIMPLE;
b.mHyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE;
b.mJustificationMode = Layout.JUSTIFICATION_MODE_NONE;
- b.mLocales = null;
b.mMeasuredText = MeasuredText.obtain();
return b;
@@ -118,7 +114,6 @@ public class StaticLayout extends Layout {
b.mMeasuredText = null;
b.mLeftIndents = null;
b.mRightIndents = null;
- b.mLocales = null;
b.mLeftPaddings = null;
b.mRightPaddings = null;
nFinishBuilder(b.mNativePtr);
@@ -409,17 +404,6 @@ public class StaticLayout extends Layout {
return this;
}
- @NonNull
- private long[] getHyphenators(@NonNull LocaleList locales) {
- final int length = locales.size();
- final long[] result = new long[length];
- for (int i = 0; i < length; i++) {
- final Locale locale = locales.get(i);
- result[i] = Hyphenator.get(locale).getNativePtr();
- }
- return result;
- }
-
/**
* Measurement and break iteration is done in native code. The protocol for using
* the native code is as follows.
@@ -438,27 +422,12 @@ public class StaticLayout extends Layout {
* After all paragraphs, call finish() to release expensive buffers.
*/
- private Pair<String, long[]> getLocaleAndHyphenatorIfChanged(TextPaint paint) {
- final LocaleList locales = paint.getTextLocales();
- if (!locales.equals(mLocales)) {
- mLocales = locales;
- return new Pair(locales.toLanguageTags(), getHyphenators(locales));
- } else {
- // passing null means keep current locale.
- // TODO: move locale change detection to native.
- return new Pair(null, null);
- }
- }
-
/* package */ void addStyleRun(TextPaint paint, int start, int end, boolean isRtl) {
- Pair<String, long[]> locHyph = getLocaleAndHyphenatorIfChanged(paint);
- nAddStyleRun(mNativePtr, paint.getNativeInstance(), start, end, isRtl, locHyph.first,
- locHyph.second);
+ nAddStyleRun(mNativePtr, paint.getNativeInstance(), start, end, isRtl);
}
/* package */ void addReplacementRun(TextPaint paint, int start, int end, float width) {
- Pair<String, long[]> locHyph = getLocaleAndHyphenatorIfChanged(paint);
- nAddReplacementRun(mNativePtr, start, end, width, locHyph.first, locHyph.second);
+ nAddReplacementRun(mNativePtr, paint.getNativeInstance(), start, end, width);
}
/**
@@ -516,8 +485,6 @@ public class StaticLayout extends Layout {
// This will go away and be subsumed by native builder code
private MeasuredText mMeasuredText;
- private LocaleList mLocales;
-
private static final SynchronizedPool<Builder> sPool = new SynchronizedPool<>(3);
}
@@ -807,9 +774,6 @@ public class StaticLayout extends Layout {
}
}
- // TODO: Move locale tracking code to native.
- b.mLocales = null; // Reset the locale tracking.
-
nSetupParagraph(b.mNativePtr, chs, paraEnd - paraStart,
firstWidth, firstWidthLineCount, restWidth,
variableTabStops, TAB_INCREMENT, b.mBreakStrategy, b.mHyphenationFrequency,
@@ -1537,15 +1501,16 @@ public class StaticLayout extends Layout {
@Nullable int[] indents, @Nullable int[] leftPaddings, @Nullable int[] rightPaddings,
@IntRange(from = 0) int indentsOffset);
+ // TODO: Make this method CriticalNative once native code defers doing layouts.
private static native void nAddStyleRun(
/* non-zero */ long nativePtr, /* non-zero */ long nativePaint,
- @IntRange(from = 0) int start, @IntRange(from = 0) int end, boolean isRtl,
- @Nullable String languageTags, @Nullable long[] hyphenators);
+ @IntRange(from = 0) int start, @IntRange(from = 0) int end, boolean isRtl);
- private static native void nAddReplacementRun(/* non-zero */ long nativePtr,
+ // TODO: Make this method CriticalNative once native code defers doing layouts.
+ private static native void nAddReplacementRun(
+ /* non-zero */ long nativePtr, /* non-zero */ long nativePaint,
@IntRange(from = 0) int start, @IntRange(from = 0) int end,
- @FloatRange(from = 0.0f) float width, @Nullable String languageTags,
- @Nullable long[] hyphenators);
+ @FloatRange(from = 0.0f) float width);
// populates LineBreaks and returns the number of breaks found
//