From 35196168bac68ba92a41246b270e2cbf897704f4 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 28 Sep 2021 13:58:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=AA=E5=B1=8F=E5=8F=8C=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../read/page/provider/ChapterProvider.kt | 63 +++++++++++-------- 1 file changed, 36 insertions(+), 27 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 5b87a67e8..3792a36f4 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 @@ -66,6 +66,7 @@ object ChapterProvider { @JvmStatic var visibleBottom = 0 + private set @JvmStatic private var lineSpacingExtra = 0 @@ -81,6 +82,7 @@ object ChapterProvider { @JvmStatic var typeface: Typeface = Typeface.DEFAULT + private set @JvmStatic val titlePaint: TextPaint = TextPaint() @@ -89,7 +91,7 @@ object ChapterProvider { val contentPaint: TextPaint = TextPaint() var doublePage = false - + private set init { upStyle() @@ -375,11 +377,13 @@ object ChapterProvider { } val bodyIndent = ReadBookConfig.paragraphIndent val icw = StaticLayout.getDesiredWidth(bodyIndent, textPaint) / bodyIndent.length - bodyIndent.toStringArray().forEach { + bodyIndent.toStringArray().forEach { char -> val x1 = x + icw textLine.textChars.add( TextChar( - it, start = absStartX + x, end = absStartX + x1 + charData = char, + start = absStartX + x, + end = absStartX + x1 ) ) x = x1 @@ -409,13 +413,13 @@ object ChapterProvider { val gapCount: Int = words.lastIndex val d = (visibleWidth - desiredWidth) / gapCount var x = startX - words.forEachIndexed { index, s -> - val cw = StaticLayout.getDesiredWidth(s, textPaint) + words.forEachIndexed { index, char -> + val cw = StaticLayout.getDesiredWidth(char, textPaint) val x1 = if (index != words.lastIndex) (x + cw + d) else (x + cw) - if (srcList != null && s == srcReplaceChar) { + if (srcList != null && char == srcReplaceChar) { textLine.textChars.add( TextChar( - srcList.removeFirst(), + charData = srcList.removeFirst(), start = absStartX + x, end = absStartX + x1, isImage = true @@ -424,13 +428,15 @@ object ChapterProvider { } else { textLine.textChars.add( TextChar( - s, start = absStartX + x, end = absStartX + x1 + charData = char, + start = absStartX + x, + end = absStartX + x1 ) ) } x = x1 } - exceed(textLine, words) + exceed(absStartX, textLine, words) } /** @@ -445,13 +451,13 @@ object ChapterProvider { srcList: LinkedList? ) { var x = startX - words.forEach { - val cw = StaticLayout.getDesiredWidth(it, textPaint) + words.forEach { char -> + val cw = StaticLayout.getDesiredWidth(char, textPaint) val x1 = x + cw - if (srcList != null && it == srcReplaceChar) { + if (srcList != null && char == srcReplaceChar) { textLine.textChars.add( TextChar( - srcList.removeFirst(), + charData = srcList.removeFirst(), start = absStartX + x, end = absStartX + x1, isImage = true @@ -460,30 +466,33 @@ object ChapterProvider { } else { textLine.textChars.add( TextChar( - it, start = absStartX + x, end = absStartX + x1 + charData = char, + start = absStartX + x, + end = absStartX + x1 ) ) } x = x1 } - exceed(textLine, words) + exceed(absStartX, textLine, words) } /** * 超出边界处理 */ - private fun exceed(textLine: TextLine, words: Array) { -// val endX = textLine.textChars.lastOrNull()?.end ?: return -// if (endX > visibleRight) { -// val cc = (endX - visibleRight) / words.size -// for (i in 0..words.lastIndex) { -// textLine.getTextCharReverseAt(i).let { -// val py = cc * (words.size - i) -// it.start = it.start - py -// it.end = it.end - py -// } -// } -// } + private fun exceed(absStartX: Int, textLine: TextLine, words: Array) { + val visibleEnd = absStartX + visibleWidth + val endX = textLine.textChars.lastOrNull()?.end ?: return + if (endX > visibleEnd) { + val cc = (endX - visibleEnd) / words.size + for (i in 0..words.lastIndex) { + textLine.getTextCharReverseAt(i).let { + val py = cc * (words.size - i) + it.start = it.start - py + it.end = it.end - py + } + } + } } /**