From c29f4cace67b385383897f9dcedde48ebbc35cdf Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 19 Aug 2022 22:22:13 -0700 Subject: [PATCH] remove the font style fallback for the fallback set --- src/font/FallbackSet.zig | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/font/FallbackSet.zig b/src/font/FallbackSet.zig index c2cc06045..fabff2adc 100644 --- a/src/font/FallbackSet.zig +++ b/src/font/FallbackSet.zig @@ -73,31 +73,31 @@ pub fn getOrAddGlyph( // Go through each familiy and look for a matching glyph var fam_i: usize = 0; const glyph = glyph: { - var style_current = style; - while (true) { - for (self.families.items) |*family, i| { - fam_i = i; + for (self.families.items) |*family, i| { + fam_i = i; - // If this family already has it loaded, return it. - if (family.getGlyph(v, style_current)) |glyph| break :glyph glyph; + // If this family already has it loaded, return it. + if (family.getGlyph(v, style)) |glyph| break :glyph glyph; - // Try to load it. - if (family.addGlyph(alloc, v, style_current)) |glyph| - break :glyph glyph - else |err| switch (err) { - error.GlyphNotFound => {}, - else => return err, - } + // Try to load it. + if (family.addGlyph(alloc, v, style)) |glyph| + break :glyph glyph + else |err| switch (err) { + // TODO: this probably doesn't belong here and should + // be higher level... but how? + error.AtlasFull => { + try family.atlas.grow(alloc, family.atlas.size * 2); + break :glyph try family.addGlyph(alloc, v, style); + }, + + error.GlyphNotFound => {}, + else => return err, } - - // We never found any glyph! For our first fallback, we'll simply - // try to the non-styled variant. - if (style_current == .regular) break; - style_current = .regular; } // If we are regular, we use a fallback character log.warn("glyph not found, using fallback. codepoint={x}", .{utf32}); + fam_i = 0; break :glyph try self.families.items[0].addGlyph(alloc, ' ', style); };