diff --git a/kitty/core_text.m b/kitty/core_text.m index 61c48fbc3..8c54ba69b 100644 --- a/kitty/core_text.m +++ b/kitty/core_text.m @@ -366,7 +366,7 @@ cell_metrics(PyObject *s, unsigned int* cell_width, unsigned int* cell_height, u CGRect bounds_without_leading = CTLineGetBoundsWithOptions(line, kCTLineBoundsExcludeTypographicLeading); CGFloat typographic_ascent, typographic_descent, typographic_leading; CTLineGetTypographicBounds(line, &typographic_ascent, &typographic_descent, &typographic_leading); - CGFloat bounds_ascent = bounds_without_leading.size.height + bounds_without_leading.origin.y; + CGFloat bounds_ascent = bounds_without_leading.size.height + bounds_without_leading.origin.y - OPT(adjust_baseline); *baseline = (unsigned int)floor(bounds_ascent + 0.5); *cell_height = MAX(4u, (unsigned int)ceilf(line_height)); // Not sure if we should add this to bounds ascent and then round it or add diff --git a/kitty/options/definition.py b/kitty/options/definition.py index d8371fe9c..e22475c9f 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -94,6 +94,15 @@ opt('adjust_column_width', '0', option_type='adjust_line_height', ctype='!adjust_column_width', ) +opt('adjust_baseline', '0', + option_type='int', ctype='int', + add_to_default=False, + long_text=''' +Adjust the baseline position of each character (in pixels) on macOS. A positive +number moves all characters up, and a negative number moves them down. +''' + ) + opt('+symbol_map', 'U+E0A0-U+E0A3,U+E0C0-U+E0C7 PowerlineSymbols', option_type='symbol_map', add_to_default=False, diff --git a/kitty/options/parse.py b/kitty/options/parse.py index b98d19b2b..b03396912 100644 --- a/kitty/options/parse.py +++ b/kitty/options/parse.py @@ -37,6 +37,9 @@ class Parser: def active_tab_title_template(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: ans['active_tab_title_template'] = active_tab_title_template(val) + def adjust_baseline(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: + ans['adjust_baseline'] = int(val) + def adjust_column_width(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: ans['adjust_column_width'] = adjust_line_height(val) diff --git a/kitty/options/to-c-generated.h b/kitty/options/to-c-generated.h index 89d13e5bb..d18dcb7a2 100644 --- a/kitty/options/to-c-generated.h +++ b/kitty/options/to-c-generated.h @@ -57,6 +57,19 @@ convert_from_opts_adjust_column_width(PyObject *py_opts, Options *opts) { Py_DECREF(ret); } +static void +convert_from_python_adjust_baseline(PyObject *val, Options *opts) { + opts->adjust_baseline = PyLong_AsLong(val); +} + +static void +convert_from_opts_adjust_baseline(PyObject *py_opts, Options *opts) { + PyObject *ret = PyObject_GetAttrString(py_opts, "adjust_baseline"); + if (ret == NULL) return; + convert_from_python_adjust_baseline(ret, opts); + Py_DECREF(ret); +} + static void convert_from_python_disable_ligatures(PyObject *val, Options *opts) { opts->disable_ligatures = PyLong_AsLong(val); @@ -886,6 +899,8 @@ convert_opts_from_python_opts(PyObject *py_opts, Options *opts) { if (PyErr_Occurred()) return false; convert_from_opts_adjust_column_width(py_opts, opts); if (PyErr_Occurred()) return false; + convert_from_opts_adjust_baseline(py_opts, opts); + if (PyErr_Occurred()) return false; convert_from_opts_disable_ligatures(py_opts, opts); if (PyErr_Occurred()) return false; convert_from_opts_cursor_shape(py_opts, opts); diff --git a/kitty/options/types.py b/kitty/options/types.py index bf7b9d2d2..9d3e14431 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -45,6 +45,7 @@ option_names = ( # {{{ 'active_tab_font_style', 'active_tab_foreground', 'active_tab_title_template', + 'adjust_baseline', 'adjust_column_width', 'adjust_line_height', 'allow_hyperlinks', @@ -435,6 +436,7 @@ class Options: active_tab_font_style: typing.Tuple[bool, bool] = (True, True) active_tab_foreground: Color = Color(red=0, green=0, blue=0) active_tab_title_template: typing.Optional[str] = None + adjust_baseline: int = 0 adjust_column_width: typing.Union[int, float] = 0 adjust_line_height: typing.Union[int, float] = 0 allow_hyperlinks: int = 1 diff --git a/kitty/state.h b/kitty/state.h index 9971565ad..5fd909084 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -42,6 +42,7 @@ typedef struct { WindowTitleIn macos_show_window_title_in; int adjust_line_height_px, adjust_column_width_px; float adjust_line_height_frac, adjust_column_width_frac; + int adjust_baseline; float background_opacity, dim_opacity; char* background_image;