diff --git a/app/src/main/java/io/legato/kazusa/ui/book/read/config/FontSelectDialog.kt b/app/src/main/java/io/legato/kazusa/ui/book/read/config/FontSelectDialog.kt index e5dabdffa..5ae586e02 100644 --- a/app/src/main/java/io/legato/kazusa/ui/book/read/config/FontSelectDialog.kt +++ b/app/src/main/java/io/legato/kazusa/ui/book/read/config/FontSelectDialog.kt @@ -137,7 +137,7 @@ class FontSelectDialog : BaseBottomSheetDialogFragment(R.layout.dialog_font_sele } val weightOptions = context?.resources?.getStringArray(R.array.text_font_weight) - val weightValues = listOf(500, 700, 300) + val weightValues = listOf(2, 1, 0) val initialIndex = weightValues.indexOf(ReadBookConfig.textBold) binding.textFontWeightConverter.text = weightOptions?.getOrNull(initialIndex) ?: "自定义" diff --git a/app/src/main/java/io/legato/kazusa/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legato/kazusa/ui/book/read/page/provider/ChapterProvider.kt index a5265c37a..93409f7fa 100644 --- a/app/src/main/java/io/legato/kazusa/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legato/kazusa/ui/book/read/page/provider/ChapterProvider.kt @@ -912,19 +912,33 @@ object ChapterProvider { } private fun getPaints(typeface: Typeface?): Pair { - // 字体统一处理 - val (titleFont, textFont) = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - Pair( - Typeface.create(typeface, ReadBookConfig.textBold, false), - Typeface.create(typeface, ReadBookConfig.textBold, false) - ) - } else { - val tf = when (ReadBookConfig.textBold) { - in 700..900 -> Typeface.DEFAULT_BOLD - in 300..499 -> Typeface.DEFAULT - else -> Typeface.DEFAULT + val bold = Typeface.create(typeface, Typeface.BOLD) + val normal = Typeface.create(typeface, Typeface.NORMAL) + val (titleFont, textFont) = when (ReadBookConfig.textBold) { + 1 -> { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) + Pair(Typeface.create(typeface, 900, false), bold) + else + Pair(bold, bold) } - Pair(tf, tf) + + 2 -> { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) + Pair(normal, Typeface.create(typeface, 300, false)) + else + Pair(normal, normal) + } + + in 100..900 -> { + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + Pair(normal, Typeface.create(typeface, ReadBookConfig.textBold, false)) + } else { + Pair(normal, normal) + } + } + + else -> Pair(bold, normal) } //标题 @@ -932,7 +946,8 @@ object ChapterProvider { tPaint.color = ReadBookConfig.textColor tPaint.letterSpacing = ReadBookConfig.letterSpacing tPaint.typeface = titleFont - tPaint.setFontVariationSettings("'wght' ${ReadBookConfig.textBold}") + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && ReadBookConfig.textBold in 100..900) + tPaint.setFontVariationSettings("'wght' ${ReadBookConfig.textBold}") tPaint.textSize = with(ReadBookConfig) { textSize + titleSize }.toFloat().spToPx() tPaint.isAntiAlias = true if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q && AppConfig.optimizeRender) { @@ -943,12 +958,14 @@ object ChapterProvider { cPaint.color = ReadBookConfig.textColor cPaint.letterSpacing = ReadBookConfig.letterSpacing cPaint.typeface = textFont - cPaint.setFontVariationSettings("'wght' ${ReadBookConfig.textBold}") + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && ReadBookConfig.textBold in 100..900) + cPaint.setFontVariationSettings("'wght' ${ReadBookConfig.textBold}") cPaint.textSize = ReadBookConfig.textSize.toFloat().spToPx() cPaint.isAntiAlias = true if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q && AppConfig.optimizeRender) { cPaint.isLinearText = true } + return Pair(tPaint, cPaint) } diff --git a/app/src/main/res/layout/dialog_font_select.xml b/app/src/main/res/layout/dialog_font_select.xml index 9917c8e31..98df2f9ab 100644 --- a/app/src/main/res/layout/dialog_font_select.xml +++ b/app/src/main/res/layout/dialog_font_select.xml @@ -30,8 +30,8 @@ style="@style/Widget.Material3Expressive.Button.TonalButton" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginStart="8dp" - android:minWidth="0dp" + android:layout_marginStart="12dp" + android:minWidth="80dp" android:textSize="12sp" /> + app:trackHeight="24dp" />