From fe16b82b3726a0f758e631a5c5aa1f54b57057c2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 26 Jan 2023 15:07:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8B=B1=E6=96=87=E4=B8=A4?= =?UTF-8?q?=E7=AB=AF=E5=AF=B9=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../read/page/provider/ChapterProvider.kt | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 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 fbb4167d6..a7abdbf7b 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 @@ -458,14 +458,30 @@ object ChapterProvider { addCharsToLineNatural(book, absStartX, textLine, words, textPaint, startX, srcList) return } - val gapCount: Int = words.lastIndex - val d = (visibleWidth - desiredWidth) / gapCount - var x = startX - words.forEachIndexed { index, char -> - val cw = StaticLayout.getDesiredWidth(char, textPaint) - val x1 = if (index != words.lastIndex) (x + cw + d) else (x + cw) - addCharToLine(book, absStartX, textLine, char, x, x1, index + 1 == words.size, srcList) - x = x1 + val spaceSize = words.filter { it == " " }.size + if (spaceSize > 0) { + val d = (visibleWidth - desiredWidth) / spaceSize + var x = startX + words.forEachIndexed { index, char -> + val cw = StaticLayout.getDesiredWidth(char, textPaint) + val x1 = if (char == " ") { + if (index != words.lastIndex) (x + cw + d) else (x + cw) + } else { + (x + cw) + } + addCharToLine(book, absStartX, textLine, char, x, x1, index + 1 == words.size, srcList) + x = x1 + } + } else { + val gapCount: Int = words.lastIndex + val d = (visibleWidth - desiredWidth) / gapCount + var x = startX + words.forEachIndexed { index, char -> + val cw = StaticLayout.getDesiredWidth(char, textPaint) + val x1 = if (index != words.lastIndex) (x + cw + d) else (x + cw) + addCharToLine(book, absStartX, textLine, char, x, x1, index + 1 == words.size, srcList) + x = x1 + } } exceed(absStartX, textLine, words) }