From b385ccbc45dc0dcd421d8025c7b4bffe1569e466 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 24 Apr 2024 13:05:22 +0530 Subject: [PATCH] Output resolved fonts in debug config --- kitty/core_text.m | 8 ++++++++ kitty/debug_config.py | 6 +++++- kitty/fast_data_types.pyi | 2 ++ kitty/freetype.c | 11 +++++++++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/kitty/core_text.m b/kitty/core_text.m index cff5f486e..5a2ccde65 100644 --- a/kitty/core_text.m +++ b/kitty/core_text.m @@ -808,6 +808,13 @@ get_variable_data(CTFace *self) { size_t table_len = cftable ? CFDataGetLength(cftable) : 0; return read_fvar_font_table(table, table_len, self->name_lookup_table); } + +static PyObject* +identify_for_debug(CTFace *self) { + return PyUnicode_FromFormat("%V: %V", self->postscript_name, "[psname]", self->path, "[path]"); +} + + // }}} @@ -822,6 +829,7 @@ display_name(CTFace *self) { static PyMethodDef methods[] = { METHODB(display_name, METH_NOARGS), METHODB(get_variable_data, METH_NOARGS), + METHODB(identify_for_debug, METH_NOARGS), METHODB(get_best_name, METH_O), {NULL} /* Sentinel */ }; diff --git a/kitty/debug_config.py b/kitty/debug_config.py index ee37d877b..fe6a3f71b 100644 --- a/kitty/debug_config.py +++ b/kitty/debug_config.py @@ -17,7 +17,7 @@ from kittens.tui.operations import colored, styled from .child import cmdline_of_pid from .cli import version from .constants import extensions_dir, is_macos, is_wayland, kitty_base_dir, kitty_exe, shell_path -from .fast_data_types import Color, SingleKey, num_users, opengl_version_string, wayland_compositor_data +from .fast_data_types import Color, SingleKey, current_fonts, num_users, opengl_version_string, wayland_compositor_data from .options.types import Options as KittyOpts from .options.types import defaults from .options.utils import KeyboardMode, KeyDefinition @@ -257,6 +257,10 @@ def debug_config(opts: KittyOpts) -> str: p('Running under:', green(compositor_name())) p(green('OpenGL:'), opengl_version_string()) p(green('Frozen:'), 'True' if getattr(sys, 'frozen', False) else 'False') + p(green('Fonts:')) + for k, font in current_fonts().items(): + if hasattr(font, 'identify_for_debug'): + p(yellow(f' {k}:'), font.identify_for_debug()) p(green('Paths:')) p(yellow(' kitty:'), os.path.realpath(kitty_exe())) p(yellow(' base dir:'), kitty_base_dir) diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 39a8caf80..bebe8120d 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -420,6 +420,7 @@ def fc_match_postscript_name( class Face: def __init__(self, descriptor: Optional[FontConfigPattern] = None, path: str = '', index: int = 0): ... def get_variable_data(self) -> VariableData: ... + def identify_for_debug(self) -> str: ... class CoreTextFont(TypedDict): @@ -445,6 +446,7 @@ class CoreTextFont(TypedDict): class CTFace: def __init__(self, descriptor: Optional[CoreTextFont] = None, path: str = ''): ... def get_variable_data(self) -> VariableData: ... + def identify_for_debug(self) -> str: ... def coretext_all_fonts() -> Tuple[CoreTextFont, ...]: diff --git a/kitty/freetype.c b/kitty/freetype.c index eea92a208..79fb1ca3a 100644 --- a/kitty/freetype.c +++ b/kitty/freetype.c @@ -691,7 +691,7 @@ render_glyphs_in_cells(PyObject *f, bool bold, bool italic, hb_glyph_info_t *inf } static PyObject* -display_name(PyObject *s, PyObject *a UNUSED) { +postscript_name(PyObject *s, PyObject *a UNUSED) { Face *self = (Face*)s; const char *psname = FT_Get_Postscript_Name(self->face); if (psname) return Py_BuildValue("s", psname); @@ -699,6 +699,12 @@ display_name(PyObject *s, PyObject *a UNUSED) { return self->path; } +static PyObject* +identify_for_debug(PyObject *s, PyObject *a UNUSED) { + Face *self = (Face*)s; + return PyUnicode_FromFormat("%s: %V:%d", FT_Get_Postscript_Name(self->face), self->path, "[path]", self->instance.val); +} + static PyObject* extra_data(PyObject *self, PyObject *a UNUSED) { return PyLong_FromVoidPtr(((Face*)self)->extra_data); @@ -862,7 +868,8 @@ static PyMemberDef members[] = { }; static PyMethodDef methods[] = { - METHODB(display_name, METH_NOARGS), + METHODB(postscript_name, METH_NOARGS), + METHODB(identify_for_debug, METH_NOARGS), METHODB(extra_data, METH_NOARGS), METHODB(get_variable_data, METH_NOARGS), METHODB(get_best_name, METH_O),