\NeedsTeXFormat{LaTeX2e}[2020-10-01]
\RequirePackage{l3keys2e}
\ProvidesExplPackage
  {projlib-font}
  {2022/02/26} {}
  {Font selection and configuration}

\keys_define:nn { projlib-font }
  {
    , useosf           .bool_set:N   = \l__projlib_font_useosf_bool
    , useosf           .initial:n    = { false }
    , old-style-figures.bool_set:N   = \l__projlib_font_useosf_bool
    , old~style~figures.bool_set:N   = \l__projlib_font_useosf_bool
    , old style figures.bool_set:N   = \l__projlib_font_useosf_bool
    , lmodern          .bool_set:N   = \l__projlib_font_lmodern_bool
    , lmodern          .initial:n    = { false }
    , latin-modern     .bool_set:N   = \l__projlib_font_lmodern_bool
    , latin~modern     .bool_set:N   = \l__projlib_font_lmodern_bool
    , latin modern     .bool_set:N   = \l__projlib_font_lmodern_bool
    , palatino         .bool_set:N   = \l__projlib_font_palatino_bool
    , palatino         .initial:n    = { false }
    , times            .bool_set:N   = \l__projlib_font_times_bool
    , times            .initial:n    = { false }
    , garamond         .bool_set:N   = \l__projlib_font_garamond_bool
    , garamond         .initial:n    = { false }
    , noto             .bool_set:N   = \l__projlib_font_noto_bool
    , noto             .initial:n    = { false }
    , biolinum         .bool_set:N   = \l__projlib_font_biolinum_bool
    , biolinum         .initial:n    = { false }
    , unknown          .code:n       = {}
  }
\ProcessKeysOptions { projlib-font }

\RequirePackage { setspace }

\cs_new:Nn \projlib_font_set_linespacing_latin:n
  {
    \cs_if_exist:NTF \projlib_language_set_linespacing_latin:n
      {
        \projlib_language_set_linespacing_latin:n { #1 }
      }
      {
        #1
      }
  }

\bool_if:NT \l__projlib_font_lmodern_bool
  {
    \RequirePackage { amssymb }
    \bool_if:NTF \l__projlib_font_useosf_bool
      {
        \RequirePackage { cfr-lm }
      }
      {
        \RequirePackage { lmodern }
      }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.00 } }
  }

\bool_if:NT \l__projlib_font_palatino_bool
  {
    \RequirePackage { mathpazo }
    \PassOptionsToPackage { defaultsups } { newpxtext }
    \RequirePackage { newpxtext }
    \cs_undefine:c { openbox }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.07 } }
    \bool_if:NT \l__projlib_font_useosf_bool { \useosf }
  }

\bool_if:NT \l__projlib_font_times_bool
  {
    \PassOptionsToPackage { defaultsups } { newtxtext }
    \RequirePackage { newtxtext }
    \RequirePackage { newtxmath }
    \cs_undefine:c { openbox }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.00 } }
    \bool_if:NT \l__projlib_font_useosf_bool { \useosf }
  }

\bool_if:NT \l__projlib_font_garamond_bool
  {
    \bool_if:NF \l__projlib_font_useosf_bool
      {
        \PassOptionsToPackage { lining } { ebgaramond }
      }
    \RequirePackage { ebgaramond-maths }
    \RequirePackage { ebgaramond }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.00 } }
  }

\bool_if:NT \l__projlib_font_noto_bool
  {
    \bool_if:NT \l__projlib_font_useosf_bool
      {
        \PassOptionsToPackage { oldstyle } { notomath }
      }
    \RequirePackage { anyfontsize }
    \RequirePackage { notomath }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.00 } }
  }

\bool_if:NT \l__projlib_font_biolinum_bool
  {
    \sys_if_engine_pdftex:TF
      {
        \bool_if:NT \l__projlib_font_useosf_bool
          {
            \PassOptionsToPackage { osf } { biolinum }
          }
          \RequirePackage { biolinum }
          \tl_gset:Nn \familydefault { \biolinum@family }
      }
      {
        \PassOptionsToPackage { no-math } { fontspec }
        \RequirePackage { fontspec }
        \bool_if:NTF \l__projlib_font_useosf_bool
          {
            \setmainfont { LinBiolinum_R.otf } [
              BoldFont       = LinBiolinum_RB.otf  ,
              ItalicFont     = LinBiolinum_RI.otf  ,
              BoldItalicFont = LinBiolinum_RBO.otf ,
              Numbers        = OldStyle            , ]
          }
          {
            \setmainfont { LinBiolinum_R.otf } [
              BoldFont       = LinBiolinum_RB.otf  ,
              ItalicFont     = LinBiolinum_RI.otf  ,
              BoldItalicFont = LinBiolinum_RBO.otf , ]
          }
      }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.05 } }
    \RequirePackage [ italic, defaultmathsizes ] { mathastext }
  }

\endinput
%%
%% End of file `projlib-font.sty'.
