This commit is contained in:
Horis 2023-10-22 11:43:20 +08:00
parent bf3fcc7206
commit ef104b9008
2 changed files with 10 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package io.legado.app.help
import android.net.Uri
import android.webkit.WebSettings
import androidx.annotation.Keep
import cn.hutool.core.codec.Base64
import cn.hutool.core.util.HexUtil
@ -490,6 +491,10 @@ interface JsExtensions : JsEncodeUtils {
return ChineseUtils.s2t(text)
}
fun getWebViewUA(): String {
return WebSettings.getDefaultUserAgent(appCtx)
}
//****************文件操作******************//
/**

View File

@ -629,24 +629,24 @@ object ChapterProvider {
val charArray = text.toCharArray()
val strList = ArrayList<String>()
val textWidthList = ArrayList<Float>()
val lastIndex = text.lastIndex
val lastIndex = charArray.lastIndex
for (i in textWidths.indices) {
if (charArray[i].isLowSurrogate()) {
continue
}
val char = if (i + 1 < lastIndex && charArray[i + 1].isLowSurrogate()) {
val char = if (i + 1 <= lastIndex && charArray[i + 1].isLowSurrogate()) {
charArray[i].toString() + charArray[i + 1].toString()
} else {
charArray[i].toString()
}
strList.add(char)
val w = textWidths[i]
if (w == 0f && i - 1 >= 0) {
textWidthList[i - 1] = textPaint.measureText(strList[i - 1])
if (w == 0f && textWidthList.size > 0) {
textWidthList[textWidthList.lastIndex] = textPaint.measureText(strList.last())
textWidthList.add(textPaint.measureText(char))
} else {
textWidthList.add(w)
}
strList.add(char)
}
return strList to textWidthList
}