\ProvidesFile{pdftex.def}[2003/06/20 v0.10a-BETA graphics/color for pdftex]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% LaTeX Colour and Graphics support for PDFTeX
%%
%% Copyright 2000-2003 David Carlisle, Sebastian Rahtz, Hans Hagen,
%% Heiko Oberdiek and Martin Schröder
%%
%% The current maintainers can be reached at pdftex-latex@pdftex.org
%%
%% The home page of this project is at http://pdftex-def.berlios.de
%% Please report bugs etc. there
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.2
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
%%
%% This program consists of the files pdftex.def and pdftex003.def
%%
%% It may be used by specifying the pdftex option to any of the
%% supported packages, for example:
%%
%% \usepackage[pdftex]{graphicx}
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Id: pdftex.def,v 1.17 2003/06/21 15:06:38 oberdiek Exp $
%
% History
% 2003/06/20 v0.10a
%  * Added option 'attr' (MS).
%  * Added option 'pagebox' (MS).
%  * Allow \write18 (MS).
%  * Remove support for tif images as per pdftex 1.01a (MS).
%  * Moved code for older versions to pdftex03.def
%  * Fix for bug #516: definitions of keyval's \define@key
%    used for new options to get more independence of package
%    loading order (HO).
%  * Added support for color models "hsb" and "HSB" (HO).
% 2002/06/19 v0.03k
%  * Correction by P\'etiard Fran\c{c}ois for \GPT@DoEndClip.
% 2002/06/18 v0.03j
%  * Contribution by P\'etiard Fran\c{c}ois <petiard@math.univ-fcomte.fr>:
%    Improvement of \Ginclude@mps (support of viewport and clip).
% 2001/11/29 v0.03i
%  * Problem with \if@inlabel (plain format) fixed.
% 2001/09/01 v0.03h
%  * Compatibilty for miniltx.tex, problems fixed:
%    \@ifpackageloaded, \PackageWarning, \PackageWarningNoLine,
%    \@currname.
% 2001/05/25 v0.03g
%  * \pdfpagewidth and \pdfpageheight are not set to zero,
%    if \paperwidth and \paperheight are not set (HO).
% 2000/11/10 v0.03f
%  * Bug, that produces an error message, if package `graphics'
%    is used (introduced in 0.03d), fixed: If \Gin@vllx is not
%    defined (graphics), then clipping and the moves of options
%    viewport/trim are silently disabled (HO).
% 2000/09/14 v0.03e
%  * Options `bbllx', `bblly', `bburx', `bbury' disabled,
%    option `bb' redirected with a warning to `viewport' (HO).
% 2000/09/14 v0.03d
%  * Fixes for `viewport' and `trim' (HO).
%  * Clip support added for viewport and trim (HO).
% 2000/09/04 v0.03c
%  * Redefinition of `natwidth' and `natheight' \AtBeginDocument (HO).
% 2000/08/31 v0.03b:
%  * support for alternate print images: option `print' added (HO).
%    * This feature is not supported by Ghostscript, xpdf, or AR3.
%    * The images should have the same dimensions/resolution.
%  * Two experimental options added (HO):
%    * `quiet': log messages are suppressed.
%    * `resolution': sets \pdfimageresolution.
%    Because these options are not supported by graphicx,
%    they have to be set after \usepackage{graphicx}, eg.
%      \setkeys{Gin}{quiet,resolution=300}
%    Option `quiet' (for pdftex) can be make known to graphic{s,x}
%    with this line in graphics.cfg:
%      \DeclareOption{quiet}{\let\Gin@log\@gobble}
%    Caution: both options are experimental and can be
%    change in next versions!
%  * \pdfpage{width,height} are only set, if \paperwidth
%    is defined (HO).
% 2000/06/16 v0.03a:
%  * Added Heiko to author list (DPC).
% 2000/05/31 v0.02v:
%  * Option `page' is defined at begin document,
%    if package `keyval' is loaded after `pdftex.def'.
% 2000/05/12 v0.02u:
%  * support for multipage pdf files, option `page' added (HO).
% 2000/05/02 v0.02t:
%  * \pagecolor supported (HO).
% 2000/04/20 v0.02s:
%  * gray color model directly supported (HO).
% ...
%
% prefix of internal commands for this file `pdftex.def':
%   \GPT@ (Graphics bundle PdfTex driver)

% load the old version of pdftex.def for older versions of pdftex.
\let\GPT@next\relax
\def\GPT@olddriver{\input{pdftex003.def}\endinput}%
\ifx\pdftexversion\@undefined
  \let\GPT@next\GPT@olddriver
\else
  \ifnum\pdftexversion<100\relax
    \let\GPT@next\GPT@olddriver
  \fi
\fi
\GPT@next

% miniltx.tex does not define \PackageWarning
% or \PackageWarningNoLine.
\@ifundefined{PackageWarning}{%
  \def\PackageWarning#1#2{%
    \begingroup
      \newlinechar=10 %
      \def\MessageBreak{%
        ^^J(#1)\@spaces\@spaces\@spaces\@spaces
      }%
      \immediate\write16{^^JPackage #1 Warning: #2\on@line.^^J}%
    \endgroup
  }%
}{}
\@ifundefined{PackageWarningNoLine}{%
  \def\PackageWarningNoLine#1#2{%
    \PackageWarning{#1}{#2\@gobble}%
  }%
}{}
\@ifundefined{on@line}{%
  \def\on@line{ on input line \the\inputlineno}%
}{}
\@ifundefined{@spaces}{%
  \def\@spaces{\space\space\space\space}%
}{}
\def\GPT@warn{\PackageWarning{pdftex.def}}%
\ifx\Gin@log\@undefined
  \def\Gin@log{\message}
\fi

% Colour Support. The following models may be used.
%   * cmyk   supported directly.
%   * rgb    supported directly.
%   * RGB    converted to rgb by this file.
%   * hsb    converted to rgb by this file.
%   * HSB    converted to rgb by this file.
%   * gray   supported directly.
%   * 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
}
% \GPT@arg@test{<value>}{<upper range>}{<cmd for result>}
\def\GPT@arg@test#1#2#3{%
  \def#3{#1}%
  \dimen@#1\p@
  \ifdim\dimen@<\z@
    \PackageError{color}{Argument `#1' too small, %
                         not in range [0,\number#2]}\@ehd
    \def#3{0}%
  \fi
  \ifdim\dimen@>#2\p@
    \PackageError{color}{Argument `#1' too large, %
                         not in range [0,\number#2]}\@ehd
    \def#3{#2}%
  \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@arg{#2}%
  \edef#1{#2 g #2 G}%
}
\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@}%
}
%
% The "hsb" color model is not supported by PDF, so the values
% are converted into "rgb" values:
%
%   Input: h (hue), s (saturation), b (brightness)
%          (h, s, b) \in ([0,1], [0,1], [0,1])       % hsb model
%          (H, S, B) \in ([0,360], [0,255], [0,255]) % HSB model
%          (h, s, b) := (H/360, S/255, B/255)
%   Output: r (red), g (green), b (blue)
%
%   M := (1 - s) * b;
%   D := s * b;
%   H := 6 * h;
%   x := (int)floor(H);
%   if (x >= 6) {
%       x := 0;
%       H := 0;
%   }
%   switch(x) {
%     case 0:    /* r >= g >= b */
%       r := b;
%       b := M;
%       g := M + D * H;
%       break;
%     case 1:    /* g >= r >= b */
%       g := b;
%       b := M;
%       r := M + D * (2 - H);
%       break;
%     case 2:    /* g >= b >= r */
%       g := b;
%       r := M;
%       b := M + D * (H - 2);
%       break;
%     case 3:    /* b >= g >= r */
%       b := b;
%       r := M;
%       g := M + D * (4 - H);
%       break;
%     case 4:    /* b >= r >= g */
%       b := b;
%       g := M;
%       r := M + D * (H - 4);
%       break;
%     case 5:    /* r >= b >= g */
%       r := b;
%       g := M;
%       b := M + D * (6 - H);
%       break;
%   }
%
% References:
% * "Color Gamut Transform Pairs" by Alvy Ray Smith
%   http://alvyray.com/Papers/PapersCG.htm
%   ftp://ftp.alvyray.com/Acrobat/Color78.pdf
% * Ghostscript's gs_cspace.ps
%   Caution: the implementation of case 6 is buggy currently (8.10).
% * "efg's Color Reference Library -- Color Science / Color Theory"
%   http://homepages.borland.com/efg2lab/Library/Color/Science.htm
%   http://homepages.borland.com/efg2lab/Graphics/Colors/HSV.htm
%
\def\color@hsb#1#2{\c@lor@@hsb#2\@@#1\z@}
\def\color@Hsb#1#2{\c@lor@@hsb#2\@@#1\@ne}
\def\color@HSB#1#2{\c@lor@@hsb#2\@@#1\tw@}
\def\c@lor@@hsb#1,#2,#3\@@#4#5{%
  \ifcase#5%
    \GPT@arg@test{#1}\@ne\@tempa
    \GPT@arg@test{#2}\@ne\@tempb
    \GPT@arg@test{#3}\@ne\@tempc
  \or
    \GPT@arg@test{#1}{360}\@tempa
    \GPT@arg@test{#2}\@ne\@tempb
    \GPT@arg@test{#3}\@ne\@tempc
  \else
    \GPT@arg@test{#1}{360}\@tempa
    \GPT@arg@test{#2}\@cclv\@tempb
    \GPT@arg@test{#3}\@cclv\@tempc
  \fi
  \begingroup
    \dimendef\H=1 % "hue" * 6
    \dimendef\s=2 % "saturation"
    \dimendef\b=3 % used for both "brightness" and "blue"
    \dimendef\M=5 % (1 - "saturation") * "brightness"
    \dimendef\D=6 % "saturation" * "brightness"
    \dimendef\r=7 % "red"
    \dimendef\g=8 % "green"
    \H=\@tempa\p@
    \s=\@tempb\p@
    \b=\@tempc\p@
    \ifcase#5%
    \or
      \divide\H 360 %
    \else
      \divide\H 360 %
      \divide\s\@cclv
      \divide\b\@cclv
    \fi
    \H=6\H
    \edef\x{\expandafter\GPT@floor\the\H}%
    \ifnum\x<6 %
    \else
      \def\x{0}%
      \H=\z@
    \fi
    \D=\strip@pt\b\s
    \GPT@hsb@calc
    \edef\x{%
      \strip@pt\r\space
      \strip@pt\g\space
      \strip@pt\b\space
    }%
    \edef\x{%
      \endgroup
      \def\noexpand#4{\x rg \x RG}%
    }%
  \x
}

\begingroup
  \def\x{\def\GPT@floor}
  \catcode`P=12 %
  \catcode`T=12 %
\lowercase{\expandafter\endgroup\x#1.#2PT{#1}}%

\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname dimexpr\endcsname\relax
  \def\GPT@hsb@calc{%
    \M=\p@
    \advance\M-\s
    \M=\strip@pt\b\M
    % first use \b (brightness), thus it is free for \b (blue)
    \ifcase\x\relax
      \r=\b
      \b=\M
      \g=\strip@pt\D\H
      \advance\g\M
    \or % 1
      \g=\b
      \b=\M
      \r=2\p@
      \advance\r-\H
      \r=\strip@pt\D\r
      \advance\r\M
    \or % 2
      \g=\b
      \r=\M
      \b=\H
      \advance\b-2\p@
      \b=\strip@pt\D\b
      \advance\b\M
    \or % 3
      % \b=\b
      \r=\M
      \g=4\p@
      \advance\g-\H
      \g=\strip@pt\D\g
      \advance\g\M
    \or % 4
      % \b=\b
      \g=\M
      \r=\H
      \advance\r-4\p@
      \r=\strip@pt\D\r
      \advance\r\M
    \or % 5
      \r=\b
      \g=\M
      \b=6\p@
      \advance\b-\H
      \b=\strip@pt\D\b
      \advance\b\M
    \fi
  }%
\else
  \def\GPT@hsb@calc{%
    \M=\strip@pt\b\dimexpr \p@ - \s \relax
    % first use \b (brightness), thus it is free for \b (blue)
    \ifcase\x\relax
      \r=\b
      \b=\M
      \g=\dimexpr \M + \strip@pt\D \H \relax
    \or % 1
      \g=\b
      \b=\M
      \r=\dimexpr \M + \strip@pt\D \dimexpr 2\p@ - \H \relax\relax
    \or % 2
      \g=\b
      \r=\M
      \b=\dimexpr \M + \strip@pt\D \dimexpr \H - 2\p@ \relax\relax
    \or % 3
      % \b=\b
      \r=\M
      \g=\dimexpr \M + \strip@pt\D \dimexpr 4\p@ - \H \relax\relax
    \or % 4
      % \b=\b
      \g=\M
      \r=\dimexpr \M + \strip@pt\D \dimexpr \H - 4\p@ \relax\relax
    \or % 5
      \r=\b
      \g=\M
      \b=\dimexpr \M + \strip@pt\D \dimexpr 6\p@ - \H \relax\relax
    \fi
  }%
\fi

\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{0 g 0 G}

% v0.02t: support for \pagecolor
\def\set@page@color{%
  \global\let\current@page@color\current@color
  \@ifundefined{GPTorg@shipout}{%
    \global\let\GPTorg@shipout\shipout
    \gdef\shipout{%
      \afterassignment\GPT@shipout
      \global\setbox\@cclv=%
    }%
    \gdef\GPT@shipout{%
      \ifvoid\@cclv\relax
         \aftergroup\GPT@@shipout
         \GPT@pageliteral
      \else
        \GPTorg@shipout\vbox{%
          \GPT@pageliteral
          \box\@cclv
        }%
      \fi
    }%
    \gdef\GPT@@shipout{%
      \GPTorg@shipout\box\@cclv\relax
    }%
    \gdef\GPT@pageliteral{%
      \pdfliteral direct{%
        q % gsave
        \current@page@color\space
        n % newpath
        0 0 \strip@pt\pdfpagewidth\space
        \strip@pt\pdfpageheight\space re % rectangle
        % there is no need to convert to bp
        f % fill
        Q% grestore
      }%
    }%
  }{}%
}

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

%
% Graphic inclusion. Currently supports .png, .jpg, .mps and .pdf inclusion;
% .mps is MetaPost output.
% .mps inclusion depends on loading a CONTEXT module by Hans Hagen;
% .pdf also needs a Context module unless pdftex 0.12n or later.
%
% PNG bitmaps may be scaled/rotated as usual
% by the graphics commands or keyword arguments.
%
% Note the magic in front of the file name after \pdfimage, to
% prevent it fouling up with file names starting with "depth".
\def\Gread@png#1{%
  \setbox\@tempboxa\hbox{\pdfimage\noexpand\noexpand\noexpand\@empty#1\relax}%
  \def\Gin@llx{0}\let\Gin@lly\Gin@llx
  \Gin@defaultbp\Gin@urx{\wd\@tempboxa}%
  \Gin@defaultbp\Gin@ury{\ht\@tempboxa}%
}

%
% support for
% * multipage pdf images
% * alternate print image (bitmaps only)
%   * printed image can be resused, but not the base image,
%     because it's dictionary contains the additional key /Alternates.
%   * not supported by Ghostscript or xpdf.
% * option quiet
% * option attr for additional entries in the dictionary of the
%     generated Forms XObject
% * option pagebox for specifying the <pdf box spec>
%     Default is the cropbox to be compatible with old versions of pdfTeX.
%
% \GPT@page: page number of pdf image or \@empty otherwise.
\let\GPT@page\@empty
% \GPT@print: file name for alternate image or \@empty otherwise.
\let\GPT@print\@empty
% \GPT@attr: additional attributes.
\let\GPT@attr\@empty
% \GPT@pagebox: <pdf box spec>
\let\GPT@pagebox\@empty
%
% Test for \define@key without defining it
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname define@key\endcsname\relax
  % package keyval is not loaded yet, thus its definitions
  % are used here to define the new options.
  % \@ifnextchar and \@namedef are provided by miniltx.tex.
  \def\GPT@define@key#1#2{%
    \@ifnextchar[{%
      \GPT@KV@def{#1}{#2}%
    }{%
      \@namedef{KV@#1@#2}####1%
    }%
  }%
  \def\GPT@KV@def#1#2[#3]{%
    \@namedef{KV@#1@#2@default\expandafter}\expandafter
        {\csname KV@#1@#2\endcsname{#3}}%
    \@namedef{KV@#1@#2}##1%
  }%
\else
  \let\GPT@define@key\define@key
\fi
\GPT@define@key{Gin}{page}{%
  \def\GPT@page{#1}%
}%
\GPT@define@key{Gin}{print}{%
  \def\GPT@print{#1}%
}%
\GPT@define@key{Gin}{quiet}[]{%
  \let\Gin@log\@gobble
}%
\GPT@define@key{Gin}{resolution}{%
  \pdfimageresolution#1\relax
}%
\GPT@define@key{Gin}{attr}{%
  \def\GPT@attr{attr {#1}}%
}%
\GPT@define@key{Gin}{pagebox}{%
  \def\GPT@pagebox{ #1}%
}%

% redefinitions of some graphicx options:
\def\GPT@disable#1{%
  \GPT@warn{%
    Option `#1' is not supported, use\MessageBreak
    option `viewport' instead%
  }%
}
% Here we have to trust that package graphicx is not
% loaded after applying the fix "\AtBeginDocument".
\def\GPT@fix{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname define@key\endcsname\relax
  \else
    \def\KV@Gin@bb{%
      \GPT@warn{%
        Option `bb' does not make sense,\MessageBreak
        using `viewport' instead%
      }%
      \KV@Gin@viewport
    }%
    \define@key{Gin}{bbllx}{\GPT@disable{bbllx}}%
    \define@key{Gin}{bblly}{\GPT@disable{bblly}}%
    \define@key{Gin}{bburx}{\GPT@disable{bburx}}%
    \define@key{Gin}{bbury}{\GPT@disable{bbury}}%
  \fi
}
\AtBeginDocument{\GPT@fix}

%
% mechanism for re-use of objects also
% allows us to get the size by deriving it from the initial storage;
% this works for all graphics types.
%
\def\GPT@ReusedName#1{%
  \ifx\GPT@print\@empty
    #1%
  \else
    \GPT@print
  \fi
}
\def\Gread@pdftex#1{%
  % Ensure that option `print' works only on bitmap images.
  \ifGPT@IsBitmap
  \else
    \ifx\GPT@print\@empty
    \else
      \GPT@warn{%
        Option `print' can only be used\MessageBreak
        for bitmap images%
      }%
      \let\GPT@print\@empty
    \fi
  \fi
  % If option `print' is set, the screen image object
  % will contain an additional /Alternate entry
  % and will therefore not be reused.
  \ifx\GPT@print\@empty
  \else
    \expandafter\expandafter\expandafter\@firstoftwo\expandafter\@gobbletwo
  \fi
  % Ensure the default cropbox for \GPT@pagebox
  \ifx\GPT@pagebox\empty
    \def\GPT@pagebox{ cropbox}%
  \fi
  \@ifundefined{#1 image\GPT@page\GPT@pagebox}{%
    \ifx\GPT@print\@empty
      \let\GPT@RuleAttr\@empty
    \else
      \@ifundefined{\GPT@print\space image\GPT@page}{%
        \immediate\pdfximage{\GPT@print}%
        \setbox\@tempboxa=\hbox{\pdfrefximage\pdflastximage}%
        \edef\GPT@PrintObj{\the\pdflastximage}%
        \expandafter\xdef\csname\GPT@print\space
          image\GPT@page\GPT@pagebox\endcsname{\pdfrefximage\GPT@PrintObj}%
        \immediate\pdfobj{%
          [<<%
            /Image \GPT@PrintObj\space 0 R%
            /DefaultForPrinting true%
          >>]%
        }%
        \def\GPT@RuleAttr{%
          width\wd\@tempboxa height\ht\@tempboxa
        }%
        \g@addto@macro\GPT@attr{/Alternates \the\pdflastobj\space 0 R}%
      }{%
        \edef\GPT@PrintObj{%
          \expandafter\expandafter\expandafter\@gobble
          \csname\GPT@print\space image\GPT@page\GPT@pagebox\endcsname
        }%
        \immediate\pdfobj{%
          [<<%
            /Image \GPT@PrintObj \space 0 R%
            /DefaultForPrinting true%
          >>]%
        }%
        \def\GPT@RuleAttr{%
          width \csname\GPT@print\space width\GPT@page\GPT@pagebox\endcsname
          height \csname\GPT@print\space height\GPT@page\GPT@pagebox\endcsname
        }%
        \g@addto@macro\GPT@attr{/Alternates \the\pdflastobj\space 0 R}%
      }%
    \fi
    \pdfximage \GPT@RuleAttr \GPT@attr
    \ifx\GPT@page\@empty
    \else
      page \GPT@page
    \fi
    \GPT@pagebox
    {#1}%
    \setbox\@tempboxa=\hbox{\pdfrefximage\pdflastximage}%
    \def\Gin@llx{0}\let\Gin@lly\Gin@llx
    \Gin@defaultbp\Gin@urx{\wd\@tempboxa}%
    \Gin@defaultbp\Gin@ury{\ht\@tempboxa}%
    \expandafter\xdef\csname\GPT@ReusedName{#1} width\GPT@page\GPT@pagebox\endcsname{%
      \the\wd\@tempboxa
    }%
    \expandafter\xdef\csname\GPT@ReusedName{#1} height\GPT@page\GPT@pagebox\endcsname{%
      \the\ht\@tempboxa
    }%
    \expandafter\xdef\csname #1 image\GPT@page\GPT@pagebox
      \ifx\GPT@print\@empty\else!\fi\endcsname{%
      \pdfrefximage\the\pdflastximage
    }%
    \Gin@log{%
       <#1, id=%
       \the\pdflastximage
       \ifx\GPT@page\@empty\else , page=\GPT@page\fi
       , pagebox=\GPT@pagebox
       \ifx\GPT@print\@empty
       \else
          , print=\GPT@print, id=\GPT@PrintObj
       \fi
       , \the\wd\@tempboxa\space x \the\ht\@tempboxa
       >%
     }%
  }{%
    \def\Gin@llx{0}\let\Gin@lly\Gin@llx
    \Gin@defaultbp\Gin@urx{\csname#1 width\GPT@page\GPT@pagebox\endcsname}%
    \Gin@defaultbp\Gin@ury{\csname#1 height\GPT@page\GPT@pagebox\endcsname}%
  }%
}
\def\Ginclude@pdftex#1{%
  \def\@tempa{!}%
  \ifx\Gin@scaley\@tempa
    \let\Gin@scaley\Gin@scalex
  \else
    \ifx\Gin@scalex\@tempa\let\Gin@scalex\Gin@scaley\fi
  \fi
  \Gin@log{%
    <use #1%
    \ifx\GPT@page\@empty\else, page \GPT@page\fi
    >%
  }%
  \hbox{%
    \Gscale@box{\Gin@scalex}[\Gin@scaley]{%
      \@ifundefined{Gin@vllx}{%
        \GPT@viewportfalse
        % without viewport/trim clipping does not make sense
        % for pdfTeX
        \Gin@clipfalse
      }{}%
      \ifGin@clip
        \if!\Gin@vllx\Gin@vlly\Gin@vurx\Gin@vury!%
        \else
          \let\GPT@clipend\GPT@DoClipEnd
          \setbox\@tempboxa\hbox\bgroup
        \fi
      \fi
      \ifGPT@viewport
        \ifdim\Gin@vlly\p@=\z@
        \else
          \lower\Gin@vlly bp\hbox\bgroup
        \fi
        \ifdim\Gin@vllx\p@=\z@
        \else
          \hskip-\Gin@vllx bp\relax
        \fi
      \fi
      \csname#1 image\GPT@page\GPT@pagebox
        \ifx\GPT@print\@empty\else!\fi
      \endcsname
      \ifGPT@viewport
        \ifdim\Gin@vlly\p@=\z@
        \else
          \egroup
        \fi
        \GPT@clipend
      \fi
    }%
  }%
}
\newif\ifGPT@viewport
\GPT@viewporttrue
\let\GPT@clipend\relax
\def\GPT@DoClipEnd{%
  \egroup
  \dp\@tempboxa\z@
  % \Gin@urx and \Gin@ury already contain the correct values,
  % so both cases viewport and trim can be handled together:
  \dimen@\Gin@urx\p@
  % v0.03k \Gin@vllx replaced by \Gin@llx
  \advance\dimen@ -\Gin@llx\p@
  \wd\@tempboxa\strip@pt\dimen@ bp\relax
  \dimen@\Gin@ury\p@
  % v0.03k \Gin@vlly replaced by \Gin@lly
  \advance\dimen@ -\Gin@lly\p@
  \ht\@tempboxa\strip@pt\dimen@ bp\relax
  \pdfxform\@tempboxa
  \pdfrefxform\pdflastxform
}
\newif\ifGPT@IsBitmap
\def\Gread@pdfbitmap#1{%
  \GPT@IsBitmaptrue
  \Gread@pdftex{#1}%
  \GPT@IsBitmapfalse
}

\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
% v0.02e: use \. not \@tempa so the space is preserved before [
        \read\@inputcheck to\.%
        \ifeof\@inputcheck
          \Gread@false
        \else
          \expandafter\Gread@find@mbox\. []\\%
        \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{%
% v0.02f add \@depth\z@ (from Sebastian)
    \pdfimage
      \@height\Gin@req@height \@width\Gin@req@width \@depth\z@
      \noexpand\noexpand\noexpand\@empty#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{%
    \Gscale@box{\Gin@scalex}[\Gin@scaley]{%
      \@ifundefined{Gin@vllx}{%
        \GPT@viewportfalse
        % without viewport/trim clipping does not make sense
        % for pdfTeX
        \Gin@clipfalse
      }{}%
      \ifGin@clip
        \if!\Gin@vllx\Gin@vlly\Gin@vurx\Gin@vury!%
        \else
          \let\GPT@clipend\GPT@DoClipEnd
          \setbox\@tempboxa\hbox\bgroup
        \fi
      \fi
      \ifGPT@viewport
        \ifdim\Gin@vlly\p@=\z@
        \else
          \lower\Gin@vlly bp\hbox\bgroup
        \fi
        \ifdim\Gin@vllx\p@=\z@
        \else
          \hskip-\Gin@vllx bp\relax
        \fi
      \fi
      \convertMPtoPDF{#1}{1}{1}%
      \ifGPT@viewport
        \ifdim\Gin@vlly\p@=\z@
        \else
          \egroup
        \fi
        \GPT@clipend
      \fi
    }%
  }%
}
\def\Gread@mps{\Gread@eps}
\let\Ginclude@png\Ginclude@pdftex
\let\Ginclude@jpg\Ginclude@pdftex
\let\Ginclude@pdf\Ginclude@pdftex
\let\Gread@pdf\Gread@pdftex
\let\Gread@png\Gread@pdfbitmap
\let\Gread@jpg\Gread@pdfbitmap

% v0.02e: restrict the rules to just the types that pdftex can currently
% deal with.
\def\Gin@extensions{.png,.pdf,.jpg,.mps}
\@namedef{Gin@rule@.jpg}#1{{jpg}{.jpg}{#1}}
\@namedef{Gin@rule@.png}#1{{png}{.png}{#1}}
\@namedef{Gin@rule@.mps}#1{{mps}{.mps}{#1}}
\@namedef{Gin@rule@.pdf}#1{{pdf}{.pdf}{#1}}


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

% Patrick Daly found an error here with doubled minus signs when \Grot@sin is
% negative. Fixed.
\def\Grot@start{%
  \pdfliteral{ q
     \Grot@cos\space\Grot@sin\space\if-\Grot@sin\else-\Grot@sin\fi\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}%
}

% Patch \Gin@setfile to execute #3, if it contains
% a command
\AtBeginDocument{%
  \let\GPT@orgGin@setfile\Gin@setfile
  \def\Gin@setfile#1#2#3{%
    \if`\@car #3\relax\@nil
      \immediate\write18{\@cdr #3\@empty\@nil}%
      \GPT@orgGin@setfile{#1}{#2}{\Gin@base #2}%
    \else
      \GPT@orgGin@setfile{#1}{#2}{#3}%
    \fi
  }%
}

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


% v0.02e: Restore catcodes of context letters.
% Not needed with current version of supp-pdf
% but protects against older versions.
\AtBeginDocument{%
  \edef\@tempa{%
    \catcode`\noexpand\!\the\catcode`\!
    \catcode`\noexpand\@\the\catcode`\@
    \catcode`\noexpand\?\the\catcode`\? }%
  \InputIfFileExists{supp-pdf}{}{}%
  \@tempa
}

% these seem to upset pdftex. ignore them. SPQR 1999/08/02
% allow for plain graphics, not graphicx.
% pdftex.def is loaded before the definition in graphicx,
% so do all the stuff \AtBeginDocument:
\AtBeginDocument{%
  \@ifundefined{define@key}{}{%
    \define@key{Gin}{natwidth}{}%
    \define@key{Gin}{natheight}{}%
  }%
}%
\endinput
% vim: syntax=tex:tw=75:ts=2
