mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -123,7 +123,7 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style),
|
||||
items = resources.getStringArray(R.array.indent).toList()
|
||||
) { _, index ->
|
||||
ReadBookConfig.paragraphIndent = " ".repeat(index)
|
||||
postEvent(EventBus.UP_CONFIG, arrayListOf(5))
|
||||
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5))
|
||||
}
|
||||
}
|
||||
tvPadding.setOnClickListener {
|
||||
|
||||
@@ -864,11 +864,15 @@ object ChapterProvider {
|
||||
titleTopSpacing = ReadBookConfig.titleTopSpacing.dpToPx()
|
||||
titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dpToPx()
|
||||
val bodyIndent = ReadBookConfig.paragraphIndent
|
||||
var indentWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||
indentWidth += contentPaint.letterSpacing * contentPaint.textSize
|
||||
indentCharWidth = if (bodyIndent.isNotEmpty()) {
|
||||
var indentWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||
indentWidth += contentPaint.letterSpacing * contentPaint.textSize
|
||||
}
|
||||
indentWidth / bodyIndent.length
|
||||
} else {
|
||||
0f
|
||||
}
|
||||
indentCharWidth = indentWidth / bodyIndent.length
|
||||
titlePaintTextHeight = titlePaint.textHeight
|
||||
contentPaintTextHeight = contentPaint.textHeight
|
||||
titlePaintFontMetrics = titlePaint.fontMetrics
|
||||
|
||||
@@ -73,6 +73,10 @@ class TextChapterLayout(
|
||||
private val stringBuilder = StringBuilder()
|
||||
|
||||
private val paragraphIndent = ReadBookConfig.paragraphIndent
|
||||
private val titleMode = ReadBookConfig.titleMode
|
||||
private val useZhLayout = ReadBookConfig.useZhLayout
|
||||
private val isMiddleTitle = ReadBookConfig.isMiddleTitle
|
||||
private val textFullJustify = ReadBookConfig.textFullJustify
|
||||
|
||||
private var pendingTextPage = TextPage()
|
||||
|
||||
@@ -196,7 +200,7 @@ class TextChapterLayout(
|
||||
val isSingleImageStyle = imageStyle.equals(Book.imgStyleSingle, true)
|
||||
val isTextImageStyle = imageStyle.equals(Book.imgStyleText, true)
|
||||
|
||||
if (ReadBookConfig.titleMode != 2 || bookChapter.isVolume || contents.isEmpty()) {
|
||||
if (titleMode != 2 || bookChapter.isVolume || contents.isEmpty()) {
|
||||
//标题非隐藏
|
||||
displayTitle.splitNotBlank("\n").forEach { text ->
|
||||
setTypeText(
|
||||
@@ -406,7 +410,7 @@ class TextChapterLayout(
|
||||
) {
|
||||
val widthsArray = allocateFloatArray(text.length)
|
||||
textPaint.getTextWidthsCompat(text, widthsArray)
|
||||
val layout = if (ReadBookConfig.useZhLayout) {
|
||||
val layout = if (useZhLayout) {
|
||||
val (words, widths) = measureTextSplit(text, widthsArray)
|
||||
val indentSize = if (isFirstLine) paragraphIndent.length else 0
|
||||
ZhLayout(text, textPaint, visibleWidth, words, widths, indentSize)
|
||||
@@ -471,7 +475,7 @@ class TextChapterLayout(
|
||||
//标题x轴居中
|
||||
val startX = if (
|
||||
isTitle &&
|
||||
(ReadBookConfig.isMiddleTitle || emptyContent || isVolumeTitle
|
||||
(isMiddleTitle || emptyContent || isVolumeTitle
|
||||
|| imageStyle?.uppercase() == Book.imgStyleSingle)
|
||||
) {
|
||||
(visibleWidth - desiredWidth) / 2
|
||||
@@ -487,7 +491,7 @@ class TextChapterLayout(
|
||||
else -> {
|
||||
if (
|
||||
isTitle &&
|
||||
(ReadBookConfig.isMiddleTitle || emptyContent || isVolumeTitle
|
||||
(isMiddleTitle || emptyContent || isVolumeTitle
|
||||
|| imageStyle?.uppercase() == Book.imgStyleSingle)
|
||||
) {
|
||||
//标题居中
|
||||
@@ -556,7 +560,7 @@ class TextChapterLayout(
|
||||
srcList: LinkedList<String>?
|
||||
) {
|
||||
var x = 0f
|
||||
if (!ReadBookConfig.textFullJustify) {
|
||||
if (!textFullJustify) {
|
||||
addCharsToLineNatural(
|
||||
book, absStartX, textLine, words,
|
||||
x, true, textWidths, srcList
|
||||
@@ -603,7 +607,7 @@ class TextChapterLayout(
|
||||
textWidths: List<Float>,
|
||||
srcList: LinkedList<String>?
|
||||
) {
|
||||
if (!ReadBookConfig.textFullJustify) {
|
||||
if (!textFullJustify) {
|
||||
addCharsToLineNatural(
|
||||
book, absStartX, textLine, words,
|
||||
startX, false, textWidths, srcList
|
||||
@@ -664,7 +668,7 @@ class TextChapterLayout(
|
||||
textWidths: List<Float>,
|
||||
srcList: LinkedList<String>?
|
||||
) {
|
||||
val indentLength = ReadBookConfig.paragraphIndent.length
|
||||
val indentLength = paragraphIndent.length
|
||||
var x = startX
|
||||
textLine.startX = absStartX + startX
|
||||
for (index in words.indices) {
|
||||
|
||||
Reference in New Issue
Block a user