
% Driver commands for 'xdvir' output

% Modelled on pgfsys-common-svg.def
%         and pgfsys-dvisvgm.def

% Helper functions:

\def\pgf@sys@xdvirnum#1{%
  {%
    \pgf@x=#1\relax%
    \edef\temp{\expandafter\Pgf@geT\the\pgf@x}%
    \pgfutil@toks@\expandafter\expandafter\expandafter{\expandafter\pgf@sys@xdvirpath\temp}%
    \xdef\pgf@sys@xdvirpath{\the\pgfutil@toks@}%
  }%
}

% Accumulator for paths
\let\pgf@sys@xdvirpath=\pgfutil@empty
\def\pgf@sys@addtoxdvirpath#1{\pgfutil@g@addto@macro\pgf@sys@xdvirpath{#1}}
\def\pgf@sys@flushxdvirpath{%
  \pgfsysprotocol@literal{\pgf@sys@xdvirpath;}%
  \global\let\pgf@sys@xdvirpath=\pgfutil@empty%
}

\def\pgf@sys@xdvir@gs#1{%
  \pgfsysprotocol@literal{gs #1;}%
}

%%% \newcount\pgf@sys@svg@objectcount
%%% 
%%% {\catcode`\%=12
%%% \gdef\pgf@sys@svg@percentchar{%}
%%% }

{\catcode`\#=11
\gdef\pgf@sys@xdvir@hash{#}
}

% Path construction:

\def\pgfsys@moveto#1#2{%
  \pgf@sys@addtoxdvirpath{moveto }\pgf@sys@xdvirnum{#1}%
  \pgf@sys@addtoxdvirpath{,}\pgf@sys@xdvirnum{#2}%
  \pgf@sys@addtoxdvirpath{:}%
}
\def\pgfsys@lineto#1#2{%
  \pgf@sys@addtoxdvirpath{lineto }\pgf@sys@xdvirnum{#1}%
  \pgf@sys@addtoxdvirpath{,}\pgf@sys@xdvirnum{#2}%
  \pgf@sys@addtoxdvirpath{:}%
}
\def\pgfsys@curveto#1#2#3#4#5#6{%
  \pgf@sys@addtoxdvirpath{curveto }\pgf@sys@xdvirnum{#1}%
  \pgf@sys@addtoxdvirpath{,}\pgf@sys@xdvirnum{#2}%
  \pgf@sys@addtoxdvirpath{,}\pgf@sys@xdvirnum{#3}%
  \pgf@sys@addtoxdvirpath{,}\pgf@sys@xdvirnum{#4}%
  \pgf@sys@addtoxdvirpath{,}\pgf@sys@xdvirnum{#5}%
  \pgf@sys@addtoxdvirpath{,}\pgf@sys@xdvirnum{#6}%
  \pgf@sys@addtoxdvirpath{:}%
}
% Start with moveto so ALL paths start with move
\def\pgfsys@rect#1#2#3#4{%
  \pgf@sys@addtoxdvirpath{moveto }\pgf@sys@xdvirnum{#1}%
  \pgf@sys@addtoxdvirpath{,}\pgf@sys@xdvirnum{#2}%
  \pgf@sys@addtoxdvirpath{:}%
  \pgf@sys@addtoxdvirpath{rect }\pgf@sys@xdvirnum{#1}%
  \pgf@sys@addtoxdvirpath{,}\pgf@sys@xdvirnum{#2}%
  \pgf@sys@addtoxdvirpath{,}\pgf@sys@xdvirnum{#3}%
  \pgf@sys@addtoxdvirpath{,}\pgf@sys@xdvirnum{#4}%
  \pgf@sys@addtoxdvirpath{:}%
  \pgf@sys@addtoxdvirpath{close}%
  \pgf@sys@addtoxdvirpath{:}%
}
\def\pgfsys@closepath{%
  \pgf@sys@addtoxdvirpath{close}%
  \pgf@sys@addtoxdvirpath{:}%
}


% Path usage:
\newif\ifpgf@sys@xdvir@clipnext

\def\pgf@sys@xdvir@newpath{%
  \pgfsysprotocol@literal{new-path;}%
}
\def\pgfsys@stroke{%
  \ifpgf@sys@xdvir@clipnext%
    \pgf@sys@xdvir@newpath%
    \pgf@sys@flushxdvirpath%
    \pgfsysprotocol@literal{stroke-clip;}%
    \pgf@sys@xdvir@clipnextfalse%
  \else%
    \pgf@sys@xdvir@newpath%
    \pgf@sys@flushxdvirpath%
    \pgfsysprotocol@literal{stroke;}%
  \fi%
}

\def\pgfsys@fill{%
  \ifpgf@sys@xdvir@clipnext%
    \pgf@sys@xdvir@newpath%
    \pgf@sys@addtoxdvirpath{close}% Ensure path is closed
    \pgf@sys@addtoxdvirpath{:}%
    \pgf@sys@flushxdvirpath%
    \pgfsysprotocol@literal{fill-clip;}
    \pgf@sys@xdvir@clipnextfalse%
  \else%
    \pgf@sys@xdvir@newpath%
    \pgf@sys@addtoxdvirpath{close}% Ensure path is closed
    \pgf@sys@addtoxdvirpath{:}%
    \pgf@sys@flushxdvirpath%
    \pgfsysprotocol@literal{fill;}
  \fi%
}

\def\pgfsys@fillstroke{%
  \ifpgf@sys@xdvir@clipnext%
    \pgf@sys@xdvir@newpath%
    \pgf@sys@flushxdvirpath%
    \pgfsysprotocol@literal{fill-stroke-clip;}
    \pgf@sys@xdvir@clipnextfalse%
  \else%
    \pgf@sys@xdvir@newpath%
    \pgf@sys@flushxdvirpath%
    \pgfsysprotocol@literal{fill-stroke;}
  \fi%
}

\def\pgfsys@clipnext{\pgf@sys@xdvir@clipnexttrue}

\def\pgfsys@discardpath{%
  \ifpgf@sys@xdvir@clipnext%
    \pgf@sys@xdvir@newpath%
    \pgf@sys@flushxdvirpath%
    \pgfsysprotocol@literal{clip;}
    \pgf@sys@xdvir@clipnextfalse%
  \else%
    \global\let\pgf@sys@xdvirpath=\pgfutil@empty
  \fi
}

% Fill rules:
\def\pgfsys@eoruletrue{\pgf@sys@xdvir@gs{fill-rule=evenodd}}
\def\pgfsys@eorulefalse{\pgf@sys@xdvir@gs{fill-rule=nonzero}}

% Transparency:
\def\pgfsys@stroke@opacity#1{\pgf@sys@xdvir@gs{stroke-opacity=#1}}
\def\pgfsys@fill@opacity#1{\pgf@sys@xdvir@gs{fill-opacity=#1}\def\pgf@sys@svg@opacity{#1}}
\def\pgf@sys@xdvir@opacity{1}
\def\pgfsys@blend@mode#1{\pgf@sys@xdvir@gs{blend-mode=#1}}
% FIXME:  more operations to support 

% Transformation:
\def\pgfsys@transformcm#1#2#3#4#5#6{%
  {\pgf@x=#5\pgf@y=#6%
  \pgfsysprotocol@literal{transform #1,#2,#3,#4,\pgf@sys@tonumber{\pgf@x},\pgf@sys@tonumber{\pgf@y};}}}

% Scopes
\newcount\pgf@sys@xdvir@scopecount
\def\pgfsys@beginscope{%
  \edef\pgf@sys@xdvir@thescopecount{\the\pgf@sys@xdvir@scopecount}%
  \begingroup%
    \pgf@sys@xdvir@scopecount=1\relax%
    \pgfsysprotocol@literal{begin-scope;}%
}
\def\pgfsys@endscope{%
    \loop%
      \pgfsysprotocol@literal{end-scope;}%
      \advance\pgf@sys@xdvir@scopecount by-1\relax%
    \ifnum\pgf@sys@xdvir@scopecount>0\relax%
    \repeat%
  \endgroup%
  \global\pgf@sys@xdvir@scopecount=\pgf@sys@xdvir@thescopecount\relax%  
}

% Graphics state

% NOTE: dash offset not supported
\def\pgfsys@setdash#1#2{%
  \edef\pgf@test@dashpattern{#1}%
  \ifx\pgf@test@dashpattern\pgfutil@empty%
    \pgf@sys@xdvir@gs{lty=none}%
  \else%
    \pgf@sys@xdvir@gs{lty=#1}%
  \fi
}
\def\pgfsys@setlinewidth#1{\pgf@sys@xdvir@gs{lwd=#1}}
\def\pgfsys@setmiterlimit#1{\pgf@sys@xdvir@gs{linemitre=#1}}
\def\pgfsys@buttcap{\pgf@sys@xdvir@gs{lineend=butt}}
\def\pgfsys@roundcap{\pgf@sys@xdvir@gs{lineend=round}}
\def\pgfsys@rectcap{\pgf@sys@xdvir@gs{lineend=square}}
\def\pgfsys@miterjoin{\pgf@sys@xdvir@gs{linejoin=mitre}}
\def\pgfsys@roundjoin{\pgf@sys@xdvir@gs{linejoin=round}}
\def\pgfsys@beveljoin{\pgf@sys@xdvir@gs{linejoin=bevel}}

%
% Color management
% 

\def\pgf@sys@xdvir@color@rgb#1,#2,#3\relax{%
  {%
    \xdef\pgf@sys@xdvir@prepared{rgb(#1,#2,#3)}%
  }%
}
\def\pgf@sys@xdvir@color@cmy#1,#2,#3\relax{%
  {%
    \xdef\pgf@sys@xdvir@prepared{cmy(#1,#2,#3)}%
  }%
}
\def\pgf@sys@xdvir@color@cmyk#1,#2,#3,#4\relax{%
  {%
    \xdef\pgf@sys@xdvir@prepared{cmyk(#1,#2,#3,#4)}%
  }%
}
\def\pgf@sys@xdvir@color@gray#1\relax{%
 {%
    \xdef\pgf@sys@xdvir@prepared{gray(#1)}%
  }%
}

\def\pgf@sys@xdvir@gs@color#1{%
  \ifpgfpicture\pgf@sys@xdvir@gs{#1}\fi%
}

\def\pgfsys@color@rgb@stroke#1#2#3{%
  \pgf@sys@xdvir@color@rgb#1,#2,#3\relax%
  \pgf@sys@xdvir@gs@color{col=\pgf@sys@xdvir@prepared}}
\def\pgfsys@color@rgb@fill#1#2#3{%
  \pgf@sys@xdvir@color@rgb#1,#2,#3\relax%
  \pgf@sys@xdvir@gs@color{fill=\pgf@sys@xdvir@prepared}}
\def\pgfsys@color@cmyk@stroke#1#2#3#4{%
  \pgf@sys@xdvir@color@cmyk#1,#2,#3,#4\relax%
  \pgf@sys@xdvir@gs@color{col=\pgf@sys@xdvir@prepared}}
\def\pgfsys@color@cmyk@fill#1#2#3#4{%
  \pgf@sys@xdvir@color@cmyk#1,#2,#3,#4\relax%
  \pgf@sys@xdvir@gs@color{fill=\pgf@sys@xdvir@prepared}}
\def\pgfsys@color@cmy@stroke#1#2#3{%
  \pgf@sys@xdvir@color@cmy#1,#2,#3\relax%
  \pgf@sys@xdvir@gs@color{col=\pgf@sys@xdvir@prepared}}
\def\pgfsys@color@cmy@fill#1#2#3{%
  \pgf@sys@xdvir@color@cmy#1,#2,#3\relax%
  \pgf@sys@xdvir@gs@color{fill=\pgf@sys@xdvir@prepared}}
\def\pgfsys@color@gray@stroke#1{%
  \pgf@sys@xdvir@color@gray#1\relax%
  \pgf@sys@xdvir@gs@color{col=\pgf@sys@xdvir@prepared}}
\def\pgfsys@color@gray@fill#1{%
  \pgf@sys@xdvir@color@gray#1\relax%
  \pgf@sys@xdvir@gs@color{fill=\pgf@sys@xdvir@prepared}}

%%% % Shadings:
%%% \def\pgf@sys@svg@shading@stops{%
%%%   % Step 1: Compute 1/\pgf@sys@shading@end@pos
%%%   \pgf@x=\pgf@sys@shading@end@pos\relax%
%%%   \c@pgf@counta=\pgf@x\relax%
%%%   \divide\c@pgf@counta by4096\relax%
%%%   % Step 2: Insert stops.
%%%   \expandafter\pgf@sys@svg@shading@dostops\pgf@sys@shading@ranges%
%%%     % dummy for end:
%%%     {{\pgf@sys@shading@end@pos}{\pgf@sys@shading@end@pos}{\pgf@sys@shading@end@rgb}{\pgf@sys@shading@end@rgb}}%
%%%     {}% end
%%% }
%%% \def\pgf@sys@svg@shading@dostops#1{%
%%%   \edef\pgf@test{#1}%
%%%   \ifx\pgf@test\pgfutil@empty%
%%%   \else%
%%%     \expandafter\pgf@sys@svg@shading@dostop\pgf@test%
%%%     \expandafter\pgf@sys@svg@shading@dostops%
%%%   \fi%
%%% }
%%% \def\pgf@sys@svg@shading@dostop#1#2#3#4{%
%%%   % #1 start pos
%%%   % #2 end pos
%%%   % #3 start rgb
%%%   % #4 end rgb
%%%   \pgf@sys@svg@addtostops{<stop offset="}%
%%%   \pgf@x=#1%
%%%   \pgf@x=16\pgf@x%
%%%   \divide\pgf@x by \c@pgf@counta\relax%
%%%   \pgf@sys@svg@addtostops{\pgf@sys@tonumber\pgf@x" stop-color="}%
%%%   \pgf@sys@svg@shading@dorgb#3%
%%%   \pgf@sys@svg@addtostops{"/>\noexpand\pgfsys@svg@newline}%
%%% }
%%% \def\pgf@sys@svg@shading@dorgb#1#2#3{%
%%%   \pgf@sys@svg@color@rgb#1,#2,#3\relax%
%%%   \pgf@sys@svg@addtostops{\pgf@sys@svg@prepared}%
%%% }
%%% 
%%% \let\pgf@sys@svg@thestops=\pgfutil@empty
%%% \def\pgf@sys@svg@addtostops#1{%
%%%   \edef\pgf@temp{#1}%
%%%   \expandafter\expandafter\expandafter\def
%%%   \expandafter\expandafter\expandafter\pgf@sys@svg@thestops
%%%   \expandafter\expandafter\expandafter{\expandafter\pgf@sys@svg@thestops\expandafter\space\pgf@temp}%
%%% }
%%% 
%%% 
%%% \def\pgfsys@horishading#1#2#3{%
%%%   {%
%%%     \pgf@parsefunc{#3}%
%%%     \global\advance\pgf@sys@svg@objectcount by1\relax%
%%%     \pgf@sys@svg@addtostops{<linearGradient id="pgfsh\the\pgf@sys@svg@objectcount">\noexpand\pgfsys@svg@newline}
%%%     \pgf@sys@svg@shading@stops%
%%%     \pgf@sys@svg@addtostops{</linearGradient>\noexpand\pgfsys@svg@newline}%
%%%     \pgf@process{\pgfpoint{\pgf@sys@shading@end@pos}{#2}}%
%%%     \expandafter\xdef\csname @pgfshading#1!\endcsname{%
%%%       \def\noexpand\pgf@sys@svg@sh@defs{\noexpand\pgfsysprotocol@literal{\pgf@sys@svg@thestops}}%
%%%       \def\noexpand\pgf@sys@svg@sh{\noexpand\pgfsysprotocol@literal{<rect
%%%         width="\pgf@sys@tonumber{\pgf@x}"
%%%         height="\pgf@sys@tonumber{\pgf@y}"
%%%         style="fill:url(\noexpand\#pgfsh\the\pgf@sys@svg@objectcount);
%%%           stroke:none"/>\noexpand\pgfsys@svg@newline}}%
%%%       \def\noexpand\pgf@sys@svg@pos{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
%%%     }%
%%%   }%
%%% }
%%% 
%%% \def\pgfsys@functionalshading#1#2#3#4{%
%%%   \pgf@sys@fail{functional shadings}%
%%%   \expandafter\gdef\csname @pgfshading#1!\endcsname{%
%%%     \let\pgf@sys@svg@sh@defs\relax%
%%%     \let\pgf@sys@svg@sh\relax%
%%%     \let\pgf@sys@svg@pos\pgfpointorigin%
%%%   }%
%%% }
%%% 
%%% \def\pgfsys@vertshading#1#2#3{%
%%%   {%
%%%     \pgf@parsefunc{#3}%
%%%     \global\advance\pgf@sys@svg@objectcount by1\relax%
%%%     \pgf@sys@svg@addtostops{<linearGradient
%%%       id="pgfsh\the\pgf@sys@svg@objectcount"
%%%       gradientTransform="rotate(90)">\noexpand\pgfsys@svg@newline}
%%%     \pgf@sys@svg@shading@stops%
%%%     \pgf@sys@svg@addtostops{</linearGradient>\noexpand\pgfsys@svg@newline}%
%%%     \pgf@process{\pgfpoint{\pgf@sys@shading@end@pos}{#2}}%
%%%     \expandafter\xdef\csname @pgfshading#1!\endcsname{%
%%%       \def\noexpand\pgf@sys@svg@sh@defs{\noexpand\pgfsysprotocol@literal{\pgf@sys@svg@thestops}}%
%%%       \def\noexpand\pgf@sys@svg@sh{\noexpand\pgfsysprotocol@literal{<rect
%%%         width="\pgf@sys@tonumber{\pgf@y}"
%%%         height="\pgf@sys@tonumber{\pgf@x}"
%%%         style="fill:url(\noexpand\#pgfsh\the\pgf@sys@svg@objectcount);
%%%           stroke:none"/>\noexpand\pgfsys@svg@newline}}%
%%%       \def\noexpand\pgf@sys@svg@pos{\noexpand\pgfpoint{\the\pgf@y}{\the\pgf@x}}%
%%%     }%
%%%   }%
%%% }
%%% 
%%% \def\pgfsys@radialshading#1#2#3{%
%%%   {%
%%%     \pgf@parsefunc{#3}%
%%%     \pgf@x=\pgf@sys@shading@end@pos\relax%
%%%     \c@pgf@counta=\pgf@x\relax%
%%%     \divide\c@pgf@counta by4096\relax%
%%%     \global\advance\pgf@sys@svg@objectcount by1\relax%
%%%     \pgf@process{#2}%
%%%     % Divide by 2\pgf@sys@shading@end@pos%
%%%     \pgf@x=8\pgf@x%
%%%     \divide\pgf@x by \c@pgf@counta\relax%
%%%     \pgf@y=8\pgf@y%
%%%     \divide\pgf@y by \c@pgf@counta\relax%
%%%     \advance\pgf@x by.5pt%
%%%     \advance\pgf@y by.5pt%
%%%     \pgf@sys@svg@addtostops{<radialGradient
%%%       id="pgfsh\the\pgf@sys@svg@objectcount"
%%%       fx="\pgf@sys@tonumber\pgf@x"
%%%       fy="\pgf@sys@tonumber\pgf@y"
%%%       >\noexpand\pgfsys@svg@newline}
%%%     \pgf@sys@svg@shading@stops%
%%%     \pgf@sys@svg@addtostops{</radialGradient>\noexpand\pgfsys@svg@newline}%
%%%     \pgf@xa=\pgf@sys@shading@end@pos%
%%%     \pgf@xb=2\pgf@xa%    
%%%     \expandafter\xdef\csname @pgfshading#1!\endcsname{%
%%%       \def\noexpand\pgf@sys@svg@sh@defs{\noexpand\pgfsysprotocol@literal{\pgf@sys@svg@thestops}}%
%%%       \def\noexpand\pgf@sys@svg@sh{\noexpand\pgfsysprotocol@literal{<circle
%%%         cx="\pgf@sys@tonumber{\pgf@xa}"
%%%         cy="\pgf@sys@tonumber{\pgf@xa}"
%%%         r="\pgf@sys@tonumber{\pgf@xa}"
%%%         style="fill:url(\noexpand\#pgfsh\the\pgf@sys@svg@objectcount);
%%%           stroke:none"/>\noexpand\pgfsys@svg@newline}}%
%%%       \def\noexpand\pgf@sys@svg@pos{\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@xb}}%
%%%     }%
%%%   }%
%%% }
%%% 
%%% 
%%% % Patterns
%%% 
%%% \iffalse % comment until interpage support is available
%%% 
%%% \def\pgfsys@declarepattern#1#2#3#4#5#6#7#8#9{%
%%%   % Start building the pattern dictionary:
%%%   \pgf@xa=#2\relax%
%%%   \pgf@ya=#3\relax% 
%%%   \pgf@xb=#4\relax%
%%%   \pgf@yb=#5\relax%
%%%   \pgf@xc=#6\relax%
%%%   \pgf@yc=#7\relax%
%%%   \ifnum#9=1\relax%
%%%     % Colored. That's easy:
%%%     \pgfsysprotocol@literal{
%%%       <pattern
%%%         id="pgfpat#1"
%%%         patternUnits="userSpaceOnUse"
%%%         width="\the\pgf@xc"
%%%         height="\the\pgf@yc">
%%%         #8
%%%       </pattern>}%
%%%   \else%
%%%     % Uncolored. Yikes!
%%%     \pgfsysprotocol@literal{
%%%       <pattern
%%%         id="pgfpat#1"
%%%         patternUnits="userSpaceOnUse"
%%%         width="\the\pgf@xc"
%%%         height="\the\pgf@yc"/>
%%%       <symbol id="pgfsym#1">
%%%         #8
%%%       </symbol>}%
%%%   \fi%
%%% }
%%% 
%%% \def\pgfsys@setpatternuncolored#1#2#3#4{%
%%%   \global\advance\pgf@sys@svg@objectcount by1\relax%
%%%   \pgf@sys@svg@color@rgb#2,#3,#4\relax%
%%%   \pgfsysprotocol@literal{
%%%     <pattern id="pgfupat\the\pgf@sys@svg@objectcount" xlink:href="\#pgfpat#1">
%%%     <g stroke="\pgf@sys@svg@prepared" fill="\pgf@sys@svg@prepared"> <use xlink:href="\#pgfsym#1"/> </g>
%%%     </pattern>}
%%%   \pgf@sys@svg@gs@color{fill="url(\#pgfupat\the\pgf@sys@svg@objectcount)"}%
%%% }
%%% 
%%% \def\pgfsys@setpatterncolored#1{%
%%%   \pgf@sys@svg@gs@color{fill="url(\#pgfpat#1)"}%
%%% }
%%% 
%%% \fi
%%% 
%%% 
%%% 
%%% 
%%% % Fadings
%%% 
%%% %
%%% % Opacity masks
%%% %
%%% % \def\pgfsys@fadingfrombox#1#2{%
%%% %   \setbox#2=\hbox{%
%%% %     \pgfsys@invoke{<mask id="pgfmask#1">}%
%%% %     \box#2%
%%% %     \pgfsys@invoke{</mask>}%
%%% %   }%
%%% %   \wd#2=0pt%
%%% %   \ht#2=0pt%
%%% %   \dp#2=0pt%
%%% %   \unskip\box#2%
%%% % }
%%% % \def\pgfsys@usefading#1#2#3#4#5#6#7{%
%%% %   \pgf@sys@svg@gs@color{mask="url(\#pgfmask#1)"}%
%%% % }
%%% 
%%% 
%%% 
%%% %
%%% 

\def\pgfutil@color{\pgfsetcolor}

\newif\ifpgf@sys@xdvir@inpicture

\def\pgfsys@invoke#1{\ifpgf@sys@xdvir@inpicture{\let\#\pgf@sys@xdvir@hash\special{xdvir-tikz:: #1}}\fi}
\def\pgfsys@beginpicture{%
  \pgf@sys@xdvir@inpicturetrue%
  \pgfsys@invoke{begin-picture;}%
}
\def\pgfsys@endpicture{%
  \pgfsys@invoke{end-picture \the\pgf@picminx,\the\pgf@picminy,\the\pgf@picmaxx,\the\pgf@picmaxy;}%
  \pgf@sys@xdvir@inpicturefalse%
}

\def\pgfsys@xdvir@newline{}

% Just emit normal DVI output ?
\def\pgfsys@hbox#1{
      \wd#1=0pt%
      \ht#1=0pt%
      \dp#1=0pt%
      \box#1
}

%%% \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%
%%%     \def\pgf@trimleft@final{0pt}%
%%%     \def\pgf@trimright@final{0pt}%
%%%     \def\pgf@shift@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},\pg
%%% f@sys@tonumber{\pgf@ya})">}%
%%%   \pgf@sys@svg@sh%
%%%   \pgfsysprotocol@literal{</g>}%
%%% }
%%% 

% position tracking
\def\pgfsys@markposition#1{%
  \pdfsavepos%
  \edef\pgf@temp{#1}%
  \expandafter\pgfutil@writetoaux\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}}%
  \pgfutil@check@rerun{#1}{{#2}{#3}}%
}

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

\endinput

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