|
|
@ -66,6 +66,7 @@ object ChapterProvider { |
|
|
|
|
|
|
|
|
|
|
|
@JvmStatic |
|
|
|
@JvmStatic |
|
|
|
var visibleBottom = 0 |
|
|
|
var visibleBottom = 0 |
|
|
|
|
|
|
|
private set |
|
|
|
|
|
|
|
|
|
|
|
@JvmStatic |
|
|
|
@JvmStatic |
|
|
|
private var lineSpacingExtra = 0 |
|
|
|
private var lineSpacingExtra = 0 |
|
|
@ -81,6 +82,7 @@ object ChapterProvider { |
|
|
|
|
|
|
|
|
|
|
|
@JvmStatic |
|
|
|
@JvmStatic |
|
|
|
var typeface: Typeface = Typeface.DEFAULT |
|
|
|
var typeface: Typeface = Typeface.DEFAULT |
|
|
|
|
|
|
|
private set |
|
|
|
|
|
|
|
|
|
|
|
@JvmStatic |
|
|
|
@JvmStatic |
|
|
|
val titlePaint: TextPaint = TextPaint() |
|
|
|
val titlePaint: TextPaint = TextPaint() |
|
|
@ -89,7 +91,7 @@ object ChapterProvider { |
|
|
|
val contentPaint: TextPaint = TextPaint() |
|
|
|
val contentPaint: TextPaint = TextPaint() |
|
|
|
|
|
|
|
|
|
|
|
var doublePage = false |
|
|
|
var doublePage = false |
|
|
|
|
|
|
|
private set |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
upStyle() |
|
|
|
upStyle() |
|
|
@ -375,11 +377,13 @@ object ChapterProvider { |
|
|
|
} |
|
|
|
} |
|
|
|
val bodyIndent = ReadBookConfig.paragraphIndent |
|
|
|
val bodyIndent = ReadBookConfig.paragraphIndent |
|
|
|
val icw = StaticLayout.getDesiredWidth(bodyIndent, textPaint) / bodyIndent.length |
|
|
|
val icw = StaticLayout.getDesiredWidth(bodyIndent, textPaint) / bodyIndent.length |
|
|
|
bodyIndent.toStringArray().forEach { |
|
|
|
bodyIndent.toStringArray().forEach { char -> |
|
|
|
val x1 = x + icw |
|
|
|
val x1 = x + icw |
|
|
|
textLine.textChars.add( |
|
|
|
textLine.textChars.add( |
|
|
|
TextChar( |
|
|
|
TextChar( |
|
|
|
it, start = absStartX + x, end = absStartX + x1 |
|
|
|
charData = char, |
|
|
|
|
|
|
|
start = absStartX + x, |
|
|
|
|
|
|
|
end = absStartX + x1 |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
x = x1 |
|
|
|
x = x1 |
|
|
@ -409,13 +413,13 @@ object ChapterProvider { |
|
|
|
val gapCount: Int = words.lastIndex |
|
|
|
val gapCount: Int = words.lastIndex |
|
|
|
val d = (visibleWidth - desiredWidth) / gapCount |
|
|
|
val d = (visibleWidth - desiredWidth) / gapCount |
|
|
|
var x = startX |
|
|
|
var x = startX |
|
|
|
words.forEachIndexed { index, s -> |
|
|
|
words.forEachIndexed { index, char -> |
|
|
|
val cw = StaticLayout.getDesiredWidth(s, 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 && s == srcReplaceChar) { |
|
|
|
if (srcList != null && char == srcReplaceChar) { |
|
|
|
textLine.textChars.add( |
|
|
|
textLine.textChars.add( |
|
|
|
TextChar( |
|
|
|
TextChar( |
|
|
|
srcList.removeFirst(), |
|
|
|
charData = srcList.removeFirst(), |
|
|
|
start = absStartX + x, |
|
|
|
start = absStartX + x, |
|
|
|
end = absStartX + x1, |
|
|
|
end = absStartX + x1, |
|
|
|
isImage = true |
|
|
|
isImage = true |
|
|
@ -424,13 +428,15 @@ object ChapterProvider { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
textLine.textChars.add( |
|
|
|
textLine.textChars.add( |
|
|
|
TextChar( |
|
|
|
TextChar( |
|
|
|
s, start = absStartX + x, end = absStartX + x1 |
|
|
|
charData = char, |
|
|
|
|
|
|
|
start = absStartX + x, |
|
|
|
|
|
|
|
end = absStartX + x1 |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
x = x1 |
|
|
|
x = x1 |
|
|
|
} |
|
|
|
} |
|
|
|
exceed(textLine, words) |
|
|
|
exceed(absStartX, textLine, words) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -445,13 +451,13 @@ object ChapterProvider { |
|
|
|
srcList: LinkedList<String>? |
|
|
|
srcList: LinkedList<String>? |
|
|
|
) { |
|
|
|
) { |
|
|
|
var x = startX |
|
|
|
var x = startX |
|
|
|
words.forEach { |
|
|
|
words.forEach { char -> |
|
|
|
val cw = StaticLayout.getDesiredWidth(it, textPaint) |
|
|
|
val cw = StaticLayout.getDesiredWidth(char, textPaint) |
|
|
|
val x1 = x + cw |
|
|
|
val x1 = x + cw |
|
|
|
if (srcList != null && it == srcReplaceChar) { |
|
|
|
if (srcList != null && char == srcReplaceChar) { |
|
|
|
textLine.textChars.add( |
|
|
|
textLine.textChars.add( |
|
|
|
TextChar( |
|
|
|
TextChar( |
|
|
|
srcList.removeFirst(), |
|
|
|
charData = srcList.removeFirst(), |
|
|
|
start = absStartX + x, |
|
|
|
start = absStartX + x, |
|
|
|
end = absStartX + x1, |
|
|
|
end = absStartX + x1, |
|
|
|
isImage = true |
|
|
|
isImage = true |
|
|
@ -460,30 +466,33 @@ object ChapterProvider { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
textLine.textChars.add( |
|
|
|
textLine.textChars.add( |
|
|
|
TextChar( |
|
|
|
TextChar( |
|
|
|
it, start = absStartX + x, end = absStartX + x1 |
|
|
|
charData = char, |
|
|
|
|
|
|
|
start = absStartX + x, |
|
|
|
|
|
|
|
end = absStartX + x1 |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
x = x1 |
|
|
|
x = x1 |
|
|
|
} |
|
|
|
} |
|
|
|
exceed(textLine, words) |
|
|
|
exceed(absStartX, textLine, words) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 超出边界处理 |
|
|
|
* 超出边界处理 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun exceed(textLine: TextLine, words: Array<String>) { |
|
|
|
private fun exceed(absStartX: Int, textLine: TextLine, words: Array<String>) { |
|
|
|
// val endX = textLine.textChars.lastOrNull()?.end ?: return |
|
|
|
val visibleEnd = absStartX + visibleWidth |
|
|
|
// if (endX > visibleRight) { |
|
|
|
val endX = textLine.textChars.lastOrNull()?.end ?: return |
|
|
|
// val cc = (endX - visibleRight) / words.size |
|
|
|
if (endX > visibleEnd) { |
|
|
|
// for (i in 0..words.lastIndex) { |
|
|
|
val cc = (endX - visibleEnd) / words.size |
|
|
|
// textLine.getTextCharReverseAt(i).let { |
|
|
|
for (i in 0..words.lastIndex) { |
|
|
|
// val py = cc * (words.size - i) |
|
|
|
textLine.getTextCharReverseAt(i).let { |
|
|
|
// it.start = it.start - py |
|
|
|
val py = cc * (words.size - i) |
|
|
|
// it.end = it.end - py |
|
|
|
it.start = it.start - py |
|
|
|
// } |
|
|
|
it.end = it.end - py |
|
|
|
// } |
|
|
|
} |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|