2020-01-09 22:13:25 -05:00
|
|
|
package eu.kanade.tachiyomi.widget
|
|
|
|
|
|
|
|
import android.graphics.Canvas
|
|
|
|
import android.graphics.Paint
|
|
|
|
import android.text.style.ReplacementSpan
|
|
|
|
import androidx.annotation.ColorInt
|
|
|
|
import androidx.annotation.Dimension
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Source: https://github.com/santaevpavel
|
|
|
|
*
|
|
|
|
* A class that draws the outlines of a text when given a stroke color and stroke width.
|
|
|
|
*/
|
|
|
|
class OutlineSpan(
|
2020-02-26 18:03:34 -05:00
|
|
|
@ColorInt private val strokeColor: Int,
|
|
|
|
@Dimension private val strokeWidth: Float
|
2020-01-09 22:13:25 -05:00
|
|
|
) : ReplacementSpan() {
|
|
|
|
|
|
|
|
override fun getSize(
|
2020-02-26 18:03:34 -05:00
|
|
|
paint: Paint,
|
|
|
|
text: CharSequence,
|
|
|
|
start: Int,
|
|
|
|
end: Int,
|
|
|
|
fm: Paint.FontMetricsInt?
|
2020-01-09 22:13:25 -05:00
|
|
|
): Int {
|
|
|
|
return paint.measureText(text.toString().substring(start until end)).toInt()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun draw(
|
2020-02-26 18:03:34 -05:00
|
|
|
canvas: Canvas,
|
|
|
|
text: CharSequence,
|
|
|
|
start: Int,
|
|
|
|
end: Int,
|
|
|
|
x: Float,
|
|
|
|
top: Int,
|
|
|
|
y: Int,
|
|
|
|
bottom: Int,
|
|
|
|
paint: Paint
|
2020-01-09 22:13:25 -05:00
|
|
|
) {
|
|
|
|
val originTextColor = paint.color
|
|
|
|
|
|
|
|
paint.apply {
|
|
|
|
color = strokeColor
|
|
|
|
style = Paint.Style.STROKE
|
|
|
|
this.strokeWidth = this@OutlineSpan.strokeWidth
|
|
|
|
}
|
|
|
|
canvas.drawText(text, start, end, x, y.toFloat(), paint)
|
|
|
|
|
|
|
|
paint.apply {
|
|
|
|
color = originTextColor
|
|
|
|
style = Paint.Style.FILL
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas.drawText(text, start, end, x, y.toFloat(), paint)
|
|
|
|
}
|
|
|
|
}
|