修复底部对齐

pull/1395/head
gedoor 3 years ago
parent aad56ae01d
commit affd802c42
  1. 7
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt
  2. 11
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt

@ -6,6 +6,7 @@ import io.legado.app.R
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.utils.textHeight
import splitties.init.appCtx import splitties.init.appCtx
import java.text.DecimalFormat import java.text.DecimalFormat
import kotlin.math.min import kotlin.math.min
@ -42,7 +43,8 @@ data class TextPage(
val lastLine = textLines[leftLineSize - 1] val lastLine = textLines[leftLineSize - 1]
if (lastLine.isImage) return@run if (lastLine.isImage) return@run
val lastLineHeight = with(lastLine) { lineBottom - lineTop } val lastLineHeight = with(lastLine) { lineBottom - lineTop }
if (visibleHeight - lastLine.lineBottom >= lastLineHeight) return@run val pageHeight = lastLine.lineBottom + contentPaint.textHeight * lineSpacingExtra
if (visibleHeight - pageHeight >= lastLineHeight) return@run
val surplus = (visibleBottom - lastLine.lineBottom) val surplus = (visibleBottom - lastLine.lineBottom)
if (surplus == 0f) return@run if (surplus == 0f) return@run
height += surplus height += surplus
@ -59,7 +61,8 @@ data class TextPage(
val lastLine = textLines.last() val lastLine = textLines.last()
if (lastLine.isImage) return@run if (lastLine.isImage) return@run
val lastLineHeight = with(lastLine) { lineBottom - lineTop } val lastLineHeight = with(lastLine) { lineBottom - lineTop }
if (visibleHeight - lastLine.lineBottom >= lastLineHeight) return@run val pageHeight = lastLine.lineBottom + contentPaint.textHeight * lineSpacingExtra
if (visibleHeight - pageHeight >= lastLineHeight) return@run
val surplus = (visibleBottom - lastLine.lineBottom) val surplus = (visibleBottom - lastLine.lineBottom)
if (surplus == 0f) return@run if (surplus == 0f) return@run
val tj = surplus / (textLines.size - leftLineSize - 1) val tj = surplus / (textLines.size - leftLineSize - 1)

@ -69,7 +69,8 @@ object ChapterProvider {
private set private set
@JvmStatic @JvmStatic
private var lineSpacingExtra = 0 var lineSpacingExtra = 0f
private set
@JvmStatic @JvmStatic
private var paragraphSpacing = 0 private var paragraphSpacing = 0
@ -351,7 +352,7 @@ object ChapterProvider {
if (isLastLine) stringBuilder.append("\n") if (isLastLine) stringBuilder.append("\n")
textPages.last().textLines.add(textLine) textPages.last().textLines.add(textLine)
textLine.upTopBottom(durY, textPaint) textLine.upTopBottom(durY, textPaint)
durY += textPaint.textHeight * lineSpacingExtra / 10f durY += textPaint.textHeight * lineSpacingExtra
textPages.last().height = durY textPages.last().height = durY
} }
if (isTitle) durY += titleBottomSpacing if (isTitle) durY += titleBottomSpacing
@ -500,12 +501,12 @@ object ChapterProvider {
*/ */
fun upStyle() { fun upStyle() {
typeface = getTypeface(ReadBookConfig.textFont) typeface = getTypeface(ReadBookConfig.textFont)
getPaint(typeface).let { getPaints(typeface).let {
titlePaint = it.first titlePaint = it.first
contentPaint = it.second contentPaint = it.second
} }
//间距 //间距
lineSpacingExtra = ReadBookConfig.lineSpacingExtra lineSpacingExtra = ReadBookConfig.lineSpacingExtra / 10f
paragraphSpacing = ReadBookConfig.paragraphSpacing paragraphSpacing = ReadBookConfig.paragraphSpacing
titleTopSpacing = ReadBookConfig.titleTopSpacing.dp titleTopSpacing = ReadBookConfig.titleTopSpacing.dp
titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dp titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dp
@ -538,7 +539,7 @@ object ChapterProvider {
} ?: Typeface.DEFAULT } ?: Typeface.DEFAULT
} }
private fun getPaint(typeface: Typeface): Pair<TextPaint, TextPaint> { private fun getPaints(typeface: Typeface): Pair<TextPaint, TextPaint> {
// 字体统一处理 // 字体统一处理
val bold = Typeface.create(typeface, Typeface.BOLD) val bold = Typeface.create(typeface, Typeface.BOLD)
val normal = Typeface.create(typeface, Typeface.NORMAL) val normal = Typeface.create(typeface, Typeface.NORMAL)

Loading…
Cancel
Save