mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-26 18:22:09 +02:00
macOS: Fix text rendered with fallback fonts not respecting bold/italic styling
This commit is contained in:
@@ -54,6 +54,8 @@ Detailed list of changes
|
|||||||
|
|
||||||
- Splits layout: Allow resizing until one of the halves in a split is minimally sized (:iss:`7220`)
|
- Splits layout: Allow resizing until one of the halves in a split is minimally sized (:iss:`7220`)
|
||||||
|
|
||||||
|
- macOS: Fix text rendered with fallback fonts not respecting bold/italic styling (:disc:`7241`)
|
||||||
|
|
||||||
0.33.0 [2024-03-12]
|
0.33.0 [2024-03-12]
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|||||||
@@ -249,8 +249,26 @@ find_substitute_face(CFStringRef str, CTFontRef old_font, CPUCell *cpu_cell) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CTFontRef
|
||||||
|
apply_styles_to_fallback_font(CTFontRef original_fallback_font, bool bold, bool italic) {
|
||||||
|
if (!original_fallback_font || is_last_resort_font(original_fallback_font)) return original_fallback_font;
|
||||||
|
CTFontRef ans = nil;
|
||||||
|
CTFontDescriptorRef original_descriptor = CTFontCopyFontDescriptor(original_fallback_font);
|
||||||
|
CTFontSymbolicTraits traits = kCTFontTraitMonoSpace;
|
||||||
|
if (bold) traits |= kCTFontTraitBold;
|
||||||
|
if (italic) traits |= kCTFontTraitItalic;
|
||||||
|
CTFontDescriptorRef descriptor = CTFontDescriptorCreateCopyWithSymbolicTraits(original_descriptor, traits, traits);
|
||||||
|
CFRelease(original_descriptor);
|
||||||
|
if (descriptor) {
|
||||||
|
ans = CTFontCreateWithFontDescriptor(descriptor, CTFontGetSize(original_fallback_font), NULL);
|
||||||
|
CFRelease(descriptor);
|
||||||
|
}
|
||||||
|
if (ans) { CFRelease(original_fallback_font); return ans; }
|
||||||
|
return original_fallback_font;
|
||||||
|
}
|
||||||
|
|
||||||
PyObject*
|
PyObject*
|
||||||
create_fallback_face(PyObject *base_face, CPUCell* cell, bool UNUSED bold, bool UNUSED italic, bool emoji_presentation, FONTS_DATA_HANDLE fg) {
|
create_fallback_face(PyObject *base_face, CPUCell* cell, bool bold, bool italic, bool emoji_presentation, FONTS_DATA_HANDLE fg) {
|
||||||
CTFace *self = (CTFace*)base_face;
|
CTFace *self = (CTFace*)base_face;
|
||||||
CTFontRef new_font;
|
CTFontRef new_font;
|
||||||
#define search_for_fallback() \
|
#define search_for_fallback() \
|
||||||
@@ -268,21 +286,19 @@ create_fallback_face(PyObject *base_face, CPUCell* cell, bool UNUSED bold, bool
|
|||||||
search_for_fallback();
|
search_for_fallback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { search_for_fallback(); }
|
else { search_for_fallback(); new_font = apply_styles_to_fallback_font(new_font, bold, italic); }
|
||||||
if (new_font == NULL) return NULL;
|
if (new_font == NULL) return NULL;
|
||||||
NSURL *url = (NSURL*)CTFontCopyAttribute(new_font, kCTFontURLAttribute);
|
PyObject *postscript_name = Py_BuildValue("s", convert_cfstring(CTFontCopyPostScriptName(new_font), true));
|
||||||
const char *font_path = [[url path] UTF8String];
|
|
||||||
ssize_t idx = -1;
|
ssize_t idx = -1;
|
||||||
PyObject *q, *ans = NULL;
|
PyObject *q, *ans = NULL;
|
||||||
while ((q = iter_fallback_faces(fg, &idx))) {
|
while ((q = iter_fallback_faces(fg, &idx))) {
|
||||||
CTFace *qf = (CTFace*)q;
|
CTFace *qf = (CTFace*)q;
|
||||||
const char *qpath;
|
if (PyObject_RichCompareBool(postscript_name, qf->postscript_name, Py_EQ) == 1) {
|
||||||
if (qf->path && (qpath = PyUnicode_AsUTF8(qf->path)) && strcmp(qpath, font_path) == 0) {
|
|
||||||
ans = PyLong_FromSsize_t(idx);
|
ans = PyLong_FromSsize_t(idx);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[url release];
|
Py_CLEAR(postscript_name);
|
||||||
if (ans == NULL) return (PyObject*)ct_face(new_font, fg);
|
if (ans == NULL) return (PyObject*)ct_face(new_font, fg);
|
||||||
CFRelease(new_font);
|
CFRelease(new_font);
|
||||||
return ans;
|
return ans;
|
||||||
|
|||||||
Reference in New Issue
Block a user