-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathEnrichedCodeBlockSpan.kt
More file actions
42 lines (38 loc) · 1.24 KB
/
Copy pathEnrichedCodeBlockSpan.kt
File metadata and controls
42 lines (38 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.swmansion.enriched.spans
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.RectF
import android.graphics.Typeface
import android.text.TextPaint
import android.text.style.LineBackgroundSpan
import android.text.style.MetricAffectingSpan
import com.swmansion.enriched.spans.interfaces.EnrichedBlockSpan
import com.swmansion.enriched.styles.HtmlStyle
class EnrichedCodeBlockSpan(private val htmlStyle: HtmlStyle) : MetricAffectingSpan(), LineBackgroundSpan, EnrichedBlockSpan {
override fun updateDrawState(paint: TextPaint) {
paint.typeface = Typeface.MONOSPACE
paint.color = htmlStyle.codeBlockColor
}
override fun updateMeasureState(paint: TextPaint) {
paint.typeface = Typeface.MONOSPACE
}
override fun drawBackground(
canvas: Canvas,
p: Paint,
left: Int,
right: Int,
top: Int,
baseline: Int,
bottom: Int,
text: CharSequence,
start: Int,
end: Int,
lineNum: Int
) {
val previousColor = p.color
p.color = htmlStyle.codeBlockBackgroundColor
val rect = RectF(left.toFloat(), top.toFloat(), right.toFloat(), bottom.toFloat())
canvas.drawRoundRect(rect, htmlStyle.codeBlockRadius, htmlStyle.codeBlockRadius, p)
p.color = previousColor
}
}