From b15928026c271cf78f61df96fb22adc1020361b0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 09:04:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ChapterProvider.kt | 18 ++++++++++++++++++ .../app/ui/book/read/page/entities/TextChar.kt | 4 ++-- .../app/ui/book/read/page/entities/TextLine.kt | 11 +++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) 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 + } }