With LuaTeX, how do I get a list of OTF features supported by the current font in use printed?
For example, with otfinfo, I can get a list of OTF features by otfinfo -f font_file_name
. Can I do anything similar with LuaTeX?
The goal is to produce such a list for each font I tested. For example, I would like to have such a macro,
\def\listfontfeatures{
\directlua{... some lua code to list font features to a string, say ff ...}
\directlua{tex.print(ff)}
}
And use it like the following,
Times Ten LT Std: \fontspec{Times Ten LT Std} \listfontfeatures \par
Palatino LT Std: \fontspec{Palatino LT Std} \listfontfeatures \par
Minion Pro: \fontspec{Minion Pro} \listfontfeatures \par
Update 12/01/2017
Here's just a small improvement to michal.h21's answer, just in case anyone will be interested.
fontspec_if_feature
actually tests font features for the currently selected font family instead of the currently selected font. Normally this makes little difference and I only noticed this recently. For some fonts, different shapes have different features. For example, the italics may have swashes while the roman fonts lack it.
Below is a few macros that I now use for font feature test. It only work for LuaTeX. some modifications to the FontName
macro is needed to make it to work with XeTeX.
\ExplSyntaxOff % remove the necessity to use ~ for space
\NewDocumentCommand\FontName{}{%
\directlua{
local i = font.current()
local f = font.getfont(i)
local n = f.fullname
tex.sprint(n)
}%
}
\ExplSyntaxOn
% Setup a new font family whose "n/m" shape is the current font.
% Limitations: The contents of the true/false clauses will be
% set in current fonts without any features selected by default,
% and it will be set in a group. For myself, this was intentionally.
\NewDocumentCommand\FontFeatureTF{m +m +m}{
\group_begin:
\fontspec_set_family:Nnn\thisfont:{}{\FontName}
\fontfamily\thisfont:\selectfont
\fontspec_if_feature:nTF{#1}{#2}{#3}
\group_end:
}
\NewDocumentCommand\FontFeatureT{m +m}{
\FontFeatureTF{#1}{#2}{\prg_do_nothing:}
}
\NewDocumentCommand\FontFeatureF{m +m}{
\FontFeatureTF{#1}{\prg_do_nothing:}{#2}
}