mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
Merge branch 'gedoor:master' into master
This commit is contained in:
commit
91fd056db0
@ -111,7 +111,7 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style),
|
|||||||
postEvent(EventBus.UP_CONFIG, arrayOf(5))
|
postEvent(EventBus.UP_CONFIG, arrayOf(5))
|
||||||
}
|
}
|
||||||
textFontWeightConverter.onChanged {
|
textFontWeightConverter.onChanged {
|
||||||
postEvent(EventBus.UP_CONFIG, arrayOf(8))
|
postEvent(EventBus.UP_CONFIG, arrayOf(8, 9, 6))
|
||||||
}
|
}
|
||||||
tvTextFont.setOnClickListener {
|
tvTextFont.setOnClickListener {
|
||||||
showDialogFragment<FontSelectDialog>()
|
showDialogFragment<FontSelectDialog>()
|
||||||
|
@ -432,7 +432,7 @@ object ChapterProvider {
|
|||||||
): Pair<Int, Float> {
|
): Pair<Int, Float> {
|
||||||
var absStartX = x
|
var absStartX = x
|
||||||
val layout = if (ReadBookConfig.useZhLayout) {
|
val layout = if (ReadBookConfig.useZhLayout) {
|
||||||
ZhLayout(text, textPaint, visibleWidth)
|
ZhLayout(text, textPaint, visibleWidth, emptyList(), emptyList())
|
||||||
} else {
|
} else {
|
||||||
StaticLayout(text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true)
|
StaticLayout(text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true)
|
||||||
}
|
}
|
||||||
|
@ -399,8 +399,11 @@ class TextChapterLayout(
|
|||||||
srcList: LinkedList<String>? = null
|
srcList: LinkedList<String>? = null
|
||||||
): Pair<Int, Float> {
|
): Pair<Int, Float> {
|
||||||
var absStartX = x
|
var absStartX = x
|
||||||
|
val widthsArray = FloatArray(text.length)
|
||||||
|
textPaint.getTextWidths(text, widthsArray)
|
||||||
val layout = if (ReadBookConfig.useZhLayout) {
|
val layout = if (ReadBookConfig.useZhLayout) {
|
||||||
ZhLayout(text, textPaint, visibleWidth)
|
val (words, widths) = measureTextSplit(text, widthsArray)
|
||||||
|
ZhLayout(text, textPaint, visibleWidth, words, widths)
|
||||||
} else {
|
} else {
|
||||||
StaticLayout(text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true)
|
StaticLayout(text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true)
|
||||||
}
|
}
|
||||||
@ -431,7 +434,6 @@ class TextChapterLayout(
|
|||||||
|
|
||||||
else -> y
|
else -> y
|
||||||
}
|
}
|
||||||
val (strList, widthList) = measureTextSplit(text, textPaint)
|
|
||||||
for (lineIndex in 0 until layout.lineCount) {
|
for (lineIndex in 0 until layout.lineCount) {
|
||||||
val textLine = TextLine(isTitle = isTitle)
|
val textLine = TextLine(isTitle = isTitle)
|
||||||
if (durY + textHeight > visibleHeight) {
|
if (durY + textHeight > visibleHeight) {
|
||||||
@ -462,8 +464,7 @@ class TextChapterLayout(
|
|||||||
val lineStart = layout.getLineStart(lineIndex)
|
val lineStart = layout.getLineStart(lineIndex)
|
||||||
val lineEnd = layout.getLineEnd(lineIndex)
|
val lineEnd = layout.getLineEnd(lineIndex)
|
||||||
val lineText = text.substring(lineStart, lineEnd)
|
val lineText = text.substring(lineStart, lineEnd)
|
||||||
val words = strList.subList(lineStart, lineEnd)
|
val (words, widths) = measureTextSplit(lineText, widthsArray, lineStart)
|
||||||
val widths = widthList.subList(lineStart, lineEnd)
|
|
||||||
val desiredWidth = widths.fastSum()
|
val desiredWidth = widths.fastSum()
|
||||||
textLine.text = lineText
|
textLine.text = lineText
|
||||||
when {
|
when {
|
||||||
@ -763,22 +764,24 @@ class TextChapterLayout(
|
|||||||
|
|
||||||
private fun measureTextSplit(
|
private fun measureTextSplit(
|
||||||
text: String,
|
text: String,
|
||||||
paint: TextPaint
|
widthsArray: FloatArray,
|
||||||
|
start: Int = 0
|
||||||
): Pair<ArrayList<String>, ArrayList<Float>> {
|
): Pair<ArrayList<String>, ArrayList<Float>> {
|
||||||
val length = text.length
|
val length = text.length
|
||||||
val widthsArray = FloatArray(length)
|
var clusterCount = 0
|
||||||
paint.getTextWidths(text, widthsArray)
|
for (i in start..<start + length) {
|
||||||
val clusterCount = widthsArray.count { it > 0f }
|
if (widthsArray[i] > 0) clusterCount++
|
||||||
|
}
|
||||||
val widths = ArrayList<Float>(clusterCount)
|
val widths = ArrayList<Float>(clusterCount)
|
||||||
val stringList = ArrayList<String>(clusterCount)
|
val stringList = ArrayList<String>(clusterCount)
|
||||||
var i = 0
|
var i = start
|
||||||
while (i < length) {
|
while (i < start + length) {
|
||||||
val clusterBaseIndex = i++
|
val clusterBaseIndex = i++
|
||||||
widths.add(widthsArray[clusterBaseIndex])
|
widths.add(widthsArray[clusterBaseIndex])
|
||||||
while (i < length && widthsArray[i] == 0f) {
|
while (i < length && widthsArray[i] == 0f) {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
stringList.add(text.substring(clusterBaseIndex, i))
|
stringList.add(text.substring(clusterBaseIndex - start, i - start))
|
||||||
}
|
}
|
||||||
return stringList to widths
|
return stringList to widths
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ class ZhLayout(
|
|||||||
text: CharSequence,
|
text: CharSequence,
|
||||||
textPaint: TextPaint,
|
textPaint: TextPaint,
|
||||||
width: Int,
|
width: Int,
|
||||||
|
words: List<String>,
|
||||||
|
widths: List<Float>
|
||||||
) : Layout(text, textPaint, width, Alignment.ALIGN_NORMAL, 0f, 0f) {
|
) : Layout(text, textPaint, width, Alignment.ALIGN_NORMAL, 0f, 0f) {
|
||||||
companion object {
|
companion object {
|
||||||
private val postPanc = hashSetOf(
|
private val postPanc = hashSetOf(
|
||||||
@ -49,7 +51,6 @@ class ZhLayout(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
var line = 0
|
var line = 0
|
||||||
val (words, widths) = ChapterProvider.measureTextSplit(text as String, textPaint)
|
|
||||||
var lineW = 0f
|
var lineW = 0f
|
||||||
var cwPre = 0f
|
var cwPre = 0f
|
||||||
var length = 0
|
var length = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user