Przeglądaj źródła

feat: 显示之问题

HapeLee 1 miesiąc temu
rodzic
commit
1c0782addf

+ 8 - 2
app/src/main/java/io/legado/app/feature/reader/core/layout/ReaderPaginator.kt

@@ -655,8 +655,14 @@ internal class ReaderPaginationSession(
                 is ReaderMeasuredInlineItem.Image -> "\uFFFC"
             }
         }
-        val lineGapPx =
-            (paragraph.lineSpacingMultiplier - 1f).coerceAtLeast(0f) * paragraph.lineHeightPx
+        // 纵向预算取「本段行距」与「正文行距」的较大者:旧 View
+        // `TextLine.drawNineSliceFrames` 的 `gap` 用的是全局(正文)的
+        // `ChapterProvider.lineSpacingExtra`,标题与正文共用一份。只按本段行距算时,
+        // 标题行距被设成 1.0(设置值 10,"标题不加行距")就会得到 0 预算,九宫格上下两条边
+        // 随之被压成 0 高度整条消失——只剩中心格和左右两条边在上下切分线之间的那一段。
+        val lineGapPx = (
+                maxOf(paragraph.lineSpacingMultiplier, config.lineSpacingMultiplier) - 1f
+                ).coerceAtLeast(0f) * paragraph.lineHeightPx
         val halfLineGapPx = lineGapPx / 2f
 
         fun itemFrame(index: Int) =

+ 41 - 0
app/src/test/java/io/legado/app/feature/reader/core/layout/ReaderPaginatorTest.kt

@@ -776,6 +776,47 @@ class ReaderPaginatorTest {
         assertEquals(glyph.bounds.right + 4f, run.bounds.right, 0.001f)
     }
 
+    /**
+     * 标题行距收紧到 1.0(设置值 10)时,本段行距留白为 0,但九宫格上下两条边不能整条消失:
+     * 纵向预算回落到正文行距——旧 View 的预算取自全局 `ChapterProvider.lineSpacingExtra`,
+     * 标题与正文共用一份。只有正文行距同样为 1.0 时才退回上一条用例的「中心 + 左右两条边」。
+     */
+    @Test
+    fun tightTitleLineSpacingStillBudgetsTheNineSliceVerticalEdges() {
+        val framedStyle = style.copy(
+            backgroundImage = ReaderTextBackgroundImage(
+                "frame.png", 3, 1f,
+                contentInsetLeftPx = 3f,
+                contentInsetRightPx = 4f,
+                contentInsetTopPx = 8f,
+                contentInsetBottomPx = 8f,
+            )
+        )
+        val page = ReaderPaginator.paginateBlocks(
+            listOf(
+                ReaderMeasuredBlock.InlineParagraph(
+                    items = listOf(ReaderMeasuredInlineItem.Text("字", 10f, framedStyle, 0)),
+                    indentCharacters = 0,
+                    alignment = ReaderTextAlignment.START,
+                    lineHeightPx = 20f,
+                    baselineOffsetPx = 15f,
+                    baseTextSizePx = 10f,
+                    emphasized = true,
+                    lineSpacingMultiplier = 1f,
+                )
+            ),
+            config.copy(viewportHeightPx = 100, lineSpacingMultiplier = 1.5f),
+        ).single()
+
+        val glyph = page.elements.single() as ReaderElement.Text
+        // 正文行距 1.5 ⇒ 留白 10px,够按原图厚度画满 8px 的上下边。
+        assertEquals(8f, glyph.backgroundFrameTopPx, 0.001f)
+        assertEquals(8f, glyph.backgroundFrameBottomPx, 0.001f)
+        val run = page.textBackgroundRuns().single()
+        assertEquals(glyph.bounds.top - 8f, run.bounds.top, 0.001f)
+        assertEquals(glyph.bounds.bottom + 8f, run.bounds.bottom, 0.001f)
+    }
+
     /**
      * 章末页的堆叠高度额外加 [ReaderPaginationConfig.chapterEndPaddingPx]:旧
      * `TextChapterLayout.setTypeText` 收尾时 `height = max(height, durY + 20dp)`,让下一章