|
8 | 8 |
|
9 | 9 | from kitty.fast_data_types import ( |
10 | 10 | FC_DUAL, FC_MONO, FC_SLANT_ITALIC, FC_SLANT_ROMAN, FC_WEIGHT_BOLD, |
11 | | - FC_WEIGHT_REGULAR, FC_WIDTH_NORMAL, fc_list, fc_match as fc_match_impl |
| 11 | + FC_WEIGHT_REGULAR, FC_WIDTH_NORMAL, fc_list, fc_match as fc_match_impl, |
| 12 | + fc_match_postscript_name, parse_font_feature |
12 | 13 | ) |
13 | 14 | from kitty.options_stub import Options |
14 | 15 | from kitty.typing import FontConfigPattern |
| 16 | +from kitty.utils import log_error |
15 | 17 |
|
16 | | -from . import ListedFont |
| 18 | +from . import ListedFont, FontFeature |
17 | 19 |
|
18 | 20 | attr_map = {(False, False): 'font_family', |
19 | 21 | (True, False): 'bold_font', |
@@ -69,6 +71,24 @@ def fc_match(family: str, bold: bool, italic: bool, spacing: int = FC_MONO) -> F |
69 | 71 | return fc_match_impl(family, bold, italic, spacing) |
70 | 72 |
|
71 | 73 |
|
| 74 | +def find_font_features(postscript_name: str) -> Tuple[str, ...]: |
| 75 | + pat = fc_match_postscript_name(postscript_name) |
| 76 | + |
| 77 | + if 'postscript_name' not in pat or pat['postscript_name'] != postscript_name or 'fontfeatures' not in pat: |
| 78 | + return tuple() |
| 79 | + |
| 80 | + features = [] |
| 81 | + for feat in pat['fontfeatures'].split(): |
| 82 | + try: |
| 83 | + parsed = parse_font_feature(feat) |
| 84 | + except ValueError: |
| 85 | + log_error('Ignoring invalid font feature: {}'.format(feat)) |
| 86 | + else: |
| 87 | + features.append(FontFeature(feat, parsed)) |
| 88 | + |
| 89 | + return tuple(features) |
| 90 | + |
| 91 | + |
72 | 92 | def find_best_match(family: str, bold: bool = False, italic: bool = False, monospaced: bool = True) -> FontConfigPattern: |
73 | 93 | q = family_name_to_key(family) |
74 | 94 | font_map = all_fonts_map(monospaced) |
|
0 commit comments