diff --git a/docs/changelog.rst b/docs/changelog.rst index 1b930e61a..93073c871 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -185,6 +185,8 @@ Detailed list of changes - Allow optionally dragging URLs with the mouse, see :sc:`start_simple_selection` (:pull:`9804`) +- Improve ``draw_single_line_of_text()`` to accept an optional ``max_width`` parameter. When set, the width is treated as a maximum and reduced to the actual text width if smaller. The function now returns both pixel data and actual width used. + - Fix thickness of diagonal lines in box drawing characters not the same as horizontal/vertical lines (:iss:`9719`) - Graphics protocol: Fix crash when handling invalid PNG image with direct transmission diff --git a/kitty/glfw.c b/kitty/glfw.c index 7cc51d264..d72454ddd 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -3111,7 +3111,7 @@ draw_single_line_of_text(PyObject *self UNUSED, PyObject *args) { size_t height = (size_t)w->fonts_data->fcm.cell_height + padding_y; if (max_width) { size_t text_w = text_width_for_single_line(font_sz_pts, ydpi, text, height); - if (text_w > 0 && (int)text_w < width) width = (int)text_w; + if (text_w > 0 && text_w < (size_t)width) width = (int)text_w; } size_t buf_sz = (size_t)width * height * 4; RAII_PyObject(ans, PyBytes_FromStringAndSize(NULL, buf_sz)); if (!ans) return NULL;