From f7f8b4cdf691dddddf7c9ba90872f2601eca4760 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 22 Apr 2024 22:11:58 +0530 Subject: [PATCH] Use the full name from CoreText when available --- kitty/core_text.m | 6 ++++-- kitty/fast_data_types.pyi | 1 + kitty/fonts/core_text.py | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/kitty/core_text.m b/kitty/core_text.m index fa1ba9c57..9383a14be 100644 --- a/kitty/core_text.m +++ b/kitty/core_text.m @@ -116,6 +116,7 @@ font_descriptor_to_python(CTFontDescriptorRef descriptor) { RAII_PyObject(ps_name, convert_cfstring(CTFontDescriptorCopyAttribute(descriptor, kCTFontNameAttribute), true)); RAII_PyObject(family, convert_cfstring(CTFontDescriptorCopyAttribute(descriptor, kCTFontFamilyNameAttribute), true)); RAII_PyObject(style, convert_cfstring(CTFontDescriptorCopyAttribute(descriptor, kCTFontStyleNameAttribute), true)); + RAII_PyObject(display_name, convert_cfstring(CTFontDescriptorCopyAttribute(descriptor, kCTFontDisplayNameAttribute), true)); RAII_CoreFoundation(CFDictionaryRef, traits, CTFontDescriptorCopyAttribute(descriptor, kCTFontTraitsAttribute)); unsigned long symbolic_traits = 0; float weight = 0, width = 0, slant = 0; #define get_number(d, key, output, type_) { \ @@ -128,10 +129,10 @@ font_descriptor_to_python(CTFontDescriptorRef descriptor) { RAII_CoreFoundation(CFDictionaryRef, variation, CTFontDescriptorCopyAttribute(descriptor, kCTFontVariationAttribute)); #undef get_number - PyObject *ans = Py_BuildValue("{ss sOsOsOsO sOsOsOsOsOsOsO sfsfsfsk}", + PyObject *ans = Py_BuildValue("{ss sOsOsOsOsO sOsOsOsOsOsOsO sfsfsfsk}", "descriptor_type", "core_text", - "path", path, "postscript_name", ps_name, "family", family, "style", style, + "path", path, "postscript_name", ps_name, "family", family, "style", style, "display_name", display_name, "bold", (symbolic_traits & kCTFontBoldTrait) != 0 ? Py_True : Py_False, "italic", (symbolic_traits & kCTFontItalicTrait) != 0 ? Py_True : Py_False, @@ -814,6 +815,7 @@ static PyObject* get_variable_data(CTFace *self) { uint8_t tag_buf[5] = {0}; RAII_CoreFoundation(CFArrayRef, cfaxes, CTFontCopyVariationAxes(self->ct_font)); + if (!cfaxes) return Py_BuildValue("{sN sN}", "axes", PyTuple_New(0), "named_styles", PyDict_New()); //, "named_styles", named_styles); RAII_PyObject(axes, PyTuple_New(CFArrayGetCount(cfaxes))); for (CFIndex i = 0; i < CFArrayGetCount(cfaxes); i++) { CFDictionaryRef a = (CFDictionaryRef)CFArrayGetValueAtIndex(cfaxes, i); diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 62e9997c4..39a8caf80 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -426,6 +426,7 @@ class CoreTextFont(TypedDict): descriptor_type: Literal['core_text'] path: str postscript_name: str + display_name: str family: str style: str bold: bool diff --git a/kitty/fonts/core_text.py b/kitty/fonts/core_text.py index 4ba5ebfc5..ce164babb 100644 --- a/kitty/fonts/core_text.py +++ b/kitty/fonts/core_text.py @@ -45,9 +45,10 @@ def list_fonts() -> Generator[ListedFont, None, None]: for fd in coretext_all_fonts(): f = fd['family'] if f: - fn = f'{f} {fd.get("style", "")}'.strip() - is_mono = bool(fd['monospace']) - yield {'family': f, 'full_name': fn, 'postscript_name': fd['postscript_name'] or '', 'is_monospace': is_mono, + fn = fd['display_name'] + if not fn: + fn = f'{f} {fd["style"]}'.strip() + yield {'family': f, 'full_name': fn, 'postscript_name': fd['postscript_name'] or '', 'is_monospace': fd['monospace'], 'is_variable': fd['variable'], 'descriptor': fd}