From 79293667db641d866d6fe41ec7d4ba15145cba12 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 22 Feb 2020 17:07:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/help/ReadBook.kt | 4 ++++ .../app/ui/book/read/page/ChapterProvider.kt | 22 ++++++++++--------- .../app/ui/book/read/page/ContentTextView.kt | 6 ++--- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 41bfa3c77..d038ad600 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -17,6 +17,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import org.jetbrains.anko.toast object ReadBook { @@ -283,6 +284,9 @@ object ReadBook { } } } + }.onError { + it.printStackTrace() + App.INSTANCE.toast(it.localizedMessage ?: "ChapterProvider ERROR") } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index 80db62d70..33b58b530 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -257,22 +257,24 @@ object ChapterProvider { if (lineIndex == 0 && layout.lineCount > 1) { //第一行 var x = 0f - val icw = StaticLayout.getDesiredWidth(bodyIndent, contentPaint) - var x1 = x + icw - val textChar = TextChar( - charData = bodyIndent, - leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), - rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop) - ) - textLine.textChars.add(textChar) - x = x1 + val icw = StaticLayout.getDesiredWidth(bodyIndent, contentPaint) / bodyIndent.length + for (i in 0..bodyIndent.lastIndex) { + val x1 = x + icw + val textChar = TextChar( + charData = bodyIndent[i].toString(), + leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), + rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop) + ) + textLine.textChars.add(textChar) + x = x1 + } words = words.replaceFirst(bodyIndent, "") val gapCount: Int = words.length - 1 val d = (visibleWidth - desiredWidth) / gapCount for (i in words.indices) { val char = words[i].toString() val cw = StaticLayout.getDesiredWidth(char, contentPaint) - x1 = if (i != words.lastIndex) x + cw + d else x + cw + val x1 = if (i != words.lastIndex) x + cw + d else x + cw val textChar1 = TextChar( charData = char, leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 15f10e5e3..99be420ab 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -207,12 +207,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (lineIndex == selectLineStart && lineIndex == selectLineEnd) { stringBuilder.append( it.textLines[lineIndex].text.substring( - selectCharStart + 1, - selectCharEnd + 2 + selectCharStart, + selectCharEnd + 1 ) ) } else if (lineIndex == selectLineStart) { - stringBuilder.append(it.textLines[lineIndex].text.substring(selectCharStart + 1)) + stringBuilder.append(it.textLines[lineIndex].text.substring(selectCharStart)) } else if (lineIndex == selectLineEnd) { stringBuilder.append( it.textLines[lineIndex].text.substring(0, selectCharEnd + 1)