From 9842d169de1cc303c3d65578118a027f0b0c2033 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Thu, 23 Feb 2023 14:40:49 -0800 Subject: [PATCH] BLF: Revert Glyph Clipping Changes Revert #104679. We are just too used to the old behavior, especially the incorrect vertical clipping. Some uses rely on setting the min and max of the clipping rect the same. Will have to revisit this later to only correct for horizontal positioning for full hinting. --- source/blender/blenfont/intern/blf_glyph.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index 8f8194be8ea..2cc730a0b42 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -1091,6 +1091,17 @@ static void blf_glyph_calc_rect(rcti *rect, GlyphBLF *g, const int x, const int rect->ymax = rect->ymin - g->dims[1]; } +static void blf_glyph_calc_rect_test(rcti *rect, GlyphBLF *g, const int x, const int y) +{ + /* Intentionally check with `g->advance`, because this is the + * width used by BLF_width. This allows that the text slightly + * overlaps the clipping border to achieve better alignment. */ + rect->xmin = x; + rect->xmax = rect->xmin + MIN2(ft_pix_to_int(g->advance_x), g->dims[0]); + rect->ymin = y; + rect->ymax = rect->ymin - g->dims[1]; +} + static void blf_glyph_calc_rect_shadow( rcti *rect, GlyphBLF *g, const int x, const int y, FontBLF *font) { @@ -1202,10 +1213,8 @@ void blf_glyph_draw(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, const int x, if (font->flags & BLF_CLIPPING) { rcti rect_test; - rect_test.xmin = x + font->pos[0] + g->pos[0] + 1; - rect_test.xmax = rect_test.xmin + g->dims[0] - 2; - rect_test.ymin = y + font->pos[1]; - rect_test.ymax = rect_test.ymin + g->pos[1]; + blf_glyph_calc_rect_test(&rect_test, g, x, y); + BLI_rcti_translate(&rect_test, font->pos[0], font->pos[1]); if (!BLI_rcti_inside_rcti(&font->clip_rec, &rect_test)) { return; } -- 2.30.2