优化
This commit is contained in:
@@ -123,7 +123,7 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style),
|
|||||||
items = resources.getStringArray(R.array.indent).toList()
|
items = resources.getStringArray(R.array.indent).toList()
|
||||||
) { _, index ->
|
) { _, index ->
|
||||||
ReadBookConfig.paragraphIndent = " ".repeat(index)
|
ReadBookConfig.paragraphIndent = " ".repeat(index)
|
||||||
postEvent(EventBus.UP_CONFIG, arrayListOf(5))
|
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tvPadding.setOnClickListener {
|
tvPadding.setOnClickListener {
|
||||||
|
|||||||
@@ -864,11 +864,15 @@ object ChapterProvider {
|
|||||||
titleTopSpacing = ReadBookConfig.titleTopSpacing.dpToPx()
|
titleTopSpacing = ReadBookConfig.titleTopSpacing.dpToPx()
|
||||||
titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dpToPx()
|
titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dpToPx()
|
||||||
val bodyIndent = ReadBookConfig.paragraphIndent
|
val bodyIndent = ReadBookConfig.paragraphIndent
|
||||||
var indentWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint)
|
indentCharWidth = if (bodyIndent.isNotEmpty()) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
var indentWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint)
|
||||||
indentWidth += contentPaint.letterSpacing * contentPaint.textSize
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||||
|
indentWidth += contentPaint.letterSpacing * contentPaint.textSize
|
||||||
|
}
|
||||||
|
indentWidth / bodyIndent.length
|
||||||
|
} else {
|
||||||
|
0f
|
||||||
}
|
}
|
||||||
indentCharWidth = indentWidth / bodyIndent.length
|
|
||||||
titlePaintTextHeight = titlePaint.textHeight
|
titlePaintTextHeight = titlePaint.textHeight
|
||||||
contentPaintTextHeight = contentPaint.textHeight
|
contentPaintTextHeight = contentPaint.textHeight
|
||||||
titlePaintFontMetrics = titlePaint.fontMetrics
|
titlePaintFontMetrics = titlePaint.fontMetrics
|
||||||
|
|||||||
@@ -73,6 +73,10 @@ class TextChapterLayout(
|
|||||||
private val stringBuilder = StringBuilder()
|
private val stringBuilder = StringBuilder()
|
||||||
|
|
||||||
private val paragraphIndent = ReadBookConfig.paragraphIndent
|
private val paragraphIndent = ReadBookConfig.paragraphIndent
|
||||||
|
private val titleMode = ReadBookConfig.titleMode
|
||||||
|
private val useZhLayout = ReadBookConfig.useZhLayout
|
||||||
|
private val isMiddleTitle = ReadBookConfig.isMiddleTitle
|
||||||
|
private val textFullJustify = ReadBookConfig.textFullJustify
|
||||||
|
|
||||||
private var pendingTextPage = TextPage()
|
private var pendingTextPage = TextPage()
|
||||||
|
|
||||||
@@ -196,7 +200,7 @@ class TextChapterLayout(
|
|||||||
val isSingleImageStyle = imageStyle.equals(Book.imgStyleSingle, true)
|
val isSingleImageStyle = imageStyle.equals(Book.imgStyleSingle, true)
|
||||||
val isTextImageStyle = imageStyle.equals(Book.imgStyleText, true)
|
val isTextImageStyle = imageStyle.equals(Book.imgStyleText, true)
|
||||||
|
|
||||||
if (ReadBookConfig.titleMode != 2 || bookChapter.isVolume || contents.isEmpty()) {
|
if (titleMode != 2 || bookChapter.isVolume || contents.isEmpty()) {
|
||||||
//标题非隐藏
|
//标题非隐藏
|
||||||
displayTitle.splitNotBlank("\n").forEach { text ->
|
displayTitle.splitNotBlank("\n").forEach { text ->
|
||||||
setTypeText(
|
setTypeText(
|
||||||
@@ -406,7 +410,7 @@ class TextChapterLayout(
|
|||||||
) {
|
) {
|
||||||
val widthsArray = allocateFloatArray(text.length)
|
val widthsArray = allocateFloatArray(text.length)
|
||||||
textPaint.getTextWidthsCompat(text, widthsArray)
|
textPaint.getTextWidthsCompat(text, widthsArray)
|
||||||
val layout = if (ReadBookConfig.useZhLayout) {
|
val layout = if (useZhLayout) {
|
||||||
val (words, widths) = measureTextSplit(text, widthsArray)
|
val (words, widths) = measureTextSplit(text, widthsArray)
|
||||||
val indentSize = if (isFirstLine) paragraphIndent.length else 0
|
val indentSize = if (isFirstLine) paragraphIndent.length else 0
|
||||||
ZhLayout(text, textPaint, visibleWidth, words, widths, indentSize)
|
ZhLayout(text, textPaint, visibleWidth, words, widths, indentSize)
|
||||||
@@ -471,7 +475,7 @@ class TextChapterLayout(
|
|||||||
//标题x轴居中
|
//标题x轴居中
|
||||||
val startX = if (
|
val startX = if (
|
||||||
isTitle &&
|
isTitle &&
|
||||||
(ReadBookConfig.isMiddleTitle || emptyContent || isVolumeTitle
|
(isMiddleTitle || emptyContent || isVolumeTitle
|
||||||
|| imageStyle?.uppercase() == Book.imgStyleSingle)
|
|| imageStyle?.uppercase() == Book.imgStyleSingle)
|
||||||
) {
|
) {
|
||||||
(visibleWidth - desiredWidth) / 2
|
(visibleWidth - desiredWidth) / 2
|
||||||
@@ -487,7 +491,7 @@ class TextChapterLayout(
|
|||||||
else -> {
|
else -> {
|
||||||
if (
|
if (
|
||||||
isTitle &&
|
isTitle &&
|
||||||
(ReadBookConfig.isMiddleTitle || emptyContent || isVolumeTitle
|
(isMiddleTitle || emptyContent || isVolumeTitle
|
||||||
|| imageStyle?.uppercase() == Book.imgStyleSingle)
|
|| imageStyle?.uppercase() == Book.imgStyleSingle)
|
||||||
) {
|
) {
|
||||||
//标题居中
|
//标题居中
|
||||||
@@ -556,7 +560,7 @@ class TextChapterLayout(
|
|||||||
srcList: LinkedList<String>?
|
srcList: LinkedList<String>?
|
||||||
) {
|
) {
|
||||||
var x = 0f
|
var x = 0f
|
||||||
if (!ReadBookConfig.textFullJustify) {
|
if (!textFullJustify) {
|
||||||
addCharsToLineNatural(
|
addCharsToLineNatural(
|
||||||
book, absStartX, textLine, words,
|
book, absStartX, textLine, words,
|
||||||
x, true, textWidths, srcList
|
x, true, textWidths, srcList
|
||||||
@@ -603,7 +607,7 @@ class TextChapterLayout(
|
|||||||
textWidths: List<Float>,
|
textWidths: List<Float>,
|
||||||
srcList: LinkedList<String>?
|
srcList: LinkedList<String>?
|
||||||
) {
|
) {
|
||||||
if (!ReadBookConfig.textFullJustify) {
|
if (!textFullJustify) {
|
||||||
addCharsToLineNatural(
|
addCharsToLineNatural(
|
||||||
book, absStartX, textLine, words,
|
book, absStartX, textLine, words,
|
||||||
startX, false, textWidths, srcList
|
startX, false, textWidths, srcList
|
||||||
@@ -664,7 +668,7 @@ class TextChapterLayout(
|
|||||||
textWidths: List<Float>,
|
textWidths: List<Float>,
|
||||||
srcList: LinkedList<String>?
|
srcList: LinkedList<String>?
|
||||||
) {
|
) {
|
||||||
val indentLength = ReadBookConfig.paragraphIndent.length
|
val indentLength = paragraphIndent.length
|
||||||
var x = startX
|
var x = startX
|
||||||
textLine.startX = absStartX + startX
|
textLine.startX = absStartX + startX
|
||||||
for (index in words.indices) {
|
for (index in words.indices) {
|
||||||
|
|||||||
Reference in New Issue
Block a user