From d112d1f8539799a1035e6204aa56c98da27d2aa5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 5 May 2026 06:15:52 +0000 Subject: [PATCH] Add builtin NERD font as fallback in cocoa_render_line_of_text Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/f8c3bf89-a05f-4d78-9e2e-cb8c6ca5a9f1 Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com> --- kitty/core_text.m | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/kitty/core_text.m b/kitty/core_text.m index d8fef7e29..b021106f2 100644 --- a/kitty/core_text.m +++ b/kitty/core_text.m @@ -960,7 +960,28 @@ cocoa_render_line_of_text(const char *text, const color_type fg, const color_typ CGContextSetRGBStrokeColor(ctx, ((fg >> 16) & 0xff) / 255.f, ((fg >> 8) & 0xff) / 255.f, (fg & 0xff) / 255.f, 1.f); NSColor *color = [NSColor colorWithCalibratedRed:((fg >> 16) & 0xff) / 255.f green:((fg >> 8) & 0xff) / 255.f blue:(fg & 0xff) / 255.f alpha:1.0]; - NSAttributedString *str = [[NSAttributedString alloc] initWithString:@(text) attributes:@{(NSString *)kCTFontAttributeName: (__bridge id)system_ui_font, NSForegroundColorAttributeName: color}]; + CTFontRef render_font = system_ui_font; + CTFontRef font_with_nerd = NULL; + if (builtin_nerd_font_descriptor) { + CFArrayRef cascade_list = CFArrayCreate(kCFAllocatorDefault, (const void *[]){builtin_nerd_font_descriptor}, 1, &kCFTypeArrayCallBacks); + if (cascade_list) { + CFDictionaryRef attrs = CFDictionaryCreate(kCFAllocatorDefault, + (const void *[]){kCTFontCascadeListAttribute}, (const void *[]){cascade_list}, + 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + CFRelease(cascade_list); + if (attrs) { + CTFontDescriptorRef nerd_desc = CTFontDescriptorCreateWithAttributes(attrs); + CFRelease(attrs); + if (nerd_desc) { + font_with_nerd = CTFontCreateCopyWithAttributes(system_ui_font, 0, NULL, nerd_desc); + CFRelease(nerd_desc); + if (font_with_nerd) render_font = font_with_nerd; + } + } + } + } + NSAttributedString *str = [[NSAttributedString alloc] initWithString:@(text) attributes:@{(NSString *)kCTFontAttributeName: (__bridge id)render_font, NSForegroundColorAttributeName: color}]; + if (font_with_nerd) CFRelease(font_with_nerd); if (!str) { CGContextRelease(ctx); return false; } CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)str); [str release];