summaryrefslogtreecommitdiff
path: root/core/java/android/text/TextLine.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/text/TextLine.java')
-rw-r--r--core/java/android/text/TextLine.java42
1 files changed, 28 insertions, 14 deletions
diff --git a/core/java/android/text/TextLine.java b/core/java/android/text/TextLine.java
index 55367dcce47e..be5bb4d1809a 100644
--- a/core/java/android/text/TextLine.java
+++ b/core/java/android/text/TextLine.java
@@ -16,6 +16,7 @@
package android.text;
+import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Canvas;
@@ -60,7 +61,7 @@ public class TextLine {
private char[] mChars;
private boolean mCharsValid;
private Spanned mSpanned;
- private MeasuredText mMeasured;
+ private PrecomputedText mComputed;
// Additional width of whitespace for justification. This value is per whitespace, thus
// the line width will increase by mAddedWidth x (number of stretchable whitespaces).
@@ -119,7 +120,7 @@ public class TextLine {
tl.mSpanned = null;
tl.mTabs = null;
tl.mChars = null;
- tl.mMeasured = null;
+ tl.mComputed = null;
tl.mMetricAffectingSpanSpanSet.recycle();
tl.mCharacterStyleSpanSet.recycle();
@@ -149,10 +150,31 @@ 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) {
+ 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) {
mPaint = paint;
mText = text;
+ mComputed = precomputed;
mStart = start;
mLen = limit - start;
mDir = dir;
@@ -170,14 +192,6 @@ 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) {
@@ -746,12 +760,12 @@ public class TextLine {
return wp.getRunAdvance(mChars, start, end, contextStart, contextEnd, runIsRtl, offset);
} else {
final int delta = mStart;
- if (mMeasured == null) {
+ if (mComputed == 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 mMeasured.getWidth(start + delta, end + delta);
+ return mComputed.getWidth(start + delta, end + delta);
}
}
}