- /* Cairo goes a little (!) wrong when asked to fill/stroke rectangles that
- * extend way beyond the surface boundaries. To avoid this issue,
- * clamp what we are drawing using the absolute end of the visible
- * canvas, converting to item-space coordinates, of course.
- */
-
- Rect plot = _rect;
- Rect visible = _canvas->visible_area();
- Duple visible_end = canvas_to_item (Duple (visible.x1, visible.y1));
-
- plot.x1 = min (plot.x1, visible_end.x);
- plot.y1 = min (plot.y1, visible_end.y);
-
- if (_fill) {
- setup_fill_context (context);
- context->rectangle (plot.x0, plot.y0, plot.width(), plot.height());
-
- if (!_outline) {
- context->fill ();
+ /* In general, a Rectangle will have a _position of (0,0) within its
+ parent, and its extent is actually defined by _rect. But in the
+ unusual case that _position is set to something other than (0,0),
+ we should take that into account when rendering.
+ */
+ Rect self = item_to_window (_rect.translate (_position));
+ boost::optional<Rect> r = self.intersection (area);
+
+ if (!r) {
+ return;
+ }
+
+ Rect draw = r.get ();
+
+ if (_fill && !_transparent) {
+ if (_stops.empty()) {
+ setup_fill_context (context);