This commit is contained in:
miaogongzi
2024-02-27 03:13:00 +08:00
4 changed files with 34 additions and 19 deletions
-1
View File
@@ -1,6 +1,5 @@
# 源规则帮助 # 源规则帮助
* [阅读3.0(Legado)规则说明](https://mgz0227.github.io/The-tutorial-of-Legado/)
* [书源帮助文档](https://alanskycn.gitee.io/teachme/Rule/source.html) * [书源帮助文档](https://alanskycn.gitee.io/teachme/Rule/source.html)
* [订阅源帮助文档](https://alanskycn.gitee.io/teachme/Rule/rss.html) * [订阅源帮助文档](https://alanskycn.gitee.io/teachme/Rule/rss.html)
* 辅助键盘❓中可插入URL参数模板,打开帮助,js教程,正则教程,选择文件 * 辅助键盘❓中可插入URL参数模板,打开帮助,js教程,正则教程,选择文件
@@ -288,21 +288,26 @@ object ReadBook : CoroutineScope by MainScope() {
} }
fun setPageIndex(index: Int) { fun setPageIndex(index: Int) {
val textChapter = curTextChapter recycleRecorders(durPageIndex, index)
if (textChapter != null) {
val pageIndex = durPageIndex
if (index > pageIndex) {
textChapter.getPage(index - 2)?.recycleRecorders()
}
if (index < pageIndex) {
textChapter.getPage(index + 3)?.recycleRecorders()
}
}
durChapterPos = curTextChapter?.getReadLength(index) ?: index durChapterPos = curTextChapter?.getReadLength(index) ?: index
saveRead(true) saveRead(true)
curPageChanged(true) curPageChanged(true)
} }
fun recycleRecorders(beforeIndex: Int, afterIndex: Int) {
executor.execute {
val textChapter = curTextChapter
if (textChapter != null) {
if (afterIndex > beforeIndex) {
textChapter.getPage(afterIndex - 2)?.recycleRecorders()
}
if (afterIndex < beforeIndex) {
textChapter.getPage(afterIndex + 3)?.recycleRecorders()
}
}
}
}
fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) { fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) {
if (index < chapterSize) { if (index < chapterSize) {
clearTextChapter() clearTextChapter()
@@ -79,8 +79,8 @@ data class TextLine(
} }
} }
fun getColumnReverseAt(index: Int): BaseColumn { fun getColumnReverseAt(index: Int, offset: Int = 0): BaseColumn {
return textColumns[textColumns.lastIndex - index] return textColumns[textColumns.lastIndex - offset - index]
} }
fun getColumnsCount(): Int { fun getColumnsCount(): Int {
@@ -622,7 +622,7 @@ class TextChapterLayout(
val spaceSize = words.count { it == " " } val spaceSize = words.count { it == " " }
textLine.startX = absStartX + startX textLine.startX = absStartX + startX
if (spaceSize > 1) { if (spaceSize > 1) {
val d = residualWidth / (spaceSize - 1) val d = residualWidth / spaceSize
textLine.wordSpacing = d textLine.wordSpacing = d
var x = startX var x = startX
for (index in words.indices) { for (index in words.indices) {
@@ -735,14 +735,25 @@ class TextChapterLayout(
* 超出边界处理 * 超出边界处理
*/ */
private fun exceed(absStartX: Int, textLine: TextLine, words: List<String>) { private fun exceed(absStartX: Int, textLine: TextLine, words: List<String>) {
var size = words.size
if (size < 2) return
val visibleEnd = absStartX + visibleWidth val visibleEnd = absStartX + visibleWidth
val endX = textLine.columns.lastOrNull()?.end?.roundToInt() ?: return val columns = textLine.columns
var offset = 0
val endColumn = if (words.last() == " ") {
size--
offset++
columns[columns.lastIndex - 1]
} else {
columns.last()
}
val endX = endColumn.end.roundToInt()
if (endX > visibleEnd) { if (endX > visibleEnd) {
textLine.exceed = true textLine.exceed = true
val cc = (endX - visibleEnd) / words.size val cc = (endX - visibleEnd) / size
for (i in 0..words.lastIndex) { for (i in 0..<size) {
textLine.getColumnReverseAt(i).let { textLine.getColumnReverseAt(i, offset).let {
val py = cc * (words.size - i) val py = cc * (size - i)
it.start -= py it.start -= py
it.end -= py it.end -= py
} }