文字下划虚线 #164
This commit is contained in:
@@ -382,6 +382,12 @@ object ReadBookConfig {
|
||||
config.underline = value
|
||||
}
|
||||
|
||||
var dottedLine: Boolean
|
||||
get() = config.dottedLine
|
||||
set(value) {
|
||||
config.dottedLine = value
|
||||
}
|
||||
|
||||
var paddingBottom: Int
|
||||
get() = config.paddingBottom
|
||||
set(value) {
|
||||
@@ -600,6 +606,7 @@ object ReadBookConfig {
|
||||
var titleSegFlag: String = "",//分段判断,碰到指定值时分段
|
||||
var paragraphIndent: String = " ",//段落缩进
|
||||
var underline: Boolean = false, //下划线
|
||||
var dottedLine: Boolean = false, //虚线
|
||||
var paddingBottom: Int = 6,
|
||||
var paddingLeft: Int = 16,
|
||||
var paddingRight: Int = 16,
|
||||
|
||||
@@ -131,6 +131,8 @@ class BgTextConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_read_bg
|
||||
binding.tvName.text = name.ifBlank { "文字" }
|
||||
binding.swDarkStatusIcon.isChecked = curStatusIconDark()
|
||||
binding.swUnderline.isChecked = underline
|
||||
binding.swDottedline.isChecked = dottedLine
|
||||
binding.swDottedline.isEnabled = underline
|
||||
binding.sbBgAlpha.value = ReadBookConfig.bgAlpha.toFloat()
|
||||
}
|
||||
|
||||
@@ -169,6 +171,15 @@ class BgTextConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_read_bg
|
||||
}
|
||||
binding.swUnderline.setOnCheckedChangeListener { _, isChecked ->
|
||||
underline = isChecked
|
||||
binding.swDottedline.isEnabled = isChecked
|
||||
if (!isChecked) {
|
||||
dottedLine = false
|
||||
binding.swDottedline.isChecked = false
|
||||
}
|
||||
postEvent(EventBus.UP_CONFIG, arrayListOf(6, 9, 11))
|
||||
}
|
||||
binding.swDottedline.setOnCheckedChangeListener { _, isChecked ->
|
||||
dottedLine = isChecked
|
||||
postEvent(EventBus.UP_CONFIG, arrayListOf(6, 9, 11))
|
||||
}
|
||||
binding.tvTextColor.setOnClickListener {
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page.entities
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.DashPathEffect
|
||||
import android.graphics.Paint.FontMetrics
|
||||
import android.os.Build
|
||||
import androidx.annotation.Keep
|
||||
@@ -170,7 +171,7 @@ data class TextLine(
|
||||
PaintPool.recycle(underlinePaint)
|
||||
}
|
||||
if (ReadBookConfig.underline && !isImage && ReadBook.book?.isImage != true) {
|
||||
drawUnderline(canvas)
|
||||
drawUnderline(canvas, ReadBookConfig.dottedLine)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,17 +214,24 @@ data class TextLine(
|
||||
/**
|
||||
* 绘制下划线
|
||||
*/
|
||||
private fun drawUnderline(canvas: Canvas) {
|
||||
private fun drawUnderline(canvas: Canvas, dottedLine: Boolean) {
|
||||
val lineY = height - 1.dpToPx()
|
||||
val paint = ChapterProvider.contentPaint
|
||||
val oldEffect = paint.pathEffect
|
||||
if (dottedLine) {
|
||||
paint.pathEffect = DashPathEffect(floatArrayOf(6f, 6f), 0f)
|
||||
}
|
||||
canvas.drawLine(
|
||||
lineStart + indentWidth,
|
||||
lineY,
|
||||
lineEnd,
|
||||
lineY,
|
||||
ChapterProvider.contentPaint
|
||||
paint
|
||||
)
|
||||
paint.pathEffect = oldEffect
|
||||
}
|
||||
|
||||
|
||||
fun checkFastDraw(): Boolean {
|
||||
if (!AppConfig.optimizeRender || exceed || !onlyTextColumn || textPage.isMsgPage) {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user