mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
Some checks are pending
Test Build / prepare (push) Waiting to run
Test Build / build (app, release) (push) Blocked by required conditions
Test Build / build (app, releaseA) (push) Blocked by required conditions
Test Build / prerelease (push) Blocked by required conditions
Test Build / lanzou (push) Blocked by required conditions
Test Build / test_Branch (push) Blocked by required conditions
Test Build / telegram (push) Blocked by required conditions
Some checks are pending
Test Build / prepare (push) Waiting to run
Test Build / build (app, release) (push) Blocked by required conditions
Test Build / build (app, releaseA) (push) Blocked by required conditions
Test Build / prerelease (push) Blocked by required conditions
Test Build / lanzou (push) Blocked by required conditions
Test Build / test_Branch (push) Blocked by required conditions
Test Build / telegram (push) Blocked by required conditions
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package io.legado.app.ui.book.read.page.provider
|
||||
|
||||
import android.graphics.Paint
|
||||
import android.os.Build
|
||||
import android.text.Layout
|
||||
import android.text.StaticLayout
|
||||
import android.text.TextPaint
|
||||
@@ -25,6 +24,7 @@ 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.dpToPx
|
||||
import io.legado.app.utils.fastSum
|
||||
import io.legado.app.utils.getTextWidthsCompat
|
||||
import io.legado.app.utils.splitNotBlank
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -76,18 +76,21 @@ class TextChapterLayout(
|
||||
|
||||
private var pendingTextPage = TextPage()
|
||||
|
||||
private var isCompleted = false
|
||||
private val job: Coroutine<*>
|
||||
private val bookChapter inline get() = textChapter.chapter
|
||||
private val displayTitle inline get() = textChapter.title
|
||||
private val chaptersSize inline get() = textChapter.chaptersSize
|
||||
|
||||
private var durY = 0f
|
||||
private var absStartX = paddingLeft
|
||||
private var floatArray = FloatArray(128)
|
||||
|
||||
private var isCompleted = false
|
||||
private val job: Coroutine<*>
|
||||
|
||||
var exception: Throwable? = null
|
||||
|
||||
var channel = Channel<TextPage>(Int.MAX_VALUE)
|
||||
|
||||
var durY = 0f
|
||||
var absStartX = paddingLeft
|
||||
|
||||
init {
|
||||
job = Coroutine.async(
|
||||
@@ -401,16 +404,8 @@ class TextChapterLayout(
|
||||
isVolumeTitle: Boolean = false,
|
||||
srcList: LinkedList<String>? = null
|
||||
) {
|
||||
val widthsArray = FloatArray(text.length)
|
||||
textPaint.getTextWidths(text, widthsArray)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||
if (widthsArray.isNotEmpty()) {
|
||||
val letterSpacing = textPaint.letterSpacing * textPaint.textSize
|
||||
val letterSpacingHalf = letterSpacing * 0.5f
|
||||
widthsArray[0] += letterSpacingHalf
|
||||
widthsArray[widthsArray.lastIndex] += letterSpacingHalf
|
||||
}
|
||||
}
|
||||
val widthsArray = allocateFloatArray(text.length)
|
||||
textPaint.getTextWidthsCompat(text, widthsArray)
|
||||
val layout = if (ReadBookConfig.useZhLayout) {
|
||||
val (words, widths) = measureTextSplit(text, widthsArray)
|
||||
val indentSize = if (isFirstLine) paragraphIndent.length else 0
|
||||
@@ -786,6 +781,13 @@ class TextChapterLayout(
|
||||
}
|
||||
}
|
||||
|
||||
private fun allocateFloatArray(size: Int): FloatArray {
|
||||
if (size > floatArray.size) {
|
||||
floatArray = FloatArray(size)
|
||||
}
|
||||
return floatArray
|
||||
}
|
||||
|
||||
private fun measureTextSplit(
|
||||
text: String,
|
||||
widthsArray: FloatArray,
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
package io.legado.app.utils
|
||||
|
||||
import android.os.Build
|
||||
import android.text.TextPaint
|
||||
|
||||
val TextPaint.textHeight: Float
|
||||
get() = fontMetrics.run { descent - ascent + leading }
|
||||
|
||||
fun TextPaint.getTextWidthsCompat(text: String, widths: FloatArray) {
|
||||
getTextWidths(text, widths)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||
val letterSpacing = letterSpacing * textSize
|
||||
val letterSpacingHalf = letterSpacing * 0.5f
|
||||
widths[0] += letterSpacingHalf
|
||||
widths[text.lastIndex] += letterSpacingHalf
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user