Fix: Wrong text clipping in the frame node #105389

Merged
Leon Schittek merged 3 commits from lone_noel/blender:fix-frame-node-text-clipping into main 2023-03-04 07:12:27 +01:00
2 changed files with 14 additions and 8 deletions

View File

@ -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;

View File

@ -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);