Skip to content

Commit

Permalink
[Fix] Better font creator
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed May 31, 2024
1 parent 111e615 commit ce0d601
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions sources/SquirrelTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,20 @@ private extension SquirrelTheme {
let fontStrings = fontString.split(separator: ",")
var fonts = [NSFont]()
for string in fontStrings {
let trimedString = string.trimmingCharacters(in: .whitespaces)
let familyName = if let firstPart = trimedString.split(separator: "-").first {
String(firstPart)
} else {
trimedString
}
if !seenFontFamilies.contains(familyName) {
seenFontFamilies.insert(familyName)
if let validFont = NSFont(name: trimedString, size: Self.defaultFontSize) {
fonts.append(validFont)
if let matchedFontName = try? /^\s*(.+)-([^-]+)\s*$/.firstMatch(in: string) {
let family = String(matchedFontName.output.1)
let style = String(matchedFontName.output.2)
let fontDescriptor = NSFontDescriptor(fontAttributes: [.family: family, .face: style])
if let font = NSFont(descriptor: fontDescriptor, size: Self.defaultFontSize) {
fonts.append(font)
continue
}
}
let fontDescriptor = NSFontDescriptor(fontAttributes: [.name: string.trimmingCharacters(in: .whitespaces)])
if let font = NSFont(descriptor: fontDescriptor, size: Self.defaultFontSize) {
fonts.append(font)
continue
}
}
return fonts
}
Expand Down

0 comments on commit ce0d601

Please sign in to comment.