mirror of
https://github.com/gedoor/legado.git
synced 2024-07-04 23:36:56 +08:00
优化
This commit is contained in:
parent
4cdedae1fe
commit
2c97f43ed3
|
@ -1,5 +1,6 @@
|
|||
package io.legado.app.help.book
|
||||
|
||||
import android.os.Build
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.AppPattern.spaceRegex
|
||||
import io.legado.app.data.appDb
|
||||
|
@ -27,6 +28,7 @@ class ContentProcessor private constructor(
|
|||
|
||||
companion object {
|
||||
private val processors = hashMapOf<String, WeakReference<ContentProcessor>>()
|
||||
private val isAndroid8 = Build.VERSION.SDK_INT in 26..27
|
||||
|
||||
fun get(book: Book) = get(book.name, book.origin)
|
||||
|
||||
|
@ -182,6 +184,9 @@ class ContentProcessor private constructor(
|
|||
useReplace = useReplace && book.getUseReplaceRule()
|
||||
) + "\n" + mContent
|
||||
}
|
||||
if (isAndroid8) {
|
||||
mContent = mContent.replace('\u00A0', ' ')
|
||||
}
|
||||
val contents = arrayListOf<String>()
|
||||
mContent.split("\n").forEach { str ->
|
||||
val paragraph = str.trim {
|
||||
|
|
|
@ -215,7 +215,9 @@ data class TextLine(
|
|||
if (exceed || !onlyTextColumn || textPage.isMsgPage) {
|
||||
return false
|
||||
}
|
||||
if (!atLeastApi29 && wordSpacing != 0f) {
|
||||
if (!atLeastApi26 && wordSpacing != 0f) {
|
||||
return false
|
||||
} else if (!wordSpacingWorking) {
|
||||
return false
|
||||
}
|
||||
return searchResultColumnCount == 0
|
||||
|
@ -234,9 +236,20 @@ data class TextLine(
|
|||
canvasRecorder.recycle()
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
companion object {
|
||||
val emptyTextLine = TextLine()
|
||||
private val atLeastApi29 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
||||
private val atLeastApi26 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||
private val wordSpacingWorking by lazy {
|
||||
// issue 3785
|
||||
val paint = PaintPool.obtain()
|
||||
val text = "一二 三"
|
||||
val width1 = paint.measureText(text)
|
||||
paint.wordSpacing = 10f
|
||||
val width2 = paint.measureText(text)
|
||||
PaintPool.recycle(paint)
|
||||
width2 - width1 == 10f
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import io.legado.app.ui.book.read.page.entities.TextPage
|
|||
import io.legado.app.ui.book.read.page.entities.column.ImageColumn
|
||||
import io.legado.app.ui.book.read.page.entities.column.ReviewColumn
|
||||
import io.legado.app.ui.book.read.page.entities.column.TextColumn
|
||||
import io.legado.app.utils.LogUtils
|
||||
import io.legado.app.utils.RealPathUtil
|
||||
import io.legado.app.utils.dpToPx
|
||||
import io.legado.app.utils.fastSum
|
||||
|
@ -817,9 +816,6 @@ object ChapterProvider {
|
|||
titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dpToPx()
|
||||
val bodyIndent = ReadBookConfig.paragraphIndent
|
||||
indentCharWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint) / bodyIndent.length
|
||||
LogUtils.d("ChapterProvider") {
|
||||
"bodyIndentLength:${bodyIndent.length} indentCharWidth:$indentCharWidth"
|
||||
}
|
||||
titlePaintTextHeight = titlePaint.textHeight
|
||||
contentPaintTextHeight = contentPaint.textHeight
|
||||
titlePaintFontMetrics = titlePaint.fontMetrics
|
||||
|
@ -889,17 +885,9 @@ object ChapterProvider {
|
|||
//正文
|
||||
val cPaint = TextPaint()
|
||||
cPaint.color = ReadBookConfig.textColor
|
||||
cPaint.letterSpacing = ReadBookConfig.letterSpacing.also {
|
||||
LogUtils.d("ChapterProvider") {
|
||||
"ReadBookConfig.letterSpacing:$it"
|
||||
}
|
||||
}
|
||||
cPaint.letterSpacing = ReadBookConfig.letterSpacing
|
||||
cPaint.typeface = textFont
|
||||
cPaint.textSize = ReadBookConfig.textSize.toFloat().spToPx().also {
|
||||
LogUtils.d("ChapterProvider") {
|
||||
"ReadBookConfig.textSize:$it"
|
||||
}
|
||||
}
|
||||
cPaint.textSize = ReadBookConfig.textSize.toFloat().spToPx()
|
||||
cPaint.isAntiAlias = true
|
||||
cPaint.isLinearText = true
|
||||
return Pair(tPaint, cPaint)
|
||||
|
|
|
@ -21,7 +21,6 @@ import io.legado.app.ui.book.read.page.entities.TextPage
|
|||
import io.legado.app.ui.book.read.page.entities.column.ImageColumn
|
||||
import io.legado.app.ui.book.read.page.entities.column.ReviewColumn
|
||||
import io.legado.app.ui.book.read.page.entities.column.TextColumn
|
||||
import io.legado.app.utils.LogUtils
|
||||
import io.legado.app.utils.dpToPx
|
||||
import io.legado.app.utils.fastSum
|
||||
import io.legado.app.utils.splitNotBlank
|
||||
|
@ -30,8 +29,6 @@ import kotlinx.coroutines.CoroutineScope
|
|||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import java.util.LinkedList
|
||||
import java.util.Locale
|
||||
import kotlin.coroutines.coroutineContext
|
||||
|
@ -84,19 +81,13 @@ class TextChapterLayout(
|
|||
|
||||
var channel = Channel<TextPage>(Int.MAX_VALUE)
|
||||
|
||||
companion object {
|
||||
val lock = Mutex()
|
||||
}
|
||||
|
||||
init {
|
||||
job = Coroutine.async(scope) {
|
||||
launch {
|
||||
val bookSource = book.getBookSource() ?: return@launch
|
||||
BookHelp.saveImages(bookSource, book, bookChapter, bookContent.toString())
|
||||
}
|
||||
lock.withLock {
|
||||
getTextChapter(book, bookChapter, displayTitle, bookContent)
|
||||
}
|
||||
getTextChapter(book, bookChapter, displayTitle, bookContent)
|
||||
}.onError {
|
||||
exception = it
|
||||
onException(it)
|
||||
|
@ -659,20 +650,7 @@ class TextChapterLayout(
|
|||
val gapCount: Int = words.lastIndex
|
||||
val d = residualWidth / gapCount
|
||||
textLine.extraLetterSpacingOffsetX = -d / 2
|
||||
val textSize = textPaint.textSize
|
||||
textLine.extraLetterSpacing = d / textSize
|
||||
LogUtils.d("TextChapterLayout") {
|
||||
"words:${words.joinToString("")}"
|
||||
}
|
||||
LogUtils.d("TextChapterLayout") {
|
||||
"textWidths(${textWidths.fastSum()}):$textWidths"
|
||||
}
|
||||
LogUtils.d("TextChapterLayout") {
|
||||
"textSize:$textSize desiredWidth:$desiredWidth residualWidth:$residualWidth " +
|
||||
"gapCount:$gapCount d:$d " +
|
||||
"extraLetterSpacingOffsetX:${textLine.extraLetterSpacingOffsetX} " +
|
||||
"extraLetterSpacing:${textLine.extraLetterSpacing}"
|
||||
}
|
||||
textLine.extraLetterSpacing = d / textPaint.textSize
|
||||
var x = startX
|
||||
for (index in words.indices) {
|
||||
val char = words[index]
|
||||
|
|
Loading…
Reference in New Issue
Block a user