\documentclass{article}
\usepackage{fontspec}
\usepackage{luamplib}
\usepackage{animate}
\usepackage{luacode}
\usepackage{tabularray}
\NewCommandCopy\aff\addfontfeatures
\newcommand\axe[1]{\addfontfeatures{RawAxis={#1}}}
\setmainfont[Renderer=OpenType]{RobotoFlex-VariableFont.ttf}
\newcommand\glyphanimate[5]{
%#1 fontname
%#2 features
%#3 start value
%#4 end value
%#5 char/string
\begin{animateinline}[controls={play, stop}, palindrome]{12}%
\setmainfont[Renderer=OpenType]{#1}
\multiframe{10}{iValue=1+1}{%
%
\begin{mplibcode}
input colorbrewer-rgb
string strii;
axe := #2;
minV := #3;
maxV := #4;
beginfig(0);
strii:="\axe{#2=" & decimal(minV+\iValue*(maxV-minV)/10) & "} #5";
draw mpliboutlinetext.d (strii) (withcolor black withtransparency (1,0.5) withpen pencircle scaled 0.05) scaled 10 ;
endfig;
\end{mplibcode}
}%
\end{animateinline}%
}
\begin{luacode*}
local function vide(s)
return s == nil or s == ''
end
function imagesMetapost(fontid,lettre)
lafonte=luaotfload.fontloader.fonts.hashes.identifiers[fontid]
if not vide(lafonte.resources.variabledata)
then
local vardata = lafonte.resources.variabledata["axis"]
tex.sprint('\\begin{tblr}{colspec={*{4}{Q[c]}}}')
i = 0
for k, v in pairs(vardata) do
i= i + 1
tex.sprint('\\begin{mplibcode}[variablefont]')
tex.sprint('beginfig(0);')
tex.sprint('draw_variable_font("')
tex.sprint(v["tag"]..'",')
tex.sprint(v["minimum"]..',')
tex.sprint(v["maximum"]..',"'..lettre..'");')
tex.sprint('endfig;\\end{mplibcode}\\par')
tex.sprint(v["tag"])
if i%4 == 0 then
tex.sprint('\\\\')
else
tex.sprint('&')
end
end
tex.sprint('\\end{tblr}')
else
tex.sprint("Pas d'axes\\\\")
end
end
function animMetapost(fontid,fonte,lettre)
lafonte=luaotfload.fontloader.fonts.hashes.identifiers[fontid]
if not vide(lafonte.resources.variabledata)
then
local vardata = lafonte.resources.variabledata["axis"]
tex.sprint('\\begin{tblr}{colspec={*{4}{Q[c]}}}')
i = 0
for k, v in pairs(vardata) do
i= i + 1
tex.sprint('\\glyphanimate{'..fonte..'}{'..v["tag"]..'}{'..v["minimum"]..'}{'..v["maximum"]..'}{'..lettre..'}\\par')
tex.sprint(v["tag"])
if i%4 == 0 then
tex.sprint('\\\\')
else
tex.sprint('&')
end
end
tex.sprint('\\end{tblr}')
else
tex.sprint("Pas d'axes\\\\")
end
end
\end{luacode*}
\newcommand{\featuresImages}[2]{
\font\mafonte="#1"
\directlua{imagesMetapost(\fontid\mafonte,"#2")}
}
\newcommand{\featuresAnim}[2]{
\font\mafonte="#1"
\directlua{animMetapost(\fontid\mafonte,"#1","#2")}
}
\begin{document}
\begin{mplibcode}[variablefont]
input colorbrewer-rgb
vardef draw_variable_font(expr a,m,M,l)=
save strii, axe, minV,maxV,N;
string strii;
string axe;
axe := a;
minV := m;
maxV := M;
N:= 10;
path bshape[];
for i:=1 upto N:
strii:="\axe{"& axe &"=" & decimal(minV+i*(maxV-minV)/N) & "} "& l;
draw mpliboutlinetext.d (strii) (withcolor Spectral[N][i] withtransparency (1,
0.5) withpen pencircle scaled 0.05) scaled N ;
endfor;
enddef;
\end{mplibcode}
\featuresImages{RobotoFlex-VariableFont.ttf}{S}
\featuresAnim{RobotoFlex-VariableFont.ttf}{S}
\end{document}