unihex font type: read buffered from zip

This commit is contained in:
Bixilon 2023-06-17 14:28:30 +02:00
parent 4e187b9985
commit 7ad39a72d7
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 6 additions and 5 deletions

View File

@ -60,10 +60,7 @@ class UnifontTexture(
private fun TextureData.set(row: Int, offset: Int, x: Int, y: Int) {
val index = ((row * UnifontRasterizer.HEIGHT + y) * size.x + offset + x) * 4
buffer.put(index + 0, 0xFF.toByte())
buffer.put(index + 1, 0xFF.toByte())
buffer.put(index + 2, 0xFF.toByte())
buffer.put(index + 3, 0xFF.toByte())
buffer.putInt(index, 0xFFFFFFFF.toInt())
}
private fun rasterize(row: Int, offset: Int, width: Int, data: ByteArray): CodePointRenderer {

View File

@ -23,6 +23,7 @@ import de.bixilon.minosoft.gui.rendering.font.types.factory.FontTypeFactory
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.listCast
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
import java.io.BufferedInputStream
import java.io.InputStream
import java.util.zip.ZipInputStream
@ -48,6 +49,7 @@ class UnihexFontType(
fun load(context: RenderContext, hexFile: ResourceLocation, sizes: List<SizeOverride>): UnihexFontType? {
val stream = ZipInputStream(context.connection.assetsManager[hexFile])
val buffered = BufferedInputStream(stream)
val chars = Int2ObjectOpenHashMap<ByteArray>()
var totalWidth = 0
@ -55,7 +57,7 @@ class UnihexFontType(
val entry = stream.nextEntry ?: break
if (!entry.name.endsWith(".hex")) continue
totalWidth += stream.readUnihex(chars)
totalWidth += buffered.readUnihex(chars)
}
if (chars.isEmpty()) return null
@ -72,6 +74,8 @@ class UnihexFontType(
rasterized[entry.intKey] = rasterizer.add(entry.value)
}
rasterized.trim()
return UnihexFontType(rasterized)
}