1. lineto
Appends a straight line segment to the current path.
1.2. Stack Effects
| Level | Object |
|---|---|
1 |
|
0 |
|
| 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.5. Examples
newpath
100 100 moveto
300 100 lineto % Horizontal line
stroke
newpath
100 100 moveto
200 100 lineto % Base
150 200 lineto % Right side
closepath % Left side (automatic)
fill
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.7. Common Pitfalls
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)
1.8. Error Conditions
| Error | Condition |
|---|---|
[ |
Path becomes too complex for implementation |
[ |
Current path is empty (no current point defined) |
[ |
Fewer than 2 operands on stack |
[ |
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
linetooperations create a polyline -
Line appearance depends on current line width, dash pattern, and line cap settings