diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index e2756096a..cd8c5c0e8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -10,7 +10,10 @@ import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookChapter import io.legado.app.help.BookHelp import io.legado.app.help.ReadBookConfig -import io.legado.app.ui.book.read.page.entities.* +import io.legado.app.ui.book.read.page.entities.TextChapter +import io.legado.app.ui.book.read.page.entities.TextChar +import io.legado.app.ui.book.read.page.entities.TextLine +import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.utils.dp import io.legado.app.utils.getPrefString import io.legado.app.utils.removePref @@ -131,10 +134,11 @@ object ChapterProvider { textPages.add(TextPage()) textPages.last().textLines.add(textLine) } - textLine.lineBottom = (paddingTop + durY - - (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex))).toFloat() textLine.lineTop = (paddingTop + durY - (layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex))).toFloat() + textLine.lineBase = (paddingTop + durY - + (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex))).toFloat() + textLine.lineBottom = textLine.lineBase + titlePaint.fontMetrics.descent val words = title.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) @@ -150,8 +154,8 @@ object ChapterProvider { val x1 = if (i != words.lastIndex) (x + cw + d) else (x + cw) val textChar = TextChar( charData = char, - leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), - rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop) + start = paddingLeft + x, + end = paddingLeft + x1 ) textLine.textChars.add(textChar) x = x1 @@ -169,14 +173,13 @@ object ChapterProvider { val x1 = x + cw val textChar = TextChar( charData = char, - leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), - rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop) + start = paddingLeft + x, + end = paddingLeft + x1 ) textLine.textChars.add(textChar) x = x1 } } - textLine.lineBottom = textLine.lineBottom + titlePaint.fontMetrics.descent } durY += paragraphSpacing return durY @@ -214,10 +217,11 @@ object ChapterProvider { textPages.add(TextPage()) textPages.last().textLines.add(textLine) } - textLine.lineBottom = (paddingTop + durY - - (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex))).toFloat() textLine.lineTop = (paddingTop + durY - (layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex))).toFloat() + textLine.lineBase = (paddingTop + durY - + (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex))).toFloat() + textLine.lineBottom = textLine.lineBase + contentPaint.fontMetrics.descent var words = text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) @@ -231,8 +235,8 @@ object ChapterProvider { val x1 = x + icw val textChar = TextChar( charData = bodyIndent[i].toString(), - leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), - rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop) + start = paddingLeft + x, + end = paddingLeft + x1 ) textLine.textChars.add(textChar) x = x1 @@ -246,8 +250,8 @@ object ChapterProvider { val x1 = if (i != words.lastIndex) x + cw + d else x + cw val textChar1 = TextChar( charData = char, - leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), - rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop) + start = paddingLeft + x, + end = paddingLeft + x1 ) textLine.textChars.add(textChar1) x = x1 @@ -263,8 +267,8 @@ object ChapterProvider { val x1 = x + cw val textChar = TextChar( charData = char, - leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), - rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop) + start = paddingLeft + x, + end = paddingLeft + x1 ) textLine.textChars.add(textChar) x = x1 @@ -280,14 +284,13 @@ object ChapterProvider { val x1 = if (i != words.lastIndex) x + cw + d else x + cw val textChar = TextChar( charData = char, - leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), - rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop) + start = paddingLeft + x, + end = paddingLeft + x1 ) textLine.textChars.add(textChar) x = x1 } } - textLine.lineBottom = textLine.lineBottom + contentPaint.fontMetrics.descent } durY += paragraphSpacing return durY diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index ff066f5b4..882c47d2d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -95,17 +95,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at ReadBookConfig.durConfig.textColor() } textLine.textChars.forEach { - canvas.drawText( - it.charData, - it.leftBottomPosition.x, - it.leftBottomPosition.y, - textPaint - ) + canvas.drawText(it.charData, it.start, textLine.lineBase, textPaint) if (it.selected) { canvas.drawRect( - it.leftBottomPosition.x, + it.start, textLine.lineTop, - it.rightTopPosition.x, + it.end, textLine.lineBottom, selectedPaint ) @@ -158,21 +153,15 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop && y < textLine.lineBottom) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { - if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { + if (x > textChar.start && x < textChar.end) { textChar.selected = true invalidate() selectLineStart = lineIndex selectCharStart = charIndex selectLineEnd = lineIndex selectCharEnd = charIndex - upSelectedStart( - textChar.leftBottomPosition.x, - textChar.leftBottomPosition.y - ) - upSelectedEnd( - textChar.rightTopPosition.x, - textChar.leftBottomPosition.y - ) + upSelectedStart(textChar.start, textLine.lineBottom) + upSelectedEnd(textChar.end, textLine.lineBottom) return true } } @@ -186,14 +175,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop && y < textLine.lineBottom) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { - if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { + if (x > textChar.start && x < textChar.end) { if (selectLineStart != lineIndex || selectCharStart != charIndex) { selectLineStart = lineIndex selectCharStart = charIndex - upSelectedStart( - textChar.leftBottomPosition.x, - textChar.leftBottomPosition.y - ) + upSelectedStart(textChar.start, textLine.lineBottom) upSelectChars(textPage) } break @@ -208,13 +194,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop && y < textLine.lineBottom) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { - if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { + if (x > textChar.start && x < textChar.end) { if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { selectLineEnd = lineIndex selectCharEnd = charIndex upSelectedEnd( - textChar.rightTopPosition.x, - textChar.leftBottomPosition.y + textChar.end, + textLine.lineBottom ) upSelectChars(textPage) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt index 9883e6dab..6fed2fe97 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt @@ -3,6 +3,6 @@ package io.legado.app.ui.book.read.page.entities data class TextChar( val charData: String, var selected: Boolean = false, - val leftBottomPosition: TextPoint, - val rightTopPosition: TextPoint + val start: Float, + val end: Float ) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index 00ae4bff6..26fb31e90 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -4,6 +4,7 @@ data class TextLine( var text: String = "", val textChars: ArrayList = arrayListOf(), var lineTop: Float = 0f, + var lineBase: Float = 0f, var lineBottom: Float = 0f, val isTitle: Boolean = false, var isReadAloud: Boolean = false diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPoint.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPoint.kt deleted file mode 100644 index 07bb142b6..000000000 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPoint.kt +++ /dev/null @@ -1,6 +0,0 @@ -package io.legado.app.ui.book.read.page.entities - -data class TextPoint( - val x: Float, - val y: Float -) \ No newline at end of file