feat: 优化代码

pull/134/head^2
kunfei 5 years ago
parent 62cacd2379
commit f059d3c33b
  1. 17
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt

@ -124,15 +124,7 @@ object ChapterProvider {
//中间行
addCharsToLineMiddle(textLine, words, textPaint, desiredWidth, 0f)
}
if (durY + textPaint.textHeight < visibleHeight) {
//当前页面新增行
stringBuilder.append(words)
if (isLastLine) stringBuilder.append("\n")
textLine.upTopBottom(durY, textPaint)
textPages.last().textLines.add(textLine)
durY += textPaint.textHeight * lineSpacingExtra / 10f
textPages.last().height = durY
} else {
if (durY + textPaint.textHeight > visibleHeight) {
//当前页面结束,设置各种值
textPages.last().text = stringBuilder.toString()
pageLines.add(textPages.last().textLines.size)
@ -141,14 +133,15 @@ object ChapterProvider {
//新建页面
textPages.add(TextPage())
stringBuilder.clear()
durY = 0f
}
stringBuilder.append(words)
if (isLastLine) stringBuilder.append("\n")
textLine.upTopBottom(0f, textPaint)
textPages.last().textLines.add(textLine)
durY = textPaint.textHeight * lineSpacingExtra / 10f
textLine.upTopBottom(durY, textPaint)
durY += textPaint.textHeight * lineSpacingExtra / 10f
textPages.last().height = durY
}
}
durY += textPaint.textHeight * paragraphSpacing / 10f
return durY
}

Loading…
Cancel
Save