[cairo-commit] libsvg-cairo/src svg-cairo-internal.h, 1.17,
1.18 svg_cairo.c, 1.34, 1.35 svg_cairo_state.c, 1.12, 1.13
Carl Worth
commit at pdx.freedesktop.org
Tue Apr 26 13:00:02 PDT 2005
Committed by: cworth
Update of /cvs/cairo/libsvg-cairo/src
In directory gabe:/tmp/cvs-serv8689/src
Modified Files:
svg-cairo-internal.h svg_cairo.c svg_cairo_state.c
Log Message:
* src/svg-cairo-internal.h:
* src/svg_cairo.c: (_svg_cairo_set_pattern),
(_svg_cairo_render_path), (_svg_cairo_render_text):
* src/svg_cairo_state.c: (_svg_cairo_state_init):
Track change in cairo API that the path is no longer inside the
graphics state, (so we use cairo_fill_preserve rather than
save/restore around cairo_fill). Clean up pattern handling
considerably, (elimate state->in_set_pattern_HACK). Manually save
the current path before re-using the same cairo context for
drawing a pattern.
Index: svg-cairo-internal.h
===================================================================
RCS file: /cvs/cairo/libsvg-cairo/src/svg-cairo-internal.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- svg-cairo-internal.h 18 Apr 2005 23:32:18 -0000 1.17
+++ svg-cairo-internal.h 26 Apr 2005 20:00:00 -0000 1.18
@@ -70,10 +70,6 @@
svg_text_anchor_t text_anchor;
struct svg_cairo_state *next;
-
- /* XXX: This is a bad hack. The pattern handling support needs to
- be sorted out properly. */
- int in_set_pattern_HACK;
} svg_cairo_state_t;
struct svg_cairo {
Index: svg_cairo.c
===================================================================
RCS file: /cvs/cairo/libsvg-cairo/src/svg_cairo.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- svg_cairo.c 18 Apr 2005 23:32:18 -0000 1.34
+++ svg_cairo.c 26 Apr 2005 20:00:00 -0000 1.35
@@ -650,12 +650,27 @@
cairo_surface_t *pattern_surface;
cairo_pattern_t *surface_pattern;
double x_px, y_px, width_px, height_px;
+ cairo_path_t *path;
_svg_cairo_length_to_pixel (svg_cairo, &pattern->x, &x_px);
_svg_cairo_length_to_pixel (svg_cairo, &pattern->y, &y_px);
_svg_cairo_length_to_pixel (svg_cairo, &pattern->width, &width_px);
_svg_cairo_length_to_pixel (svg_cairo, &pattern->height, &height_px);
+ /* OK. We've got the final path to be filled/stroked inside the
+ * cairo context right now. But we're also going to re-use that
+ * same context to draw the pattern. And since the path is no
+ * longer in the graphics state, cairo_save/restore will not help
+ * us here.
+ *
+ * Currently we deal with this by manually saving/restoring the
+ * path.
+ *
+ * It might be simpler to just use a new cairo_t for drawing the
+ * pattern.
+ */
+ path = cairo_copy_path (svg_cairo->cr);
+ cairo_new_path (svg_cairo->cr);
cairo_save (svg_cairo->cr);
pattern_surface = cairo_surface_create_similar (cairo_current_target_surface (svg_cairo->cr),
@@ -665,23 +680,24 @@
cairo_set_target_surface (svg_cairo->cr, pattern_surface);
- /* XXX: The pattern support is a real mess right now. This hack
- prevents a case of infinite recursion which is just one
- artifact of the current mess. Part of the solution involves
- restoring the graphics state of the associated pattern before
- drawing it. */
- svg_cairo->state->in_set_pattern_HACK = 1;
+ _svg_cairo_push_state (svg_cairo);
+ svg_cairo->state->fill_paint.type = SVG_PAINT_TYPE_NONE;
+ svg_cairo->state->stroke_paint.type = SVG_PAINT_TYPE_NONE;
+
svg_element_render (pattern->group_element, &SVG_CAIRO_RENDER_ENGINE, svg_cairo);
- svg_cairo->state->in_set_pattern_HACK = 0;
+ _svg_cairo_pop_state (svg_cairo);
cairo_restore (svg_cairo->cr);
+ cairo_new_path (svg_cairo->cr);
+ cairo_append_path (svg_cairo->cr, path);
+ cairo_path_destroy (path);
surface_pattern = cairo_pattern_create_for_surface (pattern_surface);
cairo_surface_destroy (pattern_surface);
cairo_pattern_set_extend (surface_pattern, CAIRO_EXTEND_REPEAT);
- cairo_set_pattern (svg_cairo->cr, surface_pattern);
+ cairo_set_source (svg_cairo->cr, surface_pattern);
cairo_pattern_destroy (surface_pattern);
@@ -1039,20 +1055,17 @@
fill_paint = &svg_cairo->state->fill_paint;
stroke_paint = &svg_cairo->state->stroke_paint;
- if (fill_paint->type
- && (fill_paint->type != SVG_PAINT_TYPE_PATTERN || !svg_cairo->state->in_set_pattern_HACK)) {
- if (stroke_paint->type)
- cairo_save (svg_cairo->cr);
+ if (fill_paint->type) {
_svg_cairo_set_paint_and_opacity (svg_cairo, fill_paint,
svg_cairo->state->fill_opacity,
SVG_CAIRO_RENDER_TYPE_FILL);
- cairo_fill (svg_cairo->cr);
if (stroke_paint->type)
- cairo_restore (svg_cairo->cr);
+ cairo_fill_preserve (svg_cairo->cr);
+ else
+ cairo_fill (svg_cairo->cr);
}
- if (stroke_paint->type
- && (stroke_paint->type != SVG_PAINT_TYPE_PATTERN || !svg_cairo->state->in_set_pattern_HACK)) {
+ if (stroke_paint->type) {
_svg_cairo_set_paint_and_opacity (svg_cairo, stroke_paint,
svg_cairo->state->stroke_opacity,
SVG_CAIRO_RENDER_TYPE_STROKE);
@@ -1180,8 +1193,7 @@
cairo_rel_move_to (svg_cairo->cr, -extents.x_advance / 2.0, -extents.y_advance / 2.0);
}
- if (fill_paint->type
- && (fill_paint->type != SVG_PAINT_TYPE_PATTERN || !svg_cairo->state->in_set_pattern_HACK)) {
+ if (fill_paint->type) {
if (stroke_paint->type)
cairo_save (svg_cairo->cr);
_svg_cairo_set_paint_and_opacity (svg_cairo, fill_paint,
@@ -1192,8 +1204,7 @@
cairo_restore (svg_cairo->cr);
}
- if (stroke_paint->type
- && (stroke_paint->type != SVG_PAINT_TYPE_PATTERN || !svg_cairo->state->in_set_pattern_HACK)) {
+ if (stroke_paint->type) {
_svg_cairo_set_paint_and_opacity (svg_cairo, stroke_paint,
svg_cairo->state->stroke_opacity,
SVG_CAIRO_RENDER_TYPE_STROKE);
Index: svg_cairo_state.c
===================================================================
RCS file: /cvs/cairo/libsvg-cairo/src/svg_cairo_state.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- svg_cairo_state.c 14 Jan 2005 22:19:03 -0000 1.12
+++ svg_cairo_state.c 26 Apr 2005 20:00:00 -0000 1.13
@@ -68,8 +68,6 @@
state->next = NULL;
- state->in_set_pattern_HACK = 0;
-
return SVG_CAIRO_STATUS_SUCCESS;
}
More information about the cairo-commit
mailing list