@@ -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