55import meteordevelopment .meteorclient .renderer .MeshRenderer ;
66import meteordevelopment .meteorclient .renderer .MeteorRenderPipelines ;
77import meteordevelopment .meteorclient .renderer .text .*;
8- import meteordevelopment .meteorclient .utils .Utils ;
98import meteordevelopment .meteorclient .utils .render .color .Color ;
109import net .minecraft .client .MinecraftClient ;
11- import org .lwjgl .BufferUtils ;
1210
11+ import java .io .IOException ;
1312import java .nio .ByteBuffer ;
1413
1514public class RichTextRenderer implements TextRenderer {
@@ -29,27 +28,14 @@ public class RichTextRenderer implements TextRenderer {
2928 private double fontScale = 1 ;
3029 private double scale = 1 ;
3130
32- public RichTextRenderer (FontFace regularFace , FontFace boldFace , FontFace italicFace ) {
33- if (boldFace == null || italicFace == null ) {
34- FontFamily fontFamily = findFontFamily (regularFace );
35-
36- regularFace = fontFamily .get (FontInfo .Type .Regular );
37- boldFace = fontFamily .get (FontInfo .Type .Bold );
38- italicFace = fontFamily .get (FontInfo .Type .Italic );
39- }
40-
41- this .regularFonts = loadFonts (regularFace );
42- this .boldFonts = boldFace != null ? loadFonts (boldFace ) : regularFonts ;
43- this .italicFonts = italicFace != null ? loadFonts (italicFace ) : regularFonts ;
31+ public RichTextRenderer (FontFace fontFace ) throws IOException {
32+ this .regularFonts = loadFonts (fontFace );
33+ this .boldFonts = resolveVariant (fontFace , FontInfo .Type .Bold );
34+ this .italicFonts = resolveVariant (fontFace , FontInfo .Type .Italic );
4435 }
4536
46- public RichTextRenderer (FontFace fontFace ) {
47- this (fontFace , null , null );
48- }
49-
50- private Font [] loadFonts (FontFace fontFace ) {
51- byte [] bytes = Utils .readBytes (fontFace .toStream ());
52- ByteBuffer buffer = BufferUtils .createByteBuffer (bytes .length ).put (bytes ).flip ();
37+ private Font [] loadFonts (FontFace fontFace ) throws IOException {
38+ ByteBuffer buffer = fontFace .readToDirectByteBuffer ();
5339
5440 Font [] fonts = new Font [5 ];
5541
@@ -59,6 +45,16 @@ private Font[] loadFonts(FontFace fontFace) {
5945 return fonts ;
6046 }
6147
48+ private Font [] resolveVariant (FontFace regularFace , FontInfo .Type type ) throws IOException {
49+ FontFamily family = Fonts .getFamily (regularFace .info .family ());
50+ FontFace fontVariant = family .get (type );
51+
52+ if (fontVariant != null && fontVariant != regularFace )
53+ return loadFonts (fontVariant );
54+
55+ return regularFonts ; // Fallback
56+ }
57+
6258 @ Override
6359 public void setAlpha (double a ) {
6460 mesh .alpha = a ;
@@ -250,12 +246,4 @@ private Font getCurrentFont(Font[] fonts) {
250246
251247 return fonts [0 ];
252248 }
253-
254- private FontFamily findFontFamily (FontFace fontFace ) {
255- for (FontFamily fontFamily : Fonts .FONT_FAMILIES )
256- if (fontFamily .getName ().equalsIgnoreCase (fontFace .info .family ()))
257- return fontFamily ;
258-
259- return Fonts .FONT_FAMILIES .getFirst ();
260- }
261249}
0 commit comments