1. rlineto

Appends a straight line segment to the current path using relative coordinates.

1.1. Syntax

dx dy rlineto → -

1.2. Stack Effects

Table 1. Before
Level Object

1

dy (number - vertical displacement)

0

dx (number - horizontal displacement)

Table 2. After
Level Object

(empty)

Stack cleared of operands

1.3. Description

rlineto (relative lineto) appends a straight line segment to the current path in the same manner as lineto. However, the number pair is interpreted as a displacement relative to the current point (x, y) rather than as an absolute coordinate. That is, rlineto constructs a line from (x, y) to (x + dx, y + dy) and makes (x + dx, y + dy) the new current point.

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

1.4. PostScript Level

Level 1 and later

1.5. Examples

Drawing a square
newpath
100 100 moveto
100 0 rlineto           % Right side
0 100 rlineto           % Top side
-100 0 rlineto          % Left side
closepath               % Bottom side
stroke
Drawing a staircase pattern
newpath
50 50 moveto
5 {
  20 0 rlineto          % Step tread
  0 20 rlineto          % Step riser
} repeat
stroke
Creating a zigzag
newpath
50 200 moveto
10 {
  20 30 rlineto
  20 -30 rlineto
} repeat
stroke

1.6. Common Use Cases

1.6.1. Drawing Regular Shapes

/drawPentagon {
  % Draws regular pentagon at current point
  /size exch def
  /angle 72 def
  gsave
  5 {
    size 0 rlineto
    angle rotate
  } repeat
  closepath
  grestore
} def

100 100 moveto
50 drawPentagon

1.6.2. Creating Relative Patterns

/zigzagLine {
  % width segments height
  /h exch def
  /n exch def
  /w exch def
  n {
    w 2 div h rlineto
    w 2 div h neg rlineto
  } repeat
} def

newpath
50 100 moveto
200 10 20 zigzagLine
stroke

1.6.3. Building Complex Paths Incrementally

/drawArrow {
  % length arrowhead-size
  /asize exch def
  /len exch def

  len 0 rlineto          % Shaft
  asize neg asize rlineto    % Upper barb
  asize asize neg rlineto    % Lower barb
} def

newpath
100 150 moveto
150 0 30 drawArrow
stroke

1.7. Common Pitfalls

Requires Current Point - rlineto requires an established current point. Use moveto first.
newpath
10 10 rlineto           % Error: nocurrentpoint
Displacements Not Absolute - The arguments are relative displacements (dx, dy). Negative values move in opposite directions.
100 100 moveto
50 0 rlineto            % Moves to (150, 100)
-25 0 rlineto           % Moves to (125, 100), not (-25, 100)
Ideal for Regular Patterns - rlineto excels at creating regular, repeating patterns where each segment relates to the previous one.

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

  • Displacements are in user space, transformed by CTM

  • More convenient than calculating absolute coordinates

  • Equivalent to: currentpoint transform dx dy add transform lineto

  • Successive rlineto calls build polylines efficiently

  • Negative displacements move backward or downward

1.10. Performance Considerations

  • No performance difference from lineto

  • Reduces calculation overhead in code

  • More maintainable for relative patterns

  • Can reduce rounding errors in repetitive patterns

1.11. See Also


Back to top

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