\ProvidesPackage{LibreBodoni}[%
   2022/09/18 (Bob Tennent)  Supports LibreBodoni fonts for all LaTeX engines. ] 

\RequirePackage{ifxetex,ifluatex,textcomp}

\newif\iflibrebodoni@otf
\ifxetex
  \librebodoni@otftrue
\else\ifluatex
  \librebodoni@otftrue
\else  % [pdf]LaTeX
  \librebodoni@otffalse
\fi\fi

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

\DeclareOptionX{type1}{\librebodoni@otffalse}

\ProcessOptionsX\relax

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

\iflibrebodoni@otf
  \defaultfontfeatures{
     Ligatures = TeX ,
     Extension = .otf ,
  }
  \setmainfont
      [ UprightFont    = *-Regular ,
        ItalicFont     = *-Italic ,
        BoldFont       = *-Bold , 
        BoldItalicFont = *-BoldItalic ]
      {LibreBodoni}
  \newfontfamily\librebodoni
      [ UprightFont    = *-Regular ,
        ItalicFont     = *-Italic ,
        BoldFont       = *-Bold , 
        BoldItalicFont = *-BoldItalic ]
      {LibreBodoni}
  \providecommand\sufigures{\addfontfeatures{VerticalPosition=Superior}}
  \providecommand\infigures{\addfontfeatures{VerticalPosition=ScientificInferior}}


\else % type1

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

  \fa@naming@exception{figures}{{inferior}{proportional}}{Inf}
  \fa@naming@exception{figures}{{inferior}{tabular}}{Inf}
  \providecommand\infigures{\@nomath\infigures\fontfigurestyle{inferior}\selectfont}

  \def\librebodonifamily{LibreBodoni-TLF}
  \renewcommand*\rmdefault{\librebodonifamily}
  \newcommand*\librebodoni{\fontfamily{\librebodonifamily}\selectfont}

\fi
\DeclareTextFontCommand{\textsu}{\sufigures}
\DeclareTextFontCommand{\textin}{\infigures}

% turn off defaults in case other fonts are selected:
\iflibrebodoni@otf
  \defaultfontfeatures{}
\fi

\endinput

