Skip to content

Commit

Permalink
Embed Noto Sans CJK font
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Aug 28, 2023
1 parent d58bf59 commit cb8c7aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,36 @@ public static void print(Object... objects) {
Main.LOGGER.info(sb.toString().trim());
}

public static Font getBuiltinFont(boolean supportCjk, boolean serif) {
public static Font getSystemFont(String fontName) {
ClientCacheAccessor clientCache = (ClientCacheAccessor) ClientData.DATA_CACHE;
if (clientCache.getFont() == null || clientCache.getFontCjk() == null) {
ResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
try {
clientCache.setFont(Font.createFont(Font.TRUETYPE_FONT, Utilities.getInputStream(resourceManager.getResource(
new ResourceLocation(mtr.MTR.MOD_ID, "font/noto-sans-semibold.ttf")))));
clientCache.setFontCjk(Font.createFont(Font.TRUETYPE_FONT, Utilities.getInputStream(resourceManager.getResource(
new ResourceLocation(mtr.MTR.MOD_ID, "font/noto-serif-cjk-tc-semibold.ttf")))));
} catch (Exception e) {
e.printStackTrace();
ResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
switch (fontName) {
case "Noto Sans" -> {
if (clientCache.getFont() == null || !clientCache.getFont().canDisplay('草')) {
try {
clientCache.setFont(Font.createFont(Font.TRUETYPE_FONT, Utilities.getInputStream(resourceManager.getResource(
new ResourceLocation(mtr.MTR.MOD_ID, "font/noto-sans-cjk-tc-medium.otf")))));
} catch (Exception ex) {
Main.LOGGER.warn("Failed loading font", ex);
}
}
return clientCache.getFont();
}
case "Noto Serif" -> {
if (clientCache.getFontCjk() == null) {
try {
clientCache.setFontCjk(Font.createFont(Font.TRUETYPE_FONT, Utilities.getInputStream(resourceManager.getResource(
new ResourceLocation(mtr.MTR.MOD_ID, "font/noto-serif-cjk-tc-semibold.ttf")))));
} catch (Exception ex) {
Main.LOGGER.warn("Failed loading font", ex);
}
}
return clientCache.getFont();
}
default -> {
return Font.getFont(fontName);
}
}
return (serif || supportCjk) ? clientCache.getFontCjk() : clientCache.getFont();
}

private static final FontRenderContext FONT_CONTEXT = new FontRenderContext(new AffineTransform(), true, false);
Expand Down
Binary file not shown.

0 comments on commit cb8c7aa

Please sign in to comment.