卷名居中显示

pull/1513/head
Xwite 3 years ago
parent 9fd1edcd3f
commit 2bf8185a16
  1. 33
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt

@ -129,11 +129,12 @@ object ChapterProvider {
matcher.appendTail(sb)
text = sb.toString()
val isTitle = index == 0
val isVolumeTitle = bookChapter.isVolume && isTitle && bookChapter.url == bookChapter.title
val textPaint = if (isTitle) titlePaint else contentPaint
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
setTypeText(
absStartX, durY, text, textPages, stringBuilder,
isTitle, textPaint, srcList
isTitle, isVolumeTitle, textPaint, srcList
).let {
absStartX = it.first
durY = it.second
@ -146,11 +147,12 @@ object ChapterProvider {
val text = content.substring(start, matcher.start())
if (text.isNotBlank()) {
val isTitle = index == 0
val isVolumeTitle = bookChapter.isVolume && isTitle && bookChapter.url == bookChapter.title
val textPaint = if (isTitle) titlePaint else contentPaint
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
setTypeText(
absStartX, durY, text, textPages,
stringBuilder, isTitle, textPaint
stringBuilder, isTitle, isVolumeTitle, textPaint
).let {
absStartX = it.first
durY = it.second
@ -167,11 +169,12 @@ object ChapterProvider {
val text = content.substring(start, content.length)
if (text.isNotBlank()) {
val isTitle = index == 0
val isVolumeTitle = bookChapter.isVolume && isTitle && bookChapter.url == bookChapter.title
val textPaint = if (isTitle) titlePaint else contentPaint
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
setTypeText(
absStartX, durY, text, textPages,
stringBuilder, isTitle, textPaint
stringBuilder, isTitle, isVolumeTitle, textPaint
).let {
absStartX = it.first
durY = it.second
@ -274,16 +277,21 @@ object ChapterProvider {
textPages: ArrayList<TextPage>,
stringBuilder: StringBuilder,
isTitle: Boolean,
isVolumeTitle: Boolean,
textPaint: TextPaint,
srcList: LinkedList<String>? = null
): Pair<Int, Float> {
var absStartX = x
var durY = if (isTitle) y + titleTopSpacing else y
val layout = if (ReadBookConfig.useZhLayout) {
ZhLayout(text, textPaint, visibleWidth)
} else StaticLayout(
text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true
)
var durY = when {
isVolumeTitle -> ((visibleHeight - layout.lineCount * textPaint.textHeight) / 2).toFloat()
isTitle -> y + titleTopSpacing
else -> y
}
for (lineIndex in 0 until layout.lineCount) {
val textLine = TextLine(isTitle = isTitle)
if (durY + textPaint.textHeight > visibleHeight) {
@ -309,8 +317,9 @@ object ChapterProvider {
text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex))
val desiredWidth = layout.getLineWidth(lineIndex)
var isLastLine = false
if (lineIndex == 0 && layout.lineCount > 1 && !isTitle) {
//第一行
when {
lineIndex == 0 && layout.lineCount > 1 && !isTitle -> {
//第一行 非标题
textLine.text = words
addCharsToLineFirst(
absStartX,
@ -320,11 +329,13 @@ object ChapterProvider {
desiredWidth,
srcList
)
} else if (lineIndex == layout.lineCount - 1) {
}
lineIndex == layout.lineCount - 1 -> {
//最后一行
textLine.text = "$words\n"
isLastLine = true
val startX = if (isTitle && ReadBookConfig.titleMode == 1)
//标题居中
val startX = if (isTitle && ReadBookConfig.titleMode == 1 || isVolumeTitle)
(visibleWidth - layout.getLineWidth(lineIndex)) / 2
else 0f
addCharsToLineLast(
@ -335,7 +346,8 @@ object ChapterProvider {
startX,
srcList
)
} else {
}
else -> {
//中间行
textLine.text = words
addCharsToLineMiddle(
@ -348,6 +360,7 @@ object ChapterProvider {
srcList
)
}
}
stringBuilder.append(words)
if (isLastLine) stringBuilder.append("\n")
textPages.last().textLines.add(textLine)
@ -355,7 +368,7 @@ object ChapterProvider {
durY += textPaint.textHeight * lineSpacingExtra
textPages.last().height = durY
}
if (isTitle) durY += titleBottomSpacing
if (isTitle && !isVolumeTitle) durY += titleBottomSpacing
durY += textPaint.textHeight * paragraphSpacing / 10f
return Pair(absStartX, durY)
}

Loading…
Cancel
Save