Improve TTS highlight contrast
This commit is contained in:
@@ -11,6 +11,7 @@ import android.text.SpannableString
|
||||
import android.text.StaticLayout
|
||||
import android.text.TextPaint
|
||||
import android.text.style.BackgroundColorSpan
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.LineHeightSpan
|
||||
import eu.kanade.tachiyomi.ui.reader.setting.TextReaderStyle
|
||||
import java.io.ByteArrayInputStream
|
||||
@@ -274,13 +275,15 @@ internal object TextPageRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
val darkBackground = resolveColors(style).first == Color.BLACK
|
||||
val (_, baseTextColor) = resolveColors(style)
|
||||
val darkTheme = baseTextColor == Color.WHITE
|
||||
sentenceHighlightRange?.let { range ->
|
||||
applyHighlightSpan(
|
||||
spannable = spannable,
|
||||
textLength = text.length,
|
||||
range = range,
|
||||
color = if (darkBackground) Color.rgb(72, 68, 40) else Color.rgb(255, 249, 196),
|
||||
backgroundColor = if (darkTheme) Color.rgb(77, 66, 25) else Color.rgb(255, 243, 176),
|
||||
foregroundColor = if (darkTheme) Color.WHITE else Color.BLACK,
|
||||
)
|
||||
}
|
||||
activeHighlightRange?.let { range ->
|
||||
@@ -288,7 +291,8 @@ internal object TextPageRenderer {
|
||||
spannable = spannable,
|
||||
textLength = text.length,
|
||||
range = range,
|
||||
color = if (darkBackground) Color.rgb(150, 117, 0) else Color.rgb(255, 193, 7),
|
||||
backgroundColor = if (darkTheme) Color.rgb(255, 193, 7) else Color.rgb(255, 179, 0),
|
||||
foregroundColor = Color.BLACK,
|
||||
)
|
||||
}
|
||||
return spannable
|
||||
@@ -298,14 +302,21 @@ internal object TextPageRenderer {
|
||||
spannable: SpannableString,
|
||||
textLength: Int,
|
||||
range: IntRange,
|
||||
color: Int,
|
||||
backgroundColor: Int,
|
||||
foregroundColor: Int,
|
||||
) {
|
||||
if (range.isEmpty()) return
|
||||
val start = range.first.coerceIn(0, textLength)
|
||||
val endExclusive = (range.last + 1).coerceIn(start, textLength)
|
||||
if (start >= endExclusive) return
|
||||
spannable.setSpan(
|
||||
BackgroundColorSpan(color),
|
||||
BackgroundColorSpan(backgroundColor),
|
||||
start,
|
||||
endExclusive,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
|
||||
)
|
||||
spannable.setSpan(
|
||||
ForegroundColorSpan(foregroundColor),
|
||||
start,
|
||||
endExclusive,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
|
||||
|
||||
Reference in New Issue
Block a user