Improve TTS highlight contrast
This commit is contained in:
@@ -11,6 +11,7 @@ import android.text.SpannableString
|
|||||||
import android.text.StaticLayout
|
import android.text.StaticLayout
|
||||||
import android.text.TextPaint
|
import android.text.TextPaint
|
||||||
import android.text.style.BackgroundColorSpan
|
import android.text.style.BackgroundColorSpan
|
||||||
|
import android.text.style.ForegroundColorSpan
|
||||||
import android.text.style.LineHeightSpan
|
import android.text.style.LineHeightSpan
|
||||||
import eu.kanade.tachiyomi.ui.reader.setting.TextReaderStyle
|
import eu.kanade.tachiyomi.ui.reader.setting.TextReaderStyle
|
||||||
import java.io.ByteArrayInputStream
|
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 ->
|
sentenceHighlightRange?.let { range ->
|
||||||
applyHighlightSpan(
|
applyHighlightSpan(
|
||||||
spannable = spannable,
|
spannable = spannable,
|
||||||
textLength = text.length,
|
textLength = text.length,
|
||||||
range = range,
|
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 ->
|
activeHighlightRange?.let { range ->
|
||||||
@@ -288,7 +291,8 @@ internal object TextPageRenderer {
|
|||||||
spannable = spannable,
|
spannable = spannable,
|
||||||
textLength = text.length,
|
textLength = text.length,
|
||||||
range = range,
|
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
|
return spannable
|
||||||
@@ -298,14 +302,21 @@ internal object TextPageRenderer {
|
|||||||
spannable: SpannableString,
|
spannable: SpannableString,
|
||||||
textLength: Int,
|
textLength: Int,
|
||||||
range: IntRange,
|
range: IntRange,
|
||||||
color: Int,
|
backgroundColor: Int,
|
||||||
|
foregroundColor: Int,
|
||||||
) {
|
) {
|
||||||
if (range.isEmpty()) return
|
if (range.isEmpty()) return
|
||||||
val start = range.first.coerceIn(0, textLength)
|
val start = range.first.coerceIn(0, textLength)
|
||||||
val endExclusive = (range.last + 1).coerceIn(start, textLength)
|
val endExclusive = (range.last + 1).coerceIn(start, textLength)
|
||||||
if (start >= endExclusive) return
|
if (start >= endExclusive) return
|
||||||
spannable.setSpan(
|
spannable.setSpan(
|
||||||
BackgroundColorSpan(color),
|
BackgroundColorSpan(backgroundColor),
|
||||||
|
start,
|
||||||
|
endExclusive,
|
||||||
|
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
|
||||||
|
)
|
||||||
|
spannable.setSpan(
|
||||||
|
ForegroundColorSpan(foregroundColor),
|
||||||
start,
|
start,
|
||||||
endExclusive,
|
endExclusive,
|
||||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
|
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
|
||||||
|
|||||||
Reference in New Issue
Block a user