From 242af576a5d59d86761831273f702ca95cff6278 Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Sun, 29 Dec 2024 14:56:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/provider/ChapterProvider.kt | 6 +++++- .../io/legado/app/ui/book/read/page/provider/ZhLayout.kt | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) 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 b00556694..7d4b9aba8 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 @@ -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 diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt index 5749dd1ef..a6edcc187 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt @@ -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