From 9e7a6750ae2ff2d5b2d16d334926675870b6d3e7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 6 Mar 2020 19:11:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/page/ChapterProvider.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index 9fff1a462..7ecedea96 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -107,15 +107,15 @@ object ChapterProvider { val textLine = TextLine(isTitle = isTitle) val words = text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) - stringBuilder.append(words) textLine.text = words val desiredWidth = layout.getLineWidth(lineIndex) + var isLastLine = false if (lineIndex == 0 && layout.lineCount > 1 && !isTitle) { //第一行 addCharsToLineFirst(textLine, words, textPaint, desiredWidth) } else if (lineIndex == layout.lineCount - 1) { //最后一行 - stringBuilder.append("\n") + isLastLine = true val x = if (isTitle && ReadBookConfig.titleMode == 1) (visibleWidth - layout.getLineWidth(lineIndex)) / 2 else 0f @@ -126,19 +126,25 @@ object ChapterProvider { } 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 { //当前页面结束,设置各种值 + stringBuilder.append(words) + if (isLastLine) stringBuilder.append("\n") textPages.last().text = stringBuilder.toString() - stringBuilder.clear() pageLines.add(textPages.last().textLines.size) pageLengths.add(textPages.last().text.length) textPages.last().height = durY //新建页面 textPages.add(TextPage()) + stringBuilder.clear() + stringBuilder.append(words) + if (isLastLine) stringBuilder.append("\n") textLine.upTopBottom(0f, textPaint) textPages.last().textLines.add(textLine) durY = textPaint.textHeight * lineSpacingExtra / 10f