DVUI

findSource

Parameters

#
self:*Cache
*Cache
font:Font
Font

Source

Implementation

#
pub fn findSource(self: *Cache, font: Font) struct { ?Source, ?Source } {
        var second_best: ?usize = null;
        for (self.database.items, 0..) |*source, i| {
            if (std.mem.eql(u8, font.familyName(), source.familyName())) {
                if (font.weight == source.weight and font.style == source.style) {
                    return .{ source.*, null }; // exact match
                }

                if (font.weight == source.weight) {
                    // second best is same family name and same weight
                    second_best = i;
                } else if (second_best == null) {
                    // at least the family name is the same
                    second_best = i;
                }
            }
        }

        if (second_best) |sb| {
            return .{ null, self.database.items[sb] };
        }

        return .{ null, null };
    }