|
|
@ -1,4 +1,4 @@ |
|
|
|
package io.legado.app.ui.book.read.page |
|
|
|
package io.legado.app.ui.book.read.page.provider |
|
|
|
|
|
|
|
|
|
|
|
import android.graphics.Typeface |
|
|
|
import android.graphics.Typeface |
|
|
|
import android.os.Build |
|
|
|
import android.os.Build |
|
|
@ -67,19 +67,21 @@ object ChapterProvider { |
|
|
|
src = NetworkUtils.getAbsoluteURL(bookChapter.url, src) |
|
|
|
src = NetworkUtils.getAbsoluteURL(bookChapter.url, src) |
|
|
|
} |
|
|
|
} |
|
|
|
src?.let { |
|
|
|
src?.let { |
|
|
|
durY = setTypeImage( |
|
|
|
durY = |
|
|
|
book, src, durY, |
|
|
|
setTypeImage( |
|
|
|
textPages, pageLines, |
|
|
|
book, src, durY, |
|
|
|
pageLengths, stringBuilder |
|
|
|
textPages, pageLines, |
|
|
|
) |
|
|
|
pageLengths, stringBuilder |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val isTitle = index == 0 |
|
|
|
val isTitle = index == 0 |
|
|
|
if (!(isTitle && ReadBookConfig.titleMode == 2)) { |
|
|
|
if (!(isTitle && ReadBookConfig.titleMode == 2)) { |
|
|
|
durY = setTypeText( |
|
|
|
durY = |
|
|
|
text, durY, textPages, pageLines, |
|
|
|
setTypeText( |
|
|
|
pageLengths, stringBuilder, isTitle |
|
|
|
text, durY, textPages, pageLines, |
|
|
|
) |
|
|
|
pageLengths, stringBuilder, isTitle |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -126,11 +128,13 @@ object ChapterProvider { |
|
|
|
var width = it.width |
|
|
|
var width = it.width |
|
|
|
if (it.width > visibleWidth) { |
|
|
|
if (it.width > visibleWidth) { |
|
|
|
height = it.height * visibleWidth / it.width |
|
|
|
height = it.height * visibleWidth / it.width |
|
|
|
width = visibleWidth |
|
|
|
width = |
|
|
|
|
|
|
|
visibleWidth |
|
|
|
} |
|
|
|
} |
|
|
|
if (height > visibleHeight) { |
|
|
|
if (height > visibleHeight) { |
|
|
|
width = width * visibleHeight / height |
|
|
|
width = width * visibleHeight / height |
|
|
|
height = visibleHeight |
|
|
|
height = |
|
|
|
|
|
|
|
visibleHeight |
|
|
|
} |
|
|
|
} |
|
|
|
if (durY + height > visibleHeight) { |
|
|
|
if (durY + height > visibleHeight) { |
|
|
|
textPages.add(TextPage()) |
|
|
|
textPages.add(TextPage()) |
|
|
@ -177,7 +181,8 @@ object ChapterProvider { |
|
|
|
var durY = if (isTitle) y + titleTopSpacing else y |
|
|
|
var durY = if (isTitle) y + titleTopSpacing else y |
|
|
|
val textPaint = if (isTitle) titlePaint else contentPaint |
|
|
|
val textPaint = if (isTitle) titlePaint else contentPaint |
|
|
|
val layout = StaticLayout( |
|
|
|
val layout = StaticLayout( |
|
|
|
text, textPaint, visibleWidth, |
|
|
|
text, textPaint, |
|
|
|
|
|
|
|
visibleWidth, |
|
|
|
Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true |
|
|
|
Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true |
|
|
|
) |
|
|
|
) |
|
|
|
for (lineIndex in 0 until layout.lineCount) { |
|
|
|
for (lineIndex in 0 until layout.lineCount) { |
|
|
@ -189,7 +194,12 @@ object ChapterProvider { |
|
|
|
if (lineIndex == 0 && layout.lineCount > 1 && !isTitle) { |
|
|
|
if (lineIndex == 0 && layout.lineCount > 1 && !isTitle) { |
|
|
|
//第一行 |
|
|
|
//第一行 |
|
|
|
textLine.text = words |
|
|
|
textLine.text = words |
|
|
|
addCharsToLineFirst(textLine, words.toStringArray(), textPaint, desiredWidth) |
|
|
|
addCharsToLineFirst( |
|
|
|
|
|
|
|
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" |
|
|
@ -197,11 +207,22 @@ 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(textLine, words.toStringArray(), textPaint, x) |
|
|
|
addCharsToLineLast( |
|
|
|
|
|
|
|
textLine, |
|
|
|
|
|
|
|
words.toStringArray(), |
|
|
|
|
|
|
|
textPaint, |
|
|
|
|
|
|
|
x |
|
|
|
|
|
|
|
) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
//中间行 |
|
|
|
//中间行 |
|
|
|
textLine.text = words |
|
|
|
textLine.text = words |
|
|
|
addCharsToLineMiddle(textLine, words.toStringArray(), textPaint, desiredWidth, 0f) |
|
|
|
addCharsToLineMiddle( |
|
|
|
|
|
|
|
textLine, |
|
|
|
|
|
|
|
words.toStringArray(), |
|
|
|
|
|
|
|
textPaint, |
|
|
|
|
|
|
|
desiredWidth, |
|
|
|
|
|
|
|
0f |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
if (durY + textPaint.textHeight > visibleHeight) { |
|
|
|
if (durY + textPaint.textHeight > visibleHeight) { |
|
|
|
//当前页面结束,设置各种值 |
|
|
|
//当前页面结束,设置各种值 |
|
|
@ -237,7 +258,12 @@ object ChapterProvider { |
|
|
|
) { |
|
|
|
) { |
|
|
|
var x = 0f |
|
|
|
var x = 0f |
|
|
|
if (!ReadBookConfig.textFullJustify) { |
|
|
|
if (!ReadBookConfig.textFullJustify) { |
|
|
|
addCharsToLineLast(textLine, words, textPaint, x) |
|
|
|
addCharsToLineLast( |
|
|
|
|
|
|
|
textLine, |
|
|
|
|
|
|
|
words, |
|
|
|
|
|
|
|
textPaint, |
|
|
|
|
|
|
|
x |
|
|
|
|
|
|
|
) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
val bodyIndent = ReadBookConfig.bodyIndent |
|
|
|
val bodyIndent = ReadBookConfig.bodyIndent |
|
|
@ -252,7 +278,13 @@ object ChapterProvider { |
|
|
|
x = x1 |
|
|
|
x = x1 |
|
|
|
} |
|
|
|
} |
|
|
|
val words1 = words.copyOfRange(bodyIndent.length, words.size) |
|
|
|
val words1 = words.copyOfRange(bodyIndent.length, words.size) |
|
|
|
addCharsToLineMiddle(textLine, words1, textPaint, desiredWidth, x) |
|
|
|
addCharsToLineMiddle( |
|
|
|
|
|
|
|
textLine, |
|
|
|
|
|
|
|
words1, |
|
|
|
|
|
|
|
textPaint, |
|
|
|
|
|
|
|
desiredWidth, |
|
|
|
|
|
|
|
x |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -266,7 +298,12 @@ object ChapterProvider { |
|
|
|
startX: Float |
|
|
|
startX: Float |
|
|
|
) { |
|
|
|
) { |
|
|
|
if (!ReadBookConfig.textFullJustify) { |
|
|
|
if (!ReadBookConfig.textFullJustify) { |
|
|
|
addCharsToLineLast(textLine, words, textPaint, startX) |
|
|
|
addCharsToLineLast( |
|
|
|
|
|
|
|
textLine, |
|
|
|
|
|
|
|
words, |
|
|
|
|
|
|
|
textPaint, |
|
|
|
|
|
|
|
startX |
|
|
|
|
|
|
|
) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
val gapCount: Int = words.lastIndex |
|
|
|
val gapCount: Int = words.lastIndex |
|
|
@ -282,7 +319,10 @@ object ChapterProvider { |
|
|
|
) |
|
|
|
) |
|
|
|
x = x1 |
|
|
|
x = x1 |
|
|
|
} |
|
|
|
} |
|
|
|
exceed(textLine, words) |
|
|
|
exceed( |
|
|
|
|
|
|
|
textLine, |
|
|
|
|
|
|
|
words |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -305,7 +345,10 @@ object ChapterProvider { |
|
|
|
) |
|
|
|
) |
|
|
|
x = x1 |
|
|
|
x = x1 |
|
|
|
} |
|
|
|
} |
|
|
|
exceed(textLine, words) |
|
|
|
exceed( |
|
|
|
|
|
|
|
textLine, |
|
|
|
|
|
|
|
words |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |