Commit d44a3f5b authored by Caleb Michael Moore's avatar Caleb Michael Moore

clip paths now in

parent a3bf1bd4
/* vim: set sw=4: -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
rsvg-shapes.c: Draw shapes with cairo
Copyright (C) 2005 Dom Lachowicz <cinamod@hotmail.com>
Copyright (C) 2005 Caleb Moore <c.moore@student.unsw.edu.au>
Copyright (C) 2005 Red Hat, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Dom Lachowicz <cinamod@hotmail.com>,
Caleb Moore <c.moore@student.unsw.edu.au>
Carl Worth <cworth@cworth.org>
*/
#include "rsvg-cairo-draw.h"
#include "rsvg-cairo-clip.h"
#include "rsvg-cairo-render.h"
#include "rsvg-styles.h"
#include "rsvg-bpath-util.h"
#include "rsvg-path.h"
#include <math.h>
#include <string.h>
typedef struct RsvgCairoClipRender RsvgCairoClipRender;
struct RsvgCairoClipRender {
RsvgRender super;
cairo_t *cr;
};
static void
_set_rsvg_affine (cairo_t *cr, const double affine[6])
{
cairo_matrix_t matrix;
cairo_matrix_init (&matrix,
affine[0], affine[1],
affine[2], affine[3],
affine[4], affine[5]);
cairo_set_matrix (cr, &matrix);
}
static void
rsvg_cairo_clip_render_path (RsvgDrawingCtx *ctx, const RsvgBpathDef *bpath_def)
{
RsvgCairoClipRender *render = (RsvgCairoClipRender *)ctx->render;
RsvgState *state = rsvg_state_current (ctx);
cairo_t *cr;
RsvgBpath *bpath;
cairo_matrix_t save;
int i;
cr = render->cr;
cairo_get_matrix (cr, &save);
_set_rsvg_affine (cr, state->affine);
for (i=0; i < bpath_def->n_bpath; i++) {
bpath = &bpath_def->bpath[i];
switch (bpath->code) {
case RSVG_MOVETO:
cairo_close_path (cr);
/* fall-through */
case RSVG_MOVETO_OPEN:
cairo_move_to (cr, bpath->x3, bpath->y3);
break;
case RSVG_CURVETO:
cairo_curve_to (cr,
bpath->x1, bpath->y1,
bpath->x2, bpath->y2,
bpath->x3, bpath->y3);
break;
case RSVG_LINETO:
cairo_line_to (cr, bpath->x3, bpath->y3);
break;
case RSVG_END:
break;
}
}
cairo_set_matrix (cr, &save);
}
static void rsvg_cairo_clip_render_image (RsvgDrawingCtx *ctx,
const GdkPixbuf * pixbuf,
double pixbuf_x, double pixbuf_y,
double w, double h)
{
}
static void
rsvg_cairo_clip_render_free (RsvgRender * self)
{
RsvgCairoClipRender * me = (RsvgCairoClipRender *)self;
g_free (me);
}
static void
rsvg_cairo_clip_push_discrete_layer (RsvgDrawingCtx *ctx) {}
static void
rsvg_cairo_clip_pop_discrete_layer (RsvgDrawingCtx *ctx) {}
static void
rsvg_cairo_clip_add_clipping_rect (RsvgDrawingCtx *ctx,
double x, double y,
double w, double h){}
static RsvgRender *
rsvg_cairo_clip_render_new(cairo_t * cr)
{
RsvgCairoClipRender * cairo_render = g_new0(RsvgCairoClipRender, 1);
cairo_render->super.free = rsvg_cairo_clip_render_free;
cairo_render->super.render_image = rsvg_cairo_clip_render_image;
cairo_render->super.render_path = rsvg_cairo_clip_render_path;
cairo_render->super.pop_discrete_layer =
rsvg_cairo_clip_pop_discrete_layer;
cairo_render->super.push_discrete_layer =
rsvg_cairo_clip_push_discrete_layer;
cairo_render->super.add_clipping_rect =
rsvg_cairo_clip_add_clipping_rect;
cairo_render->super.get_image_of_node = NULL;
cairo_render->cr = cr;
return &cairo_render->super;
}
void
rsvg_cairo_clip (RsvgDrawingCtx *ctx, RsvgClipPath *clip)
{
RsvgCairoRender * save = (RsvgCairoRender *)ctx->render;
ctx->render = rsvg_cairo_clip_render_new(save->cr);
rsvg_state_push(ctx);
_rsvg_node_draw_children ((RsvgNode *)clip, ctx, 0);
rsvg_state_pop(ctx);
if (rsvg_state_current (ctx)->fill_rule == FILL_RULE_EVENODD)
cairo_set_fill_rule (save->cr, CAIRO_FILL_RULE_EVEN_ODD);
else /* state->fill_rule == FILL_RULE_NONZERO */
cairo_set_fill_rule (save->cr, CAIRO_FILL_RULE_WINDING);
cairo_clip(save->cr);
ctx->render = &save->super;
}
/* vim: set sw=4: -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
rsvg-cairo-render.h: The cairo backend plugin
Copyright (C) 2005 Dom Lachowicz <cinamod@hotmail.com>
Caleb Moore <c.moore@student.unsw.edu.au>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Dom Lachowicz <cinamod@hotmail.com>
Caleb Moore <c.moore@student.unsw.edu.au>
*/
#ifndef RSVG_CAIRO_CLIP_H
#define RSVG_CAIRO_CLIP_H
#include "rsvg-mask.h"
#include <cairo.h>
G_BEGIN_DECLS
void
rsvg_cairo_clip (RsvgDrawingCtx *ctx, RsvgClipPath *clip);
G_END_DECLS
#endif
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