% Source Sans Pro for LaTeX
% 
% Silke Hofstra, silke@slxh.nl
%
% OpenType version of Source Sans Pro for XeTeX and LuaTeX users.
%
% Licenced under the LPPL
%
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{sourcesanspro-otf}[2012/11/04 v1.02 Adobe's Source Sans Pro typeface]

% Check if engine is XeTeX or LuaTeX
\RequirePackage{expl3}[2011/09/05]
\ExplSyntaxOn
\msg_new:nnn {sourcesanspro-otf} {cannot-use-pdftex}
{
  The~ sourcesanspro-otf~ package~ requires~ either~ XeTeX~ or~ LuaTeX~ to~ function.
  \\\\
  You~ must~ change~ your~ typesetting~ engine~ to,~
    e.g.,~ "xelatex"~ or~ "lualatex"\\
  instead~ of~ plain~ "latex"~ or~ "pdflatex".
}
\xetex_if_engine:F {
  \luatex_if_engine:TF {
    \RequirePackage{luaotfload}
    \RequireLuaModule{fontspec}
  }{
    \msg_fatal:nn {sourcesanspro-otf} {cannot-use-pdftex}
  }
}

\RequirePackage{fontspec} 

\IfFileExists{xkeyval.sty}{
    \newcommand*{\sourcesanspro@scale}{1}
    \RequirePackage{xkeyval}
    \DeclareOptionX{scaled}{\renewcommand*{\sourcesanspro@scale}{##1}}
}{
    \let\DeclareOptionX\DeclareOption
    \let\ExecuteOptionsX\ExecuteOptions
    \let\ProcessOptionsX\ProcessOptions
}

\DeclareOptionX{lining}{\edef\sourcesanspro@figurestyle{}}% An empty figure style is lining
\DeclareOptionX{nf}{\edef\sourcesanspro@figurestyle{}}% An empty figure style is lining
\DeclareOptionX{oldstyle}{\edef\sourcesanspro@figurestyle{OldStyle}}
\DeclareOptionX{osf}{\edef\sourcesanspro@figurestyle{OldStyle}}
\DeclareOptionX{tabular}{\edef\sourcesanspro@figurealign{Monospaced}}
\DeclareOptionX{proportional}{\edef\sourcesanspro@figurealign{Proportional}}
\DeclareOptionX{black}{\edef\sourcesanspro@boldstyle{Black}}
\DeclareOptionX{semibold}{\edef\sourcesanspro@boldstyle{Semibold}}
\DeclareOptionX{bold}{\edef\sourcesanspro@boldstyle{Bold}}
\DeclareOptionX{light}{\edef\sourcesanspro@regstyle{Light}}
\DeclareOptionX{extralight}{\edef\sourcesanspro@regstyle{ExtraLight}}
\DeclareOptionX{regular}{\edef\sourcesanspro@regstyle{Regular}}
\DeclareOptionX{default}{\renewcommand*{\familydefault}{\sfdefault}}
\ExecuteOptionsX{lining,proportional,bold,regular}
\ProcessOptionsX\relax

% Shared features
\defaultfontfeatures{
	Ligatures = TeX ,
	Numbers   = {\sourcesanspro@figurealign , \sourcesanspro@figurestyle } ,
	Scale     = \sourcesanspro@scale ,
	Extension = .otf }

% Default font
\setsansfont
	[ UprightFont    = *-\sourcesanspro@regstyle ,
	  ItalicFont     = *-\sourcesanspro@regstyle It ,
	  BoldFont       = *-\sourcesanspro@boldstyle , 
	  BoldItalicFont = *-\sourcesanspro@boldstyle It]
	{SourceSansPro}

% Font commands
\newfontfamily\sourcesanspro
	[ UprightFont    = *-Regular ,
	  ItalicFont     = *-RegularIt ,
	  BoldFont       = *-Bold , 
	  BoldItalicFont = *-BoldIt ]
	{SourceSansPro}

\newfontfamily\sourcesansprolight
	[ UprightFont    = *-Light ,
	  ItalicFont     = *-LightIt ,
	  BoldFont       = *-Semibold ,
	  BoldItalicFont = *-SemiboldIt ]
	{SourceSansPro}
	
\newfontfamily\sourcesansproextreme
	[ UprightFont    = *-ExtraLight ,
	  ItalicFont     = *-ExtraLightIt ,
	  BoldFont       = *-Black ,
	  BoldItalicFont = *-BlackIt ]
	{SourceSansPro}

% Old Style numbers
\renewcommand*\oldstylenums[1]{\addfontfeature{Numbers=OldStyle}#1}

\endinput