标题单独绘制

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. 78
      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,29 +141,24 @@ object ChapterProvider {
}
matcher.appendTail(sb)
text = sb.toString()
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
setTypeText(
absStartX, durY, text, textPages, stringBuilder,
isTitle, isTitleWithNoContent, isVolumeTitle, textPaint, srcList
).let {
absStartX = it.first
durY = it.second
}
setTypeText(
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
).let {
absStartX = it.first
durY = it.second
}
setTypeText(
absStartX, durY, text, textPages, stringBuilder, contentPaint
).let {
absStartX = it.first
durY = it.second
}
}
durY = setTypeImage(
@ -166,14 +170,11 @@ 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
).let {
absStartX = it.first
durY = it.second
}
setTypeText(
absStartX, durY, text, textPages, stringBuilder, contentPaint
).let {
absStartX = it.first
durY = it.second
}
}
}
@ -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,9 +333,10 @@ object ChapterProvider {
textLine.text = "$words\n"
isLastLine = true
//标题x轴居中
val startX = if (isTitle && ReadBookConfig.titleMode == 1 || isTitleWithNoContent || isVolumeTitle)
(visibleWidth - layout.getLineWidth(lineIndex)) / 2
else 0f
val startX =
if (isTitle && ReadBookConfig.titleMode == 1 || isTitleWithNoContent || isVolumeTitle)
(visibleWidth - layout.getLineWidth(lineIndex)) / 2
else 0f
addCharsToLineLast(
absStartX,
textLine,
@ -603,8 +605,8 @@ object ChapterProvider {
*/
fun upLayout() {
doublePage = (viewWidth > viewHeight || appCtx.isPad)
&& ReadBook.pageAnim() != 3
&& AppConfig.doublePageHorizontal
&& ReadBook.pageAnim() != 3
&& AppConfig.doublePageHorizontal
if (viewWidth > 0 && viewHeight > 0) {
paddingLeft = ReadBookConfig.paddingLeft.dp
paddingTop = ReadBookConfig.paddingTop.dp

Loading…
Cancel
Save