Wear CWF Include otf format compatibility for fonts
This commit is contained in:
parent
e33358d46c
commit
d00c4e223e
|
@ -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 ->
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue