%% opensans.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{opensans}[2019/06/20 Style file for Open Sans.]

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

\newif\ifopensans@otf
\ifxetex
  \opensans@otftrue
\else
  \ifluatex
    \opensans@otftrue
  \else
    \opensans@otffalse
  \fi
\fi

\newif\ifopensans@lining
\newif\ifopensans@tabular

\newif\ifopensans@default
\opensans@defaultfalse

\newif\ifopensans@defaultsans
\opensans@defaultsansfalse

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

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

\ExecuteOptionsX{tabular,lining}
\ProcessOptionsX
\relax

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

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

\ifopensans@otf
  \RequirePackage{fontspec}

  \ifxetex
    \XeTeXtracingfonts=1
  \fi

  \newcommand*{\opensans@otf@features}{%
    Extension=.ttf,%
    Ligatures={TeX,Common},%
    Scale=\opensans@scale,%
    FontFace={l}{n}{*-Light},%
    FontFace={l}{it}{*-LightItalic},%
    FontFace={lc}{n}{*Condensed-Light},%
    FontFace={lc}{it}{*Condensed-LightItalic},%
    UprightFont={*-Regular},%
    ItalicFont={*-Italic},%
    FontFace={sb}{n}{*-SemiBold},%
    FontFace={sb}{it}{*-SemiBoldItalic},%
    FontFace={b}{n}{*-Bold},%
    FontFace={b}{it}{*-BoldItalic},%
    BoldFont={*-Bold},%
    BoldItalicFont={*-BoldItalic},%
    FontFace={bc}{n}{*Condensed-Bold},%
    FontFace={eb}{n}{*-ExtraBold},%
    FontFace={eb}{it}{*-ExtraBoldItalic}%
  }

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

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

  % Legacy compatibility
  \newfontfamily{\fosfamily}[%
    \opensans@otf@features,%
    Numbers={Monospaced,Lining},%
    NFSSFamily=fos%
  ]{OpenSans}

  \ifopensans@defaultsans
    \setsansfont[%
      \opensans@otf@features,%
      Numbers={\opensans@figurewidth@otf,\opensans@figurestyle@otf},%
    ]{OpenSans}
  \fi
  \ifopensans@default
    \setmainfont[%
      \opensans@otf@features,%
      Numbers={\opensans@figurewidth@otf,\opensans@figurestyle@otf},%
    ]{OpenSans}
  \fi
\else
  \newcommand*{\opensans}{\fontfamily{\opensansfamily}\selectfont}
  % Legacy compatibility
  \newcommand*{\fosfamily}{\fontfamily{opensans-TLF}\selectfont}

  \ifopensans@defaultsans
    \renewcommand*{\sfdefault}{\opensansfamily}
  \fi
  \ifopensans@default
    \renewcommand*{\familydefault}{\opensansfamily}
  \fi
\fi

\endinput
