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