[cairo] [RFC] cairo_path_extents()

Baz brian.ewins at gmail.com
Fri Nov 16 08:48:39 PST 2007

I've been asked to look into this bug:

The problem is moz-svg wants the extents of a path ignoring the stroke
width - this was discussed here a while back:

fill_extents doesn't always work to get the measurement they want,
since it returns inked extents, which are degenerate for a straight
line; the stroke_extents take account of the stroke width, and are
also degenerate when the stroke width is 0. Fill_extents also
tesselates the path unnecessarily.

Behdad suggested adding a cairo_path_extents() call to meet their
need; to me this sounds like a better option than special-casing
stroke_extents or fill_extents for hairlines. The proposed api is:

void        cairo_path_extents (cairo_t *cr,
                                             double *x1,
                                             double *y1,
                                             double *x2,
                                             double *y2);

"Computes a bounding box in user coordinates covering the all points
on the current path. If the current path is empty, returns an empty
rectangle (0,0, 0,0). Stroke parameters, surface dimensions and
clipping are not taken into account."

The implementation of this looks quite easy, following Carl's
suggestion in the bug report, I've thrown together a
_cairo_path_fixed_interpret_flat() that takes a tolerance instead of a
curve_to (not even tried to compile this yet):
http://paste.lisp.org/display/50946 (flattening code lifted from
cairo-path.c; this fits into cairo-path-fixed.c). Combined with
cairo-path-bounds.c, this gives us the desired extents without



More information about the cairo mailing list