mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
卷的正文有内容时 标题x轴居中
This commit is contained in:
parent
d0ed7c7df4
commit
90c8fe182d
@ -129,12 +129,13 @@ object ChapterProvider {
|
|||||||
matcher.appendTail(sb)
|
matcher.appendTail(sb)
|
||||||
text = sb.toString()
|
text = sb.toString()
|
||||||
val isTitle = index == 0
|
val isTitle = index == 0
|
||||||
val isVolumeTitle = isTitle && contents.size == 1
|
val isTitleWithNoContent = isTitle && contents.size == 1
|
||||||
|
val isVolumeTitle = isTitle && bookChapter.isVolume
|
||||||
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, isVolumeTitle, textPaint, srcList
|
isTitle, isTitleWithNoContent, isVolumeTitle, textPaint, srcList
|
||||||
).let {
|
).let {
|
||||||
absStartX = it.first
|
absStartX = it.first
|
||||||
durY = it.second
|
durY = it.second
|
||||||
@ -147,12 +148,13 @@ 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 = isTitle && contents.size == 1
|
val isTitleWithNoContent = isTitle && contents.size == 1
|
||||||
|
val isVolumeTitle = isTitle && bookChapter.isVolume
|
||||||
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,
|
||||||
stringBuilder, isTitle, isVolumeTitle, textPaint
|
isTitle, isTitleWithNoContent, isVolumeTitle, textPaint
|
||||||
).let {
|
).let {
|
||||||
absStartX = it.first
|
absStartX = it.first
|
||||||
durY = it.second
|
durY = it.second
|
||||||
@ -169,12 +171,13 @@ 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 = isTitle && contents.size == 1
|
val isTitleWithNoContent = isTitle && contents.size == 1
|
||||||
|
val isVolumeTitle = isTitle && bookChapter.isVolume
|
||||||
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,
|
||||||
stringBuilder, isTitle, isVolumeTitle, textPaint
|
isTitle, isTitleWithNoContent, isVolumeTitle, textPaint
|
||||||
).let {
|
).let {
|
||||||
absStartX = it.first
|
absStartX = it.first
|
||||||
durY = it.second
|
durY = it.second
|
||||||
@ -277,6 +280,7 @@ object ChapterProvider {
|
|||||||
textPages: ArrayList<TextPage>,
|
textPages: ArrayList<TextPage>,
|
||||||
stringBuilder: StringBuilder,
|
stringBuilder: StringBuilder,
|
||||||
isTitle: Boolean,
|
isTitle: Boolean,
|
||||||
|
isTitleWithNoContent: Boolean,
|
||||||
isVolumeTitle: Boolean,
|
isVolumeTitle: Boolean,
|
||||||
textPaint: TextPaint,
|
textPaint: TextPaint,
|
||||||
srcList: LinkedList<String>? = null
|
srcList: LinkedList<String>? = null
|
||||||
@ -288,7 +292,8 @@ object ChapterProvider {
|
|||||||
text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true
|
text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true
|
||||||
)
|
)
|
||||||
var durY = when {
|
var durY = when {
|
||||||
isVolumeTitle -> ((visibleHeight - layout.lineCount * textPaint.textHeight) / 2).toFloat()
|
//标题y轴居中
|
||||||
|
isTitleWithNoContent -> ((visibleHeight - layout.lineCount * textPaint.textHeight) / 2).toFloat()
|
||||||
isTitle -> y + titleTopSpacing
|
isTitle -> y + titleTopSpacing
|
||||||
else -> y
|
else -> y
|
||||||
}
|
}
|
||||||
@ -334,8 +339,8 @@ object ChapterProvider {
|
|||||||
//最后一行
|
//最后一行
|
||||||
textLine.text = "$words\n"
|
textLine.text = "$words\n"
|
||||||
isLastLine = true
|
isLastLine = true
|
||||||
//标题居中
|
//标题x轴居中
|
||||||
val startX = if (isTitle && ReadBookConfig.titleMode == 1 || isVolumeTitle)
|
val startX = if (isTitle && ReadBookConfig.titleMode == 1 || isTitleWithNoContent || isVolumeTitle)
|
||||||
(visibleWidth - layout.getLineWidth(lineIndex)) / 2
|
(visibleWidth - layout.getLineWidth(lineIndex)) / 2
|
||||||
else 0f
|
else 0f
|
||||||
addCharsToLineLast(
|
addCharsToLineLast(
|
||||||
@ -368,7 +373,7 @@ object ChapterProvider {
|
|||||||
durY += textPaint.textHeight * lineSpacingExtra
|
durY += textPaint.textHeight * lineSpacingExtra
|
||||||
textPages.last().height = durY
|
textPages.last().height = durY
|
||||||
}
|
}
|
||||||
if (isTitle && !isVolumeTitle) durY += titleBottomSpacing
|
if (isTitle && !isTitleWithNoContent) 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