Commit d780a951 authored by Christian Persch's avatar Christian Persch

Use cairo_path_data_type_t directly

To do this, remove RSVG_END element from RsvgBpathDef.
parent e1b9f890
......@@ -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);
......
......@@ -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;
}
......@@ -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
......
......@@ -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;
}
}
}
......
......@@ -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;
}
}
......
......@@ -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 {
......
......@@ -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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment