only the app should own the font discovery instance

This commit is contained in:
Mitchell Hashimoto
2023-08-13 11:51:24 -07:00
parent bddf24f378
commit 0af6edc25b
2 changed files with 5 additions and 9 deletions

View File

@ -161,15 +161,15 @@ pub fn focusedSurface(self: *const App) ?*Surface {
/// Initialize once and return the font discovery mechanism. This remains /// Initialize once and return the font discovery mechanism. This remains
/// initialized throughout the lifetime of the application because some /// initialized throughout the lifetime of the application because some
/// font discovery mechanisms (i.e. fontconfig) are unsafe to reinit. /// font discovery mechanisms (i.e. fontconfig) are unsafe to reinit.
pub fn fontDiscover(self: *App) !?font.Discover { pub fn fontDiscover(self: *App) !?*font.Discover {
// If we're built without a font discovery mechanism, return null // If we're built without a font discovery mechanism, return null
if (comptime font.Discover == void) return null; if (comptime font.Discover == void) return null;
// If we initialized, use it // If we initialized, use it
if (self.font_discover) |v| return v; if (self.font_discover) |*v| return v;
self.font_discover = font.Discover.init(); self.font_discover = font.Discover.init();
return self.font_discover.?; return &self.font_discover.?;
} }
/// Drain the mailbox. /// Drain the mailbox.

View File

@ -47,7 +47,7 @@ faces: StyleArray,
/// If discovery is available, we'll look up fonts where we can't find /// If discovery is available, we'll look up fonts where we can't find
/// the codepoint. This can be set after initialization. /// the codepoint. This can be set after initialization.
discover: ?font.Discover = null, discover: ?*font.Discover = null,
/// Set this to a non-null value to enable sprite glyph drawing. If this /// Set this to a non-null value to enable sprite glyph drawing. If this
/// isn't enabled we'll just fall through to trying to use regular fonts /// isn't enabled we'll just fall through to trying to use regular fonts
@ -78,10 +78,6 @@ pub fn deinit(self: *Group) void {
for (entry.value.items) |*item| item.deinit(); for (entry.value.items) |*item| item.deinit();
entry.value.deinit(self.alloc); entry.value.deinit(self.alloc);
} }
if (font.Discover != void) {
if (self.discover) |*discover| discover.deinit();
}
} }
/// Add a face to the list for the given style. This face will be added as /// Add a face to the list for the given style. This face will be added as
@ -207,7 +203,7 @@ pub fn indexForCodepoint(
// If we are regular, try looking for a fallback using discovery. // If we are regular, try looking for a fallback using discovery.
if (style == .regular and font.Discover != void) { if (style == .regular and font.Discover != void) {
if (self.discover) |*disco| discover: { if (self.discover) |disco| discover: {
var disco_it = disco.discover(.{ var disco_it = disco.discover(.{
.codepoint = cp, .codepoint = cp,
.size = self.size.points, .size = self.size.points,