%D \module
%D   [       file=spec-fds,
%D        version=2000.07.04,
%D          title=\CONTEXT\ \PDF\ Macros,
%D       subtitle=PDF color separation,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D Experimental (and yet undocumented) module. 

\unprotect 

\def\doPDFstartgraymode#1%
  {\ifcase\colorfilter
     \PDFcode{#1 g #1 G}%
   \or
     \PDFhiddencolorcode
   \or
     \PDFhiddencolorcode
   \or
     \PDFhiddencolorcode
   \or
     \PDFcode{#1 g #1 G}%
   \or
     \PDFhiddencolorcode
   \or
     \PDFcode{#1 g #1 G}%
   \fi}

\def\doPDFstartcmykcolormode#1#2#3#4%
  {\ifcase\colorfilter
     \PDFcode{#1 #2 #3 #4 k #1 #2 #3 #4 K}%
   \or
     \PDFnegatedcolorcode{#1}%
   \or
     \PDFnegatedcolorcode{#2}%
   \or
     \PDFnegatedcolorcode{#3}%
   \or
     \PDFnegatedcolorcode{#4}%
   \or
     \checkprocesscolor{#1}{#2}{#3}{#4}%
     \ifdone
       \PDFnegatedcolorcode\processcolorpct
     \else
       \PDFhiddencolorcode
     \fi
   \or
     \PDFhiddencolorcode
   \fi}

\def\doPDFstartrgbcolormode#1#2#3%
  {\ifcase\colorfilter
     \PDFcode{#1 #2 #3 rg #1 #2 #3 RG}%
   \else
     \message{don't use rgb colors}\wait
   \fi}

\let\doPDFstartgraycolormode\doPDFstartgraymode

\def\doPDFstopgraymode
  {\ifcase\colorfilter
     \PDFcode{0 g 0 G}%
   \else
     \PDFhiddencolorcode
   \fi}

\let\doPDFstopcolormode\doPDFstopgraymode

\newif\ifPDFhiddencolors \PDFhiddencolorstrue

\def\checkPDFhiddencolor % dummy function 
  {\immediate \pdfobj stream attr
     {/FunctionType 4 /Domain [0.0 1.0] /Range [0.0 1.0]}{{pop}}%
   \immediate \pdfobj
     % we cannot use /DeviceN since GS <=7.21 breaks on it 
     % and Jaws does not handle it at all 
     % {[/DeviceN [/None] /DeviceGray \the\pdflastobj\space0 R]}%  
     % so we use: 
     {[/Separation /None /DeviceGray \the\pdflastobj\space0 R]}%  
     % which works and prints ok 
   \appendtoPDFdocumentcolorspaces
     {/Hidden \the\pdflastobj\space0 R}
   \global\let\checkPDFhiddencolor\relax}

\def\PDFhiddencolorcode
  {\ifx\pdftexversion\undefined 
     \PDFcode{1 g 1 G}% 
   \else\ifPDFhiddencolors 
     \checkPDFhiddencolor
     \PDFcode{/Hidden CS 0 sc /Hidden cs 0 sc }%
   \else
     \PDFcode{1 g 1 G}% 
   \fi\fi} 

\def\PDFnegatedcolorcode#1%
  {\negatecolorcomponent{#1}%
   \ifdim\colorcomponent pt=1pt 
     \PDFhiddencolorcode
   \else
     \PDFcode{\colorcomponent\space g \colorcomponent\space G}% 
   \fi}

\protect \endinput 
