This commit is contained in:
Horis
2024-02-22 00:00:24 +08:00
parent 509c2fdc5c
commit f456e659a4
@@ -26,9 +26,11 @@ import io.legado.app.utils.fastSum
import io.legado.app.utils.splitNotBlank import io.legado.app.utils.splitNotBlank
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.util.LinkedList import java.util.LinkedList
import java.util.Locale import java.util.Locale
import kotlin.coroutines.coroutineContext
class TextChapterLayout( class TextChapterLayout(
scope: CoroutineScope, scope: CoroutineScope,
@@ -187,6 +189,7 @@ class TextChapterLayout(
} }
val sb = StringBuffer() val sb = StringBuffer()
contents.forEach { content -> contents.forEach { content ->
coroutineContext.ensureActive()
if (book.getImageStyle().equals(Book.imgStyleText, true)) { if (book.getImageStyle().equals(Book.imgStyleText, true)) {
//图片样式为文字嵌入类型 //图片样式为文字嵌入类型
var text = content.replace(ChapterProvider.srcReplaceChar, "") var text = content.replace(ChapterProvider.srcReplaceChar, "")
@@ -218,6 +221,7 @@ class TextChapterLayout(
val matcher = AppPattern.imgPattern.matcher(content) val matcher = AppPattern.imgPattern.matcher(content)
var start = 0 var start = 0
while (matcher.find()) { while (matcher.find()) {
coroutineContext.ensureActive()
val text = content.substring(start, matcher.start()) val text = content.substring(start, matcher.start())
if (text.isNotBlank()) { if (text.isNotBlank()) {
setTypeText( setTypeText(
@@ -420,6 +424,7 @@ class TextChapterLayout(
else -> y else -> y
} }
for (lineIndex in 0 until layout.lineCount) { for (lineIndex in 0 until layout.lineCount) {
coroutineContext.ensureActive()
val textLine = TextLine(isTitle = isTitle) val textLine = TextLine(isTitle = isTitle)
if (durY + textHeight > visibleHeight) { if (durY + textHeight > visibleHeight) {
val textPage = textPages.last() val textPage = textPages.last()