diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/FontManager.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/FontManager.java index e772d2b2b..cdda72f11 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/FontManager.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/FontManager.java @@ -99,8 +99,7 @@ public final class FontManager { static { updateFont(); - - LOG.info("Font: " + (font.get() != null ? font.get().getFamily() : "System")); + LOG.info("Font: " + (font.get() != null ? font.get().family() : "System")); } private static void updateFont() { @@ -242,44 +241,17 @@ public final class FontManager { } // https://github.com/HMCL-dev/HMCL/issues/4072 - public static final class FontReference { - private final @NotNull String family; - private final @Nullable String style; + public record FontReference(@NotNull String family, @Nullable String style) { + public FontReference { + Objects.requireNonNull(family); + } public FontReference(@NotNull String family) { - this.family = Objects.requireNonNull(family); - this.style = null; + this(family, null); } public FontReference(@NotNull Font font) { - this.family = font.getFamily(); - this.style = font.getStyle(); - } - - public @NotNull String getFamily() { - return family; - } - - public @Nullable String getStyle() { - return style; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof FontReference)) - return false; - FontReference that = (FontReference) o; - return Objects.equals(family, that.family) && Objects.equals(style, that.style); - } - - @Override - public int hashCode() { - return Objects.hash(family, style); - } - - @Override - public String toString() { - return String.format("FontReference[family='%s', style='%s']", family, style); + this(font.getFamily(), font.getStyle()); } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/StyleSheets.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/StyleSheets.java index 3d2142e57..f9d2d5490 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/StyleSheets.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/StyleSheets.java @@ -90,11 +90,11 @@ public final class StyleSheets { final String defaultCss = "/assets/css/font.css"; final FontManager.FontReference font = FontManager.getFont(); - if (font == null || "System".equals(font.getFamily())) + if (font == null || "System".equals(font.family())) return defaultCss; - String fontFamily = font.getFamily(); - String style = font.getStyle(); + String fontFamily = font.family(); + String style = font.style(); String weight = null; String posture = null;