1. currentlinewidth

Returns current line width value.

1.1. Syntax

– currentlinewidth → num

1.2. Stack Effects

Table 1. Before
Level Object

(empty)

Table 2. After
Level Object

0

num (line width in user space units)

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

Level 1 and later

1.5. Examples

Querying current line width
1 setlinewidth
currentlinewidth
% Stack: 1
Saving and restoring line width
currentlinewidth        % Save
/savedWidth exch def

5 setlinewidth          % Change
drawThickLines

savedWidth setlinewidth % Restore
Doubling current width
currentlinewidth
2 mul
setlinewidth
Conditional drawing based on width
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.6.3. Width-Adaptive Drawing

/DrawAdaptive {
  currentlinewidth
  dup 1 lt {
    % Thin lines - add detail
    pop
    drawDetailedVersion
  } {
    % Thick lines - simplify
    pop
    drawSimpleVersion
  } ifelse
} def

1.6.4. Width Validation

/EnsureMinimumWidth {
  % minWidth
  currentlinewidth
  2 copy lt {
    % Current is less than minimum
    exch pop setlinewidth
  } {
    % Current is adequate
    pop pop
  } ifelse
} def

% Ensure at least 0.5 units
0.5 EnsureMinimumWidth

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.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 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


Back to top

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