1. setlinewidth

Sets the line width for stroking operations.

1.1. Syntax

num setlinewidth → –

1.2. Stack Effects

Table 1. Before
Level Object

0

num (line width in user space units)

Table 2. After
Level Object

(empty)

Line width parameter set

1.3. Description

setlinewidth sets the line width parameter in the graphics state to num. This controls the thickness of lines rendered by subsequent [stroke] operations.

The line width is measured in user space units. The actual rendered width in device space depends on the current transformation matrix (CTM).

  • Zero width: Thinnest line possible (1 device pixel)

  • Negative width: Absolute value used

1.4. PostScript Level

Level 1 and later

1.5. Examples

Different line widths
1 setlinewidth
0 0 moveto 100 0 lineto stroke  % 1-unit line

5 setlinewidth
0 10 moveto 100 10 lineto stroke  % 5-unit line

0.5 setlinewidth
0 20 moveto 100 20 lineto stroke  % Half-unit line
Zero-width lines
0 setlinewidth
0 0 moveto 100 100 lineto stroke  % Thinnest possible
Hairline drawing
gsave
  0.1 setlinewidth  % Very thin
  drawDetailedIllustration
grestore

1.6. Common Use Cases

1.6.1. Standard Line Widths

% Typical widths for different purposes
0.25 setlinewidth  % Fine details
1 setlinewidth     % Normal lines
2 setlinewidth     % Emphasis
5 setlinewidth     % Bold/headers

1.6.2. Scaling-Independent Width

% Width in points regardless of scaling
72 div setlinewidth  % 1 point = 1/72 inch

1.6.3. Variable Width Drawing

1 1 10 {
  dup setlinewidth
  0 0 moveto 100 0 lineto stroke
  0 15 translate
} for

1.7. Common Pitfalls

Affected by CTM - Line width is in user space, transformed to device space.
1 setlinewidth
2 2 scale
% Lines now 2 units wide in device space
stroke
Non-Uniform Scaling - Different x/y scaling produces variable width.
2 1 scale  % Scale x more than y
1 setlinewidth
% Horizontal lines thicker than vertical
Zero Width Caution - Device-dependent, may be invisible on high-res devices.
0 setlinewidth  % 1 pixel - invisible on 2400dpi!
Use Absolute Units - For consistent output, use point measurements:
1 72 div setlinewidth  % 1 point

1.8. Error Conditions

Error Condition

[stackunderflow]

No operand on stack

[typecheck]

Operand not a number

1.9. Implementation Notes

  • Width applies to all subsequent strokes

  • Measured perpendicularly from path

  • Affected by CTM at time of stroke (not at setlinewidth)

  • Very fast parameter setting

1.10. Line Width Effects

Visual comparison
Width 0:   ─────────
Width 1:   ━━━━━━━━━
Width 3:   ▬▬▬▬▬▬▬▬▬
Width 5:   ▓▓▓▓▓▓▓▓▓

1.11. See Also


Back to top

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