%D \module
%D   [       file=typo-itc,
%D        version=2011.10.08,
%D          title=\CONTEXT\ Typesetting Macros,
%D       subtitle=Italic Correction,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Typesetting Macros / Italics Corrections}

\unprotect

%D The brave might try:
%D
%D \starttyping
%D \definefontfeature[default][default][itlc=yes] % is now default
%D \setitaliccorrection
%D \stoptyping

\registerctxluafile{typo-itc}{autosuffix}

\installcorenamespace{italics}

\permanent\protected\def\typo_italic_set
  {\bitwiseflip\glyphoptions        \textcheckitalicglyphoptioncode
   \bitwiseflip\discretionaryoptions\textcheckitalicdiscoptioncode}

\permanent\protected\def\typo_italic_reset
  {\bitwiseflip\glyphoptions        -\textcheckitalicglyphoptioncode
   \bitwiseflip\discretionaryoptions-\textcheckitalicdiscoptioncode}

\letcsname\??italics\v!no    \endcsname\typo_italic_reset
\letcsname\??italics\v!reset \endcsname\typo_italic_reset
%letcsname\??italics\v!yes   \endcsname\typo_italic_set
%letcsname\??italics\v!big   \endcsname\typo_italic_set
%letcsname\??italics\v!medium\endcsname\typo_italic_set
%letcsname\??italics\v!small \endcsname\typo_italic_set

\permanent\tolerant\protected\def\setitaliccorrection[#1]%
  {\ifcsname\??italics#1\endcsname\lastnamedcs\else\typo_italic_set\fi}

\aliased\let\resetitaliccorrection\typo_italic_reset
\aliased\let\setupitaliccorrection\setitaliccorrection

\permanent\protected\def\italiccorrection
  {\ifbitwiseand\glyphoptions\textcheckitalicglyphoptioncode\else
     % This doesn't do anything due to the way we set up the callback ...
     % \normalitaliccorrection
     % ... so we do this instead:
     \forcedrightcorrection
   \fi}

\pushoverloadmode
    \aliased\let\/\italiccorrection % replaces the primitive
  % \aliased\let\explicititaliccorrection\italiccorrection % replaces the primitive
\popoverloadmode

% only for manuals ... obsolete

\permanent\protected\def\pushitaliccorrection{}% \typo_italic_reset
\permanent\protected\def\popitaliccorrection {}% \typo_italic_set

%D Correcting for weird shapes.

%D \starttyping
%D \showglyphs \showfontitalics \showfontkerns
%D
%D \setupbodyfont[bonum]
%D
%D \startTEXpage[offset=1ts,width=5em]
%D     \setupitaliccorrection[italic]
%D     \dontleavehmode
%D     \ruledhbox{\it\shapecorrection[both] f}\quad
%D     \ruledhbox{\it\shapecorrection[both]ff}
%D \stopTEXpage
%D \stoptyping

\installcorenamespace{shapecorrection}

\defcsname\??shapecorrection\v!left \endcsname{\groupedcommandcs\forcedleftcorrection\relax}
\defcsname\??shapecorrection\v!right\endcsname{\groupedcommandcs\relax               \forcedrightcorrection}
\defcsname\??shapecorrection\v!both \endcsname{\groupedcommandcs\forcedleftcorrection\forcedrightcorrection}
\defcsname\??shapecorrection        \endcsname{\groupedcommandcs\relax               \forcedrightcorrection}

\permanent\tolerant\protected\def\shapecorrection[#1]{\begincsname\??shapecorrection#1\endcsname}

\protect \endinput
