1. setlinecap

Sets the line cap style for stroking operations.

1.1. Syntax

int setlinecap → –

1.2. Stack Effects

Table 1. Before
Level Object

0

int (0, 1, or 2)

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

Level 1 and later

1.5. Examples

Different cap styles
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
Impact on short lines
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.6. Common Use Cases

1.6.1. Technical Drawing

0 setlinecap  % Butt - precise endpoints
0.5 setlinewidth
drawDiagram

1.6.2. Artistic Lines

1 setlinecap  % Round - smooth appearance
drawCurves

1.6.3. Dotted Lines

1 setlinecap  % Round caps for dots
[0 5] 0 setdash
stroke

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

[rangecheck]

int not 0, 1, or 2

[stackunderflow]

No operand on stack

[typecheck]

Operand not an integer

1.9. Line Cap Styles

Visual comparison (10-unit width)
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


Back to top

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