From 00afc2ed0a05b8b32a8455d2ecb58f4d17205df7 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Thu, 22 Feb 2024 00:00:24 +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/page/provider/TextChapterLayout.kt | 5 +++++ 1 file changed, 5 insertions(+) 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 e49c11180..70d9028a3 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 @@ -26,9 +26,11 @@ import io.legado.app.utils.fastSum import io.legado.app.utils.splitNotBlank import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.ensureActive import kotlinx.coroutines.launch import java.util.LinkedList import java.util.Locale +import kotlin.coroutines.coroutineContext class TextChapterLayout( scope: CoroutineScope, @@ -187,6 +189,7 @@ class TextChapterLayout( } val sb = StringBuffer() contents.forEach { content -> + coroutineContext.ensureActive() if (book.getImageStyle().equals(Book.imgStyleText, true)) { //图片样式为文字嵌入类型 var text = content.replace(ChapterProvider.srcReplaceChar, "▣") @@ -218,6 +221,7 @@ class TextChapterLayout( val matcher = AppPattern.imgPattern.matcher(content) var start = 0 while (matcher.find()) { + coroutineContext.ensureActive() val text = content.substring(start, matcher.start()) if (text.isNotBlank()) { setTypeText( @@ -420,6 +424,7 @@ class TextChapterLayout( else -> y } for (lineIndex in 0 until layout.lineCount) { + coroutineContext.ensureActive() val textLine = TextLine(isTitle = isTitle) if (durY + textHeight > visibleHeight) { val textPage = textPages.last()