\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mfb-oldstyle}
    [2024/08/05 (autoinst)  Style file for MFBOldstyle fonts.]

\RequirePackage{xkeyval}
\newcommand*{\MFBOldstyle@scale}{1}
\DeclareOptionX{scale}{\renewcommand*{\MFBOldstyle@scale}{#1}}
\DeclareOptionX{scaled}{\renewcommand*{\MFBOldstyle@scale}{#1}}

\DeclareOptionX{lining}{\edef\MFBOldstyle@figurestyle{LF}}
\DeclareOptionX{oldstyle}{\edef\MFBOldstyle@figurestyle{OsF}}
\DeclareOptionX{tabular}{\edef\MFBOldstyle@figurealign{T}}
\DeclareOptionX{proportional}{\edef\MFBOldstyle@figurealign{}}
\edef\MFBOldstyle@figurestyle{LF}
\edef\MFBOldstyle@figurealign{}

\DeclareOptionX{mainfont}{
    \renewcommand{\familydefault}{\rmdefault}
}
\DeclareOptionX{bold}{\edef\bfseries@rm{bold}}
\DeclareOptionX{regular}{\edef\mdseries@rm{regular}}

\ProcessOptionsX\relax

\RequirePackage[LY1,T1,T5]{fontenc}
\RequirePackage{textcomp}
\RequirePackage{ifthen}
\RequirePackage{mweights}

\IfFileExists{fontaxes.sty}{
    \RequirePackage{fontaxes}
    \fa@naming@exception{figures}{{superior}{proportional}}{Sup}
    \fa@naming@exception{figures}{{superior}{tabular}}{Sup}
    \def\supfigures{\@nomath\supfigures
        \fontfigurestyle{superior}\selectfont}
    \let\sufigures\supfigures
    \DeclareTextFontCommand{\textsup}{\supfigures}
    \let\textsu\textsup
    \let\textsuperior\textsup
    \let\@oldtextsuperscript\textsuperscript
    \def\textsuperscript{\@ifstar\@oldtextsuperscript\textsup}
    \def\@makefnmark{%
        \mbox{\footnotemarkfont\textsuperscript{\@thefnmark}}}
    \@ifundefined{ftntm@font}%
        {\let\footnotemarkfont\normalfont}%
        {\let\footnotemarkfont\ftntm@font}

    \fa@naming@exception{figures}{{inferior}{proportional}}{Inf}
    \fa@naming@exception{figures}{{inferior}{tabular}}{Inf}
    \def\inffigures{\@nomath\inffigures
        \fontfigurestyle{inferior}\selectfont}
    \let\infigures\inffigures
    \DeclareTextFontCommand{\textinf}{\inffigures}
    \let\textin\textinf
    \let\textinferior\textinf
    \let\@oldtextsubscript\textsubscript
    \def\textsubscript{\@ifstar\@oldtextsubscript\textinf}

    \fa@naming@exception{figures}{{numerators}{proportional}}{Numr}
    \fa@naming@exception{figures}{{numerator}{proportional}}{Numr}
    \fa@naming@exception{figures}{{numerators}{tabular}}{Numr}
    \fa@naming@exception{figures}{{numerator}{tabular}}{Numr}

    \fa@naming@exception{figures}{{denominators}{proportional}}{Dnom}
    \fa@naming@exception{figures}{{denominator}{proportional}}{Dnom}
    \fa@naming@exception{figures}{{denominators}{tabular}}{Dnom}
    \fa@naming@exception{figures}{{denominator}{tabular}}{Dnom}

}{}

%   Here we implement the scale=MatchLowercase option.
%   If this is given, we must compute the correct value of
%   the "\MFBOldstyle@scale" parameter before loading the .fd files;
%   but to determine that value we of course need the font's x-height.
%   To avoid triggering the loading of .fd files,
%   we use plain TeX's \font primitive to load the testfont.
%   We then compute the ratio of the current x-height to our font's x-height;
%   this is the "\MFBOldstyle@scale" we will pass to the .fd files.
\ifthenelse{\equal{\MFBOldstyle@scale}{MatchLowercase}}
    {   \newlength{\MFBOldstyle@currentx}
        \settoheight{\MFBOldstyle@currentx}{x}
        \newlength{\MFBOldstyle@xheight}
        \settoheight{\MFBOldstyle@xheight}
            {{\font\testfont=MFBOldstyle-Regular-osf-ot1 at \f@size pt\testfont x}}
        \renewcommand*{\MFBOldstyle@scale}
            {\strip@pt\dimexpr\number\numexpr\number\dimexpr\MFBOldstyle@currentx\relax*65536/\number\dimexpr\MFBOldstyle@xheight\relax\relax sp\relax}}
    {}

\renewcommand*
    {\rmdefault}
    {MFBOldstyle-\MFBOldstyle@figurealign\MFBOldstyle@figurestyle}

\endinput