%% $Id: lucida-otf.sty 751 2018-03-31 17:34:46Z 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.
%%
% Copyright 2024 Herbert Voss hvoss@tug.org
%%
\ProvidesPackage{lucida-otf}[%
  2024/12/14 v. 0.10 (Herbert Voss) Supports Lucida OpenType for lualatex/xelatex.] 
%
\RequirePackage{ifxetex,ifluatex,xkeyval,textcomp}
\RequirePackage{unicode-math}  % support opentype math fonts
                               % loads itself fontspec
%
%
\providecommand\lucidaRM@features{Scale=0.87}%  Roman
\providecommand\lucidaSS@features{Scale=0.87}%  SansSerif
\providecommand\lucidaTT@features{Scale=MatchLowercase,FakeStretch=0.88,Ligatures=ResetAll}%  Typewriter
\providecommand\lucidaGrandeTT@features{Scale=MatchLowercase,FakeStretch=0.9,Ligatures=ResetAll}%  Typewriter
\providecommand\lucidaConsoleTT@features{Scale=MatchLowercase,FakeStretch=0.9,Ligatures=ResetAll}%  Typewriter
\providecommand\lucidaMM@features{}%            Math regular
\providecommand\lucidaMMbold@features{}%        Math bold
\providecommand\lucidaBL@features{}%            Blackletter
\providecommand\lucidaCAL@features{}%           Calligraphy
\providecommand\lucidaHW@features{}%            Handwriting
\providecommand\lucida@DefaultFeatures{}
\DeclareOptionX{RM}{\renewcommand*{\lucidaRM@features}{#1}}
\DeclareOptionX{SS}{\renewcommand*{\lucidaSS@features}{#1}}
\DeclareOptionX{TT}{\renewcommand*{\lucidaTT@features}{#1}}
\DeclareOptionX{GTT}{\renewcommand*{\lucidaGrandeTT@features}{#1}}
\DeclareOptionX{CTT}{\renewcommand*{\lucidaConsoleTT@features}{#1}}
\DeclareOptionX{MM}{\renewcommand*{\lucidaMM@features}{#1}}
\DeclareOptionX{MMbold}{\renewcommand*{\lucidaMMbold@features}{#1}}
\DeclareOptionX{BL}{\renewcommand*{\lucidaBL@features}{#1}}
\DeclareOptionX{CAL}{\renewcommand*{\lucidaCAL@features}{#1}}
\DeclareOptionX{HW}{\renewcommand*{\lucidaHW@features}{#1}}
\DeclareOptionX{DefaultFeatures}{\def\lucida@DefaultFeatures{#1}}

\newif\ifLucida@useKerning \Lucida@useKerningtrue
\DeclareOptionX{useKerning}[true]{\@nameuse{Lucida@useKerning#1}}

\ProcessOptionsX\relax

\def\Lucida@RawFeatures{}\def\Lucida@MathRawFeatures{}
\ifLucida@useKerning
  \ifluatex 
    \RequirePackage{luacode}
    \typeout{loading lucida-otf-kern.tex ... }%
    \input{lucida-otf-kern.tex}% 
    \def\Lucida@RawFeatures{+lucidaletterkerning,+lucidanumberkerning}
    \def\Lucida@MathRawFeatures{+lucidanumberkerning}
  \fi
\fi

\defaultfontfeatures{Ligatures=TeX,\lucida@DefaultFeatures}% default in fontspec
%
\typeout {Using file names for the Lucida font}%
%-----------------------------------------  file names ----------------------------
\setmainfont{LucidaBrightOT}[% main rm
       Extension = .otf,
  \lucidaRM@features,
      ItalicFont = *-Italic,
        BoldFont = *-Demi,
  BoldItalicFont = *-DemiItalic,
      RawFeature = {\Lucida@RawFeatures},
]
%
\setsansfont{LucidaSansOT}[% main sans
       Extension = .otf,
  \lucidaSS@features,
      ItalicFont = *-Italic,
        BoldFont = *-Demi,
        BoldFeatures = {RawFeature={embolden=2}},
  BoldItalicFont = *-DemiItalic,
        BoldItalicFeatures = {RawFeature={embolden=2}},
]
%
\setmonofont{LucidaSansTypewriterOT}[% main typewriter
       Extension = .otf,
      \lucidaTT@features,
      ItalicFont = *-Oblique,
        BoldFont = *-Bold,
  BoldItalicFont = *-BoldOblique,
%        BoldFont = *,
%        BoldFeatures = {RawFeature={embolden=1.7},SmallCapsFont = * },        
%        BoldItalicFont = *-Oblique,
%        BoldItalicFeatures = {RawFeature={embolden=1.75},SmallCapsFont=*-Oblique}
]
\newfontfamily\lucidaSLshape{LucidaBrightOT}[
       FakeSlant = 0.2,
       Extension = .otf,
    \lucidaRM@features,
        BoldFont = *-Demi,
  BoldItalicFont = *-DemiItalic
]
%\renewcommand\sldefault{\lucidaSLshape}
\let\slshape\lucidaSLshape
%
% Setting math
% First we have to expand the feature macros:

  \edef\temp@mm@features{\lucidaMM@features, RawFeature = {\Lucida@MathRawFeatures}}
\AtBeginDocument{%
  \expandafter\setmathfont\expandafter[\temp@mm@features]{LucidaBrightMathOT.otf}%
  \expandafter\setmathfont\expandafter[\lucidaMMbold@features,version=bold]{LucidaBrightMathOT-Demi.otf}%
}

%
% The specialized one-off fonts:
\newfontface\LucidaBlackletter{LucidaBlackletterOT}[
  Extension = .otf,
  \lucidaBL@features]
\newfontface\LucidaCalligraphy{LucidaCalligraphyOT}[
  Extension = .otf,
  \lucidaCAL@features]
\newfontface\LucidaHandwriting{LucidaHandwritingOT}[
  Extension = .otf,
  \lucidaHW@features]
%
% GrandeMono and Console fonts for an example:

\newfontfamily\LucidaGrandeMonoDK{LucidaGrandeMonoDK}[
       Extension = .otf,
  \lucidaGrandeTT@features,
      ItalicFont = *-Italic,
        BoldFont = *-Bold,
  BoldItalicFont = *-BoldItalic
]
%
\newfontfamily\LucidaConsoleDK{LucidaConsoleDK}[%
       Extension = .otf,
  \lucidaConsoleTT@features,
      ItalicFont = *-Italic,
        BoldFont = *-Bold,
  BoldItalicFont = *-BoldItalic
]


\endinput
