
% overpic.sty 

% Copyright  1999 Rolf Niepraschk, niepraschk@ptb.de
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or any later version. 

%  \changes{v0.51}{1999/03/02}{New (LPPL) license}
%  \changes{v0.52}{1999/07/04}{Correction of wrong height calculation 
%                              (if depth != 0)}


\def\fileversion{v0.52}
\def\filedate{1999/07/04}% 

\ProvidesPackage{overpic}
    [\filedate\space\fileversion\space\space Overwriting eps pictures]  
                  
\NeedsTeXFormat{LaTeX2e}

\typeout{Package: overpic \fileversion\space <\filedate> (RN)}

\newcommand\OVP@scale{}

\DeclareOption{percent}{\renewcommand\OVP@scale{100}}
\DeclareOption{permil}{\renewcommand\OVP@scale{\@m}}
\DeclareOption{abs}{\renewcommand\OVP@scale{\z@}}

\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{graphicx}}

\ExecuteOptions{percent}

\ProcessOptions

\RequirePackage{graphicx,epic}

\newif\ifGin@grid 

\define@key{Gin}{grid}[true]{\lowercase{\Gin@boolkey{#1}}{grid}}
\define@key{Gin}{tics}{\count@=#1}
\define@key{Gin}{unit}{\setlength{\@tempdima}{#1}}

\ifnum\OVP@scale>\z@%
  \ifnum\OVP@scale=\@m%
    \typeout{overpic: relative positioning in permil}% 
  \else%
    \typeout{overpic: relative positioning in percent}% 
  \fi%  
  \newcommand\OVP@calc{%  
    \ifnum\@tempcnta>\@tempcntb%
      \divide\@tempcnta by \OVP@scale%
      \setlength\unitlength{\@tempcnta sp}% 
      \@tempcnta=\OVP@scale%
      \divide\@tempcntb by \unitlength%
    \else%
      \divide\@tempcntb by \OVP@scale%
      \setlength\unitlength{\@tempcntb sp}%  
      \@tempcntb=\OVP@scale%
      \divide\@tempcnta by \unitlength%
    \fi%
    \ifnum\count@=\z@% 
      \count@=\OVP@scale\divide\count@ by 10%
    \fi%
  }%  
\else%           
  \typeout{overpic: absolute positioning in \unitlength}%
  \newcommand\OVP@calc{%
    \setlength{\unitlength}{\@tempdima}%
    \divide\@tempcnta by \unitlength%
    \divide\@tempcntb by \unitlength% 
    \ifnum\count@=\z@\count@=10\fi%  
  }%  
\fi%  
 
\newenvironment{overpic}[2][]{%
  \sbox{\z@}{\includegraphics[#1]{#2}}%
  \settodepth{\@tempcnta}{\usebox{\z@}}%
  \settoheight{\@tempcntb}{\usebox{\z@}}%
  \advance\@tempcntb\@tempcnta%
  \settowidth{\@tempcnta}{\usebox{\z@}}%
  \setlength{\@tempdima}{\unitlength}%
  \count@=\z@\Gin@gridfalse\setkeys{Gin}{#1}% 
%
  \OVP@calc%
%  
  \begin{picture}(\@tempcnta,\@tempcntb)%
    \put(0,0){\makebox(0,0)[bl]{\usebox{\z@}}}%
    \ifGin@grid%
      \put(0,0){\normalfont\fontsize\@viipt\@viiipt\selectfont%
        \grid(\@tempcnta,\@tempcntb)(\count@,\count@)[0,0]}%	
    \fi%  
}{% 
  \end{picture}%
}% 

\endinput
