Search in sources :

Example 1 with BlankFont

use of net.minecraft.client.font.BlankFont in project SpeedRunIGT by RedLime.

the class FontUtils method addFont.

public static void addFont(HashMap<Identifier, List<Font>> map, File file, File configFile) {
    FileInputStream fileInputStream = null;
    STBTTFontinfo sTBTTFontinfo = null;
    ByteBuffer byteBuffer = null;
    Throwable throwable = null;
    try {
        fileInputStream = new FileInputStream(file);
        sTBTTFontinfo = STBTTFontinfo.malloc();
        byteBuffer = TextureUtil.readAllToByteBuffer(fileInputStream);
        byteBuffer.flip();
        if (!STBTruetype.stbtt_InitFont(sTBTTFontinfo, byteBuffer)) {
            return;
        }
        Identifier fontIdentifier = new Identifier(SpeedRunIGT.MOD_ID, file.getName().toLowerCase(Locale.ROOT).replace(".ttf", "").replaceAll(" ", "_").replaceAll("[^a-z0-9/._-]", ""));
        ArrayList<Font> fontArrayList = new ArrayList<>();
        FontConfigure fontConfigure;
        if (configFile != null && configFile.exists()) {
            fontConfigure = FontConfigure.fromJson(FileUtils.readFileToString(configFile, StandardCharsets.UTF_8));
        } else {
            fontConfigure = FontConfigure.create();
        }
        fontArrayList.add(new TrueTypeFont(byteBuffer, sTBTTFontinfo, fontConfigure.size, fontConfigure.oversample, fontConfigure.shift[0], fontConfigure.shift[1], fontConfigure.skip));
        SpeedRunIGT.FONT_MAPS.put(fontIdentifier, new FontIdentifier(file, fontIdentifier, fontConfigure));
        fontArrayList.add(new BlankFont());
        map.put(fontIdentifier, fontArrayList);
    } catch (FileNotFoundException e) {
        if (sTBTTFontinfo != null)
            sTBTTFontinfo.free();
        MemoryUtil.memFree(byteBuffer);
    } catch (IOException throwable1) {
        throwable = throwable1;
    } finally {
        try {
            if (fileInputStream != null)
                fileInputStream.close();
        } catch (IOException e) {
            if (throwable != null)
                throwable.addSuppressed(e);
        }
    }
}
Also used : TrueTypeFont(net.minecraft.client.font.TrueTypeFont) STBTTFontinfo(org.lwjgl.stb.STBTTFontinfo) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) Font(net.minecraft.client.font.Font) BlankFont(net.minecraft.client.font.BlankFont) TrueTypeFont(net.minecraft.client.font.TrueTypeFont) Identifier(net.minecraft.util.Identifier) BlankFont(net.minecraft.client.font.BlankFont)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 BlankFont (net.minecraft.client.font.BlankFont)1 Font (net.minecraft.client.font.Font)1 TrueTypeFont (net.minecraft.client.font.TrueTypeFont)1 Identifier (net.minecraft.util.Identifier)1 STBTTFontinfo (org.lwjgl.stb.STBTTFontinfo)1