summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2005-03-18 14:28:53 +0000
committerCarl Worth <cworth@cworth.org>2005-03-18 14:28:53 +0000
commitc629df861673bd9e60cf7a3babd83f0f5bb257f0 (patch)
tree8effbf0ea8832e0b1ae20d890af77ce508da0474
parent987a13b814d2d84cff719a817f9f73a5b7aa38f2 (diff)
* src/cairo.c: (cairo_copy_path), (cairo_copy_path_flat), (cairo_append_path): Rename cairo_copy_path_data, cairop_copy_path_data_flat, and cairo_append_path_data to cairo_copy_path, cairo_copy_path_flat, and cairo_append_path.
Add new cairo_path_t, containing a cairo_path_data_t array and an explicit length. Remove CAIRO_PATH_END_PATH terminator from cairo_path_data_t. Rename the internal path object from cairo_path_t to cairo_path_real_t.
-rw-r--r--ChangeLog36
-rw-r--r--src/cairo-atsui-font.c4
-rw-r--r--src/cairo-font.c2
-rw-r--r--src/cairo-ft-font.c10
-rw-r--r--src/cairo-gstate.c2
-rw-r--r--src/cairo-path-bounds.c4
-rw-r--r--src/cairo-path-data-private.h10
-rw-r--r--src/cairo-path-data.c65
-rw-r--r--src/cairo-path-fill.c4
-rw-r--r--src/cairo-path-stroke.c4
-rw-r--r--src/cairo-path.c62
-rw-r--r--src/cairo.c56
-rw-r--r--src/cairo.h74
-rw-r--r--src/cairo_atsui_font.c4
-rw-r--r--src/cairo_font.c2
-rw-r--r--src/cairo_ft_font.c10
-rw-r--r--src/cairo_gstate.c2
-rw-r--r--src/cairo_path.c62
-rw-r--r--src/cairo_path_bounds.c4
-rw-r--r--src/cairo_path_data.c65
-rw-r--r--src/cairo_path_fill.c4
-rw-r--r--src/cairo_path_stroke.c4
-rw-r--r--src/cairoint.h64
-rw-r--r--test/path-data.c60
-rw-r--r--test/path_data.c60
25 files changed, 402 insertions, 272 deletions
diff --git a/ChangeLog b/ChangeLog
index eca1f799..827ccfe6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,39 @@
+2005-03-18 Carl Worth <cworth@cworth.org>
+
+ * src/cairo-path-data-private.h: * src/cairo.c: (cairo_copy_path),
+ (cairo_copy_path_flat),
+ (cairo_append_path): Rename cairo_copy_path_data,
+ cairop_copy_path_data_flat, and cairo_append_path_data to
+ cairo_copy_path, cairo_copy_path_flat, and cairo_append_path.
+
+ * src/cairo.h: Add new cairo_path_t, containing a
+ cairo_path_data_t array and an explicit length. Remove
+ CAIRO_PATH_END_PATH terminator from cairo_path_data_t.
+
+ * src/cairo_atsui_font.c: (_cairo_atsui_font_glyph_path):
+ * src/cairo_font.c: (_cairo_font_glyph_path):
+ * src/cairo_ft_font.c: (_move_to), (_line_to), (_conic_to),
+ (_cubic_to), (_cairo_ft_font_glyph_path):
+ * src/cairo_gstate.c: (_cairo_gstate_interpret_path):
+ * src/cairo_path.c: (_cairo_path_init), (_cairo_path_init_copy),
+ (_cairo_path_fini), (_cairo_path_move_to),
+ (_cairo_path_rel_move_to), (_cairo_path_line_to),
+ (_cairo_path_rel_line_to), (_cairo_path_curve_to),
+ (_cairo_path_rel_curve_to), (_cairo_path_close_path),
+ (_cairo_path_get_current_point), (_cairo_path_add),
+ (_cairo_path_add_op_buf), (_cairo_path_new_op_buf),
+ (_cairo_path_add_arg_buf), (_cairo_path_new_arg_buf),
+ (_cairo_path_interpret):
+ * src/cairo_path_bounds.c: (_cairo_path_bounds):
+ * src/cairo_path_data.c: (_cairo_path_data_count),
+ (_cairo_path_data_populate), (_cairo_path_data_create_real),
+ (cairo_path_destroy), (_cairo_path_data_append_to_context):
+ * src/cairo_path_fill.c: (_cairo_path_fill_to_traps):
+ * src/cairo_path_stroke.c: (_cairo_path_stroke_to_traps):
+ * src/cairoint.h:
+ * test/path_data.c: (munge_and_set_path), (draw), (main): Rename
+ the internal path object from cairo_path_t to cairo_path_real_t.
+
2005-03-18 Kristian Høgsberg <krh@redhat.com>
* src/cairo_pdf_surface.c (cairo_set_target_pdf_as_file)
diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c
index cb4b1c5d..d17084e0 100644
--- a/src/cairo-atsui-font.c
+++ b/src/cairo-atsui-font.c
@@ -58,7 +58,7 @@ typedef struct {
typedef struct cairo_ATSUI_glyph_path_callback_info_t {
- cairo_path_t *path;
+ cairo_path_real_t *path;
cairo_matrix_t scale;
} cairo_ATSUI_glyph_path_callback_info_t;
@@ -676,7 +676,7 @@ _cairo_atsui_font_glyph_path( void *abstract_font,
cairo_font_scale_t *sc,
cairo_glyph_t *glyphs,
int num_glyphs,
- cairo_path_t *path)
+ cairo_path_real_t *path)
{
int i;
cairo_atsui_font_t *font = abstract_font;
diff --git a/src/cairo-font.c b/src/cairo-font.c
index f168e6f2..03699af4 100644
--- a/src/cairo-font.c
+++ b/src/cairo-font.c
@@ -137,7 +137,7 @@ cairo_status_t
_cairo_font_glyph_path (cairo_font_t *font,
cairo_glyph_t *glyphs,
int num_glyphs,
- cairo_path_t *path)
+ cairo_path_real_t *path)
{
return font->backend->glyph_path (font, glyphs, num_glyphs, path);
}
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 4a07fcdb..7036f26a 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -1054,7 +1054,7 @@ _cairo_ft_font_show_glyphs (void *abstract_font,
static int
_move_to (FT_Vector *to, void *closure)
{
- cairo_path_t *path = closure;
+ cairo_path_real_t *path = closure;
cairo_point_t point;
point.x = _cairo_fixed_from_26_6 (to->x);
@@ -1069,7 +1069,7 @@ _move_to (FT_Vector *to, void *closure)
static int
_line_to (FT_Vector *to, void *closure)
{
- cairo_path_t *path = closure;
+ cairo_path_real_t *path = closure;
cairo_point_t point;
point.x = _cairo_fixed_from_26_6 (to->x);
@@ -1083,7 +1083,7 @@ _line_to (FT_Vector *to, void *closure)
static int
_conic_to (FT_Vector *control, FT_Vector *to, void *closure)
{
- cairo_path_t *path = closure;
+ cairo_path_real_t *path = closure;
cairo_point_t p0, p1, p2, p3;
cairo_point_t conic;
@@ -1111,7 +1111,7 @@ _conic_to (FT_Vector *control, FT_Vector *to, void *closure)
static int
_cubic_to (FT_Vector *control1, FT_Vector *control2, FT_Vector *to, void *closure)
{
- cairo_path_t *path = closure;
+ cairo_path_real_t *path = closure;
cairo_point_t p0, p1, p2;
p0.x = _cairo_fixed_from_26_6 (control1->x);
@@ -1132,7 +1132,7 @@ static cairo_status_t
_cairo_ft_font_glyph_path (void *abstract_font,
cairo_glyph_t *glyphs,
int num_glyphs,
- cairo_path_t *path)
+ cairo_path_real_t *path)
{
int i;
cairo_ft_font_t *font = abstract_font;
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index 6cb6757f..ba3f8496 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -1301,7 +1301,7 @@ _cairo_gstate_interpret_path (cairo_gstate_t *gstate,
cairo_close_path_func_t *close_path,
void *closure)
{
- cairo_path_t path;
+ cairo_path_real_t path;
gpi_t gpi;
/* Anything we want from gstate must be copied. We must not retain
diff --git a/src/cairo-path-bounds.c b/src/cairo-path-bounds.c
index 7c5772a8..63b3d7a4 100644
--- a/src/cairo-path-bounds.c
+++ b/src/cairo-path-bounds.c
@@ -151,7 +151,9 @@ _cairo_path_bounder_close_path (void *closure)
/* XXX: Perhaps this should compute a PixRegion rather than 4 doubles */
cairo_status_t
-_cairo_path_bounds (cairo_path_t *path, double *x1, double *y1, double *x2, double *y2)
+_cairo_path_bounds (cairo_path_real_t *path,
+ double *x1, double *y1,
+ double *x2, double *y2)
{
cairo_status_t status;
diff --git a/src/cairo-path-data-private.h b/src/cairo-path-data-private.h
index 5cce71d2..882be5c4 100644
--- a/src/cairo-path-data-private.h
+++ b/src/cairo-path-data-private.h
@@ -38,19 +38,19 @@
#include "cairoint.h"
-extern cairo_path_data_t _cairo_path_data_nil;
+extern cairo_path_t _cairo_path_nil;
CAIRO_BEGIN_DECLS
-cairo_path_data_t *
+cairo_path_t *
_cairo_path_data_create (cairo_gstate_t *gstate);
-cairo_path_data_t *
+cairo_path_t *
_cairo_path_data_create_flat (cairo_gstate_t *gstate);
cairo_status_t
-_cairo_path_data_append_to_context (cairo_path_data_t *path_data,
- cairo_t *cr);
+_cairo_path_data_append_to_context (cairo_path_t *path,
+ cairo_t *cr);
CAIRO_END_DECLS
diff --git a/src/cairo-path-data.c b/src/cairo-path-data.c
index 62d6ef05..84d26554 100644
--- a/src/cairo-path-data.c
+++ b/src/cairo-path-data.c
@@ -35,8 +35,8 @@
#include "cairo-path-data-private.h"
-cairo_path_data_t
-_cairo_path_data_nil = { {0} };
+cairo_path_t
+_cairo_path_nil = { NULL, 0 };
/* Closure for path interpretation. */
typedef struct cairo_path_data_count {
@@ -92,9 +92,6 @@ _cairo_path_data_count (cairo_gstate_t *gstate, cairo_bool_t flatten)
_cpdc_close_path,
&cpdc);
- /* Add 1 for the final CAIRO_PATH_END */
- cpdc.count++;
-
return cpdc.count;
}
@@ -173,14 +170,13 @@ _cpdp_close_path (void *closure)
}
static void
-_cairo_path_data_populate (cairo_path_data_t *data,
- int count,
- cairo_gstate_t *gstate,
- cairo_bool_t flatten)
+_cairo_path_data_populate (cairo_path_t *path,
+ cairo_gstate_t *gstate,
+ cairo_bool_t flatten)
{
cpdp_t cpdp;
- cpdp.data = data;
+ cpdp.data = path->data;
_cairo_gstate_interpret_path (gstate,
_cpdp_move_to,
@@ -189,50 +185,61 @@ _cairo_path_data_populate (cairo_path_data_t *data,
_cpdp_close_path,
&cpdp);
- cpdp.data->header.type = CAIRO_PATH_END;
- cpdp.data->header.length = 0;
- cpdp.data++;
-
/* Sanity check the count */
- assert (cpdp.data - data == count);
+ assert (cpdp.data - path->data == path->num_data);
}
-static cairo_path_data_t *
+static cairo_path_t *
_cairo_path_data_create_real (cairo_gstate_t *gstate, cairo_bool_t flatten)
{
- int count;
- cairo_path_data_t *data;
+ cairo_path_t *path;
- count = _cairo_path_data_count (gstate, flatten);
+ path = malloc (sizeof (cairo_path_t));
+ if (path == NULL)
+ return &_cairo_path_nil;
- data = malloc (count * sizeof (cairo_path_data_t));
- if (data == NULL)
- return &_cairo_path_data_nil;
+ path->num_data = _cairo_path_data_count (gstate, flatten);
- _cairo_path_data_populate (data, count, gstate, flatten);
+ path->data = malloc (path->num_data * sizeof (cairo_path_data_t));
+ if (path->data == NULL) {
+ free (path);
+ return &_cairo_path_nil;
+ }
- return data;
+ _cairo_path_data_populate (path, gstate, flatten);
+
+ return path;
+}
+
+void
+cairo_path_destroy (cairo_path_t *path)
+{
+ free (path->data);
+ path->num_data = 0;
+ free (path);
}
-cairo_path_data_t *
+cairo_path_t *
_cairo_path_data_create (cairo_gstate_t *gstate)
{
return _cairo_path_data_create_real (gstate, FALSE);
}
-cairo_path_data_t *
+cairo_path_t *
_cairo_path_data_create_flat (cairo_gstate_t *gstate)
{
return _cairo_path_data_create_real (gstate, TRUE);
}
cairo_status_t
-_cairo_path_data_append_to_context (cairo_path_data_t *path_data,
- cairo_t *cr)
+_cairo_path_data_append_to_context (cairo_path_t *path,
+ cairo_t *cr)
{
+ int i;
cairo_path_data_t *p;
- for (p = path_data; p->header.type != CAIRO_PATH_END; p += p->header.length) {
+ for (i=0; i < path->num_data; i += path->data[i].header.length) {
+ p = &path->data[i];
switch (p->header.type) {
case CAIRO_PATH_MOVE_TO:
cairo_move_to (cr,
diff --git a/src/cairo-path-fill.c b/src/cairo-path-fill.c
index dc79b6b9..26a5af63 100644
--- a/src/cairo-path-fill.c
+++ b/src/cairo-path-fill.c
@@ -171,7 +171,9 @@ _cairo_filler_close_path (void *closure)
}
cairo_status_t
-_cairo_path_fill_to_traps (cairo_path_t *path, cairo_gstate_t *gstate, cairo_traps_t *traps)
+_cairo_path_fill_to_traps (cairo_path_real_t *path,
+ cairo_gstate_t *gstate,
+ cairo_traps_t *traps)
{
cairo_status_t status = CAIRO_STATUS_SUCCESS;
cairo_filler_t filler;
diff --git a/src/cairo-path-stroke.c b/src/cairo-path-stroke.c
index 08b38090..c32ea2b2 100644
--- a/src/cairo-path-stroke.c
+++ b/src/cairo-path-stroke.c
@@ -794,7 +794,9 @@ _cairo_stroker_close_path (void *closure)
}
cairo_status_t
-_cairo_path_stroke_to_traps (cairo_path_t *path, cairo_gstate_t *gstate, cairo_traps_t *traps)
+_cairo_path_stroke_to_traps (cairo_path_real_t *path,
+ cairo_gstate_t *gstate,
+ cairo_traps_t *traps)
{
cairo_status_t status = CAIRO_STATUS_SUCCESS;
cairo_stroker_t stroker;
diff --git a/src/cairo-path.c b/src/cairo-path.c
index 437641ad..89cfcfe6 100644
--- a/src/cairo-path.c
+++ b/src/cairo-path.c
@@ -39,19 +39,22 @@
/* private functions */
static cairo_status_t
-_cairo_path_add (cairo_path_t *path, cairo_path_op_t op, cairo_point_t *points, int num_pts);
+_cairo_path_add (cairo_path_real_t *path,
+ cairo_path_op_t op,
+ cairo_point_t *points,
+ int num_points);
static void
-_cairo_path_add_op_buf (cairo_path_t *path, cairo_path_op_buf_t *op);
+_cairo_path_add_op_buf (cairo_path_real_t *path, cairo_path_op_buf_t *op);
static cairo_status_t
-_cairo_path_new_op_buf (cairo_path_t *path);
+_cairo_path_new_op_buf (cairo_path_real_t *path);
static void
-_cairo_path_add_arg_buf (cairo_path_t *path, cairo_path_arg_buf_t *arg);
+_cairo_path_add_arg_buf (cairo_path_real_t *path, cairo_path_arg_buf_t *arg);
static cairo_status_t
-_cairo_path_new_arg_buf (cairo_path_t *path);
+_cairo_path_new_arg_buf (cairo_path_real_t *path);
static cairo_path_op_buf_t *
_cairo_path_op_buf_create (void);
@@ -69,10 +72,12 @@ static void
_cairo_path_arg_buf_destroy (cairo_path_arg_buf_t *buf);
static void
-_cairo_path_arg_buf_add (cairo_path_arg_buf_t *arg, cairo_point_t *points, int num_points);
+_cairo_path_arg_buf_add (cairo_path_arg_buf_t *arg,
+ cairo_point_t *points,
+ int num_points);
void
-_cairo_path_init (cairo_path_t *path)
+_cairo_path_init (cairo_path_real_t *path)
{
path->op_head = NULL;
path->op_tail = NULL;
@@ -87,7 +92,7 @@ _cairo_path_init (cairo_path_t *path)
}
cairo_status_t
-_cairo_path_init_copy (cairo_path_t *path, cairo_path_t *other)
+_cairo_path_init_copy (cairo_path_real_t *path, cairo_path_real_t *other)
{
cairo_path_op_buf_t *op, *other_op;
cairo_path_arg_buf_t *arg, *other_arg;
@@ -121,7 +126,7 @@ _cairo_path_init_copy (cairo_path_t *path, cairo_path_t *other)
}
void
-_cairo_path_fini (cairo_path_t *path)
+_cairo_path_fini (cairo_path_real_t *path)
{
cairo_path_op_buf_t *op;
cairo_path_arg_buf_t *arg;
@@ -144,7 +149,7 @@ _cairo_path_fini (cairo_path_t *path)
}
cairo_status_t
-_cairo_path_move_to (cairo_path_t *path, cairo_point_t *point)
+_cairo_path_move_to (cairo_path_real_t *path, cairo_point_t *point)
{
cairo_status_t status;
@@ -160,7 +165,7 @@ _cairo_path_move_to (cairo_path_t *path, cairo_point_t *point)
}
cairo_status_t
-_cairo_path_rel_move_to (cairo_path_t *path, cairo_distance_t *distance)
+_cairo_path_rel_move_to (cairo_path_real_t *path, cairo_distance_t *distance)
{
cairo_point_t point;
@@ -171,7 +176,7 @@ _cairo_path_rel_move_to (cairo_path_t *path, cairo_distance_t *distance)
}
cairo_status_t
-_cairo_path_line_to (cairo_path_t *path, cairo_point_t *point)
+_cairo_path_line_to (cairo_path_real_t *path, cairo_point_t *point)
{
cairo_status_t status;
@@ -186,7 +191,7 @@ _cairo_path_line_to (cairo_path_t *path, cairo_point_t *point)
}
cairo_status_t
-_cairo_path_rel_line_to (cairo_path_t *path, cairo_distance_t *distance)
+_cairo_path_rel_line_to (cairo_path_real_t *path, cairo_distance_t *distance)
{
cairo_point_t point;
@@ -197,7 +202,7 @@ _cairo_path_rel_line_to (cairo_path_t *path, cairo_distance_t *distance)
}
cairo_status_t
-_cairo_path_curve_to (cairo_path_t *path,
+_cairo_path_curve_to (cairo_path_real_t *path,
cairo_point_t *p0,
cairo_point_t *p1,
cairo_point_t *p2)
@@ -220,10 +225,10 @@ _cairo_path_curve_to (cairo_path_t *path,
}
cairo_status_t
-_cairo_path_rel_curve_to (cairo_path_t *path,
- cairo_distance_t *d0,
- cairo_distance_t *d1,
- cairo_distance_t *d2)
+_cairo_path_rel_curve_to (cairo_path_real_t *path,
+ cairo_distance_t *d0,
+ cairo_distance_t *d1,
+ cairo_distance_t *d2)
{
cairo_point_t p0, p1, p2;
@@ -240,7 +245,7 @@ _cairo_path_rel_curve_to (cairo_path_t *path,
}
cairo_status_t
-_cairo_path_close_path (cairo_path_t *path)
+_cairo_path_close_path (cairo_path_real_t *path)
{
cairo_status_t status;
@@ -256,7 +261,7 @@ _cairo_path_close_path (cairo_path_t *path)
}
cairo_status_t
-_cairo_path_get_current_point (cairo_path_t *path, cairo_point_t *point)
+_cairo_path_get_current_point (cairo_path_real_t *path, cairo_point_t *point)
{
if (! path->has_current_point)
return CAIRO_STATUS_NO_CURRENT_POINT;
@@ -267,7 +272,10 @@ _cairo_path_get_current_point (cairo_path_t *path, cairo_point_t *point)
}
static cairo_status_t
-_cairo_path_add (cairo_path_t *path, cairo_path_op_t op, cairo_point_t *points, int num_points)
+_cairo_path_add (cairo_path_real_t *path,
+ cairo_path_op_t op,
+ cairo_point_t *points,
+ int num_points)
{
cairo_status_t status;
@@ -289,7 +297,7 @@ _cairo_path_add (cairo_path_t *path, cairo_path_op_t op, cairo_point_t *points,
}
static void
-_cairo_path_add_op_buf (cairo_path_t *path, cairo_path_op_buf_t *op)
+_cairo_path_add_op_buf (cairo_path_real_t *path, cairo_path_op_buf_t *op)
{
op->next = NULL;
op->prev = path->op_tail;
@@ -304,7 +312,7 @@ _cairo_path_add_op_buf (cairo_path_t *path, cairo_path_op_buf_t *op)
}
static cairo_status_t
-_cairo_path_new_op_buf (cairo_path_t *path)
+_cairo_path_new_op_buf (cairo_path_real_t *path)
{
cairo_path_op_buf_t *op;
@@ -318,7 +326,7 @@ _cairo_path_new_op_buf (cairo_path_t *path)
}
static void
-_cairo_path_add_arg_buf (cairo_path_t *path, cairo_path_arg_buf_t *arg)
+_cairo_path_add_arg_buf (cairo_path_real_t *path, cairo_path_arg_buf_t *arg)
{
arg->next = NULL;
arg->prev = path->arg_tail;
@@ -333,7 +341,7 @@ _cairo_path_add_arg_buf (cairo_path_t *path, cairo_path_arg_buf_t *arg)
}
static cairo_status_t
-_cairo_path_new_arg_buf (cairo_path_t *path)
+_cairo_path_new_arg_buf (cairo_path_real_t *path)
{
cairo_path_arg_buf_t *arg;
@@ -416,8 +424,8 @@ static int const num_args[] =
};
cairo_status_t
-_cairo_path_interpret (cairo_path_t *path,
- cairo_direction_t dir,
+_cairo_path_interpret (cairo_path_real_t *path,
+ cairo_direction_t dir,
cairo_path_move_to_func_t *move_to,
cairo_path_line_to_func_t *line_to,
cairo_path_curve_to_func_t *curve_to,
diff --git a/src/cairo.c b/src/cairo.c
index d4e2d2d6..ed913c8f 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -1708,83 +1708,83 @@ cairo_get_path_flat (cairo_t *cr,
DEPRECATE (cairo_current_path_flat, cairo_get_path_flat);
/**
- * cairo_copy_path_data:
+ * cairo_copy_path:
* @cr: a cairo context
*
- * Creates a copy of the current path and returns it to the user as an
- * array of #cairo_path_data_t. See #cairo_path_data_t for hints on
- * how to iterate over the returned data structure.
+ * Creates a copy of the current path and returns it to the user as a
+ * #cairo_path_t. See #cairo_path_data_t for hints on how to iterate
+ * over the returned data structure.
*
- * Return value: the copy of the current path. The caller is
- * responsible for the returned memory and should free() it when
- * finished.
+ * Return value: the copy of the current path. The caller owns the
+ * returned object and should call cairo_path_destroy() when finished
+ * with it.
**/
-cairo_path_data_t *
-cairo_copy_path_data (cairo_t *cr)
+cairo_path_t *
+cairo_copy_path (cairo_t *cr)
{
CAIRO_CHECK_SANITY (cr);
if (cr->status)
- return &_cairo_path_data_nil;
+ return &_cairo_path_nil;
return _cairo_path_data_create (cr->gstate);
}
/**
- * cairo_copy_path_data_flat:
+ * cairo_copy_path_flat:
* @cr: a cairo context
*
* Gets a flattened copy of the current path and returns it to the
- * user an an array of #cairo_path_data_t. See #cairo_path_data_t for hints on
+ * user as a #cairo_path_t. See #cairo_path_data_t for hints on
* how to iterate over the returned data structure.
*
- * This function is like cairo_copy_path_data() except that any curves
+ * This function is like cairo_copy_path() except that any curves
* in the path will be approximated with piecewise-linear
* approximations, (accurate to within the current tolerance
* value). That is, the result is guaranteed to not have any elements
* of type CAIRO_PATH_CURVE_TO which will instead be replaced by a
* series of CAIRO_PATH_LINE_TO elements.
*
- * Return value: the copy of the current path. The caller is
- * responsible for the returned memory and should free() it when
- * finished.
+ * Return value: the copy of the current path. The caller owns the
+ * returned object and should call cairo_path_destroy() when finished
+ * with it.
**/
-cairo_path_data_t *
-cairo_copy_path_data_flat (cairo_t *cr)
+cairo_path_t *
+cairo_copy_path_flat (cairo_t *cr)
{
CAIRO_CHECK_SANITY (cr);
if (cr->status)
- return &_cairo_path_data_nil;
+ return &_cairo_path_nil;
return _cairo_path_data_create_flat (cr->gstate);
}
/**
- * cairo_append_path_data:
+ * cairo_append_path:
* @cr: a cairo context
- * @path_data: path data to be appended
+ * @path: path to be appended
*
- * Append the @path_data onto the current path. See #cairo_path_data_t
- * for details on how the path data array must be initialized.
+ * Append the @path onto the current path. See #cairo_path_t
+ * for details on how the path data structure must be initialized.
**/
void
-cairo_append_path_data (cairo_t *cr,
- cairo_path_data_t *path_data)
+cairo_append_path (cairo_t *cr,
+ cairo_path_t *path)
{
CAIRO_CHECK_SANITY (cr);
if (cr->status)
return;
- if (!path_data) {
+ if (path == NULL || path->data == NULL) {
cr->status = CAIRO_STATUS_NULL_POINTER;
return;
}
- if (path_data == &_cairo_path_data_nil) {
+ if (path == &_cairo_path_nil) {
cr->status = CAIRO_STATUS_NO_MEMORY;
return;
}
- cr->status = _cairo_path_data_append_to_context (path_data, cr);
+ cr->status = _cairo_path_data_append_to_context (path, cr);
CAIRO_CHECK_SANITY (cr);
}
diff --git a/src/cairo.h b/src/cairo.h
index e67cf88d..d3535f8d 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -703,15 +703,12 @@ cairo_get_path_flat (cairo_t *cr,
/**
* cairo_path_data_t:
*
- * A data structure for holding path data. This data structure is used
- * as the return value for cairo_copy_path_data() and
- * cairo_copy_path_data_flat() as well the input value for
- * cairo_append_path_data().
+ * A data structure for holding path data---appears within
+ * #cairo_path_t.
*
* The data structure is designed to try to balance the demands of
* efficiency and ease-of-use. A path is represented as an array of
- * cairo_path_data_t which is a union of headers and points. The array
- * must be terminated by a header element of type CAIRO_PATH_END_PATH.
+ * cairo_path_data_t which is a union of headers and points.
*
* Each portion of the path is represented by one or more elements in
* the array, (one header followed by 0 or more points). The length
@@ -729,26 +726,28 @@ cairo_get_path_flat (cairo_t *cr,
* with cairo_move_to(), cairo_line_to(), cairo_curve_to(), and
* cairo_close_path().
*
- * Here is sample code for iterating through a cairo_path_data_t
- * array:
+ * Here is sample code for iterating through a #cairo_path_t:
*
* <informalexample><programlisting>
- * cairo_path_data_t *path, *p;
+ * int i;
+ * cairo_path_t *path;
+ * cairo_path_data_t *data;
*
- * path = cairo_copy_path_data (cr);
+ * path = cairo_copy_path (cr);
*
- * for (p = path; p->header.type != CAIRO_PATH_END; p += p->header.length) {
- * switch (p->header.type) {
+ * for (i=0; i < path->num_data; i += path->data[i].header.length) {
+ * data = &path->data[i];
+ * switch (data->header.type) {
* case CAIRO_PATH_MOVE_TO:
- * do_move_to_things (p[1].point.x, p[1].point.y);
+ * do_move_to_things (data[1].point.x, data[1].point.y);
* break;
* case CAIRO_PATH_LINE_TO:
- * do_line_to_things (p[1].point.x, p[1].point.y);
+ * do_line_to_things (data[1].point.x, data[1].point.y);
* break;
* case CAIRO_PATH_CURVE_TO:
- * do_curve_to_things (p[1].point.x, p[1].point.y,
- * p[2].point.x, p[2].point.y,
- * p[3].point.x, p[3].point.y);
+ * do_curve_to_things (data[1].point.x, data[1].point.y,
+ * data[2].point.x, data[2].point.y,
+ * data[3].point.x, data[3].point.y);
* break;
* case CAIRO_PATH_CLOSE_PATH:
* do_close_path_things ();
@@ -756,7 +755,7 @@ cairo_get_path_flat (cairo_t *cr,
* }
* }
*
- * free (path);
+ * cairo_path_destroy (path);
* </programlisting></informalexample>
*/
typedef union {
@@ -765,8 +764,7 @@ typedef union {
CAIRO_PATH_MOVE_TO,
CAIRO_PATH_LINE_TO,
CAIRO_PATH_CURVE_TO,
- CAIRO_PATH_CLOSE_PATH,
- CAIRO_PATH_END
+ CAIRO_PATH_CLOSE_PATH
} type;
int length;
} header;
@@ -775,15 +773,39 @@ typedef union {
} point;
} cairo_path_data_t;
-cairo_path_data_t *
-cairo_copy_path_data (cairo_t *cr);
+/**
+ * cairo_path_t:
+ *
+ * A data structure for holding a path. This data structure serves as
+ * the return value for cairo_copy_path_data() and
+ * cairo_copy_path_data_flat() as well the input value for
+ * cairo_append_path_data().
+ *
+ * See #cairo_path_data_t for hints on how to iterate over the
+ * actual data within the path.
+ *
+ * The num_data member gives the number of elements in the data
+ * array. This number is larger than the number of independent path
+ * portions (MOVE_TO, LINE_TO, CURVE_TO, CLOSE_PATH), since the data
+ * includes both headers and coordinates for each portion.
+ **/
+typedef struct cairo_path {
+ cairo_path_data_t *data;
+ int num_data;
+} cairo_path_t;
+
+cairo_path_t *
+cairo_copy_path (cairo_t *cr);
+
+cairo_path_t *
+cairo_copy_path_flat (cairo_t *cr);
-cairo_path_data_t *
-cairo_copy_path_data_flat (cairo_t *cr);
+void
+cairo_append_path (cairo_t *cr,
+ cairo_path_t *path);
void
-cairo_append_path_data (cairo_t *cr,
- cairo_path_data_t *path_data);
+cairo_path_destroy (cairo_path_t *path);
/* Error status queries */
diff --git a/src/cairo_atsui_font.c b/src/cairo_atsui_font.c
index cb4b1c5d..d17084e0 100644
--- a/src/cairo_atsui_font.c
+++ b/src/cairo_atsui_font.c
@@ -58,7 +58,7 @@ typedef struct {
typedef struct cairo_ATSUI_glyph_path_callback_info_t {
- cairo_path_t *path;
+ cairo_path_real_t *path;
cairo_matrix_t scale;
} cairo_ATSUI_glyph_path_callback_info_t;
@@ -676,7 +676,7 @@ _cairo_atsui_font_glyph_path( void *abstract_font,
cairo_font_scale_t *sc,
cairo_glyph_t *glyphs,
int num_glyphs,
- cairo_path_t *path)
+ cairo_path_real_t *path)
{
int i;
cairo_atsui_font_t *font = abstract_font;
diff --git a/src/cairo_font.c b/src/cairo_font.c
index f168e6f2..03699af4 100644
--- a/src/cairo_font.c
+++ b/src/cairo_font.c
@@ -137,7 +137,7 @@ cairo_status_t
_cairo_font_glyph_path (cairo_font_t *font,
cairo_glyph_t *glyphs,
int num_glyphs,
- cairo_path_t *path)
+ cairo_path_real_t *path)
{
return font->backend->glyph_path (font, glyphs, num_glyphs, path);
}
diff --git a/src/cairo_ft_font.c b/src/cairo_ft_font.c
index 4a07fcdb..7036f26a 100644
--- a/src/cairo_ft_font.c
+++ b/src/cairo_ft_font.c
@@ -1054,7 +1054,7 @@ _cairo_ft_font_show_glyphs (void *abstract_font,
static int
_move_to (FT_Vector *to, void *closure)
{
- cairo_path_t *path = closure;
+ cairo_path_real_t *path = closure;
cairo_point_t point;
point.x = _cairo_fixed_from_26_6 (to->x);
@@ -1069,7 +1069,7 @@ _move_to (FT_Vector *to, void *closure)
static int
_line_to (FT_Vector *to, void *closure)
{
- cairo_path_t *path = closure;
+ cairo_path_real_t *path = closure;
cairo_point_t point;
point.x = _cairo_fixed_from_26_6 (to->x);
@@ -1083,7 +1083,7 @@ _line_to (FT_Vector *to, void *closure)
static int
_conic_to (FT_Vector *control, FT_Vector *to, void *closure)
{
- cairo_path_t *path = closure;
+ cairo_path_real_t *path = closure;
cairo_point_t p0, p1, p2, p3;
cairo_point_t conic;
@@ -1111,7 +1111,7 @@ _conic_to (FT_Vector *control, FT_Vector *to, void *closure)
static int
_cubic_to (FT_Vector *control1, FT_Vector *control2, FT_Vector *to, void *closure)
{
- cairo_path_t *path = closure;
+ cairo_path_real_t *path = closure;
cairo_point_t p0, p1, p2;
p0.x = _cairo_fixed_from_26_6 (control1->x);
@@ -1132,7 +1132,7 @@ static cairo_status_t
_cairo_ft_font_glyph_path (void *abstract_font,
cairo_glyph_t *glyphs,
int num_glyphs,
- cairo_path_t *path)
+ cairo_path_real_t *path)
{
int i;
cairo_ft_font_t *font = abstract_font;
diff --git a/src/cairo_gstate.c b/src/cairo_gstate.c
index 6cb6757f..ba3f8496 100644
--- a/src/cairo_gstate.c
+++ b/src/cairo_gstate.c
@@ -1301,7 +1301,7 @@ _cairo_gstate_interpret_path (cairo_gstate_t *gstate,
cairo_close_path_func_t *close_path,
void *closure)
{
- cairo_path_t path;
+ cairo_path_real_t path;
gpi_t gpi;
/* Anything we want from gstate must be copied. We must not retain
diff --git a/src/cairo_path.c b/src/cairo_path.c
index 437641ad..89cfcfe6 100644
--- a/src/cairo_path.c
+++ b/src/cairo_path.c
@@ -39,19 +39,22 @@
/* private functions */
static cairo_status_t
-_cairo_path_add (cairo_path_t *path, cairo_path_op_t op, cairo_point_t *points, int num_pts);
+_cairo_path_add (cairo_path_real_t *path,
+ cairo_path_op_t op,
+ cairo_point_t *points,
+ int num_points);
static void
-_cairo_path_add_op_buf (cairo_path_t *path, cairo_path_op_buf_t *op);
+_cairo_path_add_op_buf (cairo_path_real_t *path, cairo_path_op_buf_t *op);
static cairo_status_t
-_cairo_path_new_op_buf (cairo_path_t *path);
+_cairo_path_new_op_buf (cairo_path_real_t *path);
static void
-_cairo_path_add_arg_buf (cairo_path_t *path, cairo_path_arg_buf_t *arg);
+_cairo_path_add_arg_buf (cairo_path_real_t *path, cairo_path_arg_buf_t *arg);
static cairo_status_t
-_cairo_path_new_arg_buf (cairo_path_t *path);
+_cairo_path_new_arg_buf (cairo_path_real_t *path);
static cairo_path_op_buf_t *
_cairo_path_op_buf_create (void);
@@ -69,10 +72,12 @@ static void
_cairo_path_arg_buf_destroy (cairo_path_arg_buf_t *buf);
static void
-_cairo_path_arg_buf_add (cairo_path_arg_buf_t *arg, cairo_point_t *points, int num_points);
+_cairo_path_arg_buf_add (cairo_path_arg_buf_t *arg,
+ cairo_point_t *points,
+ int num_points);
void
-_cairo_path_init (cairo_path_t *path)
+_cairo_path_init (cairo_path_real_t *path)
{
path->op_head = NULL;
path->op_tail = NULL;
@@ -87,7 +92,7 @@ _cairo_path_init (cairo_path_t *path)
}
cairo_status_t
-_cairo_path_init_copy (cairo_path_t *path, cairo_path_t *other)
+_cairo_path_init_copy (cairo_path_real_t *path, cairo_path_real_t *other)
{
cairo_path_op_buf_t *op, *other_op;
cairo_path_arg_buf_t *arg, *other_arg;
@@ -121,7 +126,7 @@ _cairo_path_init_copy (cairo_path_t *path, cairo_path_t *other)
}
void
-_cairo_path_fini (cairo_path_t *path)
+_cairo_path_fini (cairo_path_real_t *path)
{
cairo_path_op_buf_t *op;
cairo_path_arg_buf_t *arg;
@@ -144,7 +149,7 @@ _cairo_path_fini (cairo_path_t *path)
}
cairo_status_t
-_cairo_path_move_to (cairo_path_t *path, cairo_point_t *point)
+_cairo_path_move_to (cairo_path_real_t *path, cairo_point_t *point)
{
cairo_status_t status;
@@ -160,7 +165,7 @@ _cairo_path_move_to (cairo_path_t *path, cairo_point_t *point)
}
cairo_status_t
-_cairo_path_rel_move_to (cairo_path_t *path, cairo_distance_t *distance)
+_cairo_path_rel_move_to (cairo_path_real_t *path, cairo_distance_t *distance)
{
cairo_point_t point;
@@ -171,7 +176,7 @@ _cairo_path_rel_move_to (cairo_path_t *path, cairo_distance_t *distance)
}
cairo_status_t
-_cairo_path_line_to (cairo_path_t *path, cairo_point_t *point)
+_cairo_path_line_to (cairo_path_real_t *path, cairo_point_t *point)
{
cairo_status_t status;
@@ -186,7 +191,7 @@ _cairo_path_line_to (cairo_path_t *path, cairo_point_t *point)
}
cairo_status_t
-_cairo_path_rel_line_to (cairo_path_t *path, cairo_distance_t *distance)
+_cairo_path_rel_line_to (cairo_path_real_t *path, cairo_distance_t *distance)
{
cairo_point_t point;
@@ -197,7 +202,7 @@ _cairo_path_rel_line_to (cairo_path_t *path, cairo_distance_t *distance)
}
cairo_status_t
-_cairo_path_curve_to (cairo_path_t *path,
+_cairo_path_curve_to (cairo_path_real_t *path,
cairo_point_t *p0,
cairo_point_t *p1,
cairo_point_t *p2)
@@ -220,10 +225,10 @@ _cairo_path_curve_to (cairo_path_t *path,
}
cairo_status_t
-_cairo_path_rel_curve_to (cairo_path_t *path,
- cairo_distance_t *d0,
- cairo_distance_t *d1,
- cairo_distance_t *d2)
+_cairo_path_rel_curve_to (cairo_path_real_t *path,
+ cairo_distance_t *d0,
+ cairo_distance_t *d1,
+ cairo_distance_t *d2)
{
cairo_point_t p0, p1, p2;
@@ -240,7 +245,7 @@ _cairo_path_rel_curve_to (cairo_path_t *path,
}
cairo_status_t
-_cairo_path_close_path (cairo_path_t *path)
+_cairo_path_close_path (cairo_path_real_t *path)
{
cairo_status_t status;
@@ -256,7 +261,7 @@ _cairo_path_close_path (cairo_path_t *path)
}
cairo_status_t
-_cairo_path_get_current_point (cairo_path_t *path, cairo_point_t *point)
+_cairo_path_get_current_point (cairo_path_real_t *path, cairo_point_t *point)
{
if (! path->has_current_point)
return CAIRO_STATUS_NO_CURRENT_POINT;
@@ -267,7 +272,10 @@ _cairo_path_get_current_point (cairo_path_t *path, cairo_point_t *point)
}
static cairo_status_t
-_cairo_path_add (cairo_path_t *path, cairo_path_op_t op, cairo_point_t *points, int num_points)
+_cairo_path_add (cairo_path_real_t *path,
+ cairo_path_op_t op,
+ cairo_point_t *points,
+ int num_points)
{
cairo_status_t status;
@@ -289,7 +297,7 @@ _cairo_path_add (cairo_path_t *path, cairo_path_op_t op, cairo_point_t *points,
}
static void
-_cairo_path_add_op_buf (cairo_path_t *path, cairo_path_op_buf_t *op)
+_cairo_path_add_op_buf (cairo_path_real_t *path, cairo_path_op_buf_t *op)
{
op->next = NULL;
op->prev = path->op_tail;
@@ -304,7 +312,7 @@ _cairo_path_add_op_buf (cairo_path_t *path, cairo_path_op_buf_t *op)
}
static cairo_status_t
-_cairo_path_new_op_buf (cairo_path_t *path)
+_cairo_path_new_op_buf (cairo_path_real_t *path)
{
cairo_path_op_buf_t *op;
@@ -318,7 +326,7 @@ _cairo_path_new_op_buf (cairo_path_t *path)
}
static void
-_cairo_path_add_arg_buf (cairo_path_t *path, cairo_path_arg_buf_t *arg)
+_cairo_path_add_arg_buf (cairo_path_real_t *path, cairo_path_arg_buf_t *arg)
{
arg->next = NULL;
arg->prev = path->arg_tail;
@@ -333,7 +341,7 @@ _cairo_path_add_arg_buf (cairo_path_t *path, cairo_path_arg_buf_t *arg)
}
static cairo_status_t
-_cairo_path_new_arg_buf (cairo_path_t *path)
+_cairo_path_new_arg_buf (cairo_path_real_t *path)
{
cairo_path_arg_buf_t *arg;
@@ -416,8 +424,8 @@ static int const num_args[] =
};
cairo_status_t
-_cairo_path_interpret (cairo_path_t *path,
- cairo_direction_t dir,
+_cairo_path_interpret (cairo_path_real_t *path,
+ cairo_direction_t dir,
cairo_path_move_to_func_t *move_to,
cairo_path_line_to_func_t *line_to,
cairo_path_curve_to_func_t *curve_to,
diff --git a/src/cairo_path_bounds.c b/src/cairo_path_bounds.c
index 7c5772a8..63b3d7a4 100644
--- a/src/cairo_path_bounds.c
+++ b/src/cairo_path_bounds.c
@@ -151,7 +151,9 @@ _cairo_path_bounder_close_path (void *closure)
/* XXX: Perhaps this should compute a PixRegion rather than 4 doubles */
cairo_status_t
-_cairo_path_bounds (cairo_path_t *path, double *x1, double *y1, double *x2, double *y2)
+_cairo_path_bounds (cairo_path_real_t *path,
+ double *x1, double *y1,
+ double *x2, double *y2)
{
cairo_status_t status;
diff --git a/src/cairo_path_data.c b/src/cairo_path_data.c
index 62d6ef05..84d26554 100644
--- a/src/cairo_path_data.c
+++ b/src/cairo_path_data.c
@@ -35,8 +35,8 @@
#include "cairo-path-data-private.h"
-cairo_path_data_t
-_cairo_path_data_nil = { {0} };
+cairo_path_t
+_cairo_path_nil = { NULL, 0 };
/* Closure for path interpretation. */
typedef struct cairo_path_data_count {
@@ -92,9 +92,6 @@ _cairo_path_data_count (cairo_gstate_t *gstate, cairo_bool_t flatten)
_cpdc_close_path,
&cpdc);
- /* Add 1 for the final CAIRO_PATH_END */
- cpdc.count++;
-
return cpdc.count;
}
@@ -173,14 +170,13 @@ _cpdp_close_path (void *closure)
}
static void
-_cairo_path_data_populate (cairo_path_data_t *data,
- int count,
- cairo_gstate_t *gstate,
- cairo_bool_t flatten)
+_cairo_path_data_populate (cairo_path_t *path,
+ cairo_gstate_t *gstate,
+ cairo_bool_t flatten)
{
cpdp_t cpdp;
- cpdp.data = data;
+ cpdp.data = path->data;
_cairo_gstate_interpret_path (gstate,
_cpdp_move_to,
@@ -189,50 +185,61 @@ _cairo_path_data_populate (cairo_path_data_t *data,
_cpdp_close_path,
&cpdp);
- cpdp.data->header.type = CAIRO_PATH_END;
- cpdp.data->header.length = 0;
- cpdp.data++;
-
/* Sanity check the count */
- assert (cpdp.data - data == count);
+ assert (cpdp.data - path->data == path->num_data);
}
-static cairo_path_data_t *
+static cairo_path_t *
_cairo_path_data_create_real (cairo_gstate_t *gstate, cairo_bool_t flatten)
{
- int count;
- cairo_path_data_t *data;
+ cairo_path_t *path;
- count = _cairo_path_data_count (gstate, flatten);
+ path = malloc (sizeof (cairo_path_t));
+ if (path == NULL)
+ return &_cairo_path_nil;
- data = malloc (count * sizeof (cairo_path_data_t));
- if (data == NULL)
- return &_cairo_path_data_nil;
+ path->num_data = _cairo_path_data_count (gstate, flatten);
- _cairo_path_data_populate (data, count, gstate, flatten);
+ path->data = malloc (path->num_data * sizeof (cairo_path_data_t));
+ if (path->data == NULL) {
+ free (path);
+ return &_cairo_path_nil;
+ }
- return data;
+ _cairo_path_data_populate (path, gstate, flatten);
+
+ return path;
+}
+
+void
+cairo_path_destroy (cairo_path_t *path)
+{
+ free (path->data);
+ path->num_data = 0;
+ free (path);
}
-cairo_path_data_t *
+cairo_path_t *
_cairo_path_data_create (cairo_gstate_t *gstate)
{
return _cairo_path_data_create_real (gstate, FALSE);
}
-cairo_path_data_t *
+cairo_path_t *
_cairo_path_data_create_flat (cairo_gstate_t *gstate)
{
return _cairo_path_data_create_real (gstate, TRUE);
}
cairo_status_t
-_cairo_path_data_append_to_context (cairo_path_data_t *path_data,
- cairo_t *cr)
+_cairo_path_data_append_to_context (cairo_path_t *path,
+ cairo_t *cr)
{
+ int i;
cairo_path_data_t *p;
- for (p = path_data; p->header.type != CAIRO_PATH_END; p += p->header.length) {
+ for (i=0; i < path->num_data; i += path->data[i].header.length) {
+ p = &path->data[i];
switch (p->header.type) {
case CAIRO_PATH_MOVE_TO:
cairo_move_to (cr,
diff --git a/src/cairo_path_fill.c b/src/cairo_path_fill.c
index dc79b6b9..26a5af63 100644
--- a/src/cairo_path_fill.c
+++ b/src/cairo_path_fill.c
@@ -171,7 +171,9 @@ _cairo_filler_close_path (void *closure)
}
cairo_status_t
-_cairo_path_fill_to_traps (cairo_path_t *path, cairo_gstate_t *gstate, cairo_traps_t *traps)
+_cairo_path_fill_to_traps (cairo_path_real_t *path,
+ cairo_gstate_t *gstate,
+ cairo_traps_t *traps)
{
cairo_status_t status = CAIRO_STATUS_SUCCESS;
cairo_filler_t filler;
diff --git a/src/cairo_path_stroke.c b/src/cairo_path_stroke.c
index 08b38090..c32ea2b2 100644
--- a/src/cairo_path_stroke.c
+++ b/src/cairo_path_stroke.c
@@ -794,7 +794,9 @@ _cairo_stroker_close_path (void *closure)
}
cairo_status_t
-_cairo_path_stroke_to_traps (cairo_path_t *path, cairo_gstate_t *gstate, cairo_traps_t *traps)
+_cairo_path_stroke_to_traps (cairo_path_real_t *path,
+ cairo_gstate_t *gstate,
+ cairo_traps_t *traps)
{
cairo_status_t status = CAIRO_STATUS_SUCCESS;
cairo_stroker_t stroker;
diff --git a/src/cairoint.h b/src/cairoint.h
index d6c1b8e7..f8c78216 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -218,7 +218,7 @@ typedef struct _cairo_path {
cairo_point_t last_move_point;
cairo_point_t current_point;
int has_current_point;
-} cairo_path_t;
+} cairo_path_real_t;
typedef struct _cairo_edge {
cairo_line_t edge;
@@ -516,7 +516,7 @@ typedef struct _cairo_font_backend {
cairo_status_t (*glyph_path) (void *font,
cairo_glyph_t *glyphs,
int num_glyphs,
- cairo_path_t *path);
+ cairo_path_real_t *path);
void (*get_glyph_cache_key) (void *font,
cairo_glyph_cache_key_t *key);
@@ -876,7 +876,7 @@ typedef struct _cairo_gstate {
cairo_matrix_t ctm;
cairo_matrix_t ctm_inverse;
- cairo_path_t path;
+ cairo_path_real_t path;
cairo_pen_t pen_regular;
@@ -1313,14 +1313,14 @@ _cairo_font_show_glyphs (cairo_font_t *font,
cairo_private cairo_status_t
_cairo_font_glyph_path (cairo_font_t *font,
cairo_glyph_t *glyphs,
- int num_glyphs,
- cairo_path_t *path);
+ int num_glyphs,
+ cairo_path_real_t *path);
cairo_private cairo_status_t
_cairo_font_glyph_path (cairo_font_t *font,
cairo_glyph_t *glyphs,
- int num_glyphs,
- cairo_path_t *path);
+ int num_glyphs,
+ cairo_path_real_t *path);
cairo_private void
_cairo_font_get_glyph_cache_key (cairo_font_t *font,
@@ -1332,43 +1332,43 @@ _cairo_hull_compute (cairo_pen_vertex_t *vertices, int *num_vertices);
/* cairo_path.c */
cairo_private void
-_cairo_path_init (cairo_path_t *path);
+_cairo_path_init (cairo_path_real_t *path);
cairo_private cairo_status_t
-_cairo_path_init_copy (cairo_path_t *path, cairo_path_t *other);
+_cairo_path_init_copy (cairo_path_real_t *path, cairo_path_real_t *other);
cairo_private void
-_cairo_path_fini (cairo_path_t *path);
+_cairo_path_fini (cairo_path_real_t *path);
cairo_private cairo_status_t
-_cairo_path_move_to (cairo_path_t *path, cairo_point_t *point);
+_cairo_path_move_to (cairo_path_real_t *path, cairo_point_t *point);
cairo_private cairo_status_t
-_cairo_path_rel_move_to (cairo_path_t *path, cairo_slope_t *slope);
+_cairo_path_rel_move_to (cairo_path_real_t *path, cairo_slope_t *slope);
cairo_private cairo_status_t
-_cairo_path_line_to (cairo_path_t *path, cairo_point_t *point);
+_cairo_path_line_to (cairo_path_real_t *path, cairo_point_t *point);
cairo_private cairo_status_t
-_cairo_path_rel_line_to (cairo_path_t *path, cairo_slope_t *slope);
+_cairo_path_rel_line_to (cairo_path_real_t *path, cairo_slope_t *slope);
cairo_private cairo_status_t
-_cairo_path_curve_to (cairo_path_t *path,
- cairo_point_t *p0,
- cairo_point_t *p1,
- cairo_point_t *p2);
+_cairo_path_curve_to (cairo_path_real_t *path,
+ cairo_point_t *p0,
+ cairo_point_t *p1,
+ cairo_point_t *p2);
cairo_private cairo_status_t
-_cairo_path_rel_curve_to (cairo_path_t *path,
- cairo_slope_t *s0,
- cairo_slope_t *s1,
- cairo_slope_t *s2);
+_cairo_path_rel_curve_to (cairo_path_real_t *path,
+ cairo_slope_t *s0,
+ cairo_slope_t *s1,
+ cairo_slope_t *s2);
cairo_private cairo_status_t
-_cairo_path_close_path (cairo_path_t *path);
+_cairo_path_close_path (cairo_path_real_t *path);
cairo_private cairo_status_t
-_cairo_path_get_current_point (cairo_path_t *path, cairo_point_t *point);
+_cairo_path_get_current_point (cairo_path_real_t *path, cairo_point_t *point);
typedef cairo_status_t (cairo_path_move_to_func_t) (void *closure,
cairo_point_t *point);
@@ -1384,8 +1384,8 @@ typedef cairo_status_t (cairo_path_curve_to_func_t) (void *closure,
typedef cairo_status_t (cairo_path_close_path_func_t) (void *closure);
cairo_private cairo_status_t
-_cairo_path_interpret (cairo_path_t *path,
- cairo_direction_t dir,
+_cairo_path_interpret (cairo_path_real_t *path,
+ cairo_direction_t dir,
cairo_path_move_to_func_t *move_to,
cairo_path_line_to_func_t *line_to,
cairo_path_curve_to_func_t *curve_to,
@@ -1393,15 +1393,21 @@ _cairo_path_interpret (cairo_path_t *path,
void *closure);
cairo_private cairo_status_t
-_cairo_path_bounds (cairo_path_t *path, double *x1, double *y1, double *x2, double *y2);
+_cairo_path_bounds (cairo_path_real_t *path,
+ double *x1, double *y1,
+ double *x2, double *y2);
/* cairo_path_fill.c */
cairo_private cairo_status_t
-_cairo_path_fill_to_traps (cairo_path_t *path, cairo_gstate_t *gstate, cairo_traps_t *traps);
+_cairo_path_fill_to_traps (cairo_path_real_t *path,
+ cairo_gstate_t *gstate,
+ cairo_traps_t *traps);
/* cairo_path_stroke.c */
cairo_private cairo_status_t
-_cairo_path_stroke_to_traps (cairo_path_t *path, cairo_gstate_t *gstate, cairo_traps_t *traps);
+_cairo_path_stroke_to_traps (cairo_path_real_t *path,
+ cairo_gstate_t *gstate,
+ cairo_traps_t *traps);
/* cairo_surface.c */
cairo_private cairo_surface_t *
diff --git a/test/path-data.c b/test/path-data.c
index 5c2d68f0..548d205e 100644
--- a/test/path-data.c
+++ b/test/path-data.c
@@ -42,15 +42,16 @@ scale_by_two (double *x, double *y)
typedef void (*munge_func_t) (double *x, double *y);
static void
-munge_and_set_path (cairo_t *cr,
- cairo_path_data_t *path,
- munge_func_t munge)
+munge_and_set_path (cairo_t *cr,
+ cairo_path_t *path,
+ munge_func_t munge)
{
+ int i;
cairo_path_data_t *p;
double x1, y1, x2, y2, x3, y3;
- p = path;
- while (1) {
+ for (i=0; i < path->num_data; i += path->data[i].header.length) {
+ p = &path->data[i];
switch (p->header.type) {
case CAIRO_PATH_MOVE_TO:
x1 = p[1].point.x; y1 = p[1].point.y;
@@ -77,10 +78,7 @@ munge_and_set_path (cairo_t *cr,
case CAIRO_PATH_CLOSE_PATH:
cairo_close_path (cr);
break;
- case CAIRO_PATH_END:
- return;
}
- p += p->header.length;
}
}
@@ -95,42 +93,44 @@ make_path (cairo_t *cr)
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
- cairo_path_data_t *path;
+ cairo_path_t *path;
/* copy path, munge, and fill */
cairo_translate (cr, 5, 5);
make_path (cr);
- path = cairo_copy_path_data (cr);
+ path = cairo_copy_path (cr);
cairo_new_path (cr);
munge_and_set_path (cr, path, scale_by_two);
- free (path);
+ cairo_path_destroy (path);
cairo_fill (cr);
/* copy flattened path, munge, and fill */
cairo_translate (cr, 0, 15);
make_path (cr);
- path = cairo_copy_path_data_flat (cr);
+ path = cairo_copy_path_flat (cr);
cairo_new_path (cr);
munge_and_set_path (cr, path, scale_by_two);
- free (path);
+ cairo_path_destroy (path);
cairo_fill (cr);
/* append two copies of path, and fill */
cairo_translate (cr, 0, 15);
cairo_scale (cr, 2.0, 2.0);
make_path (cr);
- path = cairo_copy_path_data (cr);
+ path = cairo_copy_path (cr);
cairo_new_path (cr);
- cairo_append_path_data (cr, path);
+ cairo_append_path (cr, path);
cairo_translate (cr, 2.5, 2.5);
- cairo_append_path_data (cr, path);
+ cairo_append_path (cr, path);
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
cairo_fill (cr);
+ cairo_path_destroy (path);
+
return CAIRO_TEST_SUCCESS;
}
@@ -138,27 +138,39 @@ int
main (void)
{
cairo_t *cr;
- cairo_path_data_t bogus_path_data;
+ cairo_path_data_t data;
+ cairo_path_t path;
+
+ /* Test a few error cases for cairo_append_path_data */
+ cr = cairo_create ();
+ cairo_append_path (cr, NULL);
+ if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER)
+ return 1;
+ cairo_destroy (cr);
- /* Test a couple error conditions for cairo_append_path_data */
cr = cairo_create ();
- cairo_append_path_data (cr, NULL);
+ path.data = NULL;
+ path.num_data = 0;
+ cairo_append_path (cr, &path);
if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER)
return 1;
cairo_destroy (cr);
cr = cairo_create ();
- bogus_path_data.header.type = CAIRO_PATH_MOVE_TO;
- bogus_path_data.header.length = 1;
- cairo_append_path_data (cr, &bogus_path_data);
+ /* Intentionally insert bogus header.length value (otherwise would be 2) */
+ data.header.type = CAIRO_PATH_MOVE_TO;
+ data.header.length = 1;
+ path.data = &data;
+ path.num_data = 1;
+ cairo_append_path (cr, &path);
if (cairo_status (cr) != CAIRO_STATUS_INVALID_PATH_DATA)
return 1;
cairo_destroy (cr);
/* And test the degnerate case */
cr = cairo_create ();
- bogus_path_data.header.type = CAIRO_PATH_END;
- cairo_append_path_data (cr, &bogus_path_data);
+ path.num_data = 0;
+ cairo_append_path (cr, &path);
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
return 1;
cairo_destroy (cr);
diff --git a/test/path_data.c b/test/path_data.c
index 5c2d68f0..548d205e 100644
--- a/test/path_data.c
+++ b/test/path_data.c
@@ -42,15 +42,16 @@ scale_by_two (double *x, double *y)
typedef void (*munge_func_t) (double *x, double *y);
static void
-munge_and_set_path (cairo_t *cr,
- cairo_path_data_t *path,
- munge_func_t munge)
+munge_and_set_path (cairo_t *cr,
+ cairo_path_t *path,
+ munge_func_t munge)
{
+ int i;
cairo_path_data_t *p;
double x1, y1, x2, y2, x3, y3;
- p = path;
- while (1) {
+ for (i=0; i < path->num_data; i += path->data[i].header.length) {
+ p = &path->data[i];
switch (p->header.type) {
case CAIRO_PATH_MOVE_TO:
x1 = p[1].point.x; y1 = p[1].point.y;
@@ -77,10 +78,7 @@ munge_and_set_path (cairo_t *cr,
case CAIRO_PATH_CLOSE_PATH:
cairo_close_path (cr);
break;
- case CAIRO_PATH_END:
- return;
}
- p += p->header.length;
}
}
@@ -95,42 +93,44 @@ make_path (cairo_t *cr)
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
- cairo_path_data_t *path;
+ cairo_path_t *path;
/* copy path, munge, and fill */
cairo_translate (cr, 5, 5);
make_path (cr);
- path = cairo_copy_path_data (cr);
+ path = cairo_copy_path (cr);
cairo_new_path (cr);
munge_and_set_path (cr, path, scale_by_two);
- free (path);
+ cairo_path_destroy (path);
cairo_fill (cr);
/* copy flattened path, munge, and fill */
cairo_translate (cr, 0, 15);
make_path (cr);
- path = cairo_copy_path_data_flat (cr);
+ path = cairo_copy_path_flat (cr);
cairo_new_path (cr);
munge_and_set_path (cr, path, scale_by_two);
- free (path);
+ cairo_path_destroy (path);
cairo_fill (cr);
/* append two copies of path, and fill */
cairo_translate (cr, 0, 15);
cairo_scale (cr, 2.0, 2.0);
make_path (cr);
- path = cairo_copy_path_data (cr);
+ path = cairo_copy_path (cr);
cairo_new_path (cr);
- cairo_append_path_data (cr, path);
+ cairo_append_path (cr, path);
cairo_translate (cr, 2.5, 2.5);
- cairo_append_path_data (cr, path);
+ cairo_append_path (cr, path);
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
cairo_fill (cr);
+ cairo_path_destroy (path);
+
return CAIRO_TEST_SUCCESS;
}
@@ -138,27 +138,39 @@ int
main (void)
{
cairo_t *cr;
- cairo_path_data_t bogus_path_data;
+ cairo_path_data_t data;
+ cairo_path_t path;
+
+ /* Test a few error cases for cairo_append_path_data */
+ cr = cairo_create ();
+ cairo_append_path (cr, NULL);
+ if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER)
+ return 1;
+ cairo_destroy (cr);
- /* Test a couple error conditions for cairo_append_path_data */
cr = cairo_create ();
- cairo_append_path_data (cr, NULL);
+ path.data = NULL;
+ path.num_data = 0;
+ cairo_append_path (cr, &path);
if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER)
return 1;
cairo_destroy (cr);
cr = cairo_create ();
- bogus_path_data.header.type = CAIRO_PATH_MOVE_TO;
- bogus_path_data.header.length = 1;
- cairo_append_path_data (cr, &bogus_path_data);
+ /* Intentionally insert bogus header.length value (otherwise would be 2) */
+ data.header.type = CAIRO_PATH_MOVE_TO;
+ data.header.length = 1;
+ path.data = &data;
+ path.num_data = 1;
+ cairo_append_path (cr, &path);
if (cairo_status (cr) != CAIRO_STATUS_INVALID_PATH_DATA)
return 1;
cairo_destroy (cr);
/* And test the degnerate case */
cr = cairo_create ();
- bogus_path_data.header.type = CAIRO_PATH_END;
- cairo_append_path_data (cr, &bogus_path_data);
+ path.num_data = 0;
+ cairo_append_path (cr, &path);
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
return 1;
cairo_destroy (cr);