diff --git a/kitty/cli.py b/kitty/cli.py index 7fdb89ed3..48a0e831e 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -107,6 +107,11 @@ Path to file in which to store the raw bytes received from the child process --debug-gl type=bool-set Debug OpenGL commands. This will cause all OpenGL calls to check for errors instead of ignoring them. Useful when debugging rendering problems + + +--debug-font-fallback +type=bool-set +Print out information about the selection of fallback fonts for characters not present in the main font. ''' diff --git a/kitty/fonts.c b/kitty/fonts.c index 8314b8cf1..1b265e532 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -339,6 +339,19 @@ has_cell_text(Font *self, Cell *cell) { return true; } +static inline void +output_cell_fallback_data(Cell *cell, bool bold, bool italic, bool emoji_presentation, PyObject *face, bool new_face) { + printf("U+%x ", cell->ch); + for (unsigned i = 0; i < arraysz(cell->cc_idx) && cell->cc_idx[i]; i++) { + printf("U+%x ", codepoint_for_mark(cell->cc_idx[i])); + } + if (bold) printf("bold "); + if (italic) printf("italic "); + if (emoji_presentation) printf("emoji_presentation "); + PyObject_Print(face, stdout, 0); + if (new_face) printf(" (new face)"); + printf("\n"); +} static inline ssize_t load_fallback_font(Cell *cell, bool bold, bool italic, bool emoji_presentation) { @@ -352,6 +365,7 @@ load_fallback_font(Cell *cell, bool bold, bool italic, bool emoji_presentation) PyObject *face = create_fallback_face(fonts.fonts[f].face, cell, bold, italic, emoji_presentation); if (face == NULL) { PyErr_Print(); return MISSING_FONT; } if (face == Py_None) { Py_DECREF(face); return MISSING_FONT; } + if (global_state.debug_font_fallback) output_cell_fallback_data(cell, bold, italic, emoji_presentation, face, true); set_size_for_face(face, cell_height, true); ensure_space_for(&fonts, fonts, Font, fonts.fonts_count + 1, fonts_capacity, 5, true); @@ -364,7 +378,6 @@ load_fallback_font(Cell *cell, bool bold, bool italic, bool emoji_presentation) return ans; } - static inline ssize_t fallback_font(Cell *cell) { bool bold = (cell->attrs >> BOLD_SHIFT) & 1; @@ -375,6 +388,7 @@ fallback_font(Cell *cell) { 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 && ff->emoji_presentation == emoji_presentation && has_cell_text(ff, cell)) { + if (global_state.debug_font_fallback) output_cell_fallback_data(cell, bold, italic, emoji_presentation, ff->face, false); return j; } } diff --git a/kitty/main.py b/kitty/main.py index 882d8b86c..7055a31de 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -39,7 +39,7 @@ def init_graphics(): def run_app(opts, args): set_scale(opts.box_drawing_scale) - set_options(opts, is_wayland, args.debug_gl) + set_options(opts, is_wayland, args.debug_gl, args.debug_font_fallback) if is_macos: from .fast_data_types import macos_change_titlebar_color macos_change_titlebar_color(opts.macos_titlebar_color) diff --git a/kitty/state.c b/kitty/state.c index 66a36cc63..4b97a55d4 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -323,10 +323,11 @@ PYWRAP1(handle_for_window_id) { PYWRAP1(set_options) { PyObject *ret, *opts; - int is_wayland = 0, debug_gl = 0; - PA("O|pp", &opts, &is_wayland, &debug_gl); + int is_wayland = 0, debug_gl = 0, debug_font_fallback = 0; + PA("O|ppp", &opts, &is_wayland, &debug_gl, &debug_font_fallback); global_state.is_wayland = is_wayland ? true : false; global_state.debug_gl = debug_gl ? true : false; + global_state.debug_font_fallback = debug_font_fallback ? true : false; #define GA(name) ret = PyObject_GetAttrString(opts, #name); if (ret == NULL) return NULL; #define S(name, convert) { GA(name); global_state.opts.name = convert(ret); Py_DECREF(ret); if (PyErr_Occurred()) return NULL; } S(visual_bell_duration, PyFloat_AsDouble); diff --git a/kitty/state.h b/kitty/state.h index 2b9b72ab3..235d3cdbf 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -130,7 +130,7 @@ typedef struct { OSWindow *callback_os_window; bool close_all_windows; bool is_wayland; - bool debug_gl; + bool debug_gl, debug_font_fallback; bool has_pending_resizes; } GlobalState;