1. setcmykcolor

Sets the current CMYK color for painting operations.

1.1. Syntax

cyan magenta yellow black setcmykcolor → –

1.2. Stack Effects

Table 1. Before
Level Object

3

cyan (0.0 to 1.0)

2

magenta (0.0 to 1.0)

1

yellow (0.0 to 1.0)

0

black (0.0 to 1.0)

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

Level 2 and later

1.5. Examples

Primary process colors
1 0 0 0 setcmykcolor  % Cyan
0 1 0 0 setcmykcolor  % Magenta
0 0 1 0 setcmykcolor  % Yellow
0 0 0 1 setcmykcolor  % Black
Secondary colors
1 1 0 0 setcmykcolor  % Blue (C+M)
1 0 1 0 setcmykcolor  % Green (C+Y)
0 1 1 0 setcmykcolor  % Red (M+Y)
Rich black
0.5 0.5 0.5 1 setcmykcolor  % Rich black
Paper white
0 0 0 0 setcmykcolor  % White (no ink)

1.6. Common Use Cases

% 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.6.3. Rich Blacks

/RichBlack {
  % C+M+Y+K for deep black
  0.6 0.4 0.4 1.0 setcmykcolor
} def

/CoolBlack {
  % Cyan-heavy rich black
  0.7 0.3 0.3 1.0 setcmykcolor
} def

/WarmBlack {
  % Magenta/Yellow rich black
  0.3 0.5 0.5 1.0 setcmykcolor
} def

1.6.4. Duotone Effects

/SepiaTone {
  % level (0-1)
  dup dup
  0 exch 0.3 mul exch 0.6 mul exch
  setcmykcolor
} def

% Usage
0.7 SepiaTone

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

[stackunderflow]

Fewer than 4 operands on stack

[typecheck]

Any operand not a number

[undefined]

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


Back to top

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