From 632d03fb6374cb0122ea2414c04721a83288e264 Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Fri, 21 Feb 2025 10:48:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/page/entities/TextPage.kt | 11 +++++++++++ .../ui/book/read/page/provider/TextChapterLayout.kt | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) 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 1ee481db5..40bfebede 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 @@ -20,6 +20,8 @@ import io.legado.app.utils.canvasrecorder.recordIfNeeded import io.legado.app.utils.dpToPx import splitties.init.appCtx import java.text.DecimalFormat +import kotlin.math.ceil +import kotlin.math.max import kotlin.math.min /** @@ -178,6 +180,7 @@ data class TextPage( addLine(textLine) } height = ChapterProvider.visibleHeight.toFloat() + upRenderHeight() invalidate() isCompleted = true } @@ -359,4 +362,12 @@ data class TextPage( fun hasImageOrEmpty(): Boolean { return textLines.any { it.isImage } || textLines.isEmpty() } + + fun upRenderHeight() { + renderHeight = ceil(lines.last().lineBottom).toInt() + if (leftLineSize > 0 && leftLineSize != lines.size) { + val leftHeight = ceil(lines[leftLineSize - 1].lineBottom).toInt() + renderHeight = max(renderHeight, leftHeight) + } + } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt index b5bfa7ee4..856b9fb3e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt @@ -131,7 +131,7 @@ class TextChapterLayout( private fun onPageCompleted() { val textPage = pendingTextPage - textPage.index = textPages.lastIndex + textPage.index = textPages.size textPage.chapterIndex = bookChapter.index textPage.chapterSize = chaptersSize textPage.title = displayTitle @@ -140,7 +140,7 @@ class TextChapterLayout( textPage.isCompleted = true textPage.textChapter = textChapter textPage.upLinesPosition() - textPage.renderHeight = textPage.lines.maxOf { it.lineBottom.toInt() } + textPage.upRenderHeight() textPages.add(textPage) channel.trySend(textPage) try {