diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index 4a9d5bb71..2c3996fd8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -265,6 +265,7 @@ object ChapterProvider { ) x = x1 } + exceed(textLine, words) } /** @@ -291,8 +292,25 @@ object ChapterProvider { ) x = x1 } + exceed(textLine, words) } + /** + * 超出边界处理 + */ + private fun exceed(textLine: TextLine, words: String) { + val endX = textLine.textChars.last().end + if (endX > visibleRight) { + val cc = (endX - visibleRight) / words.length + for (i in 0..words.lastIndex) { + textLine.getTextCharReverseAt(i).let { + val py = cc * (words.length - i) + it.start = it.start - py + it.end = it.end - py + } + } + } + } /** * 更新样式 diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt index 642fc0dc6..72798a9ea 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt @@ -2,7 +2,7 @@ package io.legado.app.ui.book.read.page.entities data class TextChar( val charData: String, - val start: Float, - val end: Float, + var start: Float, + var end: Float, var selected: Boolean = false ) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index 547ad085d..a9c84fb68 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -14,4 +14,15 @@ data class TextLine( textChars.add(TextChar(charData, start = start, end = end)) } + fun getTextCharAt(index: Int): TextChar { + return textChars[index] + } + + fun getTextCharReverseAt(index: Int): TextChar { + return textChars[textChars.lastIndex - index] + } + + fun getTextCharsCount(): Int { + return textChars.size + } }