Linux: Fix selection of fonts with multiple width variants not preferring the normal width faces
Fixes #2491
This commit is contained in:
parent
747ac85e7c
commit
e3af9f68d3
@ -31,6 +31,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
|
||||
- Fix a regression in 0.17 that broke the kitty @ launch remote command and
|
||||
also broke the --tab-title option when creating a new tab. (:iss:`2488`)
|
||||
|
||||
- Linux: Fix selection of fonts with multiple width variants not preferring
|
||||
the normal width faces (:iss:`2491`)
|
||||
|
||||
|
||||
0.17.1 [2020-03-24]
|
||||
--------------------
|
||||
|
||||
@ -323,6 +323,7 @@ FC_MONO: int = 100
|
||||
FC_DUAL: int
|
||||
FC_WEIGHT_REGULAR: int
|
||||
FC_WEIGHT_BOLD: int
|
||||
FC_WIDTH_NORMAL: int
|
||||
FC_SLANT_ROMAN: int
|
||||
FC_SLANT_ITALIC: int
|
||||
BORDERS_PROGRAM: int
|
||||
@ -402,6 +403,7 @@ class FontConfigPattern(TypedDict):
|
||||
style: str
|
||||
spacing: str
|
||||
weight: int
|
||||
width: int
|
||||
slant: int
|
||||
hint_style: int
|
||||
subpixel: int
|
||||
|
||||
@ -47,6 +47,7 @@ pattern_as_dict(FcPattern *pat) {
|
||||
S(FC_FULLNAME, full_name);
|
||||
S(FC_POSTSCRIPT_NAME, postscript_name);
|
||||
I(FC_WEIGHT, weight);
|
||||
I(FC_WIDTH, width)
|
||||
I(FC_SLANT, slant);
|
||||
I(FC_HINT_STYLE, hint_style);
|
||||
I(FC_INDEX, index);
|
||||
@ -247,5 +248,7 @@ init_fontconfig_library(PyObject *module) {
|
||||
PyModule_AddIntMacro(module, FC_DUAL);
|
||||
PyModule_AddIntMacro(module, FC_MONO);
|
||||
PyModule_AddIntMacro(module, FC_CHARCELL);
|
||||
PyModule_AddIntMacro(module, FC_WIDTH_NORMAL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ from typing import Dict, Generator, List, Optional, Tuple, cast
|
||||
|
||||
from kitty.fast_data_types import (
|
||||
FC_DUAL, FC_MONO, FC_SLANT_ITALIC, FC_SLANT_ROMAN, FC_WEIGHT_BOLD,
|
||||
FC_WEIGHT_REGULAR, fc_list, fc_match as fc_match_impl
|
||||
FC_WEIGHT_REGULAR, FC_WIDTH_NORMAL, fc_list, fc_match as fc_match_impl
|
||||
)
|
||||
from kitty.options_stub import Options
|
||||
from kitty.typing import FontConfigPattern
|
||||
@ -73,11 +73,13 @@ def find_best_match(family: str, bold: bool = False, italic: bool = False, monos
|
||||
q = family_name_to_key(family)
|
||||
font_map = all_fonts_map(monospaced)
|
||||
|
||||
def score(candidate: FontConfigPattern) -> Tuple[int, int]:
|
||||
def score(candidate: FontConfigPattern) -> Tuple[int, int, int]:
|
||||
bold_score = abs((FC_WEIGHT_BOLD if bold else FC_WEIGHT_REGULAR) - candidate.get('weight', 0))
|
||||
italic_score = abs((FC_SLANT_ITALIC if italic else FC_SLANT_ROMAN) - candidate.get('slant', 0))
|
||||
monospace_match = 0 if candidate.get('spacing') == 'MONO' else 1
|
||||
return bold_score + italic_score, monospace_match
|
||||
width_score = abs(candidate.get('width', FC_WIDTH_NORMAL) - FC_WIDTH_NORMAL)
|
||||
|
||||
return bold_score + italic_score, monospace_match, width_score
|
||||
|
||||
# First look for an exact match
|
||||
for selector in ('ps_map', 'full_map', 'family_map'):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user