[draw] Normalize w/h in hb_draw_rect

Negative w/h are documented as supported but the stroked
variant's math (outer grows by stroke_width, inner shrinks
by stroke_width) silently inverts — outer ends up smaller
than inner, the ring becomes a filled outer rect, and
arbitrary-path clip users (who feed raw font glyph extents
with y_bearing-style negative height) see the clip fill
everything instead of just the stroke ring.

Normalize w/h to non-negative at the top of hb_draw_rect
so the rest of the stroke math produces the expected
outer-contains-inner ring.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Behdad EsfahbodandClaude Opus 4.6 committed 2026-04-16 16:18:20 -06:00
1 parent f3c36ef3d6
commit 8f735c05cd
1 file changed
+6
+6
View File
@@ -596,6 +596,12 @@ hb_draw_rect (hb_draw_funcs_t *dfuncs, void *draw_data,
if (stroke_width <= 0.f || !std::isfinite (stroke_width))
return;
/* Normalize to non-negative width/height so the stroke math
* below (outer grows by sw, inner shrinks by sw) produces the
* expected outer-contains-inner ring regardless of w/h signs. */
if (w < 0.f) { x += w; w = -w; }
if (h < 0.f) { y += h; h = -h; }
/* w or h == 0 is still meaningful when stroking: a stroked
* zero-height rect is a horizontal line of length w; zero
* width is a vertical line. Both degenerate to a single