diff --git a/kitty/core_text.m b/kitty/core_text.m index 29036ea2f..229e8dc54 100644 --- a/kitty/core_text.m +++ b/kitty/core_text.m @@ -92,10 +92,10 @@ font_descriptor_to_python(CTFontDescriptorRef descriptor) { NSString *style = (NSString *) CTFontDescriptorCopyAttribute(descriptor, kCTFontStyleNameAttribute); NSDictionary *traits = (NSDictionary *) CTFontDescriptorCopyAttribute(descriptor, kCTFontTraitsAttribute); unsigned int straits = [traits[(id)kCTFontSymbolicTrait] unsignedIntValue]; - NSNumber *weightVal = traits[(id)kCTFontWeightTrait]; - NSNumber *widthVal = traits[(id)kCTFontWidthTrait]; + float *weightVal = [traits[(id)kCTFontWeightTrait] floatValue]; + float widthVal = [traits[(id)kCTFontWidthTrait] floatValue]; - PyObject *ans = Py_BuildValue("{ssssssss sOsOsO sfsfsI}", + PyObject *ans = Py_BuildValue("{ssssssss sOsOsOsOsOsO sfsfsI}", "path", [[url path] UTF8String], "postscript_name", [psName UTF8String], "family", [family UTF8String], @@ -104,9 +104,12 @@ font_descriptor_to_python(CTFontDescriptorRef descriptor) { "bold", (straits & kCTFontBoldTrait) != 0 ? Py_True : Py_False, "italic", (straits & kCTFontItalicTrait) != 0 ? Py_True : Py_False, "monospace", (straits & kCTFontMonoSpaceTrait) != 0 ? Py_True : Py_False, + "expanded", (straits & kCTFontExpandedTrait) != 0 ? Py_True : Py_False, + "condensed", (straits & kCTFontCondensedTrait) != 0 ? Py_True : Py_False, + "color_glyphs", (straits & kCTFontColorGlyphsTrait) != 0 ? Py_True : Py_False, - "weight", [weightVal floatValue], - "width", [widthVal floatValue], + "weight", weightVal, + "width", widthVal, "traits", straits ); [url release]; diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 4749e0c50..9333a8eaa 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -438,6 +438,9 @@ class CoreTextFont(TypedDict): style: str bold: bool italic: bool + expanded: bool + condensed: bool + color_glyphs: bool monospace: bool weight: float width: float diff --git a/kitty/fonts/core_text.py b/kitty/fonts/core_text.py index 20567a3a1..5061b0fb2 100644 --- a/kitty/fonts/core_text.py +++ b/kitty/fonts/core_text.py @@ -54,12 +54,13 @@ def find_best_match(family: str, bold: bool = False, italic: bool = False) -> Co q = re.sub(r'\s+', ' ', family.lower()) font_map = all_fonts_map() - def score(candidate: CoreTextFont) -> Tuple[int, int]: + def score(candidate: CoreTextFont) -> Tuple[int, int, int]: style_match = 1 if candidate['bold'] == bold and candidate[ 'italic' ] == italic else 0 monospace_match = 1 if candidate['monospace'] else 0 - return style_match, monospace_match + is_regular_width = not candidate['expanded'] and not candidate['condensed'] + return style_match, monospace_match, 1 if is_regular_width else 0 # First look for an exact match for selector in ('ps_map', 'full_map'):