|
|
@ -66,19 +66,18 @@ object ChapterProvider { |
|
|
|
src = NetworkUtils.getAbsoluteURL(bookChapter.url, src) |
|
|
|
src = NetworkUtils.getAbsoluteURL(bookChapter.url, src) |
|
|
|
} |
|
|
|
} |
|
|
|
src?.let { |
|
|
|
src?.let { |
|
|
|
durY = |
|
|
|
durY = setTypeImage( |
|
|
|
setTypeImage( |
|
|
|
book, bookChapter, src, durY, textPages, imageStyle |
|
|
|
book, bookChapter, src, durY, textPages, imageStyle |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val isTitle = index == 0 |
|
|
|
val isTitle = index == 0 |
|
|
|
|
|
|
|
val textPaint = if (isTitle) titlePaint else contentPaint |
|
|
|
if (!(isTitle && ReadBookConfig.titleMode == 2)) { |
|
|
|
if (!(isTitle && ReadBookConfig.titleMode == 2)) { |
|
|
|
durY = |
|
|
|
durY = setTypeText( |
|
|
|
setTypeText( |
|
|
|
text, durY, textPages, pageLines, |
|
|
|
text, durY, textPages, pageLines, |
|
|
|
pageLengths, stringBuilder, isTitle, textPaint |
|
|
|
pageLengths, stringBuilder, isTitle |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -185,9 +184,9 @@ object ChapterProvider { |
|
|
|
pageLengths: ArrayList<Int>, |
|
|
|
pageLengths: ArrayList<Int>, |
|
|
|
stringBuilder: StringBuilder, |
|
|
|
stringBuilder: StringBuilder, |
|
|
|
isTitle: Boolean, |
|
|
|
isTitle: Boolean, |
|
|
|
|
|
|
|
textPaint: TextPaint |
|
|
|
): Float { |
|
|
|
): Float { |
|
|
|
var durY = if (isTitle) y + titleTopSpacing else y |
|
|
|
var durY = if (isTitle) y + titleTopSpacing else y |
|
|
|
val textPaint = if (isTitle) titlePaint else contentPaint |
|
|
|
|
|
|
|
val layout = StaticLayout( |
|
|
|
val layout = StaticLayout( |
|
|
|
text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true |
|
|
|
text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true |
|
|
|
) |
|
|
|
) |
|
|
@ -200,12 +199,7 @@ object ChapterProvider { |
|
|
|
if (lineIndex == 0 && layout.lineCount > 1 && !isTitle) { |
|
|
|
if (lineIndex == 0 && layout.lineCount > 1 && !isTitle) { |
|
|
|
//第一行 |
|
|
|
//第一行 |
|
|
|
textLine.text = words |
|
|
|
textLine.text = words |
|
|
|
addCharsToLineFirst( |
|
|
|
addCharsToLineFirst(textLine, words.toStringArray(), textPaint, desiredWidth) |
|
|
|
textLine, |
|
|
|
|
|
|
|
words.toStringArray(), |
|
|
|
|
|
|
|
textPaint, |
|
|
|
|
|
|
|
desiredWidth |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} else if (lineIndex == layout.lineCount - 1) { |
|
|
|
} else if (lineIndex == layout.lineCount - 1) { |
|
|
|
//最后一行 |
|
|
|
//最后一行 |
|
|
|
textLine.text = "$words\n" |
|
|
|
textLine.text = "$words\n" |
|
|
@ -213,22 +207,11 @@ object ChapterProvider { |
|
|
|
val x = if (isTitle && ReadBookConfig.titleMode == 1) |
|
|
|
val x = if (isTitle && ReadBookConfig.titleMode == 1) |
|
|
|
(visibleWidth - layout.getLineWidth(lineIndex)) / 2 |
|
|
|
(visibleWidth - layout.getLineWidth(lineIndex)) / 2 |
|
|
|
else 0f |
|
|
|
else 0f |
|
|
|
addCharsToLineLast( |
|
|
|
addCharsToLineLast(textLine, words.toStringArray(), textPaint, x) |
|
|
|
textLine, |
|
|
|
|
|
|
|
words.toStringArray(), |
|
|
|
|
|
|
|
textPaint, |
|
|
|
|
|
|
|
x |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
//中间行 |
|
|
|
//中间行 |
|
|
|
textLine.text = words |
|
|
|
textLine.text = words |
|
|
|
addCharsToLineMiddle( |
|
|
|
addCharsToLineMiddle(textLine, words.toStringArray(), textPaint, desiredWidth, 0f) |
|
|
|
textLine, |
|
|
|
|
|
|
|
words.toStringArray(), |
|
|
|
|
|
|
|
textPaint, |
|
|
|
|
|
|
|
desiredWidth, |
|
|
|
|
|
|
|
0f |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (durY + textPaint.textHeight > visibleHeight) { |
|
|
|
if (durY + textPaint.textHeight > visibleHeight) { |
|
|
|
//当前页面结束,设置各种值 |
|
|
|
//当前页面结束,设置各种值 |
|
|
@ -264,33 +247,18 @@ object ChapterProvider { |
|
|
|
) { |
|
|
|
) { |
|
|
|
var x = 0f |
|
|
|
var x = 0f |
|
|
|
if (!ReadBookConfig.textFullJustify) { |
|
|
|
if (!ReadBookConfig.textFullJustify) { |
|
|
|
addCharsToLineLast( |
|
|
|
addCharsToLineLast(textLine, words, textPaint, x) |
|
|
|
textLine, |
|
|
|
|
|
|
|
words, |
|
|
|
|
|
|
|
textPaint, |
|
|
|
|
|
|
|
x |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
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 { |
|
|
|
val x1 = x + icw |
|
|
|
val x1 = x + icw |
|
|
|
textLine.addTextChar( |
|
|
|
textLine.addTextChar(charData = it, start = paddingLeft + x, end = paddingLeft + x1) |
|
|
|
charData = it, |
|
|
|
|
|
|
|
start = paddingLeft + x, |
|
|
|
|
|
|
|
end = paddingLeft + x1 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
x = x1 |
|
|
|
x = x1 |
|
|
|
} |
|
|
|
} |
|
|
|
val words1 = words.copyOfRange(bodyIndent.length, words.size) |
|
|
|
val words1 = words.copyOfRange(bodyIndent.length, words.size) |
|
|
|
addCharsToLineMiddle( |
|
|
|
addCharsToLineMiddle(textLine, words1, textPaint, desiredWidth, x) |
|
|
|
textLine, |
|
|
|
|
|
|
|
words1, |
|
|
|
|
|
|
|
textPaint, |
|
|
|
|
|
|
|
desiredWidth, |
|
|
|
|
|
|
|
x |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -304,12 +272,7 @@ object ChapterProvider { |
|
|
|
startX: Float, |
|
|
|
startX: Float, |
|
|
|
) { |
|
|
|
) { |
|
|
|
if (!ReadBookConfig.textFullJustify) { |
|
|
|
if (!ReadBookConfig.textFullJustify) { |
|
|
|
addCharsToLineLast( |
|
|
|
addCharsToLineLast(textLine, words, textPaint, startX) |
|
|
|
textLine, |
|
|
|
|
|
|
|
words, |
|
|
|
|
|
|
|
textPaint, |
|
|
|
|
|
|
|
startX |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
val gapCount: Int = words.lastIndex |
|
|
|
val gapCount: Int = words.lastIndex |
|
|
@ -318,17 +281,10 @@ object ChapterProvider { |
|
|
|
words.forEachIndexed { index, s -> |
|
|
|
words.forEachIndexed { index, s -> |
|
|
|
val cw = StaticLayout.getDesiredWidth(s, textPaint) |
|
|
|
val cw = StaticLayout.getDesiredWidth(s, 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) |
|
|
|
textLine.addTextChar( |
|
|
|
textLine.addTextChar(charData = s, start = paddingLeft + x, end = paddingLeft + x1) |
|
|
|
charData = s, |
|
|
|
|
|
|
|
start = paddingLeft + x, |
|
|
|
|
|
|
|
end = paddingLeft + x1 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
x = x1 |
|
|
|
x = x1 |
|
|
|
} |
|
|
|
} |
|
|
|
exceed( |
|
|
|
exceed(textLine, words) |
|
|
|
textLine, |
|
|
|
|
|
|
|
words |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -344,17 +300,10 @@ object ChapterProvider { |
|
|
|
words.forEach { |
|
|
|
words.forEach { |
|
|
|
val cw = StaticLayout.getDesiredWidth(it, textPaint) |
|
|
|
val cw = StaticLayout.getDesiredWidth(it, textPaint) |
|
|
|
val x1 = x + cw |
|
|
|
val x1 = x + cw |
|
|
|
textLine.addTextChar( |
|
|
|
textLine.addTextChar(charData = it, start = paddingLeft + x, end = paddingLeft + x1) |
|
|
|
charData = it, |
|
|
|
|
|
|
|
start = paddingLeft + x, |
|
|
|
|
|
|
|
end = paddingLeft + x1 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
x = x1 |
|
|
|
x = x1 |
|
|
|
} |
|
|
|
} |
|
|
|
exceed( |
|
|
|
exceed(textLine, words) |
|
|
|
textLine, |
|
|
|
|
|
|
|
words |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|