% epsrv.sty
% 
% Copyright (C) Koji Nakamaru
%
% Author: Koji Nakamaru (nakamaru at gmail.com)
% Modified: Apr 30 2005
%   * changed the contact information.
% Created: Jul 15 2002
% Keywords: postscript, eps, latex
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2, or (at your option)
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with GNU Emacs; see the file COPYING.  If not, write to the
% Free Software Foundation, Inc., 59 Temple Place - Suite 330,
% Boston, MA 02111-1307, USA.
%
\def\epsrv#1{%
  \special{ps:
save /epsrvSAVE exch def
systemdict /setrgbcolor known {
  /setgray {
    1 exch sub
    1 1 1
    0 1 2 {
      pop 3 index mul 3 1 roll
    } for
    setrgbcolor
    pop
  } bind def
  [ /setcmykcolor /setcolor /sethsbcolor /setrgbcolor ] {
    dup systemdict exch known {
      {
        0
        currentrgbcolor
        2 index 2 index eq 2 index 2 index eq and {
          pop pop setgray
        }{
          pop pop pop
        } ifelse
      } bind
      dup
      0 3 index load put def
    }{
      pop
    } ifelse  
  } forall
}{
  /setgray {
    1 exch sub
    1 1 1
    3 -1 roll 0.299 mul
    3 -1 roll 0.587 mul
    3 -1 roll 0.114 mul
    add add mul setgray
  } bind def
} ifelse
0 setgray
}%
#1%
\special{ps:
epsrvSAVE restore
}%
}
