From 674c7a0da0e051d3bf88e0f650c42df8aa513ad6 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 12 Jul 2020 00:23:17 +0800 Subject: [PATCH] =?UTF-8?q?epub=20=E6=98=BE=E7=A4=BA=E5=9B=BE=E7=89=87,?= =?UTF-8?q?=E6=9C=AA=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ChapterProvider.kt | 32 +++++++++++++++++-- .../app/ui/book/read/page/ContentTextView.kt | 7 ++-- .../ui/book/read/page/entities/TextChar.kt | 3 +- 3 files changed, 36 insertions(+), 6 deletions(-) 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 9d6c9b0ff..e195684f8 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 @@ -13,6 +13,7 @@ import io.legado.app.data.entities.BookChapter import io.legado.app.help.AppConfig import io.legado.app.help.ReadBookConfig 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.* @@ -36,7 +37,8 @@ object ChapterProvider { var typeface: Typeface = Typeface.SANS_SERIF lateinit var titlePaint: TextPaint lateinit var contentPaint: TextPaint - private val srcPattern = Pattern.compile("", Pattern.CASE_INSENSITIVE) + private val srcPattern = + Pattern.compile("", Pattern.CASE_INSENSITIVE) init { upStyle() @@ -120,10 +122,34 @@ object ChapterProvider { ): Float { var durY = y ImageProvider.getImage(book, src)?.let { - val textLine = TextLine(text = src, isImage = true) + var height = it.height + val width = if (it.width > visibleWidth) { + height = it.height * visibleWidth / it.width + visibleWidth + } else { + it.width + } + val textLine = TextLine(isImage = true) textLine.lineTop = durY - durY += it.height + durY += height textLine.lineBottom = durY + val (start, end) = if (visibleWidth > width) { + val adjustWidth = (visibleWidth - width) / 2f + Pair( + paddingLeft.toFloat() + adjustWidth, + paddingLeft.toFloat() + adjustWidth + width + ) + } else { + Pair(paddingLeft.toFloat(), (paddingLeft + width).toFloat()) + } + textLine.textChars.add( + TextChar( + charData = src, + start = start, + end = end, + isImage = true + ) + ) textPages.last().textLines.add(textLine) } return durY + paragraphSpacing / 10f 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 75482c2a5..68d8c43e9 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 @@ -154,8 +154,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at lineTop: Float, lineBottom: Float ) { - ImageProvider.getImage(ReadBook.book!!, textLine.text)?.let { - canvas.drawBitmap(it, ChapterProvider.paddingLeft.toFloat(), lineTop, null) + textLine.textChars.forEach { textChar -> + val rectF = RectF(textChar.start, lineTop, textChar.end, lineBottom) + ImageProvider.getImage(ReadBook.book!!, textChar.charData)?.let { + canvas.drawBitmap(it, null, rectF, null) + } } } 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 72798a9ea..6a0e9b0f4 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 @@ -4,5 +4,6 @@ data class TextChar( val charData: String, var start: Float, var end: Float, - var selected: Boolean = false + var selected: Boolean = false, + var isImage: Boolean = false ) \ No newline at end of file