[cairo] Wanted features in Cairo.

Kalle Vahlman kalle.vahlman at gmail.com
Wed Jun 27 22:35:58 PDT 2007

2007/6/27, Carl Worth <cworth at cworth.org>:
> On Mon, 25 Jun 2007 14:10:57 -0400, Miguel de Icaza wrote:
> > * Line caps
> >
> >     A feature that we are currently missing is the ability to use
> > different line caps for the beginning and end of a drawing.   Cairo
> > currently only offers one option: cairo_set_line_cap and we would need
> > to have separate versions for the beginning and end.
> So it would be fairly simple to add new cairo_set_initial_line_cap and
> cairo_set_final_line_cap functions, (and to define cairo_set_line_cap
> to simply set both to the same value). As has been brought up earlier,
> one question is whether you would want additional control for the
> capping of the dashes.
> And, meanwhile, something we've had on our TODO list for about forever
> is a means to allow the user to provide custom caps of some form or
> another, (for example, arrowheads). But I'm still not entirely sure
> what that support might look like.

The usual way to do custom caps would probably be to provide a
callback for rendering the cap with some needed data (direction etc)
and predetermined coordinate space, but I don't think that would "fit
in" with the current API too well (there isn't any callback-based API
in Cairo, right?).

Two other possibilites come to mind:

cairo_set_line_cap_source (cr, CAIRO_LINE_CAP_INITIAL, surface/pattern);

but this would get all funky with having to match the surface to the
line width beforehand.

But what about a similar approach that the groups have:

cairo_start_line_cap (cr, CAIRO_LINE_CAP_INITIAL);
cairo_rel_line_to(cr, -1,  0);
cairo_rel_line_to(cr,  1, -1);
cairo_rel_line_to(cr,  0,  2);

So start_line_cap() would set up the context so that current point
would be set at the end of the path and the scale would be adjusted so
that 1 unit would equal the current line width. The result would
probably have to be stored in some intermediate surface like the
groups do, so that you may have filled caps with stroked paths or just
some random graphics the user of your application chooses as the cap.

Does that sound feasible at all?

> Would that approach help simplify your code? Also, you might preface
> that with:
>         cairo_rectangle (cr, x, y, surface_width, surface_height);
>         cairo_clip (cr);
> to make sure that group stuff doesn't create an intermediate surface
> any larger than necessary, (we haven't yet optimized the group stuff
> to be clever with using minimal intermediate surfaces).

Oh, groups honor the clip size in creating the surface? How cool, I
assumed it always just duplicated the surface (which would be silly,
now that I think about it).

/me goes to modify some code to be more efficient

Kalle Vahlman, zuh at iki.fi
Powered by http://movial.fi
Interesting stuff at http://syslog.movial.fi

More information about the cairo mailing list