summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/text/DynamicLayout.java6
-rw-r--r--core/java/android/text/StaticLayout.java144
2 files changed, 65 insertions, 85 deletions
diff --git a/core/java/android/text/DynamicLayout.java b/core/java/android/text/DynamicLayout.java
index f82c9c4f06e8..026af34445f6 100644
--- a/core/java/android/text/DynamicLayout.java
+++ b/core/java/android/text/DynamicLayout.java
@@ -281,9 +281,9 @@ extends Layout
}
reflowed.generate(text, where, where + after,
- getPaint(), getWidth(), getAlignment(), getTextDirectionHeuristic(),
- getSpacingMultiplier(), getSpacingAdd(),
- false, true, mEllipsizedWidth, mEllipsizeAt);
+ getPaint(), getWidth(), getTextDirectionHeuristic(), getSpacingMultiplier(),
+ getSpacingAdd(), false,
+ true, mEllipsizedWidth, mEllipsizeAt);
int n = reflowed.getLineCount();
// If the new layout has a blank line at the end, but it is not
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java
index 583cbe615fa4..1dd4c8a96904 100644
--- a/core/java/android/text/StaticLayout.java
+++ b/core/java/android/text/StaticLayout.java
@@ -137,9 +137,9 @@ public class StaticLayout extends Layout {
mMeasured = MeasuredText.obtain();
- generate(source, bufstart, bufend, paint, outerwidth, align, textDir,
- spacingmult, spacingadd, includepad, includepad,
- ellipsizedWidth, ellipsize);
+ generate(source, bufstart, bufend, paint, outerwidth, textDir, spacingmult,
+ spacingadd, includepad, includepad, ellipsizedWidth,
+ ellipsize);
mMeasured = MeasuredText.recycle(mMeasured);
mFontMetricsInt = null;
@@ -157,10 +157,10 @@ public class StaticLayout extends Layout {
/* package */ void generate(CharSequence source, int bufStart, int bufEnd,
TextPaint paint, int outerWidth,
- Alignment align, TextDirectionHeuristic textDir,
- float spacingmult, float spacingadd,
- boolean includepad, boolean trackpad,
- float ellipsizedWidth, TextUtils.TruncateAt ellipsize) {
+ TextDirectionHeuristic textDir, float spacingmult,
+ float spacingadd, boolean includepad,
+ boolean trackpad, float ellipsizedWidth,
+ TextUtils.TruncateAt ellipsize) {
mLineCount = 0;
int v = 0;
@@ -328,9 +328,7 @@ public class StaticLayout extends Layout {
whichPaint = mWorkPaint;
}
- float wid = bm.getWidth() *
- -whichPaint.ascent() /
- bm.getHeight();
+ float wid = bm.getWidth() * -whichPaint.ascent() / bm.getHeight();
w += wid;
hasTabOrEmoji = true;
@@ -398,67 +396,49 @@ public class StaticLayout extends Layout {
okBottom = fitBottom;
}
} else {
- final boolean moreChars = (j + 1 < spanEnd);
- if (ok != here) {
- // Log.e("text", "output ok " + here + " to " +ok);
+ final boolean moreChars = (j + 1 < spanEnd);
+ int endPos;
+ int above, below, top, bottom;
+ float currentTextWidth;
- while (ok < spanEnd && chs[ok - paraStart] == CHAR_SPACE) {
- ok++;
- }
+ if (ok != here) {
+ // If it is a space that makes the length exceed width, cut here
+ if (c == CHAR_SPACE) ok = j + 1;
- v = out(source,
- here, ok,
- okAscent, okDescent, okTop, okBottom,
- v,
- spacingmult, spacingadd, chooseHt,
- chooseHtv, fm, hasTabOrEmoji,
- needMultiply, paraStart, chdirs, dir, easy,
- ok == bufEnd, includepad, trackpad,
- chs, widths, paraStart,
- ellipsize, ellipsizedWidth, okWidth,
- paint, moreChars);
-
- here = ok;
- } else if (fit != here) {
- // Log.e("text", "output fit " + here + " to " +fit);
- v = out(source,
- here, fit,
- fitAscent, fitDescent,
- fitTop, fitBottom,
- v,
- spacingmult, spacingadd, chooseHt,
- chooseHtv, fm, hasTabOrEmoji,
- needMultiply, paraStart, chdirs, dir, easy,
- fit == bufEnd, includepad, trackpad,
- chs, widths, paraStart,
- ellipsize, ellipsizedWidth, fitWidth,
- paint, moreChars);
-
- here = fit;
- } else {
- // Log.e("text", "output one " + here + " to " +(here + 1));
- // XXX not sure why the existing fm wasn't ok.
- // measureText(paint, mWorkPaint,
- // source, here, here + 1, fm, tab,
- // null);
-
- v = out(source,
- here, here+1,
- fm.ascent, fm.descent,
- fm.top, fm.bottom,
- v,
- spacingmult, spacingadd, chooseHt,
- chooseHtv, fm, hasTabOrEmoji,
- needMultiply, paraStart, chdirs, dir, easy,
- here + 1 == bufEnd, includepad,
- trackpad,
- chs, widths, paraStart,
- ellipsize, ellipsizedWidth,
- widths[here - paraStart], paint, moreChars);
-
- here = here + 1;
+ while (ok < spanEnd && chs[ok - paraStart] == CHAR_SPACE) {
+ ok++;
}
+ endPos = ok;
+ above = okAscent;
+ below = okDescent;
+ top = okTop;
+ bottom = okBottom;
+ currentTextWidth = okWidth;
+ } else if (fit != here) {
+ endPos = fit;
+ above = fitAscent;
+ below = fitDescent;
+ top = fitTop;
+ bottom = fitBottom;
+ currentTextWidth = fitWidth;
+ } else {
+ endPos = here + 1;
+ above = fm.ascent;
+ below = fm.descent;
+ top = fm.top;
+ bottom = fm.bottom;
+ currentTextWidth = widths[here - paraStart];
+ }
+
+ v = out(source, here, endPos,
+ above, below, top, bottom,
+ v, spacingmult, spacingadd, chooseHt,chooseHtv, fm, hasTabOrEmoji,
+ needMultiply, chdirs, dir, easy, bufEnd, includepad, trackpad,
+ chs, widths, paraStart, ellipsize, ellipsizedWidth,
+ currentTextWidth, paint, moreChars);
+ here = endPos;
+
if (here < spanStart) {
// didn't output all the text for this span
// we've measured the raw widths, though, so
@@ -501,10 +481,10 @@ public class StaticLayout extends Layout {
v,
spacingmult, spacingadd, chooseHt,
chooseHtv, fm, hasTabOrEmoji,
- needMultiply, paraStart, chdirs, dir, easy,
- paraEnd == bufEnd, includepad, trackpad,
- chs, widths, paraStart,
- ellipsize, ellipsizedWidth, w, paint, paraEnd != bufEnd);
+ needMultiply, chdirs, dir, easy, bufEnd,
+ includepad, trackpad, chs,
+ widths, paraStart, ellipsize,
+ ellipsizedWidth, w, paint, paraEnd != bufEnd);
}
paraStart = paraEnd;
@@ -525,10 +505,10 @@ public class StaticLayout extends Layout {
v,
spacingmult, spacingadd, null,
null, fm, false,
- needMultiply, bufEnd, null, DEFAULT_DIR, true,
- true, includepad, trackpad,
- null, null, bufStart,
- ellipsize, ellipsizedWidth, 0, paint, false);
+ needMultiply, null, DEFAULT_DIR, true, bufEnd,
+ includepad, trackpad, null,
+ null, bufStart, ellipsize,
+ ellipsizedWidth, 0, paint, false);
}
}
@@ -628,12 +608,12 @@ public class StaticLayout extends Layout {
float spacingmult, float spacingadd,
LineHeightSpan[] chooseHt, int[] chooseHtv,
Paint.FontMetricsInt fm, boolean hasTabOrEmoji,
- boolean needMultiply, int pstart, byte[] chdirs,
- int dir, boolean easy, boolean last,
- boolean includePad, boolean trackPad,
- char[] chs, float[] widths, int widthStart,
- TextUtils.TruncateAt ellipsize, float ellipsisWidth,
- float textWidth, TextPaint paint, boolean moreChars) {
+ boolean needMultiply, byte[] chdirs, int dir,
+ boolean easy, int bufEnd, boolean includePad,
+ boolean trackPad, char[] chs,
+ float[] widths, int widthStart, TextUtils.TruncateAt ellipsize,
+ float ellipsisWidth, float textWidth,
+ TextPaint paint, boolean moreChars) {
int j = mLineCount;
int off = j * mColumns;
int want = off + mColumns + TOP;
@@ -683,7 +663,7 @@ public class StaticLayout extends Layout {
above = top;
}
}
- if (last) {
+ if (end == bufEnd) {
if (trackPad) {
mBottomPadding = bottom - below;
}