1. setcmykcolor
Sets the current CMYK color for painting operations.
1.2. Stack Effects
| Level | Object |
|---|---|
3 |
|
2 |
|
1 |
|
0 |
|
| Level | Object |
|---|---|
(empty) |
Color space set to DeviceCMYK, color set to (c,m,y,k) |
1.3. Description
setcmykcolor sets the color space to DeviceCMYK and sets the current color using cyan, magenta, yellow, and black components.
Each component must be in range 0.0 to 1.0:
-
0.0 = no ink (paper shows through)
-
1.0 = full ink coverage
-
Values outside range are clamped (no error)
This establishes the color for subsequent painting operations (lines, fills, text). CMYK is a subtractive color model primarily used for printing.
Important: Color values set by setcmykcolor are not affected by black generation and undercolor removal operations.
1.5. Examples
1 0 0 0 setcmykcolor % Cyan
0 1 0 0 setcmykcolor % Magenta
0 0 1 0 setcmykcolor % Yellow
0 0 0 1 setcmykcolor % Black
1 1 0 0 setcmykcolor % Blue (C+M)
1 0 1 0 setcmykcolor % Green (C+Y)
0 1 1 0 setcmykcolor % Red (M+Y)
0.5 0.5 0.5 1 setcmykcolor % Rich black
0 0 0 0 setcmykcolor % White (no ink)
1.6. Common Use Cases
1.6.1. Print Production
% Spot color simulation
/PantoneBlue {
1.0 0.7 0 0.1 setcmykcolor
} def
/PantoneRed {
0 1.0 0.9 0 setcmykcolor
} def
1.6.2. Corporate Colors
/BrandPrimary {
0.85 0.15 0 0.05 setcmykcolor
} def
/BrandSecondary {
0 0.75 0.90 0.10 setcmykcolor
} def
1.7. Common Pitfalls
Changes Color Space - setcmykcolor changes color space to DeviceCMYK.
|
1 0 0 setrgbcolor % Red (DeviceRGB)
0 1 1 0 setcmykcolor % Red (DeviceCMYK - RGB lost!)
| Values Clamped - Out-of-range values adjusted, not rejected. |
1.5 0 0 0 setcmykcolor % Becomes 1.0 0 0 0 (cyan)
-0.5 0 0 0 setcmykcolor % Becomes 0.0 0 0 0 (white)
| Not RGB - CMYK is subtractive; values work opposite to RGB. |
0 0 0 0 setcmykcolor % White (no ink)
1 1 1 1 setcmykcolor % Very dark (all inks)
| Level 2 Only - Not available in Level 1 interpreters. |
/languagelevel where {
pop languagelevel 2 ge {
setcmykcolor
} {
% Fallback for Level 1
% Convert to RGB or gray
} ifelse
} if
| Use for Print - CMYK is ideal for offset printing and press output. |
1.8. Error Conditions
| Error | Condition |
|---|---|
[ |
Fewer than 4 operands on stack |
[ |
Any operand not a number |
[ |
Disabled in certain contexts or Level 1 |
1.9. Implementation Notes
-
Level 2 operator
-
Sets both color space and color
-
Subtractive color model (print-oriented)
-
Values not affected by black generation/UCR
-
Device converts to native color space if needed
-
Ideal for print production workflows
1.10. CMYK Color Mixing
C + M = Blue
C + Y = Green
M + Y = Red
C + M + Y = Brown/Gray
K alone = Black
No inks = White (paper)
1.11. Print Considerations
1.11.1. Total Ink Coverage
Monitor total ink to avoid oversaturation:
/TotalInk {
% c m y k on stack
add add add
} def
% Check before setting
0.8 0.6 0.5 0.4 % CMYK values
4 copy TotalInk
2.3 gt {
% Reduce values if total > 230%
pop pop pop pop
0.7 0.5 0.4 0.3 setcmykcolor
} {
setcmykcolor
} ifelse
1.11.2. Undercolor Removal (UCR)
Manually implement UCR:
/ApplyUCR {
% c m y k on stack
% Find minimum of CMY
4 copy pop
3 copy
2 copy lt { exch } if pop
2 copy lt { exch } if pop
% UCR amount
dup 5 1 roll
% Subtract from CMY, add to K
4 1 roll 3 -1 roll sub
3 1 roll 3 -1 roll sub
3 1 roll 3 -1 roll sub
3 1 roll add
setcmykcolor
} def
1.12. See Also
-
setrgbcolor- Set RGB color -
setgray- Set grayscale -
sethsbcolor- Set HSB color -
currentcmykcolor- Get CMYK color (Level 2)