% Copyright 2014--2019 Michael Sharpe
% Based initially on Karl Berry's inconsolata.sty.
% You may freely use, modify and/or distribute this file.

\def\fileversion{1.12}
\def\filedate{2019/05/17}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zi4}[\filedate\space v\fileversion]
\message{`inconsolata-zi4' v\fileversion, \filedate\space Text macros for Inconsolata (msharpe)}

\RequirePackage{textcomp}
\RequirePackage{xkeyval}

\newcount\zifour@ocount
\newif\ifzifour@altzero
\newif\ifzifour@noupq
\newif\ifzifour@mono
\newif\ifzifour@hyphen
% hyphenation is inhibited by default, but word spacing is, by default
% variable. The option mono  makes word spacing mono also.
\def\zifour@sp{.5em}
\def\zifour@stretch{.25em}
\def\zifour@shrink{.167em}
\def\zifour@extrasp{0em}
\def\zifour@spn{.45em}
\def\zifour@stretchn{.225em}
\def\zifour@shrinkn{.15em}
\def\zifour@extraspn{0em}

% by default, change \tt to mean zi4.
\newcommand*{\zifour@default}{%
  \renewcommand*{\ttdefault}{zi4}}%

\newcommand\zifour@scaled{s*[1]}
%\define@key{zifour}{scaled}[1.0]{\def\zifour@scaled{s*[#1]}}
\DeclareOptionX{scaled}[1.0]{\renewcommand{\zifour@scaled}{s*[#1]}}
\DeclareOptionX{scale}[1.0]{\renewcommand{\zifour@scaled}{s*[#1]}}
%\DeclareOption*{%
%  \begingroup
%  \edef\x{\endgroup
%    \noexpand\setkeys{zifour}{\CurrentOption}}%
%  \x}
\def\zifour@hyph{\hyphenchar\font=\m@ne}
\DeclareOptionX{hyphenate}{%
	\def\zifour@hyph{}}

\DeclareOptionX{mono}{%
	\zifour@monotrue}

% option [nott] to avoid changing tt.
\DeclareOptionX{nott}{%
  \def\zifour@hyph{}\zifour@monofalse%
  \def\zifour@extrasp{0em}%
  \renewcommand*{\zifour@default}{%
  \renewcommand*{\rmdefault}{zi4}}%
}
% option [noupquote] to prevent loading upquote.
\DeclareOptionX{noupquote}{%
  \zifour@noupqtrue}%
  
% option var0---use unslashed zero (slashed is default)
\DeclareOptionX{var0}{%
  \zifour@altzerotrue\advance\zifour@ocount \tw@ %
}
\DeclareOptionX{varl}{%
  \advance\zifour@ocount \@ne %
}
\DeclareOptionX{varqu}{%
  \advance\zifour@ocount 4\relax %
}
\DeclareOptionX{narrow}{%
  \gdef\zifour@narrow{n} %
}
\DeclareOptionX{spacing}[.5em]{%
 \gdef\zifour@spx{#1}}
\DeclareOptionX{stretch}[.25em]{%
 \gdef\zifour@stretchx{#1}}
\DeclareOptionX{shrink}[.167em]{%
 \gdef\zifour@shrinkx{#1}}
\DeclareOptionX{extrasp}[.167em]{%
 \gdef\zifour@extraspx{#1}}

\ProcessOptionsX
\zifour@default

\ifzifour@mono%
\def\zifour@stretch{0em}
\def\zifour@shrink{0em}
\def\zifour@extrasp{.5em}
\def\zifour@stretchn{0em}
\def\zifour@shrinkn{0em}
\def\zifour@extraspn{.45em}
\fi
\ifdefined\zifour@narrow%
  \let\zifour@sp\zifour@spn
  \let\zifour@stretch\zifour@stretchn
  \let\zifour@shrink\zifour@shrinkn
  \let\zifour@extrasp\zifour@extraspn
\fi
% Allow values specified in options to override mono
\ifdefined\zifour@spx\let\zifour@sp\zifour@spx\fi
\ifdefined\zifour@stretchx\let\zifour@stretch\zifour@stretchx\fi
\ifdefined\zifour@shrinkx\let\zifour@shrink\zifour@shrinkx\fi
\ifdefined\zifour@extraspx\let\zifour@extrasp\zifour@extraspx\fi

%\ifzifour@hyphen%
%  \edef\zifour@hyph{\hyphenchar\font=45 }
%\else%
%  \edef\zifour@hyph{\hyphenchar\font=\m@ne}
%\fi
%\show\zifour@hyph

\edef\zifour@spc{%
	\fontdimen2\font=\zifour@sp%
	\fontdimen3\font=\zifour@stretch%
	\fontdimen4\font=\zifour@shrink%
	\fontdimen7\font=\zifour@extrasp%
	\zifour@hyph%
} % used to change default text spacing via fd files
%\show\zifour@spc
\edef\zifour@opt{\the\zifour@ocount}
\ifzifour@altzero 
  \advance\zifour@ocount -\tw@
\else
  \advance\zifour@ocount \tw@
\fi
\edef\zifour@altopt{\the\zifour@ocount}
% define an \altzero macro which flips to slashed, unslashed
\def\altzero{{\fontfamily{zi4}%
 \fontshape{scit}%
 \selectfont 0}}

 
\def\zifour@T@ne@nc{T1}
\def\zifour@OT@ne@nc{OT1}
\def\zifour@LY@ne@nc{LY1}
\def\zifour@QX@nc{QX}
\def\zifour@TQS{%
\UndeclareTextCommand{\textquotesingle}{\encodingdefault}
\DeclareTextSymbol{\textquotesingle}{TS1}{39}}

\ifzifour@noupq% do nothing
  % Try to correct for wrong slots for QX
  \ifx\encodingdefault\zifour@QX@nc
    \zifour@TQS
  \else
    \ifx\encodingdefault\zifour@LY@ne@nc
      \zifour@TQS
    \fi
  \fi     
\else
  \AtBeginDocument{%
  \ifx\encodingdefault\zifour@T@ne@nc % do nothing
  \else
    \ifx\encodingdefault\zifour@OT@ne@nc % do nothing
    \else
      \zifour@TQS
    \fi
  \fi
  \usepackage{upquote}}
\fi

\endinput
