[cairo] [PATCH 04/39] [OpenVG] Added linear gradient source.
tardyp at gmail.com
tardyp at gmail.com
Fri Jul 10 10:02:06 PDT 2009
From: Øyvind Kolås <pippin at gimp.org>
---
src/cairo-openvg-surface.c | 69 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/src/cairo-openvg-surface.c b/src/cairo-openvg-surface.c
index ecbd848..77cd5df 100644
--- a/src/cairo-openvg-surface.c
+++ b/src/cairo-openvg-surface.c
@@ -305,6 +305,67 @@ _cairo_openvg_cairo_matrix_to_openvg (const cairo_matrix_t *src,
dst[8] = /* w2 */ 0;
}
+static void
+_cairo_openvg_setup_linear_source (VGPaint paint,
+ cairo_linear_pattern_t *lpat)
+{
+ cairo_pattern_t *abspat = (cairo_pattern_t *) lpat;
+ cairo_matrix_t mat;
+ VGfloat linear[4];
+ double x0, y0;
+ double x1, y1;
+
+
+ cairo_pattern_get_matrix (abspat, &mat);
+
+ if (cairo_matrix_invert (&mat) == CAIRO_STATUS_INVALID_MATRIX)
+ {
+ /* FIXME: pass on error */
+ return;
+ }
+ x0 = _cairo_fixed_to_double (lpat->p1.x);
+ y0 = _cairo_fixed_to_double (lpat->p1.y);
+ x1 = _cairo_fixed_to_double (lpat->p2.x);
+ y1 = _cairo_fixed_to_double (lpat->p2.y);
+
+ cairo_matrix_transform_point (&mat, &x0, &y0);
+ cairo_matrix_transform_point (&mat, &x1, &y1);
+
+ linear[0] = x0;
+ linear[1] = y0;
+ linear[2] = x1;
+ linear[3] = y1;
+
+ vgSetParameteri (paint, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD);
+ vgSetParameteri (paint, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT);
+ vgSetParameterfv (paint, VG_PAINT_LINEAR_GRADIENT, 4, linear);
+
+ {
+ const cairo_gradient_pattern_t *pattern = &lpat->base;
+ VGint numstops = pattern->n_stops;
+ VGfloat *stops;
+ int i;
+
+ stops = malloc (sizeof (VGfloat) * numstops * 5);
+ if (stops == NULL)
+ {
+ return; /* FIXME: report error state */
+ }
+
+ for (i=0; i< numstops; i++)
+ {
+ stops[i*5 + 1] = pattern->stops[i].color.red;
+ stops[i*5 + 2] = pattern->stops[i].color.green;
+ stops[i*5 + 0] = pattern->stops[i].color.blue;
+ stops[i*5 + 3] = pattern->stops[i].color.alpha;
+ stops[i*5 + 4] = 1;
+ }
+
+ vgSetParameterfv (paint, VG_PAINT_COLOR_RAMP_STOPS, numstops * 5, stops);
+ free (stops);
+ }
+}
+
static void setup_source (VGPaint paint,
cairo_pattern_t *source)
{
@@ -318,6 +379,12 @@ static void setup_source (VGPaint paint,
solid->color.alpha};
vgSetParameterfv (paint, VG_PAINT_COLOR, 4, color);
}
+ else if (source->type == CAIRO_PATTERN_TYPE_LINEAR)
+ {
+ cairo_linear_pattern_t *lpat = (cairo_linear_pattern_t *)source;
+ _cairo_openvg_setup_linear_source (paint, lpat);
+ return;
+ }
else
{
printf ("not handling source of type: %i\n", source->type);
@@ -411,6 +478,7 @@ _cairo_openvg_surface_fill (void *asurface,
return CAIRO_STATUS_SUCCESS;
}
+#if 0
static cairo_int_status_t
_cairo_openvg_surface_show_glyphs (void *asurface,
cairo_operator_t op,
@@ -422,6 +490,7 @@ _cairo_openvg_surface_show_glyphs (void *asurface,
printf ("show_glyphs\n");
return CAIRO_STATUS_SUCCESS;
}
+#endif
static const struct _cairo_surface_backend
cairo_openvg_surface_backend = {
--
1.6.0.4
More information about the cairo
mailing list