summaryrefslogtreecommitdiff
path: root/src/cairo-path-fixed.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2009-08-11 17:02:41 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2009-08-29 08:08:34 +0100
commit4032438625819cfa5d1928d653f404364529a2e1 (patch)
treef4b3fa9e719378e45fc2ef17ccef2b3492ba1119 /src/cairo-path-fixed.c
parent111f2be71b1e51fac551fd9214d13899a8ec7909 (diff)
[path] Eliminate redundant line-to before a close
As the close implicitly issues a line-to to the initial point, remove an identical line-to if present.
Diffstat (limited to 'src/cairo-path-fixed.c')
-rw-r--r--src/cairo-path-fixed.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index f1146d37c..995036847 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -574,6 +574,28 @@ _cairo_path_fixed_close_path (cairo_path_fixed_t *path)
if (! path->has_current_point)
return CAIRO_STATUS_SUCCESS;
+ /* If the previous op was also a LINE_TO back to the start, discard it */
+ if (_cairo_path_last_op (path) == CAIRO_PATH_OP_LINE_TO) {
+ if (path->current_point.x == path->last_move_point.x &&
+ path->current_point.y == path->last_move_point.y)
+ {
+ cairo_path_buf_t *buf;
+ cairo_point_t *p;
+
+ buf = cairo_path_tail (path);
+ if (likely (buf->num_points >= 2)) {
+ p = &buf->points[buf->num_points-2];
+ } else {
+ cairo_path_buf_t *prev_buf = cairo_path_buf_prev (buf);
+ p = &prev_buf->points[prev_buf->num_points - (2 - buf->num_points)];
+ }
+
+ path->current_point = *p;
+ buf->num_ops--;
+ buf->num_points--;
+ }
+ }
+
status = _cairo_path_fixed_add (path, CAIRO_PATH_OP_CLOSE_PATH, NULL, 0);
if (unlikely (status))
return status;