\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{nccboxes}
         [2002/03/20 v1.04 Additional Boxes (NCC)]
%
% \changes{v1.03}{2002/01/29}{This version is uploaded to CTAN}
% \changes{v1.04}{2002/03/20}{Internal changes in \jvbox}
% \changes{v1.04}{2002/03/20}{The \jparbox command introduced}
% \Strutletter is the prototype for special struts. \Strut/n/ means a strut
% which height is n lines higher (n>0) or which depth is n lines dipper
% (n<0) than prototype. Height of one line is equal to the full height of
% ordinary \strut. \Strutstretch is a stretch of \cbox line full height
% with respect to \strut. \NCC@strutsep is a half of difference between
% stretched \strut and strut letter full height.
%
\newcommand{\Strutletter}{A}
\newcommand{\Strutstretch}{1.5}
\newsavebox\NCC@strutbox
\newdimen\NCC@strutsep
%
% Support for special struts.
%
\def\NCC@setstrut#1{%
  \setbox\NCC@strutbox\hbox{\vphantom{\Strutletter}}%
  \@tempdima\ht\strutbox \advance\@tempdima\dp\strutbox
  \NCC@strutsep \Strutstretch\@tempdima 
  \advance\NCC@strutsep -\ht\NCC@strutbox
  \advance\NCC@strutsep -\dp\NCC@strutbox
  \NCC@strutsep .5\NCC@strutsep
  \@ifnextchar/{\NCC@setstrutn{#1}}{\NCC@setstrutl{#1}\z@}%
}
\def\NCC@setstrutn#1/#2/{\NCC@setstrutl{#1}{#2\@tempdima}}
\def\NCC@setstrutl#1#2{%
  \setlength\@tempdima{#2}% 
  \ifdim\@tempdima>\z@
    \advance\@tempdima \ht\NCC@strutbox 
    \ht\NCC@strutbox \@tempdima 
  \else
    \@tempdima -\@tempdima 
    \advance\@tempdima \dp\NCC@strutbox
    \dp\NCC@strutbox \@tempdima 
  \fi
  #1%
}
\newcommand{\Strut}{%
  \NCC@setstrut{\leavevmode\copy\NCC@strutbox\ignorespaces}%
}
%
% \tstrut -- special strut which height is increased to the \NCC@strutsep.
% \tstrut -- special strut which depth is increased to the \NCC@strutsep. 
% \tbstrut -- special strut which height and depth are increased to the
%             \NCC@strutsep.
%
\newcommand{\tstrut}{%
  \NCC@setstrut{}\addbox\NCC@strutsep\z@{\copy\NCC@strutbox}%
}
\newcommand{\bstrut}{%
  \NCC@setstrut{}\addbox\z@\NCC@strutsep{\copy\NCC@strutbox}%
}
\newcommand{\tbstrut}{%
  \NCC@setstrut{}\addbox\NCC@strutsep\NCC@strutsep{\copy\NCC@strutbox}%
}
%
% \addbox{height to add}{depth to add}{text}
%
\newcommand*{\addbox}[3]{%
  \@begin@tempboxa\hbox{#3}%
    \setlength\@tempdima{#1}%
    \advance\@tempdima \ht\@tempboxa 
    \ht\@tempboxa \@tempdima
    \setlength\@tempdima{#2}%
    \advance\@tempdima \dp\@tempboxa 
    \dp\@tempboxa \@tempdima
    \leavevmode\box\@tempboxa
  \@end@tempboxa
}
%
% \jhbox{prototype}[pos]{content}. The content is positioned in the box of
% of prototype's width. Position is one of l, c, r.
%
\newcommand*{\jhbox}[1]{\settowidth\@tempdima{#1}\makebox[\@tempdima]}
%
% \jvbox{prototype}[pos]{content} The content is raised or lowered to be
% vertically adjusted with respect to prototype. The adjustment method is
% one of t, b, c. The height and depth of the resulting box are calculated
% as maximum between corresponding parameters of prototype and vertically
% adjusted content.
%
\newcommand*{\jvbox}[1]{%
  \setbox\z@\hbox{\color@begingroup#1\color@endgroup}%
  \setbox\z@\hbox{\vrule \@width\z@ \@height\ht\z@ \@depth\dp\z@}%
  \NCC@jvbox
}
\newcommand*{\NCC@jvbox}[2][]{%
  \setbox\@tempboxa\hbox{\color@begingroup#2\color@endgroup}%
  \let\m@t\vss \let\m@b\vss 
  \@tfor\@tempa :=#1\do {%
    \expandafter\let\csname m@\@tempa\endcsname\relax}%
  \@tempdima\ht\z@ \advance\@tempdima -\ht\@tempboxa
  \ifx\m@t\relax \else
    \@tempdimb\dp\@tempboxa \advance\@tempdimb -\dp\z@
    \ifx\m@b\relax \@tempdima \@tempdimb \else
      \advance\@tempdimb \@tempdima \@tempdima .5\@tempdimb
    \fi
  \fi
  \leavevmode \box\z@ \raise\@tempdima\box\@tempboxa
}
%
% \jparbox{prototype}[pos]{width}{body}
%
\newcommand*{\jparbox}[1]{%
  \@ifnextchar[{\NCC@jparbox{#1}}{\NCC@jparbox{#1}[]}%
}
\long\def\NCC@jparbox#1[#2]#3#4{%
  \@begin@tempboxa\vtop{\setlength\@tempdima{#3}%
    \hsize\@tempdima\@parboxrestore#4\@@par}%
    \jvbox{#1}[#2]{\box\@tempboxa}%
  \@end@tempboxa
}
%
% \pbox[pos]{text\\text\\...} is a simple one-column table. \arraystretch
% has no effect on it. [pos] is a combination of vertical (tbc) and
% horisontal (lcr) positions. For example, [lt] means left adjusted table
% with first line on the base line.
%
\newcommand*{\pbox}[2][]{%
  \let\m@l\hss \let\m@r\hss \let\m@t\vss \let\m@b\vss
  \@tfor\@tempa:=#1\do{%
    \expandafter\let\csname m@\@tempa\endcsname\relax%
  }%
  \leavevmode\hbox{\color@begingroup
    $\ifx\m@t\relax \vtop  \else\ifx\m@b\relax \vbox\else \vcenter\fi\fi
    \bgroup \baselineskip\z@\lineskip\z@
      \def\\{\strut\@stackcr}%
      \halign{\m@l\ignorespaces ##\unskip\m@r\cr #2\strut\crcr}%
    \egroup$\color@endgroup
  }%
}
%
% \cbox/n/[pos]{content} is a simple one-column table vertically expanded to
% \tstrut in the first line and to \bstrut in the last line. It is
% vertically adjusted with respect to \Strut/n/.
%
% \cbox*/n/[pos]{content} means the same expect height and depth of the
% resulting are set to zero.
%
% \cboxstyle means a style applied to all cboxex (font size, shape, color,
% etc.)
%
\newcommand{\cboxstyle}{}
\newcommand{\cbox}{%
  \@ifstar{\def\@tempa{\ht\@tempboxa\z@ \dp\@tempboxa\z@}\NCC@xcbox}%
          {\let\@tempa\relax\NCC@xcbox}%
}
\def\NCC@xcbox{%
  \leavevmode \hbox\bgroup\color@begingroup
  \cboxstyle\NCC@setstrut{\NCC@ycbox}%
}
\newcommand*{\NCC@ycbox}[2][]{%
  \setbox\@tempboxa\hbox{%
    \jvbox{\addbox\NCC@strutsep\NCC@strutsep{\copy\NCC@strutbox}}[#1]%
      {\pbox[#1t]{\tstrut\ignorespaces #2\unskip\bstrut}}}%
  \@tempa \box\@tempboxa
  \color@endgroup\egroup
}
%
% \picbox{...} = \begin{picture}(0,0)...\end{picture}
%
\newcommand*{\picbox}[1]{%
  \setbox\@tempboxa\hb@xt@\z@{\ignorespaces#1\hss}%
  \ht\@tempboxa\z@\dp\@tempboxa\z@
  \leavevmode\box\@tempboxa
}
\endinput
