From 90c8fe182d9101780f88e1007bfa3b010f2ea589 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sat, 29 Jan 2022 12:34:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=B7=E7=9A=84=E6=AD=A3=E6=96=87=E6=9C=89?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E6=97=B6=20=E6=A0=87=E9=A2=98x=E8=BD=B4?= =?UTF-8?q?=E5=B1=85=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../read/page/provider/ChapterProvider.kt | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 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 4e0242e3f..4b6359a0b 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 @@ -129,12 +129,13 @@ object ChapterProvider { matcher.appendTail(sb) text = sb.toString() val isTitle = index == 0 - val isVolumeTitle = isTitle && contents.size == 1 + val isTitleWithNoContent = isTitle && contents.size == 1 + val isVolumeTitle = isTitle && bookChapter.isVolume val textPaint = if (isTitle) titlePaint else contentPaint if (!(isTitle && ReadBookConfig.titleMode == 2)) { setTypeText( absStartX, durY, text, textPages, stringBuilder, - isTitle, isVolumeTitle, textPaint, srcList + isTitle, isTitleWithNoContent, isVolumeTitle, textPaint, srcList ).let { absStartX = it.first durY = it.second @@ -147,12 +148,13 @@ object ChapterProvider { val text = content.substring(start, matcher.start()) if (text.isNotBlank()) { val isTitle = index == 0 - val isVolumeTitle = isTitle && contents.size == 1 + val isTitleWithNoContent = isTitle && contents.size == 1 + val isVolumeTitle = isTitle && bookChapter.isVolume val textPaint = if (isTitle) titlePaint else contentPaint if (!(isTitle && ReadBookConfig.titleMode == 2)) { setTypeText( - absStartX, durY, text, textPages, - stringBuilder, isTitle, isVolumeTitle, textPaint + absStartX, durY, text, textPages, stringBuilder, + isTitle, isTitleWithNoContent, isVolumeTitle, textPaint ).let { absStartX = it.first durY = it.second @@ -169,12 +171,13 @@ object ChapterProvider { val text = content.substring(start, content.length) if (text.isNotBlank()) { val isTitle = index == 0 - val isVolumeTitle = isTitle && contents.size == 1 + val isTitleWithNoContent = isTitle && contents.size == 1 + val isVolumeTitle = isTitle && bookChapter.isVolume val textPaint = if (isTitle) titlePaint else contentPaint if (!(isTitle && ReadBookConfig.titleMode == 2)) { setTypeText( - absStartX, durY, text, textPages, - stringBuilder, isTitle, isVolumeTitle, textPaint + absStartX, durY, text, textPages, stringBuilder, + isTitle, isTitleWithNoContent, isVolumeTitle, textPaint ).let { absStartX = it.first durY = it.second @@ -277,6 +280,7 @@ object ChapterProvider { textPages: ArrayList, stringBuilder: StringBuilder, isTitle: Boolean, + isTitleWithNoContent: Boolean, isVolumeTitle: Boolean, textPaint: TextPaint, srcList: LinkedList? = null @@ -288,7 +292,8 @@ object ChapterProvider { text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true ) var durY = when { - isVolumeTitle -> ((visibleHeight - layout.lineCount * textPaint.textHeight) / 2).toFloat() + //标题y轴居中 + isTitleWithNoContent -> ((visibleHeight - layout.lineCount * textPaint.textHeight) / 2).toFloat() isTitle -> y + titleTopSpacing else -> y } @@ -334,8 +339,8 @@ object ChapterProvider { //最后一行 textLine.text = "$words\n" isLastLine = true - //标题居中 - val startX = if (isTitle && ReadBookConfig.titleMode == 1 || isVolumeTitle) + //标题x轴居中 + val startX = if (isTitle && ReadBookConfig.titleMode == 1 || isTitleWithNoContent || isVolumeTitle) (visibleWidth - layout.getLineWidth(lineIndex)) / 2 else 0f addCharsToLineLast( @@ -368,7 +373,7 @@ object ChapterProvider { durY += textPaint.textHeight * lineSpacingExtra textPages.last().height = durY } - if (isTitle && !isVolumeTitle) durY += titleBottomSpacing + if (isTitle && !isTitleWithNoContent) durY += titleBottomSpacing durY += textPaint.textHeight * paragraphSpacing / 10f return Pair(absStartX, durY) }