|
|
|
@ -11,6 +11,7 @@ import io.legado.app.constant.AppPattern |
|
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
|
import io.legado.app.help.ReadBookConfig |
|
|
|
|
import io.legado.app.ui.book.read.page.entities.TextChapter |
|
|
|
|
import io.legado.app.ui.book.read.page.entities.TextChar |
|
|
|
@ -57,6 +58,11 @@ object ChapterProvider { |
|
|
|
|
val pageLengths = arrayListOf<Int>() |
|
|
|
|
val stringBuilder = StringBuilder() |
|
|
|
|
var durY = 0f |
|
|
|
|
var paint = Pair(titlePaint, contentPaint) |
|
|
|
|
BookHelp.getFontPath(book, bookChapter)?.let { |
|
|
|
|
val typeface = getTypeface(it) |
|
|
|
|
paint = getPaint(typeface) |
|
|
|
|
} |
|
|
|
|
textPages.add(TextPage()) |
|
|
|
|
contents.forEachIndexed { index, text -> |
|
|
|
|
val matcher = AppPattern.imgPattern.matcher(text) |
|
|
|
@ -72,7 +78,7 @@ object ChapterProvider { |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
val isTitle = index == 0 |
|
|
|
|
val textPaint = if (isTitle) titlePaint else contentPaint |
|
|
|
|
val textPaint = if (isTitle) paint.first else paint.second |
|
|
|
|
if (!(isTitle && ReadBookConfig.titleMode == 2)) { |
|
|
|
|
durY = setTypeText( |
|
|
|
|
text, durY, textPages, pageLines, |
|
|
|
@ -327,8 +333,21 @@ object ChapterProvider { |
|
|
|
|
* 更新样式 |
|
|
|
|
*/ |
|
|
|
|
fun upStyle() { |
|
|
|
|
typeface = try { |
|
|
|
|
val fontPath = ReadBookConfig.textFont |
|
|
|
|
typeface = getTypeface(ReadBookConfig.textFont) |
|
|
|
|
getPaint(typeface).let { |
|
|
|
|
titlePaint = it.first |
|
|
|
|
contentPaint = it.second |
|
|
|
|
} |
|
|
|
|
//间距 |
|
|
|
|
lineSpacingExtra = ReadBookConfig.lineSpacingExtra |
|
|
|
|
paragraphSpacing = ReadBookConfig.paragraphSpacing |
|
|
|
|
titleTopSpacing = ReadBookConfig.titleTopSpacing.dp |
|
|
|
|
titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dp |
|
|
|
|
upVisibleSize() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun getTypeface(fontPath: String): Typeface { |
|
|
|
|
return try { |
|
|
|
|
when { |
|
|
|
|
fontPath.isContentScheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> { |
|
|
|
|
val fd = App.INSTANCE.contentResolver |
|
|
|
@ -351,6 +370,9 @@ object ChapterProvider { |
|
|
|
|
ReadBookConfig.save() |
|
|
|
|
Typeface.SANS_SERIF |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun getPaint(typeface: Typeface): Pair<TextPaint, TextPaint> { |
|
|
|
|
// 字体统一处理 |
|
|
|
|
val bold = Typeface.create(typeface, Typeface.BOLD) |
|
|
|
|
val normal = Typeface.create(typeface, Typeface.NORMAL) |
|
|
|
@ -371,25 +393,20 @@ object ChapterProvider { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//标题 |
|
|
|
|
titlePaint = TextPaint() |
|
|
|
|
titlePaint.color = ReadBookConfig.textColor |
|
|
|
|
titlePaint.letterSpacing = ReadBookConfig.letterSpacing |
|
|
|
|
titlePaint.typeface = titleFont |
|
|
|
|
titlePaint.textSize = with(ReadBookConfig) { textSize + titleSize }.sp.toFloat() |
|
|
|
|
titlePaint.isAntiAlias = true |
|
|
|
|
val tPaint = TextPaint() |
|
|
|
|
tPaint.color = ReadBookConfig.textColor |
|
|
|
|
tPaint.letterSpacing = ReadBookConfig.letterSpacing |
|
|
|
|
tPaint.typeface = titleFont |
|
|
|
|
tPaint.textSize = with(ReadBookConfig) { textSize + titleSize }.sp.toFloat() |
|
|
|
|
tPaint.isAntiAlias = true |
|
|
|
|
//正文 |
|
|
|
|
contentPaint = TextPaint() |
|
|
|
|
contentPaint.color = ReadBookConfig.textColor |
|
|
|
|
contentPaint.letterSpacing = ReadBookConfig.letterSpacing |
|
|
|
|
contentPaint.typeface = textFont |
|
|
|
|
contentPaint.textSize = ReadBookConfig.textSize.sp.toFloat() |
|
|
|
|
contentPaint.isAntiAlias = true |
|
|
|
|
//间距 |
|
|
|
|
lineSpacingExtra = ReadBookConfig.lineSpacingExtra |
|
|
|
|
paragraphSpacing = ReadBookConfig.paragraphSpacing |
|
|
|
|
titleTopSpacing = ReadBookConfig.titleTopSpacing.dp |
|
|
|
|
titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dp |
|
|
|
|
upVisibleSize() |
|
|
|
|
val cPaint = TextPaint() |
|
|
|
|
cPaint.color = ReadBookConfig.textColor |
|
|
|
|
cPaint.letterSpacing = ReadBookConfig.letterSpacing |
|
|
|
|
cPaint.typeface = textFont |
|
|
|
|
cPaint.textSize = ReadBookConfig.textSize.sp.toFloat() |
|
|
|
|
cPaint.isAntiAlias = true |
|
|
|
|
return Pair(tPaint, cPaint) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|