\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{simurgh-fonts}[2013/09/18 v0.01a fonts]
\newfontscript{Parsi}{arab}
\newfontlanguage{Parsi}{FAR}
\aliasfontfeatureoption{Numbers}{Arabic}{Parsi}
\ExplSyntaxOn
\DeclareDocumentCommand \setmainparsifont { O{} m } {
  \fontspec_select:nn{Script=Parsi,Numbers=Parsi,Language=Parsi,#1}{#2}
  \use:x {
    \exp_not:N \DeclareRobustCommand \exp_not:N \parsimainfont {
      \exp_not:N \fontencoding {\g_fontspec_encoding_tl}
      \exp_not:N \fontfamily {\l_fontspec_family_tl} \exp_not:N \selectfont
    }
  }
  \cs_set_eq:NN \rmdefault \l_fontspec_family_tl
  \normalfont
}
\DeclareDocumentCommand \setmainlatinfont { O{} m } {
  \fontspec_select:nn{Ligatures=TeX,#1}{#2}
  \use:x {
    \exp_not:N \DeclareRobustCommand \exp_not:N \latinmainfont {
      \exp_not:N \fontencoding {\g_fontspec_encoding_tl}
      \exp_not:N \fontfamily {\l_fontspec_family_tl} \exp_not:N \selectfont
    }
  }
}
\cs_set_eq:NN \setlatinsansfont \setsansfont
\cs_set_eq:NN \setlatinmonofont \setmonofont
\DeclareDocumentCommand \loadnewparsifont { m O{} m } {
  \fontspec_select:nn{Script=Parsi,Numbers=Parsi,Language=Parsi,#2}{#3}
  \use:x {
    \exp_not:N \DeclareRobustCommand \exp_not:N #1 {
      \exp_not:N \fontencoding {\g_fontspec_encoding_tl}
      \exp_not:N \fontfamily {\l_fontspec_family_tl} \exp_not:N \selectfont
    }
  }
}
\DeclareDocumentCommand \loadnewlatinfont { m O{} m } {
  \fontspec_select:nn{Ligatures=TeX,#2}{#3}
  \use:x {
    \exp_not:N \DeclareRobustCommand \exp_not:N #1 {
      \exp_not:N \fontencoding {\g_fontspec_encoding_tl}
      \exp_not:N \fontfamily {\l_fontspec_family_tl} \exp_not:N \selectfont
    }
  }
}
\newcommand\parsisfdefault{}
\newcommand\parsittdefault{}
\newcommand\iranicdefault{}
\newcommand\navardefault{}
\newcommand\pookdefault{}
\newcommand\sayehdefault{}
\DeclareRobustCommand\parsisffamily
        {\not@math@alphabet\parsisffamily\mathparsisf
         \fontfamily\parsisfdefault\selectfont}
\DeclareRobustCommand\parsittfamily
        {\not@math@alphabet\parsittfamily\mathparsitt
         \fontfamily\parsittdefault\selectfont}
\DeclareRobustCommand\iranicfamily
        {\not@math@alphabet\iranicfamily\mathiranic
         \fontfamily\iranicdefault\selectfont}
\DeclareRobustCommand\navarfamily
        {\not@math@alphabet\navarfamily\mathnavar
         \fontfamily\navardefault\selectfont}
\DeclareRobustCommand\pookfamily
        {\not@math@alphabet\pookfamily\mathpook
         \fontfamily\pookdefault\selectfont}
\DeclareRobustCommand\sayehfamily
        {\not@math@alphabet\sayehfamily\mathsayeh
         \fontfamily\sayehdefault\selectfont}
\DeclareTextFontCommand{\textparsisf}{\parsisffamily}
\DeclareTextFontCommand{\textparsitt}{\parsittfamily}
\DeclareTextFontCommand{\textiranic}{\iranicfamily}
\DeclareTextFontCommand{\textnavar}{\navarfamily}
\DeclareTextFontCommand{\textpook}{\pookfamily}
\DeclareTextFontCommand{\textsayeh}{\sayehfamily}
\DeclareDocumentCommand \setparsisansfont { O{} m } {
  \fontspec_set_family:Nnn \parsisfdefault {Script=Parsi,Numbers=Parsi,Language=Parsi,#1}{#2}
  \normalfont
}
\DeclareDocumentCommand \setparsimonofont { O{} m } {
  \fontspec_set_family:Nnn \parsittdefault {Script=Parsi,Numbers=Parsi,Language=Parsi,#1}{#2}
  \normalfont
}
\DeclareDocumentCommand \setnavarfont { O{} m } {
  \fontspec_set_family:Nnn \navardefault {Script=Parsi,Numbers=Parsi,Language=Parsi,#1}{#2}
  \normalfont
}
\DeclareDocumentCommand \setpookfont { O{} m } {
  \fontspec_set_family:Nnn \pookdefault {Script=Parsi,Numbers=Parsi,Language=Parsi,#1}{#2}
  \normalfont
}

\DeclareDocumentCommand \setsayehfont { O{} m } {
  \fontspec_set_family:Nnn \sayehdefault {Script=Parsi,Numbers=Parsi,Language=Parsi,#1}{#2}
  \normalfont
}

\DeclareDocumentCommand \setiranicfont { O{} m } {
  \fontspec_set_family:Nnn \iranicdefault {Script=Parsi,Numbers=Parsi,Language=Parsi,#1}{#2}
  \normalfont
}
\ExplSyntaxOff

\def\reset@latinfont{%
\let\normalfont\latinmainfont%
\let\reset@font\normalfont%
\latinmainfont}


\def\reset@parsifont{%
\let\normalfont\parsimainfont%
\let\reset@font\normalfont%
\parsimainfont}


\simurgh@AtEndPreamble{%
  \if@simurgh@csundef{parsimainfont}{%
    \simurgh@error{choose the main parsi font}{}}%
    {}%
}



% this is not good at all; it requires heaps of improvements
\setmainlatinfont[ExternalLocation,BoldFont={lmroman10-bold},BoldItalicFont={lmroman10-bolditalic},ItalicFont={lmroman10-italic},SmallCapsFont={lmromancaps10-regular},SlantedFont={lmromanslant10-regular},BoldSlantedFont={lmromanslant10-bold}]{lmroman10-regular}

\endinput