@@ -68,16 +68,22 @@ abstract class AztecDynamicImageSpan(val context: Context, protected var imageDr
6868
6969 override fun getSize (paint : Paint ? , text : CharSequence? , start : Int , end : Int , metrics : Paint .FontMetricsInt ? ): Int {
7070 val sizeRect = adjustBounds(start)
71+ if (metrics != null && sizeRect.height() > 0 ) {
7172
72- if (metrics != null && sizeRect.width() > 0 ) {
7373 metrics.ascent = - sizeRect.height()
7474 metrics.descent = 0
7575
7676 metrics.top = metrics.ascent
7777 metrics.bottom = 0
7878 }
7979
80- return sizeRect.width()
80+ if (sizeRect.width() > 0 ) {
81+ return sizeRect.width()
82+ } else {
83+ // This code was crucial to get good results for overlapping issue
84+ val size = super .getSize(paint, text, start, end, metrics)
85+ return size
86+ }
8187 }
8288
8389 fun adjustBounds (start : Int ): Rect {
@@ -89,7 +95,9 @@ abstract class AztecDynamicImageSpan(val context: Context, protected var imageDr
8995
9096 if (measuring || layout == null ) {
9197 // if we're in pre-layout phase, just return a tiny rect
92- return Rect (0 , 0 , 1 , 1 )
98+ // It looks like if we return 1 for right and bottom
99+ // it will cause overlap
100+ return Rect (0 , 0 , 0 , 0 )
93101 }
94102
95103 val line = layout.getLineForOffset(start)
@@ -98,7 +106,6 @@ abstract class AztecDynamicImageSpan(val context: Context, protected var imageDr
98106
99107 // use the original bounds if non-zero, otherwise try the intrinsic sizes. If those are not available then
100108 // just assume maximum size.
101-
102109 var width = if ((imageDrawable?.intrinsicWidth ? : - 1 ) > - 1 ) imageDrawable?.intrinsicWidth ? : - 1
103110 else maxWidth
104111 var height = if ((imageDrawable?.intrinsicHeight ? : - 1 ) > - 1 ) imageDrawable?.intrinsicHeight ? : - 1
@@ -109,6 +116,14 @@ abstract class AztecDynamicImageSpan(val context: Context, protected var imageDr
109116 height = (width / aspectRatio).toInt()
110117 }
111118
119+ // Note: This is not a solution just a temp code
120+ // to demonstrate that for some reason value 36 ( which is got
121+ // from imageDrawable?.intrinsicHeight ) is causing overlap problem
122+ // or I think it's causing :D
123+ if (height == 36 ) {
124+ return Rect (0 , 0 , 0 , 0 )
125+ }
126+
112127 imageDrawable?.bounds = Rect (0 , 0 , width, height)
113128
114129 return Rect (imageDrawable?.bounds ? : Rect (0 , 0 , 0 , 0 ))
0 commit comments