[cairo] Some newbie question

Tuom Larsen tuom.larsen at gmail.com
Thu Dec 13 13:01:02 PST 2007


Thanks for the reply!


On Dec 13, 2007 8:12 PM, Carl Worth <cworth at cworth.org> wrote:

> 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?


I found that page - I was just not sure whether this is the right way of
converting between various surfaces and if one shouldn't use some kind of
(binary) stream object instead. In another words, I was looking for
"convert" instead of "copy". However, you introduced another question - more
on that bellow, please.


>
>
> > - 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 I understand correctly (maybe I even read it somewhere), there are
basically to "kinds" of surfaces - the ones which do preserve drawing
operations (PDF, SVG, ...) and the ones which do not (xlib, image, ...). Is
it so?

Then, the another question is, if I draw to Image surface and duplicate it
via the method from FAQ to PDF surface, what happens? In PDF, will there be
an embeded pixel-image or all the vector-paths and lines and curves which
were used to draw the Image surface? Because, sorry if I'm misunderstading
you, it seems to me now, that in PDF there will be that pixel image, instead
of vector-paths as I originally thought. And that's also how it comes to the
question how to convert between surfaces.



>
>
> > 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.


My original thought was that I will create an Image (or meta) surface, do
all the drawing, then serialize this surface via programming language (e.g.
in python via pickle) and then reuse. In that way i wouldn't need to use
Poppler or librsvg.



>
>
> > Thanks a lot in advance!
>
> You're welcome. Do have lots of fun with cairo!


Thanks!


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


Well, the mailing list archive is pretty good and the site too, but since
you asked :).. Maybe a wiki and some more diagrams would be useful but now I
see that both are being worked on. So, actually, nothing really. ... Ok, one
thing: I found a tiny bit confusing all this "samples", "recipes",
"snippets", "examples" - I wasn't really sure where to look for what.


Thanks once more!

>
>
> -Carl
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20071213/8fa7e11f/attachment.html 


More information about the cairo mailing list