% \iffalse
% $Id: dogma.dtx,v 1.15 2008-03-21 03:15:56 boris Exp $
%
% Copyright (c) 2008, Boris Veytsman
%
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions
% are met: 
%
%    * Redistributions of source code must retain the above copyright
%    notice, this list of conditions and the following disclaimer. 
%    * Redistributions in binary form must reproduce the above
%    copyright notice, this list of conditions and the following
%    disclaimer in the documentation and/or other materials provided
%    with the distribution. 
%    * Neither the name of the original author nor the names of the
%    contributors may be used to endorse or promote products derived
%    from this software without specific prior written permission. 
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
% CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
% INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
% BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
% EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
% TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
% DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
% ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
% OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
% \fi 
% \CheckSum{340}
%
%
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~} 
%
%\iffalse
% Taken from xkeyval.dtx
%\fi
%\makeatletter
%\def\DescribeOption#1{\leavevmode\@bsphack
%              \marginpar{\raggedleft\PrintDescribeOption{#1}}%
%              \SpecialOptionIndex{#1}\@esphack\ignorespaces}
%\def\PrintDescribeOption#1{\strut\emph{option}\\\MacroFont #1\ }
%\def\SpecialOptionIndex#1{\@bsphack
%    \index{#1\actualchar{\protect\ttfamily#1}
%           (option)\encapchar usage}%
%    \index{options:\levelchar#1\actualchar{\protect\ttfamily#1}\encapchar
%           usage}\@esphack}
%\def\DescribeOptions#1{\leavevmode\@bsphack
%  \marginpar{\raggedleft\strut\emph{options}%
%  \@for\@tempa:=#1\do{%
%    \\\strut\MacroFont\@tempa\SpecialOptionIndex\@tempa
%  }}\@esphack\ignorespaces}
%\makeatother
%
%
% \MakeShortVerb{|}
% \GetFileInfo{dogma.dtx}
% \title{\LaTeX{} Support For Dogma Fonts From Emigre Graphics}
% \author{Boris Veytsman\thanks{%
% \href{mailto:borisv@lk.net}{\texttt{borisv@lk.net}},
% \href{mailto:boris@varphi.com}{\texttt{boris@varphi.com}}}} 
% \date{\filedate, \fileversion}
% \maketitle
% \begin{abstract}
%   This package provides \LaTeX{} support for the Dogma Fonts from
%   Emigre Graphics, designed by Zuzana Licko, 1994.  It has
%   everything you need to typeset in this font - except the font
%   itself, of course. 
% \end{abstract}
% \tableofcontents
%
% \changes{v1.0}{2008/02/17}{First fully functional version} 
% \changes{v1.0a}{2008/02/19}{Documentation update} 
% \changes{v1.0b}{2008/02/21}{Documentation update} 
% \changes{v1.0c}{2008/02/25}{Installation update} 
% \changes{v1.1}{2008/02/26}{Added letterspaced font} 
% \changes{v1.3}{2008/03/20}{Documentation update} 
% \changes{v1.3}{2008/03/20}{Added several letterspaced fonts} 
% \clearpage
%
%
%\section{Introduction}
%\label{sec:intro}
%
% This package provides support files for the Dogma Font family from
% Emigre Graphics.  According to the Fontname scheme~\cite{fontname} this
% corresponds to the family |fdg|.
%
% The package is written for the set of fonts currently used by
% \emph{No Starch Press,} \url{http://www.nostarch.com}.  The
% copyright statement in the fonts refers to 1994.  It is possible
% that other versions of the fonts have slightly different metrics,
% and package should be changed to accommodate this.  To make this
% easier, I release the package under BSD-style license.  This is even
% more appropriate since most of the files is generated following the
% great course~\cite{fontinstallationguide}.
%
% The support is limited to T1 and TS1 encoding.  No VTeX support
% files are included.
%
%
%\section{Installation}
%\label{sec:install}
%
%
%
% First, you need to purchase the fonts themselves: the |pfb| files
% are \emph{not} included in the package.  If you got the fonts from
% \emph{No Starch press,} do not rename the |pfb| files.  However, if
% there are uppercase letters in your file names, downcase them.  If
% you obtained the files from another source, rename the fonts
% according to Table~\ref{tab:PFB}.  If your \TeX{} system is
% TDS-compliant, install the files into
% \path{$TEXMF/fonts/type1/public/dogma}. Download
% \url{http://ctan.tug.org/install/fonts/psfonts/emigre/dogma.tds.zip}
% and unzip this file in \path{$TEXMF}.  Add |+fdg.map| to the
% configuration files of dvips, pdftex and your dvi previewer.
%
% Install the files |*.fd| and |*.sty| in \path{$TEXMF/tex/latex/dogma}.
% and documentation (|*.pdf| and |README|) in
% \path{$TEXMF/doc/latex/dogma}. 
%  
% Run updmap and texhash programs to update the configuration files
% and file names database.
%
%
%
% \begin{table}[tp]
%   \centering
%   \caption{PFB Files}
%   \label{tab:PFB}
%
%   \begin{tabular}{ll}
%     \toprule
%    File  &  Font \\
%    \midrule
%    |dogmab01.pfb| & Dogma Bold \\
%    |dogmab07.pfb| & Dogma Black\\
%    |dogmao00.pfb| & Dogma Outline\\
%    |dogmsb74.pfb| & Dogma Script Bold\\
%    \bottomrule
%   \end{tabular}
%
% \end{table}
%
%
% The style |dogma.sty| provides a number of commands for using the
% font family (see Section~\ref{sec:dogma.sty})
%
%
%\section{Using \LaTeX{} Style }
%\label{sec:dogma.sty}
%
% To use Dogma font, you may just add |\usepackage{dogma}| to your
% preamble.  The package defines a number of font shapes and series,
% as listed in Table~\ref{tab:fonts}.  To use them, issue the standard
% NFSS command, for example
% \begin{verbatim}
% \fontfamily{fdg}\fontshape{ol}\fontseries{b}\selectfont
% \end{verbatim}
% \DescribeMacro{\textdogmabold}
% \DescribeMacro{\textdogmablack}
% \DescribeMacro{\textdogmaoutline}
% \DescribeMacro{\textdogmascript}
% Additionally, the commands |\textdogmabold|, |\textdogmablack|,
% |\textdogmaoutline|, |\textdogmascript| typeset their arguments in
% the corresponding fonts, for example
% |\textdogmaoutline{Zuzana~Licko}|.  The standard italics commands
% inside bold font switch from Dogma Bold to Dogma Script Bold, and
% inside heavy font switch from Dogma Heavy to Dogma Heavy Slanted. 
% 
%
% \begin{table}[tp]
%   \centering
%
%   \caption{Fonts Provided By The Package}
%   \label{tab:fonts}
%   \begin{tabular}{lp{0.6\textwidth}}
%     \toprule
%     Series  & Shapes \\
%     \midrule
%     |b| (bold) & |n| (upright), |it| (script), |sl| (slanted),
%     |sc| (small caps), |ol| (outline)\\
%     |bk| (bold letterspaced 5\%) & |n| (upright)\\
%     |bq| (bold letterspaced 10\%) & |n| (upright)\\
%     |br| (bold letterspaced 20\%) & |n| (upright)\\
%     |bs| (bold letterspaced 30\%) & |n| (upright)\\
%     |h| (heavy) & |n| (upright), |sl| (slanted),
%     |sc| (small caps)\\
%     \bottomrule
%   \end{tabular}
%   
% \end{table}
%
%
% \DescribeOption{scaled}
% It is probably not a good idea to use Dogma font in the body of the
% text.  However, if you definitely want to do this, the package
% |dogma| provides a parameter for better blending body fonts with
% Dogma font.  If you call the style with the optional parameter
% |scaled=...|, the font will be scaled down by the corresponding
% factor, for example |\usepackage[scaled=0.94]{dogma}|.
%
%
% \StopEventually{
%   \clearpage
% \paragraph{Acknowledgement}
% This package was written for No Starch Press,
% \url{http://www.nostarch.com}. 
%
%   \bibliography{dogma}
%   \bibliographystyle{unsrt}}
%
% \clearpage
%\section{Implementation}
%\label{sec:impl}
%
%\subsection{Identification}
%\label{sec:ident}
%
% We start with the declaration who we are.  Most |.dtx| files put
% driver code in a separate driver file |.drv|.  We roll this code into the
% main file, and use the pseudo-guard |<gobble>| for it.
%    \begin{macrocode}
%<style>\NeedsTeXFormat{LaTeX2e}
%<*gobble>
\ProvidesFile{dogma.dtx}
%</gobble>
%<style>\ProvidesClass{dogma}
%<fdg-drv>\ProvidesFile{fdg-drv.tex}
%<fdg-map>\ProvidesFile{fdg-map.tex}
%<*!t1k&!ts1k&!t1q&!ts1q&!t1r&!ts1r&!t1s&!ts1s>
[2008/03/20 v1.3 Using Dogma Font From Emigre Graphics in LaTeX]
%</!t1k&!ts1k&!t1q&!ts1q&!t1r&!ts1r&!t1s&!ts1s>
%    \end{macrocode}
% And the driver code:
%    \begin{macrocode}
%<*gobble>
\documentclass{ltxdoc}
\usepackage{booktabs}
\usepackage{url}
\usepackage[breaklinks,colorlinks,linkcolor=black,citecolor=black,
            pagecolor=black,urlcolor=black,hyperindex=false]{hyperref}
\PageIndex
\CodelineIndex
\RecordChanges
\EnableCrossrefs
\begin{document}
  \DocInput{dogma.dtx}
\end{document}
%</gobble> 
%    \end{macrocode}
%
%
%\subsection{Fontinst Driver}
%\label{sec:drv}
%
% This follows~\cite{fontinstallationguide}.
% 
% First, the preamble
%    \begin{macrocode}
%<*fdg-drv>
\input fontinst.sty
%    \end{macrocode}
%  
% There is no ``medium'' for Dogma (although |afm| file says that Dogma
% Black is medium, this is a lie).  We use script for italics
%    \begin{macrocode}
\substitutesilent{m}{bx}
\substitutesilent{bx}{b}
\setint{smallcapsscale}{750}
\setint{slant}{167}
%    \end{macrocode}
%
% \begin{macro}{kspread}
% \changes{v1.3}{2008/03/20}{Changed spacing} 
% Letterspacing spread 5\%
%    \begin{macrocode}
\setint{kspread}{25}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{qspread}
% \changes{v1.2}{2008/02/29}{Changed spacing} 
% \changes{v1.3}{2008/03/20}{Changed spacing} 
% Letterspacing spread 10\%
%    \begin{macrocode}
\setint{qspread}{50}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{rspread}
% \changes{v1.3}{2008/03/20}{Changed spacing} 
% Letterspacing spread 20\%
%    \begin{macrocode}
\setint{rspread}{100}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{sspread}
% \changes{v1.3}{2008/03/20}{Changed spacing} 
% Letterspacing spread 30\%
%    \begin{macrocode}
\setint{sspread}{150}
%    \end{macrocode}
% \end{macro}
% 
% Starting recording transforms:
%    \begin{macrocode}
\recordtransforms{fdg-rec.tex}
%    \end{macrocode}
% A bunch of fonts:
%    \begin{macrocode}
\transformfont{fdgb8r}{\reencodefont{8r}{\fromafm{dogmab01}}}
\transformfont{fdgh8r}{\reencodefont{8r}{\fromafm{dogmab07}}}
\transformfont{fdgbl8r}{\reencodefont{8r}{\fromafm{dogmao00}}}
\transformfont{fdgbw8r}{\reencodefont{8r}{\fromafm{dogmsb74}}}
%    \end{macrocode}
% Outline and script fonts are already slanted.  We slant the other
% two ones.
%    \begin{macrocode}
\transformfont{fdgbo8r}{\slantfont{\int{slant}}%
  \reencodefont{8r}{\fromafm{dogmab01}}} 
\transformfont{fdgho8r}{\slantfont{\int{slant}}%
  \reencodefont{8r}{\fromafm{dogmab07}}} 
%    \end{macrocode}
%
%
% There is no hook in |fontinst.sty| for writing our own preamble to
% |.fd| file.  However, we need to add scaling commands to the
% preamble. OK, we will patch fontinst:
%    \begin{macrocode}
\fontinstcc
\def\fd_family#1#2#3{
   \a_toks{#3}
   \edef\lowercase_file{\lowercase{
     \edef\noexpand\lowercase_file{#1#2.fd}}}
   \lowercase_file
   \open_out{\lowercase_file}
   \out_line{\percent_char~Filename:~\lowercase_file}
   \out_line{\percent_char~Created~by:~tex~\jobname}
   \out_line{\percent_char~Created~using~fontinst~v\fontinstversion}
   \out_line{}
   \out_line{\percent_char~THIS~FILE~SHOULD~BE~PUT~IN~A~TEX~INPUTS~
      DIRECTORY}
   \out_line{}
   \out_line{\string\ProvidesFile{\lowercase_file}}
   \out_lline{[
      \the\year/
      \ifnum10>\month0\fi\the\month/
      \ifnum10>\day0\fi\the\day\space
      Fontinst~v\fontinstversion\space
      font~definitions~for~#1/#2.
   ]}
   \out_line{}
%    \end{macrocode}
% Here is our patch:
%    \begin{macrocode}
   \out_line{\string\expandafter\string\ifx\string\csname\space
     Dgm@scale\string\endcsname\string\relax}
   \out_line{\space\string\let\string\Dgm@@scale\string\@empty}
   \out_line{\string\else}
   \out_line{\space\string\edef\string\Dgm@@scale\left_brace_char 
       s*[\string\csname\space Dgm@scale\string\endcsname]
       \right_brace_char\percent_char}
   \out_line{\string\fi\percent_char}
   \out_line{}
%    \end{macrocode}
% End of the patch.
%    \begin{macrocode}
   \out_line{\string\DeclareFontFamily{#1}{#2}{\the\a_toks}}
   {
      \csname #1-#2\endcsname
      \out_line{}
      \let\do_shape=\substitute_shape
      \csname #1-#2\endcsname
      \let\do_shape=\remove_shape
      \csname #1-#2\endcsname
   }
   \x_cs\g_let{#1-#2}\x_relax
   \out_line{}
   \out_line{\string\endinput}
   \close_out{Font~definitions}
}
\normalcc
%    \end{macrocode}
% 
% 
% Now we install the fonts.  First T1.  Note the scaling code (taken
% from PSNFSS packages).
%    \begin{macrocode}
\installfonts
\installfamily{T1}{fdg}{}
\installfont{fdgb8t}{fdgb8r,newlatin}{t1}{T1}{fdg}{b}{n}{
  <->\string\Dgm@@scale}
\installfont{fdgh8t}{fdgh8r,newlatin}{t1}{T1}{fdg}{h}{n}{
  <->\string\Dgm@@scale}
\installfont{fdgbl8t}{fdgbl8r,newlatin}{t1}{T1}{fdg}{b}{ol}{
  <->\string\Dgm@@scale}
\installfont{fdgbw8t}{fdgbw8r,newlatin}{t1}{T1}{fdg}{b}{it}{
  <->\string\Dgm@@scale}
\installfont{fdgbo8t}{fdgbo8r,newlatin}{t1}{T1}{fdg}{b}{sl}{
  <->\string\Dgm@@scale}
\installfont{fdgho8t}{fdgho8r,newlatin}{t1}{T1}{fdg}{h}{sl}{
  <->\string\Dgm@@scale}
\installfont{fdgb8tk}{fdgb8r,newlatin}{t1k}{T1}{fdg}{bk}{n}{
  <->\string\Dgm@@scale}
\installfont{fdgb8tq}{fdgb8r,newlatin}{t1q}{T1}{fdg}{bq}{n}{
  <->\string\Dgm@@scale}
\installfont{fdgb8tr}{fdgb8r,newlatin}{t1r}{T1}{fdg}{br}{n}{
  <->\string\Dgm@@scale}
\installfont{fdgb8ts}{fdgb8r,newlatin}{t1s}{T1}{fdg}{bs}{n}{
  <->\string\Dgm@@scale}
\installfont{fdgbc8t}{fdgb8r,newlatin}{t1c}{T1}{fdg}{b}{sc}{
  <->\string\Dgm@@scale}
\installfont{fdghc8t}{fdgh8r,newlatin}{t1c}{T1}{fdg}{h}{sc}{
  <->\string\Dgm@@scale}
\endinstallfonts
%    \end{macrocode}
% 
% And then TS1
%    \begin{macrocode}
\installfonts
\installfamily{TS1}{fdg}{}
\installfont{fdgb8c}{fdgb8r,textcomp}{ts1}{TS1}{fdg}{b}{n}{
  <->\string\Dgm@@scale}
\installfont{fdgh8c}{fdgh8r,textcomp}{ts1}{TS1}{fdg}{h}{n}{
  <->\string\Dgm@@scale}
\installfont{fdgbl8c}{fdgbl8r,textcomp}{ts1}{TS1}{fdg}{b}{ol}{
  <->\string\Dgm@@scale}
\installfont{fdgbw8c}{fdgbw8r,textcomp}{ts1}{TS1}{fdg}{b}{it}{
  <->\string\Dgm@@scale}
\installfont{fdgbo8c}{fdgbo8r,textcomp}{ts1}{TS1}{fdg}{b}{sl}{
  <->\string\Dgm@@scale}
\installfont{fdgho8c}{fdgho8r,textcomp}{ts1}{TS1}{fdg}{h}{sl}{
  <->\string\Dgm@@scale}
\installfont{fdgb8ck}{fdgb8r,textcomp}{ts1k}{TS1}{fdg}{bk}{n}{
  <->\string\Dgm@@scale}
\installfont{fdgb8cq}{fdgb8r,textcomp}{ts1q}{TS1}{fdg}{bq}{n}{
  <->\string\Dgm@@scale}
\installfont{fdgb8cr}{fdgb8r,textcomp}{ts1r}{TS1}{fdg}{br}{n}{
  <->\string\Dgm@@scale}
\installfont{fdgb8cs}{fdgb8r,textcomp}{ts1s}{TS1}{fdg}{bs}{n}{
  <->\string\Dgm@@scale}
\installfontas{fdgb8c}{TS1}{fdg}{b}{sc}{
  <->\string\Dgm@@scale}
\installfontas{fdgh8c}{TS1}{fdg}{h}{sc}{
  <->\string\Dgm@@scale}
\endinstallfonts
%    \end{macrocode}
% 
% And the end:
%    \begin{macrocode}
\endrecordtransforms
\bye
%</fdg-drv>
%    \end{macrocode}
% 
%\subsection{Letterspacing Driver}
%\label{sec:letterspace}
%
% This follows~\cite{Hoenig98:TeXUnbound}.  We need both |T1| and
% |TS1| files:
%    \begin{macrocode}
%<*t1k|ts1k|t1q|ts1q|t1r|ts1r|t1s|ts1s>
\relax
\encoding
%<t1k|ts1k>\resetint{letterspacing}{\int{kspread}}
%<t1q|ts1q>\resetint{letterspacing}{\int{qspread}}
%<t1r|ts1r>\resetint{letterspacing}{\int{rspread}}
%<t1s|ts1s>\resetint{letterspacing}{\int{sspread}}
\setcommand\gobblethree#1#2#3{}%
\let\ligature=\gobblethree
%<t1k|t1q|t1r|t1s>\inputetx{t1}
%<ts1k|ts1q|ts1r|ts1s>\inputetx{ts1}
\endencoding
%</t1k|ts1k|t1q|ts1q|t1r|ts1r|t1s|ts1s>
%    \end{macrocode}
% 
%
%
%\subsection{Fontmap Generation}
%\label{sec:fontmap}
%
% This is a standard procedure~\cite{fontinstallationguide}
%    \begin{macrocode}
%<*fdg-map>
\input finstmsc.sty
\resetstr{PSfontsuffix}{.pfb}
\adddriver{dvips}{fdg.map}
\input fdg-rec.tex
\donedrivers
\bye
%</fdg-map>
%    \end{macrocode}
%
%
%
%\subsection{Style File}
%\label{sec:style}
%
%
% The scaling code is from the |helvet| package:
%    \begin{macrocode}
%<*style>
\RequirePackage[T1]{fontenc}
\RequirePackage{textcomp}
\RequirePackage{keyval}
\define@key{Dogma}{scaled}[1]{%
  \def\Dgm@scale{#1}}
\def\ProcessOptionsWithKV#1{%
  \let\@tempc\relax
  \let\Dgm@tempa\@empty
  \ifx\@classoptionslist\relax\else
    \@for\CurrentOption:=\@classoptionslist\do{%
      \@ifundefined{KV@#1@\CurrentOption}%
      {}%
      {%
        \edef\Dgm@tempa{\Dgm@tempa,\CurrentOption,}%
        \@expandtwoargs\@removeelement\CurrentOption
          \@unusedoptionlist\@unusedoptionlist
      }%
    }%
  \fi
  \edef\Dgm@tempa{%
    \noexpand\setkeys{#1}{%
      \Dgm@tempa\@ptionlist{\@currname.\@currext}%
    }%
  }%
  \Dgm@tempa
  \let\CurrentOption\@empty
}
\ProcessOptionsWithKV{Dogma}
\AtEndOfPackage{%
  \let\@unprocessedoptions\relax
}
\DeclareTextFontCommand{\dogmabold}{%
  \fontfamily{fdg}\fontseries{b}\selectfont}
\DeclareTextFontCommand{\dogmablack}{%
  \fontfamily{fdg}\fontseries{h}\selectfont}
\DeclareTextFontCommand{\dogmaoutline}{%
  \fontfamily{fdg}\fontshape{ol}\fontseries{b}\selectfont}
\DeclareTextFontCommand{\dogmascript}{%
  \fontfamily{fdg}\fontshape{it}\selectfont}
%</style>
%    \end{macrocode}
%
%
%\Finale
%\clearpage
%
%\PrintChanges
%\clearpage
%\PrintIndex
%
\endinput