Wear CWF Include otf format compatibility for fonts

This commit is contained in:
Philoul 2023-09-09 23:21:54 +02:00
parent e33358d46c
commit d00c4e223e
2 changed files with 4 additions and 3 deletions

View file

@ -63,7 +63,8 @@ enum class ResFormat(val extension: String) {
SVG("svg"),
JPG("jpg"),
PNG("png"),
TTF("ttf");
TTF("ttf"),
OTF("otf");
companion object {
@ -102,7 +103,7 @@ data class ResData(val value: ByteArray, val format: ResFormat) {
fun toTypeface(): Typeface? {
try {
return when (format) {
ResFormat.TTF -> {
ResFormat.TTF, ResFormat.OTF -> {
// Workaround with temporary File, Typeface.createFromFileDescriptor(null, value, 0, value.size) more simple not available
File.createTempFile("temp", format.extension).let { tempFile ->
FileOutputStream(tempFile).let { fileOutputStream ->

View file

@ -554,7 +554,7 @@ private enum class FontMap(val key: String, var font: Typeface, @FontRes val fon
} ?: fontMap.font
}
resDataMap.filter { (_, resData) ->
resData.format == ResFormat.TTF
resData.format == ResFormat.TTF || resData.format == ResFormat.OTF
}.forEach { (key, resData) ->
customFonts[key.lowercase()] = resData.toTypeface() ?:Typeface.DEFAULT
}