[cairo] SVG radial gradient fix
Emmanuel Pacaud
emmanuel.pacaud at lapp.in2p3.fr
Mon Mar 5 12:52:24 PST 2007
Hi,
It looks like the patch below fixes the radial gradient test for SVG
surface. The output is not exactly the same as the reference one, but it
should be good enough. I've attached the resulting svg file and what
librsvg renders (batik rendering looks the same).
Comments ?
Emmanuel.
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 2b2b2fe..f1cd4bc 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -1190,11 +1190,29 @@ emit_surface_pattern (cairo_svg_surface_t *surface,
static void
emit_pattern_stops (cairo_output_stream_t *output,
cairo_gradient_pattern_t const *pattern,
- double start_offset)
+ double start_offset,
+ cairo_extend_t extend)
{
double offset;
- unsigned int i;
-
+ unsigned int i, stop_index;
+
+ if (start_offset > 0.0
+ && (extend == CAIRO_EXTEND_REPEAT
+ || extend == CAIRO_EXTEND_REFLECT))
+ for (i = 0; i < pattern->n_stops; i++) {
+ offset = start_offset *
+ _cairo_fixed_to_double (pattern->stops[i].x);
+ stop_index = (extend == CAIRO_EXTEND_REPEAT) ? i : pattern->n_stops - i - 1;
+ _cairo_output_stream_printf (output,
+ "<stop offset=\"%f\" style=\""
+ "stop-color: rgb(%f%%,%f%%,%f%%); "
+ "stop-opacity: %f;\"/>\n",
+ offset,
+ pattern->stops[stop_index].color.red / 655.35,
+ pattern->stops[stop_index].color.green / 655.35,
+ pattern->stops[stop_index].color.blue / 655.35,
+ pattern->stops[stop_index].color.alpha / 65535.0);
+ }
for (i = 0; i < pattern->n_stops; i++) {
offset = start_offset + (1 - start_offset ) *
_cairo_fixed_to_double (pattern->stops[i].x);
@@ -1222,9 +1240,7 @@ emit_pattern_extend (cairo_output_stream_t *output,
_cairo_output_stream_printf (output, "spreadMethod=\"reflect\" ");
break;
case CAIRO_EXTEND_NONE:
- break;
case CAIRO_EXTEND_PAD:
- /* FIXME not implemented */
break;
}
}
@@ -1256,7 +1272,7 @@ emit_linear_pattern (cairo_svg_surface_t *surface,
cairo_matrix_invert (&p2u);
emit_transform (document->xml_node_defs, "gradientTransform", ">\n", &p2u);
- emit_pattern_stops (document->xml_node_defs ,&pattern->base, 0.0);
+ emit_pattern_stops (document->xml_node_defs ,&pattern->base, 0.0, CAIRO_EXTEND_NONE);
_cairo_output_stream_printf (document->xml_node_defs,
"</linearGradient>\n");
@@ -1290,13 +1306,8 @@ emit_radial_pattern (cairo_svg_surface_t *surface,
/* SVG doesn't have a start radius, so computing now SVG focal coordinates
* and emulating start radius by translating color stops.
* FIXME: Handle radius1 <= radius0 */
- if (pattern->base.base.extend == CAIRO_EXTEND_NONE) {
- fx = x0;
- fy = y0;
- } else {
- fx = (r1 * x0 - r0 * x1) / (r1 - r0);
- fy = (r1 * y0 - r0 * y1) / (r1 - r0);
- }
+ fx = (r1 * x0 - r0 * x1) / (r1 - r0);
+ fy = (r1 * y0 - r0 * y1) / (r1 - r0);
_cairo_output_stream_printf (document->xml_node_defs,
"<radialGradient id=\"radial%d\" "
@@ -1327,7 +1338,7 @@ emit_radial_pattern (cairo_svg_surface_t *surface,
"stop-opacity: 0;\"/>\n",
r0 / r1);
}
- emit_pattern_stops (document->xml_node_defs, &pattern->base, r0 / r1);
+ emit_pattern_stops (document->xml_node_defs, &pattern->base, r0 / r1, pattern->base.base.extend);
if (pattern->base.base.extend == CAIRO_EXTEND_NONE)
_cairo_output_stream_printf (document->xml_node_defs,
"<stop offset=\"1.0\" style=\""
-------------- next part --------------
A non-text attachment was scrubbed...
Name: radial-gradient-svg-argb32-out.jpg
Type: image/jpeg
Size: 46693 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20070305/db49f2cf/radial-gradient-svg-argb32-out-0001.jpg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: radial-gradient-svg-argb32-out.svg.zip
Type: application/zip
Size: 1567 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20070305/db49f2cf/radial-gradient-svg-argb32-out.svg-0001.zip
More information about the cairo
mailing list