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