\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/systemlayer/pgfsys-tex4ht.def,v 1.8 2005/08/13 18:59:56 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.


\RequirePackage{xcolor}


% Driver commands for tex4ht

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

%
% tex4ht-specific stuff:
%
\def\pgfsys@invoke#1{\HCode{#1}}

\newcount\pgf@sys@svg@picnum


\def\pgfsys@beginpicture{%
  \Configure{[]}{$}{$}
  \Configure{()}{$}{$}
  \Configure{$$}{}{}{}%$$
  \Configure{$}{}{}{}%$
  \Configure{SUB}{\HCode{<tspan baseline-shift="sub">}}{\HCode{</tspan>}}
  \Configure{SUP}{\HCode{<tspan baseline-shift="sub">}}{\HCode{</tspan>}}
  \Configure{SUBSUP}{}{}{}
  \Configure{htf} 
    {0}{+}{<tspan font-family="}
    {\%s}{" font-size="\%s}{}{}
    {">}{</tspan>}
}
\def\pgfsys@endpicture{%
  % undo:
  \Configure{htf}{0}{+}{<span\Hnewline
     class="}{\%s}{-\%s}{x-x-\%d}{}{">}{</span>}
}
 
\def\pgfsys@typesetpicturebox#1{%
  \global\advance\pgf@sys@svg@picnum by 1\relax%
  % Ok, compute width/height
  \pgf@xa=\pgf@picminx%
  \pgf@ya=\pgf@picminy%
  \pgf@xb=\pgf@picmaxx%
  \pgf@yb=\pgf@picmaxy%
  \pgf@x=\pgf@xb%
  \advance\pgf@x by-\pgf@xa%
  \pgf@y=\pgf@yb%
  \advance\pgf@y by-\pgf@ya%
  \ifdim\pgf@y<1pt%
    \pgf@y=1pt%
  \fi%
  \HCode{<object data="\jobname-\the\pgf@sys@svg@picnum.svg"
    width="\the\pgf@x" height="\the\pgf@y"
    type="image/svg+xml"><p>SVG-Viewer needed.</p></object>}%
  \special{t4ht>\jobname-\the\pgf@sys@svg@picnum.svg}%
  \pgfsys@invoke{<svg width="\the\pgf@x" height="\the\pgf@y" viewBox="}%
  \pgf@sys@pt{\pgf@xa}\pgf@sys@pt{\pgf@ya}\pgf@sys@pt{\pgf@x}\pgf@sys@pt{\pgf@y}%
  \pgfsysprotocol@flushcurrentprotocol%
  \pgf@ya=-\pgf@ya%
  \pgfsys@invoke{">\Hnewline  <g transform="translate(0,\the\pgf@yb) scale(1,-1)
    translate(0,\the\pgf@ya)">\Hnewline }%
  \setlength\pgf@x{\pgf@shift@baseline}%
  \advance\pgf@x by-\pgf@picminy\relax%
  \advance\pgf@picmaxy by-\pgf@picminy\relax% maxy is now the height
  \advance\pgf@picmaxx by-\pgf@picminx\relax% maxx is now the width
  \setbox#1=\hbox{\hskip-\pgf@picminx\lower\pgf@picminy\box#1}%
  \ht#1=\pgf@picmaxy%
  \wd#1=\pgf@picmaxx%
  \dp#1=0pt%
  \leavevmode\raise-\pgf@x\box#1%
  \pgfsys@invoke{</g>\Hnewline </svg>\Hnewline }%
  \special{t4ht<\jobname-\the\pgf@sys@svg@picnum.svg}%
}

\def\pgfsys@hbox#1{%
  \pgf@x=.5\wd#1%
  \ifx\tikz@textcolor\relax%
  \else%
    \ifx\tikz@textcolor\@empty%
      \pgfsetfillcolor{.}%
    \else%
      \pgfsetfillcolor{\tikz@textcolor}%
    \fi%
  \fi% tweak for TikZ
  \HCode{<text
    style="stroke:none"
    transform="scale(1,-1) translate(\the\pgf@x,0pt)"
    text-anchor="middle"
  }%
  \ifx\f@size\@empty%
  \else%
    \HCode{ font-size="\f@size"}%
  \fi%  
  \HCode{>\Hnewline }%
    \wd#1=0pt%
    \ht#1=0pt%
    \dp#1=0pt%
    \box#1
  \HCode{</text>\Hnewline }%
}

\def\pgfsys@outerinvoke{\ifpgfpicture\expandafter\pgfsys@invoke\else\expandafter\@gobble\fi}


\def\pgfsys@shadingoutsidepgfpicture#1{%
  \begingroup%
    #1%
    \setbox\pgfpic=\hbox to0pt{%
      \pgfsys@beginpicture%
        \pgfsys@beginscope%
          \pgf@sys@svg@sh@defs%
          \pgf@sys@svg@sh%
        \pgfsys@endscope%
      \pgfsys@endpicture%
      \hss%  
    }%
    \pgf@process{\pgf@sys@svg@pos}%
    \pgf@picminx=0pt%
    \pgf@picminy=0pt%
    \pgf@picmaxx=\pgf@x%
    \pgf@picmaxy=\pgf@y%
    \pgf@baseline=0pt%
    \pgfsys@typesetpicturebox\pgfpic%
  \endgroup%
}

\def\pgfsys@shadinginsidepgfpicture#1{%
  #1%
  \pgf@sys@svg@sh@defs% hmmm....
  \pgf@process{\pgf@sys@svg@pos}
  \pgf@xa=-.5\pgf@x%
  \pgf@ya=-.5\pgf@y%
  \pgfsysprotocol@literal{<g transform="translate(\pgf@sys@tonumber{\pgf@xa},\pgf@sys@tonumber{\pgf@ya})">\Hnewline}%
  \pgf@sys@svg@sh%
  \pgfsysprotocol@literal{</g>\Hnewline}%
}



% Protect against color.4ht evil meddling with xcolor:
\let\pgf@xcolor@declaredcolor=\@declaredcolor
\let\pgf@xcolor@undeclaredcolor=\@undeclaredcolor

\AtBeginDocument{
  \let\pgf@texht@declaredcolor=\@declaredcolor
  \let\pgf@texht@undeclaredcolor=\@undeclaredcolor
  \def\@declaredcolor{\ifpgfpicture\expandafter\pgf@xcolor@declaredcolor\else\expandafter\pgf@texht@declaredcolor\fi}
  \def\@undeclaredcolor{\ifpgfpicture\expandafter\pgf@xcolor@undeclaredcolor\else\expandafter\pgf@texht@undeclaredcolor\fi}
  \ConfigureEnv{pgfpicture}{}{}{}{}
}

\endinput


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