Use Atkinson Hyperlegible Next, keeping Mono for code

This commit is contained in:
Ian Gulliver
2026-10-21 08:48:30 -07:00
parent 279919c6cd
commit 6a949dc448
14 changed files with 28 additions and 118 deletions
+2 -2
View File
@@ -418,7 +418,7 @@ private struct HiddenComments: View {
.font(Fonts.font(11))
.foregroundStyle(Palette.muted)
Text(verbatim: c.anchor.quote)
.font(Fonts.font(11))
.font(Fonts.font(11, mono: true))
.lineLimit(1)
.truncationMode(.tail)
LineCommentBox(drafts: drafts, taskId: taskId, anchor: c.anchor)
@@ -608,7 +608,7 @@ struct DiffLines: View {
}
}
}
.font(Fonts.font(11))
.font(Fonts.font(11, mono: true))
.padding(.vertical, 4)
.textSelection(.enabled)
}
+1 -1
View File
@@ -432,7 +432,7 @@ private struct FileText: View {
.textSelection(.enabled)
.padding(.trailing, 10)
}
.font(Fonts.font(11))
.font(Fonts.font(11, mono: true))
.fixedSize()
.padding(.vertical, 6)
if content.truncated {
+13 -12
View File
@@ -37,15 +37,16 @@ final class FontSize {
}
enum Fonts {
private static func file(_ subset: String, _ italic: Bool, _ weight: CGFloat) -> CTFontDescriptor {
let url = Bundle.main.resourceURL!.appending(path: "fonts/atkinson-hyperlegible-mono-\(subset)-wght-\(italic ? "italic" : "normal").woff2")
private static func file(_ family: String, _ subset: String, _ italic: Bool, _ weight: CGFloat) -> CTFontDescriptor {
let url = Bundle.main.resourceURL!.appending(path: "fonts/atkinson-hyperlegible-\(family)-\(subset)-wght-\(italic ? "italic" : "normal").woff2")
let d = (CTFontManagerCreateFontDescriptorsFromURL(url as CFURL) as! [CTFontDescriptor])[0]
return CTFontDescriptorCreateCopyWithVariation(d, 0x7767_6874 as CFNumber, weight)
}
private static func ct(_ size: CGFloat, weight: CGFloat = 400, italic: Bool = false) -> CTFont {
let ext = file("latin-ext", italic, weight)
let d = CTFontDescriptorCreateCopyWithAttributes(file("latin", italic, weight), [kCTFontCascadeListAttribute: [ext]] as CFDictionary)
private static func ct(_ size: CGFloat, weight: CGFloat, italic: Bool, mono: Bool) -> CTFont {
let family = mono ? "mono" : "next"
let ext = file(family, "latin-ext", italic, weight)
let d = CTFontDescriptorCreateCopyWithAttributes(file(family, "latin", italic, weight), [kCTFontCascadeListAttribute: [ext]] as CFDictionary)
return CTFontCreateWithFontDescriptor(d, size, nil)
}
@@ -53,26 +54,26 @@ enum Fonts {
// Call sites give sizes relative to a 13pt body; the user's font size shifts them all.
@MainActor
private static func cached(_ size: CGFloat, _ weight: CGFloat, _ italic: Bool) -> CTFont {
private static func cached(_ size: CGFloat, _ weight: CGFloat, _ italic: Bool, _ mono: Bool) -> CTFont {
let size = size + CGFloat(FontSize.shared.body - 13)
let key = "\(size) \(weight) \(italic)"
let key = "\(size) \(weight) \(italic) \(mono)"
return fonts.withLock { fonts in
if let f = fonts[key] {
return f
}
let f = ct(size, weight: weight, italic: italic)
let f = ct(size, weight: weight, italic: italic, mono: mono)
fonts[key] = f
return f
}
}
@MainActor
static func font(_ size: CGFloat, weight: CGFloat = 400, italic: Bool = false) -> Font {
Font(cached(size, weight, italic))
static func font(_ size: CGFloat, weight: CGFloat = 400, italic: Bool = false, mono: Bool = false) -> Font {
Font(cached(size, weight, italic, mono))
}
@MainActor
static func ns(_ size: CGFloat, weight: CGFloat = 400, italic: Bool = false) -> NSFont {
cached(size, weight, italic) as NSFont
static func ns(_ size: CGFloat, weight: CGFloat = 400, italic: Bool = false, mono: Bool = false) -> NSFont {
cached(size, weight, italic, mono) as NSFont
}
}
+1 -1
View File
@@ -240,7 +240,7 @@ struct PreBox: View {
Copyable(text: text) {
ScrollView {
Text(verbatim: text)
.font(Fonts.font(size))
.font(Fonts.font(size, mono: true))
.textSelection(.enabled)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, 8)
+6 -4
View File
@@ -172,6 +172,7 @@ struct InlineRenderer {
var color: Color?
var small = false
var tip: String?
var mono = false
}
func segments(_ items: [MDInline]) -> [MDSegment] {
@@ -192,8 +193,8 @@ struct InlineRenderer {
private func run(_ s: String, _ style: Style) -> AttributedString {
var a = AttributedString(s)
a.font = Fonts.font(style.small ? 11 : size, weight: style.bold ? 700 : weight, italic: style.italic)
a.mergeAttributes(try! AttributeContainer([.font: Fonts.ns(style.small ? 11 : size, weight: style.bold ? 700 : weight, italic: style.italic)], including: \.appKit))
a.font = Fonts.font(style.small ? 11 : size, weight: style.bold ? 700 : weight, italic: style.italic, mono: style.mono)
a.mergeAttributes(try! AttributeContainer([.font: Fonts.ns(style.small ? 11 : size, weight: style.bold ? 700 : weight, italic: style.italic, mono: style.mono)], including: \.appKit))
if let link = style.link {
a.link = link
}
@@ -224,6 +225,7 @@ struct InlineRenderer {
append(run("\n", style), &out)
case .code(let c):
var s = style
s.mono = true
if s.link == nil, let path = codeFile(c) {
s.link = path
s.color = Palette.accent
@@ -795,7 +797,7 @@ private struct BlockView: View {
Copyable(text: code) {
ScrollView(.horizontal) {
Text(verbatim: code)
.font(Fonts.font(ctx.size))
.font(Fonts.font(ctx.size, mono: true))
.foregroundStyle(Palette.text)
.textSelection(.enabled)
.fixedSize()
@@ -881,7 +883,7 @@ private struct DiffBlock: View {
StretchColumn(minWidth: width) {
ForEach(Array(lines.enumerated()), id: \.offset) { _, line in
Text(verbatim: line.isEmpty ? " " : line)
.font(Fonts.font(size))
.font(Fonts.font(size, mono: true))
.foregroundStyle(line.hasPrefix("@@") || line.hasPrefix("+++") || line.hasPrefix("---") ? Palette.muted : Palette.text)
.textSelection(.enabled)
.fixedSize()
+1 -1
View File
@@ -103,7 +103,7 @@ private struct CommandBox: View {
private var box: some View {
HStack(alignment: .firstTextBaseline, spacing: 8) {
Text(verbatim: command)
.font(Fonts.font(12))
.font(Fonts.font(12, mono: true))
.textSelection(.enabled)
.frame(maxWidth: .infinity, alignment: .leading)
Button(copied ? "Copied" : "Copy", action: copy)
+2 -2
View File
@@ -77,7 +77,7 @@ struct TerminalHost: NSViewRepresentable {
func makeNSView(context: Context) -> TerminalView {
let t = TerminalView(frame: NSRect(x: 0, y: 0, width: 800, height: 400))
t.font = Fonts.ns(13)
t.font = Fonts.ns(13, mono: true)
t.changeScrollback(5000)
t.setCursorStyle(.steadyBlock)
t.terminalDelegate = context.coordinator
@@ -90,7 +90,7 @@ struct TerminalHost: NSViewRepresentable {
}
func updateNSView(_ nsView: TerminalView, context: Context) {
let font = Fonts.ns(13)
let font = Fonts.ns(13, mono: true)
if nsView.font !== font {
nsView.font = font
}