【功能】为墨水屏模式增加自动下划线高亮 (#5207)
Some checks failed
update fork / build (push) Has been cancelled
Test Build / prepare (push) Has been cancelled
Test Build / build (app, release) (push) Has been cancelled
Test Build / build (app, releaseA) (push) Has been cancelled
Test Build / prerelease (push) Has been cancelled
Test Build / lanzou (push) Has been cancelled
Test Build / test_Branch (push) Has been cancelled
Test Build / telegram (push) Has been cancelled

* Feat: Auto add underline for highlight in E-Ink mode

* Feat: Unify search result highlight to underline in E-Ink mode

* Feat: Create a simplified workflow for building signed release APK

* Fix: Restore original signing method for release build

* Feat: Create final workflow to build and release signed APK with custom body

* Feat: Finalized custom release workflow

* Chore: Revert workflow file to original version

* Fix: Adjust underline vertical position for visual perfection
This commit is contained in:
Leroy-X
2025-06-27 21:26:40 +08:00
committed by GitHub
parent 8503854cab
commit df0370cde7
2 changed files with 39 additions and 11 deletions

View File

@@ -160,6 +160,17 @@ data class TextLine(
columns[i].draw(view, canvas)
}
}
// 墨水屏模式下的朗读和搜索下划线
if (AppConfig.isEInkMode && (isReadAloud || searchResultColumnCount > 0)) {
val underlinePaint = PaintPool.obtain()
underlinePaint.set(ChapterProvider.contentPaint)
underlinePaint.strokeWidth = 1.dpToPx().toFloat()
val lineY = height - 1.dpToPx()
canvas.drawLine(lineStart + indentWidth, lineY, lineEnd, lineY, underlinePaint)
PaintPool.recycle(underlinePaint)
}
if (ReadBookConfig.underline && !isImage && ReadBook.book?.isImage != true) {
drawUnderline(canvas)
}

View File

@@ -2,6 +2,7 @@ package io.legado.app.ui.book.searchContent
import android.text.Spanned
import androidx.core.text.HtmlCompat
import io.legado.app.help.config.AppConfig
data class SearchResult(
val resultCount: Int = 0,
@@ -22,23 +23,39 @@ data class SearchResult(
val leftString = resultText.substring(0, queryIndexInSurrounding)
val rightString =
resultText.substring(queryIndexInSurrounding + query.length, resultText.length)
val html = buildString {
append(chapterTitle.colorTextForHtml(accentColor))
append("<br>")
append(leftString.colorTextForHtml(textColor))
append(query.colorTextForHtml(accentColor))
append(rightString.colorTextForHtml(textColor))
// 检查是否为墨水屏模式
val html = if (AppConfig.isEInkMode) {
// 墨水屏模式:使用下划线
buildString {
append("<u>${chapterTitle}</u>")
append("<br>")
append(leftString)
append("<u>${query}</u>")
append(rightString)
}
} else {
// 普通模式:使用颜色
buildString {
append(chapterTitle.colorTextForHtml(accentColor))
append("<br>")
append(leftString.colorTextForHtml(textColor))
append(query.colorTextForHtml(accentColor))
append(rightString.colorTextForHtml(textColor))
}
}
HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY)
} else {
HtmlCompat.fromHtml(
resultText.colorTextForHtml(textColor),
HtmlCompat.FROM_HTML_MODE_LEGACY
)
val html = if (AppConfig.isEInkMode) {
resultText
} else {
resultText.colorTextForHtml(textColor)
}
HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY)
}
}
private fun String.colorTextForHtml(textColor: String) =
"<font color=#${textColor}>$this</font>"
}
}