添加图片样式TEXT

pull/885/head^2
gedoor 4 years ago
parent 638a10f649
commit 8f4bf259ad
  1. 44
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  2. 1
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt

@ -113,19 +113,15 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
val lineTop = textLine.lineTop + relativeOffset val lineTop = textLine.lineTop + relativeOffset
val lineBase = textLine.lineBase + relativeOffset val lineBase = textLine.lineBase + relativeOffset
val lineBottom = textLine.lineBottom + relativeOffset val lineBottom = textLine.lineBottom + relativeOffset
if (textLine.isImage) { drawChars(
drawImage(canvas, textLine, lineTop, lineBottom) canvas,
} else { textLine.textChars,
drawChars( lineTop,
canvas, lineBase,
textLine.textChars, lineBottom,
lineTop, isTitle = textLine.isTitle,
lineBase, isReadAloud = textLine.isReadAloud
lineBottom, )
isTitle = textLine.isTitle,
isReadAloud = textLine.isReadAloud
)
}
} }
/** /**
@ -148,7 +144,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
textPaint.color = textPaint.color =
if (isReadAloud) context.accentColor else ReadBookConfig.textColor if (isReadAloud) context.accentColor else ReadBookConfig.textColor
textChars.forEach { textChars.forEach {
canvas.drawText(it.charData, it.start, lineBase, textPaint) if (it.isImage) {
drawImage(canvas, it, lineTop, lineBottom)
} else {
canvas.drawText(it.charData, it.start, lineBase, textPaint)
}
if (it.selected) { if (it.selected) {
canvas.drawRect(it.start, lineTop, it.end, lineBottom, selectedPaint) canvas.drawRect(it.start, lineTop, it.end, lineBottom, selectedPaint)
} }
@ -160,18 +160,16 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
*/ */
private fun drawImage( private fun drawImage(
canvas: Canvas, canvas: Canvas,
textLine: TextLine, textChar: TextChar,
lineTop: Float, lineTop: Float,
lineBottom: Float, lineBottom: Float,
) { ) {
textLine.textChars.forEach { textChar -> ReadBook.book?.let { book ->
ReadBook.book?.let { book -> val rectF = RectF(textChar.start, lineTop, textChar.end, lineBottom)
val rectF = RectF(textChar.start, lineTop, textChar.end, lineBottom) ImageProvider.getImage(book, textPage.chapterIndex, textChar.charData, true)
ImageProvider.getImage(book, textPage.chapterIndex, textChar.charData, true) ?.let {
?.let { canvas.drawBitmap(it, null, rectF, null)
canvas.drawBitmap(it, null, rectF, null) }
}
}
} }
} }

@ -12,7 +12,6 @@ data class TextLine(
var lineBase: Float = 0f, var lineBase: Float = 0f,
var lineBottom: Float = 0f, var lineBottom: Float = 0f,
val isTitle: Boolean = false, val isTitle: Boolean = false,
val isImage: Boolean = false,
var isReadAloud: Boolean = false var isReadAloud: Boolean = false
) { ) {

@ -164,7 +164,7 @@ object ChapterProvider {
} }
} }
} }
val textLine = TextLine(isImage = true) val textLine = TextLine()
textLine.lineTop = durY textLine.lineTop = durY
durY += height durY += height
textLine.lineBottom = durY textLine.lineBottom = durY

Loading…
Cancel
Save