标题单独绘制

pull/1625/head
kunfei 3 years ago
parent 73ce68ac54
commit 089a21d7c3
  1. 1
      app/src/main/java/io/legado/app/help/ContentProcessor.kt
  2. 3
      app/src/main/java/io/legado/app/model/ReadBook.kt
  3. 46
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt

@ -60,6 +60,7 @@ class ContentProcessor private constructor(
return titleReplaceRules
}
@Suppress("MemberVisibilityCanBePrivate")
fun getContentReplaceRules(): List<ReplaceRule> {
return contentReplaceRules
}

@ -355,7 +355,8 @@ object ReadBook : CoroutineScope by MainScope() {
contentProcessor.getTitleReplaceRules(),
book.getUseReplaceRule()
)
val contents = contentProcessor.getContent(book, chapter, content)
val contents = contentProcessor
.getContent(book, chapter, content, includeTitle = false)
val textChapter = ChapterProvider
.getTextChapter(book, chapter, displayTitle, contents, chapterSize)
when (val offset = chapter.index - durChapterIndex) {

@ -113,11 +113,20 @@ object ChapterProvider {
var absStartX = paddingLeft
var durY = 0f
textPages.add(TextPage())
contents.forEachIndexed { index, content ->
val isTitle = index == 0
val isTitleWithNoContent = isTitle && contents.size == 1
val isVolumeTitle = isTitle && bookChapter.isVolume
val textPaint = if (isTitle) titlePaint else contentPaint
if (ReadBookConfig.titleMode != 2) {
displayTitle.splitNotBlank("\n").forEach { text ->
setTypeText(
absStartX, durY, text, textPages, stringBuilder, titlePaint,
isTitle = true,
isTitleWithNoContent = contents.isEmpty(),
isVolumeTitle = bookChapter.isVolume
).let {
absStartX = it.first
durY = it.second
}
}
}
contents.forEach { content ->
if (book.getImageStyle() == Book.imgStyleText) {
var text = content.replace(srcReplaceChar, "")
val srcList = LinkedList<String>()
@ -132,31 +141,26 @@ object ChapterProvider {
}
matcher.appendTail(sb)
text = sb.toString()
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
setTypeText(
absStartX, durY, text, textPages, stringBuilder,
isTitle, isTitleWithNoContent, isVolumeTitle, textPaint, srcList
absStartX, durY, text, textPages, stringBuilder, contentPaint,
srcList = srcList
).let {
absStartX = it.first
durY = it.second
}
}
} else if (book.getImageStyle() != Book.imgStyleText) {
} else {
val matcher = AppPattern.imgPattern.matcher(content)
var start = 0
while (matcher.find()) {
val text = content.substring(start, matcher.start())
if (text.isNotBlank()) {
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
setTypeText(
absStartX, durY, text, textPages, stringBuilder,
isTitle, isTitleWithNoContent, isVolumeTitle, textPaint
absStartX, durY, text, textPages, stringBuilder, contentPaint
).let {
absStartX = it.first
durY = it.second
}
}
}
durY = setTypeImage(
book, bookChapter, matcher.group(1)!!,
durY, textPages, book.getImageStyle()
@ -166,10 +170,8 @@ object ChapterProvider {
if (start < content.length) {
val text = content.substring(start, content.length)
if (text.isNotBlank()) {
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
setTypeText(
absStartX, durY, text, textPages, stringBuilder,
isTitle, isTitleWithNoContent, isVolumeTitle, textPaint
absStartX, durY, text, textPages, stringBuilder, contentPaint
).let {
absStartX = it.first
durY = it.second
@ -178,7 +180,6 @@ object ChapterProvider {
}
}
}
}
textPages.last().height = durY + 20.dp
textPages.last().text = stringBuilder.toString()
textPages.forEachIndexed { index, item ->
@ -271,10 +272,10 @@ object ChapterProvider {
text: String,
textPages: ArrayList<TextPage>,
stringBuilder: StringBuilder,
isTitle: Boolean,
isTitleWithNoContent: Boolean,
isVolumeTitle: Boolean,
textPaint: TextPaint,
isTitle: Boolean = false,
isTitleWithNoContent: Boolean = false,
isVolumeTitle: Boolean = false,
srcList: LinkedList<String>? = null
): Pair<Int, Float> {
var absStartX = x
@ -332,7 +333,8 @@ object ChapterProvider {
textLine.text = "$words\n"
isLastLine = true
//标题x轴居中
val startX = if (isTitle && ReadBookConfig.titleMode == 1 || isTitleWithNoContent || isVolumeTitle)
val startX =
if (isTitle && ReadBookConfig.titleMode == 1 || isTitleWithNoContent || isVolumeTitle)
(visibleWidth - layout.getLineWidth(lineIndex)) / 2
else 0f
addCharsToLineLast(

Loading…
Cancel
Save