mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
卷名居中显示
This commit is contained in:
parent
9fd1edcd3f
commit
2bf8185a16
@ -129,11 +129,12 @@ object ChapterProvider {
|
|||||||
matcher.appendTail(sb)
|
matcher.appendTail(sb)
|
||||||
text = sb.toString()
|
text = sb.toString()
|
||||||
val isTitle = index == 0
|
val isTitle = index == 0
|
||||||
|
val isVolumeTitle = bookChapter.isVolume && isTitle && bookChapter.url == bookChapter.title
|
||||||
val textPaint = if (isTitle) titlePaint else contentPaint
|
val textPaint = if (isTitle) titlePaint else contentPaint
|
||||||
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
|
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
|
||||||
setTypeText(
|
setTypeText(
|
||||||
absStartX, durY, text, textPages, stringBuilder,
|
absStartX, durY, text, textPages, stringBuilder,
|
||||||
isTitle, textPaint, srcList
|
isTitle, isVolumeTitle, textPaint, srcList
|
||||||
).let {
|
).let {
|
||||||
absStartX = it.first
|
absStartX = it.first
|
||||||
durY = it.second
|
durY = it.second
|
||||||
@ -146,11 +147,12 @@ object ChapterProvider {
|
|||||||
val text = content.substring(start, matcher.start())
|
val text = content.substring(start, matcher.start())
|
||||||
if (text.isNotBlank()) {
|
if (text.isNotBlank()) {
|
||||||
val isTitle = index == 0
|
val isTitle = index == 0
|
||||||
|
val isVolumeTitle = bookChapter.isVolume && isTitle && bookChapter.url == bookChapter.title
|
||||||
val textPaint = if (isTitle) titlePaint else contentPaint
|
val textPaint = if (isTitle) titlePaint else contentPaint
|
||||||
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
|
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
|
||||||
setTypeText(
|
setTypeText(
|
||||||
absStartX, durY, text, textPages,
|
absStartX, durY, text, textPages,
|
||||||
stringBuilder, isTitle, textPaint
|
stringBuilder, isTitle, isVolumeTitle, textPaint
|
||||||
).let {
|
).let {
|
||||||
absStartX = it.first
|
absStartX = it.first
|
||||||
durY = it.second
|
durY = it.second
|
||||||
@ -167,11 +169,12 @@ object ChapterProvider {
|
|||||||
val text = content.substring(start, content.length)
|
val text = content.substring(start, content.length)
|
||||||
if (text.isNotBlank()) {
|
if (text.isNotBlank()) {
|
||||||
val isTitle = index == 0
|
val isTitle = index == 0
|
||||||
|
val isVolumeTitle = bookChapter.isVolume && isTitle && bookChapter.url == bookChapter.title
|
||||||
val textPaint = if (isTitle) titlePaint else contentPaint
|
val textPaint = if (isTitle) titlePaint else contentPaint
|
||||||
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
|
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
|
||||||
setTypeText(
|
setTypeText(
|
||||||
absStartX, durY, text, textPages,
|
absStartX, durY, text, textPages,
|
||||||
stringBuilder, isTitle, textPaint
|
stringBuilder, isTitle, isVolumeTitle, textPaint
|
||||||
).let {
|
).let {
|
||||||
absStartX = it.first
|
absStartX = it.first
|
||||||
durY = it.second
|
durY = it.second
|
||||||
@ -274,16 +277,21 @@ object ChapterProvider {
|
|||||||
textPages: ArrayList<TextPage>,
|
textPages: ArrayList<TextPage>,
|
||||||
stringBuilder: StringBuilder,
|
stringBuilder: StringBuilder,
|
||||||
isTitle: Boolean,
|
isTitle: Boolean,
|
||||||
|
isVolumeTitle: Boolean,
|
||||||
textPaint: TextPaint,
|
textPaint: TextPaint,
|
||||||
srcList: LinkedList<String>? = null
|
srcList: LinkedList<String>? = null
|
||||||
): Pair<Int, Float> {
|
): Pair<Int, Float> {
|
||||||
var absStartX = x
|
var absStartX = x
|
||||||
var durY = if (isTitle) y + titleTopSpacing else y
|
|
||||||
val layout = if (ReadBookConfig.useZhLayout) {
|
val layout = if (ReadBookConfig.useZhLayout) {
|
||||||
ZhLayout(text, textPaint, visibleWidth)
|
ZhLayout(text, textPaint, visibleWidth)
|
||||||
} else StaticLayout(
|
} else StaticLayout(
|
||||||
text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true
|
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) {
|
for (lineIndex in 0 until layout.lineCount) {
|
||||||
val textLine = TextLine(isTitle = isTitle)
|
val textLine = TextLine(isTitle = isTitle)
|
||||||
if (durY + textPaint.textHeight > visibleHeight) {
|
if (durY + textPaint.textHeight > visibleHeight) {
|
||||||
@ -309,44 +317,49 @@ object ChapterProvider {
|
|||||||
text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex))
|
text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex))
|
||||||
val desiredWidth = layout.getLineWidth(lineIndex)
|
val desiredWidth = layout.getLineWidth(lineIndex)
|
||||||
var isLastLine = false
|
var isLastLine = false
|
||||||
if (lineIndex == 0 && layout.lineCount > 1 && !isTitle) {
|
when {
|
||||||
//第一行
|
lineIndex == 0 && layout.lineCount > 1 && !isTitle -> {
|
||||||
textLine.text = words
|
//第一行 非标题
|
||||||
addCharsToLineFirst(
|
textLine.text = words
|
||||||
absStartX,
|
addCharsToLineFirst(
|
||||||
textLine,
|
absStartX,
|
||||||
words.toStringArray(),
|
textLine,
|
||||||
textPaint,
|
words.toStringArray(),
|
||||||
desiredWidth,
|
textPaint,
|
||||||
srcList
|
desiredWidth,
|
||||||
)
|
srcList
|
||||||
} else if (lineIndex == layout.lineCount - 1) {
|
)
|
||||||
//最后一行
|
}
|
||||||
textLine.text = "$words\n"
|
lineIndex == layout.lineCount - 1 -> {
|
||||||
isLastLine = true
|
//最后一行
|
||||||
val startX = if (isTitle && ReadBookConfig.titleMode == 1)
|
textLine.text = "$words\n"
|
||||||
(visibleWidth - layout.getLineWidth(lineIndex)) / 2
|
isLastLine = true
|
||||||
else 0f
|
//标题居中
|
||||||
addCharsToLineLast(
|
val startX = if (isTitle && ReadBookConfig.titleMode == 1 || isVolumeTitle)
|
||||||
absStartX,
|
(visibleWidth - layout.getLineWidth(lineIndex)) / 2
|
||||||
textLine,
|
else 0f
|
||||||
words.toStringArray(),
|
addCharsToLineLast(
|
||||||
textPaint,
|
absStartX,
|
||||||
startX,
|
textLine,
|
||||||
srcList
|
words.toStringArray(),
|
||||||
)
|
textPaint,
|
||||||
} else {
|
startX,
|
||||||
//中间行
|
srcList
|
||||||
textLine.text = words
|
)
|
||||||
addCharsToLineMiddle(
|
}
|
||||||
absStartX,
|
else -> {
|
||||||
textLine,
|
//中间行
|
||||||
words.toStringArray(),
|
textLine.text = words
|
||||||
textPaint,
|
addCharsToLineMiddle(
|
||||||
desiredWidth,
|
absStartX,
|
||||||
0f,
|
textLine,
|
||||||
srcList
|
words.toStringArray(),
|
||||||
)
|
textPaint,
|
||||||
|
desiredWidth,
|
||||||
|
0f,
|
||||||
|
srcList
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
stringBuilder.append(words)
|
stringBuilder.append(words)
|
||||||
if (isLastLine) stringBuilder.append("\n")
|
if (isLastLine) stringBuilder.append("\n")
|
||||||
@ -355,7 +368,7 @@ object ChapterProvider {
|
|||||||
durY += textPaint.textHeight * lineSpacingExtra
|
durY += textPaint.textHeight * lineSpacingExtra
|
||||||
textPages.last().height = durY
|
textPages.last().height = durY
|
||||||
}
|
}
|
||||||
if (isTitle) durY += titleBottomSpacing
|
if (isTitle && !isVolumeTitle) durY += titleBottomSpacing
|
||||||
durY += textPaint.textHeight * paragraphSpacing / 10f
|
durY += textPaint.textHeight * paragraphSpacing / 10f
|
||||||
return Pair(absStartX, durY)
|
return Pair(absStartX, durY)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user