%% cantarell.sty
%% Copyright 2019 Mohamed El Morabity
%
% This work may be distributed and/or modified under the conditions of the LaTeX
% Project Public License, either version 1.3 of this license or (at your option)
% any later version. The latest version of this license is in
% http://www.latex-project.org/lppl.txt and version 1.3 or later is part of all
% distributions of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Mohamed El Morabity
%
% This work consists of all files listed in manifest.txt.


\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{cantarell}[2019/06/20 Style file for Cantarell.]

\RequirePackage{fontaxes}
\RequirePackage{ifluatex}
\RequirePackage{ifxetex}
\RequirePackage{xkeyval}

\newif\ifcantarell@otf
\ifxetex
\cantarell@otftrue
\else
\ifluatex
\cantarell@otftrue
\else
\cantarell@otffalse
\fi
\fi

\newif\ifcantarell@lining
\newif\ifcantarell@tabular

\newif\ifcantarell@default
\cantarell@defaultfalse

\newif\ifcantarell@defaultsans
\cantarell@defaultsansfalse

\newcommand*{\cantarell@scale}{1}
\DeclareOptionX{scale}{\renewcommand*{\cantarell@scale}{#1}}
\DeclareOptionX{scaled}{\renewcommand*{\cantarell@scale}{#1}}

\DeclareOptionX{default}{\cantarell@defaulttrue}
\DeclareOptionX{defaultsans}{\cantarell@defaultsanstrue}
\DeclareOptionX{lining}{\cantarell@liningtrue}
\DeclareOptionX{oldstyle}{\cantarell@liningfalse}
\DeclareOptionX{tabular}{\cantarell@tabulartrue}
\DeclareOptionX{proportional}{\cantarell@tabularfalse}
\DeclareOptionX{type1}{\cantarell@otffalse}

\ExecuteOptionsX{tabular,lining}
\ProcessOptionsX
\relax

\ifcantarell@tabular
  \newcommand*{\cantarell@figurewidth@otf}{Monospaced}
  \newcommand*{\cantarell@figurewidth@pfb}{T}
\else
  \newcommand*{\cantarell@figurewidth@otf}{Proportional}
  \newcommand*{\cantarell@figurewidth@pfb}{}
\fi
\ifcantarell@lining
  \newcommand*{\cantarell@figurestyle@otf}{Lining}
  \newcommand*{\cantarell@figurestyle@pfb}{LF}
\else
  \newcommand*{\cantarell@figurestyle@otf}{OldStyle}
  \newcommand*{\cantarell@figurestyle@pfb}{OsF}
\fi

\newcommand*{\cantarell@familyprefix}{cantarell}
\newcommand*{\cantarell@family}[1]{\cantarell@familyprefix-#1}
\newcommand*{\cantarellfamily}{\cantarell@family{\cantarell@figurewidth@pfb\cantarell@figurestyle@pfb}}

\ifcantarell@otf
  \RequirePackage{fontspec}

  \ifxetex
    \XeTeXtracingfonts=1
  \fi

  \newcommand*{\cantarell@otf@slant}{0.141}
  \newcommand*{\cantarell@otf@features}{%
    Extension=.otf,%
    Ligatures={TeX,Common},%
    Scale=\cantarell@scale,%
    FontFace={el}{n}{*-Thin},%
    FontFace={el}{it}{Font=*-Thin,FakeSlant=\cantarell@otf@slant},%
    FontFace={l}{n}{*-Light},%
    FontFace={l}{it}{Font=*-Light,FakeSlant=\cantarell@otf@slant},%
    UprightFont={*-Regular},%
    ItalicFont={*-Regular},%
    ItalicFeatures={FakeSlant=\cantarell@otf@slant},
    FontFace={b}{n}{*-Bold},%
    FontFace={b}{it}{Font=*-Bold,FakeSlant=\cantarell@otf@slant},%
    BoldFont={*-Bold},%
    BoldItalicFont={*-Bold},%
    BoldItalicFeatures={FakeSlant=\cantarell@otf@slant},%
    FontFace={eb}{n}{*-ExtraBold},%
    FontFace={eb}{it}{Font=*-ExtraBold,FakeSlant=\cantarell@otf@slant}%
  }

  % Define family for each figure style/width, with corresponding
  % NFSS family, for fontaxes support
  \newfontfamily{\cantarell@otf@TLF}[%
    \cantarell@otf@features,%
    Numbers={Monospaced,Lining},%
    NFSSFamily=\cantarell@family{TLF}%
  ]{Cantarell}
  \newfontfamily{\cantarell@otf@LF}[%
    \cantarell@otf@features,%
    Numbers={Proportional,Lining},%
    NFSSFamily=\cantarell@family{LF}%
  ]{Cantarell}
  \newfontfamily{\cantarell@otf@TOsF}[%
    \cantarell@otf@features,%
    Numbers={Monospaced,OldStyle},%
    NFSSFamily=\cantarell@family{TOsF}%
  ]{Cantarell}
  \newfontfamily{\cantarell@otf@OsF}[%
    \cantarell@otf@features,%
    Numbers={Proportional,OldStyle},%
    NFSSFamily=\cantarell@family{OsF}%
  ]{Cantarell}

  \expandafter\let\expandafter\cantarell\csname cantarell@otf@\cantarell@figurewidth@pfb\cantarell@figurestyle@pfb\endcsname

  % Legacy compatibility
  \newfontfamily{\fcafamily}[%
    \cantarell@otf@features,%
    Numbers={Monospaced,Lining},%
    NFSSFamily=fca%
  ]{Cantarell}

  \ifcantarell@defaultsans
    \setsansfont[%
      \cantarell@otf@features,%
      Numbers={\cantarell@figurewidth@otf,\cantarell@figurestyle@otf},%
    ]{Cantarell}
  \fi
  \ifcantarell@default
    \setmainfont[%
      \cantarell@otf@features,%
      Numbers={\cantarell@figurewidth@otf,\cantarell@figurestyle@otf},%
    ]{Cantarell}
  \fi
\else
  \newcommand*{\cantarell}{\fontfamily{\cantarellfamily}\selectfont}
  % Legacy compatibility
  \newcommand*{\fcafamily}{\fontfamily{cantarell-TLF}\selectfont}

  \ifcantarell@defaultsans
    \renewcommand*{\sfdefault}{\cantarellfamily}
  \fi
  \ifcantarell@default
    \renewcommand*{\familydefault}{\cantarellfamily}
  \fi
\fi

\endinput
