From bf7c26d357ca792ec9f1cb8596f1e7bd138b2f9d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 24 Mar 2020 19:27:14 +0530 Subject: [PATCH] CoreText: Prefer less bold variants over heavier variants when auto-selecting the bold face --- kitty/fonts/core_text.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kitty/fonts/core_text.py b/kitty/fonts/core_text.py index 5061b0fb2..08289c3fb 100644 --- a/kitty/fonts/core_text.py +++ b/kitty/fonts/core_text.py @@ -54,13 +54,16 @@ def find_best_match(family: str, bold: bool = False, italic: bool = False) -> Co q = re.sub(r'\s+', ' ', family.lower()) font_map = all_fonts_map() - def score(candidate: CoreTextFont) -> Tuple[int, int, int]: + def score(candidate: CoreTextFont) -> Tuple[int, int, int, float]: style_match = 1 if candidate['bold'] == bold and candidate[ 'italic' ] == italic else 0 monospace_match = 1 if candidate['monospace'] else 0 is_regular_width = not candidate['expanded'] and not candidate['condensed'] - return style_match, monospace_match, 1 if is_regular_width else 0 + # prefer demi-bold to bold to heavy, less bold means less chance of + # overflow + weight_distance_from_medium = abs(candidate['weight']) + return style_match, monospace_match, 1 if is_regular_width else 0, 1 - weight_distance_from_medium # First look for an exact match for selector in ('ps_map', 'full_map'):