font: don't fallback styles when searching for a codepoint

see comment
This commit is contained in:
Mitchell Hashimoto
2023-07-03 15:55:01 -07:00
parent 4bf8a0d149
commit c90a52ee50
2 changed files with 12 additions and 2 deletions

View File

@ -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", .{});
}

View File

@ -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,