From 6dcf567554eaf99eae0166838ff3e5d1f2b9a513 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 8 May 2024 18:33:14 -0700 Subject: [PATCH] font: fix coretext test issues with harfbuzz shaper --- src/font/CodepointResolver.zig | 39 ++++++++++++++++++---------------- src/font/shaper/harfbuzz.zig | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/font/CodepointResolver.zig b/src/font/CodepointResolver.zig index a0073f9ad..543378c4f 100644 --- a/src/font/CodepointResolver.zig +++ b/src/font/CodepointResolver.zig @@ -380,32 +380,35 @@ test getIndex { var c = try Collection.init(alloc); c.load_options = .{ .library = lib }; - _ = try c.add(alloc, .regular, .{ .loaded = try Face.init( - lib, - testFont, - .{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } }, - ) }); - if (font.options.backend != .coretext) { - // Coretext doesn't support Noto's format + { + errdefer c.deinit(alloc); + _ = try c.add(alloc, .regular, .{ .loaded = try Face.init( + lib, + testFont, + .{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } }, + ) }); + if (comptime !font.options.backend.hasCoretext()) { + // Coretext doesn't support Noto's format + _ = try c.add( + alloc, + .regular, + .{ .loaded = try Face.init( + lib, + testEmoji, + .{ .size = .{ .points = 12 } }, + ) }, + ); + } _ = try c.add( alloc, .regular, .{ .loaded = try Face.init( lib, - testEmoji, + testEmojiText, .{ .size = .{ .points = 12 } }, ) }, ); } - _ = try c.add( - alloc, - .regular, - .{ .loaded = try Face.init( - lib, - testEmojiText, - .{ .size = .{ .points = 12 } }, - ) }, - ); var r: CodepointResolver = .{ .collection = c }; defer r.deinit(alloc); @@ -429,7 +432,7 @@ test getIndex { { const idx = r.getIndex(alloc, 0x270C, .regular, .text).?; try testing.expectEqual(Style.regular, idx.style); - const text_idx = if (font.options.backend == .coretext) 1 else 2; + const text_idx = if (comptime font.options.backend.hasCoretext()) 1 else 2; try testing.expectEqual(@as(Collection.Index.IndexInt, text_idx), idx.idx); } { diff --git a/src/font/shaper/harfbuzz.zig b/src/font/shaper/harfbuzz.zig index c34a57627..11adecb76 100644 --- a/src/font/shaper/harfbuzz.zig +++ b/src/font/shaper/harfbuzz.zig @@ -1213,7 +1213,7 @@ fn testShaperWithFont(alloc: Allocator, font_req: TestFont) !TestShaper { .{ .size = .{ .points = 12 } }, ) }); - if (font.options.backend != .coretext) { + if (comptime !font.options.backend.hasCoretext()) { // Coretext doesn't support Noto's format _ = try c.add(alloc, .regular, .{ .loaded = try Face.init( lib,