From cb5108933e0b665f4322ec9659aa7eb44ad93721 Mon Sep 17 00:00:00 2001 From: aoi Date: Fri, 5 Jun 2026 00:06:46 +0800 Subject: [PATCH] =?UTF-8?q?=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 --- .../read/page/provider/TextChapterLayout.kt | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) 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 9b881b90c..b5cab46b3 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 @@ -278,7 +278,9 @@ class TextChapterLayout( val matcher = AppPattern.imgPattern.matcher(text) val ssb = StringBuffer() while (matcher.find()) { - matcher.appendReplacement(ssb, srcReplaceChar) + if (matcher.group(1) != null) { + matcher.appendReplacement(ssb, srcReplaceChar) + } } matcher.appendTail(ssb) fullTextBuilder.append(ssb.toString()) @@ -1394,8 +1396,10 @@ class TextChapterLayout( var hasMatch = false for (rule in rules) { try { - val regex = regexCache.getOrPut(rule.pattern) { - Regex(rule.pattern, RegexOption.DOT_MATCHES_ALL) + val regex = synchronized(regexCache) { + regexCache.getOrPut(rule.pattern) { + Regex(rule.pattern, RegexOption.DOT_MATCHES_ALL) + } } regex.findAll(fullText).forEach { match -> hasMatch = true @@ -1415,23 +1419,29 @@ class TextChapterLayout( private fun applyRegexColorRules(text: String, offset: Int): RegexMatchResult? { val globalResult = globalRegexResult ?: return null if (offset < 0) return null + val endIdx = minOf(offset + text.length, globalResult.colorArray.size) + var hasMatch = false + for (globalIdx in offset until endIdx) { + if (globalResult.colorArray[globalIdx] != -1 || globalResult.fontPathArray[globalIdx] != null) { + hasMatch = true + break + } + } + if (!hasMatch) return null val colorArray = IntArray(text.length) { -1 } val fontPathArray = arrayOfNulls(text.length) - var hasMatch = false for (i in text.indices) { val globalIdx = offset + i if (globalIdx >= 0 && globalIdx < globalResult.colorArray.size) { if (globalResult.colorArray[globalIdx] != -1) { colorArray[i] = globalResult.colorArray[globalIdx] - hasMatch = true } if (globalResult.fontPathArray[globalIdx] != null) { fontPathArray[i] = globalResult.fontPathArray[globalIdx] - hasMatch = true } } } - return if (hasMatch) RegexMatchResult(colorArray, fontPathArray) else null + return RegexMatchResult(colorArray, fontPathArray) } private data class WordStyle(