%D \module
%D   [       file=wolf-jap,
%D        version=20xx.xx.xx,
%D          title=\CONTEXT\ User Module,
%D       subtitle=Japanese,
%D         author=Wolfgang Schuster,
%D           date=\currentdate,
%D      copyright=Wolfgang Schuster]

\writestatus{loading}{Context User Module / Japanese}

\unprotect

%D Systemvariable

\def\????rb{@@@@rb} % RuBy

%D Setup for rubyenvironment

\def\setupruby%
  {\dosingleempty\dosetupruby}

\def\dosetupruby[#1]%
  {\getparameters[\????rb][#1]}

%D Ruby definition

\def\ruby%
  {\dosingleempty\doruby}

\def\doruby[#1]#2#3% Zeichen unter Rubybase im Moment nicht unterst�tzt
  {\dontleavehmode
   \bgroup
   \getparameters[\????rb][#1]%
   \offinterlineskip
   \edef\localstrut{\@@@@rbstrut}%
   \edef\rubysize  {\switchtobodyfont[\the\dimexpr\@@@@rbscale\bodyfontsize\relax]}%
   \setbox0=\hbox{#2}\dimen0=\wd0
   \setbox1=\hbox{\rubysize#3}\dimen1=\wd1
   \ifdim\dimen0>\dimen1
     \hbox to \dimen0
       {\vbox
          {\hbox to \dimen0{\hss\ifx\localstrut\v!yes\strut\fi\box1\hss}
           \doifvalue{\@@@@rbdistance}{\vskip\@@@@rbdistance}
           \hbox{\ifx\localstrut\v!yes\strut\fi\box0}}}\space%
   \else
     %\hbox to \dimen1
     %  {\vbox
     %     {\hbox{\box1}
     %      \vskip-0.7ex
     %      \hbox to \dimen1{\hss\ifx\localstrut\v!yes\strut\fi\box0\hss}}}%
     \hbox to \dimen0
       {\vbox
          {\hbox to \dimen0{\rubysize\hss\ifx\localstrut\v!yes\strut\fi\box1\hss}
           \doifvalue{\@@@@rbdistance}{\vskip\@@@@rbdistance}
           \hbox{\ifx\localstrut\v!yes\strut\fi\box0}}}\space%
   \fi
   \egroup
   \ignorespaces}

%D A few examples
%D
%D Text text text
%D \ruby{ruby base}{ruby text}
%D text text text
%D \ruby[scale=0.7,strut=no,distance=]{ruby base}{ruby text}
%D text text text
%D 
%D Text text text
%D \ruby{ruby base}{ruby text}
%D text text text
%D \ruby[strut=no]{ruby base}{ruby text}
%D text text text
%D 
%D Text text text
%D \ruby{ruby base}{very long ruby text}
%D text text text
%D \ruby[scale=0.8,strut=no,distance=]{ruby base}{very long ruby text}
%D text text text

%D Default values

\setupruby
  [\c!distance=-0.7ex,
   \c!scale=0.6,
   \c!strut=\v!yes]

\protect \endinput
