将 FontReference 转换为 record (#5187)
This commit is contained in:
@@ -99,8 +99,7 @@ public final class FontManager {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
updateFont();
|
updateFont();
|
||||||
|
LOG.info("Font: " + (font.get() != null ? font.get().family() : "System"));
|
||||||
LOG.info("Font: " + (font.get() != null ? font.get().getFamily() : "System"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateFont() {
|
private static void updateFont() {
|
||||||
@@ -242,44 +241,17 @@ public final class FontManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/HMCL-dev/HMCL/issues/4072
|
// https://github.com/HMCL-dev/HMCL/issues/4072
|
||||||
public static final class FontReference {
|
public record FontReference(@NotNull String family, @Nullable String style) {
|
||||||
private final @NotNull String family;
|
public FontReference {
|
||||||
private final @Nullable String style;
|
Objects.requireNonNull(family);
|
||||||
|
}
|
||||||
|
|
||||||
public FontReference(@NotNull String family) {
|
public FontReference(@NotNull String family) {
|
||||||
this.family = Objects.requireNonNull(family);
|
this(family, null);
|
||||||
this.style = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FontReference(@NotNull Font font) {
|
public FontReference(@NotNull Font font) {
|
||||||
this.family = font.getFamily();
|
this(font.getFamily(), font.getStyle());
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,11 +90,11 @@ public final class StyleSheets {
|
|||||||
final String defaultCss = "/assets/css/font.css";
|
final String defaultCss = "/assets/css/font.css";
|
||||||
final FontManager.FontReference font = FontManager.getFont();
|
final FontManager.FontReference font = FontManager.getFont();
|
||||||
|
|
||||||
if (font == null || "System".equals(font.getFamily()))
|
if (font == null || "System".equals(font.family()))
|
||||||
return defaultCss;
|
return defaultCss;
|
||||||
|
|
||||||
String fontFamily = font.getFamily();
|
String fontFamily = font.family();
|
||||||
String style = font.getStyle();
|
String style = font.style();
|
||||||
String weight = null;
|
String weight = null;
|
||||||
String posture = null;
|
String posture = null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user