|
|
@ -116,7 +116,7 @@ object ChapterProvider { |
|
|
|
if (ReadBookConfig.titleMode != 2) { |
|
|
|
if (ReadBookConfig.titleMode != 2) { |
|
|
|
displayTitle.splitNotBlank("\n").forEach { text -> |
|
|
|
displayTitle.splitNotBlank("\n").forEach { text -> |
|
|
|
setTypeText( |
|
|
|
setTypeText( |
|
|
|
absStartX, durY, text, textPages, stringBuilder, titlePaint, |
|
|
|
book, absStartX, durY, text, textPages, stringBuilder, titlePaint, |
|
|
|
isTitle = true, |
|
|
|
isTitle = true, |
|
|
|
isTitleWithNoContent = contents.isEmpty(), |
|
|
|
isTitleWithNoContent = contents.isEmpty(), |
|
|
|
isVolumeTitle = bookChapter.isVolume |
|
|
|
isVolumeTitle = bookChapter.isVolume |
|
|
@ -142,7 +142,7 @@ object ChapterProvider { |
|
|
|
matcher.appendTail(sb) |
|
|
|
matcher.appendTail(sb) |
|
|
|
text = sb.toString() |
|
|
|
text = sb.toString() |
|
|
|
setTypeText( |
|
|
|
setTypeText( |
|
|
|
absStartX, durY, text, textPages, stringBuilder, contentPaint, |
|
|
|
book, absStartX, durY, text, textPages, stringBuilder, contentPaint, |
|
|
|
srcList = srcList |
|
|
|
srcList = srcList |
|
|
|
).let { |
|
|
|
).let { |
|
|
|
absStartX = it.first |
|
|
|
absStartX = it.first |
|
|
@ -155,7 +155,7 @@ object ChapterProvider { |
|
|
|
val text = content.substring(start, matcher.start()) |
|
|
|
val text = content.substring(start, matcher.start()) |
|
|
|
if (text.isNotBlank()) { |
|
|
|
if (text.isNotBlank()) { |
|
|
|
setTypeText( |
|
|
|
setTypeText( |
|
|
|
absStartX, durY, text, textPages, stringBuilder, contentPaint |
|
|
|
book, absStartX, durY, text, textPages, stringBuilder, contentPaint |
|
|
|
).let { |
|
|
|
).let { |
|
|
|
absStartX = it.first |
|
|
|
absStartX = it.first |
|
|
|
durY = it.second |
|
|
|
durY = it.second |
|
|
@ -171,7 +171,7 @@ object ChapterProvider { |
|
|
|
val text = content.substring(start, content.length) |
|
|
|
val text = content.substring(start, content.length) |
|
|
|
if (text.isNotBlank()) { |
|
|
|
if (text.isNotBlank()) { |
|
|
|
setTypeText( |
|
|
|
setTypeText( |
|
|
|
absStartX, durY, text, textPages, stringBuilder, contentPaint |
|
|
|
book, absStartX, durY, text, textPages, stringBuilder, contentPaint |
|
|
|
).let { |
|
|
|
).let { |
|
|
|
absStartX = it.first |
|
|
|
absStartX = it.first |
|
|
|
durY = it.second |
|
|
|
durY = it.second |
|
|
@ -199,6 +199,9 @@ object ChapterProvider { |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 排版图片 |
|
|
|
|
|
|
|
*/ |
|
|
|
private suspend fun setTypeImage( |
|
|
|
private suspend fun setTypeImage( |
|
|
|
book: Book, |
|
|
|
book: Book, |
|
|
|
src: String, |
|
|
|
src: String, |
|
|
@ -264,7 +267,8 @@ object ChapterProvider { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 排版文字 |
|
|
|
* 排版文字 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun setTypeText( |
|
|
|
private suspend fun setTypeText( |
|
|
|
|
|
|
|
book: Book, |
|
|
|
x: Int, |
|
|
|
x: Int, |
|
|
|
y: Float, |
|
|
|
y: Float, |
|
|
|
text: String, |
|
|
|
text: String, |
|
|
@ -336,12 +340,8 @@ object ChapterProvider { |
|
|
|
//第一行 非标题 |
|
|
|
//第一行 非标题 |
|
|
|
textLine.text = words |
|
|
|
textLine.text = words |
|
|
|
addCharsToLineFirst( |
|
|
|
addCharsToLineFirst( |
|
|
|
absStartX, |
|
|
|
book, absStartX, textLine, words.toStringArray(), |
|
|
|
textLine, |
|
|
|
textPaint, desiredWidth, srcList |
|
|
|
words.toStringArray(), |
|
|
|
|
|
|
|
textPaint, |
|
|
|
|
|
|
|
desiredWidth, |
|
|
|
|
|
|
|
srcList |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
lineIndex == layout.lineCount - 1 -> { |
|
|
|
lineIndex == layout.lineCount - 1 -> { |
|
|
@ -354,25 +354,16 @@ object ChapterProvider { |
|
|
|
(visibleWidth - layout.getLineWidth(lineIndex)) / 2 |
|
|
|
(visibleWidth - layout.getLineWidth(lineIndex)) / 2 |
|
|
|
else 0f |
|
|
|
else 0f |
|
|
|
addCharsToLineLast( |
|
|
|
addCharsToLineLast( |
|
|
|
absStartX, |
|
|
|
book, absStartX, textLine, words.toStringArray(), |
|
|
|
textLine, |
|
|
|
textPaint, startX, srcList |
|
|
|
words.toStringArray(), |
|
|
|
|
|
|
|
textPaint, |
|
|
|
|
|
|
|
startX, |
|
|
|
|
|
|
|
srcList |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
else -> { |
|
|
|
else -> { |
|
|
|
//中间行 |
|
|
|
//中间行 |
|
|
|
textLine.text = words |
|
|
|
textLine.text = words |
|
|
|
addCharsToLineMiddle( |
|
|
|
addCharsToLineMiddle( |
|
|
|
absStartX, |
|
|
|
book, absStartX, textLine, words.toStringArray(), |
|
|
|
textLine, |
|
|
|
textPaint, desiredWidth, 0f, srcList |
|
|
|
words.toStringArray(), |
|
|
|
|
|
|
|
textPaint, |
|
|
|
|
|
|
|
desiredWidth, |
|
|
|
|
|
|
|
0f, |
|
|
|
|
|
|
|
srcList |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -392,7 +383,8 @@ object ChapterProvider { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 有缩进,两端对齐 |
|
|
|
* 有缩进,两端对齐 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun addCharsToLineFirst( |
|
|
|
private suspend fun addCharsToLineFirst( |
|
|
|
|
|
|
|
book: Book, |
|
|
|
absStartX: Int, |
|
|
|
absStartX: Int, |
|
|
|
textLine: TextLine, |
|
|
|
textLine: TextLine, |
|
|
|
words: Array<String>, |
|
|
|
words: Array<String>, |
|
|
@ -402,7 +394,7 @@ object ChapterProvider { |
|
|
|
) { |
|
|
|
) { |
|
|
|
var x = 0f |
|
|
|
var x = 0f |
|
|
|
if (!ReadBookConfig.textFullJustify) { |
|
|
|
if (!ReadBookConfig.textFullJustify) { |
|
|
|
addCharsToLineLast(absStartX, textLine, words, textPaint, x, srcList) |
|
|
|
addCharsToLineLast(book, absStartX, textLine, words, textPaint, x, srcList) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
val bodyIndent = ReadBookConfig.paragraphIndent |
|
|
|
val bodyIndent = ReadBookConfig.paragraphIndent |
|
|
@ -420,14 +412,17 @@ object ChapterProvider { |
|
|
|
} |
|
|
|
} |
|
|
|
if (words.size > bodyIndent.length) { |
|
|
|
if (words.size > bodyIndent.length) { |
|
|
|
val words1 = words.copyOfRange(bodyIndent.length, words.size) |
|
|
|
val words1 = words.copyOfRange(bodyIndent.length, words.size) |
|
|
|
addCharsToLineMiddle(absStartX, textLine, words1, textPaint, desiredWidth, x, srcList) |
|
|
|
addCharsToLineMiddle( |
|
|
|
|
|
|
|
book, absStartX, textLine, words1, textPaint, desiredWidth, x, srcList |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 无缩进,两端对齐 |
|
|
|
* 无缩进,两端对齐 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun addCharsToLineMiddle( |
|
|
|
private suspend fun addCharsToLineMiddle( |
|
|
|
|
|
|
|
book: Book, |
|
|
|
absStartX: Int, |
|
|
|
absStartX: Int, |
|
|
|
textLine: TextLine, |
|
|
|
textLine: TextLine, |
|
|
|
words: Array<String>, |
|
|
|
words: Array<String>, |
|
|
@ -437,7 +432,7 @@ object ChapterProvider { |
|
|
|
srcList: LinkedList<String>? |
|
|
|
srcList: LinkedList<String>? |
|
|
|
) { |
|
|
|
) { |
|
|
|
if (!ReadBookConfig.textFullJustify) { |
|
|
|
if (!ReadBookConfig.textFullJustify) { |
|
|
|
addCharsToLineLast(absStartX, textLine, words, textPaint, startX, srcList) |
|
|
|
addCharsToLineLast(book, absStartX, textLine, words, textPaint, startX, srcList) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
val gapCount: Int = words.lastIndex |
|
|
|
val gapCount: Int = words.lastIndex |
|
|
@ -446,24 +441,7 @@ object ChapterProvider { |
|
|
|
words.forEachIndexed { index, char -> |
|
|
|
words.forEachIndexed { index, char -> |
|
|
|
val cw = StaticLayout.getDesiredWidth(char, textPaint) |
|
|
|
val cw = StaticLayout.getDesiredWidth(char, textPaint) |
|
|
|
val x1 = if (index != words.lastIndex) (x + cw + d) else (x + cw) |
|
|
|
val x1 = if (index != words.lastIndex) (x + cw + d) else (x + cw) |
|
|
|
if (srcList != null && char == srcReplaceChar) { |
|
|
|
addCharToLine(book, absStartX, textLine, char, x, x1, srcList) |
|
|
|
textLine.textChars.add( |
|
|
|
|
|
|
|
TextChar( |
|
|
|
|
|
|
|
charData = srcList.removeFirst(), |
|
|
|
|
|
|
|
start = absStartX + x, |
|
|
|
|
|
|
|
end = absStartX + x1, |
|
|
|
|
|
|
|
isImage = true |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
textLine.textChars.add( |
|
|
|
|
|
|
|
TextChar( |
|
|
|
|
|
|
|
charData = char, |
|
|
|
|
|
|
|
start = absStartX + x, |
|
|
|
|
|
|
|
end = absStartX + x1 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
x = x1 |
|
|
|
x = x1 |
|
|
|
} |
|
|
|
} |
|
|
|
exceed(absStartX, textLine, words) |
|
|
|
exceed(absStartX, textLine, words) |
|
|
@ -472,7 +450,8 @@ object ChapterProvider { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 最后一行,自然排列 |
|
|
|
* 最后一行,自然排列 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun addCharsToLineLast( |
|
|
|
private suspend fun addCharsToLineLast( |
|
|
|
|
|
|
|
book: Book, |
|
|
|
absStartX: Int, |
|
|
|
absStartX: Int, |
|
|
|
textLine: TextLine, |
|
|
|
textLine: TextLine, |
|
|
|
words: Array<String>, |
|
|
|
words: Array<String>, |
|
|
@ -484,12 +463,32 @@ object ChapterProvider { |
|
|
|
words.forEach { char -> |
|
|
|
words.forEach { char -> |
|
|
|
val cw = StaticLayout.getDesiredWidth(char, textPaint) |
|
|
|
val cw = StaticLayout.getDesiredWidth(char, textPaint) |
|
|
|
val x1 = x + cw |
|
|
|
val x1 = x + cw |
|
|
|
|
|
|
|
addCharToLine(book, absStartX, textLine, char, x, x1, srcList) |
|
|
|
|
|
|
|
x = x1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
exceed(absStartX, textLine, words) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 添加字符 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private suspend fun addCharToLine( |
|
|
|
|
|
|
|
book: Book, |
|
|
|
|
|
|
|
absStartX: Int, |
|
|
|
|
|
|
|
textLine: TextLine, |
|
|
|
|
|
|
|
char: String, |
|
|
|
|
|
|
|
xStart: Float, |
|
|
|
|
|
|
|
xEnd: Float, |
|
|
|
|
|
|
|
srcList: LinkedList<String>? |
|
|
|
|
|
|
|
) { |
|
|
|
if (srcList != null && char == srcReplaceChar) { |
|
|
|
if (srcList != null && char == srcReplaceChar) { |
|
|
|
|
|
|
|
val src = srcList.removeFirst() |
|
|
|
|
|
|
|
ImageProvider.cacheImage(book, src, ReadBook.bookSource) |
|
|
|
textLine.textChars.add( |
|
|
|
textLine.textChars.add( |
|
|
|
TextChar( |
|
|
|
TextChar( |
|
|
|
charData = srcList.removeFirst(), |
|
|
|
charData = src, |
|
|
|
start = absStartX + x, |
|
|
|
start = absStartX + xStart, |
|
|
|
end = absStartX + x1, |
|
|
|
end = absStartX + xEnd, |
|
|
|
isImage = true |
|
|
|
isImage = true |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
@ -497,14 +496,11 @@ object ChapterProvider { |
|
|
|
textLine.textChars.add( |
|
|
|
textLine.textChars.add( |
|
|
|
TextChar( |
|
|
|
TextChar( |
|
|
|
charData = char, |
|
|
|
charData = char, |
|
|
|
start = absStartX + x, |
|
|
|
start = absStartX + xStart, |
|
|
|
end = absStartX + x1 |
|
|
|
end = absStartX + xEnd |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
x = x1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
exceed(absStartX, textLine, words) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|