Graphics Programs Reference
In-Depth Information
Clipping
We can use a path, built in the usual way, to set the
clipping path
. From that point on,
only content within the path's area will be shown. This is done by using the
W
operator
(for a non-zero path) or
W*
operator (for an even-odd path).
The operator intersects the path given with the existing clipping path, so it can only be
used to make the clipping region smaller, not larger. The clipping path remains the
current path, so it can be used to stroke the outline of the clipping region using, for
example, the
S
operator. The
W
operator is a modifier to the painting operation, so if
we don't want to stroke the outline of the new clipping path, we must substitute the
no-op path painting operator
n
. Here's an example where we define a clipping path:
200 100 m 200 500 l 500 100 l h W S
Here we have defined a closed triangular path, set the clipping region using
W
and then
stroked it using
S
. The result of setting this clipping path and then drawing the same
scene as
Figure 5-2
can be seen in
Figure 5-10
.
Figure 5-10. Clipping to a path (the path is also shown)