Fix some emoji glyphs not colored on Linux

Linux has a plethora of fonts that contain some emoji glyphs. If one of
those fonts is used as a fallback font for a non-emoji character, it
also gets used for emojis -- leading to non-colored emoji. Fix by making
sure the first fallback font is a dedicated emoji font.
This commit is contained in:
Kovid Goyal 2017-12-20 10:40:23 +05:30
parent e69de2f968
commit 11ee317884
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -1,4 +1,5 @@
/* /*
* vim:fileencoding=utf-8
* fonts.c * fonts.c
* Copyright (C) 2017 Kovid Goyal <kovid at kovidgoyal.net> * Copyright (C) 2017 Kovid Goyal <kovid at kovidgoyal.net>
* *
@ -331,20 +332,11 @@ has_cell_text(Font *self, Cell *cell) {
return true; return true;
} }
static inline ssize_t static inline ssize_t
fallback_font(Cell *cell) { load_fallback_font(Cell *cell, bool bold, bool italic) {
bool bold = (cell->attrs >> BOLD_SHIFT) & 1;
bool italic = (cell->attrs >> ITALIC_SHIFT) & 1;
ssize_t f;
for (size_t i = 0, j = fonts.first_fallback_font_idx; i < fonts.fallback_fonts_count; i++, j++) {
Font *ff = fonts.fonts +j;
if (ff->bold == bold && ff->italic == italic && has_cell_text(ff, cell)) {
return j;
}
}
if (fonts.fallback_fonts_count > 100) { fprintf(stderr, "Too many fallback fonts\n"); return MISSING_FONT; } if (fonts.fallback_fonts_count > 100) { fprintf(stderr, "Too many fallback fonts\n"); return MISSING_FONT; }
ssize_t f;
if (bold) f = fonts.italic_font_idx > 0 ? fonts.bi_font_idx : fonts.bold_font_idx; if (bold) f = fonts.italic_font_idx > 0 ? fonts.bi_font_idx : fonts.bold_font_idx;
else f = italic ? fonts.italic_font_idx : fonts.medium_font_idx; else f = italic ? fonts.italic_font_idx : fonts.medium_font_idx;
@ -365,6 +357,31 @@ fallback_font(Cell *cell) {
return ans; return ans;
} }
static inline ssize_t
fallback_font(Cell *cell) {
bool bold = (cell->attrs >> BOLD_SHIFT) & 1;
bool italic = (cell->attrs >> ITALIC_SHIFT) & 1;
// Load the emoji fallback font first as on Linux there are a bunch of
// non-color fonts that provide some emoji glyphs.
if (fonts.fallback_fonts_count < 1) {
Cell c = {0};
c.ch = 0x1f648; // 🙈
load_fallback_font(&c, false, false);
}
// Check if one of the existing fallback fonts has this text
for (size_t i = 0, j = fonts.first_fallback_font_idx; i < fonts.fallback_fonts_count; i++, j++) {
Font *ff = fonts.fonts +j;
if (ff->bold == bold && ff->italic == italic && has_cell_text(ff, cell)) {
return j;
}
}
return load_fallback_font(cell, bold, italic);
}
static inline ssize_t static inline ssize_t
in_symbol_maps(char_type ch) { in_symbol_maps(char_type ch) {
for (size_t i = 0; i < fonts.symbol_maps_count; i++) { for (size_t i = 0; i < fonts.symbol_maps_count; i++) {