1. currentdash

Returns current dash pattern and offset.

1.1. Syntax

– currentdash → array offset

1.2. Stack Effects

Table 1. Before
Level Object

(empty)

Table 2. After
Level Object

1

array (dash pattern array)

0

offset (dash offset value)

1.3. Description

currentdash returns the current dash pattern array and offset parameter from the graphics state. These are the values most recently set by setdash.

The dash pattern array specifies the pattern of dashes and gaps:

  • Empty array []: solid line (no dashing)

  • One element [a]: alternating a-unit dashes and a-unit gaps

  • Multiple elements [a b c…​]: sequence of dash/gap lengths that repeats

The offset specifies the distance into the pattern at which to start the dash.

1.4. PostScript Level

Level 1 and later

1.5. Examples

Querying solid line (no dash)
[] 0 setdash
currentdash
% Stack: [] 0
Querying dash pattern
[3 5] 2 setdash
currentdash
% Stack: [3 5] 2
Saving and restoring dash pattern
currentdash             % Save both
/savedOffset exch def
/savedArray exch def

[10 5 2 5] 0 setdash   % Change
drawDashedLines

savedArray savedOffset setdash  % Restore
Modifying current pattern
currentdash
pop                     % Remove offset
% Modify array elements
0 6 put                 % Change first element
0 setdash               % Apply modified pattern

1.6. Common Use Cases

1.6.1. Dash State Preservation

/DrawWithCustomDash {
  % array offset on stack
  currentdash           % Save current
  4 2 roll              % Bring new values forward
  setdash

  drawShape

  setdash               % Restore
} def

% Usage
[5 3] 0 DrawWithCustomDash

1.6.2. Checking for Solid Lines

/IsSolid {
  currentdash
  pop                   % Remove offset
  length 0 eq           % Empty array?
} def

IsSolid {
  % Solid line
  drawSolid
} {
  % Dashed line
  drawDashed
} ifelse

1.6.3. Pattern Analysis

/GetDashLength {
  % Returns total pattern length
  currentdash
  pop                   % Remove offset
  0 exch                % Accumulator
  { add } forall
} def

GetDashLength
% Stack: total pattern length

1.6.4. Doubling Dash Pattern

/DoubleDashPattern {
  currentdash
  exch                  % offset array
  [ exch { 2 mul } forall ]
  exch 2 mul            % Double offset too
  setdash
} def

1.7. Common Pitfalls

Returned Array is Copy - Modifying returned array requires calling setdash.
currentdash pop
0 10 put                % Modifies array
% Pattern unchanged until setdash called
0 setdash
Array Can Be Empty - Empty array means solid line.
currentdash pop
length                  % Could be 0
dup 0 eq {
  % Handle solid line case
} if
Save Both Values - Always save both array and offset for complete restoration.

1.8. Error Conditions

Error Condition

[stackoverflow]

Fewer than 2 free stack positions

1.9. Implementation Notes

  • Fast query operation

  • No modification to graphics state

  • Returns copy of dash array

  • Returns both array and offset

  • Default is [] 0 (solid line)

  • Widely supported (Level 1)

1.10. Dash Pattern Behavior

Common patterns:

[] 0           % Solid line: ─────────────
[3] 0          % Equal dash/gap: ───   ───   ───
[5 3] 0        % Long dash, short gap: ─────   ─────
[10 3 3 3] 0   % Dash-dot: ──────────   ───   ──────────
[2 2] 0        % Dots: ──  ──  ──  ──
[2 2] 1        % Dots offset: ── ── ── ──

1.11. Pattern Offset Effect

% Pattern: [6 3]
[6 3] 0 setdash   % ██████   ███████   ██████
[6 3] 3 setdash   % ███   ██████   ██████   ███
[6 3] 6 setdash   % ██████   ██████   ██████

1.12. See Also


Back to top

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