1. lineto

Appends a straight line segment to the current path.

1.1. Syntax

x y lineto → -

1.2. Stack Effects

Table 1. Before
Level Object

1

y (number - endpoint y-coordinate)

0

x (number - endpoint x-coordinate)

Table 2. After
Level Object

(empty)

Stack cleared of operands

1.3. Description

lineto appends a straight line segment to the current path. The line extends from the current point to the point (x, y) in user space; (x, y) then becomes the new current point.

If the current point is undefined because the current path is empty, lineto executes the [nocurrentpoint] error.

The coordinates are interpreted as user space coordinates and are transformed by the current transformation matrix (CTM) when the path is constructed.

1.4. PostScript Level

Level 1 and later

1.5. Examples

Drawing a simple line
newpath
100 100 moveto
300 100 lineto           % Horizontal line
stroke
Drawing a triangle
newpath
100 100 moveto
200 100 lineto           % Base
150 200 lineto           % Right side
closepath                % Left side (automatic)
fill
Drawing a polyline
newpath
50 50 moveto
100 150 lineto
150 100 lineto
200 200 lineto
250 50 lineto
stroke

1.6. Common Use Cases

1.6.1. Drawing Rectangles

/drawRect {              % x y width height
  /h exch def
  /w exch def
  /y exch def
  /x exch def
  newpath
  x y moveto
  x w add y lineto
  x w add y h add lineto
  x y h add lineto
  closepath
} def

100 100 200 150 drawRect
stroke

1.6.2. Creating Grid Lines

% Draw vertical lines
0 10 500 {
  dup 0 moveto
  500 lineto
} for
stroke

% Draw horizontal lines
0 10 500 {
  0 exch moveto
  500 exch lineto
} for
stroke

1.6.3. Connecting Points

/points [
  100 100
  200 150
  300 100
  400 200
] def

newpath
points 0 get points 1 get moveto
2 2 points length 1 sub {
  /i exch def
  points i get points i 1 add get lineto
} for
stroke

1.7. Common Pitfalls

No Current Point - lineto requires an established current point. Always use moveto first.
newpath
200 200 lineto           % Error: nocurrentpoint
Coordinates Not Cumulative - Unlike rlineto, coordinates are absolute positions, not offsets.
100 100 moveto
50 50 lineto             % Goes to (50, 50), not (150, 150)
Use for Straight Segments - For curved paths, use curveto or arc instead of approximating with many short line segments.

1.8. Error Conditions

Error Condition

[limitcheck]

Path becomes too complex for implementation

[nocurrentpoint]

Current path is empty (no current point defined)

[stackunderflow]

Fewer than 2 operands on stack

[typecheck]

Operands are not numbers

1.9. Implementation Notes

  • Creates a straight line segment in device space after CTM transformation

  • The endpoint becomes the new current point

  • Lines are not rendered until a painting operator is executed

  • Multiple consecutive lineto operations create a polyline

  • Line appearance depends on current line width, dash pattern, and line cap settings

1.10. Performance Considerations

  • Very efficient for straight segments

  • Large numbers of line segments may hit implementation limits

  • For complex paths, consider simplification algorithms

  • Straight lines are faster to render than curves

1.11. See Also


Back to top

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