优化
This commit is contained in:
@@ -456,28 +456,33 @@ interface JsExtensions {
|
|||||||
*/
|
*/
|
||||||
fun queryTTF(str: String?): QueryTTF? {
|
fun queryTTF(str: String?): QueryTTF? {
|
||||||
str ?: return null
|
str ?: return null
|
||||||
val key = md5Encode16(str)
|
try {
|
||||||
var qTTF = CacheManager.getQueryTTF(key)
|
val key = md5Encode16(str)
|
||||||
if (qTTF != null) return qTTF
|
var qTTF = CacheManager.getQueryTTF(key)
|
||||||
val font: ByteArray? = when {
|
if (qTTF != null) return qTTF
|
||||||
str.isAbsUrl() -> runBlocking {
|
val font: ByteArray? = when {
|
||||||
var x = CacheManager.getByteArray(key)
|
str.isAbsUrl() -> runBlocking {
|
||||||
if (x == null) {
|
var x = CacheManager.getByteArray(key)
|
||||||
x = okHttpClient.newCallResponseBody { url(str) }.bytes()
|
if (x == null) {
|
||||||
x.let {
|
x = okHttpClient.newCallResponseBody { url(str) }.bytes()
|
||||||
CacheManager.put(key, it)
|
x.let {
|
||||||
|
CacheManager.put(key, it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return@runBlocking x
|
||||||
}
|
}
|
||||||
return@runBlocking x
|
str.isContentScheme() -> Uri.parse(str).readBytes(appCtx)
|
||||||
|
str.startsWith("/storage") -> File(str).readBytes()
|
||||||
|
else -> base64DecodeToByteArray(str)
|
||||||
}
|
}
|
||||||
str.isContentScheme() -> Uri.parse(str).readBytes(appCtx)
|
font ?: return null
|
||||||
str.startsWith("/storage") -> File(str).readBytes()
|
qTTF = QueryTTF(font)
|
||||||
else -> base64DecodeToByteArray(str)
|
CacheManager.put(key, qTTF)
|
||||||
|
return qTTF
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Timber.e(e, "获取字体处理类出错")
|
||||||
|
throw e
|
||||||
}
|
}
|
||||||
font ?: return null
|
|
||||||
qTTF = QueryTTF(font)
|
|
||||||
CacheManager.put(key, qTTF)
|
|
||||||
return qTTF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user