diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index da5f29f4f..a9432cb94 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -6,6 +6,7 @@ import io.legado.app.R import io.legado.app.help.ReadBookConfig import io.legado.app.model.ReadBook import io.legado.app.ui.book.read.page.provider.ChapterProvider +import io.legado.app.utils.textHeight import splitties.init.appCtx import java.text.DecimalFormat import kotlin.math.min @@ -42,7 +43,8 @@ data class TextPage( val lastLine = textLines[leftLineSize - 1] if (lastLine.isImage) return@run 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) if (surplus == 0f) return@run height += surplus @@ -59,7 +61,8 @@ data class TextPage( val lastLine = textLines.last() if (lastLine.isImage) return@run 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) if (surplus == 0f) return@run val tj = surplus / (textLines.size - leftLineSize - 1) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index ca948ff0c..2e4f4713b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -69,7 +69,8 @@ object ChapterProvider { private set @JvmStatic - private var lineSpacingExtra = 0 + var lineSpacingExtra = 0f + private set @JvmStatic private var paragraphSpacing = 0 @@ -351,7 +352,7 @@ object ChapterProvider { if (isLastLine) stringBuilder.append("\n") textPages.last().textLines.add(textLine) textLine.upTopBottom(durY, textPaint) - durY += textPaint.textHeight * lineSpacingExtra / 10f + durY += textPaint.textHeight * lineSpacingExtra textPages.last().height = durY } if (isTitle) durY += titleBottomSpacing @@ -500,12 +501,12 @@ object ChapterProvider { */ fun upStyle() { typeface = getTypeface(ReadBookConfig.textFont) - getPaint(typeface).let { + getPaints(typeface).let { titlePaint = it.first contentPaint = it.second } //间距 - lineSpacingExtra = ReadBookConfig.lineSpacingExtra + lineSpacingExtra = ReadBookConfig.lineSpacingExtra / 10f paragraphSpacing = ReadBookConfig.paragraphSpacing titleTopSpacing = ReadBookConfig.titleTopSpacing.dp titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dp @@ -538,7 +539,7 @@ object ChapterProvider { } ?: Typeface.DEFAULT } - private fun getPaint(typeface: Typeface): Pair { + private fun getPaints(typeface: Typeface): Pair { // 字体统一处理 val bold = Typeface.create(typeface, Typeface.BOLD) val normal = Typeface.create(typeface, Typeface.NORMAL)