From c90a52ee5073eef4cb9cb9d21fcf9f17bec536af Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 3 Jul 2023 15:55:01 -0700 Subject: [PATCH] font: don't fallback styles when searching for a codepoint see comment --- src/Surface.zig | 3 +++ src/font/Group.zig | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index f135043e3..3393d8d31 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -296,6 +296,9 @@ pub fn init( } } } else { + // We don't support auto-italics. If we don't have an italic font + // face let the user know so they aren't surprised (if they look + // at logs). if (group.getFace(.italic) == null) { log.warn("no italic font face available, italics will not render", .{}); } diff --git a/src/font/Group.zig b/src/font/Group.zig index bdda5f449..251827af7 100644 --- a/src/font/Group.zig +++ b/src/font/Group.zig @@ -198,8 +198,15 @@ pub fn indexForCodepoint( // If we can find the exact value, then return that. if (self.indexForCodepointExact(cp, style, p)) |value| return value; - // Try looking for another font that will satisfy this request. - if (font.Discover != void) { + // If we're not a regular font style, try looking for a regular font + // that will satisfy this request. Blindly looking for unmatched styled + // fonts to satisfy one codepoint results in some ugly rendering. + if (style != .regular) { + if (self.indexForCodepoint(cp, .regular, p)) |value| return value; + } + + // If we are regular, try looking for a fallback using discovery. + if (style == .regular and font.Discover != void) { if (self.discover) |*disco| discover: { var disco_it = disco.discover(.{ .codepoint = cp,