diff options
| author | Mitchell Hashimoto <mitchell.hashimoto@gmail.com> | 2024-04-02 14:59:54 -0700 |
|---|---|---|
| committer | Mitchell Hashimoto <mitchell.hashimoto@gmail.com> | 2024-04-05 09:29:41 -0700 |
| commit | 4eccd42f6b281e06038ac3d412586a239d27209e (patch) | |
| tree | 039b0922966aab4fd98a7ef362102329c734120b /src/font/Collection.zig | |
| parent | bd479db09f2929ea3e0cb02803ecc18b03513b91 (diff) | |
font: CodepointResolver beginnings
Diffstat (limited to 'src/font/Collection.zig')
| -rw-r--r-- | src/font/Collection.zig | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/font/Collection.zig b/src/font/Collection.zig index e3ad969bc..4d623967a 100644 --- a/src/font/Collection.zig +++ b/src/font/Collection.zig @@ -5,7 +5,7 @@ //! //! The purpose of a collection is to store a list of fonts by style //! and priority order. A collection does not handle searching for font -//! callbacks, rasterization, etc. +//! callbacks, rasterization, etc. For this, see CodepointResolver. //! //! The collection can contain both loaded and deferred faces. Deferred faces //! typically use less memory while still providing some necessary information @@ -152,6 +152,24 @@ pub fn getIndex( return null; } +/// Check if a specific font index has a specific codepoint. This does not +/// necessarily force the font to load. The presentation value "p" will +/// verify the Emoji representation matches if it is non-null. If "p" is +/// null then any presentation will be accepted. +pub fn hasCodepoint( + self: *const Collection, + index: Index, + cp: u32, + p: ?Presentation, +) 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 = {} }, + ); +} + /// Automatically create an italicized font from the regular /// font face if we don't have one already. If we already have /// an italicized font face, this does nothing. @@ -315,7 +333,11 @@ pub const Entry = union(enum) { } /// True if this face satisfies the given codepoint and presentation. - fn hasCodepoint(self: Entry, cp: u32, p_mode: PresentationMode) bool { + pub fn hasCodepoint( + self: Entry, + cp: u32, + p_mode: PresentationMode, + ) bool { return switch (self) { // Non-fallback fonts require explicit presentation matching but // otherwise don't care about presentation |
