Przeglądaj źródła

feat(read): 优化single样式排版 (#4663)

-调整标题和内容的排版方式

Co-authored-by: SunQAQ <sunqi87c6@gmail.com>
Sun-QAQ 1 rok temu
rodzic
commit
31c097f9cc

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

@@ -186,6 +186,9 @@ class TextChapterLayout(
         val contents = bookContent.textList
         val contents = bookContent.textList
         var absStartX = paddingLeft
         var absStartX = paddingLeft
         var durY = 0f
         var durY = 0f
+        val imageStyle = book.getImageStyle()
+        val isSingleImageStyle = imageStyle.equals(Book.imgStyleSingle, true)
+
         if (ReadBookConfig.titleMode != 2 || bookChapter.isVolume || contents.isEmpty()) {
         if (ReadBookConfig.titleMode != 2 || bookChapter.isVolume || contents.isEmpty()) {
             //标题非隐藏
             //标题非隐藏
             displayTitle.splitNotBlank("\n").forEach { text ->
             displayTitle.splitNotBlank("\n").forEach { text ->
@@ -195,7 +198,7 @@ class TextChapterLayout(
                     titlePaint,
                     titlePaint,
                     titlePaintTextHeight,
                     titlePaintTextHeight,
                     titlePaintFontMetrics,
                     titlePaintFontMetrics,
-                    book.getImageStyle(),
+                    imageStyle,
                     isTitle = true,
                     isTitle = true,
                     emptyContent = contents.isEmpty(),
                     emptyContent = contents.isEmpty(),
                     isVolumeTitle = bookChapter.isVolume
                     isVolumeTitle = bookChapter.isVolume
@@ -207,6 +210,17 @@ class TextChapterLayout(
             pendingTextPage.lines.last().isParagraphEnd = true
             pendingTextPage.lines.last().isParagraphEnd = true
             stringBuilder.append("\n")
             stringBuilder.append("\n")
             durY += titleBottomSpacing
             durY += titleBottomSpacing
+
+            // 如果是单图模式且当前页有内容,强制分页
+            if (isSingleImageStyle && pendingTextPage.lines.isNotEmpty()) {
+                pendingTextPage.height = durY
+                textPages.add(pendingTextPage)
+                onPageCompleted()
+                pendingTextPage = TextPage()
+                stringBuilder.clear()
+                absStartX = paddingLeft
+                durY = 0f
+            }
         }
         }
         val sb = StringBuffer()
         val sb = StringBuffer()
         contents.forEach { content ->
         contents.forEach { content ->
@@ -273,6 +287,15 @@ class TextChapterLayout(
                         absStartX = it.first
                         absStartX = it.first
                         durY = it.second
                         durY = it.second
                     }
                     }
+                    if (isSingleImageStyle) {
+                        pendingTextPage.height = durY
+                        textPages.add(pendingTextPage)
+                        onPageCompleted()
+                        pendingTextPage = TextPage()
+                        stringBuilder.clear()
+                        absStartX = paddingLeft
+                        durY = 0f
+                    }
                     start = matcher.end()
                     start = matcher.end()
                 }
                 }
                 if (start < content.length) {
                 if (start < content.length) {
@@ -293,7 +316,9 @@ class TextChapterLayout(
                     }
                     }
                 }
                 }
             }
             }
-            pendingTextPage.lines.last().isParagraphEnd = true
+            if (pendingTextPage.lines.isNotEmpty()) {
+                pendingTextPage.lines.last().isParagraphEnd = true
+            }
             stringBuilder.append("\n")
             stringBuilder.append("\n")
         }
         }
         textPages.add(pendingTextPage)
         textPages.add(pendingTextPage)