This commit is contained in:
Horis 2024-06-14 12:12:08 +08:00
parent 5acfe9be68
commit 0337e465de
5 changed files with 8 additions and 13 deletions

View File

@ -188,7 +188,6 @@ class ContentProcessor private constructor(
mContent = mContent.replace('\u00A0', ' ')
}
val contents = arrayListOf<String>()
val paragraphIndent = ReadBookConfig.paragraphIndent
mContent.split("\n").forEach { str ->
val paragraph = str.trim {
it.code <= 0x20 || it == ' '
@ -197,14 +196,10 @@ class ContentProcessor private constructor(
if (contents.isEmpty() && includeTitle) {
contents.add(paragraph)
} else {
contents.add("$paragraphIndent$paragraph")
contents.add("${ReadBookConfig.paragraphIndent}$paragraph")
}
}
}
if (contents.isEmpty()) {
contents.add("${paragraphIndent}加载正文失败")
contents.add("${paragraphIndent}内容处理后为空")
}
return BookContent(sameTitleRemoved, contents, effectiveReplaceRules)
}

View File

@ -218,7 +218,7 @@ abstract class BaseReadAloudService : BaseService(),
}
nowSpeak = textChapter.getParagraphNum(readAloudNumber + 1, readAloudByPage) - 1
if (!readAloudByPage && startPos == 0 && !toLast) {
pos = page.lines.first().chapterPosition -
pos = page.chapterPosition -
textChapter.paragraphs[nowSpeak].chapterPosition
}
if (toLast) {
@ -226,7 +226,7 @@ abstract class BaseReadAloudService : BaseService(),
readAloudNumber = textChapter.getLastParagraphPosition()
nowSpeak = contentList.lastIndex
if (page.paragraphs.size == 1) {
pos = page.lines.first().chapterPosition -
pos = page.chapterPosition -
textChapter.paragraphs[nowSpeak].chapterPosition
}
}

View File

@ -112,7 +112,7 @@ data class TextChapter(
*/
fun getReadLength(pageIndex: Int): Int {
if (pageIndex < 0) return 0
return pages[min(pageIndex, lastIndex)].lines.first().chapterPosition
return pages[min(pageIndex, lastIndex)].chapterPosition
/*
var length = 0
val maxIndex = min(pageIndex, pages.size)
@ -224,14 +224,13 @@ data class TextChapter(
return -1
}
val bIndex = pages.fastBinarySearchBy(charIndex, 0, pageSize) {
it.lines.first().chapterPosition
it.chapterPosition
}
val index = abs(bIndex + 1) - 1
// 判断是否已经排版到 charIndex ,没有则返回 -1
if (!isCompleted && index == pageSize - 1) {
val page = pages[index]
val line = page.lines.first()
val pageEndPos = line.chapterPosition + page.charSize
val pageEndPos = page.chapterPosition + page.charSize
if (charIndex > pageEndPos) {
return -1
}

View File

@ -45,6 +45,7 @@ data class TextPage(
val lines: List<TextLine> get() = textLines
val lineSize: Int get() = textLines.size
val charSize: Int get() = text.length.coerceAtLeast(1)
val chapterPosition: Int get() = textLines.first().chapterPosition
val searchResult = hashSetOf<TextColumn>()
var isMsgPage: Boolean = false
var canvasRecorder = CanvasRecorderFactory.create(true)

View File

@ -177,7 +177,7 @@ class TextChapterLayout(
val contents = bookContent.textList
var absStartX = paddingLeft
var durY = 0f
if (ReadBookConfig.titleMode != 2 || bookChapter.isVolume) {
if (ReadBookConfig.titleMode != 2 || bookChapter.isVolume || contents.isEmpty()) {
//标题非隐藏
displayTitle.splitNotBlank("\n").forEach { text ->
setTypeText(