1. currentlinecap

Returns current line cap style.

1.1. Syntax

– currentlinecap → int

1.2. Stack Effects

Table 1. Before
Level Object

(empty)

Table 2. After
Level Object

0

int (0, 1, or 2)

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.4. PostScript Level

Level 1 and later

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.6.2. Cap-Dependent Rendering

/DrawLineCap {
  currentlinecap
  dup 0 eq {
    % Butt - draw arrow
    drawArrow
  } if
  dup 1 eq {
    % Round - draw circle
    drawCircle
  } if
  2 eq {
    % Square - draw square
    drawSquare
  } if
} def

1.6.3. Style Detection

/IsRoundCap {
  currentlinecap 1 eq
} def

IsRoundCap {
  % Use round cap drawing
} {
  % Use other cap drawing
} ifelse

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.8. Error Conditions

Error Condition

[stackoverflow]

No room on operand stack

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.10. Line Cap Styles

Butt (0):     ├─────┤
Round (1):    (─────)
Square (2):   [─────]

1.11. See Also


Back to top

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