[cairo] Clipping and stroking
otaylor at redhat.com
Fri Apr 29 16:25:50 PDT 2005
On Sat, 2005-04-30 at 11:14 +1200, Jonathan Roewen wrote:
> I'm having a problem with cairo and clipping. From docs, it says it
> only clips the area equivalent to calling cairo_fill. Wouldn't it be
> better if it were to clip the area equivalent to fill + stroke?
> Whilst for a rectangle, it's not remarkably hard to make a bigger
> rectangle in order to get a clip region that includes the stroke, but
> for arbitrary paths, this isn't so easy.
> While developing my GUI using Cairo, I need to be able to do effective
> clipping in order to minimise screen redraw, but without stroke being
> included in the clip region is making life a bit harder than it should
Clipping to a path is seldom appropriate for doing incremental redraw
because you'll get artifacts at the edges in the partially occupied
pixels at the edges. A clip for partial redraw should almost consist
of a set of pixel-aligned rectangles.
In theory you could imagine Cairo exporting a set of functions:
- Get a device-aligned region surrounding path as stroke
- Get a device-aligned region surrounding path as fill
But computing such regions could be expensive (it's almost as expensive
as rasterizing them) and the resulting regions might be quite complex.
In general, using a bounding rectangle is almost as good, and
Cairo provides functions for that - cairo_stroke_extents(),
To make them usefully pixel aligned and in device coordinates
you want to do something like:
cairo_stroke_extents (cr, &x1, &x2, &y1, &y2);
x1 = floor (x1);
x2 = ceiling (x2);
y1 = floor (y1);
y2 = ceiling (y2);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050429/d7d6407e/attachment.pgp
More information about the cairo