From e931c21e89210aafd73ec956f03c6c9abeec5167 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 1 Mar 2026 21:55:11 +0100 Subject: [PATCH] Correct draw translation by 0.5 pixels only Using 1.5 pixels causes text to be rendered one pixel offset to the top left. This is visible when text is selected as the characters touch the top left border. The fl_text_extents is also updated to make sure the bounding box is properly placed. --- src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx index 9d883e14e..3a9262f91 100644 --- a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx +++ b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx @@ -1340,7 +1340,7 @@ void Fl_Cairo_Graphics_Driver::draw(const char* str, int n, float x, float y) { if (!n) return; cairo_save(cairo_); Fl_Cairo_Font_Descriptor *fd = (Fl_Cairo_Font_Descriptor*)font_descriptor(); - cairo_translate(cairo_, x - 1.5, y - (fd->line_height - fd->descent) / float(PANGO_SCALE) - 1.5); + cairo_translate(cairo_, x - 0.5, y - (fd->line_height - fd->descent) / float(PANGO_SCALE) - 0.5); str = clean_utf8(str, n); pango_layout_set_text(pango_layout_, str, n); pango_cairo_show_layout(cairo_, pango_layout_); // 1.1O @@ -1424,8 +1424,8 @@ void Fl_Cairo_Graphics_Driver::text_extents(const char* txt, int n, int& dx, int pango_layout_get_extents(pango_layout_, &ink_rect, NULL); double f = PANGO_SCALE; Fl_Cairo_Font_Descriptor *fd = (Fl_Cairo_Font_Descriptor*)font_descriptor(); - dx = ink_rect.x / f - 1; - dy = (ink_rect.y - fd->line_height + fd->descent) / f - 1; + dx = ink_rect.x / f; + dy = (ink_rect.y - fd->line_height + fd->descent) / f; w = ceil(ink_rect.width / f); h = ceil(ink_rect.height / f); }