This commit is contained in:
Horis 2024-12-29 14:56:14 +08:00
parent f5ce657d1d
commit 242af576a5
2 changed files with 13 additions and 2 deletions

View File

@ -845,7 +845,11 @@ object ChapterProvider {
titleTopSpacing = ReadBookConfig.titleTopSpacing.dpToPx()
titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dpToPx()
val bodyIndent = ReadBookConfig.paragraphIndent
indentCharWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint) / bodyIndent.length
var indentWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
indentWidth += contentPaint.letterSpacing * contentPaint.textSize
}
indentCharWidth = indentWidth / bodyIndent.length
titlePaintTextHeight = titlePaint.textHeight
contentPaintTextHeight = contentPaint.textHeight
titlePaintFontMetrics = titlePaint.fontMetrics

View File

@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page.provider
import android.graphics.Paint
import android.graphics.Rect
import android.os.Build
import android.text.Layout
import android.text.TextPaint
import java.util.WeakHashMap
@ -216,7 +217,13 @@ class ZhLayout(
return cnCharWidth / 2 - d
}
fun getDesiredWidth(sting: String, paint: TextPaint) = paint.measureText(sting)
fun getDesiredWidth(string: String, paint: TextPaint): Float {
var width = paint.measureText(string)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
width += paint.letterSpacing * paint.textSize
}
return width
}
override fun getLineCount(): Int {
return lineCount