Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Oct 22, 2023
1 parent bf3fcc7 commit ef104b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/io/legado/app/help/JsExtensions.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -490,6 +491,10 @@ interface JsExtensions : JsEncodeUtils {
return ChineseUtils.s2t(text)
}

fun getWebViewUA(): String {
return WebSettings.getDefaultUserAgent(appCtx)
}

//****************文件操作******************//

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit ef104b9

Please sign in to comment.