epub 显示图片,未完善

pull/274/head
gedoor 4 years ago
parent 6f936c377c
commit 674c7a0da0
  1. 32
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
  2. 7
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  3. 3
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt

@ -13,6 +13,7 @@ import io.legado.app.data.entities.BookChapter
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.ReadBookConfig 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.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.TextLine
import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.utils.* import io.legado.app.utils.*
@ -36,7 +37,8 @@ object ChapterProvider {
var typeface: Typeface = Typeface.SANS_SERIF var typeface: Typeface = Typeface.SANS_SERIF
lateinit var titlePaint: TextPaint lateinit var titlePaint: TextPaint
lateinit var contentPaint: TextPaint lateinit var contentPaint: TextPaint
private val srcPattern = Pattern.compile("<img .*?src=\"(.*?)\".*?>", Pattern.CASE_INSENSITIVE) private val srcPattern =
Pattern.compile("<img .*?src.*?=.*?\"(.*?)\".*?>", Pattern.CASE_INSENSITIVE)
init { init {
upStyle() upStyle()
@ -120,10 +122,34 @@ object ChapterProvider {
): Float { ): Float {
var durY = y var durY = y
ImageProvider.getImage(book, src)?.let { 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 textLine.lineTop = durY
durY += it.height durY += height
textLine.lineBottom = durY 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) textPages.last().textLines.add(textLine)
} }
return durY + paragraphSpacing / 10f return durY + paragraphSpacing / 10f

@ -154,8 +154,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
lineTop: Float, lineTop: Float,
lineBottom: Float lineBottom: Float
) { ) {
ImageProvider.getImage(ReadBook.book!!, textLine.text)?.let { textLine.textChars.forEach { textChar ->
canvas.drawBitmap(it, ChapterProvider.paddingLeft.toFloat(), lineTop, null) val rectF = RectF(textChar.start, lineTop, textChar.end, lineBottom)
ImageProvider.getImage(ReadBook.book!!, textChar.charData)?.let {
canvas.drawBitmap(it, null, rectF, null)
}
} }
} }

@ -4,5 +4,6 @@ data class TextChar(
val charData: String, val charData: String,
var start: Float, var start: Float,
var end: Float, var end: Float,
var selected: Boolean = false var selected: Boolean = false,
var isImage: Boolean = false
) )
Loading…
Cancel
Save