From 089a21d7c3e7b6274fde33b826e8f72feb7086b4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 13 Feb 2022 15:21:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E9=A2=98=E5=8D=95=E7=8B=AC=E7=BB=98?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/ContentProcessor.kt | 1 + .../main/java/io/legado/app/model/ReadBook.kt | 3 +- .../read/page/provider/ChapterProvider.kt | 78 ++++++++++--------- 3 files changed, 43 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/ContentProcessor.kt index 7f2d8eecc..cf3116a82 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -60,6 +60,7 @@ class ContentProcessor private constructor( return titleReplaceRules } + @Suppress("MemberVisibilityCanBePrivate") fun getContentReplaceRules(): List { return contentReplaceRules } diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index a0518651b..e72366389 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -355,7 +355,8 @@ object ReadBook : CoroutineScope by MainScope() { contentProcessor.getTitleReplaceRules(), book.getUseReplaceRule() ) - val contents = contentProcessor.getContent(book, chapter, content) + val contents = contentProcessor + .getContent(book, chapter, content, includeTitle = false) val textChapter = ChapterProvider .getTextChapter(book, chapter, displayTitle, contents, chapterSize) when (val offset = chapter.index - durChapterIndex) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 9abe851d1..3f1c66ff0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -113,11 +113,20 @@ object ChapterProvider { var absStartX = paddingLeft var durY = 0f textPages.add(TextPage()) - contents.forEachIndexed { index, content -> - val isTitle = index == 0 - val isTitleWithNoContent = isTitle && contents.size == 1 - val isVolumeTitle = isTitle && bookChapter.isVolume - val textPaint = if (isTitle) titlePaint else contentPaint + if (ReadBookConfig.titleMode != 2) { + displayTitle.splitNotBlank("\n").forEach { text -> + setTypeText( + absStartX, durY, text, textPages, stringBuilder, titlePaint, + isTitle = true, + isTitleWithNoContent = contents.isEmpty(), + isVolumeTitle = bookChapter.isVolume + ).let { + absStartX = it.first + durY = it.second + } + } + } + contents.forEach { content -> if (book.getImageStyle() == Book.imgStyleText) { var text = content.replace(srcReplaceChar, "▣") val srcList = LinkedList() @@ -132,29 +141,24 @@ object ChapterProvider { } matcher.appendTail(sb) text = sb.toString() - if (!(isTitle && ReadBookConfig.titleMode == 2)) { - setTypeText( - absStartX, durY, text, textPages, stringBuilder, - isTitle, isTitleWithNoContent, isVolumeTitle, textPaint, srcList - ).let { - absStartX = it.first - durY = it.second - } + setTypeText( + absStartX, durY, text, textPages, stringBuilder, contentPaint, + srcList = srcList + ).let { + absStartX = it.first + durY = it.second } - } else if (book.getImageStyle() != Book.imgStyleText) { + } else { val matcher = AppPattern.imgPattern.matcher(content) var start = 0 while (matcher.find()) { val text = content.substring(start, matcher.start()) if (text.isNotBlank()) { - if (!(isTitle && ReadBookConfig.titleMode == 2)) { - setTypeText( - absStartX, durY, text, textPages, stringBuilder, - isTitle, isTitleWithNoContent, isVolumeTitle, textPaint - ).let { - absStartX = it.first - durY = it.second - } + setTypeText( + absStartX, durY, text, textPages, stringBuilder, contentPaint + ).let { + absStartX = it.first + durY = it.second } } durY = setTypeImage( @@ -166,14 +170,11 @@ object ChapterProvider { if (start < content.length) { val text = content.substring(start, content.length) if (text.isNotBlank()) { - if (!(isTitle && ReadBookConfig.titleMode == 2)) { - setTypeText( - absStartX, durY, text, textPages, stringBuilder, - isTitle, isTitleWithNoContent, isVolumeTitle, textPaint - ).let { - absStartX = it.first - durY = it.second - } + setTypeText( + absStartX, durY, text, textPages, stringBuilder, contentPaint + ).let { + absStartX = it.first + durY = it.second } } } @@ -271,10 +272,10 @@ object ChapterProvider { text: String, textPages: ArrayList, stringBuilder: StringBuilder, - isTitle: Boolean, - isTitleWithNoContent: Boolean, - isVolumeTitle: Boolean, textPaint: TextPaint, + isTitle: Boolean = false, + isTitleWithNoContent: Boolean = false, + isVolumeTitle: Boolean = false, srcList: LinkedList? = null ): Pair { var absStartX = x @@ -332,9 +333,10 @@ object ChapterProvider { textLine.text = "$words\n" isLastLine = true //标题x轴居中 - val startX = if (isTitle && ReadBookConfig.titleMode == 1 || isTitleWithNoContent || isVolumeTitle) - (visibleWidth - layout.getLineWidth(lineIndex)) / 2 - else 0f + val startX = + if (isTitle && ReadBookConfig.titleMode == 1 || isTitleWithNoContent || isVolumeTitle) + (visibleWidth - layout.getLineWidth(lineIndex)) / 2 + else 0f addCharsToLineLast( absStartX, textLine, @@ -603,8 +605,8 @@ object ChapterProvider { */ fun upLayout() { doublePage = (viewWidth > viewHeight || appCtx.isPad) - && ReadBook.pageAnim() != 3 - && AppConfig.doublePageHorizontal + && ReadBook.pageAnim() != 3 + && AppConfig.doublePageHorizontal if (viewWidth > 0 && viewHeight > 0) { paddingLeft = ReadBookConfig.paddingLeft.dp paddingTop = ReadBookConfig.paddingTop.dp