Просмотр исходного кода

现在当使用按钮切换字重时,会和官方逻辑相同

HapeLee 1 год назад
Родитель
Сommit
7b615cd186

+ 1 - 1
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) ?: "自定义"

+ 31 - 14
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<TextPaint, TextPaint> {
-        // 字体统一处理
-        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)
+            }
+
+            2 -> {
+                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
+                    Pair(normal, Typeface.create(typeface, 300, false))
+                else
+                    Pair(normal, normal)
             }
-            Pair(tf, tf)
+
+            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)
     }
 

+ 4 - 4
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" />
 
         <com.google.android.material.slider.Slider
@@ -188,9 +188,9 @@
         android:valueFrom="0"
         android:valueTo="20"
         app:isBottomBackground="true"
-        app:thumbHeight="28dp"
+        app:thumbHeight="24dp"
         app:title="@string/paragraph_size"
-        app:trackHeight="28dp" />
+        app:trackHeight="24dp" />
 
     <androidx.recyclerview.widget.RecyclerView
         android:id="@+id/recycler_view"