diff --git a/src/hb-draw.cc b/src/hb-draw.cc index 1dc14ba90..c17398e70 100644 --- a/src/hb-draw.cc +++ b/src/hb-draw.cc @@ -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