\NeedsTeXFormat{LaTeX2e}[2020/02/02]
\ProvidesPackage{SourceSansThree}
    [2026/05/03 (autoinst)  Style file for SourceSansThree fonts.]

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

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

\DeclareOptionX{mainfont}{
    \renewcommand{\familydefault}{\sfdefault}
}
\DeclareOptionX{black}{\edef\bfseries@sf{black}}
\DeclareOptionX{semibold}{\edef\bfseries@sf{semibold}}
\DeclareOptionX{bold}{\edef\bfseries@sf{bold}}
\DeclareOptionX{medium}{\edef\mdseries@sf{medium}}
\DeclareOptionX{regular}{\edef\mdseries@sf{regular}}

\ProcessOptionsX\relax

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

\ExplSyntaxOn
\IfFileExists{figureversions.sty}{
    \RequirePackage{figureversions}

    \figureversions_new_figurestyle:nnn {superior} {Sup} {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}

    \figureversions_new_figurestyle:nnn {inferior} {Inf} {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}

    \figureversions_new_figurestyle:nnn {numerators} {Numr} {Numr}
    \figureversions_new_figurestyle:nnn {numerator}  {Numr} {Numr}

    \figureversions_new_figurestyle:nnn {denominators} {Dnom} {Dnom}
    \figureversions_new_figurestyle:nnn {denominator}  {Dnom} {Dnom}

}{}
\ExplSyntaxOff

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

\renewcommand*
    {\sfdefault}
    {SourceSansThree-\SourceSansThree@figurealign\SourceSansThree@figurestyle}

\endinput
