mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
fontconfig: Lift axes spec to named style
This commit is contained in:
@@ -180,6 +180,17 @@ def set_named_style(name: str, font: FontConfigPattern, vd: VariableData) -> boo
|
||||
return False
|
||||
|
||||
|
||||
def lift_axes_to_named_style_if_possible(font: FontConfigPattern, vd: VariableData) -> bool:
|
||||
axes = font.get('axes', tuple(ax['default'] for ax in vd['axes']))
|
||||
q = {vd['axes'][i]['tag']: val for i, val in enumerate(axes)}
|
||||
for i, ns in enumerate(vd['named_styles']):
|
||||
if ns['axis_values'] == q:
|
||||
font.pop('axes', None)
|
||||
font['named_style'] = i
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def set_axis_values(tag_map: Dict[str, float], font: FontConfigPattern, vd: VariableData) -> bool:
|
||||
axes = list(font.get('axes', ())) or [ax['default'] for ax in vd['axes']]
|
||||
changed = False
|
||||
@@ -190,4 +201,5 @@ def set_axis_values(tag_map: Dict[str, float], font: FontConfigPattern, vd: Vari
|
||||
axes[i] = val
|
||||
if changed:
|
||||
font['axes'] = tuple(axes)
|
||||
lift_axes_to_named_style_if_possible(font, vd)
|
||||
return changed
|
||||
|
||||
@@ -26,18 +26,26 @@ class Selection(BaseTest):
|
||||
fonts_map = all_fonts_map(monospaced=True)
|
||||
family_map = fonts_map['family_map']
|
||||
variable_map = fonts_map['variable_map']
|
||||
def a(family: str, *expected: str) -> None:
|
||||
has_source_code_pro = family_name_to_key('Source Code Pro') in family_map
|
||||
has_source_code_vf = family_name_to_key('sourcecodeVf') in variable_map
|
||||
del fonts_map, family_map, variable_map
|
||||
|
||||
def s(family: str, *expected: str) -> None:
|
||||
opts.font_family = parse_font_spec(family)
|
||||
ff = get_font_files(opts)
|
||||
actual = tuple(face_from_descriptor(ff[x]).postscript_name() for x in ('medium', 'bold', 'italic', 'bi')) # type: ignore
|
||||
self.assertEqual(expected, actual)
|
||||
def t(family: str, *expected: str) -> None:
|
||||
a(family, *expected)
|
||||
a(f'family="{family}"', *expected)
|
||||
if family_name_to_key('Source Code Pro') in family_map:
|
||||
t('Source Code Pro', 'SourceCodePro-Regular', 'SourceCodePro-Bold', 'SourceCodePro-It', 'SourceCodePro-BoldIt')
|
||||
if family_name_to_key('sourcecodeVf') in variable_map:
|
||||
a('sourcecodeVf', 'SourceCodeVF-Regular', 'SourceCodeVF-Bold', 'SourceCodeVF-Italic', 'SourceCodeVF-BoldItalic')
|
||||
with self.subTest(spec=family):
|
||||
self.ae(expected, actual)
|
||||
|
||||
def both(family: str, *expected: str) -> None:
|
||||
for family in (family, f'family="{family}"'):
|
||||
s(family, *expected)
|
||||
|
||||
if has_source_code_pro:
|
||||
both('Source Code Pro', 'SourceCodePro-Regular', 'SourceCodePro-Bold', 'SourceCodePro-It', 'SourceCodePro-BoldIt')
|
||||
if has_source_code_vf:
|
||||
s('sourcecodeVf', 'SourceCodeVF-Regular', 'SourceCodeVF-Bold', 'SourceCodeVF-Italic', 'SourceCodeVF-BoldItalic')
|
||||
s('family=sourcecodeVf', 'SourceCodeVF-Regular', 'SourceCodeVF-Semibold', 'SourceCodeVF-Italic', 'SourceCodeVF-SemiboldItalic')
|
||||
|
||||
|
||||
class Rendering(BaseTest):
|
||||
|
||||
Reference in New Issue
Block a user