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 65121906c..b7cf7182e 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 @@ -75,6 +75,7 @@ object ChapterProvider { item.chapterIndex = bookChapter.index item.chapterSize = chapterSize item.title = bookChapter.title + item.upLinesPosition(visibleHeight) } return TextChapter( bookChapter.index, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index bfb8e822c..adb5f0ec9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -18,6 +18,21 @@ data class TextPage( var height: Float = 0f ) { + fun upLinesPosition(visibleHeight: Int) { + if (textLines.size <= 1) return + if (visibleHeight - height > with(textLines.last()) { lineBottom - lineTop }) return + val surplus = (visibleHeight - textLines.last().lineBottom) + height += surplus + val tj = surplus / (textLines.size - 1) + if (tj == 0f) return + for (i in 1 until textLines.size) { + val line = textLines[i] + line.lineTop = line.lineTop + tj * i + line.lineBase = line.lineBase + tj * i + line.lineBottom = line.lineBottom + tj * i + } + } + @Suppress("DEPRECATION") fun format(): TextPage { if (textLines.isEmpty() && ChapterProvider.visibleWidth > 0) { @@ -101,4 +116,5 @@ data class TextPage( } return percent } + }