\usemodule[s][mat-10]

% \enabletrackers[pages.timing]

% todo: mode for screen
% todo: variant for HD with one menu at the right (with include menu)

% layout

\definecolor[backgroundcolor] [r=.6,g=.6]
\definecolor[backgroundcolorx][r=.6]
\definecolor[backgroundcolory][g=.6]
\definecolor[baselinecolor]   [a=1,t=.5,s=.6]
\definecolor[charactercolor]  [b=.6]
\definecolor[pagecolor]       [s=.1]
\definecolor[nonecolor]       [s=.5]
\definecolor[textcolor]       [s=.9]

% \setuppapersize[HD]
%
% \setuplayout
%   [page]

\setuppapersize[HD+]

\setuplayout
  [backspace=0pt,
   topspace=0pt,
   bottomspace=120pt, %1200-1080
   bottom=24pt,
   bottomdistance=5mm,
   header=0pt,
   footer=0pt,
   width=middle,
   height=middle]

\definelayer
  [page]

\setuplayer
  [page]
  [width=\textwidth,
   height=\textheight]

\setupbackgrounds
  [page]
  [background=color,
   backgroundcolor=pagecolor]

\setupbackgrounds
  [text][text]
  [bottomframe=on,framecolor=textcolor,rulethickness=0.025ex]

\setupmakeup
  [standard]
  [pagestate=start]

\setupinteraction
  [state=start,
   menu=on]

\defineinteractionmenu
  [ALPHABETS]
  [bottom]

\defineinteractionmenu
  [alphabets]
  [bottom]

\defineinteractionmenu
  [symbols]
  [bottom]

\setupinteractionmenu
  [bottom]
  [before=\vfill,
   after=\vfill,
   left=\hfill,
   right=\hfill,
   style=\tt\bf,
   distance=0pt,
   color=textcolor,
   contrastcolor=nonecolor]

\startinteractionmenu[bottom]
    \startgot [firstpage]       first    \stopgot \quad
    \startgot [deltapage(-100)] -100     \stopgot \quad
    \startgot [deltapage(-10)]  -10      \stopgot \quad
    \startgot [previouspage]    previous \stopgot \quad
    \startgot [nextpage]        next     \stopgot \quad
    \startgot [deltapage(+10)]  +10      \stopgot \quad
    \startgot [deltapage(+100)] +100     \stopgot \quad
    \startgot [lastpage]        last     \stopgot
\stopinteractionmenu

\startinteractionmenu[ALPHABETS]
    \startgot [U+00041] NORMAL            \stopgot \quad
    \startgot [U+1D400] BOLD              \stopgot \quad
    \startgot [U+1D434] ITALIC            \stopgot \quad
    \startgot [U+1D468] BOLDITALIC        \stopgot \quad
    \startgot [U+1D49C] SCRIPT            \stopgot \quad
    \startgot [U+1D4D0] BOLDSCRIPT        \stopgot \quad
    \startgot [U+1D504] FRAKTUR           \stopgot \quad
    \startgot [U+1D538] DOUBLESTRUCK      \stopgot \quad
    \startgot [U+1D56C] BOLDFRAKTUR       \stopgot \quad
    \startgot [U+1D5A0] SS NORMAL         \stopgot \quad
    \startgot [U+1D5D4] SS BOLD           \stopgot \quad
    \startgot [U+1D608] SS ITALIC         \stopgot \quad
    \startgot [U+1D63C] SS BOLDITALIC     \stopgot \quad
    \startgot [U+1D670] MONOSPACE         \stopgot \quad
    \startgot [U+00391] GRK NORMAL        \stopgot \quad
    \startgot [U+1D6A8] GRK BOLD          \stopgot \quad
    \startgot [U+1D6E2] GRK ITALIC        \stopgot \quad
    \startgot [U+1D71C] GRK BOLDITALIC    \stopgot \quad
    \startgot [U+1D756] GRK SS BOLD       \stopgot \quad
    \startgot [U+1D790] GRK SS BOLDITALIC \stopgot
\stopinteractionmenu

\startinteractionmenu[alphabets]
    \startgot [U+00061] normal            \stopgot \quad
    \startgot [U+1D41A] bold              \stopgot \quad
    \startgot [U+1D44E] italic            \stopgot \quad
    \startgot [U+1D482] bolditalic        \stopgot \quad
    \startgot [U+1D4B6] script            \stopgot \quad
    \startgot [U+1D4EA] boldscript        \stopgot \quad
    \startgot [U+1D51E] fraktur           \stopgot \quad
    \startgot [U+1D552] doublestruck      \stopgot \quad
    \startgot [U+1D586] boldfraktur       \stopgot \quad
    \startgot [U+1D5BA] ss normal         \stopgot \quad
    \startgot [U+1D5EE] ss bold           \stopgot \quad
    \startgot [U+1D622] ss italic         \stopgot \quad
    \startgot [U+1D656] ss bolditalic     \stopgot \quad
    \startgot [U+1D68A] monospace         \stopgot \quad
    \startgot [U+003B1] grk normal        \stopgot \quad
    \startgot [U+1D6C2] grk bold          \stopgot \quad
    \startgot [U+1D6FC] grk italic        \stopgot \quad
    \startgot [U+1D736] grk bolditalic    \stopgot \quad
    \startgot [U+1D770] grk ss bold       \stopgot \quad
    \startgot [U+1D7AA] grk ss bolditalic \stopgot
\stopinteractionmenu

\startinteractionmenu[symbols]
    \startgot [U+00030] dig normal       \stopgot \quad
    \startgot [U+1D7CE] dig bold         \stopgot \quad
    \startgot [U+1D7D8] dig doublestruck \stopgot \quad
    \startgot [U+1D7E2] dig ss normal    \stopgot \quad
    \startgot [U+1D7EC] dig ss bold      \stopgot \quad
    \startgot [U+1D7F6] dig monospace    \stopgot \quad
    \startgot [U+02200] operators        \stopgot \quad
    \startgot [U+02701] symbols a        \stopgot \quad
    \startgot [U+02901] symbols b        \stopgot \quad
    \startgot [U+02A00] supplemental     \stopgot
\stopinteractionmenu

\defineframed
  [somedata]
  [background=color,
   backgroundcolor=textcolor,
  %framecolor=charactercolor,
  %rulethickness=1pt,
   frame=off,
   offset=1ex]

% helpers

\def\mathfontlisttxt#1%
  {{\tttf#1}}

\def\mathfontlistchr#1#2%
  {\iffontchar\font#2\relax
     \scale
       [sx=#1,sy=#1]
       {\dontleavehmode
        \begingroup
        \setbox\scratchbox\hbox{\charactercolor\char#2}%
        \scratchdimen\wd\scratchbox
        \ifdim\scratchdimen>\zeropoint
          \backgroundline[backgroundcolor]{\box\scratchbox}%
        \else\ifdim\scratchdimen<\zeropoint
          \scratchdimen-\scratchdimen
          \setbox\scratchbox\hbox to \scratchdimen{\hss\charactercolor\char#2}%
          \backgroundline[backgroundcolorx]{\box\scratchbox}%
        \else
          \setbox\scratchbox\hbox to 1em{\hss\charactercolor\char#2}%
          \scratchdimen\wd\scratchbox
          \backgroundline[backgroundcolory]{\box\scratchbox}%
        \fi\fi
        \hskip-\scratchdimen
        \baselinecolor\vrule width \scratchdimen height .05ex depth .05ex
        \endgroup}%
   \fi}

\def\mathfontlistmth#1#2%
  {\setbox\scratchbox\hbox{\mathfontlistchr{#1}{#2}}%
   \ht\scratchbox\strutht
   \dp\scratchbox\strutdp
   \box\scratchbox}

\let\mathfontlistbodyfonts\empty

\def\mathfontlistbodyfontentry#1#2%
  {\somedata
     [align={none,middle},background=,height=5cm]
     {\begingroup
      \switchtobodyfont[#2,12pt]%
      \definedfont[MathRoman*math-text]%
      \mathfontlistmth{10}{#1}%
      \endgroup
      \vfilll
      \doifmodeelse{crosslink}
        {\goto{\strut\textcolor\mathfontlisttxt{#2}}[#2::#1]}%
              {\strut\textcolor\mathfontlisttxt{#2}}}%
   \hskip1ex}

\def\setmathfontlistbodyfonts#1%
  {\edef\mathfontlistbodyfonts{#1}%
   \def\dosetmathfontlistbodyfonts##1%
     {\setupbodyfont[##1,12pt]}%
   \processcommacommand[\mathfontlistbodyfonts]\dosetmathfontlistbodyfonts}

\def\mathfontlistbodyfontschars#1%
  {\processcommacommand[\mathfontlistbodyfonts]{\mathfontlistbodyfontentry{#1}}}

% main

\def\startmathfontlist
  {\starttext
   \startstandardmakeup % we use baselinecolor so that we have a transparency on page 1
     \setupalign[middle]
     \vfil
     \dontleavehmode \scale[height=.3\textheight]{\strut\color[textcolor]{\fontclass}}
     \vfil
     \dontleavehmode \scale[height=.1\textheight]{\strut\color[baselinecolor]{\currentdate}}
     \vfil
     \vfil
   \stopstandardmakeup}

\def\stopmathfontlist
  {\stoptext}

% entry

\def\startmathfontlistentry
  {\startstandardmakeup}

\def\stopmathfontlistentry
  {\tightlayer[page]
   \stopstandardmakeup}

\def\mathfontlistreference#1%
  {\setlayer[page]{\pagereference[#1]}}

\def\mathfontlistentryhexdectit#1#2#3%
  {\setlayer
     [page]
     [preset=middletop,voffset=5mm]
     {\somedata[height=1cm]{\mathfontlisttxt{#1}}}
   \setlayer
     [page]
     [preset=middle,y=2cm]
     {\mathfontlistmth{25}{#2}}
   \setlayer
     [page]
     [preset=righttop,offset=5mm]
     {\somedata[height=1cm]{\mathfontlisttxt{#3}}}
   \doifsomething\mathfontlistbodyfonts
     {\setlayer
        [page]
        [preset=middlebottom,voffset=5mm]
        {\mathfontlistbodyfontschars{#2}}}}

% dimensions

\def\mathfontlistentrywdhtdpic#1#2#3#4%
  {\setlayer
     [page]
     [preset=leftbottom,offset=5mm]
     {\somedata[align=normal,width=5cm]
        {\strut width \hfill \the\dimexpr#1sp\par
         \strut height\hfill \the\dimexpr#2sp\par
         \strut depth \hfill \the\dimexpr#3sp\par
         \strut italic\hfill \the\dimexpr#4sp}}}

\def\mathfontlistentryresource#1%
  {} % {virtual: #1\par}

% next

\def\startmathfontlistnext
  {\setlayer
     [page]
     [preset=middleleft,hoffset=5mm]
     \bgroup\vbox\bgroup}

\def\stopmathfontlistnext
  {\egroup\egroup}

\def\mathfontlistnextentry#1#2#3%
  {\ifnum#1>1 \vskip1ex \fi
   \dontleavehmode\somedata
     [align=normal,width=4cm]
     {\strut\mathfontlisttxt{#2}\hfill\mathfontlistchr{2}{#3}}\par}

\def\mathfontlistnextcycle#1%
  {\ifnum#1>1 \vskip1ex \fi
   \dontleavehmode\somedata
     [align=normal,width=4cm]
     {\strut\mathfontlisttxt{cycle}}\par}

% variants

\def\startmathfontlistvvariants
  {\setlayer
     [page]
     [preset=lefttop,offset=5mm]
     \bgroup\vbox\bgroup}

\def\startmathfontlisthvariants
  {\setlayer
     [page]
     [preset=lefttop,offset=5mm]
     \bgroup\hbox\bgroup}

\def\mathfontlistvvariantsentry#1#2#3%
  {\ifnum#1>1 \vskip1ex \fi
   \dontleavehmode\somedata
     [align=middle,width=4cm]
     {\strut\mathfontlisttxt{#2}\hfilll\mathfontlistchr{2}{#3}}}

\def\mathfontlisthvariantsentry#1#2#3%
  {\ifnum#1>1 \hskip1ex \else \dontleavehmode \fi
   \somedata
     [align={none,middle},height=2cm]
     {\strut\mathfontlisttxt{#2}\vfilll\mathfontlistchr{2}{#3}}}

\def\stopmathfontlistvvariants
  {\egroup\egroup}

\def\stopmathfontlisthvariants
  {\egroup\egroup}

\def\mathfontlistbetweennextandvariants
  {}

% classes

\def\startmathfontlistentryclassspec
  {\setlayer
     [page]
     [preset=rightbottom,offset=5mm]
     \bgroup\somedata[align=normal,width=8cm]\bgroup}

\def\stopmathfontlistentryclassspec
  {\egroup\egroup}

\def\mathfontlistentryclassname#1#2%
  {\strut{\mathfontlisttxt#1}\hfill\mathfontlisttxt{#2}\par}

% symbols

\def\mathfontlistentrysymbol#1#2%
  {\setlayer
     [page]
     [preset=leftbottom,hoffset=5mm,voffset=50mm]
     {\somedata
        [align=normal,width=5cm]
        {\mathfontlisttxt{#1}\hfill\mathfontlistchr{4}{#2}}}}

% alternates

\def\startmathfontlookupvariants
  {\setlayer
     [page]
     [preset=middleright,hoffset=5mm]
     \bgroup\vbox\bgroup}

\def\stopmathfontlookupvariants
  {\egroup\egroup}

\def\mathfontlookupvariant#1#2#3#4%
  {\ifnum#1>1 \vskip1ex \fi
   \somedata
     [align=normal,width=7cm]
     {\mathfontlisttxt{#4:} \mathfontlisttxt{#2}\hfill\mathfontlistchr{4}{#3}}}

% done

\continueifinputfile{s-mat-12.mkiv}

\setmathfontlistbodyfonts{lucidanova,cambria,xits,modern,pagella}

\starttext
%     \setupbodyfont[cambria,  12pt] \showmathfontcharacters
%     \setupbodyfont[modern,   12pt] \showmathfontcharacters
%     \setupbodyfont[lmvirtual,12pt] \showmathfontcharacters
%     \setupbodyfont[pxvirtual,12pt] \showmathfontcharacters
%     \setupbodyfont[txvirtual,12pt] \showmathfontcharacters
%     \setupbodyfont[palatino, 10pt] \showmathfontcharacters
%     \setupbodyfont[mathtimes,12pt] \showmathfontcharacters
%     \setupbodyfont[stix,     12pt] \showmathfontcharacters
%     \setupbodyfont[xits,     12pt] \showmathfontcharacters
%     \setupbodyfont[lucida,   12pt] \showmathfontcharacters
%     \setupbodyfont[lucidanova,   12pt] \showmathfontcharacters
    \setupbodyfont[pagella,   12pt] \showmathfontcharacters
\stoptext

