File tree 1 file changed +17
-10
lines changed
1 file changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -300,18 +300,25 @@ private extension SquirrelTheme {
300
300
let fontStrings = fontString. split ( separator: " , " )
301
301
var fonts = [ NSFont] ( )
302
302
for string in fontStrings {
303
- let trimedString = string. trimmingCharacters ( in: . whitespaces)
304
- let familyName = if let firstPart = trimedString. split ( separator: " - " ) . first {
305
- String ( firstPart)
306
- } else {
307
- trimedString
308
- }
309
- if !seenFontFamilies. contains ( familyName) {
310
- seenFontFamilies. insert ( familyName)
311
- if let validFont = NSFont ( name: trimedString, size: Self . defaultFontSize) {
312
- fonts. append ( validFont)
303
+ if let matchedFontName = try ? /^ \s* ( .+ ) - ( [ ^- ] + ) \s* $/ . firstMatch( in: string) {
304
+ let family = String ( matchedFontName. output. 1 )
305
+ let style = String ( matchedFontName. output. 2 )
306
+ if seenFontFamilies. contains ( family) { continue }
307
+ let fontDescriptor = NSFontDescriptor ( fontAttributes: [ . family: family, . face: style] )
308
+ if let font = NSFont ( descriptor: fontDescriptor, size: Self . defaultFontSize) {
309
+ fonts. append ( font)
310
+ seenFontFamilies. insert ( family)
311
+ continue
313
312
}
314
313
}
314
+ let fontName = string. trimmingCharacters ( in: . whitespaces)
315
+ if seenFontFamilies. contains ( fontName) { continue }
316
+ let fontDescriptor = NSFontDescriptor ( fontAttributes: [ . name: fontName] )
317
+ if let font = NSFont ( descriptor: fontDescriptor, size: Self . defaultFontSize) {
318
+ fonts. append ( font)
319
+ seenFontFamilies. insert ( fontName)
320
+ continue
321
+ }
315
322
}
316
323
return fonts
317
324
}
You can’t perform that action at this time.
0 commit comments