优化英文两端对齐
This commit is contained in:
@@ -458,14 +458,30 @@ object ChapterProvider {
|
|||||||
addCharsToLineNatural(book, absStartX, textLine, words, textPaint, startX, srcList)
|
addCharsToLineNatural(book, absStartX, textLine, words, textPaint, startX, srcList)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val gapCount: Int = words.lastIndex
|
val spaceSize = words.filter { it == " " }.size
|
||||||
val d = (visibleWidth - desiredWidth) / gapCount
|
if (spaceSize > 0) {
|
||||||
var x = startX
|
val d = (visibleWidth - desiredWidth) / spaceSize
|
||||||
words.forEachIndexed { index, char ->
|
var x = startX
|
||||||
val cw = StaticLayout.getDesiredWidth(char, textPaint)
|
words.forEachIndexed { index, char ->
|
||||||
val x1 = if (index != words.lastIndex) (x + cw + d) else (x + cw)
|
val cw = StaticLayout.getDesiredWidth(char, textPaint)
|
||||||
addCharToLine(book, absStartX, textLine, char, x, x1, index + 1 == words.size, srcList)
|
val x1 = if (char == " ") {
|
||||||
x = x1
|
if (index != words.lastIndex) (x + cw + d) else (x + cw)
|
||||||
|
} else {
|
||||||
|
(x + cw)
|
||||||
|
}
|
||||||
|
addCharToLine(book, absStartX, textLine, char, x, x1, index + 1 == words.size, srcList)
|
||||||
|
x = x1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val gapCount: Int = words.lastIndex
|
||||||
|
val d = (visibleWidth - desiredWidth) / gapCount
|
||||||
|
var x = startX
|
||||||
|
words.forEachIndexed { index, char ->
|
||||||
|
val cw = StaticLayout.getDesiredWidth(char, textPaint)
|
||||||
|
val x1 = if (index != words.lastIndex) (x + cw + d) else (x + cw)
|
||||||
|
addCharToLine(book, absStartX, textLine, char, x, x1, index + 1 == words.size, srcList)
|
||||||
|
x = x1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exceed(absStartX, textLine, words)
|
exceed(absStartX, textLine, words)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user