From 30b785fbb9497697cad2e709657a463af18ab7cc Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 14 Apr 2022 12:24:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 38 +++++++------------ 1 file changed, 13 insertions(+), 25 deletions(-) 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 5c9766534..5fd7e37cd 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 @@ -150,6 +150,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at /** * 绘制图片 */ + @Suppress("UNUSED_PARAMETER") private fun drawImage( canvas: Canvas, textPage: TextPage, @@ -165,22 +166,18 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at (textChar.end - textChar.start).toInt(), (lineBottom - lineTop).toInt() ) - relativeOffset(textPage)?.let { relativeOffset -> - val lineTopNow = textLine.lineTop + relativeOffset - val lineBottomNow = textLine.lineBottom + relativeOffset - val rectF = if (textLine.isImage) { - RectF(textChar.start, lineTopNow, textChar.end, lineBottomNow) - } else { - /*以宽度为基准保持图片的原始比例叠加,当div为负数时,允许高度比字符更高*/ - val h = (textChar.end - textChar.start) / bitmap.width * bitmap.height - val div = (lineBottomNow - lineTopNow - h) / 2 - RectF(textChar.start, lineTopNow + div, textChar.end, lineBottomNow - div) - } - kotlin.runCatching { - canvas.drawBitmap(bitmap, null, rectF, null) - }.onFailure { e -> - context.toastOnUi(e.localizedMessage) - } + val rectF = if (textLine.isImage) { + RectF(textChar.start, lineTop, textChar.end, lineBottom) + } else { + /*以宽度为基准保持图片的原始比例叠加,当div为负数时,允许高度比字符更高*/ + val h = (textChar.end - textChar.start) / bitmap.width * bitmap.height + val div = (lineBottom - lineTop - h) / 2 + RectF(textChar.start, lineTop + div, textChar.end, lineBottom - div) + } + kotlin.runCatching { + canvas.drawBitmap(bitmap, null, rectF, null) + }.onFailure { e -> + context.toastOnUi(e.localizedMessage) } } @@ -522,15 +519,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } - private fun relativeOffset(textPage: TextPage): Float? { - return when (textPage) { - this.textPage -> relativeOffset(0) - pageFactory.nextPage -> relativeOffset(1) - pageFactory.nextPlusPage -> relativeOffset(2) - else -> null - } - } - fun relativePage(relativePos: Int): TextPage { return when (relativePos) { 0 -> textPage