1. currentcmykcolor
Returns current color as CMYK values.
1.2. Stack Effects
| Level | Object |
|---|---|
(empty) |
– |
| Level | Object |
|---|---|
3 |
|
2 |
|
1 |
|
0 |
|
1.3. Description
currentcmykcolor returns the current color in the graphics state according to the cyan-magenta-yellow-black color space.
-
If the current color space is DeviceCMYK,
currentcmykcolorreturns the color values most recently specified bysetcmykcoloror [setcolor]. -
If the current color space is DeviceRGB or DeviceGray,
currentcmykcolorconverts the current color to CMYK. -
For any other color space,
currentcmykcolorreturns 0.0 0.0 0.0 1.0 (black).
Each returned value is in the range 0.0 (no ink) to 1.0 (full ink coverage).
1.5. Examples
0 1 1 0 setcmykcolor % Cyan
currentcmykcolor
% Stack: 0.0 1.0 1.0 0.0
currentcmykcolor % Save current
/black exch def
/yellow exch def
/magenta exch def
/cyan exch def
1 0 0 0 setcmykcolor % Change to cyan
drawShape
cyan magenta yellow black setcmykcolor % Restore
1 0 0 setrgbcolor % Red
currentcmykcolor
% Stack: 0.0 1.0 1.0 0.0 (approximately)
currentcmykcolor
0.5 add % Increase black
4 1 roll % Reorder
setcmykcolor
1.6. Common Use Cases
1.6.1. Print Production Color Management
/SaveCMYK {
currentcmykcolor
/savedBlack exch def
/savedYellow exch def
/savedMagenta exch def
/savedCyan exch def
} def
/RestoreCMYK {
savedCyan savedMagenta savedYellow savedBlack
setcmykcolor
} def
1.6.2. Undercolor Removal Adjustment
/ApplyUCR {
currentcmykcolor
% Get minimum of CMY
3 copy
2 copy lt { exch } if pop
2 copy lt { exch } if pop
% Add to black, reduce CMY
dup 4 1 roll add
4 1 roll exch 3 -1 roll sub
3 1 roll exch 3 -1 roll sub
3 1 roll exch 3 -1 roll sub
3 1 roll
setcmykcolor
} def
1.7. Common Pitfalls
| Color Space Conversion - RGB to CMYK conversion is not exact. |
1 0 0 setrgbcolor % Pure red in RGB
currentcmykcolor % ~0 1 1 0 in CMYK
setcmykcolor
currentrgbcolor % May not be exactly 1 0 0
| Returns Black for Unknown Spaces - Pattern and other spaces return 0 0 0 1. |
/Pattern setcolorspace
myPattern setcolor
currentcmykcolor % Returns 0 0 0 1
| Stack Order - CMYK order: cyan at level 3, black at level 0. |
currentcmykcolor
% Stack (bottom to top): cyan magenta yellow black
% Pop order: black, yellow, magenta, cyan
| Level 2 Only - Not available in Level 1 interpreters. |
/languagelevel where {
pop languagelevel 2 ge {
currentcmykcolor
} {
% Level 1 - no CMYK support
} ifelse
} if
| Use Array for Storage - Simplifies CMYK color management. |
[ currentcmykcolor ] /myColor exch def
myColor aload pop setcmykcolor
1.8. Error Conditions
| Error | Condition |
|---|---|
[ |
Fewer than 4 free stack positions |
[ |
Level 1 interpreter (operator not defined) |
1.9. Implementation Notes
-
Level 2 operator
-
Fast query operation
-
No modification to graphics state
-
Values always in range 0.0 to 1.0
-
Conversion algorithms device-dependent
-
Ideal for print production workflows
1.10. Color Conversion
When converting from other color spaces:
cyan = magenta = yellow = 0.0 black = 1 - grayValue
cyan = 1 - red magenta = 1 - green yellow = 1 - blue black = min(cyan, magenta, yellow) cyan = cyan - black magenta = magenta - black yellow = yellow - black
cyan = magenta = yellow = 0.0 black = 1.0
1.11. CMYK Color Model
The CMYK color model is subtractive:
Cyan + Magenta = Blue
Cyan + Yellow = Green
Magenta + Yellow = Red
C + M + Y = Dark gray
C + M + Y + K = Rich black
No components = White (paper)
1.12. See Also
-
setcmykcolor- Set CMYK color (Level 2) -
currentrgbcolor- Get RGB color -
currentgray- Get gray value -
currenthsbcolor- Get HSB color