@@ -24,6 +24,7 @@ public final class AppKitBackend: AppBackend {
2424 public let requiresImageUpdateOnScaleFactorChange = false
2525 public let menuImplementationStyle = MenuImplementationStyle . dynamicPopover
2626 public let canRevealFiles = true
27+ public let deviceClass = DeviceClass . desktop
2728
2829 public var scrollBarWidth : Int {
2930 // We assume that all scrollers have their controlSize set to `.regular` by default.
@@ -323,13 +324,9 @@ public final class AppKitBackend: AppBackend {
323324
324325 public func computeRootEnvironment( defaultEnvironment: EnvironmentValues ) -> EnvironmentValues {
325326 let isDark = UserDefaults . standard. string ( forKey: " AppleInterfaceStyle " ) == " Dark "
326- let font = Font . system (
327- size: Int ( NSFont . systemFont ( ofSize: 0.0 ) . pointSize. rounded ( . awayFromZero) )
328- )
329327 return
330328 defaultEnvironment
331329 . with ( \. colorScheme, isDark ? . dark : . light)
332- . with ( \. font, font)
333330 }
334331
335332 public func setRootEnvironmentChangeHandler( to action: @escaping ( ) -> Void ) {
@@ -752,8 +749,9 @@ public final class AppKitBackend: AppBackend {
752749 textField. isEnabled = environment. isEnabled
753750 textField. placeholderString = placeholder
754751 textField. appearance = environment. colorScheme. nsAppearance
755- if textField. font != Self . font ( for: environment) {
756- textField. font = Self . font ( for: environment)
752+ let resolvedFont = environment. resolvedFont
753+ if textField. font != Self . font ( for: resolvedFont) {
754+ textField. font = Self . font ( for: resolvedFont)
757755 }
758756 textField. onEdit = { textField in
759757 onChange ( textField. stringValue)
@@ -806,8 +804,9 @@ public final class AppKitBackend: AppBackend {
806804 textEditor. onEdit = { textView in
807805 onChange ( self . getContent ( ofTextEditor: textView) )
808806 }
809- if textEditor. font != Self . font ( for: environment) {
810- textEditor. font = Self . font ( for: environment)
807+ let resolvedFont = environment. resolvedFont
808+ if textEditor. font != Self . font ( for: resolvedFont) {
809+ textEditor. font = Self . font ( for: resolvedFont)
811810 }
812811 textEditor. appearance = environment. colorScheme. nsAppearance
813812 textEditor. isEditable = environment. isEnabled
@@ -1112,50 +1111,55 @@ public final class AppKitBackend: AppBackend {
11121111 case . trailing:
11131112 . right
11141113 }
1114+
1115+ let resolvedFont = environment. resolvedFont
1116+
1117+ // This is definitely what these properties were intended for
1118+ paragraphStyle. minimumLineHeight = CGFloat ( resolvedFont. lineHeight)
1119+ paragraphStyle. maximumLineHeight = CGFloat ( resolvedFont. lineHeight)
1120+ paragraphStyle. lineSpacing = 0
1121+
11151122 return [
11161123 . foregroundColor: environment. suggestedForegroundColor. nsColor,
1117- . font: font ( for: environment ) ,
1124+ . font: font ( for: resolvedFont ) ,
11181125 . paragraphStyle: paragraphStyle,
11191126 ]
11201127 }
11211128
1122- private static func font( for environment : EnvironmentValues ) -> NSFont {
1123- switch environment . font {
1124- case . system ( let size , let weight, let design ) :
1125- switch design {
1126- case . default , . none :
1127- NSFont . systemFont (
1128- ofSize : CGFloat ( size ) , weight : weight . map ( Self . weight ( for : ) ) ?? . regular
1129- )
1129+ private static func font( for font : Font . Resolved ) -> NSFont {
1130+ let size = CGFloat ( font . pointSize )
1131+ let weight = weight ( for : font . weight )
1132+ switch font . identifier . kind {
1133+ case . system :
1134+ switch font . design {
1135+ case . default :
1136+ return NSFont . systemFont ( ofSize : size , weight : weight )
11301137 case . monospaced:
1131- NSFont . monospacedSystemFont (
1132- ofSize: CGFloat ( size) ,
1133- weight: weight. map ( Self . weight ( for: ) ) ?? . regular
1134- )
1138+ return NSFont . monospacedSystemFont ( ofSize: size, weight: weight)
11351139 }
11361140 }
11371141 }
11381142
11391143 private static func weight( for weight: Font . Weight ) -> NSFont . Weight {
11401144 switch weight {
1141- case . black:
1142- . black
1143- case . bold:
1144- . bold
1145- case . heavy:
1146- . heavy
1145+ case . thin:
1146+ . thin
1147+ case . ultraLight:
1148+ . ultraLight
11471149 case . light:
11481150 . light
1149- case . medium:
1150- . medium
11511151 case . regular:
11521152 . regular
1153+ case . medium:
1154+ . medium
11531155 case . semibold:
11541156 . semibold
1155- case . thin:
1156- . thin
1157- case . ultraLight:
1158- . ultraLight
1157+ case . bold:
1158+ . bold
1159+ case . black:
1160+ . black
1161+ case . heavy:
1162+ . heavy
11591163 }
11601164 }
11611165
0 commit comments