From 3966db208744af7e2c397442f10ac1de56ec996a Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 13 Feb 2022 19:13:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E9=A2=98=E5=8D=95=E7=8B=AC=E7=BB=98?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../read/page/provider/ChapterProvider.kt | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index dc01a6e03..ee88867b5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -125,6 +125,7 @@ object ChapterProvider { durY = it.second } } + durY += titleBottomSpacing } contents.forEach { content -> if (book.getImageStyle() == Book.imgStyleText) { @@ -286,8 +287,27 @@ object ChapterProvider { ) var durY = when { //标题y轴居中 - y == 0f && isTitleWithNoContent -> ((visibleHeight - layout.lineCount * textPaint.textHeight) / 2) - y == 0f && isTitle -> y + titleTopSpacing + isTitleWithNoContent && textPages.size == 1 -> { + val textPage = textPages.last() + if (textPage.lineSize == 0) { + val ty = (visibleHeight - layout.lineCount * textPaint.textHeight) / 2 + if (ty > 0) ty else titleTopSpacing.toFloat() + } else { + var textLayoutHeight = layout.lineCount * textPaint.textHeight + val fistLine = textPage.getLine(0) + if (fistLine.lineTop < textLayoutHeight + titleTopSpacing) { + textLayoutHeight = fistLine.lineTop - titleTopSpacing + } + textPage.textLines.forEach { + it.lineTop = it.lineTop - textLayoutHeight + it.lineBase = it.lineBase - textLayoutHeight + it.lineBottom = it.lineBottom - textLayoutHeight + } + y - textLayoutHeight + } + } + isTitle && textPages.size == 1 && textPages.last().textLines.isEmpty() -> + y + titleTopSpacing else -> y } for (lineIndex in 0 until layout.lineCount) { @@ -367,7 +387,6 @@ object ChapterProvider { durY += textPaint.textHeight * lineSpacingExtra textPages.last().height = durY } - if (isTitle && !isTitleWithNoContent) durY += titleBottomSpacing durY += textPaint.textHeight * paragraphSpacing / 10f return Pair(absStartX, durY) }