Skip to content

Commit 8a5137a

Browse files
author
Fabrice Di Meglio
committed
Fix bug #5349461 TextView: text that ends with an ImageSpan causes line height to shrink to ImageSpan height
- save current metrics values before updating them Change-Id: I2d88dd7d30e8e01d0c5e2328973f256b689672b2
1 parent 70a8568 commit 8a5137a

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

core/java/android/text/TextLine.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,12 @@ private static void expandMetricsFromPaint(FontMetricsInt fmi, TextPaint wp) {
679679

680680
wp.getFontMetricsInt(fmi);
681681

682+
updateMetrics(fmi, previousTop, previousAscent, previousDescent, previousBottom,
683+
previousLeading);
684+
}
685+
686+
static void updateMetrics(FontMetricsInt fmi, int previousTop, int previousAscent,
687+
int previousDescent, int previousBottom, int previousLeading) {
682688
fmi.top = Math.min(fmi.top, previousTop);
683689
fmi.ascent = Math.min(fmi.ascent, previousAscent);
684690
fmi.descent = Math.max(fmi.descent, previousDescent);
@@ -809,7 +815,28 @@ private float handleReplacement(ReplacementSpan replacement, TextPaint wp,
809815
int textLimit = mStart + limit;
810816

811817
if (needWidth || (c != null && runIsRtl)) {
818+
int previousTop = 0;
819+
int previousAscent = 0;
820+
int previousDescent = 0;
821+
int previousBottom = 0;
822+
int previousLeading = 0;
823+
824+
boolean needUpdateMetrics = (fmi != null);
825+
826+
if (needUpdateMetrics) {
827+
previousTop = fmi.top;
828+
previousAscent = fmi.ascent;
829+
previousDescent = fmi.descent;
830+
previousBottom = fmi.bottom;
831+
previousLeading = fmi.leading;
832+
}
833+
812834
ret = replacement.getSize(wp, mText, textStart, textLimit, fmi);
835+
836+
if (needUpdateMetrics) {
837+
updateMetrics(fmi, previousTop, previousAscent, previousDescent, previousBottom,
838+
previousLeading);
839+
}
813840
}
814841

815842
if (c != null) {

0 commit comments

Comments
 (0)