diff options
| author | Roozbeh Pournader <roozbeh@google.com> | 2017-08-08 15:49:01 -0700 |
|---|---|---|
| committer | Roozbeh Pournader <roozbeh@google.com> | 2017-08-08 16:21:46 -0700 |
| commit | b1f0365dc4283fda926d5ff9f35c042220022ff6 (patch) | |
| tree | acc9031e893814f99ec16a594d2afefbd77439cc /core/java/android/text/Layout.java | |
| parent | a7d731d5fecbac339a37ad963253b651b1ba7046 (diff) | |
Make sure Layout doesn't modify the paint
Previously, Layout would modify the HyphenEdit of the Paint passed to it
for its internal operations, potentially leaving the Paint in a different status than when
it was created. Now we use an internal copy of the Paint to modify.
Fixes: 64452136
Test: bit CtsTextTestCases:android.text.cts.
Test: bit FrameworksCoreTests:android.text.
Change-Id: I0b95a10c05711350950d6c8d6501f6af9414d413
Diffstat (limited to 'core/java/android/text/Layout.java')
| -rw-r--r-- | core/java/android/text/Layout.java | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java index d612fc7360b3..04596f5ea1cf 100644 --- a/core/java/android/text/Layout.java +++ b/core/java/android/text/Layout.java @@ -402,7 +402,8 @@ public abstract class Layout { int previousLineEnd = getLineStart(firstLine); ParagraphStyle[] spans = NO_PARA_SPANS; int spanEnd = 0; - final TextPaint paint = mPaint; + final TextPaint paint = mWorkPaint; + paint.set(mPaint); CharSequence buf = mText; Alignment paraAlign = mAlignment; @@ -418,6 +419,7 @@ public abstract class Layout { previousLineEnd = getLineStart(lineNum + 1); final boolean justify = isJustificationRequired(lineNum); int end = getLineVisibleEnd(lineNum, start, previousLineEnd); + paint.setHyphenEdit(getHyphen(lineNum)); int ltop = previousLineBottom; int lbottom = getLineTop(lineNum + 1); @@ -541,7 +543,6 @@ public abstract class Layout { } } - paint.setHyphenEdit(getHyphen(lineNum)); Directions directions = getLineDirections(lineNum); if (directions == DIRS_ALL_LEFT_TO_RIGHT && !mSpannedText && !hasTab && !justify) { // XXX: assumes there's nothing additional to be done @@ -553,7 +554,6 @@ public abstract class Layout { } tl.draw(canvas, x, ltop, lbaseline, lbottom); } - paint.setHyphenEdit(0); } TextLine.recycle(tl); @@ -1208,10 +1208,10 @@ public abstract class Layout { * @return the extent of the line */ private float getLineExtent(int line, boolean full) { - int start = getLineStart(line); - int end = full ? getLineEnd(line) : getLineVisibleEnd(line); + final int start = getLineStart(line); + final int end = full ? getLineEnd(line) : getLineVisibleEnd(line); - boolean hasTabs = getLineContainsTab(line); + final boolean hasTabs = getLineContainsTab(line); TabStops tabStops = null; if (hasTabs && mText instanceof Spanned) { // Just checking this line should be good enough, tabs should be @@ -1221,21 +1221,22 @@ public abstract class Layout { tabStops = new TabStops(TAB_INCREMENT, tabs); // XXX should reuse } } - Directions directions = getLineDirections(line); + final Directions directions = getLineDirections(line); // Returned directions can actually be null if (directions == null) { return 0f; } - int dir = getParagraphDirection(line); + final int dir = getParagraphDirection(line); - TextLine tl = TextLine.obtain(); - mPaint.setHyphenEdit(getHyphen(line)); + final TextLine tl = TextLine.obtain(); + final TextPaint paint = mWorkPaint; + paint.set(mPaint); + paint.setHyphenEdit(getHyphen(line)); tl.set(mPaint, mText, start, end, dir, directions, hasTabs, tabStops); if (isJustificationRequired(line)) { tl.justify(getJustifyWidth(line)); } - float width = tl.metrics(null); - mPaint.setHyphenEdit(0); + final float width = tl.metrics(null); TextLine.recycle(tl); return width; } @@ -1249,20 +1250,21 @@ public abstract class Layout { * @return the extent of the text on this line */ private float getLineExtent(int line, TabStops tabStops, boolean full) { - int start = getLineStart(line); - int end = full ? getLineEnd(line) : getLineVisibleEnd(line); - boolean hasTabs = getLineContainsTab(line); - Directions directions = getLineDirections(line); - int dir = getParagraphDirection(line); - - TextLine tl = TextLine.obtain(); - mPaint.setHyphenEdit(getHyphen(line)); + final int start = getLineStart(line); + final int end = full ? getLineEnd(line) : getLineVisibleEnd(line); + final boolean hasTabs = getLineContainsTab(line); + final Directions directions = getLineDirections(line); + final int dir = getParagraphDirection(line); + + final TextLine tl = TextLine.obtain(); + final TextPaint paint = mWorkPaint; + paint.set(mPaint); + paint.setHyphenEdit(getHyphen(line)); tl.set(mPaint, mText, start, end, dir, directions, hasTabs, tabStops); if (isJustificationRequired(line)) { tl.justify(getJustifyWidth(line)); } - float width = tl.metrics(null); - mPaint.setHyphenEdit(0); + final float width = tl.metrics(null); TextLine.recycle(tl); return width; } @@ -2233,6 +2235,7 @@ public abstract class Layout { private CharSequence mText; private TextPaint mPaint; + private TextPaint mWorkPaint = new TextPaint(); private int mWidth; private Alignment mAlignment = Alignment.ALIGN_NORMAL; private float mSpacingMult; |
