[PATCH] Fix cairo_path_extents to ignore lone cairo_move_to points.

Carl Worth cworth at cworth.org
Mon Jan 21 13:47:05 PST 2008


Update the documentation as well.
---
 src/cairo-path-bounds.c |   11 ++++++++++-
 src/cairo.c             |   40 +++++++++++++++++++++++++---------------
 2 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/src/cairo-path-bounds.c b/src/cairo-path-bounds.c
index f996977..b945c40 100644
--- a/src/cairo-path-bounds.c
+++ b/src/cairo-path-bounds.c
@@ -37,6 +37,8 @@
 #include "cairoint.h"

 typedef struct cairo_path_bounder {
+    cairo_point_t trailing_move_to_point;
+    int has_trailing_move_to;
     int has_point;

     cairo_fixed_t min_x;
@@ -105,7 +107,8 @@ _cairo_path_bounder_move_to (void *closure, cairo_point_t *point)
 {
     cairo_path_bounder_t *bounder = closure;

-    _cairo_path_bounder_add_point (bounder, point);
+    bounder->trailing_move_to_point = *point;
+    bounder->has_trailing_move_to = 1;

     return CAIRO_STATUS_SUCCESS;
 }
@@ -115,6 +118,12 @@ _cairo_path_bounder_line_to (void *closure, cairo_point_t *point)
 {
     cairo_path_bounder_t *bounder = closure;

+    if (bounder->has_trailing_move_to) {
+	_cairo_path_bounder_add_point (bounder,
+				       &bounder->trailing_move_to_point);
+	bounder->has_trailing_move_to = 0;
+    }
+
     _cairo_path_bounder_add_point (bounder, point);

     return CAIRO_STATUS_SUCCESS;
diff --git a/src/cairo.c b/src/cairo.c
index 9e71c81..f5b92a7 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -1877,16 +1877,26 @@ slim_hidden_def(cairo_close_path);
  * @x2: right of the resulting extents
  * @y2: bottom of the resulting extents
  *
- * Computes a bounding box in user coordinates covering the 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.
+ * Computes a bounding box in user-space coordinates covering the
+ * 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.
  *
  * Contrast with cairo_fill_extents() and cairo_stroke_extents() which
- * return the extents of the area that would be "inked" by drawing
- * operations.  The results of cairo_path_extent() and
- * cairo_fill_extents() are identical unless there are one or more
- * sub-paths with zero area.
+ * return the extents of only the area that would be "inked" by
+ * the corresponding drawing operations.
+ *
+ * The result of cairo_path_extents() is defined as equivalent to the
+ * limit of cairo_stroke_extents() as the line width approaches 0.0,
+ * (but never reaching the empty-rectangle returned by
+ * cairo_stroke_extents() for a line width of 0.0).
+ *
+ * Specifically, this means that zero-area sub-paths such as
+ * cairo_move_to();cairo_line_to() segments, (even degenerate cases
+ * where the coordinates to both calls are identical), will be
+ * considered as contributing to the extents. However, a lone
+ * cairo_move_to() will not contribute to the results of
+ * cairo_path_extents().
  *
  * Since: 1.6
  **/
@@ -2273,8 +2283,8 @@ cairo_in_fill (cairo_t *cr, double x, double y)
  * would be affected, (the "inked" area), by a cairo_stroke()
  * operation operation given the current path and stroke
  * parameters. If the current path is empty, returns an empty
- * rectangle (0,0, 0,0). Surface dimensions and clipping are not taken
- * into account.
+ * rectangle ((0,0), (0,0)). Surface dimensions and clipping are not
+ * taken into account.
  *
  * Note that if the line width is set to exactly zero, then
  * cairo_stroke_extents will return an empty rectangle. Contrast with
@@ -2312,12 +2322,12 @@ cairo_stroke_extents (cairo_t *cr,
  * Computes a bounding box in user coordinates covering the area that
  * would be affected, (the "inked" area), by a cairo_fill() operation
  * given the current path and fill parameters. If the current path is
- * empty, returns an empty rectangle (0,0, 0,0). Surface dimensions
- * and clipping are not taken into account.
+ * empty, returns an empty rectangle ((0,0), (0,0)). Surface
+ * dimensions and clipping are not taken into account.
  *
- * Contrast with cairo_path_extents(), which is similar, but will
- * return non-zero extents for a path with no inked area, (such as a
- * simple line segment).
+ * Contrast with cairo_path_extents(), which is similar, but returns
+ * non-zero extents for some paths no inked area, (such as a simple
+ * line segment).
  *
  * See cairo_fill(), cairo_set_fill_rule() and cairo_fill_preserve().
  **/
--
1.5.2.4


--Multipart_Mon_Jan_21_13:52:31_2008-1--

--pgp-sign-Multipart_Mon_Jan_21_13:52:31_2008-1
Content-Type: application/pgp-signature
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQBHlRQl6JDdNq8qSWgRAlrnAKCCCtNHbX9q4nOsLbuAp7ifs7FxTQCffUi5
wIFQ6L9mU79Ba+64ATD/0EI=
=d+We
-----END PGP SIGNATURE-----

--pgp-sign-Multipart_Mon_Jan_21_13:52:31_2008-1--


More information about the cairo mailing list