[cairo] Pattern rendering questions

Carl Worth cworth at cworth.org
Mon Sep 8 14:41:05 PDT 2008


On Fri, 2008-08-22 at 09:39 +0200, Dirk Schönberger wrote:
> Or you could coumbine both lines of the cross into one path which is
> rendered as one element. IIRC, this would be something like

That's an excellent suggestion.

> cairo_moveto(cr,0,0);
> cairo_lineto(cr,w,h);
> criro_close_path(cr);
> cairo_moveto(cr,0,h);
> cairo_lineto(cr,w,0);
> cairo_close_path(cr);
> cairo_stroke();

And the code is really close. The only change you want is to eliminate
those two calls to cairo_close_path, (and add some underscores), giving:

cairo_move_to(cr,0,0);
cairo_line_to(cr,w,h);
cairo_move_to(cr,0,h);
cairo_line_to(cr,w,0);
cairo_stroke(cr);

Although in this specific case there probably wouldn't be a noticeable
effect, the cairo_close_path calls could get quite confusing in other
cases. What cairo_close_path does is add another line_to segment from
the current point back to the initial point of the current subpath, (and
add a join there so there are no caps).

It looks like Dirk was thinking it did "end the current subpath", but it
doesn't, (and cairo_move_to does do "begin a new subpath", so there's no
"end the current subpath" call needed).

I hope that helps,

-Carl




More information about the cairo mailing list