标题粗体独立控制 #186
This commit is contained in:
@@ -219,6 +219,12 @@ object ReadBookConfig {
|
||||
config.textBold = value
|
||||
}
|
||||
|
||||
var titleBold: Int
|
||||
get() = config.titleBold
|
||||
set(value) {
|
||||
config.titleBold = value
|
||||
}
|
||||
|
||||
var textItalic: Boolean
|
||||
get() = config.textItalic
|
||||
set(value) {
|
||||
@@ -490,6 +496,7 @@ object ReadBookConfig {
|
||||
var titleSize: Int = 0,
|
||||
var titleTopSpacing: Int = 0,
|
||||
var titleBottomSpacing: Int = 0,
|
||||
var titleBold: Int = 500,
|
||||
var paragraphIndent: String = " ",//段落缩进
|
||||
var underline: Boolean = false, //下划线
|
||||
var paddingBottom: Int = 6,
|
||||
|
||||
@@ -10,6 +10,7 @@ import io.legado.app.constant.EventBus
|
||||
import io.legado.app.databinding.DialogTipConfigBinding
|
||||
import io.legado.app.help.config.ReadBookConfig
|
||||
import io.legado.app.help.config.ReadTipConfig
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.lib.dialogs.selector
|
||||
import io.legado.app.utils.hexString
|
||||
import io.legado.app.utils.observeEvent
|
||||
@@ -47,6 +48,35 @@ class TipConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_tip_config
|
||||
2 -> binding.rgTitleMode.check(R.id.rb_title_mode3)
|
||||
else -> { }
|
||||
}
|
||||
val weightOptions = context?.resources?.getStringArray(R.array.text_font_weight)
|
||||
val weightValues = listOf(2, 1, 0)
|
||||
val initialIndex = weightValues.indexOf(ReadBookConfig.titleBold)
|
||||
binding.textFontWeightConverter.text = weightOptions?.getOrNull(initialIndex) ?: "自定义"
|
||||
binding.textFontWeightConverter.setOnClickListener {
|
||||
context?.alert(titleResource = R.string.text_font_weight_converter) {
|
||||
weightOptions?.let { options ->
|
||||
items(options.toList()) { _, i ->
|
||||
ReadBookConfig.titleBold = weightValues[i]
|
||||
binding.sliderFontWeight.value =
|
||||
ReadBookConfig.titleBold.toFloat().coerceAtLeast(100f)
|
||||
binding.textFontWeightConverter.text = options.getOrNull(i) ?: ""
|
||||
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 9, 6))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
binding.sliderFontWeight.apply {
|
||||
valueFrom = 100f
|
||||
valueTo = 900f
|
||||
stepSize = 1f
|
||||
value = ReadBookConfig.titleBold.toFloat().coerceAtLeast(100f)
|
||||
addOnChangeListener { _, newValue, _ ->
|
||||
binding.textFontWeightConverter.text = "自定义"
|
||||
ReadBookConfig.titleBold = newValue.toInt()
|
||||
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 9, 6))
|
||||
}
|
||||
}
|
||||
|
||||
binding.dsbTitleSize.progress = ReadBookConfig.titleSize
|
||||
binding.dsbTitleTop.progress = ReadBookConfig.titleTopSpacing
|
||||
|
||||
@@ -915,40 +915,52 @@ object ChapterProvider {
|
||||
private fun getPaints(typeface: Typeface?): Pair<TextPaint, TextPaint> {
|
||||
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)
|
||||
}
|
||||
val titleFont = when (ReadBookConfig.titleBold) {
|
||||
1 -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||
Typeface.create(typeface, 900, false)
|
||||
else
|
||||
bold
|
||||
|
||||
2 -> {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||
Pair(normal, Typeface.create(typeface, 300, false))
|
||||
else
|
||||
Pair(normal, normal)
|
||||
}
|
||||
2 -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||
Typeface.create(typeface, 300, false)
|
||||
else
|
||||
normal
|
||||
|
||||
in 100..900 -> {
|
||||
in 100..900 -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||
Typeface.create(typeface, ReadBookConfig.titleBold, false)
|
||||
else
|
||||
normal
|
||||
|
||||
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)
|
||||
else -> bold
|
||||
}
|
||||
|
||||
val textFont = when (ReadBookConfig.textBold) {
|
||||
1 -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||
Typeface.create(typeface, 900, false)
|
||||
else
|
||||
bold
|
||||
|
||||
2 -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||
Typeface.create(typeface, 300, false)
|
||||
else
|
||||
normal
|
||||
|
||||
in 100..900 -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||
Typeface.create(typeface, ReadBookConfig.textBold, false)
|
||||
else
|
||||
normal
|
||||
|
||||
else -> bold
|
||||
}
|
||||
|
||||
|
||||
//标题
|
||||
val tPaint = TextPaint()
|
||||
tPaint.color = ReadBookConfig.textColor
|
||||
tPaint.letterSpacing = ReadBookConfig.letterSpacing
|
||||
tPaint.typeface = titleFont
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && ReadBookConfig.textBold in 100..900)
|
||||
tPaint.setFontVariationSettings("'wght' ${ReadBookConfig.textBold}")
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && ReadBookConfig.titleBold in 100..900)
|
||||
tPaint.setFontVariationSettings("'wght' ${ReadBookConfig.titleBold}")
|
||||
tPaint.textSize = with(ReadBookConfig) { textSize + titleSize }.toFloat().spToPx()
|
||||
tPaint.isAntiAlias = true
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q && AppConfig.optimizeRender) {
|
||||
|
||||
Reference in New Issue
Block a user