1. newpath

Initializes the current path to empty, making the current point undefined.

1.1. Syntax

- newpath → -

1.2. Stack Effects

Table 1. Before
Level Object

(empty)

No operands required

Table 2. After
Level Object

(empty)

No results

1.3. Description

newpath initializes the current path to be empty, causing the current point to become undefined.

This operator is typically used at the beginning of a path construction sequence to ensure that no leftover path segments from previous operations interfere with the new path being constructed.

After newpath, the first path construction operation must be moveto (or arc, which can start without a current point) to establish a current point before using operations like lineto or curveto.

1.4. PostScript Level

Level 1 and later

1.5. Examples

Starting a new path
newpath
100 100 moveto
200 200 lineto
stroke
Multiple independent paths
% First path
newpath
100 100 moveto
200 100 lineto
stroke

% Second path (independent)
newpath
100 200 moveto
200 200 lineto
stroke
Clearing previous path
newpath
100 100 moveto
200 200 lineto
% Decide not to use this path
newpath                  % Discard it

% Start fresh
150 150 moveto
250 250 lineto
stroke

1.6. Common Use Cases

1.6.1. Starting Every Drawing Operation

/drawCircle {
  % x y radius
  /r exch def
  /y exch def
  /x exch def

  newpath
  x y r 0 360 arc
  closepath
  fill
} def

100 100 50 drawCircle
200 200 75 drawCircle

1.6.2. Separating Path Construction from Painting

% Define shape
/myShape {
  newpath
  100 100 moveto
  200 100 lineto
  200 200 lineto
  100 200 lineto
  closepath
} def

% Paint it multiple times
gsave
myShape fill
grestore

gsave
2 setlinewidth
myShape stroke
grestore

1.6.3. Clearing Unwanted Paths

% Complex path construction with error checking
newpath
{
  % Some path construction that might fail
  complexPathOperation
} stopped {
  % Error occurred - clear path and try alternative
  newpath
  simplePathFallback
} if

1.7. Common Pitfalls

No Current Point After newpath - After newpath, you must use moveto before lineto, curveto, etc.
newpath
200 200 lineto           % Error: nocurrentpoint
Painting Operators Don’t Clear Path - Unlike painting operators in some graphics systems, PostScript’s stroke and fill do not automatically clear the path. Use newpath explicitly.
newpath
100 100 moveto
200 200 lineto
stroke
% Path still exists!
fill                     % Fills the same path again

% Better practice:
newpath
100 100 moveto
200 200 lineto
stroke
newpath                  % Explicitly clear
Use at Start of Path Procedures - Always begin path construction procedures with newpath to ensure a clean slate.

1.8. Error Conditions

None. newpath cannot generate errors.

1.9. Implementation Notes

  • Clears all subpaths from the current path

  • Makes the current point undefined

  • Does not affect the graphics state otherwise

  • Very lightweight operation

  • Does not consume or produce any stack values

  • Idempotent: calling newpath multiple times has same effect as calling once

1.10. Interaction with Graphics State

newpath only affects the current path. It does not change:

  • Current transformation matrix (CTM)

  • Current color

  • Line width or dash pattern

  • Clipping path

  • Current font

  • Any other graphics state parameters

1.11. Best Practices

1.11.1. Always Start with newpath

% Good practice
/drawShape {
  newpath
  % ... path construction ...
  stroke
} def

1.11.2. Separate Concerns

% Define the path
/trianglePath {
  newpath
  100 100 moveto
  200 100 lineto
  150 200 lineto
  closepath
} def

% Use it in different ways
trianglePath fill
trianglePath stroke
trianglePath clip

1.11.3. Clean Up After Path Operations

% Create temporary path
gsave
newpath
% ... construct complex path ...
clip                     % Use for clipping

% Draw clipped content
% ...

grestore                 % Restore, including path
newpath                  % Start fresh

1.12. Performance Considerations

  • Extremely fast operation

  • No memory allocation involved

  • No computational overhead

  • Should be used liberally for code clarity

  • Does not affect rendering performance

1.13. See Also


Back to top

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