%D \module
%D   [       file=font-run,
%D        version=1998.09.11, % (second)
%D        version=2001.02.20, % (third)
%D          title=\CONTEXT\ Font Macros,
%D       subtitle=Runtime Macros,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D [This code is hooked into the core macros and saves some
%D format space.]

\unprotect

\gdef\dosetshowfonttitle#1%
  {\tabskip\!!zeropoint
   \parindent\!!zeropoint
   \setlocalhsize
   \doifelsenothing{#1}
     {\def\title{[\the\korpsgrootte]}}
     {\switchtobodyfont[#1]\def\title{[#1]}}
   \doifsomething{\fontclass}
     {\doifnot{[\fontclass]}{\title}
        {\edef\title{[\fontclass]\space\title}}}}

\gdef\showbodyfont%
  {\dosingleempty\doshowbodyfont}

\gdef\doshowbodyfont[#1]%
  {\ifinsidefloat\else\startbaselinecorrection\fi
   \vbox
     {\dosetshowfonttitle{#1}%
      \def\bigstrut##1##2%
        {\hbox{\vrule
           \!!height ##1\ht\strutbox
           \!!depth  ##2\dp\strutbox
           \!!width  \!!zeropoint}}
      \def\next##1##2##3%
        {&&##1&&##2\tf##3&&##2\sc##3%
         &&##2\sl##3&&##2\it##3&&##2\bf##3&&##2\bs##3&&##2\bi##3%
         &&##2\tfx##3&&##2\tfxx##3%
         &&##2\tfa##3&&##2\tfb##3&&##2\tfc##3&&##2\tfd##3&\cr}%
      \halign to \localhsize
        {\bigstrut{1.5}{2}##&\vrule##
         \tabskip=\!!zeropoint \!!plus 1fill
         &\hfil##\hfil&\vrule##&\hfil##\hfil&\vrule##
         &\hfil##\hfil&\vrule##&\hfil##\hfil&\vrule##
         &\hfil##\hfil&\vrule##&\hfil##\hfil&\vrule##
         &\hfil##\hfil&\vrule##&\hfil##\hfil&\vrule##
         &\hfil##\hfil&\vrule##&\hfil##\hfil&\vrule##
         &\hfil##\hfil&\vrule##&\hfil##\hfil&\vrule##
         &\hfil##\hfil&\vrule##&\hfil##\hfil&##\vrule
         \tabskip=\!!zeropoint\cr
         \noalign{\hrule}
         &\multispan{29}{\vrule\hfil\tttf\strut\title\hfil
          \llap{\string\mr\hbox to 1em{\hss:\hss}$\mr \languageparameter\c!tekst$\quad}\vrule}\cr
         \noalign{\hrule}\next{}{\tt\string}{}
         \noalign{\hrule}\next{\tt\string\rm}\rm{\languageparameter\c!tekst}
         \noalign{\hrule}\next{\tt\string\ss}\ss{\languageparameter\c!tekst}
         \noalign{\hrule}\next{\tt\string\tt}\tt{\languageparameter\c!tekst}
         \noalign{\hrule}}}
   \ifinsidefloat\else\stopbaselinecorrection\fi}

\gdef\showbodyfontenvironment
  {\dosingleempty\doshowbodyfontenvironment}

\gdef\doshowbodyfontenvironment[#1]%
  {\ifinsidefloat\else\startbaselinecorrection\fi
   \vbox
     {\dosetshowfonttitle{#1}%
      \def\next##1%
        {&&\getvalue{\bodyfontvariable{##1\s!text}}%
         &&\getvalue{\bodyfontvariable{##1\s!script}}%
         &&\getvalue{\bodyfontvariable{##1\s!scriptscript}}%
         &&\getvalue{\bodyfontvariable{##1\c!x}}%
         &&\getvalue{\bodyfontvariable{##1\c!xx}}%
         &&\getvalue{\bodyfontvariable{##1\interfaced\v!klein}}%
         &&\getvalue{\bodyfontvariable{##1\interfaced\v!groot}}%
         &&\getvalue{\bodyfontvariable{##1\c!interlinie}}&\cr
         \noalign{\hrule}}
      \halign to \localhsize
        {##&\vrule##\strut
         \tabskip=\!!zeropoint \!!plus 1fill
         &\hfil##\hfil&\vrule##&\hfil##\hfil&\vrule##&\hfil##\hfil&\vrule##
         &\hfil##\hfil&\vrule##&\hfil##\hfil&\vrule##&\hfil##\hfil&\vrule##
         &\hfil##\hfil&\vrule##&\hfil##\hfil&##\vrule
         \tabskip=\!!zeropoint\cr
         \noalign{\hrule}
         &\multispan{17}{\vrule\hfil\tttf\strut\title\hfil}\vrule\cr
         \noalign{\hrule}
         &&\tttf\tx\s!text&&\tttf\tx\s!script&&\tttf\tx\s!scriptscript
         &&\tttf\tx\c!x&&\tttf\tx\c!xx&&\tttf\tx\v!klein&&\tttf\tx\v!groot
         &&\tttf\tx\c!interlinie&\cr
         \noalign{\hrule}
         \@EA\globalprocesscommalist\@EA[\bodyfontenvironmentlist]\next}}
   \ifinsidefloat\else\stopbaselinecorrection\fi}

\gdef\showfont
  {\dosingleempty\doshowfont}

\beginTEX \iffontchar

\gdef\iffontchar#1#2{\iftrue}

\endTEX

\gdef\doshowfont[#1]%
  {\bgroup
   \setupcolors[\c!status=\v!lokaal]%
   \iffirstargument
     \definefont[\s!dummy][#1]\dummy
   \else\ifdim2.5em>.05\hsize \tx
        \ifdim2.5em>.05\hsize \txx
   \fi\fi\fi
   \ifinsidefloat\else\startbaselinecorrection\fi
   \vbox\bgroup
   \forgetall
   \startoverlay
     {\vbox
        {\tf \setstrut \dummy
         \localcolortrue \offinterlineskip
         \dostepwiserecurse{0}{15}{1}
           {\let\row\recurselevel
            \hbox
              {\red
               \dostepwiserecurse{0}{15}{1}
                 {\let\col\recurselevel
                  \@EA\scratchcounter\normaldblquote\hexnumber\row\hexnumber\col\relax
                  \edef\rowcol{\the\scratchcounter}%
                  \iffontchar\font\scratchcounter
                    \setbox\scratchbox\ruledhbox{\black\char\scratchcounter}%
                    \ifdim\wd\scratchbox>\!!zeropoint\relax
                      \donetrue \else \donefalse
                    \fi
                  \else
                    \setbox\scratchbox\hbox{\gray\vrule\!!width1ex\!!height.5ex\!!depth.5ex}%
                  \fi
                  \startoverlay
                    {\tf\vbox to 2.5em
                       {\vss
                        \hbox to 2.5em
                          {\dummy\ifdim\fontdimen2\font=\!!zeropoint
                           \setbox\scratchbox=\hbox
                             {\raise.5\dp\scratchbox\hbox
                                {\lower.5\ht\scratchbox\copy\scratchbox}}%
                             \ht\scratchbox\zeropoint
                             \dp\scratchbox\zeropoint
                           \else
                             \ht\scratchbox\ht\strutbox
                             \dp\scratchbox\dp\strutbox
                             \strut
                           \fi
                           \hss\copy\scratchbox\hss}
                        \vss}}
                    {\tf\vbox to 2.3em
                       {\ifdone
                          \blue \hsize2.4em
                          \edef\ascii
                            {\ifnum\hyphenchar\font=\rowcol
                               hyph%
                             \else\ifnum\skewchar\font=\rowcol
                               skew%
                             \fi\fi}%
                          \tinyfont
                          {\red\ascii}\hfill
                          \number\rowcol
                          \vfill
                          \octnumber\rowcol\hfill
                          \lchexnumbers\rowcol\par
                        \fi}}
                  \stopoverlay}}}
          \par}}
     {\tf\basegrid[\c!nx=16,\c!ny=16,\c!dx=2.5,\c!dy=2.5,\c!eenheid=em]}
   \stopoverlay
   \nointerlineskip
   \vskip2pt
   \edef\ascii % \noexpand needed for non etex 
     {name:     {\noexpand\black\fontname\font  }\quad
      encoding: {\noexpand\black\currentencoding}\quad
      mapping:  {\noexpand\black\currentmapping }\quad
      handling: {\noexpand\black\fonthandling   }}%
   \tf\hbox to 40em
     {\blue\hfill\tinyfont\setstrut\strut\ascii}
   \egroup
   \ifinsidefloat\else\stopbaselinecorrection\fi
   \egroup}

\gdef\showfontstyle
  {\dotripleempty\doshowfontstyle}

\gdef\doshowfontstyle[#1][#2][#3]%
  {\ifthirdargument
     \bgroup
     \raggedright
     \switchtobodyfont[#1]
     \def\dodocommando##1##2%
       {\starttextrule{\tttf #1 ##1 ##2}
        \nobreak \getvalue{##2}%
        \dorecurse{255}
          {\iffontchar\font\recurselevel\relax
             \char\recurselevel\relax\space
           \fi}
        \par \nobreak
        \stoptextrule}
     \def\docommando##1%
       {\getvalue{##1}\processcommacommand[#3]{\dodocommando{##1}}}
     \processcommalist[#2]\docommando
     \egroup
   \else\ifsecondargument
                      \showfontstyle[#1][#2][\alternativetextlist]%
     \doif{#2}{\c!mm}{\showfontstyle[#1][#2][\alternativemathlist]}%
   \else
     \showfontstyle[#1][\c!rm]\showfontstyle[#1][\c!ss]
     \showfontstyle[#1][\c!tt]\showfontstyle[#1][\c!mm]
   \fi\fi}

\gdef\showligature#1%
  {\hbox{\type{#1}\enspace\red\ruledhbox{\black#1}}}

\gdef\showligatures[#1]%
  {\bgroup
   \setupcolors[\c!status=\v!lokaal]%
   \def\show##1{\hbox{\red\ruledhbox{\black##1}}}%
   \definefont[\s!dummy][#1]\dummy
   \starttabulate[|*{9}{c|}]
   \NC\type{ff}\NC\type{fi}\NC\type{fl}\NC\type{ffi}\NC\type{ffl}\NC 
      \type{``}\NC\type{''}\NC\type{--}\NC\type{---}\NC\NR 
   \NC\show{ff}\NC\show{fi}\NC\show{fl}\NC\show{ffi}\NC\show{ffl}\NC 
      \show{``}\NC\show{''}\NC\show{--}\NC\show{---}\NC\NR 
   \stoptabulate
   \egroup}

\gdef\showfontstrip
  {\dosingleempty\doshowfontstrip}

\gdef\doshowfontstrip[#1]%
  {\bgroup
   \def\dofontstripa##1##2%
     {\tttf\string##1}
   \def\dofontstripb##1##2%
     {\ruledhbox{\switchtobodyfont[#1]##1{##2}}}
   \def\dofontstripc##1##2%
     {\setbox\scratchbox\hbox{\switchtobodyfont[#1]##1{##2}}%
      \tt\tfx\the\ht\scratchbox}%
   \def\dofontstripd##1##2%
     {\setbox\scratchbox\hbox{\switchtobodyfont[#1]##1{##2}}%
      \tt\tfx\the\wd\scratchbox}%
   \def\fontstrip##1##2##3%
     {\NC##2\rm{##3}\NC
         ##2\ss{##3}\NC
         ##2\tt{##3}\NC
         ##2\mathematics{##3}\NC
         \tttf##1\NR}
   \starttabulate[|c|c|c|c|c|]
     \fontstrip\relax\dofontstripa\empty
     \TB
     \fontstrip\relax\dofontstripb{xxxx}
     \fontstrip\relax\dofontstripb{12345}
     \fontstrip\relax\dofontstripb{(Agw)}
     \TB
     \fontstrip{(x height)}\dofontstripc{x}
     \fontstrip{(m  width)}\dofontstripd{m}
   \stoptabulate
   \egroup}

\ifx\databox\undefined \newbox\databox \fi 

\gdef\testminimalbaseline#1%
  {\setbox\databox\ruledhbox{#1}%
   \scratchdimen\ht\databox
   \advance\scratchdimen\dp\databox
   \scratchtoks{#1}%
   \expanded
     {\NC \ruledhbox{\the\scratchtoks}
      \noexpand \NC ->
      \noexpand \NC \the\scratchdimen
      \noexpand \NC =
      \noexpand \NC \the\ht\databox
      \noexpand \NC +
      \noexpand \NC \the\dp\databox
      \noexpand \NC \ifdim\scratchdimen<\baselineskip <
                    \else\ifdim\scratchdimen=\baselineskip =
                    \else > \fi\fi 
      \noexpand \NC \the\baselineskip
      \noexpand \NC (\ifdim\scratchdimen>\baselineskip not \fi ok)  
      \noexpand \NC \noexpand \NR }}

\gdef\showminimalbaseline
  {\starttabulate[||T|T|T|T|T|T|T|T|T|]
   \testminimalbaseline{\hbox to 1em{\hss\showstruts\strut\hss}}%
   \testminimalbaseline{(/)}%
   \testminimalbaseline{$\frac{1}{2}x^2_3$}
   \stoptabulate}

\gdef\showkerning#1%
  {\bgroup
   \let\MPfshowcommand\ruledhbox
   \setMPtext\s!dummy{#1}%
   \startMPcode draw textext(\MPstring\s!dummy);\stopMPcode
   \egroup}

\protect \endinput
