%D \module
%D   [      file=s-fonts-steps, % was s-fnt-20
%D        version=2009.01.10,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Tracing Feature Application (1),
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%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 file is used by Idris and me in the process of getting the
%D best arabic fonts getting rendered best. As such it might change.

\startmodule[fonts-steps]

% \setvariables
%   [otftracker]
%   [title=Reverse Chaining,
%    figure=test-003-volt.pdf,
%    font=husayni,
%    sample={ببب بببب ببببب بببببب}]

\def\checkedotftrackerfeature  #1{otftracker-\ifnum\featureattribute{otftracker-#1}=\zerocount default\else#1\fi}
\def\checkedotftrackerdirection#1{\csname otftracker-direction-\ifcsname otftracker-direction-#1\endcsname#1\else default\fi\endcsname}

% we can consider adding a dir key to features

\definefontfeature
  [otftracker-default]
  [default]
  [mode=node]

\definefontfeature
  [otftracker-arabtype]
  [mode=node,analyze=yes,
   language=dflt,script=arab,ccmp=yes,
   init=yes,medi=yes,fina=yes,isol=yes,
   liga=yes,dlig=yes,rlig=yes,clig=yes,
   mark=yes,mkmk=yes,kern=yes,curs=yes]

\definefontfeature
  [otftracker-husayni-default]
  [analyze=yes,mode=node,
   language=dflt,script=arab,
   init=yes,medi=yes,fina=yes,
   spacekern=yes,
   calt=yes,
   rlig=yes,
   ccmp=yes,
   salt=yes,
   ss01=yes, % full Allah, Muhammad, Allahumma
   ss05=yes, % full Jiim stacking
   ss09=yes, % full Haa stacking
   ss10=yes, % partial dipped Miim
   ss13=yes, % full stacked Miim
   ss15=yes, % full stacked Laam-on-Miim
   ss17=yes, % full stacked Ayn-on-Miim
   ss19=yes, % LM_im
   ss24=yes, % BX specials
   ss25=yes, % LH_im specials
   ss26=yes, % full Yaa.final specials
   ss27=yes, % partial thin Miim.final
   ss31=yes, % partial Raa.final contexts
   ss34=yes, % partial Raa.final contexts
   ss35=yes, % full Kaaf contexts
   ss36=yes, % full Laam contexts
   ss37=yes, % Miim-Miim contexts
   ss38=yes, % fancy thin Haa.medial-Miim.final
   ss39=yes, % high and low Baa strings
   ss40=yes, % diagonal entry
   ss41=yes, % initial alternates
   mark=yes,mkmk=yes,kern=yes,curs=yes]

\definefontfeature
  [otftracker-husayni]
  [otftracker-husayni-default]

\definefontfeature
  [otftracker-simplenaskhi]
  [analyze=yes,mode=node,
   language=dflt,script=arab,
   init=yes,medi=yes,fina=yes,calt=yes,
   rlig=yes,liga=yes,dlig=yes,
   mark=yes,mkmk=yes,kern=yes,curs=yes]

\setvalue{otftracker-direction-arabtype}{r2l}
\setvalue{otftracker-direction-husayni}{r2l}
\setvalue{otftracker-direction-simplenaskhi}{r2l}
\setvalue{otftracker-direction-default}{}
\setvalue{otftracker-direction-sbl-hbrw}{r2l}

\setvariables
  [otftracker]
  [font=Serif,
   features=\checkedotftrackerfeature{\getvariable{otftracker}{font}},
   direction=\checkedotftrackerdirection{\getvariable{otftracker}{font}},
   size=48pt,
   figure=,
   title=Feature Check,
   sample=no sample,
   set=\setups{otftracker}]

\setuplayout
  [topspace=1.5cm,
   backspace=1.5cm,
   width=middle,
   height=middle,
   header=1.5cm,
   footer=1.5cm]

\setuphead
  [chapter]
  [header=high,
   number=no]

\setupfootertexts
  [chapter]

\setupalign
  [flushleft]

\setupcolors
  [state=start]

\startsetups otftracker-steps
    \doifsomething {\getvariable{otftracker}{figure}} {
        \startlinecorrection
            \externalfigure[\getvariable{otftracker}{figure}][maxwidth=\hsize,frame=on]
        \stoplinecorrection
    }
    \showotfcomposition
        {\getvariable{otftracker}{font}*\getvariable{otftracker}{features} at \getvariable{otftracker}{size}}
        {\getvariable{otftracker}{direction}}
        {\getvariable{otftracker}{sample}}
\stopsetups

\startsetups otftracker
    \setupbodyfont[tt,10pt]
    \starttext
        \normalexpanded{\startchapter[title={\getvariable{otftracker}{title}}]}
            \directsetup{otftracker-steps}
            \directsetup{otftracker-extra}
        \stopchapter
        \setvariables[otftracker][comment=]
    \stoptext
\stopsetups

%D For old times sake we keep this one:

\unexpanded\def\ShowOtfTrackerSample#1%
  {\doiffile{#1}
     {\blank
      \startlinecorrection
      \vbox \bgroup
        \forgetall
        \setbox\scratchbox\hbox{\component #1 \relax}
        \hbox{\copy\scratchbox\quad\lower\dp\scratchbox\hbox{\ruledhbox{\externalfigure[#1-volt.pdf][height=\htdp\scratchbox]}}}
        \hbox{\strut\tttf#1}%
      \egroup
      \stoplinecorrection
      \blank}}

\stopmodule

\continueifinputfile{s-fonts-steps.mkiv}

\usemodule[art-01]

\setupbodyfont
%   [cambria]
  [dejavu]

\starttext

\setvariables
  [otftracker]
  [font=Serif,
   size=48pt,
   figure=,
   title=Feature Check,
   sample={affiliation}]

\stoptext
