Skip to content

Commit

Permalink
feat(read): 优化single样式排版 (#4663)
Browse files Browse the repository at this point in the history
-调整标题和内容的排版方式

Co-authored-by: SunQAQ <sunqi87c6@gmail.com>
  • Loading branch information
Sun-QAQ and SunQAQ authored Feb 13, 2025
1 parent 8685957 commit 9576a50
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ class TextChapterLayout(
val contents = bookContent.textList
var absStartX = paddingLeft
var durY = 0f
val imageStyle = book.getImageStyle()
val isSingleImageStyle = imageStyle.equals(Book.imgStyleSingle, true)

if (ReadBookConfig.titleMode != 2 || bookChapter.isVolume || contents.isEmpty()) {
//标题非隐藏
displayTitle.splitNotBlank("\n").forEach { text ->
Expand All @@ -195,7 +198,7 @@ class TextChapterLayout(
titlePaint,
titlePaintTextHeight,
titlePaintFontMetrics,
book.getImageStyle(),
imageStyle,
isTitle = true,
emptyContent = contents.isEmpty(),
isVolumeTitle = bookChapter.isVolume
Expand All @@ -207,6 +210,17 @@ class TextChapterLayout(
pendingTextPage.lines.last().isParagraphEnd = true
stringBuilder.append("\n")
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()
contents.forEach { content ->
Expand Down Expand Up @@ -273,6 +287,15 @@ class TextChapterLayout(
absStartX = it.first
durY = it.second
}
if (isSingleImageStyle) {
pendingTextPage.height = durY
textPages.add(pendingTextPage)
onPageCompleted()
pendingTextPage = TextPage()
stringBuilder.clear()
absStartX = paddingLeft
durY = 0f
}
start = matcher.end()
}
if (start < content.length) {
Expand All @@ -293,7 +316,9 @@ class TextChapterLayout(
}
}
}
pendingTextPage.lines.last().isParagraphEnd = true
if (pendingTextPage.lines.isNotEmpty()) {
pendingTextPage.lines.last().isParagraphEnd = true
}
stringBuilder.append("\n")
}
textPages.add(pendingTextPage)
Expand Down

0 comments on commit 9576a50

Please sign in to comment.