%% $Id: gentium-otf.sty 1133 2025-07-14 17:48:41Z herbert $
%%
%% This file is distributed under the terms of the LaTeX Project Public
%% License from CTAN archives in directory  macros/latex/base/lppl.txt.
%% Either version 1.3 or, at your option, any later version.
%%
%
\ProvidesPackage{gentium-otf}[%
  2025/07/14 v. 1.01 (Herbert Voss) Supports gentium fonts for lualatex and xelatex.] 

\RequirePackage{iftex,xkeyval,textcomp,fontspec}

\newif\if@gentium@book \@gentium@bookfalse
\DeclareOptionX{book}{\@gentium@booktrue}

\newif\if@gentium@medium \@gentium@mediumfalse
\DeclareOptionX{medium}{\@gentium@mediumtrue}

\newcommand*\gentiumRM@scale{1}
\DeclareOptionX{ScaleRM}{\renewcommand*{\gentiumRM@scale}{#1}}

\newcommand*\gentium@math{}  
\newcommand*\gentium@math@features{}  
\DeclareOptionX{math}{\renewcommand*{\gentium@math}{#1}}
\DeclareOptionX{mathFeatures}{\renewcommand*{\gentium@math@features}{#1}}

\newcommand*\gentium@sans{}  
\newcommand*\gentium@sans@features{}  
\DeclareOptionX{sans}{\renewcommand*{\gentium@sans}{#1}}
\DeclareOptionX{sansFeatures}{\renewcommand*{\gentium@sans@features}{#1}}

\newcommand*\gentium@mono{}  
\newcommand*\gentium@mono@features{}  
\DeclareOptionX{mono}{\renewcommand*{\gentium@mono}{#1}}
\DeclareOptionX{monoFeatures}{\renewcommand*{\gentium@mono@features}{#1}}

\def\gentium@defaultfeatures{}
\DeclareOptionX{defaultfeatures}{\def\gentium@defaultfeatures{#1}}

\ProcessOptionsX\relax

\if@gentium@book
  \def\gentium@variant{Book}%
\else
  \def\gentium@variant{}%
\fi

\ifxetex\XeTeXtracingfonts=1\fi
\defaultfontfeatures[\rmfamily]{
     Ligatures = TeX ,
     SmallCapsFeatures={Letters=SmallCaps},%       \ifluatex,Renderer=Basic\fi}, 
     \gentium@defaultfeatures
}

%------------------------   filenames start -------------------------
%%% NEW
%   1.            Gentium-Bold.ttf  
%   2.      Gentium-BoldItalic.ttf
%   3.       Gentium-ExtraBold.ttf
%   4. Gentium-ExtraBoldItalic.ttf
%   5.          Gentium-Italic.ttf
%   6.          Gentium-Medium.ttf
%   7.    Gentium-MediumItalic.ttf
%   8.         Gentium-Regular.ttf
%   9.        Gentium-SemiBold.ttf
%  10.  Gentium-SemiBoldItalic.ttf
%
%   1.           GentiumBook-Bold.ttf           
%   2.         GentiumBook-Medium.ttf         
%   3.       GentiumBook-SemiBold.ttf
%   4.     GentiumBook-BoldItalic.ttf     
%   5.   GentiumBook-MediumItalic.ttf   
%   6. GentiumBook-SemiBoldItalic.ttf
%   7.         GentiumBook-Italic.ttf  
%   8.        GentiumBook-Regular.ttf

\if$\gentium@math$\else
  \RequirePackage{unicode-math}
  \expandafter\setmathfont\expandafter[\gentium@math@features]{\gentium@math}
\fi

\if$\gentium@sans$\else
  \expandafter\setsansfont\expandafter[\gentium@sans@features]{\gentium@sans}
\fi

\if$\gentium@mono$\else
  \expandafter\setmonofont\expandafter[\gentium@mono@features]{\gentium@mono}
\fi

\edef\gentium@fontname{Gentium\gentium@variant}

\def\GentiumRegular{%
  \setmainfont{\gentium@fontname}[
    Scale          = \gentiumRM@scale ,
    UprightFont    = *-Regular,
    ItalicFont     = *-Italic,
    ItalicFeatures = { SmallCapsFont = *-Italic },
    SlantedFont    = *-Regular,
    SlantedFeatures= {FakeSlant=0.2},
    BoldFont       = *-SemiBold,
    BoldFeatures   = { SmallCapsFont = *-SemiBold },
    BoldItalicFont = *-SemiBoldItalic,
    BoldItalicFeatures = { SmallCapsFont = *-SemiBoldItalic },
    BoldSlantedFont= *-SemiBold,
    BoldSlantedFeatures= {FakeSlant=0.2, SmallCapsFont = *-SemiBold },
    SmallCapsFont  = *-Regular,
%  SmallCapsFeatures={RawFeature=+smcp},
    SmallCapsFeatures={Letters=SmallCaps}, 
    Extension      = .ttf
  ]
}
\def\GentiumMedium{%
  \setmainfont{\gentium@fontname}[
    Scale          = \gentiumRM@scale ,
    UprightFont    = *-Medium,
    ItalicFont     = *-MediumItalic,
    ItalicFeatures = { SmallCapsFont = *-MediumItalic },
    SlantedFont    = *-MediumItalic,
    SlantedFeatures= {FakeSlant=0.2},
    BoldFont       = *-Bold,
    BoldFeatures   = { SmallCapsFont = *-Bold },
    BoldItalicFont = *-BoldItalic,
    BoldItalicFeatures = { SmallCapsFont = *-BoldItalic },
    BoldSlantedFont= *-Bold,
    BoldSlantedFeatures= {FakeSlant=0.2, SmallCapsFont = *-Bold },
    SmallCapsFont  = *-Medium,
%  SmallCapsFeatures={RawFeature=+smcp},
    SmallCapsFeatures={Letters=SmallCaps}, 
    Extension      = .ttf  
  ]%
}

\if@gentium@medium
  \edef\gentium@main@font{Gentium\gentium@variant-Medium}%
  \GentiumMedium
\else
  \edef\gentium@main@font{Gentium\gentium@variant}%
  \GentiumRegular
\fi

\newfontface\ExtraBold{Gentium}%
  [ Scale          = \gentiumRM@scale ,
    UprightFont    = *-Medium,
    ItalicFont     = *-MediumItalic,
    ItalicFeatures = { SmallCapsFont = *-MediumItalic },
    SlantedFont    = *-Medium,
    SlantedFeatures= {FakeSlant=0.2},
    BoldFont       = *-ExtraBold,
    BoldFeatures   = { SmallCapsFont = *-ExtraBold },
    BoldItalicFont = *-ExtraBoldItalic,
    BoldItalicFeatures = { SmallCapsFont = *-ExtraBoldItalic },
    BoldSlantedFont= *-ExtraBold,
    BoldSlantedFeatures= {FakeSlant=0.2, SmallCapsFont = *-ExtraBold },
    SmallCapsFont  = *-Regular,
%  SmallCapsFeatures={RawFeature=+smcp},
    SmallCapsFeatures={Letters=SmallCaps}, 
    Extension      = .ttf  
  ]


\def\Lctosc#1{{\addfontfeature{RawFeature=+c2sc}#1}}
\def\LCtoSC{\@ifnextchar-\L@CtoSC\L@@CtoSC}
\def\L@CtoSC-{\addfontfeature{RawFeature=-c2sc}}
\def\L@@CtoSC#1{\addfontfeature{RawFeature=+c2sc}\ifx#1+\else#1\fi}

\def\Lctosmcp#1{{\addfontfeature{RawFeature={+c2sc,+smcp}}#1}}
\def\LCtoSMCP{\@ifnextchar-\L@CtoSMCP\L@@CtoSMCP}
\def\L@CtoSMCP-{\addfontfeature{RawFeature={-c2sc,-smcp}}}
\def\L@@CtoSMCP#1{\addfontfeature{RawFeature={+c2sc,+smcp}}\ifx#1+\else#1\fi}

\def\Lliga#1{{\addfontfeature{RawFeature=+liga}#1}}
\def\LLIGA{\@ifnextchar-\L@LIGA\L@@LIGA}
\def\L@LIGA-{\addfontfeature{RawFeature=-liga}}
\def\L@@LIGA#1{\addfontfeature{RawFeature=+liga}\ifx#1+\else#1\fi}

\def\Lss#1#2#3{{\addfontfeature{RawFeature=+ss#1#2}#3}}
\def\LSS#1#2{\addfontfeature{RawFeature=+ss#1#2}}

\def\Lcv{\@ifnextchar[\Lcv@i{\Lcv@i[1]}}
\def\Lcv@i[#1]#2#3#4{{\addfontfeature{RawFeature={+cv#2#3=#1}}#4}}
\def\LCV#1#2{\@ifnextchar[\LCV@i{\LCV@i[1]}}
\def\LCV[#1]#2#3{\addfontfeature{RawFeature={+cv#2#3=#1}}}

\def\Llang#1{\addfontfeature{Script=Cyrillic,Language=Serbian}}

\def\Lsup#1{{\addfontfeature{RawFeature=+sups}#1}}
\def\LSUP{\@ifnextchar-\L@SUP\L@@SUP}
\def\L@SUP-{\addfontfeature{RawFeature=-sups}}
\def\L@@SUP#1{\addfontfeature{RawFeature=+sups}\ifx#1+\else#1\fi}

\def\Lsub#1{{\addfontfeature{RawFeature=+subs}#1}}
\def\LSUB{\@ifnextchar-\L@SUB\L@@SUB}
\def\L@SUB-{\addfontfeature{RawFeature=-subs}}
\def\L@@SUB#1{\addfontfeature{RawFeature=+subs}\ifx#1+\else#1\fi}

\def\Lfrac#1{{\addfontfeature{RawFeature=+frac}#1}}
\def\LFRAC{\@ifnextchar-\L@FRAC\L@@FRAC}
\def\L@FRAC-{\addfontfeature{RawFeature=-frac}}
\def\L@@FRAC#1{\addfontfeature{RawFeature=+frac}\ifx#1+\else#1\fi}


\endinput

