refactor(font): move ownership of Metrics to Collection

This sets the stage for dynamically adjusting the sizes of fallback
fonts based on the primary font's face metrics. It also removes a lot of
unnecessary work when loading fallback fonts, since we only actually use
the metrics based on the parimary font.
This commit is contained in:
Qwerasd
2025-01-06 19:00:13 -05:00
parent 540fcc0b69
commit 298aeb7536
8 changed files with 206 additions and 207 deletions

View File

@@ -111,15 +111,10 @@ pub fn deinit(self: *SharedGrid, alloc: Allocator) void {
}
fn reloadMetrics(self: *SharedGrid) !void {
// Get our cell metrics based on a regular font ascii 'M'. Why 'M'?
// Doesn't matter, any normal ASCII will do we're just trying to make
// sure we use the regular font.
// We don't go through our caching layer because we want to minimize
// possible failures.
const collection = &self.resolver.collection;
const index = collection.getIndex('M', .regular, .{ .any = {} }).?;
const face = try collection.getFace(index);
self.metrics = face.metrics;
try collection.updateMetrics();
self.metrics = collection.metrics.?;
// Setup our sprite font.
self.resolver.sprite = .{ .metrics = self.metrics };