1. clip

Intersects the current clipping path with the current path using the non-zero winding rule.

1.1. Syntax

- clip → -

1.2. Stack Effects

Table 1. Before
Level Object

(empty)

No operands required

Table 2. After
Level Object

(empty)

No results

1.3. Description

clip intersects the inside of the current clipping path with the inside of the current path to produce a new, smaller current clipping path. The inside of the current path is determined by the normal PostScript non-zero winding number rule, while the inside of the current clipping path is determined by whatever rule was used at the time that path was created.

In general, clip produces a new path whose inside (according to the non-zero winding number rule) consists of all areas that are inside both of the original paths. The way this new path is constructed (the order of its segments, whether it self-intersects, etc.) is not specified.

clip treats an open subpath of the current path as though it were closed; it does not actually alter the path itself. It is permissible for the current path to be empty. The result of executing clip is always a non-empty clipping path, though it may enclose zero area.

Unlike fill and stroke, clip does not implicitly perform a newpath after it has finished using the current path.

1.4. PostScript Level

Level 1 and later

1.5. Examples

Simple rectangular clip
newpath
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath
clip
newpath

% Graphics are now clipped to rectangle
50 50 moveto
250 250 lineto
stroke  % Only portion inside clip is visible
Circular clip region
newpath
150 150 75 0 360 arc
closepath
clip
newpath

% Draw something that gets clipped
0 0 moveto
300 300 lineto
stroke
Multiple clip operations
% First clip
newpath
50 50 moveto
250 50 lineto
250 250 lineto
50 250 lineto
closepath
clip
newpath

% Second clip (intersection)
newpath
100 100 150 0 360 arc
closepath
clip
newpath

% Only intersection of both clips is visible

1.6. Common Use Cases

1.6.1. Creating Masked Regions

gsave
  % Create mask
  newpath
  100 100 80 60 link:/commands/references/arc/[`arc`]
  closepath
  clip
  newpath

  % Draw content
  % Only visible within mask
  50 50 200 200 rectfill
grestore

1.6.2. Text as Clip Path

/Helvetica-Bold findfont 120 scalefont setfont

gsave
  newpath
  50 100 moveto
  (CLIP) true charpath
  clip
  newpath

  % Fill with pattern visible through text
  0 10 300 {
    0 exch moveto
    300 0 rlineto
    stroke
  } for
grestore

1.6.3. Vignette Effect

gsave
  % Circular vignette
  newpath
  150 150 100 0 360 arc
  closepath
  clip
  newpath

  % Draw image or content
  0 0 300 300 rectfill
grestore

1.7. Common Pitfalls

Clipping Can Only Shrink - There is no way to enlarge the current clipping path except by grestore or initclip.
% First clip
newpath
50 50 100 100 link:/commands/references/arc/[`arc`]
clip

% Can't expand beyond this
newpath
0 0 200 200 link:/commands/references/arc/[`arc`]
clip  % Still limited to intersection
Path Not Cleared After clip - Unlike fill and stroke, the path remains after clip.
newpath
100 100 moveto
200 200 lineto
clip
% Path still exists!
% Must explicitly clear
newpath
Open Paths Are Implicitly Closed - Open subpaths are treated as closed for clipping.
newpath
100 100 moveto
200 100 lineto
200 200 lineto
% No closepath, but treated as closed
clip
newpath
Always Use with gsave/grestore - Bracket clip operations to restore the original clipping path:
gsave
  newpath
  100 100 50 0 360 arc
  clip
  newpath

  % Clipped drawing operations
  % ...
grestore
% Original clipping path restored

1.8. Error Conditions

Error Condition

[limitcheck]

Clipping path becomes too complex for implementation

1.9. Implementation Notes

  • The clipping path is maintained separately from the current path

  • Clipping is applied during rendering of fill, stroke, show, etc.

  • Complex clipping paths may degrade rendering performance

  • The clipping path can become arbitrarily complex through repeated clips

  • Some implementations may have limits on clipping path complexity

1.10. Graphics State Interaction

The clipping path is part of the graphics state and is affected by:

  • gsave - Saves current clipping path

  • grestore - Restores saved clipping path

  • initclip - Resets to device default

  • save/restore - Saves/restores with VM state

The clipping path affects:

  • fill and eofill - Clip filled area

  • stroke - Clip stroked lines

  • show and text operators - Clip character outlines

  • image and imagemask - Clip images

  • All painting operations

1.11. Winding Number Rule

clip uses the non-zero winding number rule:

  1. Draw a ray from the point in any direction

  2. Count crossings with path segments:

    • +1 for left-to-right crossings

    • -1 for right-to-left crossings

  3. If the total is non-zero, point is inside

This means path direction matters and can create solid fills from complex paths.

1.12. Best Practices

1.12.1. Always Pair with gsave/grestore

% Good practice
gsave
  newpath
  100 100 80 60 link:/commands/references/arc/[`arc`]
  closepath
  clip
  newpath

  % Clipped operations
  % ...
grestore
% Clip restored

1.12.2. Clear Path After clip

% Always clear path explicitly
newpath
100 100 moveto
200 200 lineto
closepath
clip
newpath  % Important!

% Now draw clipped content

1.12.3. Use Appropriate Winding Rule

% For simple clips, clip is fine
newpath
100 100 50 0 360 arc
closepath
clip
newpath

% For clips with holes, use eoclip
% (see eoclip documentation)

1.12.4. Limit Clipping Complexity

% Avoid excessive clip operations
% Bad: many successive clips
gsave
  clip1
  clip2
  clip3
  % ... many more clips
grestore

% Better: combine into single path when possible
gsave
  newpath
  % Construct complete clip path
  % ...
  clip
  newpath
grestore

1.13. Performance Considerations

  • Simple rectangular clips are fastest

  • Circular and polygonal clips are moderately fast

  • Complex paths with many segments are slower

  • Each additional clip operation adds overhead

  • Very complex clipping paths may significantly impact rendering performance

  • Consider simplifying clips when possible

1.14. Clipping Path Management

Setting Initial Clip
% At document start
gsave
  newpath
  50 50 moveto
  550 50 lineto
  550 750 lineto
  50 750 lineto
  closepath
  clip
  newpath

  % All document content
  % ...
grestore
Nested Clipping
gsave
  % Outer clip
  newpath
  50 50 200 200 link:/commands/references/arc/[`arc`]
  clip
  newpath

  gsave
    % Inner clip (intersection)
    newpath
    100 100 100 100 link:/commands/references/arc/[`arc`]
    clip
    newpath

    % Drawing here is clipped to intersection
    % ...
  grestore

  % Back to outer clip only
  % ...
grestore
% Original clip restored

1.15. See Also

  • eoclip - Clip using even-odd rule

  • clippath - Get current clipping path

  • rectclip - Clip to rectangles (Level 2)

  • initclip - Reset to device default

  • fill - Fill path

  • stroke - Stroke path

  • gsave - Save graphics state

  • grestore - Restore graphics state

  • newpath - Clear current path

  • closepath - Close current subpath


Back to top

Copyright © 2025 Ribose. PostScript is a trademark of Adobe. Distributed under the MIT License.