pull/1785/head
kunfei 3 years ago
parent 8101cf7ba8
commit 30b785fbb9
  1. 38
      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( private fun drawImage(
canvas: Canvas, canvas: Canvas,
textPage: TextPage, textPage: TextPage,
@ -165,22 +166,18 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
(textChar.end - textChar.start).toInt(), (textChar.end - textChar.start).toInt(),
(lineBottom - lineTop).toInt() (lineBottom - lineTop).toInt()
) )
relativeOffset(textPage)?.let { relativeOffset -> val rectF = if (textLine.isImage) {
val lineTopNow = textLine.lineTop + relativeOffset RectF(textChar.start, lineTop, textChar.end, lineBottom)
val lineBottomNow = textLine.lineBottom + relativeOffset } else {
val rectF = if (textLine.isImage) { /*以宽度为基准保持图片的原始比例叠加,当div为负数时,允许高度比字符更高*/
RectF(textChar.start, lineTopNow, textChar.end, lineBottomNow) val h = (textChar.end - textChar.start) / bitmap.width * bitmap.height
} else { val div = (lineBottom - lineTop - h) / 2
/*以宽度为基准保持图片的原始比例叠加,当div为负数时,允许高度比字符更高*/ RectF(textChar.start, lineTop + div, textChar.end, lineBottom - div)
val h = (textChar.end - textChar.start) / bitmap.width * bitmap.height }
val div = (lineBottomNow - lineTopNow - h) / 2 kotlin.runCatching {
RectF(textChar.start, lineTopNow + div, textChar.end, lineBottomNow - div) canvas.drawBitmap(bitmap, null, rectF, null)
} }.onFailure { e ->
kotlin.runCatching { context.toastOnUi(e.localizedMessage)
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 { fun relativePage(relativePos: Int): TextPage {
return when (relativePos) { return when (relativePos) {
0 -> textPage 0 -> textPage

Loading…
Cancel
Save