trim font

This should reduce some call overhead, normally once include just contains one font type and not multiple
This commit is contained in:
Bixilon 2023-06-16 16:14:46 +02:00
parent d9e26b1b86
commit 80790c4637
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 11 additions and 2 deletions

View File

@ -49,7 +49,7 @@ class FontManager(
Log.log(LogMessageType.ASSETS, LogLevels.WARN) { "Font ${DefaultFontIndices.DEFAULT} seems to be empty!" }
}
return FontManager(font ?: EmptyFont)
return FontManager(font?.trim() ?: EmptyFont)
}
}
}

View File

@ -25,6 +25,6 @@ object ReferenceFontType : FontTypeFactory<FontType> {
override fun build(context: RenderContext, data: JsonObject): FontType? {
val index = data["id"]?.toResourceLocation()?.prefix("font/")?.suffix(".json") ?: throw IllegalArgumentException("id missing!")
return FontLoader.load(context, index, null)
return FontLoader.load(context, index, null)?.trim()
}
}

View File

@ -71,6 +71,15 @@ class Font(
}
fun trim(): FontType? {
return when (providers.size) {
0 -> null
1 -> providers.first()
else -> this
}
}
companion object {
private const val CACHE_START = ' '.code // all control chars (like ESC, CR, ...) are not used anyway (in a normal environment)
private const val CACHE_SIZE = (1 shl 7) - CACHE_START // ascii