Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Dec 29, 2024
1 parent f5ce657 commit 242af57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 242af57

Please sign in to comment.