feat: 优化代码

pull/121/head
kunfei 5 years ago
parent 6cc2e8b140
commit b15928026c
  1. 18
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt
  3. 11
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt

@ -265,6 +265,7 @@ object ChapterProvider {
) )
x = x1 x = x1
} }
exceed(textLine, words)
} }
/** /**
@ -291,8 +292,25 @@ object ChapterProvider {
) )
x = x1 x = x1
} }
exceed(textLine, words)
} }
/**
* 超出边界处理
*/
private fun exceed(textLine: TextLine, words: String) {
val endX = textLine.textChars.last().end
if (endX > visibleRight) {
val cc = (endX - visibleRight) / words.length
for (i in 0..words.lastIndex) {
textLine.getTextCharReverseAt(i).let {
val py = cc * (words.length - i)
it.start = it.start - py
it.end = it.end - py
}
}
}
}
/** /**
* 更新样式 * 更新样式

@ -2,7 +2,7 @@ package io.legado.app.ui.book.read.page.entities
data class TextChar( data class TextChar(
val charData: String, val charData: String,
val start: Float, var start: Float,
val end: Float, var end: Float,
var selected: Boolean = false var selected: Boolean = false
) )

@ -14,4 +14,15 @@ data class TextLine(
textChars.add(TextChar(charData, start = start, end = end)) textChars.add(TextChar(charData, start = start, end = end))
} }
fun getTextCharAt(index: Int): TextChar {
return textChars[index]
}
fun getTextCharReverseAt(index: Int): TextChar {
return textChars[textChars.lastIndex - index]
}
fun getTextCharsCount(): Int {
return textChars.size
}
} }

Loading…
Cancel
Save