From 8d94285a5d04f9acbb62a721f431061798cd5175 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 19 Dec 2017 00:54:04 +0530 Subject: [PATCH] Ensure underlines are rendered even for fonts with very poor metrics Fixes #236 --- kitty/fonts.c | 2 ++ kitty/fonts/render.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/kitty/fonts.c b/kitty/fonts.c index bba2847b8..91c6bae64 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -289,6 +289,8 @@ update_cell_metrics() { if (cell_height < 4) { PyErr_SetString(PyExc_ValueError, "line height too small after adjustment"); return NULL; } if (cell_height > 1000) { PyErr_SetString(PyExc_ValueError, "line height too large after adjustment"); return NULL; } 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--; if (line_height_adjustment > 1) { baseline += MIN(cell_height - 1, (unsigned)line_height_adjustment / 2); underline_position += MIN(cell_height - 1, (unsigned)line_height_adjustment / 2); diff --git a/kitty/fonts/render.py b/kitty/fonts/render.py index 821b20010..0264596a9 100644 --- a/kitty/fonts/render.py +++ b/kitty/fonts/render.py @@ -73,7 +73,7 @@ def resize_fonts(new_sz): def add_line(buf, cell_width, position, thickness, cell_height): y = position - thickness // 2 - while thickness > 0 and y > -1 and y < cell_height - 1: + while thickness > 0 and y > -1 and y < cell_height: thickness -= 1 ctypes.memset(ctypes.addressof(buf) + (cell_width * y), 255, cell_width) y += 1