\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{spectral}
    [2022/09/27 (Bob Tennent and autoinst)  Style file for Spectral fonts.]

\RequirePackage{ifxetex,ifluatex,xkeyval,textcomp}

\newif\ifspectral@ttf 
\ifxetex
  \spectral@ttftrue
\else\ifluatex
  \spectral@ttftrue
\else  % [pdf]LaTeX
  \spectral@ttffalse
\fi\fi

\newif\ifspectral@lining \spectral@liningfalse
\newif\ifspectral@tabular \spectral@tabularfalse
\newif\ifspectral@extralight \spectral@extralightfalse
\newif\ifspectral@light \spectral@lightfalse
\newif\ifspectral@medium \spectral@mediumfalse
\newif\ifspectral@semibold \spectral@semiboldfalse
\newif\ifspectral@extrabold \spectral@extraboldfalse

\newcommand*{\Spectral@scale}{1}
\newcommand*{\SpectralInitials@scale}{1}
\RequirePackage{xkeyval}
\DeclareOptionX{scaled}{\renewcommand*{\Spectral@scale}{#1}}
\DeclareOptionX{scale}{\renewcommand*{\Spectral@scale}{#1}}
\DeclareOptionX{type1}{\spectral@ttffalse}
\DeclareOptionX{lining}{\spectral@liningtrue}
\DeclareOptionX{lf}{\spectral@liningtrue}
\DeclareOptionX{oldstyle}{\spectral@liningfalse}
\DeclareOptionX{osf}{\spectral@liningfalse}
\DeclareOptionX{tabular}{\spectral@tabulartrue}
\DeclareOptionX{t}{\spectral@tabulartrue}
\DeclareOptionX{proportional}{\spectral@tabularfalse}
\DeclareOptionX{p}{\spectral@tabularfalse}
\DeclareOptionX{medium}{\spectral@mediumtrue}
\DeclareOptionX{m}{\spectral@mediumtrue}
\DeclareOptionX{light}{\spectral@lighttrue}
\DeclareOptionX{l}{\spectral@lighttrue}
\DeclareOptionX{el}{\spectral@extralighttrue}
\DeclareOptionX{extralight}{\spectral@extralighttrue}
\DeclareOptionX{semibold}{\spectral@semiboldtrue}
\DeclareOptionX{sb}{\spectral@semiboldtrue}
\DeclareOptionX{extrabold}{\spectral@extraboldtrue}
\DeclareOptionX{eb}{\spectral@extraboldtrue}


\ExecuteOptionsX{oldstyle,proportional}
\ProcessOptionsX\relax

\ifspectral@ttf
  \ifspectral@lining
    \def\spectral@figurestyle{Lining}
  \else
    \def\spectral@figurestyle{OldStyle} 
  \fi
  \ifspectral@tabular
    \def\spectral@figurealign{Monospaced} 
  \else
    \def\spectral@figurealign{Proportional} 
  \fi
  \ifspectral@medium
    \def\spectral@regularstyle{Medium}
  \else\ifspectral@light
    \def\spectral@regularstyle{Light}
  \else\ifspectral@extralight
    \def\spectral@regularstyle{ExtraLight}
  \else
    \def\spectral@regularstyle{Regular}
  \fi\fi\fi
  \ifspectral@semibold
    \def\spectral@boldstyle{SemiBold}
  \else\ifspectral@extrabold
    \def\spectral@boldstyle{ExtraBold}
  \else
    \def\spectral@boldstyle{Bold}
  \fi\fi
    
\else % type1
  \ifspectral@lining
    \def\spectral@figurestyle{LF}
  \else
    \def\spectral@figurestyle{OsF}
  \fi
  \ifspectral@tabular
    \def\spectral@figurealign{T}
  \else
    \def\spectral@figurealign{}
  \fi
  \ifspectral@medium
    \def\mdseries@rm{medium}
  \else\ifspectral@light
    \def\mdseries@rm{l}
  \else\ifspectral@extralight
    \def\mdseries@rm{el}
  \else
    \def\mdseries@rm{m}
  \fi\fi\fi
  \def\seriesdefault{\mdseries@rm}
  \ifspectral@semibold
    \def\bfseries@rm{sb}
  \else\ifspectral@extrabold
    \def\bfseries@rm{eb}
  \else
    \def\bfseries@rm{b}
  \fi\fi

\fi

\ifspectral@ttf
  \RequirePackage{fontspec}
\else
  \RequirePackage{fontenc,fontaxes}
\fi

\ifspectral@ttf
  \def\spectral@regular{Regular}

  \defaultfontfeatures{
        Ligatures = TeX ,
        Scale     = \Spectral@scale ,
        SmallCapsFeatures={\ifluatex Renderer=Basic\fi},
        Extension = .ttf }
  \setmainfont
      [ Numbers = {\spectral@figurealign,\spectral@figurestyle},
        UprightFont    = *-\spectral@regularstyle ,
        ItalicFont     = *-\ifx\spectral@regularstyle\spectral@regular Italic\else\spectral@regularstyle Italic\fi,
        BoldFont    = *-\spectral@boldstyle ,
        BoldItalicFont     = *-\spectral@boldstyle Italic ,
      ]
      {Spectral}
  \newfontfamily\spectralextralight
      [ Numbers = {\spectral@figurealign,\spectral@figurestyle},
        UprightFont    = *-ExtraLight ,
        ItalicFont     = *-ExtraLightItalic ,
        BoldFont    = *-\spectral@boldstyle ,
        BoldItalicFont     = *-\spectral@boldstyle Italic ,
      ]
      {Spectral}
  \newfontfamily\spectrallight
      [ Numbers = {\spectral@figurealign,\spectral@figurestyle},
        UprightFont    = *-Light ,
        ItalicFont     = *-LightItalic ,
        BoldFont    = *-\spectral@boldstyle ,
        BoldItalicFont     = *-\spectral@boldstyle Italic ,
      ]
      {Spectral}
  \newfontfamily\spectralmedium
      [ Numbers = {\spectral@figurealign,\spectral@figurestyle},
        UprightFont    = *-Medium ,
        ItalicFont     = *-MediumItalic ,
        BoldFont    = *-\spectral@boldstyle ,
        BoldItalicFont     = *-\spectral@boldstyle Italic ,
      ]
      {Spectral}
  \newfontfamily\spectralsemibold
      [ Numbers = {\spectral@figurealign,\spectral@figurestyle},
        UprightFont    = *-SemiBold ,
        ItalicFont     = *-SemiBoldItalic ,
      ]
      {Spectral}
  \newfontfamily\spectralextrabold
      [ Numbers = {\spectral@figurealign,\spectral@figurestyle},
        UprightFont    = *-ExtraBold ,
        ItalicFont     = *-ExtraBoldItalic ,
      ]
      {Spectral}
  \providecommand\sufigures{\addfontfeatures{VerticalPosition=Superior}}
  \DeclareTextFontCommand{\oldstylenums}{\addfontfeatures{Numbers=OldStyle}}
  \DeclareTextFontCommand{\liningnums}{\addfontfeatures{Numbers=Lining}}

\else % type1

  \def\spectral@family{Spectral-\spectral@figurealign\spectral@figurestyle}
  \renewcommand*\rmdefault{\spectral@family}

  \fa@naming@exception{figures}{{superior}{proportional}}{Sup}
  \fa@naming@exception{figures}{{superior}{tabular}}{Sup}
  \def\sufigures{\@nomath\sufigures\fontfigurestyle{superior}\selectfont}

  \ifx\swshape\@undefined
    \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}
  \fi

  \def\spectralextralight{\fontfamily{\spectral@family}\fontseries{el}\selectfont}
  \def\spectrallight{\fontfamily{\spectral@family}\fontseries{l}\selectfont}
  \def\spectralmedium{\fontfamily{\spectral@family}\fontseries{medium}\selectfont}
  \def\spectralsemibold{\fontfamily{\spectral@family}\fontseries{sb}\selectfont}
  \def\spectralextrabold{\fontfamily{\spectral@family}\fontseries{eb}\selectfont}

  \DeclareTextFontCommand{\oldstylenums}{\fontfamily{Spectral-\spectral@figurealign OsF}\selectfont}
  \DeclareTextFontCommand{\liningnums}{\fontfamily{Spectral-\spectral@figurealign LF}\selectfont}

\fi

\DeclareTextFontCommand{\textsu}{\sufigures}
\DeclareTextFontCommand{\textsw}{\swshape}

\ifspectral@ttf
  \DeclareTextFontCommand{\tabularnums}{\addfontfeatures{Numbers=Tabular}}
  \DeclareTextFontCommand{\proportionalnums}{\addfontfeatures{Numbers=Proportional}}
\else % type1
  \DeclareTextFontCommand{\tabularnums}{\fontfamily{Spectral-T\spectral@figurestyle}\selectfont}
  \DeclareTextFontCommand{\proportionalnums}{\fontfamily{Spectral-\spectral@figurestyle}\selectfont}
\fi

\ifspectral@ttf
  \defaultfontfeatures{}
\fi

\endinput
