[cairo] multiple paths

Dirk Schönberger dirk.schoenberger at sz-online.de
Mon Nov 5 08:23:29 PST 2007


> Hi,
>
> I have a list of measured values and want to plot them. For every x_i
> from the list I do cairo_line_to(i,x_i) and when I've processed the
> whole list I stroke. Simple.
>
> However, every x_i also has its own variance. And I want to plot a
> variance band around the line connecting the x_i's. For the code to be
> as efficient as possible I thought it's best when I iterate through
> the list of x_i's only once.
>
> I was thinking of a solution like this: make 3 cairo paths. For every
> x_i, line_to in path1, line_to(i,x_i - variance_x_i) in path2 and
> line_to (i,x_i + variance_x_i) in path three. At the end, stroke
> path1, reverse path3, concat path3 to path2 and close path2, stroke
> path2.
>
> Now for the questions:
> first: how to make these paths in cairo
> second: is this the way to do it? Or is it really clumsy? I feel I'm
> missing something.
>
> thanks for your input,
> CH

If I don't miss something important, I don't think your approach matches
well with Cairo's approach.
Cairo is a "stateful" graphics system where most of the interesting work
is done in one place, the Cairo context. Basically you create paths,
render it and forget it.
It is not assumed that paths are kept and rendered later, outside of the
cairro context. Cairo paths store device coordinates (instead of user
coordinates), and it is rather difficult to iterate over them using public
APIs.
There is only one active path at a given time (perhaps there are some more
internally used paths e.g. for clipping)

What you seem to want is an API where the graphical primitives are first
level objects, which are rendered to a target. However, this is outside
Cairo's scope.
If you want such things, you could write your own path implementation,
which can render itself to a cairo context. If you do this, you can keep
as many parallel paths as you like.

Regards
Dirk


More information about the cairo mailing list