[PATCH] API: cairo_set_current_point()
Chris Wilson
chris at chris-wilson.co.uk
Wed Sep 3 02:05:08 PDT 2008
After this call the current point will be (x, y), without forming
a new sub-path. This establishes the current point for subsequent
relative path building operations.
FIXME: add test.
---
src/cairo-path-fixed-private.h | 4 +++-
src/cairo-path-fixed.c | 34 ++++++++++++++++++++++++----------
src/cairo.c | 27 +++++++++++++++++++++++++++
src/cairo.h | 3 +++
src/cairoint.h | 5 +++++
5 files changed, 62 insertions(+), 11 deletions(-)
diff --git a/src/cairo-path-fixed-private.h b/src/cairo-path-fixed-private.h
index 4a5990d..cbe8767 100644
--- a/src/cairo-path-fixed-private.h
+++ b/src/cairo-path-fixed-private.h
@@ -44,7 +44,7 @@ enum cairo_path_op {
CAIRO_PATH_OP_CURVE_TO = 2,
CAIRO_PATH_OP_CLOSE_PATH = 3
};
-/* we want to make sure a single byte is used for thie enum */
+/* we want to make sure a single byte is used for the enum */
typedef char cairo_path_op_t;
/* make _cairo_path_fixed fit a 512 bytes. about 50 items */
@@ -70,7 +70,9 @@ typedef struct _cairo_path_buf_fixed {
struct _cairo_path_fixed {
cairo_point_t last_move_point;
cairo_point_t current_point;
+ cairo_point_t last_point;
unsigned int has_current_point : 1;
+ unsigned int has_last_point : 1;
unsigned int has_curve_to : 1;
cairo_path_buf_t *buf_tail;
diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index 9086119..5dc937f 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -82,6 +82,8 @@ _cairo_path_fixed_init (cairo_path_fixed_t *path)
path->current_point.x = 0;
path->current_point.y = 0;
path->has_current_point = FALSE;
+ path->last_point = path->current_point;
+ path->has_last_point = FALSE;
path->has_curve_to = FALSE;
path->last_move_point = path->current_point;
}
@@ -97,6 +99,8 @@ _cairo_path_fixed_init_copy (cairo_path_fixed_t *path,
path->current_point = other->current_point;
path->has_current_point = other->has_current_point;
+ path->last_point = other->last_point;
+ path->has_last_point = other->has_last_point;
path->has_curve_to = other->has_curve_to;
path->last_move_point = other->last_move_point;
@@ -187,6 +191,16 @@ _cairo_path_fixed_destroy (cairo_path_fixed_t *path)
free (path);
}
+void
+_cairo_path_fixed_set_current_point (cairo_path_fixed_t *path,
+ cairo_fixed_t x,
+ cairo_fixed_t y)
+{
+ path->current_point.x = x;
+ path->current_point.y = y;
+ path->has_current_point = TRUE;
+}
+
cairo_status_t
_cairo_path_fixed_move_to (cairo_path_fixed_t *path,
cairo_fixed_t x,
@@ -212,8 +226,8 @@ _cairo_path_fixed_move_to (cairo_path_fixed_t *path,
return status;
}
- path->current_point = point;
- path->has_current_point = TRUE;
+ path->last_point = path->current_point = point;
+ path->has_last_point = path->has_current_point = TRUE;
path->last_move_point = path->current_point;
return CAIRO_STATUS_SUCCESS;
@@ -265,8 +279,8 @@ _cairo_path_fixed_line_to (cairo_path_fixed_t *path,
if (status)
return status;
- path->current_point = point;
- path->has_current_point = TRUE;
+ path->last_point = path->current_point = point;
+ path->has_last_point = path->has_current_point = TRUE;
return CAIRO_STATUS_SUCCESS;
}
@@ -311,8 +325,8 @@ _cairo_path_fixed_curve_to (cairo_path_fixed_t *path,
if (status)
return status;
- path->current_point = point[2];
- path->has_current_point = TRUE;
+ path->last_point = path->current_point = point[2];
+ path->has_last_point = path->has_current_point = TRUE;
path->has_curve_to = TRUE;
return CAIRO_STATUS_SUCCESS;
@@ -351,7 +365,7 @@ _cairo_path_fixed_close_path (cairo_path_fixed_t *path)
{
cairo_status_t status;
- if (! path->has_current_point)
+ if (! path->has_last_point)
return CAIRO_STATUS_SUCCESS;
status = _cairo_path_fixed_add (path, CAIRO_PATH_OP_CLOSE_PATH, NULL, 0);
@@ -661,9 +675,9 @@ _cairo_path_fixed_is_equal (cairo_path_fixed_t *path,
{
cairo_path_buf_t *path_buf, *other_buf;
- if (path->current_point.x != other->current_point.x ||
- path->current_point.y != other->current_point.y ||
- path->has_current_point != other->has_current_point ||
+ if (path->last_point.x != other->last_point.x ||
+ path->last_point.y != other->last_point.y ||
+ path->has_last_point != other->has_last_point ||
path->has_curve_to != other->has_curve_to ||
path->last_move_point.x != other->last_move_point.x ||
path->last_move_point.y != other->last_move_point.y)
diff --git a/src/cairo.c b/src/cairo.c
index 6b919a3..d03fee1 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -56,7 +56,9 @@ static const cairo_t _cairo_nil = {
{{ /* path */
{ 0, 0 }, /* last_move_point */
{ 0, 0 }, /* current point */
+ { 0, 0 }, /* last point */
FALSE, /* has_current_point */
+ FALSE, /* has_last_point */
FALSE, /* has_curve_to */
NULL, {{NULL}} /* buf_tail, buf_head */
}}
@@ -3494,6 +3496,31 @@ cairo_has_current_point (cairo_t *cr)
}
/**
+ * cairo_set_current_point:
+ * @cr: a cairo context
+ * @x: the X coordinate of the new position
+ * @y: the Y coordinate of the new position
+ *
+ * After this call the current point will be (@x, @y), without forming
+ * a new sub-path. This establishes the current point for subsequent
+ * relative path building operations.
+ **/
+void
+cairo_set_current_point (cairo_t *cr, double x, double y)
+{
+ cairo_fixed_t x_fixed, y_fixed;
+
+ if (cr->status)
+ return;
+
+ _cairo_gstate_user_to_backend (cr->gstate, &x, &y);
+ x_fixed = _cairo_fixed_from_double (x);
+ y_fixed = _cairo_fixed_from_double (y);
+
+ _cairo_path_fixed_set_current_point (cr->path, x_fixed, y_fixed);
+}
+
+/**
* cairo_get_current_point:
* @cr: a cairo context
* @x: return value for X coordinate of the current point
diff --git a/src/cairo.h b/src/cairo.h
index a201507..76b8c4e 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -1681,6 +1681,9 @@ cairo_public cairo_bool_t
cairo_has_current_point (cairo_t *cr);
cairo_public void
+cairo_set_current_point (cairo_t *cr, double x, double y);
+
+cairo_public void
cairo_get_current_point (cairo_t *cr, double *x, double *y);
cairo_public cairo_fill_rule_t
diff --git a/src/cairoint.h b/src/cairoint.h
index bffceb3..d5cf251 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1399,6 +1399,11 @@ _cairo_path_fixed_fini (cairo_path_fixed_t *path);
cairo_private void
_cairo_path_fixed_destroy (cairo_path_fixed_t *path);
+cairo_private void
+_cairo_path_fixed_set_current_point (cairo_path_fixed_t *path,
+ cairo_fixed_t x,
+ cairo_fixed_t y);
+
cairo_private cairo_status_t
_cairo_path_fixed_move_to (cairo_path_fixed_t *path,
cairo_fixed_t x,
--
1.5.6.3
--=-tqtLUOgqtQNNlHcoQHK3--
More information about the cairo
mailing list