Skip to content

Commit 7fa2df5

Browse files
committed
Fixed line detection.
1 parent 296fa71 commit 7fa2df5

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecPreformatSpan.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import android.graphics.Color
55
import android.graphics.CornerPathEffect
66
import android.graphics.Paint
77
import android.graphics.Path
8-
import android.graphics.Rect
98
import android.text.Layout
109
import android.text.Spanned
1110
import 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,

aztec/src/main/res/values/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<item name="preformatBackground">@color/code_background</item>
4242
<item name="preformatBackgroundAlpha">75%</item>
4343
<item name="preformatColor">@color/white</item>
44-
<item name="preformatBorderColor">#1AFFFFFF</item>
44+
<item name="preformatBorderColor">@android:color/darker_gray</item>
4545
<item name="preformatBorderRadius">2dp</item>
4646
<item name="preformatBorderThickness">1dp</item>
4747
<item name="preformatLeadingMargin">@dimen/preformat_leading_margin</item>

0 commit comments

Comments
 (0)