Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import android.graphics.Paint
import android.graphics.Path
import android.os.Build
import android.text.Layout
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import kotlin.math.max
import kotlin.math.min
import kotlin.math.roundToInt
Expand Down Expand Up @@ -126,7 +128,18 @@ internal fun drawSpannedDecoration(
yOffsetForLine: (paint: Paint, baseline: Float, thickness: Float) -> Float,
) {
val textPaint = layout.paint
val effectiveColor = if (color != Color.TRANSPARENT) color else textPaint.color
val effectiveColor =
if (color != Color.TRANSPARENT) {
color
} else {
// Look up the actual foreground color at the span position. layout.paint
// is the base paint whose color may differ from per-span foreground colors
// applied via ForegroundColorSpan (e.g., link text, colored text).
val spanned = layout.text as? Spanned
val fgSpans = spanned?.getSpans(start, start + 1, ForegroundColorSpan::class.java)
if (fgSpans != null && fgSpans.isNotEmpty()) fgSpans.last().foregroundColor
else textPaint.color
}
val minThickness = 1.5f * textPaint.density
val thickness =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Expand Down
Loading