vegebond
vegebond

Reputation: 337

What is the proper technique for using the postscript 'clip' command to print multiple fields within a document?

My first clip seems to be working properly, but the second string isn't printing at all.

newpath
20 20 moveto
0 24 rlineto
50 0 rlineto
0 -24 rlineto
closepath clip
20 20 moveto
(Hello World) show

newpath
80 20 moveto
0 24 rlineto
50 0 rlineto
0 -24 rlineto
closepath clip
80 20 moveto
(Hello Again) show

Upvotes: 3

Views: 616

Answers (2)

Lad
Lad

Reputation: 11

I believe you make a mistake in what you think the effect of a clip path is. If a clip path is set, it will influence and clip all painting operations which follow. I.e. all painting operations (fill, stroke, show, etc.) are limited to painting within the current clip path which is in effect at the time they are executed. You can remove the clippath after that painting operation by calling grestore, and set a new one for the next painting operation(s).

/Helvetica 12 selectfont
gsave
    <construct the desired clip path with moveto, lineto, whatever>
    clip
    newpath
    20 20 moveto
    (Hello!) show % cannot paint outside the current clippath
grestore
% now no clippath is in effect
gsave
    <construct the desired clip path somewhere else>
    clip
    newpath
    80 20 moveto
    (Hello again!) show
grestore

Note that unlike stroke or fill etc., the clip operator does not remove the current path, which is why the clip operator is almost always followed by the newpath operator.

Upvotes: 1

beginner6789
beginner6789

Reputation: 605

The first clip allows painting within the enclosed area. The second clip is already outside the allowed area. See the PostScript Language Reference Manual:

PSLRM3 at 4.4.2 Clipping Path: The graphics state also contains a clipping path that limits the regions of the page affected by the painting operators. The closed subpaths of this path define the area that can be painted. Marks falling inside this area will be applied to the page; those falling outside it will not.

Clip: There is no way to enlarge the current clipping path (other than by initclip or initgraphics) or to set a new clipping path without reference to the current one. The recommended way of using clip is to bracket the clip and the sequence of graphics to be clipped with gsave and grestore. The grestore will restore the clipping path that was in effect before the gsave. The setgstate operator can also be used to reset the clipping path to an earlier state.

EDIT: This might be useful:

%!

/Helvetica 12 selectfont
gsave
20 20 moveto
0 24 rlineto
50 0 rlineto
0 -24 rlineto
closepath
80 20 moveto
0 24 rlineto
50 0 rlineto
0 -24 rlineto
closepath
clip
clippath 0.8 setgray fill
0 setgray
20 20 moveto
(Hello World) show
80 20 moveto
(Hello Again and Again) show
grestore
showpage

Upvotes: 2

Related Questions