\ProvidesPackage{PlayfairDisplay}[%
   2020/07/25 (Bob Tennent)  Supports PlayfairDisplay fonts for xeLaTeX and luaLaTeX. ] 

\RequirePackage{iftex}

\ifpdftex
\PackageError{playfair}{%
 *****************************************\MessageBreak
  Please process using XeLaTeX or luaLaTeX\MessageBreak
 *****************************************}
\fi  


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

\newif\ifplayfair@black \playfair@blackfalse

\DeclareOptionX{black}{\playfair@blacktrue}

\newif\ifplayfair@lining \playfair@liningtrue

\DeclareOptionX{lining}[true]{%
\@nameuse{if#1}%
  \playfair@liningtrue
\else
  playfair@liningfalse
\fi
}
\DeclareOptionX{lf}[true]{%
\@nameuse{if#1}%
  \playfair@liningtrue
\else
  playfair@liningfalse
\fi
}
\DeclareOptionX{oldstyle}[true]{%
\@nameuse{if#1}%
  \playfair@liningfalse
\else
  \playfair@liningtrue
\fi
}

\DeclareOptionX{osf}[true]{%
\@nameuse{if#1}%
  \playfair@liningfalse
\else
  \playfair@liningtrue
\fi
}

\ProcessOptionsX\relax

  \ifplayfair@lining
    \def\playfair@figurestyle{Lining}
  \else
    \def\playfair@figurestyle{OldStyle}
  \fi
  \ifplayfair@black
    \def\playfair@boldstyle{Black}
  \else
    \def\playfair@boldstyle{Bold}
  \fi


\RequirePackage{fontspec}

% Set main and/or sans fonts:

  \ifxetex\XeTeXtracingfonts=1\fi
  \defaultfontfeatures{
     Ligatures = TeX ,
     Scale     = \PlayfairDisplay@scale ,
     Extension = .otf ,
  }
  \setmainfont
      [ Numbers = {\playfair@figurestyle}, 
        UprightFont    = *-Regular ,
        ItalicFont     = *-Italic ,
        BoldFont       = *-\playfair@boldstyle , 
        BoldItalicFont = *-\playfair@boldstyle Italic ]
      {PlayfairDisplay}
  \newfontfamily\playfairblack
      [ Numbers = {\playfair@figurestyle}, 
        UprightFont    = *-Black ,
        ItalicFont     = *-BlackItalic ,
        BoldFont       = *-\playfair@boldstyle , 
        BoldItalicFont = *-\playfair@boldstyle Italic ]
      {PlayfairDisplay}
   \providecommand\sufigures{\addfontfeatures{VerticalPosition=Superior}}
   \newfontfamily\playfairOsF
      [ Numbers = {OldStyle},
        UprightFont    = *-Regular ,
        ItalicFont     = *-Italic ,
        BoldFont    = *-Regular ,
        BoldItalicFont     = *-Italic ,
      ]
      {PlayfairDisplay}
   \newfontfamily\playfairLF
      [ Numbers = {Lining},
        UprightFont    = *-Regular ,
        ItalicFont     = *-Italic ,
        BoldFont    = *-Regular ,
        BoldItalicFont     = *-Italic ,
      ]
      {PlayfairDisplay}



\DeclareTextFontCommand{\textsu}{\sufigures}
\let\textsuperior\textsu

% turn off defaults in case other fonts are selected:
  \defaultfontfeatures{}

\endinput

