From ce4abc9b910b60acdcee7025329ee5adfdce2439 Mon Sep 17 00:00:00 2001 From: joshavant <830519+joshavant@users.noreply.github.com> Date: Fri, 3 Jul 2026 18:11:21 -0500 Subject: [PATCH] Preserve macOS chat typography scaling --- apps/ios/Tests/OpenClawTypographyTests.swift | 11 ++++++++ .../OpenClawChatUI/ChatTypography.swift | 26 ++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/apps/ios/Tests/OpenClawTypographyTests.swift b/apps/ios/Tests/OpenClawTypographyTests.swift index c5290f2e05b..3868b9d24fd 100644 --- a/apps/ios/Tests/OpenClawTypographyTests.swift +++ b/apps/ios/Tests/OpenClawTypographyTests.swift @@ -155,6 +155,11 @@ struct OpenClawTypographyTests { contentsOf: Self.sourceURL("Design/SettingsChannelsDestination.swift"), encoding: .utf8) let docs = try String(contentsOf: Self.sourceURL("Design/OpenClawDocsScreen.swift"), encoding: .utf8) + let chatTypography = try String( + contentsOf: Self.iosRootURL() + .deletingLastPathComponent() + .appendingPathComponent("shared/OpenClawKit/Sources/OpenClawChatUI/ChatTypography.swift"), + encoding: .utf8) let chatMessageViews = try String( contentsOf: Self.iosRootURL() .deletingLastPathComponent() @@ -232,6 +237,12 @@ struct OpenClawTypographyTests { #expect(!chatMessageViews.contains("font: .body")) #expect(!chatMessageViews.contains("Font.body")) #expect(!chatMessageViews.contains("Font.callout")) + #expect(chatTypography + .contains("Font.custom(self.macSystemFontName(size: size), size: size, relativeTo: textStyle)")) + #expect(chatTypography.contains( + "Font.custom(self.macMonospacedSystemFontName(size: size), size: size, relativeTo: textStyle)")) + #expect(!chatTypography.contains("Font.system(textStyle, design: .default)")) + #expect(!chatTypography.contains("Font.system(textStyle, design: .monospaced)")) } @Test func `iOS app text and control calls keep branded font boundaries`() throws { diff --git a/apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatTypography.swift b/apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatTypography.swift index 715b4f4e2c4..bca9eee14fd 100644 --- a/apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatTypography.swift +++ b/apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatTypography.swift @@ -1,5 +1,8 @@ import Foundation import SwiftUI +#if os(macOS) +import AppKit +#endif enum OpenClawChatTypography { static var title3: Font { @@ -43,12 +46,14 @@ enum OpenClawChatTypography { } static func avatar(size: CGFloat) -> Font { - body(size: size, weight: .bold, relativeTo: .caption) + self.body(size: size, weight: .bold, relativeTo: .caption) } static func body(size: CGFloat, weight: Font.Weight, relativeTo textStyle: Font.TextStyle) -> Font { #if os(iOS) - Font.custom(Self.bodyPostScriptName, size: size, relativeTo: textStyle).weight(weight) + Font.custom(self.bodyPostScriptName, size: size, relativeTo: textStyle).weight(weight) + #elseif os(macOS) + Font.custom(self.macSystemFontName(size: size), size: size, relativeTo: textStyle).weight(weight) #else Font.system(size: size, weight: weight) #endif @@ -56,7 +61,9 @@ enum OpenClawChatTypography { static func display(size: CGFloat, weight: Font.Weight, relativeTo textStyle: Font.TextStyle) -> Font { #if os(iOS) - Font.custom(Self.displayPostScriptName, size: size, relativeTo: textStyle).weight(weight) + Font.custom(self.displayPostScriptName, size: size, relativeTo: textStyle).weight(weight) + #elseif os(macOS) + Font.custom(self.macSystemFontName(size: size), size: size, relativeTo: textStyle).weight(weight) #else Font.system(size: size, weight: weight) #endif @@ -66,6 +73,9 @@ enum OpenClawChatTypography { #if os(iOS) let name = weight == .semibold ? Self.monoSemiBoldPostScriptName : Self.monoPostScriptName return Font.custom(name, size: size, relativeTo: textStyle) + #elseif os(macOS) + return Font.custom(self.macMonospacedSystemFontName(size: size), size: size, relativeTo: textStyle) + .weight(weight) #else return Font.system(size: size, weight: weight, design: .monospaced) #endif @@ -75,4 +85,14 @@ enum OpenClawChatTypography { private static let bodyPostScriptName = "Inter-Regular" private static let monoPostScriptName = "JetBrainsMono-Regular" private static let monoSemiBoldPostScriptName = "JetBrainsMono-SemiBold" + + #if os(macOS) + private static func macSystemFontName(size: CGFloat) -> String { + NSFont.systemFont(ofSize: size).fontName + } + + private static func macMonospacedSystemFontName(size: CGFloat) -> String { + NSFont.monospacedSystemFont(ofSize: size, weight: .regular).fontName + } + #endif }