diff options
| author | Seigo Nonaka <nona@google.com> | 2018-02-13 21:40:01 +0000 |
|---|---|---|
| committer | Seigo Nonaka <nona@google.com> | 2018-02-14 17:03:16 +0000 |
| commit | 4e90fa262d57c1c1ee72166e2ddfce391696ca24 (patch) | |
| tree | 0b38575786a462224d2cddd07355649c6c939015 /core/java/android/text/TextLine.java | |
| parent | acc788a9525ab1759fb1a81100b6161a22b5b97d (diff) | |
Revert "Reorganize MeasuredText API"
The last change needs more discussion and found some edge cases. Revert and make small step-by-step changes.
Bug: 73091756
This reverts commit 7fd36d19e309ea515b4048cfaabb8035ceab7baf.
Change-Id: I89ff52a70cf6a5d6c553afa20f83719e1f9eb726
Diffstat (limited to 'core/java/android/text/TextLine.java')
| -rw-r--r-- | core/java/android/text/TextLine.java | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/core/java/android/text/TextLine.java b/core/java/android/text/TextLine.java index be5bb4d1809a..55367dcce47e 100644 --- a/core/java/android/text/TextLine.java +++ b/core/java/android/text/TextLine.java @@ -16,7 +16,6 @@ package android.text; -import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.graphics.Canvas; @@ -61,7 +60,7 @@ public class TextLine { private char[] mChars; private boolean mCharsValid; private Spanned mSpanned; - private PrecomputedText mComputed; + private MeasuredText mMeasured; // Additional width of whitespace for justification. This value is per whitespace, thus // the line width will increase by mAddedWidth x (number of stretchable whitespaces). @@ -120,7 +119,7 @@ public class TextLine { tl.mSpanned = null; tl.mTabs = null; tl.mChars = null; - tl.mComputed = null; + tl.mMeasured = null; tl.mMetricAffectingSpanSpanSet.recycle(); tl.mCharacterStyleSpanSet.recycle(); @@ -150,31 +149,10 @@ public class TextLine { * @param tabStops the tabStops. Can be null. */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) - public void set(TextPaint paint, CharSequence text, int start, - int limit, int dir, Directions directions, boolean hasTabs, TabStops tabStops) { - set(paint, text, null, start, limit, dir, directions, hasTabs, tabStops); - } - - /** - * Initializes a TextLine and prepares it for use. - * - * @param paint the base paint for the line - * @param text the text, can be Styled - * @param precomputed the precomputed text - * @param start the start of the line relative to the text - * @param limit the limit of the line relative to the text - * @param dir the paragraph direction of this line - * @param directions the directions information of this line - * @param hasTabs true if the line might contain tabs - * @param tabStops the tabStops. - */ - public void set(@NonNull TextPaint paint, @NonNull CharSequence text, - @Nullable PrecomputedText precomputed, @IntRange(from = 0) int start, - @IntRange(from = 0) int limit, int dir, @NonNull Directions directions, boolean hasTabs, - @Nullable TabStops tabStops) { + public void set(TextPaint paint, CharSequence text, int start, int limit, int dir, + Directions directions, boolean hasTabs, TabStops tabStops) { mPaint = paint; mText = text; - mComputed = precomputed; mStart = start; mLen = limit - start; mDir = dir; @@ -192,6 +170,14 @@ public class TextLine { hasReplacement = mReplacementSpanSpanSet.numberOfSpans > 0; } + mMeasured = null; + if (text instanceof MeasuredText) { + MeasuredText mt = (MeasuredText) text; + if (mt.canUseMeasuredResult(paint)) { + mMeasured = mt; + } + } + mCharsValid = hasReplacement || hasTabs || directions != Layout.DIRS_ALL_LEFT_TO_RIGHT; if (mCharsValid) { @@ -760,12 +746,12 @@ public class TextLine { return wp.getRunAdvance(mChars, start, end, contextStart, contextEnd, runIsRtl, offset); } else { final int delta = mStart; - if (mComputed == null) { + if (mMeasured == null) { // TODO: Enable measured getRunAdvance for ReplacementSpan and RTL text. return wp.getRunAdvance(mText, delta + start, delta + end, delta + contextStart, delta + contextEnd, runIsRtl, delta + offset); } else { - return mComputed.getWidth(start + delta, end + delta); + return mMeasured.getWidth(start + delta, end + delta); } } } |
