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);
}
}
}
Aggregations