From 318ff762fa8e1b44fcbf764a6c241ca49f3eded5 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Sun, 1 Oct 2023 23:45:47 +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 --- .../ui/book/read/page/provider/ZhLayout.kt | 23 ++++++++++++++----- .../main/java/io/legado/app/utils/UrlUtil.kt | 3 ++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt index 12806677dde7..fd06e3768330 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt @@ -15,17 +15,20 @@ class ZhLayout( textPaint: TextPaint, width: Int ) : Layout(text, textPaint, width, Alignment.ALIGN_NORMAL, 0f, 0f) { + companion object { + private val postPanc = hashSetOf( + ",", "。", ":", "?", "!", "、", "”", "’", ")", "》", "}", + "】", ")", ">", "]", "}", ",", ".", "?", "!", ":", "」", ";", ";" + ) + private val prePanc = hashSetOf("“", "(", "《", "【", "‘", "‘", "(", "<", "[", "{", "「") + } + private val defaultCapacity = 10 var lineStart = IntArray(defaultCapacity) var lineWidth = FloatArray(defaultCapacity) private var lineCount = 0 private val curPaint = textPaint private val cnCharWitch = getDesiredWidth("我", textPaint) - private val postPanc = hashSetOf( - ",", "。", ":", "?", "!", "、", "”", "’", ")", "》", "}", - "】", ")", ">", "]", "}", ",", ".", "?", "!", ":", "」", ";", ";" - ) - private val prePanc = hashSetOf("“", "(", "《", "【", "‘", "‘", "(", "<", "[", "{", "「") enum class BreakMod { NORMAL, BREAK_ONE_CHAR, BREAK_MORE_CHAR, CPS_1, CPS_2, CPS_3, } class Locate { @@ -42,7 +45,10 @@ class ZhLayout( var line = 0 val widthsArray = FloatArray(text.length) curPaint.getTextWidths(text as String, widthsArray) - val (words, widths) = ChapterProvider.getStringArrayAndTextWidths(text, widthsArray.asList()) + val (words, widths) = ChapterProvider.getStringArrayAndTextWidths( + text, + widthsArray.asList() + ) var lineW = 0f var cwPre = 0f var length = 0 @@ -111,26 +117,31 @@ class ZhLayout( lineStart[line + 1] = length breakCharCnt = 1 } + BreakMod.BREAK_ONE_CHAR -> {//模式1 当前行下移一个字 offset = cw + cwPre lineStart[line + 1] = length - words[index - 1].length breakCharCnt = 2 } + BreakMod.BREAK_MORE_CHAR -> {//模式2 当前行下移多个字 offset = cw + cwPre lineStart[line + 1] = length - breakLength breakCharCnt = breakIndex + 1 } + BreakMod.CPS_1 -> {//模式3 两个后置标点压缩 offset = 0f lineStart[line + 1] = length + s.length breakCharCnt = 0 } + BreakMod.CPS_2 -> { //模式4 前置标点压缩+前置标点压缩+字 offset = 0f lineStart[line + 1] = length + s.length breakCharCnt = 0 } + BreakMod.CPS_3 -> {//模式5 前置标点压缩+字+后置标点压缩 offset = 0f lineStart[line + 1] = length + s.length diff --git a/app/src/main/java/io/legado/app/utils/UrlUtil.kt b/app/src/main/java/io/legado/app/utils/UrlUtil.kt index bc057b2e4025..97d9b6c7def2 100644 --- a/app/src/main/java/io/legado/app/utils/UrlUtil.kt +++ b/app/src/main/java/io/legado/app/utils/UrlUtil.kt @@ -148,13 +148,14 @@ object UrlUtil { } } + private val fileSuffixRegex = Regex("^[a-z\\d]+$", RegexOption.IGNORE_CASE) + /* 获取合法的文件后缀 */ fun getSuffix(str: String, default: String? = null): String { val suffix = CustomUrl(str).getUrl() .substringAfterLast(".", "") .substringBefore("?") //检查截取的后缀字符是否合法 [a-zA-Z0-9] - val fileSuffixRegex = Regex("^[a-z\\d]+$", RegexOption.IGNORE_CASE) return if (suffix.length > 5 || !suffix.matches(fileSuffixRegex)) { AppLog.put("Cannot find legal suffix:\n target: $str\n suffix: $suffix") default ?: "ext"