mirror of
https://github.com/gedoor/legado.git
synced 2024-07-17 00:58:29 +08:00
优化
This commit is contained in:
parent
9181a41458
commit
0ed31ae56c
@ -132,8 +132,7 @@ object BookContent {
|
|||||||
//全文替换
|
//全文替换
|
||||||
val replaceRegex = contentRule.replaceRegex
|
val replaceRegex = contentRule.replaceRegex
|
||||||
if (!replaceRegex.isNullOrEmpty()) {
|
if (!replaceRegex.isNullOrEmpty()) {
|
||||||
contentStr = contentStr.split(AppPattern.LFRegex)
|
contentStr = contentStr.split(AppPattern.LFRegex).joinToString("\n") { it.trim() }
|
||||||
.joinToString("\n") { it.trim { c -> c <= ' ' || c == ' ' } }
|
|
||||||
contentStr = analyzeRule.getString(replaceRegex, contentStr)
|
contentStr = analyzeRule.getString(replaceRegex, contentStr)
|
||||||
contentStr = contentStr.split(AppPattern.LFRegex).joinToString("\n") { " $it" }
|
contentStr = contentStr.split(AppPattern.LFRegex).joinToString("\n") { " $it" }
|
||||||
}
|
}
|
||||||
|
@ -809,11 +809,8 @@ object ChapterProvider {
|
|||||||
paragraphSpacing = ReadBookConfig.paragraphSpacing
|
paragraphSpacing = ReadBookConfig.paragraphSpacing
|
||||||
titleTopSpacing = ReadBookConfig.titleTopSpacing.dpToPx()
|
titleTopSpacing = ReadBookConfig.titleTopSpacing.dpToPx()
|
||||||
titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dpToPx()
|
titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dpToPx()
|
||||||
var bodyIndent = ReadBookConfig.paragraphIndent
|
val bodyIndent = ReadBookConfig.paragraphIndent
|
||||||
val indentLength = bodyIndent.length
|
indentCharWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint) / bodyIndent.length
|
||||||
// 有些字体的中文空格宽度不对
|
|
||||||
bodyIndent = "一".repeat(indentLength)
|
|
||||||
indentCharWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint) / indentLength
|
|
||||||
titlePaintTextHeight = titlePaint.textHeight
|
titlePaintTextHeight = titlePaint.textHeight
|
||||||
contentPaintTextHeight = contentPaint.textHeight
|
contentPaintTextHeight = contentPaint.textHeight
|
||||||
titlePaintFontMetrics = titlePaint.fontMetrics
|
titlePaintFontMetrics = titlePaint.fontMetrics
|
||||||
|
@ -431,6 +431,7 @@ class TextChapterLayout(
|
|||||||
|
|
||||||
else -> y
|
else -> y
|
||||||
}
|
}
|
||||||
|
val (strList, widthList) = measureTextSplit(text, textPaint)
|
||||||
for (lineIndex in 0 until layout.lineCount) {
|
for (lineIndex in 0 until layout.lineCount) {
|
||||||
val textLine = TextLine(isTitle = isTitle)
|
val textLine = TextLine(isTitle = isTitle)
|
||||||
if (durY + textHeight > visibleHeight) {
|
if (durY + textHeight > visibleHeight) {
|
||||||
@ -461,12 +462,13 @@ class TextChapterLayout(
|
|||||||
val lineStart = layout.getLineStart(lineIndex)
|
val lineStart = layout.getLineStart(lineIndex)
|
||||||
val lineEnd = layout.getLineEnd(lineIndex)
|
val lineEnd = layout.getLineEnd(lineIndex)
|
||||||
val lineText = text.substring(lineStart, lineEnd)
|
val lineText = text.substring(lineStart, lineEnd)
|
||||||
val (words, widths) = measureTextSplit(lineText, textPaint)
|
val words = strList.subList(lineStart, lineEnd)
|
||||||
|
val widths = widthList.subList(lineStart, lineEnd)
|
||||||
val desiredWidth = widths.fastSum()
|
val desiredWidth = widths.fastSum()
|
||||||
textLine.text = lineText
|
textLine.text = lineText
|
||||||
when {
|
when {
|
||||||
lineIndex == 0 && layout.lineCount > 1 && !isTitle -> {
|
lineIndex == 0 && layout.lineCount > 1 && !isTitle -> {
|
||||||
//第一行 非标题
|
//多行的第一行 非标题
|
||||||
addCharsToLineFirst(
|
addCharsToLineFirst(
|
||||||
book, absStartX, textLine, words, textPaint,
|
book, absStartX, textLine, words, textPaint,
|
||||||
desiredWidth, widths, srcList
|
desiredWidth, widths, srcList
|
||||||
@ -474,7 +476,7 @@ class TextChapterLayout(
|
|||||||
}
|
}
|
||||||
|
|
||||||
lineIndex == layout.lineCount - 1 -> {
|
lineIndex == layout.lineCount - 1 -> {
|
||||||
//最后一行
|
//最后一行、单行
|
||||||
//标题x轴居中
|
//标题x轴居中
|
||||||
val startX = if (
|
val startX = if (
|
||||||
isTitle &&
|
isTitle &&
|
||||||
|
Loading…
Reference in New Issue
Block a user