From 8a15b7d27461627f80a9d3949161d77dfbe8e3fe Mon Sep 17 00:00:00 2001 From: Glavo Date: Mon, 10 Feb 2025 00:41:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=AD=97=E4=BD=93=E6=97=B6=E6=9C=AA=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E8=AE=BE=E7=BD=AE=E5=AD=97=E9=87=8D=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#3598)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jackhuang/hmcl/setting/Theme.java | 53 +++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) 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('}');