[cairo] Cairo and SVG

Carl Worth cworth at cworth.org
Fri Dec 21 14:58:25 PST 2007


On Fri, 21 Dec 2007 17:47:27 -0500, "Jake B" wrote:
> Can you tell me, are there any open source applications that make use of the
> SVG backend for Cairo? I'm trying to envision how it would be used, and it
> would be nice if I could see an example.

It's not really different than any other backend. You start with
cairo_svg_surface_create, then cairo_create and make as many other
cairo calls as you'd like. When you're done you have an SVG file.

Here's a simple pdf2svg program that illustrates the basics:

	http://www.cityinthesky.co.uk/pdf2svg.html

The cairo-specific parts of that application are no more than the
following:

    // Open the SVG file
    surface = cairo_svg_surface_create(svgFilename, width, height);
    drawcontext = cairo_create(surface);

    // Render the PDF file into the SVG file
    poppler_page_render(page, drawcontext);
    cairo_show_page(drawcontext);

    // Close the SVG file
    cairo_destroy(drawcontext);
    cairo_surface_destroy(surface);

Of course, poppler_page_render makes a lot of cairo calls, but they
are all ignorant of the fact that you are passing a cairo_t* that's
targetting an svg surface. They all work just as well if you were
targeting an image or an xlib surface, (or anything else).

And that's the important point about how cairo backends work. In
general, to switch from one backend to another, you should only have
to change the surface_create function and very little else.

Does that help?

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20071221/96db1fe3/attachment.pgp 


More information about the cairo mailing list