\ProvidesFile{pdftex.def}[1997/06/09 v0.02d graphics/color for pdftex]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% LaTeX Colour and Graphics support for PDFTeX
%%
%% David Carlisle, Sebastian Rahtz and Hans Hagen
%%
%% It may be used by specifying the pdftex option to any of the
%% supported packages, for example:
%%
%% \usepackage[pdftex]{graphicx}
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% Colour Support. The following models may be used.
%   * cmyk   supported directly.
%   * rgb    supported directly.
%   * RGB    converted to rgb by this file.
%   * gray   converted to rgb by this file.
%   * named  converted to cmyk by this file.
%
\def\c@lor@arg#1{%
  \dimen@#1\p@
  \ifdim\dimen@<\z@\dimen@\maxdimen\fi
  \ifdim\dimen@>\p@
    \PackageError{color}{Argument `#1' not in range [0,1]}\@ehd
  \fi}
\def\color@cmyk#1#2{\c@lor@@cmyk#2\@@#1}
\def\c@lor@@cmyk#1,#2,#3,#4\@@#5{%
  \c@lor@arg{#4}%
  \c@lor@arg{#1}%
  \c@lor@arg{#2}%
  \c@lor@arg{#3}%
  \edef#5{#1 #2 #3 #4 k #1 #2 #3 #4 K}%
  }
\def\color@gray#1#2{\c@lor@@rgb#2,#2,#2\@@#1}
\def\color@rgb#1#2{\c@lor@@rgb#2\@@#1}
\def\c@lor@@rgb#1,#2,#3\@@#4{%
  \c@lor@arg{#1}%
  \c@lor@arg{#2}%
  \c@lor@arg{#3}%
  \edef#4{#1 #2 #3 rg #1 #2 #3 RG}%
  }
\def\color@RGB#1#2{\c@lor@@RGB#2\@@#1}
\def\c@lor@@RGB#1,#2,#3\@@#4{%
 \c@lor@RGB@rgb{#1}\@tempa
 \c@lor@RGB@rgb{#2}\@tempb
 \c@lor@RGB@rgb{#3}\@tempc
 \c@lor@@rgb\@tempa,\@tempb,\@tempc\@@#4%
  }
\def\c@lor@RGB@rgb#1#2{%
  \dimen@#1\p@
  \divide\dimen@\@cclv
  \edef#2{\strip@pt\dimen@}}

\def\color@named#1#2{\c@lor@@named#2,,\@@#1}
\def\c@lor@@named#1,#2,#3\@@#4{%
  \@ifundefined{col@#1}%
    {\PackageError{color}{Undefined color `#1'}\@ehd}%
  {\edef#4{\csname col@#1\endcsname}}%
  }

\def\set@color{\pdfliteral{\current@color}\aftergroup\reset@color}
\def\reset@color{\pdfliteral{\current@color}}
\def\define@color@named#1#2{%
   \expandafter\edef\csname col@#1\endcsname{#2}}
\def\current@color{1 1 1 1 k 1 1 1 1 K}


% Need the `colorfix' modifications as no internal colour stack
% is maintained
%<*colorfix>
\AtBeginDocument{%
  \let\@ldc@l@r\color
  \def\color{\if@inlabel\leavevmode\fi\@ldc@l@r}%
  \let\@lduseb@x\usebox
  \def\usebox#1{\@lduseb@x{#1}\set@color}}
%</colorfix>

%
% Graphic inclusion. Currently supports .png, .mps and .pdf inclusion;
% .mps is MetaPost output. 
% .pdf is the limited subset derived from GhostScript processing.
%
% .pdf and .mps inclusion depend on loading a CONTEXT module by Hans Hagen
%

% PNG bitmaps may be scaled/rotated as usual
% by the graphics commands or keyword arguments.
\def\Gread@png#1{%
  \setbox\@tempboxa\hbox{\pdfimage#1\relax}%
   \def\Gin@llx{0}\let\Gin@lly\Gin@llx
   \Gin@defaultbp\Gin@urx{\wd\@tempboxa}%
   \Gin@defaultbp\Gin@ury{\ht\@tempboxa}}

\edef\Gread@MBox{/MediaBox}
\def\Gread@pdf#1{%
  \begingroup
  \@tempcnta\z@
   \loop\ifnum\@tempcnta<\@xxxii
   \catcode\@tempcnta14 %
   \advance\@tempcnta\@ne
  \repeat
  \catcode127=14 %
  \let\do\@makeother\dospecials\catcode`\ 10 %
  \catcode\endlinechar5 %
  \immediate\openin\@inputcheck#1 %
  \ifeof\@inputcheck
    \@latex@error{File `#1' not found}\@ehc
  \else
     \Gread@true
     \let\@tempb\Gread@false
     \loop
       \read\@inputcheck to\@tempa
       \ifeof\@inputcheck
         \Gread@false
       \else
         \expandafter\Gread@find@mbox\@tempa []\\%
       \fi
     \ifGread@
     \repeat
    \immediate\closein\@inputcheck
  \fi
  \ifGin@bbox\else
    \@latex@error
      {Cannot determine size of graphic in #1 (no BoundingBox)}%
      \@ehc
    \gdef\@gtempa{0 0 72 72 }%
  \fi
  \endgroup
  \expandafter\Gread@parse@bb\@gtempa\\}
\long\def\Gread@find@mbox#1 [#2]#3\\{%
  \def\@tempa{#1}%
  \ifx\@tempa\Gread@MBox
    \gdef\@gtempa{#2 }%
    \@tempb
    \Gin@bboxtrue
  \fi
}
\def\Ginclude@png#1{%
  \hbox{%
    \pdfimage \@height\Gin@req@height \@width\Gin@req@width #1\relax}}
\def\Ginclude@mps#1{%
   \def\@tempa{!}%
   \ifx\Gin@scaley\@tempa
     \let\Gin@scaley\Gin@scalex
   \else
    \ifx\Gin@scalex\@tempa\let\Gin@scalex\Gin@scaley\fi
   \fi    
   \hbox{%
     \convertMPtoPDF{#1}{\Gin@scalex}{\Gin@scaley}%
        }%
}

\def\Gread@mps{\Gread@eps}
\def\Ginclude@pdf#1{%
   \def\@tempa{!}%
   \ifx\Gin@scaley\@tempa
     \let\Gin@scaley\Gin@scalex
   \else
    \ifx\Gin@scalex\@tempa\let\Gin@scalex\Gin@scaley\fi
   \fi    
   \hbox{%
\convertPDFtoPDF{#1}{\Gin@scalex}{\Gin@scaley} {0bp} {0bp}{\Gin@req@width}{\Gin@req@height}%
        }%
}

\def\Gin@extensions{.png,.mps,.pdf,.eps,.ps,.eps.gz,.ps.gz,.eps.Z}
\@namedef{Gin@rule@.png}#1{{png}{.png}{#1}}
\@namedef{Gin@rule@.mps}#1{{mps}{.mps}{#1}}
\@namedef{Gin@rule@.pdf}#1{{pdf}{.pdf}{#1}}
\@namedef{Gin@rule@.ps}#1{{eps}{.ps}{#1}}
\@namedef{Gin@rule@.eps}#1{{eps}{.eps}{#1}}
\@namedef{Gin@rule@.pz}#1{{eps}{.bb}{`gunzip -c #1}}
\@namedef{Gin@rule@.eps.Z}#1{{eps}{.eps.bb}{`gunzip -c #1}}
\@namedef{Gin@rule@.ps.Z}#1{{eps}{.ps.bb}{`gunzip -c #1}}
\@namedef{Gin@rule@.ps.gz}#1{{eps}{.ps.bb}{`gunzip -c #1}}
\@namedef{Gin@rule@.eps.gz}#1{{eps}{.eps.bb}{`gunzip -c #1}}
\@namedef{Gin@rule@*}#1{{eps}{\Gin@ext}{#1}}
\@namedef{Gin@rule@.pcx}#1{{bmp}{}{#1}}
\@namedef{Gin@rule@.bmp}#1{{bmp}{}{#1}}
\@namedef{Gin@rule@.msp}#1{{bmp}{}{#1}}

% Rotation
% slightly hacky, but set width of box 0 to 0pt otherwise
% the CTM gets restored in the wrong place.

\def\Grot@start{%
 \pdfliteral{ q
     \Grot@cos\space\Grot@sin\space-\Grot@sin\space\Grot@cos\space
     0 0 cm}%
  \wd\z@\z@}

\def\Grot@end{\pdfliteral{ Q}}

% Scaling is OK, as graphics package does it right here.
\def\Gscale@start{%
  \pdfliteral{ q
   \Gscale@x\space0 0 \Gscale@y\space 0 0 cm}}

\let\Gscale@end\Grot@end

% undo the trig.sty `optimisation' so that these 0 1 and -1 values
% get written out as digits, not unexpandable TeX primitives.
\AtBeginDocument{%
\expandafter\def\csname sin(0)\endcsname{0}%
\expandafter\def\csname cos(0)\endcsname{1}%
\expandafter\def\csname sin(90)\endcsname{1}%
\expandafter\def\csname cos(90)\endcsname{0}%
\expandafter\def\csname sin(-90)\endcsname{-1}%
\expandafter\def\csname cos(-90)\endcsname{0}%
\expandafter\def\csname sin(180)\endcsname{0}%
\expandafter\def\csname cos(180)\endcsname{-1}}

% Are we running under PDFTeX?
\ifx\pdfpageheight\@undefined
  \PackageWarningNoLine\@currname
    {pdftex option does not work with standard TeX}
\else
   \pdfpageheight\paperheight
   \pdfpagewidth\paperwidth
   \pdfoutput=1
\fi

% supp-pdf does strange things to some catcodes; isolate
% for now. This is Hans Hagen's module from CONTEXT.
\AtBeginDocument{\InputIfFileExists{supp-pdf}{}{}}

\endinput
