Skip to content

Commit 909c2db

Browse files
committed
fix: Meteor b51 - Refactor FontUtils Font loading
1 parent 00352bd commit 909c2db

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

src/main/java/me/pindour/catpuccin/gui/text/RichTextRenderer.java

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
import meteordevelopment.meteorclient.renderer.MeshRenderer;
66
import meteordevelopment.meteorclient.renderer.MeteorRenderPipelines;
77
import meteordevelopment.meteorclient.renderer.text.*;
8-
import meteordevelopment.meteorclient.utils.Utils;
98
import meteordevelopment.meteorclient.utils.render.color.Color;
109
import net.minecraft.client.MinecraftClient;
11-
import org.lwjgl.BufferUtils;
1210

11+
import java.io.IOException;
1312
import java.nio.ByteBuffer;
1413

1514
public 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
}

src/main/java/me/pindour/catpuccin/gui/themes/catpuccin/CatpuccinGuiTheme.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.pindour.catpuccin.gui.themes.catpuccin;
22

3+
import me.pindour.catpuccin.CatpuccinAddon;
34
import me.pindour.catpuccin.gui.animation.AnimationType;
45
import me.pindour.catpuccin.gui.renderer.CatpuccinRenderer;
56
import me.pindour.catpuccin.gui.screens.CatpuccinModuleScreen;
@@ -623,7 +624,14 @@ public TextRenderer textRenderer() {
623624
}
624625

625626
public RichTextRenderer richTextRenderer() {
626-
if (textRenderer == null) textRenderer = new RichTextRenderer(Config.get().font.get());
627+
if (textRenderer == null) {
628+
try {
629+
setTextRenderer(new RichTextRenderer(Config.get().font.get()));
630+
} catch (Exception e) {
631+
CatpuccinAddon.LOG.error("Failed to load TextRenderer: ", e);
632+
}
633+
}
634+
627635
return textRenderer;
628636
}
629637

0 commit comments

Comments
 (0)