添加图片样式TEXT

pull/885/head^2
gedoor 4 years ago
parent 638a10f649
commit 8f4bf259ad
  1. 12
      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,9 +113,6 @@ 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) {
drawImage(canvas, textLine, lineTop, lineBottom)
} else {
drawChars( drawChars(
canvas, canvas,
textLine.textChars, textLine.textChars,
@ -126,7 +123,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
isReadAloud = textLine.isReadAloud 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 {
if (it.isImage) {
drawImage(canvas, it, lineTop, lineBottom)
} else {
canvas.drawText(it.charData, it.start, lineBase, textPaint) 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,11 +160,10 @@ 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)
@ -173,7 +172,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} }
} }
} }
}
/** /**
* 滚动事件 * 滚动事件

@ -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