25
25
import javafx .scene .paint .Color ;
26
26
import javafx .scene .text .Font ;
27
27
import org .jackhuang .hmcl .ui .FXUtils ;
28
+ import org .jackhuang .hmcl .util .Pair ;
28
29
import org .jackhuang .hmcl .util .io .FileUtils ;
29
30
30
31
import java .io .File ;
@@ -123,19 +124,58 @@ private static String rgba(Color color, double opacity) {
123
124
opacity );
124
125
}
125
126
127
+ private static Pair <String , String > parseFontStyle (String style ) {
128
+ if (style == null ) {
129
+ return null ;
130
+ }
131
+
132
+ style = style .toLowerCase (Locale .ROOT );
133
+
134
+ String weight ;
135
+ String posture ;
136
+
137
+ if (style .contains ("thin" )) {
138
+ weight = "100" ;
139
+ } else if (style .contains ("extralight" ) || style .contains ("extra light" ) || style .contains ("ultralight" ) | style .contains ("ultra light" )) {
140
+ weight = "200" ;
141
+ } else if (style .contains ("medium" )) {
142
+ weight = "500" ;
143
+ } else if (style .contains ("semibold" ) || style .contains ("semi bold" ) || style .contains ("demibold" ) || style .contains ("demi bold" )) {
144
+ weight = "600" ;
145
+ } else if (style .contains ("extrabold" ) || style .contains ("extra bold" ) || style .contains ("ultrabold" ) || style .contains ("ultra bold" )) {
146
+ weight = "800" ;
147
+ } else if (style .contains ("black" ) || style .contains ("heavy" )) {
148
+ weight = "900" ;
149
+ } else if (style .contains ("light" )) {
150
+ weight = "lighter" ;
151
+ } else if (style .contains ("bold" )) {
152
+ weight = "bold" ;
153
+ } else {
154
+ weight = null ;
155
+ }
156
+
157
+ if (style .contains ("italic" ) || style .contains ("oblique" )) {
158
+ posture = "italic" ;
159
+ } else {
160
+ posture = null ;
161
+ }
162
+
163
+ return Pair .pair (weight , posture );
164
+ }
165
+
126
166
public String [] getStylesheets (String overrideFontFamily ) {
127
167
String css = "/assets/css/blue.css" ;
128
168
129
169
String fontFamily = overrideFontFamily == null
130
170
? System .getProperty ("hmcl.font.override" , System .getenv ("HMCL_FONT" ))
131
171
: overrideFontFamily ;
132
172
133
- String fontStyle = null ;
173
+ Pair < String , String > fontStyle = null ;
134
174
if (fontFamily == null ) {
135
175
Optional <Font > font = tryLoadFont ();
136
176
if (font .isPresent ()) {
137
177
fontFamily = font .get ().getFamily ();
138
- fontStyle = font .get ().getStyle ();
178
+ fontStyle = parseFontStyle ( font .get ().getStyle () );
139
179
}
140
180
}
141
181
@@ -159,8 +199,13 @@ public String[] getStylesheets(String overrideFontFamily) {
159
199
else
160
200
themeBuilder .append ("-fx-font-family:\" " ).append (fontFamily ).append ("\" ;" );
161
201
162
- if (fontStyle != null && !fontStyle .isEmpty ())
163
- themeBuilder .append ("-fx-font-style:\" " ).append (fontStyle ).append ("\" ;" );
202
+ if (fontStyle != null ) {
203
+ if (fontStyle .getKey () != null )
204
+ themeBuilder .append ("-fx-font-weight:" ).append (fontStyle .getKey ()).append (";" );
205
+
206
+ if (fontStyle .getValue () != null )
207
+ themeBuilder .append ("-fx-font-style:" ).append (fontStyle .getValue ()).append (";" );
208
+ }
164
209
165
210
themeBuilder .append ('}' );
166
211
0 commit comments