From 1523f1ca959885af8f5a7470c8cfbef470194238 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 7 Sep 2022 20:49:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=86=E5=A4=87=E5=9C=A8=E6=AD=A3=E6=96=87?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/page/ContentTextView.kt | 10 +++++----- .../page/entities/{TextChar.kt => TextColumn.kt} | 4 ++-- .../app/ui/book/read/page/entities/TextLine.kt | 6 +++--- .../app/ui/book/read/page/entities/TextPage.kt | 2 +- .../ui/book/read/page/provider/ChapterProvider.kt | 12 ++++++------ 5 files changed, 17 insertions(+), 17 deletions(-) rename app/src/main/java/io/legado/app/ui/book/read/page/entities/{TextChar.kt => TextColumn.kt} (79%) 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 fe1e9e09d..7408efd7d 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 @@ -14,7 +14,7 @@ import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.lib.theme.accentColor import io.legado.app.model.ReadBook -import io.legado.app.ui.book.read.page.entities.TextChar +import io.legado.app.ui.book.read.page.entities.TextColumn import io.legado.app.ui.book.read.page.entities.TextLine import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPos @@ -160,7 +160,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } val textColor = if (textLine.isReadAloud) context.accentColor else ReadBookConfig.textColor textLine.textChars.forEach { - if (it.isImage) { + if (it.style == 1) { drawImage(canvas, textPage, textLine, it, lineTop, lineBottom) } else { textPaint.color = textColor @@ -183,7 +183,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at canvas: Canvas, textPage: TextPage, textLine: TextLine, - textChar: TextChar, + textChar: TextColumn, lineTop: Float, lineBottom: Float ) { @@ -284,7 +284,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at select: (textPos: TextPos) -> Unit, ) { touch(x, y) { _, textPos, _, _, textChar -> - if (textChar.isImage) { + if (textChar.style == 1) { callBack.onImageLongPress(x, y, textChar.charData) } else { if (!selectAble) return@touch @@ -367,7 +367,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at textPos: TextPos, textPage: TextPage, textLine: TextLine, - textChar: TextChar + textColumn: TextColumn ) -> Unit ) { if (!visibleRect.contains(x, y)) return 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/TextColumn.kt similarity index 79% rename from app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt rename to app/src/main/java/io/legado/app/ui/book/read/page/entities/TextColumn.kt index f52525597..82badb33f 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/TextColumn.kt @@ -3,12 +3,12 @@ package io.legado.app.ui.book.read.page.entities /** * 字符信息 */ -data class TextChar( +data class TextColumn( val charData: String, var start: Float, var end: Float, + val style: Int = 0, //0:文字,1:图片,2:按钮 var selected: Boolean = false, - var isImage: Boolean = false, var isSearchResult: Boolean = false ) { 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 176c4fea4..28ac5b24f 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 @@ -10,7 +10,7 @@ import io.legado.app.utils.textHeight @Suppress("unused", "MemberVisibilityCanBePrivate") data class TextLine( var text: String = "", - val textChars: ArrayList = arrayListOf(), + val textChars: ArrayList = arrayListOf(), var lineTop: Float = 0f, var lineBase: Float = 0f, var lineBottom: Float = 0f, @@ -30,13 +30,13 @@ data class TextLine( lineBase = lineBottom - textPaint.fontMetrics.descent } - fun getTextChar(index: Int): TextChar { + fun getTextChar(index: Int): TextColumn { return textChars.getOrElse(index) { textChars.last() } } - fun getTextCharReverseAt(index: Int): TextChar { + fun getTextCharReverseAt(index: Int): TextColumn { return textChars[textChars.lastIndex - index] } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index 82966b138..a69483ab2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -114,7 +114,7 @@ data class TextPage( val cw = StaticLayout.getDesiredWidth(char, ChapterProvider.contentPaint) val x1 = x + cw textLine.textChars.add( - TextChar(char, start = x, end = x1) + TextColumn(char, start = x, end = x1) ) x = x1 } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 5ae48f727..185d251e6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -14,7 +14,7 @@ import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.model.ReadBook 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.TextColumn 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.* @@ -252,7 +252,7 @@ object ChapterProvider { Pair(0f, width.toFloat()) } textLine.textChars.add( - TextChar(charData = src, start = x + start, end = x + end, isImage = true) + TextColumn(charData = src, start = x + start, end = x + end, style = 1) ) textPages.last().textLines.add(textLine) } @@ -401,7 +401,7 @@ object ChapterProvider { bodyIndent.toStringArray().forEach { char -> val x1 = x + icw textLine.textChars.add( - TextChar(charData = char, start = absStartX + x, end = absStartX + x1) + TextColumn(charData = char, start = absStartX + x, end = absStartX + x1) ) x = x1 } @@ -480,16 +480,16 @@ object ChapterProvider { val src = srcList.removeFirst() ImageProvider.cacheImage(book, src, ReadBook.bookSource) textLine.textChars.add( - TextChar( + TextColumn( charData = src, start = absStartX + xStart, end = absStartX + xEnd, - isImage = true + style = 1 ) ) } else { textLine.textChars.add( - TextChar( + TextColumn( charData = char, start = absStartX + xStart, end = absStartX + xEnd