Fix T62678: Wrong text clipping
authorJacques Lucke <mail@jlucke.com>
Sun, 17 Mar 2019 13:15:26 +0000 (14:15 +0100)
committerJacques Lucke <mail@jlucke.com>
Sun, 17 Mar 2019 13:15:26 +0000 (14:15 +0100)
There are two issues at play here.
First, BLF_width computed a width that was not wide
enough to actually hold the text.
Second, blf_glyph_calc_rect_test computed an incorrect
rect->xmax when the glyph was moved to the left a bit.
We ignore the overlap on the left, but the right side
should still be adjusted accordingly.

source/blender/blenfont/intern/blf_glyph.c

index 4c5f598..45761a3 100644 (file)
@@ -441,9 +441,9 @@ static void blf_glyph_calc_rect_test(rctf *rect, GlyphBLF *g, float x, float y)
 {
        /* intentionally check clipping without shadow offset and negative kerning */
        rect->xmin = floorf(x + MAX2(0.0f, g->pos_x));
-       rect->xmax = rect->xmin + (float)g->width;
+       rect->xmax = rect->xmin + (float)g->width + MIN2(0.0f, g->pos_x);
        rect->ymin = floorf(y + MAX2(0.0f, g->pos_y));
-       rect->ymax = rect->ymin - (float)g->height;
+       rect->ymax = rect->ymin - (float)g->height - MIN2(0.0f, g->pos_y);
 }
 
 static void blf_glyph_calc_rect_shadow(rctf *rect, GlyphBLF *g, float x, float y, FontBLF *font)