% Macros for importing of IPE pictures in plain TeX
% (c) 2001 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
% ------------------------------------------------------------------------------

% To access internal macros of plain TeX
% --------------------------------------

\def\makeatletter{\catcode`@=11 }
\def\makeatother{\catcode`@=12 }
\makeatletter

% Importing of IPE pictures
% -------------------------

\newdimen\unitlength
\newbox\picbox
\newdimen\picht

\def\IpeInput#1{{\def\IPEfile{#1}\latexemulation
\input\IPEfile\relax
}}

\def\latexemulation{
\def\newcommand##1[##2]##3{}
\def\@ifundefined##1##2{##2}
\def\begin##1(##2,##3)(##4,##5){\picht=##3\unitlength
\setbox\picbox=\hbox to ##2\unitlength\bgroup
\hskip -##4\unitlength\lower ##5\unitlength\hbox\bgroup
\ignorespaces}
\def\end##1{\egroup\hss\egroup\ht\picbox=\picht\dp\picbox=0pt\picout}
}

\def\picout{
\nointerlineskip
{
\vskip 4pt plus 1pt minus 0.5pt
\line{\hss\box\picbox\hss}
\vskip 4pt plus 1pt minus 0.5pt
}
\nointerlineskip
}
\def\killglue{\unskip}
\def\put(#1,#2)#3{\killglue\raise#2\unitlength\hbox to 0pt{\kern #1\unitlength #3\hss}\ignorespaces}

\let\selectfont\relax
\def\fontsize#1#2{}
\def\IPEput#1#2#3#4{\put(0,0){\special{psfile=\IPEfile}}}
\def\IPEmp#1#2{\MiniPagesAreNotSupported}
\def\IPEtext#1{\hbox{#1\special{color pop}}}
\def\IPEfs#1{\IPEcolfs{0 0 0}{#1}}
\def\IPEcolfs#1#2{\dimen0=#2pt\fontsize{#2}{1.2\dimen0}\selectfont\special{color push rgb #1}}
\def\IPEsize#1#2{\unitlength=1bp\ignorespaces}

\makeatother
