Skip to content

Commit 2363488

Browse files
fonts: add tests for fallback font lookup w/ system ui font
...we're probably not supposed to be accessing system fonts this way. when running the tests w/o my first fix (clearing restrictions for system font): ``` [I] ➜ ghostty git:(upstream-3) ✗ zig build test -Dtest-filter="discoverFallback" test └─ run ghostty-test 59/60 passed, 1 failed error: 'font.discovery.test.coretext discoverFallback CJK codepoint' failed: 2025-09-10 13:53:31.792 ghostty-test[51978:12386835] CoreText note: Client requested name ".PingFangUITextSC-Regular", it will get TimesNewRomanPSMT rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:]. 2025-09-10 13:53:31.792 ghostty-test[51978:12386835] CoreText note: Set a breakpoint on CTFontLogSystemFontNameRequest to debug. /opt/homebrew/Cellar/zig/0.14.1/lib/zig/std/testing.zig:580:14: 0x10575e86f in expect (ghostty-test) if (!ok) return error.TestUnexpectedResult; ^ /Users/cheru/Code/ghostty/src/font/discovery.zig:1133:5: 0x10577445f in test.coretext discoverFallback CJK codepoint (ghostty-test) try testing.expect(face.hasCodepoint(0x4E2D, null)); ^ error: while executing test 'os.TempDir.test_0', the following test command failed: /Users/cheru/Code/ghostty/.zig-cache/o/d8ac3a9ccf171ecb22ca38e4e30bc420/ghostty-test --seed=0x9fe58469 --cache-dir=/Users/cheru/Code/ghostty/.zig-cache --listen=- Build Summary: 49/51 steps succeeded; 1 failed; 59/60 tests passed; 1 failed test transitive failure └─ run ghostty-test 59/60 passed, 1 failed error: the following build command failed with exit code 1: /Users/cheru/Code/ghostty/.zig-cache/o/526a4ea34f8d95eb90ea2f3856ac80e8/build /opt/homebrew/Cellar/zig/0.14.1/bin/zig /opt/homebrew/Cellar/zig/0.14.1/lib/zig /Users/cheru/Code/ghostty /Users/cheru/Code/ghostty/.zig-cache /Users/cheru/.cache/zig --seed 0x9fe58469 -Z70fd58e5d3dc4a11 test -Dtest-filter=discoverFallback ```
1 parent 93d020e commit 2363488

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

src/font/discovery.zig

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const opentype = @import("opentype.zig");
88
const options = @import("main.zig").options;
99
const Collection = @import("main.zig").Collection;
1010
const DeferredFace = @import("main.zig").DeferredFace;
11+
const Face = @import("main.zig").Face;
12+
const Library = @import("main.zig").Library;
1113
const Variation = @import("main.zig").face.Variation;
1214

1315
const log = std.log.scoped(.discovery);
@@ -1053,3 +1055,77 @@ test "coretext sorting" {
10531055
try testing.expectEqualStrings("SF Pro Bold Italic", name);
10541056
}
10551057
}
1058+
1059+
test "coretext discoverFallback latin codepoint" {
1060+
if (options.backend != .coretext and options.backend != .coretext_freetype)
1061+
return error.SkipZigTest;
1062+
1063+
const testing = std.testing;
1064+
const alloc = testing.allocator;
1065+
1066+
var ct = CoreText.init();
1067+
defer ct.deinit();
1068+
1069+
var collection = Collection.init();
1070+
collection.load_options = .{
1071+
.library = try Library.init(alloc),
1072+
};
1073+
defer collection.deinit(alloc);
1074+
1075+
var disco_it = try ct.discover(alloc, .{ .family = ".AppleSystemUIFontMonospaced", .size = 12 });
1076+
defer disco_it.deinit();
1077+
1078+
const deferred_face = (try disco_it.next()).?;
1079+
_ = try collection.addDeferred(alloc, deferred_face, .{
1080+
.style = .regular,
1081+
.fallback = false,
1082+
.size_adjustment = .none,
1083+
});
1084+
1085+
// Test Latin codepoint (A)
1086+
var it = try ct.discoverFallback(alloc, &collection, .{
1087+
.codepoint = 'A',
1088+
.size = 12,
1089+
});
1090+
defer it.deinit();
1091+
1092+
const face = (try it.next()).?;
1093+
try testing.expect(face.hasCodepoint('A', null));
1094+
}
1095+
1096+
test "coretext discoverFallback CJK codepoint" {
1097+
if (options.backend != .coretext and options.backend != .coretext_freetype)
1098+
return error.SkipZigTest;
1099+
1100+
const testing = std.testing;
1101+
const alloc = testing.allocator;
1102+
1103+
var ct = CoreText.init();
1104+
defer ct.deinit();
1105+
1106+
var collection = Collection.init();
1107+
collection.load_options = .{
1108+
.library = try Library.init(alloc),
1109+
};
1110+
defer collection.deinit(alloc);
1111+
1112+
var disco_it = try ct.discover(alloc, .{ .family = ".AppleSystemUIFontMonospaced", .size = 12 });
1113+
defer disco_it.deinit();
1114+
1115+
const deferred_face = (try disco_it.next()).?;
1116+
_ = try collection.addDeferred(alloc, deferred_face, .{
1117+
.style = .regular,
1118+
.fallback = false,
1119+
.size_adjustment = .none,
1120+
});
1121+
1122+
// Test CJK codepoint (中)
1123+
var it = try ct.discoverFallback(alloc, &collection, .{
1124+
.codepoint = 0x4E2D,
1125+
.size = 12,
1126+
});
1127+
defer it.deinit();
1128+
1129+
const face = (try it.next()).?;
1130+
try testing.expect(face.hasCodepoint(0x4E2D, null));
1131+
}

0 commit comments

Comments
 (0)