#include <string.h>
#include <stdio.h>
#include <librsvg/rsvg.h>

void test (const char *s, int scale)
{
  GError *e = NULL;
  RsvgHandle *r = rsvg_handle_new_from_data ((const unsigned char *) s, strlen (s), &e);
  int n = 10 * scale;
  cairo_surface_t *u = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, n, n);
  cairo_t *c = cairo_create (u);
  cairo_scale (c, scale, scale);
  rsvg_handle_render_cairo (r, c);
  unsigned char *d = cairo_image_surface_get_data (u);
  int i, j;
  for (j = 0; j < n; j++)
    {
      for (i = 0; i < n; i++)
        putchar (d[(j * n + i) * 4] ? '*' : '.');
      putchar ('\n');
    }
  cairo_destroy (c);
  cairo_surface_destroy (u);
  g_object_unref (r);
}

const char *svg =
  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
  "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20001102//EN\" \"http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd\">"
  "<svg width=\"10\" height=\"10\">"
  "<defs>"
  "<radialGradient id=\"g1\">"
  "<stop offset=\"0\" style=\"stop-color:red\"/>"
  "<stop offset=\"1\" style=\"stop-color:green\"/>"
  "</radialGradient>"
  "</defs>"
  "<path d=\"m0,0 c0.5,0 0,1 -1,1\" fill=\"url(#g1)\"/>"
  "<rect width=\"5\" height=\"5\" fill=\"white\"/>"
  "</svg>";

int main ()
{
  printf ("Scale 1, wrong:\n");
  test (svg, 1);
  printf ("\nScale 2, OK:\n");
  test (svg, 2);
}
