% Copyright 2006 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/systemlayer/pgfsys-dvipdfm.def,v 1.14 2007/06/07 07:41:11 tantau Exp $

% Driver commands for dvipdfm

%
% Load common pdf commands:
%
\input pgfsys-common-pdf.def

%
% dvipdfm-specific stuff:
%
\def\pgfsys@invoke#1{\special{pdf: content Q #1 q}}

\def\pgfsys@hbox#1{%
  \special{pdf: content Q q -1 0 0 -1 0 0 cm q}%
  \special{pdf: content -1 0 0 -1 0 0 cm 3 Tr q}% translate to
                                % original coordinate system and do
                                % not show anything
  {\hbox to 0pt{\pgfutil@font@normalfont\pgfutil@selectfont.\hss}}% enforce font change
  \special{pdf: content Q 0 Tr q}% end of font change enforcement.
    \wd#1=0pt%
    \ht#1=0pt%
    \dp#1=0pt%
    \box#1
  \special{pdf: content Q n Q}%
}
\def\pgfsys@beginpicture{%
  \special{pdf: content Q 3 Tr q}% do not show anything
  \hbox to 0pt{\pgfutil@font@normalfont\pgfutil@selectfont.\hss}% enforce font change
  \special{pdf: content Q 0 Tr q}% end of font change enforcement.
  \special{pdf: content q}}
\def\pgfsys@endpicture{%
  \special{pdf: content n Q}%
}
\def\pgfsys@beginpurepicture{\special{pdf: content q}}


\def\pgf@sys@pdf@addtopageresources@extgs#1{%
  \ifx\pgf@sys@pdf@obj\@undefined%
    \global\let\pgf@sys@pdf@obj=\relax%
    \special{pdf: obj @pgfopacities << >>}%
  \fi%
  \special{pdf: put @pgfopacities << #1 >>}%
  \special{pdf: put @resources << /ExtGState @pgfopacities >>}%
}
\def\pgf@sys@pdf@readdtopageresources@extgs#1{%
  \special{pdf: put @resources << /ExtGState @pgfopacities >>}%
}

\def\pgfsys@imagesuffixlist{pdf:jpg:jpeg:png}
\def\pgfsys@horishading#1#2#3{%
  {%
    \pgf@parsefunc{#3}%
    \pgf@process{\pgfpoint{\pgf@max}{#2}}%
    \edef\@temp{\noexpand\pgf@sys@atbeginpage{\special{pdf: beginxobj @pgfshade#1 width \the\pgf@max\space height \the\pgf@y}}}\@temp%
    \edef\@temp{\noexpand\pgf@sys@atbeginpage{\special{pdf: put @resources <<
      /Shading << /Sh << /ShadingType 2
      /ColorSpace /DeviceRGB
      /Domain [\pgf@pdfparseddomain]
      /Coords [\pgf@doma\space0 \pgf@domb\space0]
      /Function \pgf@pdfparsedfunction
      /Extend [false false] >> >> >>}}}\@temp%
      \pgf@sys@atbeginpage{\special{pdf: content /Sh sh}%
      \special{pdf: endxobj}}%
    \expandafter\xdef\csname @pgfshading#1!\endcsname{%
      \hbox to\the\pgf@max{\vbox to#2{\vfil\special{pdf: usexobj @pgfshade#1}}\hfil}}% 
  }%
}
\def\pgfsys@vertshading#1#2#3{%
  {%
    \pgf@parsefunc{#3}%
    \pgf@process{\pgfpoint{\pgf@max}{#2}}%
    \edef\@temp{\noexpand\pgf@sys@atbeginpage{\special{pdf: beginxobj @pgfshade#1 width \the\pgf@y\space height \the\pgf@max\space}}}\@temp%
    \edef\@temp{\noexpand\pgf@sys@atbeginpage{\special{pdf: put @resources <<
      /Shading << /Sh << /ShadingType 2
      /ColorSpace /DeviceRGB
      /Domain [\pgf@pdfparseddomain]
      /Coords [0 \pgf@doma\space0 \pgf@domb]
      /Function \pgf@pdfparsedfunction
      /Extend [false false] >> >> >>}}}\@temp%
      \pgf@sys@atbeginpage{\special{pdf: content /Sh sh}%
      \special{pdf: endxobj}}%
    \expandafter\xdef\csname @pgfshading#1!\endcsname{%
      \hbox to#2{\vbox to\the\pgf@max{\vfil\special{pdf: usexobj @pgfshade#1}}\hfil}}% 
  }%
}
\def\pgfsys@radialshading#1#2#3{%
  {%
    \pgf@parsefunc{#3}%
    \pgf@process{#2}%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{\pgfpoint{\pgf@max}{\pgf@max}}%
    \advance\pgf@xa by \pgf@x\relax%
    \advance\pgf@ya by \pgf@y\relax%
    \pgf@sys@bp@correct{\pgf@x}%
    \pgf@sys@bp@correct{\pgf@y}%
    \pgf@sys@bp@correct{\pgf@xa}%
    \pgf@sys@bp@correct{\pgf@ya}%
    \pgfutil@tempdima=2\pgf@max\relax%
    \edef\@temp{\noexpand\pgf@sys@atbeginpage{\special{pdf: beginxobj @pgfshade#1 width \the\pgfutil@tempdima\space height \the\pgfutil@tempdima}}}\@temp%
    \edef\@temp{\noexpand\pgf@sys@atbeginpage{\special{pdf: put @resources <<
      /Shading << /Sh << /ShadingType 3
      /ColorSpace /DeviceRGB
      /Domain [\pgf@pdfparseddomain]
      /Coords [\pgf@sys@tonumber{\pgf@xa} \pgf@sys@tonumber{\pgf@ya} \pgf@doma\space \pgf@sys@tonumber{\pgf@x} \pgf@sys@tonumber{\pgf@y} \pgf@domb]
      /Function \pgf@pdfparsedfunction
      /Extend [true false] >> >> >>}}}\@temp%
      \pgf@sys@atbeginpage{\special{pdf: content /Sh sh}%
      \special{pdf: endxobj}}%
    \expandafter\xdef\csname @pgfshading#1!\endcsname{%
      \hbox to\the\pgfutil@tempdima{\vbox to\the\pgfutil@tempdima{\vfil\special{pdf: usexobj @pgfshade#1}}\hfil}}% 
  }%
}%


\def\pgf@sys@atbeginpage#1{\AtBeginDvi{#1}}
\AtBeginDocument{% hyperref hack
  \ifx\HyPL@EveryPage\@undefined\def\HyPL@EveryPage{}\fi
  \def\@begindvi{\unvbox\@begindvibox\HyPL@EveryPage}
}


%
% Position tracking (needs pdftex >= 1.40.0-alpha-20051205 in dvi mode)
%
\ifx\pdftexversion\@undefined
\else
  \ifnum\pdftexversion>139

\def\pgfsys@markposition#1{%
  \pdfsavepos%
  \edef\pgf@temp{#1}%
  \expandafter\write\expandafter\pgfutil@auxout\expandafter{%
    \expandafter\noexpand\expandafter\pgfsyspdfmark\expandafter{\pgf@temp}{\the\pdflastxpos}{\the\pdflastypos}}%
}

\def\pgfsyspdfmark#1#2#3{%
  \expandafter\gdef\csname pgf@sys@pdf@mark@pos@#1\endcsname{\pgfqpoint{#2sp}{#3sp}}%
}

\def\pgfsys@getposition#1#2{%
  \edef\pgf@marshal{\let\noexpand#2=\expandafter\noexpand\csname pgf@sys@pdf@mark@pos@#1\endcsname}%
  \pgf@marshal%
}

\def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfpointorigin}

  \fi
\fi

\endinput

%%% Local Variables: 
%%% mode: latex
%%% End: 
