@@ -5,7 +5,6 @@ import android.graphics.Color
55import android.graphics.CornerPathEffect
66import android.graphics.Paint
77import android.graphics.Path
8- import android.graphics.Rect
98import android.text.Layout
109import android.text.Spanned
1110import android.text.style.LeadingMarginSpan
@@ -58,8 +57,6 @@ open class AztecPreformatSpan(
5857 override var endBeforeBleed: Int = - 1
5958 override var startBeforeCollapse: Int = - 1
6059
61- val rect = Rect ()
62-
6360 override fun chooseHeight (text : CharSequence , start : Int , end : Int , spanstartv : Int , v : Int ,
6461 fm : Paint .FontMetricsInt ) {
6562 val spanned = text as Spanned
@@ -87,12 +84,14 @@ open class AztecPreformatSpan(
8784 strokeCap = Paint .Cap .ROUND
8885 }
8986
90- private var borderPath = Path ()
91- private var fillPath = Path ()
87+
9288
9389 override fun drawBackground (canvas : Canvas , paint : Paint , left : Int , right : Int , top : Int , baseline : Int ,
9490 bottom : Int , text : CharSequence? , start : Int , end : Int , lnum : Int ) {
95- val color = paint.color
91+
92+ val spanned = text as Spanned
93+ val spanEnd = spanned.getSpanEnd(this )
94+
9695 val alpha: Int = (preformatStyle.preformatBackgroundAlpha * 255 ).toInt()
9796
9897 fillPaint.color = Color .argb(
@@ -101,7 +100,6 @@ open class AztecPreformatSpan(
101100 Color .green(preformatStyle.preformatBackground),
102101 Color .blue(preformatStyle.preformatBackground)
103102 )
104- paint.color = fillPaint.color
105103
106104 fillPaint.pathEffect = CornerPathEffect (preformatStyle.preformatBorderRadius.toFloat())
107105 strokePaint.pathEffect = CornerPathEffect (preformatStyle.preformatBorderRadius.toFloat())
@@ -111,9 +109,9 @@ open class AztecPreformatSpan(
111109
112110 val isFirstLine = top == 0
113111
114- val isLastLine = text?.length == end
112+ val isLastLine = spanEnd == end
115113
116- fillPath = Path ().apply {
114+ val fillPath = Path ().apply {
117115 if (isFirstLine) {
118116 moveTo(left.toFloat(), bottom.toFloat())
119117 lineTo(left.toFloat(), top.toFloat())
@@ -137,12 +135,15 @@ open class AztecPreformatSpan(
137135
138136 canvas.drawPath(fillPath, fillPaint)
139137
140- borderPath = Path ().apply {
138+ val borderPath = Path ().apply {
141139 if (isFirstLine) {
142140 moveTo(left.toFloat(), bottom.toFloat())
143141 lineTo(left.toFloat(), top.toFloat())
144142 lineTo(right.toFloat(), top.toFloat())
145143 lineTo(right.toFloat(), bottom.toFloat())
144+ if (isLastLine) {
145+ lineTo(left.toFloat(), bottom.toFloat())
146+ }
146147 } else if (isLastLine) {
147148 moveTo(left.toFloat(), top.toFloat())
148149 lineTo(left.toFloat(), bottom.toFloat())
@@ -157,7 +158,6 @@ open class AztecPreformatSpan(
157158 }
158159
159160 canvas.drawPath(borderPath, strokePaint)
160- paint.color = color
161161 }
162162
163163 override fun drawLeadingMargin (canvas : Canvas , paint : Paint , x : Int , dir : Int , top : Int , baseline : Int ,
0 commit comments