diff --git a/kitty/fonts.c b/kitty/fonts.c index 76ba64246..dc5b295f1 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -331,6 +331,20 @@ python_send_to_gpu(FONTS_DATA_HANDLE fg, unsigned int x, unsigned int y, unsigne } } +static void +adjust_metric(unsigned int *metric, float adj, AdjustmentUnit unit, double dpi) { + if (adj == 0.f) return; + int a = 0; + switch (unit) { + case POINT: + a = ((long)round((adj * (dpi / 72.0)))); break; + case PERCENT: + *metric = (int)roundf((fabsf(adj) * (float)*metric) / 100.f); return; + case PIXEL: + a = (int)roundf(adj); break; + } + *metric = (a < 0 && -a > (int)*metric) ? 0 : *metric + a; +} static void calc_cell_metrics(FontGroup *fg) { @@ -358,6 +372,11 @@ calc_cell_metrics(FontGroup *fg) { #undef MIN_WIDTH #undef MIN_HEIGHT #undef MAX_DIM + +#define A(which, dpi) adjust_metric(&which, OPT(which).val, OPT(which).unit, fg->logical_dpi_##dpi); + A(underline_thickness, y); A(underline_position, y); A(strikethrough_thickness, y); A(strikethrough_position, y); +#undef A + underline_position = MIN(cell_height - 1, underline_position); // ensure there is at least a couple of pixels available to render styled underlines while (underline_position > baseline + 1 && cell_height - underline_position < 2) underline_position--; diff --git a/kitty/options/to-c.h b/kitty/options/to-c.h index 82a7efa67..ba2ed1820 100644 --- a/kitty/options/to-c.h +++ b/kitty/options/to-c.h @@ -120,11 +120,8 @@ parse_font_mod_size(PyObject *val, float *sz, AdjustmentUnit *unit) { PyObject *mv = PyObject_GetAttrString(val, "mod_value"); if (mv) { *sz = PyFloat_AsFloat(PyTuple_GET_ITEM(mv, 0)); - switch (PyLong_AsLong(PyTuple_GET_ITEM(mv, 1))) { - case 0: *unit = POINT; break; - case 1: *unit = PIXEL; break; - case 2: *unit = PERCENT; break; - } + long u = PyLong_AsLong(PyTuple_GET_ITEM(mv, 1)); + switch (u) { case POINT: case PERCENT: case PIXEL: *unit = u; break; } } } diff --git a/kitty/state.h b/kitty/state.h index 0f911a76a..e7dbb8019 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -21,7 +21,7 @@ typedef struct { size_t len; } UrlPrefix; -typedef enum AdjustmentUnit { POINT, PERCENT, PIXEL } AdjustmentUnit; +typedef enum AdjustmentUnit { POINT = 0, PERCENT = 1, PIXEL = 2 } AdjustmentUnit; typedef struct { monotonic_t visual_bell_duration, cursor_blink_interval, cursor_stop_blinking_after, mouse_hide_wait, click_interval;