From 61dd2011f5688afae16bcac8d4846ce073552f1a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 7 Jan 2020 09:30:41 +0530 Subject: [PATCH] Dont rely on fontconfig to get postscript names --- kitty/config_data.py | 18 ++++++++++-------- kitty/fonts/core_text.py | 2 +- kitty/fonts/fontconfig.py | 2 +- kitty/fonts/list.py | 3 +++ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/kitty/config_data.py b/kitty/config_data.py index 76c79cd76..45ef161a8 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -291,15 +291,17 @@ Note that this code is indexed by PostScript name, and not the font family. This allows you to define very precise feature settings; e.g. you can disable a feature in the italic font but not in the regular font. -To get the PostScript name for a font, ask Fontconfig for it, using the family -name:: +To get the PostScript name for a font, use :code:`kitty + list-fonts --psnames`:: - $ fc-match "Fira Code" postscriptname - :postscriptname=FiraCode-Regular - $ fc-match "Fira Code Retina" postscriptname - :postscriptname=FiraCode-Retina - $ fc-match "TT2020Base:style=italic" postscriptname - :postscriptname=TT2020Base-Italic + $ kitty + list-fonts --psnames | grep Fira + Fira Code + Fira Code Bold (FiraCode-Bold) + Fira Code Light (FiraCode-Light) + Fira Code Medium (FiraCode-Medium) + Fira Code Regular (FiraCode-Regular) + Fira Code Retina (FiraCode-Retina) + +The part in brackets is the PostScript name. Enable alternate zero and oldstyle numerals:: diff --git a/kitty/fonts/core_text.py b/kitty/fonts/core_text.py index 5378356c8..7339c06c8 100644 --- a/kitty/fonts/core_text.py +++ b/kitty/fonts/core_text.py @@ -38,7 +38,7 @@ def list_fonts(): if f: fn = (f + ' ' + (fd['style'] or '')).strip() is_mono = bool(fd['monospace']) - yield {'family': f, 'full_name': fn, 'is_monospace': is_mono} + yield {'family': f, 'full_name': fn, 'postscript_name': fd['postscript_name'] or '', 'is_monospace': is_mono} def find_best_match(family, bold=False, italic=False): diff --git a/kitty/fonts/fontconfig.py b/kitty/fonts/fontconfig.py index c49fb990b..8a004d33b 100644 --- a/kitty/fonts/fontconfig.py +++ b/kitty/fonts/fontconfig.py @@ -45,7 +45,7 @@ def list_fonts(): if f: fn = fd.get('full_name') or (f + ' ' + fd.get('style', '')).strip() is_mono = fd.get('spacing') in ('MONO', 'DUAL') - yield {'family': f, 'full_name': fn, 'is_monospace': is_mono} + yield {'family': f, 'full_name': fn, 'postscript_name': fd.get('postscript_name', ''), 'is_monospace': is_mono} def family_name_to_key(family): diff --git a/kitty/fonts/list.py b/kitty/fonts/list.py index b34298b59..ef6947812 100644 --- a/kitty/fonts/list.py +++ b/kitty/fonts/list.py @@ -20,6 +20,7 @@ def create_family_groups(monospaced=True): def main(argv): + psnames = '--psnames' in argv isatty = sys.stdout.isatty() groups = create_family_groups() for k in sorted(groups, key=lambda x: x.lower()): @@ -31,5 +32,7 @@ def main(argv): p = f['full_name'] if isatty: p = '\033[3m' + p + '\033[m' + if psnames: + p += ' ({})'.format(f['postscript_name']) print(' ', p) print()