1. currentlinewidth
Returns current line width value.
1.2. Stack Effects
| Level | Object |
|---|---|
(empty) |
– |
| Level | Object |
|---|---|
0 |
|
1.3. Description
currentlinewidth returns the current line width parameter from the graphics state. This is the value most recently set by setlinewidth.
The returned value is in user space units. The actual rendered width in device space depends on the current transformation matrix (CTM) at the time of stroking.
1.5. Examples
1 setlinewidth
currentlinewidth
% Stack: 1
currentlinewidth % Save
/savedWidth exch def
5 setlinewidth % Change
drawThickLines
savedWidth setlinewidth % Restore
currentlinewidth
2 mul
setlinewidth
currentlinewidth 2 gt {
% Current width is thick
drawBoldGraphic
} {
% Current width is thin
drawDetailedGraphic
} ifelse
1.6. Common Use Cases
1.6.1. Width State Preservation
/DrawWithCustomWidth {
% width on stack
currentlinewidth exch % Save, put new width on top
setlinewidth
drawShape
setlinewidth % Restore
} def
% Usage
3 DrawWithCustomWidth
1.6.2. Relative Width Adjustment
/ScaleLineWidth {
% factor
currentlinewidth mul
setlinewidth
} def
% Double current width
2 ScaleLineWidth
% Halve current width
0.5 ScaleLineWidth
1.7. Common Pitfalls
| User Space, Not Device Space - Returned value is in user space. |
1 setlinewidth
2 2 scale
currentlinewidth
% Returns 1, but renders as 2 device units
| Not Affected by CTM - Current width is the set value, not transformed value. |
1 setlinewidth
45 rotate
currentlinewidth
% Still returns 1 (rotation doesn't affect value)
| Use for State Management - Good for preserving/restoring line parameters. |
1.9. Implementation Notes
-
Very fast query operation
-
No modification to graphics state
-
Returns exact value set by
setlinewidth -
Value is in user space coordinates
-
Default value is typically 1.0
-
Widely supported (Level 1)
1.10. Line Width Behavior
The line width affects stroked paths:
% Width in user space
1 setlinewidth
0 0 moveto 100 0 lineto stroke % 1 unit thick
% After transformation
2 2 scale
currentlinewidth % Still 1.0
0 0 moveto 100 0 lineto stroke % Renders 2 units thick
1.11. See Also
-
setlinewidth- Set line width -
currentlinecap- Get line cap style -
currentlinejoin- Get line join style -
currentdash- Get dash pattern -
currentmiterlimit- Get miter limit