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!
pull/9649/head
Qwerasd 2025-11-19 22:02:17 -07:00
parent 410d79b151
commit a347406137
1 changed files with 12 additions and 7 deletions

View File

@ -845,15 +845,20 @@ pub const CoreText = struct {
// limitation because we may have used that to filter but we // limitation because we may have used that to filter but we
// don't want it anymore because it'll restrict the characters // don't want it anymore because it'll restrict the characters
// available. // available.
//const desc = self.list.getValueAtIndex(macos.text.FontDescriptor, self.i);
const desc = desc: { const desc = desc: {
const original = self.list[self.i]; // We create a copy, overwriting the character set attribute.
const attrs = try macos.foundation.MutableDictionary.create(0);
// For some reason simply copying the attributes and recreating
// the descriptor removes the charset restriction. This is tested.
const attrs = original.copyAttributes();
defer attrs.release(); 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(); defer desc.release();