[cairo-commit] src/cairo.h src/cairo-path.c

Behdad Esfahbod behdad at kemper.freedesktop.org
Mon Mar 5 14:11:43 PST 2007


 src/cairo-path.c |    8 ++++----
 src/cairo.h      |   11 +++++++++--
 2 files changed, 13 insertions(+), 6 deletions(-)

New commits:
diff-tree d25548d679b8a7fce12c9a55e728539e408c75a1 (from 3ab9ca54aa490438dbbfae7b5f1cde0bd98352cd)
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Mar 5 17:11:39 2007 -0500

    In cairo_append_path(), allow excess path_data elements

diff --git a/src/cairo-path.c b/src/cairo-path.c
index 544abf3..7c2374c 100644
--- a/src/cairo-path.c
+++ b/src/cairo-path.c
@@ -465,19 +465,19 @@ _cairo_path_append_to_context (const cai
 	p = &path->data[i];
 	switch (p->header.type) {
 	case CAIRO_PATH_MOVE_TO:
-	    if (p->header.length != 2)
+	    if (p->header.length < 2)
 		return CAIRO_STATUS_INVALID_PATH_DATA;
 	    cairo_move_to (cr,
 			   p[1].point.x, p[1].point.y);
 	    break;
 	case CAIRO_PATH_LINE_TO:
-	    if (p->header.length != 2)
+	    if (p->header.length < 2)
 		return CAIRO_STATUS_INVALID_PATH_DATA;
 	    cairo_line_to (cr,
 			   p[1].point.x, p[1].point.y);
 	    break;
 	case CAIRO_PATH_CURVE_TO:
-	    if (p->header.length != 4)
+	    if (p->header.length < 4)
 		return CAIRO_STATUS_INVALID_PATH_DATA;
 	    cairo_curve_to (cr,
 			    p[1].point.x, p[1].point.y,
@@ -485,7 +485,7 @@ _cairo_path_append_to_context (const cai
 			    p[3].point.x, p[3].point.y);
 	    break;
 	case CAIRO_PATH_CLOSE_PATH:
-	    if (p->header.length != 1)
+	    if (p->header.length < 1)
 		return CAIRO_STATUS_INVALID_PATH_DATA;
 	    cairo_close_path (cr);
 	    break;
diff --git a/src/cairo.h b/src/cairo.h
index a74871d..cdb9a02 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -1289,8 +1289,7 @@ typedef enum _cairo_path_data_type {
  * the array, (one header followed by 0 or more points). The length
  * value of the header is the number of array elements for the current
  * portion including the header, (ie. length == 1 + # of points), and
- * where the number of points for each element type must be as
- * follows:
+ * where the number of points for each element type is as follows:
  *
  * <programlisting>
  *     %CAIRO_PATH_MOVE_TO:     1 point
@@ -1333,6 +1332,14 @@ typedef enum _cairo_path_data_type {
  *      }
  *      cairo_path_destroy (path);
  * </programlisting></informalexample>
+ *
+ * Cairo does not mind if there are more elements in a portion
+ * of the path than needed.  Such elements can be used by users of
+ * the cairo API to hold extra values in the path data structure.
+ * For this reason, it is recommended that applications always use
+ * <literal>data->header.length</literal> to advance iterate over
+ * the path data, instead of hardcoding the number of elements for
+ * each element type.
  **/
 typedef union _cairo_path_data_t cairo_path_data_t;
 union _cairo_path_data_t {


More information about the cairo-commit mailing list