\ProvidesPackage{overprint}
\RequirePackage{color}
%
% support for overprinting.
% only support for dvips.def and pdftex.def
%
% Copyright (C) 2004 Siep Kroonenberg
% siepo at elvenkind dot com

% dummy definition for other drivers:
\let\set@op\relax

\newif\if@op
\def\overprint{%
  \@optrue
  \set@op
  \ignorespaces
}
\def\knockout{%
  \@opfalse
  \set@op
  \ignorespaces
}

\def\testname{pdftex.def}
\ifx \Gin@driver \testname
  % create graphics state dictionaries with overprint settings
  \immediate\pdfobj{<< /Type /ExtGState /op false /OP false /OPM 0 >>}
  \edef\op@off{\the\pdflastobj}
  \immediate\pdfobj{<< /Type /ExtGState /op true /OP true /OPM 1 >>}
  \edef\op@on{\the\pdflastobj}
  \immediate\pdfobj{ << %
    /GSko \op@off\space 0 R %
    /GSop \op@on\space 0 R >>}
  \edef\@extgs{\the\pdflastobj}
  \edef\next{\global\pdfpageresources{/ExtGState \@extgs\space 0 R }}
  \next
  % macros for setting and resetting overprint state
  \def\set@op{%
    \if@op
      \pdfliteral direct {/GSop gs}%
    \else
      \pdfliteral direct {/GSko gs}%
    \fi
    \aftergroup\reset@op}
  \def\reset@op{%
    \if@op
      \pdfliteral direct {/GSop gs}%
    \else
      \pdfliteral direct {/GSko gs}%
    \fi
  }
\fi

\def\testname{dvips.def}
\ifx \Gin@driver \testname
  \def\set@op{%
    \if@op
      \special{ps:true setoverprint}%
    \else
      \special{ps:false setoverprint}%
    \fi
    \aftergroup\reset@op}
  \def\reset@op{%
    \if@op
      \special{ps:true setoverprint}%
    \else
      \special{ps:false setoverprint}%
    \fi
  }
\fi

% initialize to knockout
\@opfalse
\knockout

% do we need something like colorfix?
%\AtBeginDocument{%
%  \let\@ld@op\overprint
%  \def\overprint{%
%    \@ifundefined{if@inlabel}{}{%
%      \csname if@inlabel\expandafter\endcsname
%      \expandafter\leavevmode\csname fi\endcsname
%    }%
%    \@ld@op
%  }%
%  \let\@ld@ko\knockout
%  \def\knockout{%
%    \@ifundefined{if@inlabel}{}{%
%      \csname if@inlabel\expandafter\endcsname
%      \expandafter\leavevmode\csname fi\endcsname
%    }%
%    \@ld@ko
%  }%
%  \let\@lduseb@x\usebox
%  \def\usebox#1{\@lduseb@x{#1}\set@op}%
%}
