1. setlinecap
Sets the line cap style for stroking operations.
1.2. Stack Effects
| Level | Object |
|---|---|
0 |
|
| Level | Object |
|---|---|
(empty) |
Line cap parameter set |
1.3. Description
setlinecap sets the line cap parameter to int, which must be 0, 1, or 2. This controls the shape of line ends for open subpaths painted by [stroke].
Cap styles: * 0 = Butt cap: squared off at endpoint (no projection) * 1 = Round cap: semicircular arc with diameter = line width * 2 = Projecting square cap: extends half line width beyond endpoint
1.5. Examples
5 setlinewidth
0 setlinecap % Butt
0 10 moveto 100 10 lineto stroke
1 setlinecap % Round
0 20 moveto 100 20 lineto stroke
2 setlinecap % Square
0 30 moveto 100 30 lineto stroke
10 setlinewidth
1 setlinecap
50 50 moveto 50 50 lineto stroke % Draws circle
0 setlinecap
60 50 moveto 60 50 lineto stroke % Draws nothing (zero-length)
1.7. Common Pitfalls
| Affects Line Length - Round and square caps extend beyond path endpoints. |
10 setlinewidth
2 setlinecap % Square
0 0 moveto 100 0 lineto stroke
% Line extends from -5 to 105 (not 0 to 100)
| Closed Paths Unaffected - Line caps only apply to open subpaths. |
% Rectangle (closed path)
0 0 moveto 100 0 lineto 100 100 lineto 0 100 lineto closepath
2 setlinecap stroke % Caps not visible (path closed)
| Use Round for Dots - Round caps make perfect circles for zero-length lines. |
1.8. Error Conditions
| Error | Condition |
|---|---|
[ |
int not 0, 1, or 2 |
[ |
No operand on stack |
[ |
Operand not an integer |
1.9. Line Cap Styles
Butt (0): ├─────────┤
Round (1): (──────────)
Square (2): [──────────]
1.10. Implementation Notes
-
Default value: 0 (butt)
-
Applies to all subsequent stroke operations
-
Does not affect closed subpaths
-
Fast parameter setting
1.11. See Also
-
setlinejoin- Set corner style -
setlinewidth- Set line width -
currentlinecap- Get current cap -
Stroke operations (to be documented)