From 3037202d7110686b72ff9a69bec785a7a382bf7d Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Thu, 15 May 2025 21:40:06 +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 --- .../app/ui/book/read/config/ReadStyleDialog.kt | 2 +- .../book/read/page/provider/ChapterProvider.kt | 12 ++++++++---- .../read/page/provider/TextChapterLayout.kt | 18 +++++++++++------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 2ad6dd497..ed3736dc6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -123,7 +123,7 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style), items = resources.getStringArray(R.array.indent).toList() ) { _, index -> ReadBookConfig.paragraphIndent = " ".repeat(index) - postEvent(EventBus.UP_CONFIG, arrayListOf(5)) + postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5)) } } tvPadding.setOnClickListener { 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 83e6419ca..ff5fe904e 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 @@ -864,11 +864,15 @@ object ChapterProvider { titleTopSpacing = ReadBookConfig.titleTopSpacing.dpToPx() titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dpToPx() val bodyIndent = ReadBookConfig.paragraphIndent - var indentWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { - indentWidth += contentPaint.letterSpacing * contentPaint.textSize + indentCharWidth = if (bodyIndent.isNotEmpty()) { + var indentWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { + indentWidth += contentPaint.letterSpacing * contentPaint.textSize + } + indentWidth / bodyIndent.length + } else { + 0f } - indentCharWidth = indentWidth / bodyIndent.length titlePaintTextHeight = titlePaint.textHeight contentPaintTextHeight = contentPaint.textHeight titlePaintFontMetrics = titlePaint.fontMetrics 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 59c1aaedd..ecb11ce8e 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 @@ -73,6 +73,10 @@ class TextChapterLayout( private val stringBuilder = StringBuilder() private val paragraphIndent = ReadBookConfig.paragraphIndent + private val titleMode = ReadBookConfig.titleMode + private val useZhLayout = ReadBookConfig.useZhLayout + private val isMiddleTitle = ReadBookConfig.isMiddleTitle + private val textFullJustify = ReadBookConfig.textFullJustify private var pendingTextPage = TextPage() @@ -196,7 +200,7 @@ class TextChapterLayout( val isSingleImageStyle = imageStyle.equals(Book.imgStyleSingle, true) val isTextImageStyle = imageStyle.equals(Book.imgStyleText, true) - if (ReadBookConfig.titleMode != 2 || bookChapter.isVolume || contents.isEmpty()) { + if (titleMode != 2 || bookChapter.isVolume || contents.isEmpty()) { //标题非隐藏 displayTitle.splitNotBlank("\n").forEach { text -> setTypeText( @@ -406,7 +410,7 @@ class TextChapterLayout( ) { val widthsArray = allocateFloatArray(text.length) textPaint.getTextWidthsCompat(text, widthsArray) - val layout = if (ReadBookConfig.useZhLayout) { + val layout = if (useZhLayout) { val (words, widths) = measureTextSplit(text, widthsArray) val indentSize = if (isFirstLine) paragraphIndent.length else 0 ZhLayout(text, textPaint, visibleWidth, words, widths, indentSize) @@ -471,7 +475,7 @@ class TextChapterLayout( //标题x轴居中 val startX = if ( isTitle && - (ReadBookConfig.isMiddleTitle || emptyContent || isVolumeTitle + (isMiddleTitle || emptyContent || isVolumeTitle || imageStyle?.uppercase() == Book.imgStyleSingle) ) { (visibleWidth - desiredWidth) / 2 @@ -487,7 +491,7 @@ class TextChapterLayout( else -> { if ( isTitle && - (ReadBookConfig.isMiddleTitle || emptyContent || isVolumeTitle + (isMiddleTitle || emptyContent || isVolumeTitle || imageStyle?.uppercase() == Book.imgStyleSingle) ) { //标题居中 @@ -556,7 +560,7 @@ class TextChapterLayout( srcList: LinkedList? ) { var x = 0f - if (!ReadBookConfig.textFullJustify) { + if (!textFullJustify) { addCharsToLineNatural( book, absStartX, textLine, words, x, true, textWidths, srcList @@ -603,7 +607,7 @@ class TextChapterLayout( textWidths: List, srcList: LinkedList? ) { - if (!ReadBookConfig.textFullJustify) { + if (!textFullJustify) { addCharsToLineNatural( book, absStartX, textLine, words, startX, false, textWidths, srcList @@ -664,7 +668,7 @@ class TextChapterLayout( textWidths: List, srcList: LinkedList? ) { - val indentLength = ReadBookConfig.paragraphIndent.length + val indentLength = paragraphIndent.length var x = startX textLine.startX = absStartX + startX for (index in words.indices) {