\NeedsTeXFormat{LaTeX2e}[2020/02/02]
\ProvidesPackage{splentinex}[2025/11/11 splentinex 1.0]

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

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

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

\ProcessOptionsX\relax

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

\IfFileExists{fontaxes.sty}{
    \RequirePackage{fontaxes}
    \DeclareRobustCommand\swshape{\not@math@alphabet\swshape\relax
        \fontprimaryshape\itdefault\fontsecondaryshape\swdefault\selectfont}
    \fa@naming@exception{shape}{{n}{sw}}{nw}
    \fa@naming@exception{shape}{{it}{sw}}{sw}

    \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}

}{}

%   Here we implement the scale=MatchLowercase option.
%   If this is given, we must compute the correct value of
%   the "\Splentinex@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 "\Splentinex@scale" we will pass to the .fd files.
\ifthenelse{\equal{\Splentinex@scale}{MatchLowercase}}
    {   \newlength{\Splentinex@currentx}
        \settoheight{\Splentinex@currentx}{x}
        \newlength{\Splentinex@xheight}
        \settoheight{\Splentinex@xheight}
            {{\font\testfont=Splentinex-Regular-osf-ot1 at \f@size pt\testfont x}}
        \renewcommand*{\Splentinex@scale}
            {\fpeval{\Splentinex@currentx / \Splentinex@xheight}}}
    {}

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

\endinput
