From a3474061374fbe3284d9bd3dc05892176b516d56 Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Wed, 19 Nov 2025 22:02:17 -0700 Subject: [PATCH] fix(font/CoreText): make system fallback fonts work again The code that re-creates the font descriptor from scratch using the same attributes also rubs off the magic dust that makes CoreText not throw a fit at us for using a "hidden" system font (name prefixed with a dot) by name when we use the descriptor. This means that a small subset of chars that only have glyphs in these fallback system fonts like ".CJK Symbols Fallback HK Regular" and ".DecoType Nastaleeq Urdu UI" would not be able to be rendered, since when we requested the font with the non-magical descriptor CoreText would complain in the console and give us Times New Roman instead. Using `CTFontDescriptorCreateCopyWithAttributes` to clear the charset attribute instead of recreating from scratch makes the copy come out magical, and CoreText lets us instantiate the font from it, yippee! --- src/font/discovery.zig | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/font/discovery.zig b/src/font/discovery.zig index 2f8412790..45fc89ea9 100644 --- a/src/font/discovery.zig +++ b/src/font/discovery.zig @@ -845,15 +845,20 @@ pub const CoreText = struct { // limitation because we may have used that to filter but we // don't want it anymore because it'll restrict the characters // available. - //const desc = self.list.getValueAtIndex(macos.text.FontDescriptor, self.i); const desc = desc: { - const original = self.list[self.i]; - - // For some reason simply copying the attributes and recreating - // the descriptor removes the charset restriction. This is tested. - const attrs = original.copyAttributes(); + // We create a copy, overwriting the character set attribute. + const attrs = try macos.foundation.MutableDictionary.create(0); defer attrs.release(); - break :desc try macos.text.FontDescriptor.createWithAttributes(@ptrCast(attrs)); + + attrs.setValue( + macos.text.FontAttribute.character_set.key(), + macos.c.kCFNull, + ); + + break :desc try macos.text.FontDescriptor.createCopyWithAttributes( + self.list[self.i], + @ptrCast(attrs), + ); }; defer desc.release();