From 47492c7aa6aa5cb910fd941eae442959fbdb67fe Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Thu, 28 Nov 2024 20:14:59 +0100 Subject: [PATCH] Fix #130385: Use Only Advance When Measuring Mono Text When measuring text strings we consider both the advance and the glyph bounding box. But monospaced text should only use the advance because many fonts allow some mono characters to slightly overflow. This just removes bounding box from the calculation of width for mono text. Pull Request: https://projects.blender.org/blender/blender/pulls/131114 --- source/blender/blenfont/intern/blf_font.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/blender/blenfont/intern/blf_font.cc b/source/blender/blenfont/intern/blf_font.cc index e1d57e5fb9f..ffe19e14a25 100644 --- a/source/blender/blenfont/intern/blf_font.cc +++ b/source/blender/blenfont/intern/blf_font.cc @@ -916,7 +916,10 @@ static void blf_font_boundbox_ex(FontBLF *font, const ft_pix pen_x_next = pen_x + g->advance_x; const ft_pix gbox_xmin = std::min(pen_x, pen_x + g->box_xmin); - const ft_pix gbox_xmax = std::max(pen_x_next, pen_x + g->box_xmax); + /* Monspaced characters should only use advance. #130385. */ + const ft_pix gbox_xmax = (font->flags & BLF_MONOSPACED) ? + pen_x_next : + std::max(pen_x_next, pen_x + g->box_xmax); const ft_pix gbox_ymin = g->box_ymin + pen_y; const ft_pix gbox_ymax = g->box_ymax + pen_y;