diff options
| author | Mitchell Hashimoto <mitchell.hashimoto@gmail.com> | 2024-04-02 19:32:03 -0700 |
|---|---|---|
| committer | Mitchell Hashimoto <mitchell.hashimoto@gmail.com> | 2024-04-05 09:29:41 -0700 |
| commit | b2541d24f19f3233f8a862f10dfa20d1e16cd5c9 (patch) | |
| tree | c5bb546771494a09a3a951527c8e222acc586cbe /src/font/Collection.zig | |
| parent | 4eccd42f6b281e06038ac3d412586a239d27209e (diff) | |
font: CodepointResolver style disabling test
Diffstat (limited to 'src/font/Collection.zig')
| -rw-r--r-- | src/font/Collection.zig | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/src/font/Collection.zig b/src/font/Collection.zig index 4d623967a..f75356bc9 100644 --- a/src/font/Collection.zig +++ b/src/font/Collection.zig @@ -18,6 +18,7 @@ const Collection = @This(); const std = @import("std"); const Allocator = std.mem.Allocator; const font = @import("main.zig"); +const options = font.options; const DeferredFace = font.DeferredFace; const DesiredSize = font.face.DesiredSize; const Face = font.Face; @@ -160,14 +161,11 @@ pub fn hasCodepoint( self: *const Collection, index: Index, cp: u32, - p: ?Presentation, + p_mode: PresentationMode, ) bool { const list = self.faces.get(index.style); if (index.idx >= list.items.len) return false; - return list.items[index.idx].hasCodepoint( - cp, - if (p) |v| .{ .explicit = v } else .{ .any = {} }, - ); + return list.items[index.idx].hasCodepoint(cp, p_mode); } /// Automatically create an italicized font from the regular @@ -601,3 +599,50 @@ test setSize { try c.setSize(.{ .points = 24 }); try testing.expectEqual(@as(u32, 24), c.load_options.?.size.points); } + +test hasCodepoint { + const testing = std.testing; + const alloc = testing.allocator; + const testFont = @import("test.zig").fontRegular; + + var lib = try Library.init(); + defer lib.deinit(); + + var c = try init(alloc); + defer c.deinit(alloc); + c.load_options = .{ .library = lib }; + + const idx = try c.add(alloc, .regular, .{ .loaded = try Face.init( + lib, + testFont, + .{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } }, + ) }); + + try testing.expect(c.hasCodepoint(idx, 'A', .{ .any = {} })); + try testing.expect(!c.hasCodepoint(idx, '🥸', .{ .any = {} })); +} + +test "hasCodepoint emoji default graphical" { + if (options.backend != .fontconfig_freetype) return error.SkipZigTest; + + const testing = std.testing; + const alloc = testing.allocator; + const testEmoji = @import("test.zig").fontEmoji; + + var lib = try Library.init(); + defer lib.deinit(); + + var c = try init(alloc); + defer c.deinit(alloc); + c.load_options = .{ .library = lib }; + + const idx = try c.add(alloc, .regular, .{ .loaded = try Face.init( + lib, + testEmoji, + .{ .size = .{ .points = 12, .xdpi = 96, .ydpi = 96 } }, + ) }); + + try testing.expect(!c.hasCodepoint(idx, 'A', .{ .any = {} })); + try testing.expect(c.hasCodepoint(idx, '🥸', .{ .any = {} })); + // TODO(fontmem): test explicit/implicit +} |
