feat: 优化代码

pull/132/head
kunfei 5 years ago
parent 0ab1cb8958
commit 11de854088
  1. 30
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt

@ -106,22 +106,9 @@ object ChapterProvider {
for (lineIndex in 0 until layout.lineCount) { for (lineIndex in 0 until layout.lineCount) {
textPages.last().height = durY textPages.last().height = durY
val textLine = TextLine(isTitle = isTitle) val textLine = TextLine(isTitle = isTitle)
if (durY + textPaint.textHeight < visibleHeight) { textLine.lineBottom = paddingTop + durY + textPaint.textHeight
textPages.last().textLines.add(textLine)
durY += textPaint.textHeight * lineSpacingExtra / 10f
} else {
textPages.last().text = stringBuilder.toString()
stringBuilder.clear()
pageLines.add(textPages.last().textLines.size)
pageLengths.add(textPages.last().text.length)
//新建页面
durY = textPaint.textHeight * lineSpacingExtra / 10f
textPages.add(TextPage())
textPages.last().textLines.add(textLine)
}
textLine.lineBottom = paddingTop + durY - lineSpacingExtra
textLine.lineBase = textLine.lineBottom - textPaint.fontMetrics.descent textLine.lineBase = textLine.lineBottom - textPaint.fontMetrics.descent
textLine.lineTop = textLine.lineBottom - textPaint.textHeight textLine.lineTop = paddingTop + durY
val words = val words =
text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex))
stringBuilder.append(words) stringBuilder.append(words)
@ -140,6 +127,19 @@ object ChapterProvider {
//中间行 //中间行
addCharsToLineMiddle(textLine, words, textPaint, desiredWidth, 0f) addCharsToLineMiddle(textLine, words, textPaint, desiredWidth, 0f)
} }
if (durY + textPaint.textHeight < visibleHeight) {
textPages.last().textLines.add(textLine)
durY += textPaint.textHeight * lineSpacingExtra / 10f
} else {
textPages.last().text = stringBuilder.toString()
stringBuilder.clear()
pageLines.add(textPages.last().textLines.size)
pageLengths.add(textPages.last().text.length)
//新建页面
durY = textPaint.textHeight * lineSpacingExtra / 10f
textPages.add(TextPage())
textPages.last().textLines.add(textLine)
}
} }
durY += textPaint.textHeight * paragraphSpacing / 10f durY += textPaint.textHeight * paragraphSpacing / 10f
return durY return durY

Loading…
Cancel
Save