This commit is contained in:
Horis 2023-09-26 20:41:06 +08:00
parent 3601ba1178
commit b5bea5e3c4
3 changed files with 45 additions and 14 deletions

View File

@ -90,6 +90,15 @@ object ChapterProvider {
@JvmStatic
private var titleBottomSpacing = 0
@JvmStatic
private var indentCharWidth = 0f
@JvmStatic
private var titlePaintTextHeight = 0f
@JvmStatic
private var contentPaintTextHeight = 0f
@JvmStatic
var typeface: Typeface? = Typeface.DEFAULT
private set
@ -136,6 +145,7 @@ object ChapterProvider {
textPages,
stringBuilder,
titlePaint,
titlePaintTextHeight,
isTitle = true,
emptyContent = contents.isEmpty(),
isVolumeTitle = bookChapter.isVolume
@ -162,7 +172,14 @@ object ChapterProvider {
matcher.appendTail(sb)
text = sb.toString()
setTypeText(
book, absStartX, durY, text, textPages, stringBuilder, contentPaint,
book,
absStartX,
durY,
text,
textPages,
stringBuilder,
contentPaint,
contentPaintTextHeight,
srcList = srcList
).let {
absStartX = it.first
@ -175,7 +192,14 @@ object ChapterProvider {
val text = content.substring(start, matcher.start())
if (text.isNotBlank()) {
setTypeText(
book, absStartX, durY, text, textPages, stringBuilder, contentPaint
book,
absStartX,
durY,
text,
textPages,
stringBuilder,
contentPaint,
contentPaintTextHeight
).let {
absStartX = it.first
durY = it.second
@ -195,7 +219,8 @@ object ChapterProvider {
if (AppConfig.enableReview) text + reviewChar else text,
textPages,
stringBuilder,
contentPaint
contentPaint,
contentPaintTextHeight
).let {
absStartX = it.first
durY = it.second
@ -305,6 +330,7 @@ object ChapterProvider {
textPages: ArrayList<TextPage>,
stringBuilder: StringBuilder,
textPaint: TextPaint,
textHeight: Float,
isTitle: Boolean = false,
emptyContent: Boolean = false,
isVolumeTitle: Boolean = false,
@ -321,10 +347,10 @@ object ChapterProvider {
emptyContent && textPages.size == 1 -> {
val textPage = textPages.last()
if (textPage.lineSize == 0) {
val ty = (visibleHeight - layout.lineCount * textPaint.textHeight) / 2
val ty = (visibleHeight - layout.lineCount * textHeight) / 2
if (ty > titleTopSpacing) ty else titleTopSpacing.toFloat()
} else {
var textLayoutHeight = layout.lineCount * textPaint.textHeight
var textLayoutHeight = layout.lineCount * textHeight
val fistLine = textPage.getLine(0)
if (fistLine.lineTop < textLayoutHeight + titleTopSpacing) {
textLayoutHeight = fistLine.lineTop - titleTopSpacing
@ -430,16 +456,17 @@ object ChapterProvider {
else -> lastLine.paragraphNum
}
textLine.paragraphNum = paragraphNum
textLine.chapterPosition = textPages.foldIndexed(sbLength) { index, acc, textPage ->
acc + if (index == textPages.lastIndex) 0 else textPage.text.length
}
textLine.chapterPosition =
(textPages.getOrNull(textPages.lastIndex - 1)?.lines?.last()?.run {
chapterPosition + charSize + if (isParagraphEnd) 1 else 0
} ?: 0) + sbLength
textLine.pagePosition = sbLength
textPages.last().addLine(textLine)
textLine.upTopBottom(durY, textPaint)
durY += textPaint.textHeight * lineSpacingExtra
durY += textHeight * lineSpacingExtra
textPages.last().height = durY
}
durY += textPaint.textHeight * paragraphSpacing / 10f
durY += textHeight * paragraphSpacing / 10f
return Pair(absStartX, durY)
}
@ -465,9 +492,8 @@ object ChapterProvider {
return
}
val bodyIndent = ReadBookConfig.paragraphIndent
val icw = StaticLayout.getDesiredWidth(bodyIndent, textPaint) / bodyIndent.length
for (char in bodyIndent.toStringArray()) {
val x1 = x + icw
val x1 = x + indentCharWidth
textLine.addColumn(
TextColumn(
charData = char,
@ -649,6 +675,10 @@ object ChapterProvider {
paragraphSpacing = ReadBookConfig.paragraphSpacing
titleTopSpacing = ReadBookConfig.titleTopSpacing.dpToPx()
titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dpToPx()
val bodyIndent = ReadBookConfig.paragraphIndent
indentCharWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint) / bodyIndent.length
titlePaintTextHeight = titlePaint.textHeight
contentPaintTextHeight = contentPaint.textHeight
upLayout()
}

View File

@ -3,4 +3,4 @@ package io.legado.app.utils
import android.text.TextPaint
val TextPaint.textHeight: Float
get() = fontMetrics.descent - fontMetrics.ascent + fontMetrics.leading
get() = fontMetrics.run { descent - ascent + leading }

View File

@ -53,10 +53,11 @@ public class MediaTypes {
"application/adobe-page-template+xml", ".xpgt");
public static final MediaType PLS = new MediaType("application/pls+xml",
".pls");
public static final MediaType UNKNOWN = new MediaType("application/octet-stream", "");
public static final MediaType[] mediaTypes = new MediaType[]{
XHTML, EPUB, JPG, PNG, GIF, CSS, SVG, TTF, NCX, XPGT, OPENTYPE, WOFF,
SMIL, PLS, JAVASCRIPT, MP3, MP4, OGG
SMIL, PLS, JAVASCRIPT, MP3, MP4, OGG, UNKNOWN
};
public static final Map<String, MediaType> mediaTypesByName = new HashMap<>();