|
|
@ -136,7 +136,7 @@ object ChapterProvider { |
|
|
|
stringBuilder, |
|
|
|
stringBuilder, |
|
|
|
titlePaint, |
|
|
|
titlePaint, |
|
|
|
isTitle = true, |
|
|
|
isTitle = true, |
|
|
|
isTitleWithNoContent = contents.isEmpty(), |
|
|
|
emptyContent = contents.isEmpty(), |
|
|
|
isVolumeTitle = bookChapter.isVolume |
|
|
|
isVolumeTitle = bookChapter.isVolume |
|
|
|
).let { |
|
|
|
).let { |
|
|
|
absStartX = it.first |
|
|
|
absStartX = it.first |
|
|
@ -295,7 +295,7 @@ object ChapterProvider { |
|
|
|
stringBuilder: StringBuilder, |
|
|
|
stringBuilder: StringBuilder, |
|
|
|
textPaint: TextPaint, |
|
|
|
textPaint: TextPaint, |
|
|
|
isTitle: Boolean = false, |
|
|
|
isTitle: Boolean = false, |
|
|
|
isTitleWithNoContent: Boolean = false, |
|
|
|
emptyContent: Boolean = false, |
|
|
|
isVolumeTitle: Boolean = false, |
|
|
|
isVolumeTitle: Boolean = false, |
|
|
|
srcList: LinkedList<String>? = null |
|
|
|
srcList: LinkedList<String>? = null |
|
|
|
): Pair<Int, Float> { |
|
|
|
): Pair<Int, Float> { |
|
|
@ -307,7 +307,7 @@ object ChapterProvider { |
|
|
|
} |
|
|
|
} |
|
|
|
var durY = when { |
|
|
|
var durY = when { |
|
|
|
//标题y轴居中 |
|
|
|
//标题y轴居中 |
|
|
|
isTitleWithNoContent && textPages.size == 1 -> { |
|
|
|
emptyContent && textPages.size == 1 -> { |
|
|
|
val textPage = textPages.last() |
|
|
|
val textPage = textPages.last() |
|
|
|
if (textPage.lineSize == 0) { |
|
|
|
if (textPage.lineSize == 0) { |
|
|
|
val ty = (visibleHeight - layout.lineCount * textPaint.textHeight) / 2 |
|
|
|
val ty = (visibleHeight - layout.lineCount * textPaint.textHeight) / 2 |
|
|
@ -368,9 +368,9 @@ object ChapterProvider { |
|
|
|
textLine.text = words |
|
|
|
textLine.text = words |
|
|
|
textLine.isParagraphEnd = true |
|
|
|
textLine.isParagraphEnd = true |
|
|
|
//标题x轴居中 |
|
|
|
//标题x轴居中 |
|
|
|
val startX = if (isTitle && ReadBookConfig.titleMode == 1 |
|
|
|
val startX = if ( |
|
|
|
|| isTitleWithNoContent |
|
|
|
isTitle && |
|
|
|
|| isVolumeTitle |
|
|
|
(ReadBookConfig.isMiddleTitle || emptyContent || isVolumeTitle) |
|
|
|
) { |
|
|
|
) { |
|
|
|
(visibleWidth - layout.getLineWidth(lineIndex)) / 2 |
|
|
|
(visibleWidth - layout.getLineWidth(lineIndex)) / 2 |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -382,12 +382,24 @@ object ChapterProvider { |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
else -> { |
|
|
|
else -> { |
|
|
|
//中间行 |
|
|
|
if ( |
|
|
|
textLine.text = words |
|
|
|
isTitle && |
|
|
|
addCharsToLineMiddle( |
|
|
|
(ReadBookConfig.isMiddleTitle || emptyContent || isVolumeTitle) |
|
|
|
book, absStartX, textLine, words.toStringArray(), |
|
|
|
) { |
|
|
|
textPaint, desiredWidth, 0f, srcList |
|
|
|
//标题居中 |
|
|
|
) |
|
|
|
val startX = (visibleWidth - layout.getLineWidth(lineIndex)) / 2 |
|
|
|
|
|
|
|
addCharsToLineNatural( |
|
|
|
|
|
|
|
book, absStartX, textLine, words.toStringArray(), |
|
|
|
|
|
|
|
textPaint, startX, srcList |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//中间行 |
|
|
|
|
|
|
|
textLine.text = words |
|
|
|
|
|
|
|
addCharsToLineMiddle( |
|
|
|
|
|
|
|
book, absStartX, textLine, words.toStringArray(), |
|
|
|
|
|
|
|
textPaint, desiredWidth, 0f, srcList |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
stringBuilder.append(words) |
|
|
|
stringBuilder.append(words) |
|
|
@ -412,6 +424,7 @@ object ChapterProvider { |
|
|
|
textLine: TextLine, |
|
|
|
textLine: TextLine, |
|
|
|
words: Array<String>, |
|
|
|
words: Array<String>, |
|
|
|
textPaint: TextPaint, |
|
|
|
textPaint: TextPaint, |
|
|
|
|
|
|
|
/**自然排版长度**/ |
|
|
|
desiredWidth: Float, |
|
|
|
desiredWidth: Float, |
|
|
|
srcList: LinkedList<String>? |
|
|
|
srcList: LinkedList<String>? |
|
|
|
) { |
|
|
|
) { |
|
|
@ -436,7 +449,8 @@ 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( |
|
|
|
addCharsToLineMiddle( |
|
|
|
book, absStartX, textLine, words1, textPaint, desiredWidth, x, srcList |
|
|
|
book, absStartX, textLine, words1, |
|
|
|
|
|
|
|
textPaint, desiredWidth, x, srcList |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -450,7 +464,9 @@ object ChapterProvider { |
|
|
|
textLine: TextLine, |
|
|
|
textLine: TextLine, |
|
|
|
words: Array<String>, |
|
|
|
words: Array<String>, |
|
|
|
textPaint: TextPaint, |
|
|
|
textPaint: TextPaint, |
|
|
|
|
|
|
|
/**自然排版长度**/ |
|
|
|
desiredWidth: Float, |
|
|
|
desiredWidth: Float, |
|
|
|
|
|
|
|
/**起始x坐标**/ |
|
|
|
startX: Float, |
|
|
|
startX: Float, |
|
|
|
srcList: LinkedList<String>? |
|
|
|
srcList: LinkedList<String>? |
|
|
|
) { |
|
|
|
) { |
|
|
@ -458,9 +474,10 @@ object ChapterProvider { |
|
|
|
addCharsToLineNatural(book, absStartX, textLine, words, textPaint, startX, srcList) |
|
|
|
addCharsToLineNatural(book, absStartX, textLine, words, textPaint, startX, srcList) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
val residualWidth = visibleWidth - desiredWidth |
|
|
|
val spaceSize = words.filter { it == " " }.size |
|
|
|
val spaceSize = words.filter { it == " " }.size |
|
|
|
if (spaceSize > 0) { |
|
|
|
if (spaceSize > 0) { |
|
|
|
val d = (visibleWidth - desiredWidth) / spaceSize |
|
|
|
val d = residualWidth / spaceSize |
|
|
|
var x = startX |
|
|
|
var x = startX |
|
|
|
words.forEachIndexed { index, char -> |
|
|
|
words.forEachIndexed { index, char -> |
|
|
|
val cw = StaticLayout.getDesiredWidth(char, textPaint) |
|
|
|
val cw = StaticLayout.getDesiredWidth(char, textPaint) |
|
|
@ -469,17 +486,23 @@ object ChapterProvider { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
(x + cw) |
|
|
|
(x + cw) |
|
|
|
} |
|
|
|
} |
|
|
|
addCharToLine(book, absStartX, textLine, char, x, x1, index + 1 == words.size, srcList) |
|
|
|
addCharToLine( |
|
|
|
|
|
|
|
book, absStartX, textLine, char, |
|
|
|
|
|
|
|
x, x1, index + 1 == words.size, srcList |
|
|
|
|
|
|
|
) |
|
|
|
x = x1 |
|
|
|
x = x1 |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val gapCount: Int = words.lastIndex |
|
|
|
val gapCount: Int = words.lastIndex |
|
|
|
val d = (visibleWidth - desiredWidth) / gapCount |
|
|
|
val d = residualWidth / gapCount |
|
|
|
var x = startX |
|
|
|
var x = startX |
|
|
|
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) |
|
|
|
addCharToLine(book, absStartX, textLine, char, x, x1, index + 1 == words.size, srcList) |
|
|
|
addCharToLine( |
|
|
|
|
|
|
|
book, absStartX, textLine, char, |
|
|
|
|
|
|
|
x, x1, index + 1 == words.size, srcList |
|
|
|
|
|
|
|
) |
|
|
|
x = x1 |
|
|
|
x = x1 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|