macOS: When the Apple Color Emoji font lacks an emoji glyph search for it in other installed fonts

Fixes #3591
This commit is contained in:
Kovid Goyal 2021-05-09 07:17:32 +05:30
parent 7c48db7da8
commit 63d76ee837
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 17 additions and 7 deletions

View File

@ -15,6 +15,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- Fix a regression in 0.20.0 that sent incorrect bytes for the :kbd:`F1-F4` keys
in rmkx mode (:iss:`3586`)
- macOS: When the Apple Color Emoji font lacks an emoji glyph search for it in other
installed fonts (:iss:`3591`)
0.20.3 [2021-05-06]
----------------------

View File

@ -250,15 +250,22 @@ PyObject*
create_fallback_face(PyObject *base_face, CPUCell* cell, bool UNUSED bold, bool UNUSED italic, bool emoji_presentation, FONTS_DATA_HANDLE fg UNUSED) {
CTFace *self = (CTFace*)base_face;
CTFontRef new_font;
if (emoji_presentation) new_font = CTFontCreateWithName((CFStringRef)@"AppleColorEmoji", self->scaled_point_sz, NULL);
else {
char text[64] = {0};
cell_as_utf8_for_fallback(cell, text);
CFStringRef str = CFStringCreateWithCString(NULL, text, kCFStringEncodingUTF8);
if (str == NULL) return PyErr_NoMemory();
new_font = find_substitute_face(str, self->ct_font, cell);
#define search_for_fallback() \
char text[64] = {0}; \
cell_as_utf8_for_fallback(cell, text); \
CFStringRef str = CFStringCreateWithCString(NULL, text, kCFStringEncodingUTF8); \
if (str == NULL) return PyErr_NoMemory(); \
new_font = find_substitute_face(str, self->ct_font, cell); \
CFRelease(str);
if (emoji_presentation) {
new_font = CTFontCreateWithName((CFStringRef)@"AppleColorEmoji", self->scaled_point_sz, NULL);
if (!new_font || !glyph_id_for_codepoint_ctfont(new_font, cell->ch)) {
if (new_font) CFRelease(new_font);
search_for_fallback();
}
}
else { search_for_fallback(); }
if (new_font == NULL) return NULL;
return (PyObject*)ct_face(new_font);
}