Table of Contents
1. currentlinecap
Returns current line cap style.
1.2. Stack Effects
| Level | Object |
|---|---|
(empty) |
– |
| Level | Object |
|---|---|
0 |
|
1.3. Description
currentlinecap returns the current line cap parameter from the graphics state. This is the value most recently set by setlinecap.
Cap styles:
-
0 = Butt cap (squared off at endpoint)
-
1 = Round cap (semicircular)
-
2 = Projecting square cap (extends beyond endpoint)
1.5. Examples
Querying current line cap
1 setlinecap
currentlinecap
% Stack: 1
Saving and restoring line cap
currentlinecap % Save
/savedCap exch def
2 setlinecap % Change to square
drawLines
savedCap setlinecap % Restore
Conditional drawing
currentlinecap 1 eq {
% Round caps - draw dots
drawDottedLine
} {
% Other caps - draw dashed
drawDashedLine
} ifelse
1.6. Common Use Cases
1.6.1. Cap State Preservation
/DrawWithRoundCaps {
currentlinecap % Save
1 setlinecap % Round
drawShape
setlinecap % Restore
} def
1.7. Common Pitfalls
| Only Applies to Open Paths - Line caps don’t affect closed paths. |
2 setlinecap
currentlinecap % Returns 2
% But closed paths won't show square caps
| Use for Dots - Round caps (1) with zero-length lines make perfect dots. |
1.9. Implementation Notes
-
Very fast query operation
-
No modification to graphics state
-
Returns integer 0, 1, or 2
-
Default value is typically 0 (butt)
-
Widely supported (Level 1)
1.11. See Also
-
setlinecap- Set line cap style -
currentlinejoin- Get line join style -
currentlinewidth- Get line width -
currentdash- Get dash pattern