%D \module
%D   [     file=enco-run,
%D      version=2000.27.12, % moved to runtime module
%D        title=\CONTEXT\ Encoding Macros,
%D     subtitle=Runtime Macros,
%D       author=Hans Hagen,
%D         date=\currentdate,
%D    copyright=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.

\unprotect

\gdef\visualizecharacters% {}'s needed
  {\def\uchar##1##2{\hbox to 2.5em
     {\ifcase##1\relax\red\or\blue\else\green\fi##1\hss##2}}%
   \let\normalbuildtextaccent\buildtextaccent
   \let\normalbottomaccent   \bottomaccent
  %\def\char{\green\normalchar}%
   \def\char % can be used in \oalign
     {\bgroup\def\char{\green\normalchar\scratchcounter\egroup}%
      \afterassignment\char\scratchcounter}%
   \def\buildtextaccent{\let\green\empty\blue\normalbuildtextaccent}%
   \def\bottomaccent{\let\green\empty\red\normalbottomaccent}}

\unexpanded\gdef\visualizecharacterslegend
  {\hbox
     {\edef\banner{\currentencoding\space\fontname\font}%
      \tttf\banner:\space
      {\blue composed}\space{\red bottom}\space{\green char}\space raw}}

\gdef\showaccents
  {\bgroup
   \savefont
   \setuptextrules[\c!bodyfont=,\c!style=]
   \starttextrule{\visualizecharacterslegend}
   \whitespace
   \restorefont\setupinterlinespace
   \visualizecharacters
   \def\do##1%
     {{\def\dodo####1%
         {\hss\hbox to 1em{\hss\expanded{##1####1\recurselevel}\hss}}%
       \hbox to \hsize
         {\strut
          \localcolortrue
          \hbox to 2em{\tttf\string##1\hss}%
          \dorecurse{26}{\dodo\character}}%
       \hbox to \hsize
         {\strut
          \localcolortrue
          \hskip2em
          \dorecurse{26}{\dodo\Character}}}%
       \par}
   \do\'\do\`\do\^\do\~\do\"
   \do\H\do\r\do\v\do\u\do\=
   \do\.\do\b\do\d\do\k\do\c
   \stoptextrule
   \egroup}

\gdef\showcharacters
  {\bgroup
   \savefont
   \setuptextrules[\c!bodyfont=,\c!style=]
   \starttextrule{\visualizecharacterslegend}
   \whitespace
   \dontcomplain
   \forgetall
   \def\startencoding[##1]{}
   \def\stopencoding{\endinput}
   \dimen0=\zeropoint
   \dimen2=\zeropoint
   \def\definecharacter ##1 ##2 %
     {\setbox0=\hbox spread 1em{\getvalue{##1}}%
      \ifdim\wd0>\dimen0 \dimen0=\wd0 \fi
      \setbox2=\hbox spread 1em{\box0 \tttf##1}
      \ifdim\wd2>\dimen2 \dimen2=\wd2 \fi}%
   \readsysfile{\f!encodingprefix def}{}{}
   \edef\encwidth{\the\dimen0}
   \dimen0=\hsize
   \advance\dimen0 2em
   \advance\dimen2 2em
   \divide \dimen0 by \dimen2 \advance\dimen0 1sp
   \edef\enccols{\number\dimen0}
   \visualizecharacters
   \startcolumns[\c!n=\enccols,\c!distance=2em]
   \restorefont\setupinterlinespace
   \def\definecharacter ##1 ##2 %
     {\setbox0=\hbox to \hsize{\localcolortrue\hbox to \encwidth{\getvalue{##1}\hss}\tttf##1}%
      \ht0\strutheight \dp0\strutdepth \box0 \allowbreak}
   \readsysfile{\f!encodingprefix def}{}{}
   \stopcolumns
   \stoptextrule
   \egroup}

% \hbox
%   {\font\test=uplr8t \test \ruledhbox{t}
%    \font\test=uplr8r \test \ruledhbox{t}}

\beginETEX \fontcharwd

\gdef\showcharacterbounds
  {\bgroup
   \localcolortrue
   \dorecurse{255}
     {\ifnum\fontcharwd\font\recurselevel>\zeropoint
        \noindent\ruledhbox{\darkgray\char\recurselevel}\space
      \fi}\unskip
   \egroup}

\endETEX

\beginTEX

\gdef\showcharacterbounds
  {\bgroup
   \localcolortrue
   \dorecurse{255}
     {\setbox\scratchbox\ruledhbox{\darkgray\char\recurselevel}%
      \ifnum\wd\scratchbox>\zeropoint
        \noindent\box\scratchbox\space
      \fi}\unskip
   \egroup}

\endTEX

\gdef\showhyphenations#1%
  {\starttabulate[|le|l|]
   \NC language \NC \currentlanguage\ (internal code:\the\normallanguage)    \NC \NR
   \NC font     \NC \fontname\font                                           \NC \NR
   \NC encoding \NC \ifx\@@fontencoding\empty not set\else\@@fontencoding\fi \NC \NR
   \NC mapping  \NC \ifx\@@fontmapping \empty not set\else\@@fontmapping \fi \NC \NR
   \NC handling \NC \ifx\@@fonthandling\empty not set\else\@@fonthandling\fi \NC \NR
   \NC sample   \NC \hyphenatedword{#1}                                      \NC \NR
   \stoptabulate}

\gdef\showmapping
  {\dostepwiserecurse{128}{255}{1}
      {\hbox\bgroup
         \hbox to 2em{\hss\recurselevel}%
         \hbox to 2em{\hss\char\recurselevel\hss}%
         \hbox to 3em{\hss\ifcase\lccode\recurselevel\else\the \lccode\recurselevel\fi}%
         \hbox to 2em{\hss\ifcase\lccode\recurselevel\else\char\lccode\recurselevel\fi\hss}%
         \hbox to 3em{\hss\ifcase\lccode\recurselevel\else\the \uccode\recurselevel\fi}%
         \hbox to 2em{\hss\ifcase\uccode\recurselevel\else\char\uccode\recurselevel\fi\hss}%
       \egroup
       \endgraf}}

\protect \endinput
