
%%% OFS: Olsak's Font System based on NFSS + LaTeX macros
%%% Jul 2001                                   Petr Olsak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% see ofsdoc.tex for more details

\NeedsTeXFormat{LaTeX2e} % I don't like LaTeX, the plain macro is more clean.
                         % See the variant of my macros ofs.tex for plain.
                         % But, some users ask for LaTeX style files :-((

%\ProvidesPackage{ofs}[2001/07/01 OFS based on NFSS]
%\ProvidesPackage{ofs}[2002/10/24 OFS based on NFSS]
% \addcmd added
\ProvidesPackage{ofs}[2003/02/25 OFS based on NFSS]
% \setfonts {\bgroup \catcode`\-=12 ... by Z. Wagner added

\def\OFSversion{Oct. 2002}
\typeout{OFS (Olsak's Font System) based on NFSS initialized.
     <\OFSversion>}

%%%% \fontusage %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\bgroup \catcode`\#=12 
  \catcode`\{=12 \catcode`}=12 \catcode`\X=1 \catcode`\Z=2
  \catcode`\^^M=14 \catcode`\ =12 \catcode`\|=0\catcode`\\=12%
|gdef|fontusageX
|begingroup
|typeoutX%---------------------------------------------------------------
\fontusage: ============ Olsak's Font System, usage: ===============^^J
\usepackage [sjannon, sdynamo] {ofs} ... for example^^J 
\showfonts  ... shows all loaded font families (by previous \usepackage)^^J
\setfonts [Family/] ... local switch to the new family, after this, the^^J
  \rm, \bf, \it, bi will switch to the variants. The current size is used.^^J
\setfonts [/size] ... local switch to the new size of fonts, the family is^^J 
  not changed. The "size" has the following possible formats:^^J
    at<dimen>       ... the same as \font\something=file at<dimen>^^J
    <dimen>         ... the same as at<dimen>^^J
    <number>        ... the same as at<number>pt^^J
    scaled<number>  ... the same as \font\something=file scaled<number>^^J
    mag<decimal-number> fonts will be magnified by given coefficient^^J
                        depend on current size of the fonts.^^J
\setfonts [Family/size] ... switch to the new family at given size^^J
\setfonts [Family-vr/]  ... switch to the specified font, the current size^^J
  is used. The "vr" is two-letter acronym for variants: rm, bf, it, bi.^^J
\setfonts [Family-vr/size] ... switch to the specified font.^^J
\fontdef\name [Family/size] ... same as \gdef\name{\setfonts[Family/size]}^^J
  The "Family" or "size" parameter may be empty.^^J
\OFSfamily [Family]        ... expands to internal NFSS family name.^^J
\OFSfamilydefault [Family] ... same as \edef\familydefault{\OFSfamily[Family]}
Z%-----------------------------------------------------------------------
|endgroup 
Z
|egroup


%%%% \rm, \bf, \it, bi %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\bi{\fontseries{b}\fontshape{it}\selectfont}
\def\bf{\fontseries{b}\fontshape{n}\selectfont}
\def\it{\fontseries{m}\fontshape{it}\selectfont}
\def\rm{\fontseries{m}\fontshape{n}\selectfont}
\def\bfdefault{b}

%%%% Macros used in declaration files %%%%%%%%%%%%%%%%%%

\def\ofs@listfamilies{}
\def\ofs@messageheader{OFS (l.\the\inputlineno): }
\def\ofs@unknownfam{undefined}

\def\OFSdeclarefamily [#1] #2{%
   \OFSputfamlist {^^J \space\space[#1/]}%
   \expandafter \gdef\csname ofs-fam:#1\endcsname {#2}%
   \expandafter \gdef\csname ofs-fam:#2\endcsname {#2}%
   \bgroup
      \count2=18
      \def\tmpa ##1{\if:##1\let\tmpa=\relax 
                    \else\advance\count2 by-1 \fi\tmpa}\tmpa #1:%
      \def\tmpa {\ifnum\count2>0 \advance\count2 by-1 \OFSputfamlist{ }%
                 \else\let\tmpa=\relax \fi\tmpa}\tmpa     
   \egroup
}
\def\OFSfamily [#1]{%
   \expandafter \ifx\csname ofs-fam:#1\endcsname \relax
      \ofs@unknownfam
   \else \csname ofs-fam:#1\endcsname 
   \fi
}
\def\OFSfamilydefault [#1]{%
   \edef\tmpa{\OFSfamily[#1]}%
   \ifx\tmpa\ofs@unknownfam 
      \typeout{\ofs@messageheader WARNING. The family is not set.^^J 
         The family name [#1] is not known in the list:
         \ofs@listfamilies}%
   \else
      \edef\familydefault{\tmpa}%
   \fi
}      
\def\OFSputfamlist #1{%
   \xdef\ofs@listfamilies {\ofs@listfamilies #1}%
}
\def\OFSextraencoding #1{%
   \expandafter \ifx \csname ofs-enc:#1\endcsname \relax
      \edef\ofs@extraencoding{#1}%
      \lowercase{\input{#1ini.def}}\relax
      \expandafter \def \csname ofs-enc:#1\endcsname {}%
   \fi
}
\def\OFSnormalvariants{\OFSputfamlist{%
  \string\rm, \string\bf, \string\it, \string\bi}}

%%%% Defaults %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\OFSputfamlist {^^Jdefaults:}
\OFSdeclarefamily  [CMRoman]       {cmr}  \OFSnormalvariants
\OFSputfamlist {, \string\sl}

\OFSdeclarefamily  [CMSans]        {cmss}
\OFSputfamlist {\string\rm, \string\bf, \string\it, \space-} 

\OFSdeclarefamily  [CMTypewriter]  {cmtt}
\OFSputfamlist {\string\rm, \space- , \string\it, \space- , \string\sl}

\OFSdeclarefamily  [Times]         {ptm}  \OFSnormalvariants

\OFSdeclarefamily  [Helvetica]     {phv}  \OFSnormalvariants
\OFSputfamlist{, \string\nrm, \string\nbf, \string\nit, \string\nbi}

\OFSdeclarefamily  [Courier]       {pcr}  \OFSnormalvariants

\def\sl{\fontseries{m}\fontshape{sl}\selectfont}
\def\nrm{\fontseries{mc}\fontshape{n}\selectfont}
\def\nbf{\fontseries{bc}\fontshape{n}\selectfont}
\def\nit{\fontseries{mc}\fontshape{it}\selectfont}
\def\nbi{\fontseries{bc}\fontshape{it}\selectfont}


%%%% \showfonts %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\showfonts{\typeout{\ofs@messageheader
    The list of known font families:\ofs@listfamilies}}

%%%% \setfonts %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\setfonts {\bgroup \catcode`\-=12 \ofs@setfonts}
\def\ofs@setfonts [#1/#2]{\egroup \OFSsetfonts{#1}{#2}}
\DeclareRobustCommand \OFSsetfonts [2]{%
   \edef\tmpa{#1}\expandafter \ofs@readfamvariant\tmpa--:%
   \ifx\famvariant\empty
      \ofs@setfontfamily [#1/#2]%
   \else
      \ofs@setsinglefont [#1/#2]%
   \fi
   \ignorespaces
}
\def\ofs@readfamvariant #1-#2-#3:{\def\tmpb{#1}\def\famvariant{#2}}   

\def\ofs@setfontfamily [#1/#2]{%
   \if |#1|\else
      \edef\tmpa{\OFSfamily[#1]}%
      \ifx\tmpa\ofs@unknownfam 
         \typeout{\ofs@messageheader WARNING. The family is not set.^^J 
            The family name [#1/] is not known in the list:
            \ofs@listfamilies}%
      \else
         \fontfamily{\tmpa}%
      \fi
   \fi
   \if |#2|\else
      \edef\tmpa{#2}\expandafter\ofs@readfontsize \tmpa:%
      \fontsize{\tmpa}{\f@baselineskip}%
   \fi
   \ofs@selectfont
}
\let\ofs@selectfont=\selectfont

\def\ofs@setsinglefont [#1-#2/#3]{%
   \let\ofs@selectfont=\relax
   \ofs@setfontfamily [#1/#3]\let\ofs@selectfont=\selectfont
   \csname #2\endcsname
}
\def\ofs@readfontsize #1#2:{\if a#1\ofs@readfontsizeat #1#2:%
   \else \if s#1\ofs@readfontsizescaled #1#2:%
   \else \if m#1\ofs@readfontsizemag #1#2..:%
   \fi\fi\fi
}
\def\ofs@readfontsizeat at#1:{\def\tmpa{#1}}
\def\ofs@readfontsizescaled scaled#1:{\dimen0=0.01pt \dimen0=#1\dimen0
   \edef\tmpa{\the\dimen0}}
\def\ofs@readfontsizemag mag#1.#2.#3:{\dimen0=\f@size pt 
   \if|#2|\if|#3|%
      \errmessage{OFS: "mag" need the decimal parameter with decimal point}%
   \fi\fi
   \dimen0 =#1.#2 \dimen0
   \advance\dimen0 by7sp % rounding to three digits after decimal point
   \ifdim\dimen0<10pt \edef\tmpa{+\the\dimen0}\else \edef\tmpa{\the\dimen0}\fi
   \dimen0 =\expandafter \ofs@readsixdigits \tmpa :::::|pt
   \edef\tmpa{\the\dimen0}%
}
\def\ofs@readsixdigits #1#2#3#4#5#6#7#8#9|{%
   \if:#5#1#2\else\if:#6#1#2#3\else\if:#7#1#2#3#4\else
   \if:#8#1#2#3#4#5\else#1#2#3#4#5#6\fi\fi\fi\fi
}

%%%% \fontdef %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\fontdef #1[#2/#3]{\def\tmpc{!}%
   \edef\tmpa{#3}\ifx \tmpa\tmpc \edef\tmpa{\f@size}\fi
   \edef\tmpb{#2}\expandafter \ofs@readfamvariant\tmpb--:%
   \ifx \tmpb\tmpc
      \ifx\famvariant\empty
         \xdef #1{\noexpand\setfonts [\f@family/\tmpa]}%
      \else
         \xdef #1{\noexpand\setfonts [\f@family-\famvariant/\tmpa]}%
      \fi
   \else
      \xdef #1{\noexpand\setfonts [#2/\tmpa]}%
   \fi
}

%%%% \ifknownfam %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newif \ifofs@familypresent

\def\ifknownfam [#1]{%
   \expandafter \ifx\csname ofs-fam:#1\endcsname \relax
       \expandafter \ofs@familypresentfalse
   \else
       \expandafter \ofs@familypresenttrue
   \fi
   \ifofs@familypresent
}

%%%% \addcmd %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\addcmd #1#2{\expandafter\def\expandafter\tmpa\expandafter{#1}%
   \def\tmpb{#1}%
   \ifx\tmpa\tmpb % the #1 is not a macro
      \expandafter\let\csname \string#1-original\endcsname =#1%
      \expandafter\def\expandafter #1\expandafter{%
           \csname\string#1-original\endcsname #2}%
   \else          % the #1 is a macro
      \expandafter\def\expandafter #1\expandafter{#1#2}%
   \fi
}

%%%% Extra encoding %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\setextrafont{\ifx\ofs@extraencoding\undefined
   \typeout{\ofs@messageheader WARNING. Extra encoding is no declared by
        \string\OFSextraencoding.}%
   \else \fontencoding{\ofs@extraencoding}\selectfont \fi
}
\def\extchar{\afterassignment\ofs@doextchar \chardef\tmpa=}
\def\ofs@doextchar{{\setextrafont\tmpa}}


%%%% Accents %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\DeclareRobustCommand \accentabove [3]{%
   \def\tmpa{#3}%
   \ifx \tmpa\empty #1\else
      \leavevmode\vbox{%
         \setbox0=\hbox{#3}\setbox2=\hbox{#1}%
         \dimen0=\ht0 \advance\dimen0 by\dp2 \advance\dimen0 by#2\relax 
         \offinterlineskip
         \halign {##\cr
            \hidewidth\slantcorrection{\dimen0}\box2 \hidewidth\cr
            \noalign{\kern#2}\box0 \cr}}%
   \fi
}
\DeclareRobustCommand \accentbelow [3]{%
   \def\tmpa{#3}%
   \ifx \tmpa\empty #1\else
      \leavevmode\vtop{%
         \setbox0=\hbox{#3}\setbox2=\hbox{#1}%
         \dimen0=-\dp0 \advance\dimen0 by-\ht2 \advance\dimen0 by-#2\relax
         \offinterlineskip
         \halign {##\cr \box0 \cr\noalign{\kern#2}%
            \hidewidth \slantcorrection{\dimen0}%
            \dimen0=\dp2 \ifdim\dimen0<.2ex \dimen0=.2ex \fi
            \vbox to\dimen0{\hbox{\box2}\vss}\hidewidth\cr}}%
   \fi
}
\def\slantcorrection #1{\dimen0=#1\relax
    \dimen0 =\strip@pt \fontdimen1\the\font \dimen0
    \kern 2\dimen0
}


%%%% Options = OFS-style files %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\let\OFSprocessoptions=\relax
\DeclareOption *{\input{\CurrentOption.sty}}
\ProcessOptions\relax
\let\OFSprocessoptions=\undefined




