% beuron.sty
% Paket f��r die Schrift der Beuroner Kunstschule
% Beuronese art script package
% Version 1.3
% Autor: K. Wehr
% 17. Januar 2018
% U.I.O.G.D.

% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.


\RequirePackage{expl3}
\ProvidesExplPackage {beuron} {2018/01/17} {1.3} {Beuronese art script package}

\RequirePackage{xparse}

\bool_lazy_or:nnT {\sys_if_engine_xetex_p:} {\sys_if_engine_luatex_p:}
   {
      \RequirePackage{fontspec}

      \fontspec_set_family:Nnn \l_beuron_schriftfamilie_tl
         {
            FontFace = {c}{n}{BeuronCondensed-Regular.otf},
            FontFace = {x}{n}{BeuronExtended-Regular.otf}
         }
         {
            Beuron-Regular.otf
         }
   }

\cs_generate_variant:Nn \tl_replace_all:Nnn {Nxn}

\box_new:N \l_beuron_mittepunkt_box
\skip_new:N \l_beuron_mittepunktabstand_skip

\tl_const:Nn \c_beuron_dehnbarer_doppelpunkt_tl
   {
      \penalty10000
      \skip_horizontal:N \l_beuron_mittepunktabstand_skip
      \c_colon_str
      \skip_horizontal:N \l_beuron_mittepunktabstand_skip
   }

% #1: Sollen Leerzeichen erhalten bleiben?
% #2: Text
\cs_new_protected:Npn \beuron_replace:nn #1#2
   {
      \skip_set:Nn \l_beuron_mittepunktabstand_skip {0em plus0.14em minus0.1em}

      \tl_set:Nn \l_tmpa_tl {#2}
      \tl_replace_all:Nnn \l_tmpa_tl {��} {AE}
      \tl_replace_all:Nnn \l_tmpa_tl {��} {AE}
      \tl_replace_all:Nnn \l_tmpa_tl {��} {OE}
      \tl_replace_all:Nnn \l_tmpa_tl {��} {OE}
      \tl_replace_all:Nnn \l_tmpa_tl {��} {UE}
      \tl_replace_all:Nnn \l_tmpa_tl {��} {UE}
      \tl_replace_all:Nnn \l_tmpa_tl {��} {SS}
      \tl_replace_all:Nxn \l_tmpa_tl {\c_colon_str \c_space_tl} {\c_beuron_dehnbarer_doppelpunkt_tl}
      \tl_replace_all:Nxn \l_tmpa_tl {\c_colon_str} {\c_beuron_dehnbarer_doppelpunkt_tl}

      \bool_if:NF #1
         {
            \hbox_set:Nn \l_beuron_mittepunkt_box {/}

            \tl_replace_all:Nnn \l_tmpa_tl {~}
               {
                  \skip_horizontal:N \l_beuron_mittepunktabstand_skip
                  \cleaders
                     \box_use:N \l_beuron_mittepunkt_box
                     \skip_horizontal:n {\box_wd:N \l_beuron_mittepunkt_box}
                  \skip_horizontal:N \l_beuron_mittepunktabstand_skip
               }
         }

      \l_tmpa_tl
   }

\cs_generate_variant:Nn \beuron_replace:nn {no}

\NewDocumentCommand \textbeuron {s m}
   {
      \group_begin:
      \bool_lazy_or:nnTF {\sys_if_engine_xetex_p:} {\sys_if_engine_luatex_p:}
         {
            \fontfamily{\l_beuron_schriftfamilie_tl}
            \fontseries{m}
            \fontshape{n}
            \selectfont
         }
         {
            \usefont{T1}{beuron}{m}{n}
         }
      \beuron_replace:no {#1}{#2}
      \group_end:
   }

\NewDocumentCommand \textbeuronc {s m}
   {
      \group_begin:
      \bool_lazy_or:nnTF {\sys_if_engine_xetex_p:} {\sys_if_engine_luatex_p:}
         {
            \fontfamily{\l_beuron_schriftfamilie_tl}
            \fontseries{c}
            \fontshape{n}
            \selectfont
         }
         {
            \usefont{T1}{beuron}{c}{n}
         }
      \beuron_replace:no {#1}{#2}
      \group_end:
   }

\NewDocumentCommand \textbeuronx {s m}
   {
      \group_begin:
      \bool_lazy_or:nnTF {\sys_if_engine_xetex_p:} {\sys_if_engine_luatex_p:}
         {
            \fontfamily{\l_beuron_schriftfamilie_tl}
            \fontseries{x}
            \fontshape{n}
            \selectfont
         }
         {
            \usefont{T1}{beuron}{x}{n}
         }
      \beuron_replace:no {#1}{#2}
      \group_end:
   }

\NewDocumentCommand \beuronOmega { }
   {
      \group_begin:
      \bool_lazy_or:nnTF {\sys_if_engine_xetex_p:} {\sys_if_engine_luatex_p:}
         {
            \fontfamily{\l_beuron_schriftfamilie_tl}
            \fontshape{n}
            \selectfont
            \symbol{937}
         }
         {
            \fontencoding{T1}
            \fontfamily{beuron}
            \fontshape{n}
            \selectfont
            \symbol{141}
         }
      \group_end:
   }