pull/1333/head
gedoor 3 years ago
parent a5210a3d11
commit c7b8dc0595
  1. 2
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  3. 53
      app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt
  4. 6
      app/src/main/java/io/legado/app/utils/PaintExtensions.kt
  5. BIN
      app/src/main/res/drawable/image_cover_default.png

@ -2,7 +2,7 @@ package io.legado.app.ui.book.read.page.entities
import android.text.TextPaint import android.text.TextPaint
import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.ui.book.read.page.provider.ChapterProvider.textHeight import io.legado.app.utils.textHeight
@Suppress("unused") @Suppress("unused")
data class TextLine( data class TextLine(

@ -550,6 +550,4 @@ object ChapterProvider {
} }
} }
val TextPaint.textHeight: Float
get() = fontMetrics.descent - fontMetrics.ascent + fontMetrics.leading
} }

@ -16,6 +16,8 @@ import io.legado.app.help.AppConfig
import io.legado.app.help.glide.ImageLoader import io.legado.app.help.glide.ImageLoader
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import io.legado.app.utils.textHeight
import io.legado.app.utils.toStringArray
import splitties.init.appCtx import splitties.init.appCtx
/** /**
@ -44,7 +46,6 @@ class CoverImageView @JvmOverloads constructor(
textPaint.typeface = Typeface.DEFAULT_BOLD textPaint.typeface = Typeface.DEFAULT_BOLD
textPaint.isAntiAlias = true textPaint.isAntiAlias = true
textPaint.textAlign = Paint.Align.CENTER textPaint.textAlign = Paint.Align.CENTER
textPaint.textSkewX = -0.2f
textPaint textPaint
} }
private val authorPaint by lazy { private val authorPaint by lazy {
@ -52,7 +53,6 @@ class CoverImageView @JvmOverloads constructor(
textPaint.typeface = Typeface.DEFAULT textPaint.typeface = Typeface.DEFAULT
textPaint.isAntiAlias = true textPaint.isAntiAlias = true
textPaint.textAlign = Paint.Align.CENTER textPaint.textAlign = Paint.Align.CENTER
textPaint.textSkewX = -0.1f
textPaint textPaint
} }
@ -86,11 +86,8 @@ class CoverImageView @JvmOverloads constructor(
} }
namePaint.textSize = width / 6 namePaint.textSize = width / 6
namePaint.strokeWidth = namePaint.textSize / 10 namePaint.strokeWidth = namePaint.textSize / 10
authorPaint.textSize = width / 9 authorPaint.textSize = width / 8
authorPaint.strokeWidth = authorPaint.textSize / 10 authorPaint.strokeWidth = authorPaint.textSize / 10
val fm = namePaint.fontMetrics
nameHeight = height * 0.5f + (fm.bottom - fm.top) * 0.5f
authorHeight = nameHeight + (fm.bottom - fm.top) * 0.6f
} }
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {
@ -104,21 +101,37 @@ class CoverImageView @JvmOverloads constructor(
} }
private fun drawName(canvas: Canvas) { private fun drawName(canvas: Canvas) {
name?.let { var startX = width * 0.2f
namePaint.color = Color.WHITE var startY = height * 0.2f
namePaint.style = Paint.Style.STROKE name?.toStringArray()?.let { name ->
canvas.drawText(it, width / 2, nameHeight, namePaint) name.forEach {
namePaint.color = Color.RED namePaint.color = Color.WHITE
namePaint.style = Paint.Style.FILL namePaint.style = Paint.Style.STROKE
canvas.drawText(it, width / 2, nameHeight, namePaint) canvas.drawText(it, startX, startY, namePaint)
namePaint.color = Color.DKGRAY
namePaint.style = Paint.Style.FILL
canvas.drawText(it, startX, startY, namePaint)
startY += namePaint.textHeight
if (startY > height * 0.9) {
return@let
}
}
} }
author?.let { startX = width * 0.8f
authorPaint.color = Color.WHITE startY = height * 0.7f
authorPaint.style = Paint.Style.STROKE author?.toStringArray()?.let { author ->
canvas.drawText(it, width / 2, authorHeight, authorPaint) author.forEach {
authorPaint.color = Color.RED authorPaint.color = Color.WHITE
authorPaint.style = Paint.Style.FILL authorPaint.style = Paint.Style.STROKE
canvas.drawText(it, width / 2, authorHeight, authorPaint) canvas.drawText(it, startX, startY, authorPaint)
authorPaint.color = Color.DKGRAY
authorPaint.style = Paint.Style.FILL
canvas.drawText(it, startX, startY, authorPaint)
startY += authorPaint.textHeight
if (startY > height * 0.95) {
return@let
}
}
} }
} }

@ -0,0 +1,6 @@
package io.legado.app.utils
import android.text.TextPaint
val TextPaint.textHeight: Float
get() = fontMetrics.descent - fontMetrics.ascent + fontMetrics.leading

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 260 KiB

Loading…
Cancel
Save