%%% opentype-info.tex %%%
% By Jonathan Kew
%
% Prints XeTeX font features for an OpenType 
% font using the "ICU" renderer of XeTeX.
%
% See 'aat-info.tex' for the equivalent
% functionality with AAT fonts (Mac OS X only).
%
% Usage:
%   Type the name of the font below and compile this 
%   document with plain `xetex` to receive a listing
%   of the OpenType font features, languages & scripts
%   supported by the chosen font.
%
% opentype-info is distributed under the Apache License v2: 
%   <http://www.apache.org/licenses/LICENSE-2.0.html>
%
%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Select the font name:
\def\myfontname{Latin Modern Roman}
%
%%% OpenType-info.tex %%%

\font\testfont="\myfontname/ICU" at 12pt

\nopagenumbers 
\rightskip=0pt plus 1fil

\font\title=ec-lmssbx10 at 14pt
\font\tenrm=ec-lmss10 at 10pt \tenrm
\font\tentt=ec-lmtt10 at 10pt

\def\fourcharcode#1{\begingroup
 \count0=#1\count1=\count0
 \ifnum\count0=0
  $\langle$default$\rangle$%
 \else
  \tentt
  '%
  \divide\count0 by "1000000
  \char\count0
  \multiply\count0 by "1000000
  \advance\count1 by -\count0
  \count0=\count1
  \divide\count0 by "10000
  \char\count0
  \multiply\count0 by "10000
  \advance\count1 by -\count0
  \count0=\count1
  \divide\count0 by "100
  \char\count0
  \multiply\count0 by "100
  \advance\count1 by -\count0
  \ifnum\count1=32 \ \else \char\count1 \fi
  '%
 \fi
 \endgroup
}

\newcount\scriptcount
\newcount\scriptindex
\newcount\scripttag
\newcount\langcount
\newcount\langindex
\newcount\langtag
\newcount\featurecount
\newcount\featureindex
\newcount\featuretag

\leftline{\title OpenType Layout features found in `\myfontname'}
\nobreak\bigskip

\scriptcount=\XeTeXOTcountscripts\testfont
\ifnum\scriptcount=0 \noindent None\par\fi

\loop
 \ifnum\scriptindex<\scriptcount
  \scripttag=\XeTeXOTscripttag\testfont\scriptindex
  \noindent script = \fourcharcode{\scripttag}\endgraf\nobreak
  \langcount=\XeTeXOTcountlanguages\testfont\scripttag
  \advance\langcount by 1 % one extra to get the default language system
  {\loop
    \langtag=\XeTeXOTlanguagetag\testfont\scripttag\langindex
    \indent language = \fourcharcode{\langtag}\endgraf\nobreak
    \featurecount=\XeTeXOTcountfeatures\testfont\scripttag\langtag
    {\indent\indent \hangindent=3\parindent \hangafter=1 features = \loop
      \featuretag=\XeTeXOTfeaturetag\testfont\scripttag\langtag\featureindex
      \fourcharcode{\featuretag}
      \advance\featureindex by 1
      \ifnum\featureindex<\featurecount \repeat\endgraf}
    \advance\langindex by 1
  \ifnum\langindex<\langcount \medskip \repeat}
  \advance\scriptindex by 1
  \bigskip \repeat

\bye
