From e4e0740bd33f58953270dd8ca58a1f2c706ff93f Mon Sep 17 00:00:00 2001 From: Antecer Date: Sun, 22 Nov 2020 21:41:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E5=90=88queryTTF=E6=94=AF=E6=8C=81bas?= =?UTF-8?q?e64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/JsExtensions.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index b282fbcc2..94400265e 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -244,9 +244,7 @@ interface JsExtensions { fun queryTTF(path: String): QueryTTF? { val key = md5Encode16(path) var qTTF = CacheManager.getQueryTTF(key) - if (qTTF != null) { - return qTTF - } + if (qTTF != null) return qTTF val font: ByteArray? = when { path.isAbsUrl() -> runBlocking { var x = CacheManager.getByteArray(key) @@ -261,9 +259,12 @@ interface JsExtensions { path.isContentScheme() -> { Uri.parse(path).readBytes(App.INSTANCE) } - else -> { + path.startsWith("/storage")->{ File(path).readBytes() } + else -> { + base64DecodeToByteArray(path.removePrefix("base64,")) + } } font ?: return null qTTF = QueryTTF(font) @@ -278,12 +279,12 @@ interface JsExtensions { start: Int, end: Int ): String { - if (font1 == null || font2 == null) { - return text - } + if (font1 == null || font2 == null) return text + val startChar = start.toChar() + val endChar = end.toChar() val contentArray = text.toCharArray() contentArray.forEachIndexed { index, s -> - if (s > start.toChar() && s < end.toChar()) { + if (s in startChar until endChar) { val code = font2.GetCodeByGlyf(font1.GetGlyfByCode(s.toInt())) contentArray[index] = code.toChar() }