[cairo] Latest diagram - svgz file 51K

Baz brian.ewins at gmail.com
Sun Dec 16 05:30:03 PST 2007


On Dec 16, 2007 8:34 AM, Donn <donn.ingle at gmail.com> wrote:
> Baz,
>  Some feedback and some questions:
> > - "your path accrues on the mask layer". Not really.
> In previous posts I have mentioned this as my working metaphor and I have seen
> nothing, yet, to disabuse me of the idea - paths really *seem* to be placed
> on the "Mask" ( a nebulous internal thing that has no Object or reference on
> the user side of the API).

Ignoring alpha for the moment, the mask is a stencil that we paint
through. When you do move_to(0, 0); line_to(0, 10); line_to(10,0);,
does it have any effect on that stencil?
- If the next command was 'clip();', you'd see I wasn't doing anything
to the mask at all.
- If I said fill(), it would punch a triangular hole in the mask and
show you the source paint through that.
- If I said stroke(), it will score two line_width wide lines through
the mask (not a triangle, since the path isnt closed).
If you think of the mask as a stencil like this rather than an object
with properties, you'll see that its brought into existence by the
drawing operators, not the path operators.

Of course, describing the mask without alpha compositing like that, it
sounds pretty similar to the clip. But even without alpha, cairo
doesn't have stroke_to_path() yet, so you can't emulate stroke() with
clip().

The path itself is the nebulous internal concept you're looking for,
and it doesn't act like a layer. In fact it's more like the circle Tim
Robbins holds up in the Hudsucker Proxy where he says "y'know - for
kids!". The path was always a circle, the source was always extruded
plastic, but by changing the process he got hula hoops, frisbees and
bendy straws; the path is just a blueprint, not part of the
manufacturing machinery (the mask).

I'll stop with the ludicrous analogies now :)

> > - I don't think save(), restore() belong in the box with
> > transform/rotate/scale. They also save and restore the font, the clip
> > path, the stroke properties, etc. This box makes it look like they
> > don't affect those properties.
> This one interested me. My own major use of save/restore has been to build
> nested transforms for animation. I'm actually sitting here trying to figure
> out what use there would be for save/restore in terms of font, paths etc.
>  I am tired, so my imagination is on the fritz. It seems that there's some use
> for a kind of redo/undo thing, or maybe re-drawing old stuff in new places,
> but that's better covered by push_group et al.
>  Can you give me an example?

Sure. save/restore are a useful way to break down drawing code into
independent functions, ie

my_function() {
 save();
 change the clip, transform, font size, source;
 do some drawing;
 call some other functions;
 restore();
}

If you don't do something like this your functions quickly become
interdependent. So this isn't about reuse, its about isolation of
drawing code. But the thing I most commonly use save/restore for is to
manipulate the clip. An example of this in your own (previous) diagram
is the rounded rectangles with the purple area at the top for the
title. The way I drew these in my lua version was roughly like this:

draw_box_with_title() {
 fill a white rectange;
 fill a purple rectangle at the top of the white rectangle;
 draw black text on the box.
}

draw_rounded_box_with_title() {
 save
 construct a rounded rect path
 clip to the rounded rect
 -- this now draws the box rounded
 draw_box_with_title
 restore
 -- if the rounded clip was still in effect only the inside of
 -- this stroke would have appeared...
 stroke the rounded rect with yellow
 -- and if the rounded clip hadn't been restored when I returned from
 -- here, nothing else would appear outside the box.
}

-Baz

>
> /d
>


More information about the cairo mailing list