mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
Fix chapter layout
This commit is contained in:
@@ -400,7 +400,7 @@ object ChapterProvider {
|
||||
durY = adjustHeight // 将 Y 坐标设置为居中位置
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
else -> {
|
||||
if (size.width > visibleWidth) {
|
||||
height = size.height * visibleWidth / size.width
|
||||
@@ -473,7 +473,10 @@ object ChapterProvider {
|
||||
): Pair<Int, Float> {
|
||||
var absStartX = x
|
||||
val layout = if (ReadBookConfig.useZhLayout) {
|
||||
ZhLayout(text, textPaint, visibleWidth, emptyList(), emptyList())
|
||||
ZhLayout(
|
||||
text, textPaint, visibleWidth, emptyList(), emptyList(),
|
||||
ReadBookConfig.paragraphIndent.length
|
||||
)
|
||||
} else {
|
||||
StaticLayout(text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true)
|
||||
}
|
||||
@@ -605,7 +608,9 @@ object ChapterProvider {
|
||||
sbLength: Int
|
||||
) {
|
||||
val lastLine = textPages.last().lines.lastOrNull { it.paragraphNum > 0 }
|
||||
?: textPages.getOrNull(textPages.lastIndex - 1)?.lines?.lastOrNull { it.paragraphNum > 0 }
|
||||
?: textPages.getOrNull(
|
||||
textPages.lastIndex - 1
|
||||
)?.lines?.lastOrNull { it.paragraphNum > 0 }
|
||||
val paragraphNum = when {
|
||||
lastLine == null -> 1
|
||||
lastLine.isParagraphEnd -> lastLine.paragraphNum + 1
|
||||
|
||||
@@ -72,6 +72,8 @@ class TextChapterLayout(
|
||||
private val indentCharWidth = ChapterProvider.indentCharWidth
|
||||
private val stringBuilder = StringBuilder()
|
||||
|
||||
private val paragraphIndent = ReadBookConfig.paragraphIndent
|
||||
|
||||
private var pendingTextPage = TextPage()
|
||||
|
||||
private var isCompleted = false
|
||||
@@ -252,7 +254,8 @@ class TextChapterLayout(
|
||||
contentPaint,
|
||||
contentPaintTextHeight,
|
||||
contentPaintFontMetrics,
|
||||
book.getImageStyle()
|
||||
book.getImageStyle(),
|
||||
isFirstLine = start == 0
|
||||
).let {
|
||||
absStartX = it.first
|
||||
durY = it.second
|
||||
@@ -281,7 +284,8 @@ class TextChapterLayout(
|
||||
contentPaint,
|
||||
contentPaintTextHeight,
|
||||
contentPaintFontMetrics,
|
||||
book.getImageStyle()
|
||||
book.getImageStyle(),
|
||||
isFirstLine = start == 0
|
||||
).let {
|
||||
absStartX = it.first
|
||||
durY = it.second
|
||||
@@ -442,6 +446,7 @@ class TextChapterLayout(
|
||||
fontMetrics: Paint.FontMetrics,
|
||||
imageStyle: String?,
|
||||
isTitle: Boolean = false,
|
||||
isFirstLine: Boolean = true,
|
||||
emptyContent: Boolean = false,
|
||||
isVolumeTitle: Boolean = false,
|
||||
srcList: LinkedList<String>? = null
|
||||
@@ -459,7 +464,8 @@ class TextChapterLayout(
|
||||
}
|
||||
val layout = if (ReadBookConfig.useZhLayout) {
|
||||
val (words, widths) = measureTextSplit(text, widthsArray)
|
||||
ZhLayout(text, textPaint, visibleWidth, words, widths)
|
||||
val indentSize = if (isFirstLine) paragraphIndent.length else 0
|
||||
ZhLayout(text, textPaint, visibleWidth, words, widths, indentSize)
|
||||
} else {
|
||||
StaticLayout(text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true)
|
||||
}
|
||||
@@ -532,7 +538,7 @@ class TextChapterLayout(
|
||||
val desiredWidth = widths.fastSum()
|
||||
textLine.text = lineText
|
||||
when {
|
||||
lineIndex == 0 && layout.lineCount > 1 && !isTitle -> {
|
||||
lineIndex == 0 && layout.lineCount > 1 && !isTitle && isFirstLine -> {
|
||||
//多行的第一行 非标题
|
||||
addCharsToLineFirst(
|
||||
book, absStartX, textLine, words, textPaint,
|
||||
@@ -638,8 +644,8 @@ class TextChapterLayout(
|
||||
)
|
||||
return
|
||||
}
|
||||
val bodyIndent = ReadBookConfig.paragraphIndent
|
||||
for (i in bodyIndent.indices) {
|
||||
val bodyIndent = paragraphIndent
|
||||
repeat(bodyIndent.length) {
|
||||
val x1 = x + indentCharWidth
|
||||
textLine.addColumn(
|
||||
TextColumn(
|
||||
@@ -708,7 +714,7 @@ class TextChapterLayout(
|
||||
}
|
||||
} else {
|
||||
val gapCount: Int = words.lastIndex
|
||||
val d = residualWidth / gapCount
|
||||
val d = if (gapCount > 0) residualWidth / gapCount else 0f
|
||||
textLine.extraLetterSpacingOffsetX = -d / 2
|
||||
textLine.extraLetterSpacing = d / textPaint.textSize
|
||||
var x = startX
|
||||
|
||||
@@ -18,7 +18,8 @@ class ZhLayout(
|
||||
textPaint: TextPaint,
|
||||
width: Int,
|
||||
words: List<String>,
|
||||
widths: List<Float>
|
||||
widths: List<Float>,
|
||||
indentSize: Int
|
||||
) : Layout(text, textPaint, width, Alignment.ALIGN_NORMAL, 0f, 0f) {
|
||||
companion object {
|
||||
private val postPanc = hashSetOf(
|
||||
@@ -97,8 +98,9 @@ class ZhLayout(
|
||||
/*特殊标点使用难保证显示效果,所以不考虑间隔,直接查找到能满足条件的分割字*/
|
||||
var breakLength = 0
|
||||
if (reCheck && index > 2) {
|
||||
val startPos = if (line == 0) indentSize else getLineStart(line)
|
||||
breakMod = BreakMod.NORMAL
|
||||
for (i in (index) downTo 1) {
|
||||
for (i in (index) downTo 1 + startPos) {
|
||||
if (i == index) {
|
||||
breakIndex = 0
|
||||
cwPre = 0f
|
||||
|
||||
Reference in New Issue
Block a user