优化
Some checks failed
Test Build / prepare (push) Has been cancelled
Test Build / build (app, release) (push) Has been cancelled
Test Build / build (app, releaseA) (push) Has been cancelled
Test Build / prerelease (push) Has been cancelled
Test Build / lanzou (push) Has been cancelled
Test Build / test_Branch (push) Has been cancelled
Test Build / telegram (push) Has been cancelled
Update Cronet / build (push) Has been cancelled

This commit is contained in:
Horis
2025-03-16 20:03:48 +08:00
parent fdd3e0345f
commit 3352426bed
2 changed files with 14 additions and 13 deletions

View File

@@ -803,19 +803,10 @@ class TextChapterLayout(
var i = 0
while (i < length) {
val clusterBaseIndex = i++
var extra = 0f
while (i < length) {
val c = text[i]
val w = widthsArray[start + i]
if (w > 0 || isZeroWidthChar(c)) {
if (!c.isLowSurrogate()) {
break
}
extra = w
}
widths.add(widthsArray[start + clusterBaseIndex])
while (i < length && widthsArray[start + i] == 0f && !isZeroWidthChar(text[i])) {
i++
}
widths.add(widthsArray[start + clusterBaseIndex] + extra)
stringList.add(text.substring(clusterBaseIndex, i))
}
return stringList to widths

View File

@@ -11,7 +11,17 @@ fun TextPaint.getTextWidthsCompat(text: String, widths: FloatArray) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
val letterSpacing = letterSpacing * textSize
val letterSpacingHalf = letterSpacing * 0.5f
widths[0] += letterSpacingHalf
widths[text.lastIndex] += letterSpacingHalf
for (i in widths.indices) {
if (widths[i] > 0) {
widths[i] += letterSpacingHalf
break
}
}
for (i in text.lastIndex downTo 0) {
if (widths[i] > 0) {
widths[i] += letterSpacingHalf
break
}
}
}
}