|
@@ -67,6 +67,8 @@ class TextChapterLayout(
|
|
|
private val indentCharWidth = ChapterProvider.indentCharWidth
|
|
private val indentCharWidth = ChapterProvider.indentCharWidth
|
|
|
private val stringBuilder = StringBuilder()
|
|
private val stringBuilder = StringBuilder()
|
|
|
|
|
|
|
|
|
|
+ private var pendingTextPage = TextPage()
|
|
|
|
|
+
|
|
|
private var isCompleted = false
|
|
private var isCompleted = false
|
|
|
private val job: Coroutine<*>
|
|
private val job: Coroutine<*>
|
|
|
private val bookChapter inline get() = textChapter.chapter
|
|
private val bookChapter inline get() = textChapter.chapter
|
|
@@ -167,7 +169,6 @@ class TextChapterLayout(
|
|
|
val contents = bookContent.textList
|
|
val contents = bookContent.textList
|
|
|
var absStartX = paddingLeft
|
|
var absStartX = paddingLeft
|
|
|
var durY = 0f
|
|
var durY = 0f
|
|
|
- textPages.add(TextPage())
|
|
|
|
|
if (ReadBookConfig.titleMode != 2 || bookChapter.isVolume) {
|
|
if (ReadBookConfig.titleMode != 2 || bookChapter.isVolume) {
|
|
|
//标题非隐藏
|
|
//标题非隐藏
|
|
|
displayTitle.splitNotBlank("\n").forEach { text ->
|
|
displayTitle.splitNotBlank("\n").forEach { text ->
|
|
@@ -185,7 +186,7 @@ class TextChapterLayout(
|
|
|
durY = it.second
|
|
durY = it.second
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- textPages.last().lines.last().isParagraphEnd = true
|
|
|
|
|
|
|
+ pendingTextPage.lines.last().isParagraphEnd = true
|
|
|
stringBuilder.append("\n")
|
|
stringBuilder.append("\n")
|
|
|
durY += titleBottomSpacing
|
|
durY += titleBottomSpacing
|
|
|
}
|
|
}
|
|
@@ -244,7 +245,6 @@ class TextChapterLayout(
|
|
|
matcher.group(1)!!,
|
|
matcher.group(1)!!,
|
|
|
absStartX,
|
|
absStartX,
|
|
|
durY,
|
|
durY,
|
|
|
- textPages,
|
|
|
|
|
contentPaintTextHeight,
|
|
contentPaintTextHeight,
|
|
|
stringBuilder,
|
|
stringBuilder,
|
|
|
book.getImageStyle()
|
|
book.getImageStyle()
|
|
@@ -270,10 +270,11 @@ class TextChapterLayout(
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- textPages.last().lines.last().isParagraphEnd = true
|
|
|
|
|
|
|
+ pendingTextPage.lines.last().isParagraphEnd = true
|
|
|
stringBuilder.append("\n")
|
|
stringBuilder.append("\n")
|
|
|
}
|
|
}
|
|
|
- val textPage = textPages.last()
|
|
|
|
|
|
|
+ textPages.add(pendingTextPage)
|
|
|
|
|
+ val textPage = pendingTextPage
|
|
|
val endPadding = 20.dpToPx()
|
|
val endPadding = 20.dpToPx()
|
|
|
val durYPadding = durY + endPadding
|
|
val durYPadding = durY + endPadding
|
|
|
if (textPage.height < durYPadding) {
|
|
if (textPage.height < durYPadding) {
|
|
@@ -295,7 +296,6 @@ class TextChapterLayout(
|
|
|
src: String,
|
|
src: String,
|
|
|
x: Int,
|
|
x: Int,
|
|
|
y: Float,
|
|
y: Float,
|
|
|
- textPages: ArrayList<TextPage>,
|
|
|
|
|
textHeight: Float,
|
|
textHeight: Float,
|
|
|
stringBuilder: StringBuilder,
|
|
stringBuilder: StringBuilder,
|
|
|
imageStyle: String?,
|
|
imageStyle: String?,
|
|
@@ -305,15 +305,16 @@ class TextChapterLayout(
|
|
|
val size = ImageProvider.getImageSize(book, src, ReadBook.bookSource)
|
|
val size = ImageProvider.getImageSize(book, src, ReadBook.bookSource)
|
|
|
if (size.width > 0 && size.height > 0) {
|
|
if (size.width > 0 && size.height > 0) {
|
|
|
if (durY > visibleHeight) {
|
|
if (durY > visibleHeight) {
|
|
|
- val textPage = textPages.last()
|
|
|
|
|
|
|
+ val textPage = pendingTextPage
|
|
|
if (textPage.height < durY) {
|
|
if (textPage.height < durY) {
|
|
|
textPage.height = durY
|
|
textPage.height = durY
|
|
|
}
|
|
}
|
|
|
textPage.text = stringBuilder.toString().ifEmpty { "本页无文字内容" }
|
|
textPage.text = stringBuilder.toString().ifEmpty { "本页无文字内容" }
|
|
|
stringBuilder.clear()
|
|
stringBuilder.clear()
|
|
|
|
|
+ textPages.add(textPage)
|
|
|
coroutineContext.ensureActive()
|
|
coroutineContext.ensureActive()
|
|
|
onPageCompleted()
|
|
onPageCompleted()
|
|
|
- textPages.add(TextPage())
|
|
|
|
|
|
|
+ pendingTextPage = TextPage()
|
|
|
durY = 0f
|
|
durY = 0f
|
|
|
}
|
|
}
|
|
|
var height = size.height
|
|
var height = size.height
|
|
@@ -334,7 +335,7 @@ class TextChapterLayout(
|
|
|
height = visibleHeight
|
|
height = visibleHeight
|
|
|
}
|
|
}
|
|
|
if (durY + height > visibleHeight) {
|
|
if (durY + height > visibleHeight) {
|
|
|
- val textPage = textPages.last()
|
|
|
|
|
|
|
+ val textPage = pendingTextPage
|
|
|
if (doublePage && absStartX < viewWidth / 2) {
|
|
if (doublePage && absStartX < viewWidth / 2) {
|
|
|
//当前页面左列结束
|
|
//当前页面左列结束
|
|
|
textPage.leftLineSize = textPage.lineSize
|
|
textPage.leftLineSize = textPage.lineSize
|
|
@@ -346,9 +347,10 @@ class TextChapterLayout(
|
|
|
}
|
|
}
|
|
|
textPage.text = stringBuilder.toString().ifEmpty { "本页无文字内容" }
|
|
textPage.text = stringBuilder.toString().ifEmpty { "本页无文字内容" }
|
|
|
stringBuilder.clear()
|
|
stringBuilder.clear()
|
|
|
|
|
+ textPages.add(textPage)
|
|
|
coroutineContext.ensureActive()
|
|
coroutineContext.ensureActive()
|
|
|
onPageCompleted()
|
|
onPageCompleted()
|
|
|
- textPages.add(TextPage())
|
|
|
|
|
|
|
+ pendingTextPage = TextPage()
|
|
|
}
|
|
}
|
|
|
// 双页的 durY 不正确,可能会小于实际高度
|
|
// 双页的 durY 不正确,可能会小于实际高度
|
|
|
if (textPage.height < durY) {
|
|
if (textPage.height < durY) {
|
|
@@ -373,7 +375,7 @@ class TextChapterLayout(
|
|
|
)
|
|
)
|
|
|
calcTextLinePosition(textPages, textLine, stringBuilder.length)
|
|
calcTextLinePosition(textPages, textLine, stringBuilder.length)
|
|
|
stringBuilder.append(" ") // 确保翻页时索引计算正确
|
|
stringBuilder.append(" ") // 确保翻页时索引计算正确
|
|
|
- textPages.last().addLine(textLine)
|
|
|
|
|
|
|
+ pendingTextPage.addLine(textLine)
|
|
|
}
|
|
}
|
|
|
return absStartX to durY + textHeight * paragraphSpacing / 10f
|
|
return absStartX to durY + textHeight * paragraphSpacing / 10f
|
|
|
}
|
|
}
|
|
@@ -403,8 +405,8 @@ class TextChapterLayout(
|
|
|
}
|
|
}
|
|
|
var durY = when {
|
|
var durY = when {
|
|
|
//标题y轴居中
|
|
//标题y轴居中
|
|
|
- emptyContent && textPages.size == 1 -> {
|
|
|
|
|
- val textPage = textPages.last()
|
|
|
|
|
|
|
+ emptyContent && textPages.isEmpty() -> {
|
|
|
|
|
+ val textPage = pendingTextPage
|
|
|
if (textPage.lineSize == 0) {
|
|
if (textPage.lineSize == 0) {
|
|
|
val ty = (visibleHeight - layout.lineCount * textHeight) / 2
|
|
val ty = (visibleHeight - layout.lineCount * textHeight) / 2
|
|
|
if (ty > titleTopSpacing) ty else titleTopSpacing.toFloat()
|
|
if (ty > titleTopSpacing) ty else titleTopSpacing.toFloat()
|
|
@@ -423,7 +425,7 @@ class TextChapterLayout(
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- isTitle && textPages.size == 1 && textPages.last().lines.isEmpty() ->
|
|
|
|
|
|
|
+ isTitle && textPages.isEmpty() && pendingTextPage.lines.isEmpty() ->
|
|
|
y + titleTopSpacing
|
|
y + titleTopSpacing
|
|
|
|
|
|
|
|
else -> y
|
|
else -> y
|
|
@@ -431,7 +433,7 @@ class TextChapterLayout(
|
|
|
for (lineIndex in 0 until layout.lineCount) {
|
|
for (lineIndex in 0 until layout.lineCount) {
|
|
|
val textLine = TextLine(isTitle = isTitle)
|
|
val textLine = TextLine(isTitle = isTitle)
|
|
|
if (durY + textHeight > visibleHeight) {
|
|
if (durY + textHeight > visibleHeight) {
|
|
|
- val textPage = textPages.last()
|
|
|
|
|
|
|
+ val textPage = pendingTextPage
|
|
|
if (doublePage && absStartX < viewWidth / 2) {
|
|
if (doublePage && absStartX < viewWidth / 2) {
|
|
|
//当前页面左列结束
|
|
//当前页面左列结束
|
|
|
textPage.leftLineSize = textPage.lineSize
|
|
textPage.leftLineSize = textPage.lineSize
|
|
@@ -442,10 +444,11 @@ class TextChapterLayout(
|
|
|
textPage.leftLineSize = textPage.lineSize
|
|
textPage.leftLineSize = textPage.lineSize
|
|
|
}
|
|
}
|
|
|
textPage.text = stringBuilder.toString()
|
|
textPage.text = stringBuilder.toString()
|
|
|
|
|
+ textPages.add(textPage)
|
|
|
coroutineContext.ensureActive()
|
|
coroutineContext.ensureActive()
|
|
|
onPageCompleted()
|
|
onPageCompleted()
|
|
|
//新建页面
|
|
//新建页面
|
|
|
- textPages.add(TextPage())
|
|
|
|
|
|
|
+ pendingTextPage = TextPage()
|
|
|
stringBuilder.clear()
|
|
stringBuilder.clear()
|
|
|
absStartX = paddingLeft
|
|
absStartX = paddingLeft
|
|
|
}
|
|
}
|
|
@@ -514,7 +517,7 @@ class TextChapterLayout(
|
|
|
calcTextLinePosition(textPages, textLine, stringBuilder.length)
|
|
calcTextLinePosition(textPages, textLine, stringBuilder.length)
|
|
|
stringBuilder.append(lineText)
|
|
stringBuilder.append(lineText)
|
|
|
textLine.upTopBottom(durY, textHeight, fontMetrics)
|
|
textLine.upTopBottom(durY, textHeight, fontMetrics)
|
|
|
- val textPage = textPages.last()
|
|
|
|
|
|
|
+ val textPage = pendingTextPage
|
|
|
textPage.addLine(textLine)
|
|
textPage.addLine(textLine)
|
|
|
durY += textHeight * lineSpacingExtra
|
|
durY += textHeight * lineSpacingExtra
|
|
|
if (textPage.height < durY) {
|
|
if (textPage.height < durY) {
|
|
@@ -530,8 +533,8 @@ class TextChapterLayout(
|
|
|
textLine: TextLine,
|
|
textLine: TextLine,
|
|
|
sbLength: Int
|
|
sbLength: Int
|
|
|
) {
|
|
) {
|
|
|
- val lastLine = textPages.last().lines.lastOrNull { it.paragraphNum > 0 }
|
|
|
|
|
- ?: textPages.getOrNull(textPages.lastIndex - 1)?.lines?.lastOrNull { it.paragraphNum > 0 }
|
|
|
|
|
|
|
+ val lastLine = pendingTextPage.lines.lastOrNull { it.paragraphNum > 0 }
|
|
|
|
|
+ ?: textPages.lastOrNull()?.lines?.lastOrNull { it.paragraphNum > 0 }
|
|
|
val paragraphNum = when {
|
|
val paragraphNum = when {
|
|
|
lastLine == null -> 1
|
|
lastLine == null -> 1
|
|
|
lastLine.isParagraphEnd -> lastLine.paragraphNum + 1
|
|
lastLine.isParagraphEnd -> lastLine.paragraphNum + 1
|
|
@@ -539,7 +542,7 @@ class TextChapterLayout(
|
|
|
}
|
|
}
|
|
|
textLine.paragraphNum = paragraphNum
|
|
textLine.paragraphNum = paragraphNum
|
|
|
textLine.chapterPosition =
|
|
textLine.chapterPosition =
|
|
|
- (textPages.getOrNull(textPages.lastIndex - 1)?.lines?.lastOrNull()?.run {
|
|
|
|
|
|
|
+ (textPages.lastOrNull()?.lines?.lastOrNull()?.run {
|
|
|
chapterPosition + charSize + if (isParagraphEnd) 1 else 0
|
|
chapterPosition + charSize + if (isParagraphEnd) 1 else 0
|
|
|
} ?: 0) + sbLength
|
|
} ?: 0) + sbLength
|
|
|
textLine.pagePosition = sbLength
|
|
textLine.pagePosition = sbLength
|