Cache calls to fc_match since FcFontMatch is very slow

Fixes #1547
This commit is contained in:
Kovid Goyal 2019-04-21 11:07:37 +05:30
parent 934336e642
commit f8b311b289
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -7,7 +7,7 @@ from functools import lru_cache
from kitty.fast_data_types import (
FC_SLANT_ITALIC, FC_SLANT_ROMAN, FC_WEIGHT_BOLD, FC_WEIGHT_REGULAR,
fc_list, fc_match,
fc_list, fc_match as fc_match_impl,
)
attr_map = {(False, False): 'font_family',
@ -48,6 +48,11 @@ def family_name_to_key(family):
return re.sub(r'\s+', ' ', family.lower())
@lru_cache()
def fc_match(family, bold, italic):
return fc_match_impl(family, bold, italic)
def find_best_match(family, bold=False, italic=False, monospaced=True):
q = family_name_to_key(family)
font_map = all_fonts_map(monospaced)