From ae3341e2b6f71d1a2abf88a21917a688da5b328f Mon Sep 17 00:00:00 2001 From: Sun-QAQ <75133710+Sun-QAQ@users.noreply.github.com> Date: Tue, 31 Dec 2024 19:28:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8D=95=E5=9B=BE=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E6=A0=87=E9=A2=98=E7=9A=84=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E5=B1=85=E4=B8=AD=20(#4485)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 当图片格式设置为single时,图片居中显示。 * 优化单图模式下标题的显示位置优化了标题威之居中 --- .../read/page/provider/TextChapterLayout.kt | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) 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 727fbcbf8..197c64990 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 @@ -194,6 +194,7 @@ class TextChapterLayout( titlePaint, titlePaintTextHeight, titlePaintFontMetrics, + book.getImageStyle(), isTitle = true, emptyContent = contents.isEmpty(), isVolumeTitle = bookChapter.isVolume @@ -231,6 +232,7 @@ class TextChapterLayout( contentPaint, contentPaintTextHeight, contentPaintFontMetrics, + book.getImageStyle(), srcList = srcList ).let { absStartX = it.first @@ -250,7 +252,8 @@ class TextChapterLayout( text, contentPaint, contentPaintTextHeight, - contentPaintFontMetrics + contentPaintFontMetrics, + book.getImageStyle() ).let { absStartX = it.first durY = it.second @@ -278,7 +281,8 @@ class TextChapterLayout( if (AppConfig.enableReview) text + ChapterProvider.reviewChar else text, contentPaint, contentPaintTextHeight, - contentPaintFontMetrics + contentPaintFontMetrics, + book.getImageStyle() ).let { absStartX = it.first durY = it.second @@ -443,6 +447,7 @@ class TextChapterLayout( textPaint: TextPaint, textHeight: Float, fontMetrics: Paint.FontMetrics, + imageStyle: String?, isTitle: Boolean = false, emptyContent: Boolean = false, isVolumeTitle: Boolean = false, @@ -487,8 +492,31 @@ class TextChapterLayout( } } - isTitle && textPages.isEmpty() && pendingTextPage.lines.isEmpty() -> - y + titleTopSpacing + isTitle && textPages.isEmpty() && pendingTextPage.lines.isEmpty() -> { + when (imageStyle?.uppercase(Locale.ROOT)) { + Book.imgStyleSingle -> { + val textPage = pendingTextPage + if (textPage.lineSize == 0) { + val ty = (visibleHeight - layout.lineCount * textHeight) / 2 + if (ty > titleTopSpacing) ty else titleTopSpacing.toFloat() + } else { + var textLayoutHeight = layout.lineCount * textHeight + val fistLine = textPage.getLine(0) + if (fistLine.lineTop < textLayoutHeight + titleTopSpacing) { + textLayoutHeight = fistLine.lineTop - titleTopSpacing + } + textPage.lines.forEach { + it.lineTop -= textLayoutHeight + it.lineBase -= textLayoutHeight + it.lineBottom -= textLayoutHeight + } + y - textLayoutHeight + } + } + + else -> y + titleTopSpacing + } + } else -> y } @@ -539,7 +567,7 @@ class TextChapterLayout( //标题x轴居中 val startX = if ( isTitle && - (ReadBookConfig.isMiddleTitle || emptyContent || isVolumeTitle) + (ReadBookConfig.isMiddleTitle || emptyContent || isVolumeTitle || imageStyle == "SINGLE") ) { (visibleWidth - desiredWidth) / 2 } else { @@ -554,7 +582,7 @@ class TextChapterLayout( else -> { if ( isTitle && - (ReadBookConfig.isMiddleTitle || emptyContent || isVolumeTitle) + (ReadBookConfig.isMiddleTitle || emptyContent || isVolumeTitle || imageStyle == "SINGLE") ) { //标题居中 val startX = (visibleWidth - desiredWidth) / 2