summaryrefslogtreecommitdiff
path: root/core/java/android/text/StaticLayout.java
diff options
context:
space:
mode:
authorGilles Debunne <debunne@google.com>2011-01-14 12:12:04 -0800
committerGilles Debunne <debunne@google.com>2011-01-30 18:23:13 -0800
commit0a4db3c5270440eeb7e4e44a7029926e239ec3bd (patch)
tree93978bf40f919f8c833a7fefac5727109d212efb /core/java/android/text/StaticLayout.java
parentcd73d1ed6d1149a2ae642e87ffe8d89100fbafec (diff)
Pixel were missing on the last line of text when using MaxLines.
Bug 3295544 Only the last line of text includes the bottomPadding (extra line spacing below the characters' descent. When The text is clipped using maxLines, the desired height correctly added this value, but getLineTop and getLineDescent are also used when the layout is drawn. The fix is to make the layout aware of its clipping so that these values are correctly updated. Change-Id: I703656cf45022d34a90f55f0ed8fc5e4b30f80b1
Diffstat (limited to 'core/java/android/text/StaticLayout.java')
-rw-r--r--core/java/android/text/StaticLayout.java60
1 files changed, 39 insertions, 21 deletions
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java
index 43dce53ea628..ac3df795c760 100644
--- a/core/java/android/text/StaticLayout.java
+++ b/core/java/android/text/StaticLayout.java
@@ -98,7 +98,7 @@ public class StaticLayout extends Layout
generate(source, bufstart, bufend, paint, outerwidth, align,
spacingmult, spacingadd, includepad, includepad,
- ellipsize != null, ellipsizedWidth, ellipsize);
+ ellipsizedWidth, ellipsize);
mMeasured = MeasuredText.recycle(mMeasured);
mFontMetricsInt = null;
@@ -119,8 +119,7 @@ public class StaticLayout extends Layout
Alignment align,
float spacingmult, float spacingadd,
boolean includepad, boolean trackpad,
- boolean breakOnlyAtSpaces,
- float ellipsizedWidth, TextUtils.TruncateAt where) {
+ float ellipsizedWidth, TextUtils.TruncateAt ellipsize) {
mLineCount = 0;
int v = 0;
@@ -281,8 +280,7 @@ public class StaticLayout extends Layout
int emoji = Character.codePointAt(chs, j - paraStart);
if (emoji >= MIN_EMOJI && emoji <= MAX_EMOJI) {
- Bitmap bm = EMOJI_FACTORY.
- getBitmapFromAndroidPua(emoji);
+ Bitmap bm = EMOJI_FACTORY.getBitmapFromAndroidPua(emoji);
if (bm != null) {
Paint whichPaint;
@@ -362,7 +360,8 @@ public class StaticLayout extends Layout
okbottom = fitbottom;
}
} else {
- if (breakOnlyAtSpaces) {
+ if (ellipsize != null) {
+ // Break only at spaces using ok indexes.
if (ok != here) {
// Log.e("text", "output ok " + here + " to " +ok);
@@ -379,7 +378,7 @@ public class StaticLayout extends Layout
needMultiply, paraStart, chdirs, dir, easy,
ok == bufend, includepad, trackpad,
chs, widths, here - paraStart,
- where, ellipsizedWidth, okwidth,
+ ellipsize, ellipsizedWidth, okwidth,
paint);
here = ok;
@@ -415,7 +414,7 @@ public class StaticLayout extends Layout
needMultiply, paraStart, chdirs, dir, easy,
ok == bufend, includepad, trackpad,
chs, widths, here - paraStart,
- where, ellipsizedWidth, okwidth,
+ ellipsize, ellipsizedWidth, okwidth,
paint);
here = ok;
@@ -431,7 +430,7 @@ public class StaticLayout extends Layout
needMultiply, paraStart, chdirs, dir, easy,
fit == bufend, includepad, trackpad,
chs, widths, here - paraStart,
- where, ellipsizedWidth, fitwidth,
+ ellipsize, ellipsizedWidth, fitwidth,
paint);
here = fit;
@@ -453,7 +452,7 @@ public class StaticLayout extends Layout
here + 1 == bufend, includepad,
trackpad,
chs, widths, here - paraStart,
- where, ellipsizedWidth,
+ ellipsize, ellipsizedWidth,
widths[here - paraStart], paint);
here = here + 1;
@@ -502,7 +501,7 @@ public class StaticLayout extends Layout
needMultiply, paraStart, chdirs, dir, easy,
paraEnd == bufend, includepad, trackpad,
chs, widths, here - paraStart,
- where, ellipsizedWidth, w, paint);
+ ellipsize, ellipsizedWidth, w, paint);
}
paraStart = paraEnd;
@@ -525,7 +524,7 @@ public class StaticLayout extends Layout
needMultiply, bufend, null, DEFAULT_DIR, true,
true, includepad, trackpad,
null, null, bufstart,
- where, ellipsizedWidth, 0, paint);
+ ellipsize, ellipsizedWidth, 0, paint);
}
}
@@ -738,13 +737,13 @@ public class StaticLayout extends Layout
} else {
mLineDirections[j] = AndroidBidi.directions(dir, chdirs, widstart, chs,
widstart, end - start);
+ }
- // If ellipsize is in marquee mode, do not apply ellipsis on the first line
- if (ellipsize != null && (ellipsize != TextUtils.TruncateAt.MARQUEE || j != 0)) {
- calculateEllipsis(start, end, widths, widstart,
- ellipsiswidth, ellipsize, j,
- textwidth, paint);
- }
+ // If ellipsize is in marquee mode, do not apply ellipsis on the first line
+ if (ellipsize != null && (ellipsize != TextUtils.TruncateAt.MARQUEE || j != 0)) {
+ calculateEllipsis(start, end, widths, widstart,
+ ellipsiswidth, ellipsize, j,
+ textwidth, paint);
}
mLineCount++;
@@ -755,7 +754,6 @@ public class StaticLayout extends Layout
float[] widths, int widstart,
float avail, TextUtils.TruncateAt where,
int line, float textwidth, TextPaint paint) {
- int len = lineend - linestart;
if (textwidth <= avail) {
// Everything fits!
@@ -766,6 +764,7 @@ public class StaticLayout extends Layout
float ellipsiswid = paint.measureText("\u2026");
int ellipsisStart, ellipsisCount;
+ int len = lineend - linestart;
if (where == TextUtils.TruncateAt.START) {
float sum = 0;
@@ -865,12 +864,22 @@ public class StaticLayout extends Layout
@Override
public int getLineTop(int line) {
- return mLines[mColumns * line + TOP];
+ int top = mLines[mColumns * line + TOP];
+ if (mMaximumVisibleLineCount > 0 && line >= mMaximumVisibleLineCount &&
+ line != mLineCount) {
+ top += getBottomPadding();
+ }
+ return top;
}
@Override
public int getLineDescent(int line) {
- return mLines[mColumns * line + DESCENT];
+ int descent = mLines[mColumns * line + DESCENT];
+ if (mMaximumVisibleLineCount > 0 && line >= mMaximumVisibleLineCount - 1 &&
+ line != mLineCount) {
+ descent += getBottomPadding();
+ }
+ return descent;
}
@Override
@@ -926,6 +935,14 @@ public class StaticLayout extends Layout
return mEllipsizedWidth;
}
+ /**
+ * @hide
+ */
+ @Override
+ public void setMaximumVisibleLineCount(int line) {
+ mMaximumVisibleLineCount = line;
+ }
+
private int mLineCount;
private int mTopPadding, mBottomPadding;
private int mColumns;
@@ -943,6 +960,7 @@ public class StaticLayout extends Layout
private int[] mLines;
private Directions[] mLineDirections;
+ private int mMaximumVisibleLineCount = 0;
private static final int START_MASK = 0x1FFFFFFF;
private static final int DIR_SHIFT = 30;