Option to print debug information about font fallback

This commit is contained in:
Kovid Goyal 2018-02-28 21:43:40 +05:30
parent c93238d8c9
commit 139838c717
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 25 additions and 5 deletions

View File

@ -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.
'''

View File

@ -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;
}
}

View File

@ -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)

View File

@ -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);

View File

@ -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;