[cairo] [PATCH 05/39] [OpenVG] Added radial source, made the gradient stop setup a separate utility

tardyp at gmail.com tardyp at gmail.com
Fri Jul 10 10:02:07 PDT 2009


From: Øyvind Kolås <pippin at gimp.org>

function.
---
 src/cairo-openvg-surface.c |   95 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 74 insertions(+), 21 deletions(-)

diff --git a/src/cairo-openvg-surface.c b/src/cairo-openvg-surface.c
index 77cd5df..690b3a9 100644
--- a/src/cairo-openvg-surface.c
+++ b/src/cairo-openvg-surface.c
@@ -306,6 +306,32 @@ _cairo_openvg_cairo_matrix_to_openvg (const cairo_matrix_t *src,
 }
 
 static void
+_cairo_openvg_setup_gradient_stops (VGPaint paint,
+                                    cairo_gradient_pattern_t *pattern)
+{
+  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 + 0] = _cairo_fixed_to_double (pattern->stops[i].x);
+      stops[i*5 + 1] = pattern->stops[i].color.red;
+      stops[i*5 + 2] = pattern->stops[i].color.green;
+      stops[i*5 + 3] = pattern->stops[i].color.blue;
+      stops[i*5 + 4] = pattern->stops[i].color.alpha;
+    }
+  vgSetParameterfv (paint, VG_PAINT_COLOR_RAMP_STOPS, numstops * 5, stops);
+  free (stops);
+}
+
+static void
 _cairo_openvg_setup_linear_source (VGPaint paint,
                                    cairo_linear_pattern_t *lpat)
 {
@@ -340,30 +366,51 @@ _cairo_openvg_setup_linear_source (VGPaint paint,
   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;
+  _cairo_openvg_setup_gradient_stops (paint,
+                                      (cairo_gradient_pattern_t *) &lpat->base);
 
-    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;
-      }
+static void
+_cairo_openvg_setup_radial_source (VGPaint paint,
+                                   cairo_radial_pattern_t *rpat)
+{
+  cairo_pattern_t *abspat = (cairo_pattern_t *) rpat;
+  cairo_matrix_t   mat;
+  VGfloat radial[5];
+  double cx, cy;
+  double fx, fy;
 
-    vgSetParameterfv (paint, VG_PAINT_COLOR_RAMP_STOPS, numstops * 5, stops);
-    free (stops);
-  }
+
+  cairo_pattern_get_matrix (abspat, &mat);
+
+  if (cairo_matrix_invert (&mat) == CAIRO_STATUS_INVALID_MATRIX)
+    {
+      /* FIXME: pass on error */
+      return;
+    }
+  cx = _cairo_fixed_to_double (rpat->c1.x);
+  cy = _cairo_fixed_to_double (rpat->c1.y);
+  fx = _cairo_fixed_to_double (rpat->c2.x);
+  fy = _cairo_fixed_to_double (rpat->c2.y);
+
+  cairo_matrix_transform_point (&mat, &cx, &cy);
+  cairo_matrix_transform_point (&mat, &fx, &fy);
+
+  /* FIXME: if rpat->r1 != 0.0 return unsupported */
+
+  radial[0] = cx;
+  radial[1] = cy;
+  radial[2] = fx;
+  radial[3] = fy;
+  radial[4] = _cairo_fixed_to_double (rpat->r2);
+
+  vgSetParameteri (paint, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD);
+  vgSetParameteri (paint, VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT);
+  vgSetParameterfv (paint, VG_PAINT_RADIAL_GRADIENT, 5, radial);
+
+  _cairo_openvg_setup_gradient_stops (paint,
+                                      (cairo_gradient_pattern_t *) rpat);
 }
 
 static void setup_source (VGPaint paint,
@@ -385,6 +432,12 @@ static void setup_source (VGPaint paint,
       _cairo_openvg_setup_linear_source (paint, lpat);
       return;
     }
+  else if (source->type == CAIRO_PATTERN_TYPE_RADIAL)
+    {
+      cairo_radial_pattern_t *rpat = (cairo_radial_pattern_t *)source;
+      _cairo_openvg_setup_radial_source (paint, rpat);
+      return;
+    }
   else
     {
       printf ("not handling source of type: %i\n", source->type);
-- 
1.6.0.4



More information about the cairo mailing list