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"), SVG("svg"),
JPG("jpg"), JPG("jpg"),
PNG("png"), PNG("png"),
TTF("ttf"); TTF("ttf"),
OTF("otf");
companion object { companion object {
@ -102,7 +103,7 @@ data class ResData(val value: ByteArray, val format: ResFormat) {
fun toTypeface(): Typeface? { fun toTypeface(): Typeface? {
try { try {
return when (format) { return when (format) {
ResFormat.TTF -> { ResFormat.TTF, ResFormat.OTF -> {
// Workaround with temporary File, Typeface.createFromFileDescriptor(null, value, 0, value.size) more simple not available // Workaround with temporary File, Typeface.createFromFileDescriptor(null, value, 0, value.size) more simple not available
File.createTempFile("temp", format.extension).let { tempFile -> File.createTempFile("temp", format.extension).let { tempFile ->
FileOutputStream(tempFile).let { fileOutputStream -> 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 } ?: fontMap.font
} }
resDataMap.filter { (_, resData) -> resDataMap.filter { (_, resData) ->
resData.format == ResFormat.TTF resData.format == ResFormat.TTF || resData.format == ResFormat.OTF
}.forEach { (key, resData) -> }.forEach { (key, resData) ->
customFonts[key.lowercase()] = resData.toTypeface() ?:Typeface.DEFAULT customFonts[key.lowercase()] = resData.toTypeface() ?:Typeface.DEFAULT
} }