Wear CWF Clean loaded font before loading

This commit is contained in:
Philoul 2023-09-09 23:15:28 +02:00
parent a9b6fdef27
commit e33358d46c
2 changed files with 2 additions and 1 deletions

View file

@ -104,7 +104,7 @@ data class ResData(val value: ByteArray, val format: ResFormat) {
return when (format) {
ResFormat.TTF -> {
// Workaround with temporary File, Typeface.createFromFileDescriptor(null, value, 0, value.size) more simple not available
File.createTempFile("temp", ".ttf").let { tempFile ->
File.createTempFile("temp", format.extension).let { tempFile ->
FileOutputStream(tempFile).let { fileOutputStream ->
fileOutputStream.write(value)
fileOutputStream.close()

View file

@ -547,6 +547,7 @@ private enum class FontMap(val key: String, var font: Typeface, @FontRes val fon
private val customFonts = mutableMapOf<String, Typeface>()
fun init(context: Context, resDataMap: CwfResDataMap) {
customFonts.clear()
values().forEach { fontMap ->
customFonts[fontMap.key.lowercase()] = fontMap.fontRessources?.let { fontResource ->
ResourcesCompat.getFont(context, fontResource)