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

cairo obb fix

parent f6b986d0
...@@ -38,6 +38,10 @@ ...@@ -38,6 +38,10 @@
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
typedef struct {
int x, y, w, h;
} RsvgCairoBbox;
static void static void
_pattern_add_rsvg_color_stops (cairo_pattern_t *pattern, _pattern_add_rsvg_color_stops (cairo_pattern_t *pattern,
GPtrArray *stops, GPtrArray *stops,
...@@ -67,7 +71,8 @@ static void ...@@ -67,7 +71,8 @@ static void
_set_source_rsvg_linear_gradient (cairo_t *cr, _set_source_rsvg_linear_gradient (cairo_t *cr,
RsvgLinearGradient *linear, RsvgLinearGradient *linear,
guint32 current_color_rgb, guint32 current_color_rgb,
guint8 opacity) guint8 opacity,
RsvgCairoBbox bbox)
{ {
cairo_pattern_t *pattern; cairo_pattern_t *pattern;
cairo_matrix_t matrix; cairo_matrix_t matrix;
...@@ -86,6 +91,12 @@ _set_source_rsvg_linear_gradient (cairo_t *cr, ...@@ -86,6 +91,12 @@ _set_source_rsvg_linear_gradient (cairo_t *cr,
linear->affine[0], linear->affine[1], linear->affine[0], linear->affine[1],
linear->affine[2], linear->affine[3], linear->affine[2], linear->affine[3],
linear->affine[4], linear->affine[5]); linear->affine[4], linear->affine[5]);
if (linear->obj_bbox){
cairo_matrix_t bboxmatrix;
cairo_matrix_init (&bboxmatrix,
bbox.w, 0, 0, bbox.h, bbox.x, bbox.y);
cairo_matrix_multiply(&matrix, &matrix, &bboxmatrix);
}
cairo_matrix_invert (&matrix); cairo_matrix_invert (&matrix);
cairo_pattern_set_matrix (pattern, &matrix); cairo_pattern_set_matrix (pattern, &matrix);
...@@ -100,7 +111,8 @@ static void ...@@ -100,7 +111,8 @@ static void
_set_source_rsvg_radial_gradient (cairo_t *cr, _set_source_rsvg_radial_gradient (cairo_t *cr,
RsvgRadialGradient *radial, RsvgRadialGradient *radial,
guint32 current_color_rgb, guint32 current_color_rgb,
guint8 opacity) guint8 opacity,
RsvgCairoBbox bbox)
{ {
cairo_pattern_t *pattern; cairo_pattern_t *pattern;
cairo_matrix_t matrix; cairo_matrix_t matrix;
...@@ -120,6 +132,13 @@ _set_source_rsvg_radial_gradient (cairo_t *cr, ...@@ -120,6 +132,13 @@ _set_source_rsvg_radial_gradient (cairo_t *cr,
radial->affine[0], radial->affine[1], radial->affine[0], radial->affine[1],
radial->affine[2], radial->affine[3], radial->affine[2], radial->affine[3],
radial->affine[4], radial->affine[5]); radial->affine[4], radial->affine[5]);
if (radial->obj_bbox){
cairo_matrix_t bboxmatrix;
cairo_matrix_init (&bboxmatrix,
bbox.w, 0, 0, bbox.h, bbox.x, bbox.y);
cairo_matrix_multiply(&matrix, &matrix, &bboxmatrix);
}
cairo_matrix_invert (&matrix); cairo_matrix_invert (&matrix);
cairo_pattern_set_matrix (pattern, &matrix); cairo_pattern_set_matrix (pattern, &matrix);
...@@ -160,16 +179,19 @@ static void ...@@ -160,16 +179,19 @@ static void
_set_source_rsvg_paint_server (cairo_t *cr, _set_source_rsvg_paint_server (cairo_t *cr,
guint32 current_color_rgb, guint32 current_color_rgb,
RsvgPaintServer *ps, RsvgPaintServer *ps,
guint8 opacity) guint8 opacity,
RsvgCairoBbox bbox)
{ {
switch (ps->type) { switch (ps->type) {
case RSVG_PAINT_SERVER_LIN_GRAD: case RSVG_PAINT_SERVER_LIN_GRAD:
_set_source_rsvg_linear_gradient (cr, ps->core.lingrad, _set_source_rsvg_linear_gradient (cr, ps->core.lingrad,
current_color_rgb, opacity); current_color_rgb, opacity,
bbox);
break; break;
case RSVG_PAINT_SERVER_RAD_GRAD: case RSVG_PAINT_SERVER_RAD_GRAD:
_set_source_rsvg_radial_gradient (cr, ps->core.radgrad, _set_source_rsvg_radial_gradient (cr, ps->core.radgrad,
current_color_rgb, opacity); current_color_rgb, opacity,
bbox);
break; break;
case RSVG_PAINT_SERVER_SOLID: case RSVG_PAINT_SERVER_SOLID:
_set_source_rsvg_solid_colour (cr, ps->core.colour, opacity); _set_source_rsvg_solid_colour (cr, ps->core.colour, opacity);
...@@ -200,6 +222,8 @@ rsvg_cairo_render_path (RsvgDrawingCtx *ctx, const RsvgBpathDef *bpath_def) ...@@ -200,6 +222,8 @@ rsvg_cairo_render_path (RsvgDrawingCtx *ctx, const RsvgBpathDef *bpath_def)
cairo_t *cr = render->cr; cairo_t *cr = render->cr;
RsvgBpath *bpath; RsvgBpath *bpath;
int i; int i;
int xmin = 0, ymin = 0, xmax = 0, ymax = 0, virgin = 1;
RsvgCairoBbox bbox;
cairo_save (cr); cairo_save (cr);
...@@ -213,6 +237,12 @@ rsvg_cairo_render_path (RsvgDrawingCtx *ctx, const RsvgBpathDef *bpath_def) ...@@ -213,6 +237,12 @@ rsvg_cairo_render_path (RsvgDrawingCtx *ctx, const RsvgBpathDef *bpath_def)
for (i=0; i < bpath_def->n_bpath; i++) { for (i=0; i < bpath_def->n_bpath; i++) {
bpath = &bpath_def->bpath[i]; bpath = &bpath_def->bpath[i];
if (bpath->x3 < xmin || virgin) xmin = bpath->x3;
if (bpath->x3 > xmax || virgin) xmax = bpath->x3;
if (bpath->y3 < ymin || virgin) ymin = bpath->y3;
if (bpath->y3 > ymax || virgin) ymax = bpath->y3;
virgin = 0;
switch (bpath->code) { switch (bpath->code) {
case RSVG_MOVETO: case RSVG_MOVETO:
cairo_close_path (cr); cairo_close_path (cr);
...@@ -234,16 +264,22 @@ rsvg_cairo_render_path (RsvgDrawingCtx *ctx, const RsvgBpathDef *bpath_def) ...@@ -234,16 +264,22 @@ rsvg_cairo_render_path (RsvgDrawingCtx *ctx, const RsvgBpathDef *bpath_def)
} }
} }
bbox.x = xmin;
bbox.y = ymin;
bbox.w = xmax - xmin;
bbox.h = ymax - ymin;
if (state->fill != NULL) { if (state->fill != NULL) {
if (state->fill_rule == FILL_RULE_EVENODD) if (state->fill_rule == FILL_RULE_EVENODD)
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
else /* state->fill_rule == FILL_RULE_NONZERO */ else /* state->fill_rule == FILL_RULE_NONZERO */
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
_set_source_rsvg_paint_server (cr, _set_source_rsvg_paint_server (cr,
state->current_color, state->current_color,
state->fill, state->fill,
state->fill_opacity); state->fill_opacity,
bbox);
if (state->stroke != NULL) if (state->stroke != NULL)
cairo_fill_preserve (cr); cairo_fill_preserve (cr);
...@@ -255,7 +291,8 @@ rsvg_cairo_render_path (RsvgDrawingCtx *ctx, const RsvgBpathDef *bpath_def) ...@@ -255,7 +291,8 @@ rsvg_cairo_render_path (RsvgDrawingCtx *ctx, const RsvgBpathDef *bpath_def)
_set_source_rsvg_paint_server (cr, _set_source_rsvg_paint_server (cr,
state->current_color, state->current_color,
state->stroke, state->stroke,
state->stroke_opacity); state->stroke_opacity,
bbox);
cairo_stroke (cr); cairo_stroke (cr);
} }
......
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