[cairo] fill pre-existing png polygons? (tried formatting better)
M Joonas Pihlaja
jpihlaja at cc.helsinki.fi
Mon Aug 9 12:12:00 PDT 2010
On Mon, 9 Aug 2010, Daniel Goldman wrote:
> What might be some example cairo functions that cache surfaces? I think what you
> are saying is maybe I can just draw once, and then copy to the png and pdf
Yeah, almost exactly that. In the upcoming 1.10 release exactly this
is possible and you'll be able to use a "recording surface" instead of
a "similar surface" to capture drawing commands for later replay.
This doesn't give you any speed benefits like using a similar surface
For the moment, however, you'd need to create an image surface for
caching the drawing when you're making a png map and a pdf surface for
caching when making a pdf map. You can create the right kind of
surface using the function cairo_surface_create_similar(): this takes
a surface and produces a new empty surface of the same kind (this is
what the API means by "similar") as the one you gave it. Then you'd
draw onto your polygons onto the similar surface normally once, and
when you want to reuse your drawing later, you'd use
cairo_set_source_surface() and cairo_paint() (or perhaps cairo_fill())
on your target context to copy the previous rendering.
> I have the png polygon coordinates as integers, and the pdf
> coordinates as doubles. Maybe I might draw with the doubles, and then copy the
> surface to the png map, possibly resizing if a bigger or smaller map is needed.
I'm not entirely sure what you mean here. Cairo always takes polygon
coordinates as doubles.
More information about the cairo