Copy link to clipboard
Copied
I have defined a clipping path and then defined an object (closed path) to be filled protected within a gsave/grestore block. The clipping path should clip the object and leave the remaining object filled within a the unfilled background of the clipping path. But the result is the entire clipping path is filled. How do I stop this?
An example is:
/inch {72 mul } def
/triangle {gsave .9 setgray
0 inch 0 inch moveto
5 inch 0 inch lineto
2.5 inch 5 inch lineto
0 inch 0 inch lineto fill 0 setgray
0 inch 0 inch moveto
5 inch 0 inch lineto
2.5 inch 5 inch lineto
0 inch 0 inch lineto stroke
grestore} def
/SquarePath {newpath
1 inch 0 inch moveto
3 inch 0 inch lineto
3 inch 8 inch lineto
1 inch 8 inch lineto
1 inch 0 inch lineto closepath} def
% draw it
1 inch 1 inch translate
SquarePath clip
triangle
showpage
Any ideas? Thanks in advance
Copy link to clipboard
Copied
Hi.
One of clip's surprises is that it doesn't erase the current path, as do fill and stroke. Add a call to newpath immediately after the clip and the code should behave as you intended.
By the way, in case you haven't stumbled on this before, you can simplify your triangle code significantly by using another, nested, gsave-grestore pair:
/triangle {gsave .9 setgray
gsave
0 inch 0 inch moveto
5 inch 0 inch lineto
2.5 inch 5 inch lineto
0 inch 0 inch lineto fill
grestore
stroke
grestore} def
Hope this helps.
- John
-------
John Deubert
Acumen Training
PostScript & PDF consulting and training
www.acumentraining.com
Copy link to clipboard
Copied
Thank you, John. Great tip. It worked like a charm. I really appreciate the comment about clip not clearing the path.
Again, thanks for the tips, and for the fast response.
John Hobbie