[cairo] Cairo is non-deterministic?

Carl Worth cworth at cworth.org
Tue Jan 3 09:24:08 PST 2006

On Mon, 2 Jan 2006 14:48:34 +0100 (CET), Dirk Schönberger wrote:
> This sounds rather unexpected. From what I remember, the current path was
> part of the Gstate in the Postscript and PDF rendering models.

The current path is part of the gstate in Postscript, but it is not in

Early versions of cairo (pre 1.0) did have the path as part of the
gstate, but we changed this to make it easier to write path-creating
functions that can locally modify the CTM within a save/restore block.

Not having the path as part of the gstate also reduces the amount of
data copying needed for cairo_save quite a lot.

Before we made this decision we decided that the most common usage
taking advantage of path-in-gstate was filling then stroking the same
path in two different colors. With path-in-gstate this would look

	/* ... create path ... */

	cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); /* fill color */
	cairo_save (cr);
	cairo_fill (cr);
	cairo_restore (cr);

	cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); /* stroke color */
	cairo_stroke (cr);

With PDF, this operation is made possible by having both a stroke
color _and_ a fill color within the gstate, and by adding a new
fill_and_stroke operation in addition to fill and stroke.

We didn't like that approach at all, so instead we added
cairo_stroke_preserve and cairo_fill_preserve which are identical to
cairo_stroke and cairo_fill except that they don't consume the current
path. So with cairo, the correct way to perform a fill then stroke
operation is:

	/* ... create path ... */

	cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); /* fill color */
	cairo_fill_preserve (cr);

	cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); /* stroke color */
	cairo_stroke (cr);

We also added cairo_clip_preserve which helps eliminate a source of
confusion in the original PostScript model (the fact that fill and
stroke consume the path but clip does not). With cairo now, all three
operations are available in path-consuming and path-preserving
variants so that's a lot less confusing.

I hope that explanation helps.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20060103/7dcd6c68/attachment.pgp

More information about the cairo mailing list