From 87f15dfb5d25afb39bbd91f5139a3d735124e435 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Wed, 6 Mar 2024 09:53:25 +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 --- .../read/page/provider/TextChapterLayout.kt | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 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 283038bcb..bdc1f69c2 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 @@ -780,16 +780,28 @@ class TextChapterLayout( } val widths = ArrayList(clusterCount) val stringList = ArrayList(clusterCount) - var i = start - while (i < start + length) { + var i = 0 + while (i < length) { val clusterBaseIndex = i++ - widths.add(widthsArray[clusterBaseIndex]) - while (i < length && widthsArray[i] == 0f) { + widths.add(widthsArray[start + clusterBaseIndex]) + while (i < length && widthsArray[start + i] == 0f && !isZeroWidthChar(text[i])) { i++ } - stringList.add(text.substring(clusterBaseIndex - start, i - start)) + stringList.add(text.substring(clusterBaseIndex, i)) } return stringList to widths } + private fun isZeroWidthChar(char: Char): Boolean { + return zeroWidthCodePoints.binarySearch(char.code) >= 0 + } + + companion object { + val zeroWidthCodePoints = intArrayOf( + 173, 1564, 1807, 6158, 8203, 8204, 8205, 8206, 8207, 8234, + 8235, 8236, 8237, 8238, 8288, 8289, 8290, 8291, 8292, 8294, + 8295, 8296, 8297, 8299, 8300, 8301, 8302, 8303, 65279, 65529 + ) + } + }