This commit is contained in:
Horis 2023-10-16 15:49:35 +08:00
parent 3751af35f4
commit 76f503a687
3 changed files with 17 additions and 8 deletions

View File

@ -558,7 +558,7 @@ object ChapterProvider {
} }
val residualWidth = visibleWidth - desiredWidth val residualWidth = visibleWidth - desiredWidth
val spaceSize = text.count { it == ' ' } val spaceSize = text.count { it == ' ' }
val (words, widths) = getStringArrayAndTextWidths(text, textWidths) val (words, widths) = getStringArrayAndTextWidths(text, textWidths, textPaint)
if (spaceSize > 1) { if (spaceSize > 1) {
val d = residualWidth / spaceSize val d = residualWidth / spaceSize
var x = startX var x = startX
@ -608,7 +608,7 @@ object ChapterProvider {
) { ) {
val indentLength = ReadBookConfig.paragraphIndent.length val indentLength = ReadBookConfig.paragraphIndent.length
var x = startX var x = startX
val (words, widths) = getStringArrayAndTextWidths(text, textWidths) val (words, widths) = getStringArrayAndTextWidths(text, textWidths, textPaint)
words.forEachIndexed { index, char -> words.forEachIndexed { index, char ->
val cw = widths[index] val cw = widths[index]
val x1 = x + cw val x1 = x + cw
@ -623,7 +623,8 @@ object ChapterProvider {
fun getStringArrayAndTextWidths( fun getStringArrayAndTextWidths(
text: String, text: String,
textWidths: List<Float> textWidths: List<Float>,
textPaint: TextPaint
): Pair<List<String>, List<Float>> { ): Pair<List<String>, List<Float>> {
val charArray = text.toCharArray() val charArray = text.toCharArray()
val strList = ArrayList<String>() val strList = ArrayList<String>()
@ -639,7 +640,13 @@ object ChapterProvider {
charArray[i].toString() charArray[i].toString()
} }
strList.add(char) strList.add(char)
textWidthList.add(textWidths[i]) val w = textWidths[i]
if (w == 0f && i - 1 >= 0) {
textWidthList[i - 1] = textPaint.measureText(strList[i - 1])
textWidthList.add(textPaint.measureText(char))
} else {
textWidthList.add(w)
}
} }
return strList to textWidthList return strList to textWidthList
} }

View File

@ -53,7 +53,8 @@ class ZhLayout(
curPaint.getTextWidths(text as String, widthsArray) curPaint.getTextWidths(text as String, widthsArray)
val (words, widths) = ChapterProvider.getStringArrayAndTextWidths( val (words, widths) = ChapterProvider.getStringArrayAndTextWidths(
text, text,
widthsArray.asList() widthsArray.asList(),
curPaint
) )
var lineW = 0f var lineW = 0f
var cwPre = 0f var cwPre = 0f

View File

@ -5,10 +5,11 @@ pluginManagement {
google() google()
mavenCentral() mavenCentral()
//,, //,,
//maven {url"https://maven-central-asia.storage-download.googleapis.com/maven2/"} //maven { url "https://maven-central-asia.storage-download.googleapis.com/maven2/" }
//maven { url 'https://maven.aliyun.com/repository/google' } //maven { url 'https://maven.aliyun.com/repository/google' }
//maven { url 'https://maven.aliyun.com/repository/public' } //maven { url 'https://maven.aliyun.com/repository/public' }
//maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } //maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
//maven { url 'https://repo.huaweicloud.com/repository/maven/' }
} }
} }
@ -20,10 +21,10 @@ dependencyResolutionManagement {
mavenCentral() mavenCentral()
maven { url 'https://jitpack.io' } maven { url 'https://jitpack.io' }
//,, //,,
//maven {url"https://maven-central-asia.storage-download.googleapis.com/maven2/"} //maven { url "https://maven-central-asia.storage-download.googleapis.com/maven2/" }
//maven { url 'https://maven.aliyun.com/repository/google' } //maven { url 'https://maven.aliyun.com/repository/google' }
//maven { url 'https://maven.aliyun.com/repository/public' } //maven { url 'https://maven.aliyun.com/repository/public' }
//maven { url 'https://repo.huaweicloud.com/repository/maven/' }
} }
} }
rootProject.name = 'legado' rootProject.name = 'legado'