diff options
| author | Siyamed Sinir <siyamed@google.com> | 2017-07-28 17:06:22 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-07-28 17:06:22 +0000 |
| commit | 5494361c592b83a641774130505eef00cd90a678 (patch) | |
| tree | f241f4afa3b5332daa527e2b39d85a6990a90011 /core/java/android/text/StaticLayout.java | |
| parent | 1234826acd6be6d1bf6b786105162d72d0123e58 (diff) | |
| parent | fb0b2dc754fe54269dc8aac86b6e8c1458f96013 (diff) | |
Merge changes from topic 'edit_text_linespacing'
* changes:
Fix DynamicLayout last line spacing
Fix EditText line spacing
Diffstat (limited to 'core/java/android/text/StaticLayout.java')
| -rw-r--r-- | core/java/android/text/StaticLayout.java | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java index 527c3604b488..e66e475b3a23 100644 --- a/core/java/android/text/StaticLayout.java +++ b/core/java/android/text/StaticLayout.java @@ -334,6 +334,17 @@ public class StaticLayout extends Layout { return this; } + /** + * Sets whether the line spacing should be applied for the last line. Default value is + * {@code false}. + * + * @hide + */ + /* package */ Builder setAddLastLineLineSpacing(boolean value) { + mAddLastLineLineSpacing = value; + return this; + } + private long[] getHyphenators(LocaleList locales) { final int length = locales.size(); final long[] result = new long[length]; @@ -430,6 +441,7 @@ public class StaticLayout extends Layout { int[] mLeftIndents; int[] mRightIndents; int mJustificationMode; + boolean mAddLastLineLineSpacing; Paint.FontMetricsInt mFontMetricsInt = new Paint.FontMetricsInt(); @@ -599,6 +611,7 @@ public class StaticLayout extends Layout { float spacingadd = b.mSpacingAdd; float ellipsizedWidth = b.mEllipsizedWidth; TextUtils.TruncateAt ellipsize = b.mEllipsize; + final boolean addLastLineSpacing = b.mAddLastLineLineSpacing; LineBreaks lineBreaks = new LineBreaks(); // TODO: move to builder to avoid allocation costs // store span end locations int[] spanEndCache = new int[4]; @@ -849,8 +862,8 @@ public class StaticLayout extends Layout { fmAscent, fmDescent, fmTop, fmBottom, v, spacingmult, spacingadd, chooseHt, chooseHtv, fm, flags[breakIndex], needMultiply, chdirs, dir, easy, bufEnd, includepad, trackpad, - chs, widths, paraStart, ellipsize, ellipsizedWidth, - lineWidths[breakIndex], paint, moreChars); + addLastLineSpacing, chs, widths, paraStart, ellipsize, + ellipsizedWidth, lineWidths[breakIndex], paint, moreChars); if (endPos < spanEnd) { // preserve metrics for current span @@ -890,7 +903,7 @@ public class StaticLayout extends Layout { spacingmult, spacingadd, null, null, fm, 0, needMultiply, measured.mLevels, measured.mDir, measured.mEasy, bufEnd, - includepad, trackpad, null, + includepad, trackpad, addLastLineSpacing, null, null, bufStart, ellipsize, ellipsizedWidth, 0, paint, false); } @@ -903,7 +916,7 @@ public class StaticLayout extends Layout { Paint.FontMetricsInt fm, int flags, boolean needMultiply, byte[] chdirs, int dir, boolean easy, int bufEnd, boolean includePad, - boolean trackPad, char[] chs, + boolean trackPad, boolean addLastLineLineSpacing, char[] chs, float[] widths, int widthStart, TextUtils.TruncateAt ellipsize, float ellipsisWidth, float textWidth, TextPaint paint, boolean moreChars) { @@ -987,7 +1000,20 @@ public class StaticLayout extends Layout { } } - boolean lastLine = mEllipsized || (end == bufEnd); + final boolean lastLine; + if (mEllipsized) { + lastLine = true; + } else { + final boolean lastCharIsNewLine = widthStart != bufEnd && bufEnd > 0 + && text.charAt(bufEnd - 1) == CHAR_NEW_LINE; + if (end == bufEnd && !lastCharIsNewLine) { + lastLine = true; + } else if (start == bufEnd && lastCharIsNewLine) { + lastLine = true; + } else { + lastLine = false; + } + } if (firstLine) { if (trackPad) { @@ -1011,7 +1037,7 @@ public class StaticLayout extends Layout { } } - if (needMultiply && !lastLine) { + if (needMultiply && (addLastLineLineSpacing || !lastLine)) { double ex = (below - above) * (spacingmult - 1) + spacingadd; if (ex >= 0) { extra = (int)(ex + EXTRA_ROUNDING); |
