1. currentdash
Returns current dash pattern and offset.
1.2. Stack Effects
| Level | Object |
|---|---|
(empty) |
– |
| Level | Object |
|---|---|
1 |
|
0 |
|
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.5. Examples
[] 0 setdash
currentdash
% Stack: [] 0
[3 5] 2 setdash
currentdash
% Stack: [3 5] 2
currentdash % Save both
/savedOffset exch def
/savedArray exch def
[10 5 2 5] 0 setdash % Change
drawDashedLines
savedArray savedOffset setdash % Restore
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.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.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
-
setdash- Set dash pattern -
currentlinewidth- Get line width -
currentlinecap- Get line cap style -
currentlinejoin- Get line join style