1. setlinewidth
Sets the line width for stroking operations.
1.2. Stack Effects
| Level | Object |
|---|---|
0 |
|
| 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.5. Examples
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
0 setlinewidth
0 0 moveto 100 100 lineto stroke % Thinnest possible
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.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 |
|---|---|
[ |
No operand on stack |
[ |
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
Width 0: ─────────
Width 1: ━━━━━━━━━
Width 3: ▬▬▬▬▬▬▬▬▬
Width 5: ▓▓▓▓▓▓▓▓▓
1.11. See Also
-
setlinecap- Set line end style -
setlinejoin- Set corner style -
setdash- Set dash pattern -
currentlinewidth- Get current width -
Stroke operations (to be documented)