\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{GaramondLibre}
    [2024/04/23 (Bob Tennent and autoinst)  Style file for GaramondLibre fonts.]

\RequirePackage{ifxetex,ifluatex,xkeyval,textcomp}

\newif\ifgaramondlibre@otf 
\ifxetex
  \garamondlibre@otftrue
\else\ifluatex
  \garamondlibre@otftrue
\else  % [pdf]LaTeX
  \garamondlibre@otffalse
\fi\fi

\newif\ifgaramondlibre@lining \garamondlibre@liningtrue

\newcommand*{\GaramondLibre@scale}{1}
\RequirePackage{xkeyval}
\DeclareOptionX{scaled}{\renewcommand*{\GaramondLibre@scale}{#1}}
\DeclareOptionX{scale}{\renewcommand*{\GaramondLibre@scale}{#1}}
\DeclareOptionX{type1}{\garamondlibre@otffalse}
\DeclareOptionX{oldstyle}{\garamondlibre@liningfalse}
\DeclareOptionX{osf}{\garamondlibre@liningfalse}
\DeclareOptionX{lining}{\garamondlibre@liningtrue}
\DeclareOptionX{lf}{\garamondlibre@liningtrue}


\ProcessOptionsX\relax

\ifgaramondlibre@otf
  \ifgaramondlibre@lining
    \def\garamondlibre@figurestyle{Lining}
  \else
    \def\garamondlibre@figurestyle{OldStyle} 
  \fi
\else % type1
  \ifgaramondlibre@lining
    \def\garamondlibre@figurestyle{LF}
  \else
    \def\garamondlibre@figurestyle{OsF}
  \fi
\fi

\ifgaramondlibre@otf
\else
  \def\bfseries@rm{b}
  \def\mdseries@rm{m}
\fi

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

\ifgaramondlibre@otf
  \defaultfontfeatures{
        Ligatures = TeX ,
        Scale     = \GaramondLibre@scale ,
        Extension = .otf }
  \setmainfont[
        Numbers       = {\garamondlibre@figurestyle},
        UprightFont    = *-Regular ,
        ItalicFont     = *-Italic ,
        BoldFont    = *-Bold ,
        BoldItalicFont = *-BoldItalic,
      ]
      {GaramondLibre}
  \providecommand\sufigures{\addfontfeatures{VerticalPosition=Superior}}
  \providecommand\infigures{\addfontfeatures{VerticalPosition=Inferior}}

  \providecommand{\swashshape}{\itshape\addfontfeatures{ItalicFeatures={Style=Swash}}}
  \DeclareTextFontCommand{\textsw}{\swashshape}

  \providecommand\ornaments{\addfontfeatures{Numbers=Lining,Ornament}}
  \DeclareTextFontCommand{\textornaments}{\ornaments}

  \DeclareTextFontCommand{\oldstylenums}{\addfontfeatures{Numbers=OldStyle}}
  \DeclareTextFontCommand{\liningnums}{\addfontfeatures{Numbers=Lining}}

\else % type1

  \def\garamondlibre@family{GaramondLibre-\garamondlibre@figurestyle}
  \renewcommand*\rmdefault{\garamondlibre@family}
  \edef\seriesdefault{\mdseries@rm}

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

  \fa@naming@exception{figures}{{ornament}{proportional}}{Orn}
  \fa@naming@exception{figures}{{ornament}{tabular}}{Orn}
  \def\ornaments{\@nomath\ornaments
      \fontencoding{U}\fontfigurestyle{ornament}\selectfont}
  \DeclareTextFontCommand{\textornaments}{\ornaments}
  \providecommand{\ornament}[1]{\textornaments{\char##1}}


  \DeclareTextFontCommand{\oldstylenums}{\fontfamily{GaramondLibre-OsF}\selectfont}
  \DeclareTextFontCommand{\liningnums}{\fontfamily{GaramondLibre-LF}\selectfont}
  \DeclareTextFontCommand{\textsw}{\swshape}

\fi

\DeclareTextFontCommand{\textsu}{\sufigures}
\DeclareTextFontCommand{\textin}{\infigures}
\newcommand*\garamondlibrelgr{\fontencoding{LGR}\fontfamily{GaramondLibre-LF}\selectfont}


\ifgaramondlibre@otf
  \defaultfontfeatures{}
\fi

\endinput
