public static Rectangle DrawRectangle(this Cairo.Context g, Cairo.Rectangle r, Cairo.Color color, int lineWidth)
{
// Put it on a pixel line
if (lineWidth == 1)
{
r = new Rectangle(r.X - 0.5, r.Y - 0.5, r.Width, r.Height);
}
g.Save();
g.MoveTo(r.X, r.Y);
g.LineTo(r.X + r.Width, r.Y);
g.LineTo(r.X + r.Width, r.Y + r.Height);
g.LineTo(r.X, r.Y + r.Height);
g.LineTo(r.X, r.Y);
g.Color = color;
g.LineWidth = lineWidth;
g.LineCap = LineCap.Square;
Rectangle dirty = g.StrokeExtents();
g.Stroke();
g.Restore();
return(dirty);
}