\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{CrimsonPro}
    [2018/12/18 (Bob Tennent and autoinst)  Style file for CrimsonPro fonts.]

\RequirePackage{ifxetex,ifluatex,xkeyval,textcomp}

\newif\ifcrimsonpro@otf 
\ifxetex
  \crimsonpro@otftrue
\else\ifluatex
  \crimsonpro@otftrue
\else  % [pdf]LaTeX
  \crimsonpro@otffalse
\fi\fi

\newif\ifcrimsonpro@lining \crimsonpro@liningfalse
\newif\ifcrimsonpro@tabular \crimsonpro@tabularfalse
\newif\ifcrimsonpro@medium \crimsonpro@mediumfalse
\newif\ifcrimsonpro@semibold \crimsonpro@semiboldfalse
\newif\ifcrimsonpro@extrabold \crimsonpro@extraboldfalse
\newif\ifcrimsonpro@black \crimsonpro@blackfalse
\newif\ifcrimsonpro@light \crimsonpro@lightfalse
\newif\ifcrimsonpro@extralight \crimsonpro@extralightfalse

\newcommand*{\CrimsonPro@scale}{1}
\RequirePackage{xkeyval}
\DeclareOptionX{scaled}{\renewcommand*{\CrimsonPro@scale}{#1}\renewcommand*{\CrimsonProInitials@scale}{#1}}
\DeclareOptionX{type1}{\crimsonpro@otffalse}
\DeclareOptionX{lining}{\crimsonpro@liningtrue}
\DeclareOptionX{nf}{\crimsonpro@liningtrue}
\DeclareOptionX{lf}{\crimsonpro@liningtrue}
\DeclareOptionX{oldstyle}{\crimsonpro@liningfalse}
\DeclareOptionX{osf}{\crimsonpro@liningfalse}
\DeclareOptionX{tabular}{\crimsonpro@tabulartrue}
\DeclareOptionX{t}{\crimsonpro@tabulartrue}
\DeclareOptionX{proportional}{\crimsonpro@tabularfalse}
\DeclareOptionX{p}{\crimsonpro@tabularfalse}
\DeclareOptionX{medium}{\crimsonpro@mediumtrue}
\DeclareOptionX{m}{\crimsonpro@mediumtrue}
\DeclareOptionX{semibold}{\crimsonpro@semiboldtrue}
\DeclareOptionX{sb}{\crimsonpro@semiboldtrue}
\DeclareOptionX{extrabold}{\crimsonpro@extraboldtrue}
\DeclareOptionX{eb}{\crimsonpro@extraboldtrue}
\DeclareOptionX{k}{\crimsonpro@blacktrue}
\DeclareOptionX{black}{\crimsonpro@blacktrue}
\DeclareOptionX{light}{\crimsonpro@lighttrue}
\DeclareOptionX{el}{\crimsonpro@extralighttrue}
\DeclareOptionX{extralight}{\crimsonpro@extralighttrue}


\ExecuteOptionsX{oldstyle,proportional}
\ProcessOptionsX\relax

\ifcrimsonpro@otf
  \ifcrimsonpro@lining
    \def\crimsonpro@figurestyle{Lining}
  \else
    \def\crimsonpro@figurestyle{OldStyle} 
  \fi
  \ifcrimsonpro@tabular
    \def\crimsonpro@figurealign{Monospaced} 
  \else
    \def\crimsonpro@figurealign{Proportional} 
  \fi
  \ifcrimsonpro@medium
    \def\crimsonpro@regularstyle{Medium}
  \else\ifcrimsonpro@light
    \def\crimsonpro@regularstyle{Light}
  \else\ifcrimsonpro@extralight
    \def\crimsonpro@regularstyle{ExtraLight}
  \else
    \def\crimsonpro@regularstyle{Regular}
  \fi\fi\fi
  \ifcrimsonpro@semibold
    \def\crimsonpro@boldstyle{SemiBold}
  \else\ifcrimsonpro@extrabold
    \def\crimsonpro@boldstyle{ExtraBold}
  \else\ifcrimsonpro@black
    \def\crimsonpro@boldstyle{Black}
  \else
    \def\crimsonpro@boldstyle{Bold}
  \fi\fi\fi
    
\else % type1
  \ifcrimsonpro@lining
    \def\crimsonpro@figurestyle{LF}
  \else
    \def\crimsonpro@figurestyle{OsF}
  \fi
  \ifcrimsonpro@tabular
    \def\crimsonpro@figurealign{T}
  \else
    \def\crimsonpro@figurealign{}
  \fi
  \ifcrimsonpro@medium
    \def\mdseries@rm{mb}
  \else\ifcrimsonpro@light
    \def\mdseries@rm{l}
  \else\ifcrimsonpro@extralight
    \def\mdseries@rm{el}
  \else
    \def\mdseries@rm{m}
  \fi\fi\fi
  \ifcrimsonpro@semibold
    \def\bfseries@rm{sb}
  \else\ifcrimsonpro@extrabold
    \def\bfseries@rm{eb}
  \else\ifcrimsonpro@black
    \def\bfseries@rm{k}
  \else
    \def\bfseries@rm{b}
  \fi\fi\fi

\fi

\ifcrimsonpro@otf
  \RequirePackage{fontspec}
\else
  \RequirePackage{fontenc,fontaxes,mweights}
\fi

\ifcrimsonpro@otf
  \ifxetex\XeTeXtracingfonts=1\fi
  \def\crimsonpro@regular{Regular}
  \defaultfontfeatures{
        Ligatures = TeX ,
        Scale     = \CrimsonPro@scale ,
        SmallCapsFeatures={\ifluatex Renderer=Basic\fi},
        Extension = .ttf }
  \setmainfont
      [ Numbers = {\crimsonpro@figurealign,\crimsonpro@figurestyle},
        UprightFont    = *-\crimsonpro@regularstyle ,
        ItalicFont     = *-\ifx\crimsonpro@regularstyle\crimsonpro@regular Italic\else\crimsonpro@regularstyle Italic\fi,
        BoldFont    = *-\crimsonpro@boldstyle ,
        BoldItalicFont     = *-\crimsonpro@boldstyle Italic ,
      ]
      {CrimsonPro}
  \newfontfamily\crimsonpro
      [ Numbers = {\crimsonpro@figurealign,\crimsonpro@figurestyle},
        UprightFont    = *-\crimsonpro@regularstyle ,
        ItalicFont     = *-\ifx\crimsonpro@regularstyle\crimsonpro@regular Italic\else\crimsonpro@regularstyle Italic\fi ,
        BoldFont    = *-\crimsonpro@boldstyle ,
        BoldItalicFont     = *-\crimsonpro@boldstyle Italic ,
      ]
      {CrimsonPro}
  \providecommand\sufigures{\addfontfeatures{VerticalPosition=Superior}}
  \providecommand\infigures{\addfontfeatures{VerticalPosition=ScientificInferior}}
  \newfontfamily\crimsonproOsF
      [ Numbers = {\crimsonpro@figurealign,OldStyle},
        UprightFont    = *-\crimsonpro@regularstyle ,
        ItalicFont     = *-\ifx\crimsonpro@regularstyle\crimsonpro@regular Italic\else\crimsonpro@regularstyle Italic\fi ,
        BoldFont    = *-\crimsonpro@boldstyle ,
        BoldItalicFont     = *-\crimsonpro@boldstyle Italic ,
      ]
      {CrimsonPro}
  \newfontfamily\crimsonproLF
      [ Numbers = {\crimsonpro@figurealign,Lining},
        UprightFont    = *-\crimsonpro@regularstyle ,
        ItalicFont     = *-\ifx\crimsonpro@regularstyle\crimsonpro@regular Italic\else\crimsonpro@regularstyle Italic\fi ,
        BoldFont    = *-\crimsonpro@boldstyle ,
        BoldItalicFont     = *-\crimsonpro@boldstyle Italic ,
      ]
      {CrimsonPro}
  \newfontfamily\crimsonprotabular
    [ Numbers = {Monospaced,\crimsonpro@figurestyle},
        UprightFont    = *-\crimsonpro@regularstyle ,
        ItalicFont     = *-\ifx\crimsonpro@regularstyle\crimsonpro@regular Italic\else\crimsonpro@regularstyle Italic\fi ,
        BoldFont    = *-\crimsonpro@boldstyle ,
        BoldItalicFont     = *-\crimsonpro@boldstyle Italic ,
    ]
    {CrimsonPro}
  \newfontfamily\crimsonproproportional
    [ Numbers = {Proportional,\crimsonpro@figurestyle},
        UprightFont    = *-\crimsonpro@regularstyle ,
        ItalicFont     = *-\ifx\crimsonpro@regularstyle\crimsonpro@regular Italic\else\crimsonpro@regularstyle Italic\fi ,
        BoldFont    = *-\crimsonpro@boldstyle ,
        BoldItalicFont     = *-\crimsonpro@boldstyle Italic ,
    ]
    {CrimsonPro}
  \DeclareTextFontCommand{\tabularnums}{\crimsonprotabular}
  \DeclareTextFontCommand{\proportionalnums}{\crimsonproproportional}
  \DeclareTextFontCommand{\oldstylenums}{\crimsonproOsF}
  \DeclareTextFontCommand{\liningnums}{\crimsonproLF}

\else % type1

  \def\crimsonpro@family{CrimsonPro-\crimsonpro@figurealign\crimsonpro@figurestyle}
  \renewcommand*\rmdefault{\crimsonpro@family}
  \newcommand*\crimsonpro{\fontfamily{\crimsonpro@family}\selectfont}

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

  \fa@naming@exception{figures}{{inferior}{proportional}}{Inf}
  \fa@naming@exception{figures}{{inferior}{tabular}}{Inf}
  \def\infigures{\@nomath\infigures\fontfigurestyle{inferior}\selectfont}
  \DeclareTextFontCommand{\oldstylenums}{\fontfamily{CrimsonPro-\crimsonpro@figurealign OsF}\selectfont}
  \DeclareTextFontCommand{\liningnums}{\fontfamily{CrimsonPro-\crimsonpro@figurealign LF}\selectfont}
  \DeclareTextFontCommand{\tabularnums}{\fontfamily{CrimsonPro-T\crimsonpro@figurestyle}\selectfont}
  \DeclareTextFontCommand{\proportionalnums}{\fontfamily{CrimsonPro-\crimsonpro@figurestyle}\selectfont}

\fi

\DeclareTextFontCommand{\textsu}{\sufigures}
\DeclareTextFontCommand{\textinf}{\infigures}

\ifcrimsonpro@otf
  \defaultfontfeatures{}
\fi

\endinput
