[cairo] Some newbie question

Carl Worth cworth at cworth.org
Thu Dec 13 11:12:36 PST 2007


On Thu, 13 Dec 2007 19:44:10 +0100, "Tuom Larsen" wrote:
> I'm very new to Cairo, please bear with me:

Hi Tuom, welcome to cairo!

> - I don't really get the concept of Surfaces - can I convert between various
> surfaces? Say from Image to PDF? How? Create an Image, Create a PDF with the
> same dimensions and call cairo_paint? (btw, I'm using pycairo)

Yes, you can copy from one surface to another and you just described
how to do it, (along with cairo_set_source_surface). See:

	http://cairographics.org/FAQ/#paint_from_a_surface

Is there somewhere we could add a pointer to that page so you would
have found it? Or had you found that page and there's something we
could do to make it more clear?

> - Is there a generic/meta Surface I'm drawing to, and all the other Surfaces
> (Image, PDF) provide "mere" disk serialization in the format
> specified?

There is a meta surface, (which is precisely what it's called in the
cairo internals), for things like the PDF, PostScript, and SVG
backends, (and win32-printing). And yes, those simply do
serialization.

But for the image backend, the meta-surface is not involved, and every
drawing operation results immediately in changes to the pixel
buffer. Similarly, for xlib, quartz, and win32 backends, each drawing
operation results immediately in some call to the underlying system to
do some actual drawing, (no meta-surface involved).

> If so, is it also possible to serialize this generic Surface?

There's no cairo-specific serialization. But you can serialize to PDF,
PostScript, or SVG. Note that after you do that, cairo itself doesn't
provide de-serialization for you. But the poppler library can
de-serialize PDF files to cairo operations, and librsvg does the same
for SVG files. We don't currently have a good option for PostScript to
cairo though.

> And if not, how can I store an Image Surface and the load it some
> another time?

For any surface type, (not just image surfaces), you can save a
rasterized version of the content with cairo_surface_write_to_png and
load it later with cairo_image_surface_create_from_png.

> Thanks a lot in advance!

You're welcome. Do have lots of fun with cairo!

And let us know if there are things you see that could be added to the
FAQ or to other documentation.

-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/20071213/e27e2b3a/attachment.pgp 


More information about the cairo mailing list