diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Theme.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Theme.java index a120b6640..c72d69da0 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Theme.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Theme.java @@ -25,6 +25,7 @@ import javafx.beans.binding.ObjectBinding; import javafx.scene.paint.Color; import javafx.scene.text.Font; import org.jackhuang.hmcl.ui.FXUtils; +import org.jackhuang.hmcl.util.Pair; import org.jackhuang.hmcl.util.io.FileUtils; import java.io.File; @@ -123,6 +124,45 @@ public class Theme { opacity); } + private static Pair parseFontStyle(String style) { + if (style == null) { + return null; + } + + style = style.toLowerCase(Locale.ROOT); + + String weight; + String posture; + + if (style.contains("thin")) { + weight = "100"; + } else if (style.contains("extralight") || style.contains("extra light") || style.contains("ultralight") | style.contains("ultra light")) { + weight = "200"; + } else if (style.contains("medium")) { + weight = "500"; + } else if (style.contains("semibold") || style.contains("semi bold") || style.contains("demibold") || style.contains("demi bold")) { + weight = "600"; + } else if (style.contains("extrabold") || style.contains("extra bold") || style.contains("ultrabold") || style.contains("ultra bold")) { + weight = "800"; + } else if (style.contains("black") || style.contains("heavy")) { + weight = "900"; + } else if (style.contains("light")) { + weight = "lighter"; + } else if (style.contains("bold")) { + weight = "bold"; + } else { + weight = null; + } + + if (style.contains("italic") || style.contains("oblique")) { + posture = "italic"; + } else { + posture = null; + } + + return Pair.pair(weight, posture); + } + public String[] getStylesheets(String overrideFontFamily) { String css = "/assets/css/blue.css"; @@ -130,12 +170,12 @@ public class Theme { ? System.getProperty("hmcl.font.override", System.getenv("HMCL_FONT")) : overrideFontFamily; - String fontStyle = null; + Pair fontStyle = null; if (fontFamily == null) { Optional font = tryLoadFont(); if (font.isPresent()) { fontFamily = font.get().getFamily(); - fontStyle = font.get().getStyle(); + fontStyle = parseFontStyle(font.get().getStyle()); } } @@ -159,8 +199,13 @@ public class Theme { else themeBuilder.append("-fx-font-family:\"").append(fontFamily).append("\";"); - if (fontStyle != null && !fontStyle.isEmpty()) - themeBuilder.append("-fx-font-style:\"").append(fontStyle).append("\";"); + if (fontStyle != null) { + if (fontStyle.getKey() != null) + themeBuilder.append("-fx-font-weight:").append(fontStyle.getKey()).append(";"); + + if (fontStyle.getValue() != null) + themeBuilder.append("-fx-font-style:").append(fontStyle.getValue()).append(";"); + } themeBuilder.append('}');