From 57742c78680e7f03ea0424f9d87b047cfdc1a191 Mon Sep 17 00:00:00 2001 From: Leon Schittek Date: Sat, 4 Mar 2023 07:12:14 +0100 Subject: [PATCH] Fix: Wrong text clipping in the frame node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When drawing text with multiple lines inside a frame node, depending on the zoom level some lines would wrongly get clipped despite being inside the clipping region. This was caused by the clipping check in `blf_glyph_draw` not accounting for the font’s aspect. Pull Request #105389 --- source/blender/blenfont/intern/blf_glyph.c | 13 ++++++++++++- source/blender/editors/space_node/node_draw.cc | 9 ++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index 67418644fea..1990b43122c 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -1212,8 +1212,19 @@ void blf_glyph_draw(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, const int x, } if (font->flags & BLF_CLIPPING) { + float xa, ya; + + if (font->flags & BLF_ASPECT) { + xa = font->aspect[0]; + ya = font->aspect[1]; + } + else { + xa = 1.0f; + ya = 1.0f; + } + rcti rect_test; - blf_glyph_calc_rect_test(&rect_test, g, x, y); + blf_glyph_calc_rect_test(&rect_test, g, x * xa, y * ya); BLI_rcti_translate(&rect_test, font->pos[0], font->pos[1]); if (!BLI_rcti_inside_rcti(&font->clip_rec, &rect_test)) { return; diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index ef943ea30ba..b25f97c9c54 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -2845,7 +2845,7 @@ static void frame_node_draw_label(TreeDrawContext &tree_draw_ctx, const Text *text = (const Text *)node.id; const int line_height_max = BLF_height_max(fontid); const float line_spacing = (line_height_max * aspect); - const float line_width = (BLI_rctf_size_x(&rct) - margin) / aspect; + const float line_width = (BLI_rctf_size_x(&rct) - 2 * margin) / aspect; /* 'x' doesn't need aspect correction. */ x = rct.xmin + margin; @@ -2854,12 +2854,7 @@ static void frame_node_draw_label(TreeDrawContext &tree_draw_ctx, int y_min = y + ((margin * 2) - (y - rct.ymin)); BLF_enable(fontid, BLF_CLIPPING | BLF_WORD_WRAP); - BLF_clipping(fontid, - rct.xmin, - /* Round to avoid clipping half-way through a line. */ - y - (floorf(((y - rct.ymin) - (margin * 2)) / line_spacing) * line_spacing), - rct.xmin + line_width, - rct.ymax); + BLF_clipping(fontid, rct.xmin, rct.ymin + margin, rct.xmax, rct.ymax); BLF_wordwrap(fontid, line_width);