font: SharedGrid hasCodepoint

This commit is contained in:
Mitchell Hashimoto
2024-04-05 19:07:45 -07:00
parent c99b27d364
commit 90ea733cbd

View File

@ -176,6 +176,22 @@ pub fn getIndex(
return value; return value;
} }
/// Returns true if the given font index has the codepoint and presentation.
pub fn hasCodepoint(
self: *SharedGrid,
idx: Collection.Index,
cp: u32,
p: ?Presentation,
) bool {
self.lock.lockShared();
defer self.lock.unlockShared();
return self.resolver.collection.hasCodepoint(
idx,
cp,
if (p) |v| .{ .explicit = v } else .{ .any = {} },
);
}
const CodepointKey = struct { const CodepointKey = struct {
style: Style, style: Style,
codepoint: u32, codepoint: u32,
@ -228,6 +244,7 @@ test getIndex {
const idx = (try grid.getIndex(alloc, @intCast(i), .regular, null)).?; const idx = (try grid.getIndex(alloc, @intCast(i), .regular, null)).?;
try testing.expectEqual(Style.regular, idx.style); try testing.expectEqual(Style.regular, idx.style);
try testing.expectEqual(@as(Collection.Index.IndexInt, 0), idx.idx); try testing.expectEqual(@as(Collection.Index.IndexInt, 0), idx.idx);
try testing.expect(grid.hasCodepoint(idx, @intCast(i), null));
} }
// Do it again without a resolver set to ensure we only hit the cache // Do it again without a resolver set to ensure we only hit the cache