[cairo] SVG Newbie

Baz brian.ewins at gmail.com
Tue May 29 11:10:39 PDT 2007


On 29/05/07, Peter Laurens <peterlaurenspublic at gmail.com> wrote:
> Hi, I am new to Cairo, and am having some trouble getting the basics
> down about rendering SVGs.
>
> I have attempted to take the example snippet and just use it to
> render to an SVG file to a PNG, that's all my needs are really. Here
> is my code:
>
> #include <stdio.h>
> #include <cairo.h>
> #include <cairo-svg.h>
^ I think you mean:
#include <svg-cairo.h>

>
> int main (int argc, char const* argv[])
> {
>         // 1
>         cairo_surface_t *surface;
>         surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 250, 100);
>         cairo_t *cr;
>         cr = cairo_create(surface);
>
>         // 2
>         svg_cairo_t  *svgc;
>         unsigned int  w, h;
>
>         snippet_normalize (cr, width, height);
>
>         svg_cairo_create (&svgc);
>
>         svg_cairo_parse (svgc, "barChart.svg");
>         svg_cairo_get_size (svgc, &w, &h);
>         cairo_scale (cr, 1.0/w, 1.0/h);
>         svg_cairo_render (svgc, cr);
>
>         svg_cairo_destroy (svgc);
>
>         // 3
>         cairo_destroy(cr);
>         cairo_surface_write_to_png(surface, "output.png");
>         cairo_surface_destroy(surface);
>
>         return 0;
> }
>
> Now there are a couple obvious things there that are going to cause
> compile errors I know, like I haven't set the variables 'width' and
> 'height', but I get problems with some of the SVG functions, here's
> what the compiler says:
>
> cairo_test.c: In function 'main':
> cairo_test.c:16: error: 'svg_cairo_t' undeclared (first use in this
> function)
> cairo_test.c:16: error: (Each undeclared identifier is reported only
> once
> cairo_test.c:16: error: for each function it appears in.)
> cairo_test.c:16: error: 'svgc' undeclared (first use in this function)
> cairo_test.c:19: warning: implicit declaration of function
> 'snippet_normalize'
> cairo_test.c:19: error: 'width' undeclared (first use in this function)
> cairo_test.c:19: error: 'height' undeclared (first use in this function)
> cairo_test.c:21: warning: implicit declaration of function
> 'svg_cairo_create'
> cairo_test.c:23: warning: implicit declaration of function
> 'svg_cairo_parse'
> cairo_test.c:24: warning: implicit declaration of function
> 'svg_cairo_get_size'
> cairo_test.c:26: warning: implicit declaration of function
> 'svg_cairo_render'
> cairo_test.c:28: warning: implicit declaration of function
> 'svg_cairo_destroy'
>
> Can anyone help advise me on what I've done wrong here - I'm also
> unsure of my using the SVG stuff in relation to the cairo surface etc.
>
> Any help is much appreciated,
>
> Thanks in advance,
>
> - Peter
>
>
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://cairographics.org/cgi-bin/mailman/listinfo/cairo
>


More information about the cairo mailing list