pull/357/head
gedoor 4 years ago
parent 16b7655cf6
commit b8c8a4465d
  1. 4
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  2. 21
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt

@ -65,9 +65,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
ChapterProvider.viewWidth = w
ChapterProvider.viewHeight = h
ChapterProvider.upViewSize()
ChapterProvider.upViewSize(w, h)
upVisibleRect()
textPage.format()
}

@ -22,8 +22,8 @@ import java.util.*
@Suppress("DEPRECATION")
object ChapterProvider {
var viewWidth = 0
var viewHeight = 0
private var viewWidth = 0
private var viewHeight = 0
var paddingLeft = 0
var paddingTop = 0
var visibleWidth = 0
@ -440,13 +440,25 @@ object ChapterProvider {
paragraphSpacing = ReadBookConfig.paragraphSpacing
titleTopSpacing = ReadBookConfig.titleTopSpacing.dp
titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dp
upViewSize()
upVisibleSize()
}
/**
* 更新View尺寸
*/
fun upViewSize() {
fun upViewSize(width: Int, height: Int) {
if (width > 0 && height > 0) {
viewWidth = width
viewHeight = height
upVisibleSize()
}
}
/**
* 更新绘制尺寸
*/
private fun upVisibleSize() {
if (viewWidth > 0 && viewHeight > 0) {
paddingLeft = ReadBookConfig.paddingLeft.dp
paddingTop = ReadBookConfig.paddingTop.dp
visibleWidth = viewWidth - paddingLeft - ReadBookConfig.paddingRight.dp
@ -454,6 +466,7 @@ object ChapterProvider {
visibleRight = paddingLeft + visibleWidth
visibleBottom = paddingTop + visibleHeight
}
}
val TextPaint.textHeight: Float
get() = fontMetrics.descent - fontMetrics.ascent + fontMetrics.leading

Loading…
Cancel
Save