Horis hace 2 años
padre
commit
b27c4a5bf9

+ 1 - 2
app/src/main/java/io/legado/app/model/webBook/BookContent.kt

@@ -132,8 +132,7 @@ object BookContent {
         //全文替换
         val replaceRegex = contentRule.replaceRegex
         if (!replaceRegex.isNullOrEmpty()) {
-            contentStr = contentStr.split(AppPattern.LFRegex)
-                .joinToString("\n") { it.trim { c -> c <= ' ' || c == ' ' } }
+            contentStr = contentStr.split(AppPattern.LFRegex).joinToString("\n") { it.trim() }
             contentStr = analyzeRule.getString(replaceRegex, contentStr)
             contentStr = contentStr.split(AppPattern.LFRegex).joinToString("\n") { "  $it" }
         }

+ 2 - 5
app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt

@@ -809,11 +809,8 @@ object ChapterProvider {
         paragraphSpacing = ReadBookConfig.paragraphSpacing
         titleTopSpacing = ReadBookConfig.titleTopSpacing.dpToPx()
         titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dpToPx()
-        var bodyIndent = ReadBookConfig.paragraphIndent
-        val indentLength = bodyIndent.length
-        // 有些字体的中文空格宽度不对
-        bodyIndent = "一".repeat(indentLength)
-        indentCharWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint) / indentLength
+        val bodyIndent = ReadBookConfig.paragraphIndent
+        indentCharWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint) / bodyIndent.length
         titlePaintTextHeight = titlePaint.textHeight
         contentPaintTextHeight = contentPaint.textHeight
         titlePaintFontMetrics = titlePaint.fontMetrics

+ 5 - 3
app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt

@@ -431,6 +431,7 @@ class TextChapterLayout(
 
             else -> y
         }
+        val (strList, widthList) = measureTextSplit(text, textPaint)
         for (lineIndex in 0 until layout.lineCount) {
             val textLine = TextLine(isTitle = isTitle)
             if (durY + textHeight > visibleHeight) {
@@ -461,12 +462,13 @@ class TextChapterLayout(
             val lineStart = layout.getLineStart(lineIndex)
             val lineEnd = layout.getLineEnd(lineIndex)
             val lineText = text.substring(lineStart, lineEnd)
-            val (words, widths) = measureTextSplit(lineText, textPaint)
+            val words = strList.subList(lineStart, lineEnd)
+            val widths = widthList.subList(lineStart, lineEnd)
             val desiredWidth = widths.fastSum()
             textLine.text = lineText
             when {
                 lineIndex == 0 && layout.lineCount > 1 && !isTitle -> {
-                    //第一行 非标题
+                    //多行的第一行 非标题
                     addCharsToLineFirst(
                         book, absStartX, textLine, words, textPaint,
                         desiredWidth, widths, srcList
@@ -474,7 +476,7 @@ class TextChapterLayout(
                 }
 
                 lineIndex == layout.lineCount - 1 -> {
-                    //最后一行
+                    //最后一行、单行
                     //标题x轴居中
                     val startX = if (
                         isTitle &&