From 0af6edc25b04be4afacf12ab549d55b77644ef39 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 13 Aug 2023 11:51:24 -0700 Subject: [PATCH] only the app should own the font discovery instance --- src/App.zig | 6 +++--- src/font/Group.zig | 8 ++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/App.zig b/src/App.zig index 32f890699..c7721eb54 100644 --- a/src/App.zig +++ b/src/App.zig @@ -161,15 +161,15 @@ pub fn focusedSurface(self: *const App) ?*Surface { /// Initialize once and return the font discovery mechanism. This remains /// initialized throughout the lifetime of the application because some /// 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 (comptime font.Discover == void) return null; // 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(); - return self.font_discover.?; + return &self.font_discover.?; } /// Drain the mailbox. diff --git a/src/font/Group.zig b/src/font/Group.zig index 77d813a81..1296db8fc 100644 --- a/src/font/Group.zig +++ b/src/font/Group.zig @@ -47,7 +47,7 @@ faces: StyleArray, /// If discovery is available, we'll look up fonts where we can't find /// 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 /// 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(); 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 @@ -207,7 +203,7 @@ pub fn indexForCodepoint( // If we are regular, try looking for a fallback using discovery. if (style == .regular and font.Discover != void) { - if (self.discover) |*disco| discover: { + if (self.discover) |disco| discover: { var disco_it = disco.discover(.{ .codepoint = cp, .size = self.size.points,