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