[librsvg/next: 19/31] Use cairo_path_data_type_t directly
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/next: 19/31] Use cairo_path_data_type_t directly
- Date: Fri, 21 Oct 2011 21:22:27 +0000 (UTC)
commit 7e8ed9b420bd04077dc045dd86a0e3a7384559b1
Author: Christian Persch <chpe gnome org>
Date: Thu Sep 15 22:59:52 2011 +0200
Use cairo_path_data_type_t directly
To do this, remove RSVG_END element from RsvgBpathDef.
rsvg-base.c | 1 -
rsvg-bpath-util.c | 21 ++++++---------------
rsvg-bpath-util.h | 12 +++---------
rsvg-cairo-clip.c | 10 ++++------
rsvg-cairo-draw.c | 10 ++++------
rsvg-marker.c | 38 ++++++++++++++++++++++----------------
rsvg-path.c | 2 ++
7 files changed, 41 insertions(+), 53 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index 52d822c..092f24b 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -2067,7 +2067,6 @@ rsvg_render_path (RsvgDrawingCtx * ctx, const char *d)
RsvgBpathDef *bpath_def;
bpath_def = rsvg_parse_path (d);
- rsvg_bpath_def_art_finish (bpath_def);
ctx->render->render_path (ctx, bpath_def);
rsvg_render_markers (bpath_def, ctx);
diff --git a/rsvg-bpath-util.c b/rsvg-bpath-util.c
index 1c713d9..db2ca9a 100644
--- a/rsvg-bpath-util.c
+++ b/rsvg-bpath-util.c
@@ -72,7 +72,7 @@ rsvg_bpath_def_moveto (RsvgBpathDef * bpd, double x, double y)
n_bpath = bpd->n_bpath;
if (n_bpath > 0)
- if (bpath[n_bpath - 1].code == RSVG_MOVETO_OPEN) {
+ if (bpath[n_bpath - 1].code == CAIRO_PATH_MOVE_TO) {
bpath[n_bpath - 1].x3 = x;
bpath[n_bpath - 1].y3 = y;
bpd->moveto_idx = n_bpath - 1;
@@ -84,7 +84,7 @@ rsvg_bpath_def_moveto (RsvgBpathDef * bpd, double x, double y)
if (n_bpath == bpd->n_bpath_max)
bpd->bpath = g_realloc (bpd->bpath, (bpd->n_bpath_max <<= 1) * sizeof (RsvgBpath));
bpath = bpd->bpath;
- bpath[n_bpath].code = RSVG_MOVETO_OPEN;
+ bpath[n_bpath].code = CAIRO_PATH_MOVE_TO;
bpath[n_bpath].x3 = x;
bpath[n_bpath].y3 = y;
bpd->moveto_idx = n_bpath;
@@ -104,7 +104,7 @@ rsvg_bpath_def_lineto (RsvgBpathDef * bpd, double x, double y)
if (n_bpath == bpd->n_bpath_max)
bpd->bpath = g_realloc (bpd->bpath, (bpd->n_bpath_max <<= 1) * sizeof (RsvgBpath));
bpath = bpd->bpath;
- bpath[n_bpath].code = RSVG_LINETO;
+ bpath[n_bpath].code = CAIRO_PATH_LINE_TO;
bpath[n_bpath].x3 = x;
bpath[n_bpath].y3 = y;
}
@@ -124,7 +124,7 @@ rsvg_bpath_def_curveto (RsvgBpathDef * bpd, double x1, double y1, double x2, dou
if (n_bpath == bpd->n_bpath_max)
bpd->bpath = g_realloc (bpd->bpath, (bpd->n_bpath_max <<= 1) * sizeof (RsvgBpath));
bpath = bpd->bpath;
- bpath[n_bpath].code = RSVG_CURVETO;
+ bpath[n_bpath].code = CAIRO_PATH_CURVE_TO;
bpath[n_bpath].x1 = x1;
bpath[n_bpath].y1 = y1;
bpath[n_bpath].x2 = x2;
@@ -159,20 +159,11 @@ rsvg_bpath_def_closepath (RsvgBpathDef * bpd)
rsvg_bpath_def_replicate (bpd, bpd->moveto_idx);
bpath = bpd->bpath;
- bpath[bpd->n_bpath - 1].code = RSVG_MOVETO;
+ bpath[bpd->n_bpath - 1].code = CAIRO_PATH_CLOSE_PATH;
bpd->moveto_idx = bpd->n_bpath - 1;
}
void
-rsvg_bpath_def_art_finish (RsvgBpathDef * bpd)
+rsvg_bpath_def_finish (RsvgBpathDef *bpd)
{
- int n_bpath;
-
- g_return_if_fail (bpd != NULL);
-
- n_bpath = bpd->n_bpath++;
-
- if (n_bpath == bpd->n_bpath_max)
- bpd->bpath = g_realloc (bpd->bpath, (bpd->n_bpath_max <<= 1) * sizeof (RsvgBpath));
- bpd->bpath[n_bpath].code = RSVG_END;
}
diff --git a/rsvg-bpath-util.h b/rsvg-bpath-util.h
index f1204dd..bb2cee6 100644
--- a/rsvg-bpath-util.h
+++ b/rsvg-bpath-util.h
@@ -28,20 +28,14 @@
#define RSVG_BPATH_UTIL_H
#include <glib.h>
+#include <cairo.h>
G_BEGIN_DECLS
-typedef enum {
- RSVG_MOVETO,
- RSVG_MOVETO_OPEN,
- RSVG_CURVETO,
- RSVG_LINETO,
- RSVG_END
-} RsvgPathcode;
typedef struct _RsvgBpath RsvgBpath;
struct _RsvgBpath {
/*< public > */
- RsvgPathcode code;
+ cairo_path_data_type_t code;
double x1;
double y1;
double x2;
@@ -69,7 +63,7 @@ void rsvg_bpath_def_curveto (RsvgBpathDef * bpd,
double x1, double y1, double x2, double y2, double x3, double y3);
void rsvg_bpath_def_closepath (RsvgBpathDef * bpd);
-void rsvg_bpath_def_art_finish (RsvgBpathDef * bpd);
+void rsvg_bpath_def_finish (RsvgBpathDef * bpd);
G_END_DECLS
diff --git a/rsvg-cairo-clip.c b/rsvg-cairo-clip.c
index 3aeb7d8..622c989 100644
--- a/rsvg-cairo-clip.c
+++ b/rsvg-cairo-clip.c
@@ -81,20 +81,18 @@ rsvg_cairo_clip_render_path (RsvgDrawingCtx * ctx, const RsvgBpathDef * bpath_de
bpath = &bpath_def->bpath[i];
switch (bpath->code) {
- case RSVG_MOVETO:
+ case CAIRO_PATH_CLOSE_PATH:
cairo_close_path (cr);
/* fall-through */
- case RSVG_MOVETO_OPEN:
+ case CAIRO_PATH_MOVE_TO:
cairo_move_to (cr, bpath->x3, bpath->y3);
break;
- case RSVG_CURVETO:
+ case CAIRO_PATH_CURVE_TO:
cairo_curve_to (cr, bpath->x1, bpath->y1, bpath->x2, bpath->y2, bpath->x3, bpath->y3);
break;
- case RSVG_LINETO:
+ case CAIRO_PATH_LINE_TO:
cairo_line_to (cr, bpath->x3, bpath->y3);
break;
- case RSVG_END:
- break;
}
}
}
diff --git a/rsvg-cairo-draw.c b/rsvg-cairo-draw.c
index 91a164d..197ac87 100644
--- a/rsvg-cairo-draw.c
+++ b/rsvg-cairo-draw.c
@@ -474,20 +474,18 @@ rsvg_cairo_render_path (RsvgDrawingCtx * ctx, const RsvgBpathDef * bpath_def)
bpath = &bpath_def->bpath[i];
switch (bpath->code) {
- case RSVG_MOVETO:
+ case CAIRO_PATH_CLOSE_PATH:
cairo_close_path (cr);
/* fall-through */
- case RSVG_MOVETO_OPEN:
+ case CAIRO_PATH_MOVE_TO:
cairo_move_to (cr, bpath->x3, bpath->y3);
break;
- case RSVG_CURVETO:
+ case CAIRO_PATH_CURVE_TO:
cairo_curve_to (cr, bpath->x1, bpath->y1, bpath->x2, bpath->y2, bpath->x3, bpath->y3);
break;
- case RSVG_LINETO:
+ case CAIRO_PATH_LINE_TO:
cairo_line_to (cr, bpath->x3, bpath->y3);
break;
- case RSVG_END:
- break;
}
}
diff --git a/rsvg-marker.c b/rsvg-marker.c
index c7e76f1..21628fd 100644
--- a/rsvg-marker.c
+++ b/rsvg-marker.c
@@ -208,12 +208,13 @@ void
rsvg_render_markers (const RsvgBpathDef * bpath_def, RsvgDrawingCtx * ctx)
{
int i;
+ int n_bpath, n_bpath_minus_1;
double x, y;
double lastx, lasty;
double nextx, nexty;
double linewidth;
- RsvgPathcode code, lastcode, nextcode;
+ cairo_path_data_type_t code, nextcode;
RsvgState *state;
RsvgMarker *startmarker;
@@ -235,27 +236,32 @@ rsvg_render_markers (const RsvgBpathDef * bpath_def, RsvgDrawingCtx * ctx)
x = 0;
y = 0;
- code = RSVG_END;
nextx = bpath_def->bpath[0].x3;
nexty = bpath_def->bpath[0].y3;
nextcode = bpath_def->bpath[0].code;
- for (i = 0; i < bpath_def->n_bpath - 1; i++) {
+ n_bpath = bpath_def->n_bpath;
+ n_bpath_minus_1 = n_bpath - 1;
+
+ for (i = 0; i < n_bpath; i++) {
lastx = x;
lasty = y;
- lastcode = code;
x = nextx;
y = nexty;
code = nextcode;
- nextx = bpath_def->bpath[i + 1].x3;
- nexty = bpath_def->bpath[i + 1].y3;
- nextcode = bpath_def->bpath[i + 1].code;
- if (nextcode == RSVG_MOVETO ||
- nextcode == RSVG_MOVETO_OPEN ||
- nextcode == RSVG_END) {
+ if (i == n_bpath_minus_1) {
+ nextcode = CAIRO_PATH_MOVE_TO;
+ } else {
+ nextx = bpath_def->bpath[i + 1].x3;
+ nexty = bpath_def->bpath[i + 1].y3;
+ nextcode = bpath_def->bpath[i + 1].code;
+ }
+
+ if (nextcode == CAIRO_PATH_CLOSE_PATH ||
+ nextcode == CAIRO_PATH_MOVE_TO) {
if (endmarker) {
- if (code == RSVG_CURVETO) {
+ if (code == CAIRO_PATH_CURVE_TO) {
rsvg_marker_render (endmarker, x, y,
atan2 (y - bpath_def->bpath[i].y2,
x - bpath_def->bpath[i].x2),
@@ -266,10 +272,10 @@ rsvg_render_markers (const RsvgBpathDef * bpath_def, RsvgDrawingCtx * ctx)
linewidth, ctx);
}
}
- } else if (code == RSVG_MOVETO ||
- code == RSVG_MOVETO_OPEN) {
+ } else if (code == CAIRO_PATH_CLOSE_PATH ||
+ code == CAIRO_PATH_MOVE_TO) {
if (startmarker) {
- if (nextcode == RSVG_CURVETO) {
+ if (nextcode == CAIRO_PATH_CURVE_TO) {
rsvg_marker_render (startmarker, x, y,
atan2 (bpath_def->bpath[i + 1].y1 - y,
bpath_def->bpath[i + 1].x1 - x),
@@ -286,14 +292,14 @@ rsvg_render_markers (const RsvgBpathDef * bpath_def, RsvgDrawingCtx * ctx)
if (middlemarker) {
double xdifin, ydifin, xdifout, ydifout, intot, outtot, angle;
- if (code == RSVG_CURVETO) {
+ if (code == CAIRO_PATH_CURVE_TO) {
xdifin = x - bpath_def->bpath[i].x2;
ydifin = y - bpath_def->bpath[i].y2;
} else {
xdifin = x - lastx;
ydifin = y - lasty;
}
- if (nextcode == RSVG_CURVETO) {
+ if (nextcode == CAIRO_PATH_CURVE_TO) {
xdifout = bpath_def->bpath[i+1].x1 - x;
ydifout = bpath_def->bpath[i+1].y1 - y;
} else {
diff --git a/rsvg-path.c b/rsvg-path.c
index ac6fb58..8c92d97 100644
--- a/rsvg-path.c
+++ b/rsvg-path.c
@@ -568,5 +568,7 @@ rsvg_parse_path (const char *path_str)
if (ctx.param)
rsvg_parse_path_do_cmd (&ctx, TRUE);
+ rsvg_bpath_def_finish (ctx.bpath);
+
return ctx.bpath;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]