[Xr] Clipping and a crazy idea for the fundamental operator
cworth at east.isi.edu
Thu May 1 08:54:50 PDT 2003
I started working on a new XrClip function yesterday, and I uncovered
an interesting problem.
The semantics of XrClip is that it appends the current path to the
"clipping path" within the Xr graphics state. Then, all subsequent
drawing commands are clipped by the clipping path.
I've committed a very preliminary, (and rather broken), implementation
if anyone wants to look. It doesn't do the right thing when XrClip is
called multiple times, and currently only strokes are clipped, not
fills, images, or text. Those things should be easy enough to fix.
But now, the interesting problem: the simple implementation I started
playing with just fills the current path to a "clip surface" and
subsequently uses that surface as the mask argument for later
Xc/Render compositing operations.
As a reminder, the fundamental Xc/Render compositing operation is:
dst = (src IN mask) OP dst
The Xr clipping works just fine when OP is SRC or OVER, but it gives
an undesirable result when OP == IN:
dst = (src IN mask) IN dst
The result of this operation is that dst will be cleared everywhere
that mask has 0 alpha. This is counterintuitive from the way I wanted
to use mask which is to restrict the modification of dst to the region
in which mask has non-zero alpha. Instead, this operation guarantees
that dst will be modified everywhere outside the region of interest.
It occurs to me that PostScript does not have a similar problem since
its painter's model could be implemented as:
dst = (src IN mask) SRC dst
and the Plan 9 window system also doesn't have the problem since it
dst = (src IN mask) OVER dst
I could work around the problem within Xr, but it might make sense to
push the fix lower. I don't think that "(src IN mask) IN dst" would be
very useful in any situation. Something more useful would be a new
dst = (src RESTRICT_OP mask) OP dst
where RESTRICT_OP is defined appropriately so that the region affected
by the outer compositing is restricted to mask. For example, when OP
is OVER or SRC, RESTRICT would be IN, but when OP is IN, RESTRICT
would be a new operator, (whose behavior I haven't yet defined
So, there are my thoughts, midway through the resolution of this
problem. Sorry for the length.
USC Information Sciences Institute cworth at isi.edu
More information about the cairo