优化
This commit is contained in:
@@ -5,7 +5,6 @@ import android.graphics.Canvas
|
|||||||
import android.graphics.Paint.FontMetrics
|
import android.graphics.Paint.FontMetrics
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
import androidx.core.graphics.withTranslation
|
|
||||||
import io.legado.app.help.PaintPool
|
import io.legado.app.help.PaintPool
|
||||||
import io.legado.app.help.book.isImage
|
import io.legado.app.help.book.isImage
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
@@ -183,19 +182,16 @@ data class TextLine(
|
|||||||
}
|
}
|
||||||
val paint = PaintPool.obtain()
|
val paint = PaintPool.obtain()
|
||||||
paint.set(textPaint)
|
paint.set(textPaint)
|
||||||
|
val letterSpacing = paint.letterSpacing * paint.textSize
|
||||||
|
val letterSpacingHalf = letterSpacing * 0.5f
|
||||||
if (extraLetterSpacing != 0f) {
|
if (extraLetterSpacing != 0f) {
|
||||||
paint.letterSpacing += extraLetterSpacing
|
paint.letterSpacing += extraLetterSpacing
|
||||||
}
|
}
|
||||||
if (wordSpacing != 0f) {
|
if (wordSpacing != 0f) {
|
||||||
paint.wordSpacing = wordSpacing
|
paint.wordSpacing = wordSpacing
|
||||||
}
|
}
|
||||||
if (extraLetterSpacingOffsetX != 0f) {
|
val offsetX = if (atLeastApi35) letterSpacingHalf else extraLetterSpacingOffsetX
|
||||||
canvas.withTranslation(extraLetterSpacingOffsetX) {
|
canvas.drawText(text, indentSize, text.length, startX + offsetX, lineBase - lineTop, paint)
|
||||||
canvas.drawText(text, indentSize, text.length, startX, lineBase - lineTop, paint)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
canvas.drawText(text, indentSize, text.length, startX, lineBase - lineTop, paint)
|
|
||||||
}
|
|
||||||
PaintPool.recycle(paint)
|
PaintPool.recycle(paint)
|
||||||
for (i in columns.indices) {
|
for (i in columns.indices) {
|
||||||
val column = columns[i] as TextColumn
|
val column = columns[i] as TextColumn
|
||||||
@@ -246,6 +242,7 @@ data class TextLine(
|
|||||||
companion object {
|
companion object {
|
||||||
val emptyTextLine = TextLine()
|
val emptyTextLine = TextLine()
|
||||||
private val atLeastApi26 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
private val atLeastApi26 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||||
|
private val atLeastApi35 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM
|
||||||
private val wordSpacingWorking by lazy {
|
private val wordSpacingWorking by lazy {
|
||||||
// issue 3785 3846
|
// issue 3785 3846
|
||||||
val paint = PaintPool.obtain()
|
val paint = PaintPool.obtain()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page.entities
|
|||||||
|
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
|
import android.os.Build
|
||||||
import android.text.Layout
|
import android.text.Layout
|
||||||
import android.text.StaticLayout
|
import android.text.StaticLayout
|
||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
@@ -142,10 +143,12 @@ data class TextPage(
|
|||||||
if (isMsgPage && ChapterProvider.viewWidth > 0) {
|
if (isMsgPage && ChapterProvider.viewWidth > 0) {
|
||||||
textLines.clear()
|
textLines.clear()
|
||||||
val visibleWidth = ChapterProvider.visibleRight - ChapterProvider.paddingLeft
|
val visibleWidth = ChapterProvider.visibleRight - ChapterProvider.paddingLeft
|
||||||
|
val paint = ChapterProvider.contentPaint
|
||||||
val layout = StaticLayout(
|
val layout = StaticLayout(
|
||||||
text, ChapterProvider.contentPaint, visibleWidth,
|
text, paint, visibleWidth,
|
||||||
Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false
|
Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false
|
||||||
)
|
)
|
||||||
|
val letterSpacing = paint.letterSpacing * paint.textSize
|
||||||
var y = (ChapterProvider.visibleHeight - layout.height) / 2f
|
var y = (ChapterProvider.visibleHeight - layout.height) / 2f
|
||||||
if (y < 0) y = 0f
|
if (y < 0) y = 0f
|
||||||
for (lineIndex in 0 until layout.lineCount) {
|
for (lineIndex in 0 until layout.lineCount) {
|
||||||
@@ -161,7 +164,10 @@ data class TextPage(
|
|||||||
text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex))
|
text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex))
|
||||||
for (i in textLine.text.indices) {
|
for (i in textLine.text.indices) {
|
||||||
val char = textLine.text[i].toString()
|
val char = textLine.text[i].toString()
|
||||||
val cw = StaticLayout.getDesiredWidth(char, ChapterProvider.contentPaint)
|
var cw = StaticLayout.getDesiredWidth(char, paint)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||||
|
cw += letterSpacing
|
||||||
|
}
|
||||||
val x1 = x + cw
|
val x1 = x + cw
|
||||||
textLine.addColumn(
|
textLine.addColumn(
|
||||||
TextColumn(start = x, end = x1, char)
|
TextColumn(start = x, end = x1, char)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package io.legado.app.ui.book.read.page.entities.column
|
package io.legado.app.ui.book.read.page.entities.column
|
||||||
|
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
|
import android.os.Build
|
||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
import io.legado.app.help.config.ReadBookConfig
|
import io.legado.app.help.config.ReadBookConfig
|
||||||
import io.legado.app.lib.theme.ThemeStore
|
import io.legado.app.lib.theme.ThemeStore
|
||||||
@@ -55,7 +56,14 @@ data class TextColumn(
|
|||||||
if (textPaint.color != textColor) {
|
if (textPaint.color != textColor) {
|
||||||
textPaint.color = textColor
|
textPaint.color = textColor
|
||||||
}
|
}
|
||||||
canvas.drawText(charData, start, textLine.lineBase - textLine.lineTop, textPaint)
|
val y = textLine.lineBase - textLine.lineTop
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||||
|
val letterSpacing = textPaint.letterSpacing * textPaint.textSize
|
||||||
|
val letterSpacingHalf = letterSpacing * 0.5f
|
||||||
|
canvas.drawText(charData, start + letterSpacingHalf, y, textPaint)
|
||||||
|
} else {
|
||||||
|
canvas.drawText(charData, start, y, textPaint)
|
||||||
|
}
|
||||||
if (selected) {
|
if (selected) {
|
||||||
canvas.drawRect(start, 0f, end, textLine.height, view.selectedPaint)
|
canvas.drawRect(start, 0f, end, textLine.height, view.selectedPaint)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package io.legado.app.ui.book.read.page.provider
|
package io.legado.app.ui.book.read.page.provider
|
||||||
|
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
|
import android.os.Build
|
||||||
import android.text.Layout
|
import android.text.Layout
|
||||||
import android.text.StaticLayout
|
import android.text.StaticLayout
|
||||||
import android.text.TextPaint
|
import android.text.TextPaint
|
||||||
@@ -416,6 +417,14 @@ class TextChapterLayout(
|
|||||||
var absStartX = x
|
var absStartX = x
|
||||||
val widthsArray = FloatArray(text.length)
|
val widthsArray = FloatArray(text.length)
|
||||||
textPaint.getTextWidths(text, widthsArray)
|
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 layout = if (ReadBookConfig.useZhLayout) {
|
val layout = if (ReadBookConfig.useZhLayout) {
|
||||||
val (words, widths) = measureTextSplit(text, widthsArray)
|
val (words, widths) = measureTextSplit(text, widthsArray)
|
||||||
ZhLayout(text, textPaint, visibleWidth, words, widths)
|
ZhLayout(text, textPaint, visibleWidth, words, widths)
|
||||||
|
|||||||
Reference in New Issue
Block a user