%D \module
%D   [       file=core-gen,
%D        version=1995.10.10,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=General,
%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 Core Macros / General}

\unprotect

%D \macros
%D   {assigndimension,assignalfadimension}
%D
%D The following commands are used to process keyword based
%D dimension setters.
%D
%D \starttyping
%D \assigndimension
%D   {<value>|small|medium|big|-small|-medium|-big|none}
%D   {\dimension}
%D   {value small}
%D   {value medium}
%D   {value big}
%D \stoptyping
%D
%D The given keyword determines the result.

\installcorenamespace{dimensionnormal}

\setvalue{\??dimensionnormal \v!none  }#value#dimension#small#medium#big{#dimension\zeropoint}
\setvalue{\??dimensionnormal \empty   }#value#dimension#small#medium#big{#dimension\zeropoint}
\setvalue{\??dimensionnormal \v!small }#value#dimension#small#medium#big{#dimension=#small\relax}
\setvalue{\??dimensionnormal \v!medium}#value#dimension#small#medium#big{#dimension=#medium\relax}
\setvalue{\??dimensionnormal \v!big   }#value#dimension#small#medium#big{#dimension=#big\relax}
\setvalue{\??dimensionnormal-\v!small }#value#dimension#small#medium#big{#dimension=-#small\relax}
\setvalue{\??dimensionnormal-\v!medium}#value#dimension#small#medium#big{#dimension=-#medium\relax}
\setvalue{\??dimensionnormal-\v!big   }#value#dimension#small#medium#big{#dimension=-#big\relax}
\setvalue{\??dimensionnormal\s!unknown}#value#dimension#small#medium#big{#dimension=#value\relax}

\unexpanded\def\assigndimension#value%
  {\csname\??dimensionnormal\ifcsname\??dimensionnormal#value\endcsname#value\else\s!unknown\fi\endcsname{#value}}

%D The next variant assigns to a macro instead of a dimension.
%D
%D \starttyping
%D \assignalfadimension
%D   {<value>|small|medium|big|none}
%D   {\macro}
%D   {value small}
%D   {value medium}
%D   {value big}
%D \stoptyping
%D
%D This one is used for factors.

\installcorenamespace{dimensionalfa}

\setvalue{\??dimensionalfa\v!none   }#value#macro#small#medium#big{\let #macro\!!zerocount}
\setvalue{\??dimensionalfa\v!small  }#value#macro#small#medium#big{\edef#macro{#small}}
\setvalue{\??dimensionalfa\v!medium }#value#macro#small#medium#big{\edef#macro{#medium}}
\setvalue{\??dimensionalfa\v!big    }#value#macro#small#medium#big{\edef#macro{#big}}
\setvalue{\??dimensionalfa\s!unknown}#value#macro#small#medium#big{\edef#macro{#value}}

\unexpanded\def\assignalfadimension#value%
  {\csname\??dimensionalfa\ifcsname\??dimensionalfa#value\endcsname#value\else\s!unknown\fi\endcsname{#value}}

%D \macros
%D   {assignvalue}
%D
%D A variant that does not assume dimenions ios the following:
%D
%D \starttyping
%D \assignvalue
%D   {<value>|small|medium|big}
%D   {\macro}
%D   {value small}
%D   {value medium}
%D   {value big}
%D \stoptyping

\installcorenamespace{dimensionvalue}

\setvalue{\??dimensionvalue\v!small  }#value#macro#small#medium#big{\edef#macro{#small}}
\setvalue{\??dimensionvalue\v!medium }#value#macro#small#medium#big{\edef#macro{#medium}}
\setvalue{\??dimensionvalue\v!big    }#value#macro#small#medium#big{\edef#macro{#big}}
\setvalue{\??dimensionvalue\s!unknown}#value#macro#small#medium#big{\edef#macro{#value}}

\unexpanded\def\assignvalue#value%
  {\csname\??dimensionvalue\ifcsname\??dimensionvalue#value\endcsname#value\else\s!unknown\fi\endcsname{#value}}

%D \macros
%D   {assignwidth}
%D
%D Een breedte van een opgegeven tekst kan worden berekend en
%D toegekend aan een \DIMENSION\ met:
%D
%D \starttyping
%D \assignwidth
%D   {<value>|fit|broad}
%D   {\dimension}
%D   {text}
%D   {extra}
%D \stoptyping

\installcorenamespace{dimensionwidth}

\newbox\b_assign_width

\setvalue{\??dimensionwidth          }#value#dimension#content#extra{\setbox\b_assign_width\hbox{#content}#dimension\wd\b_assign_width
                                                                     \setbox\b_assign_width\emptybox}
\setvalue{\??dimensionwidth\v!fit    }#value#dimension#content#extra{\setbox\b_assign_width\hbox{#content}#dimension\wd\b_assign_width
                                                                     \setbox\b_assign_width\emptybox}
\setvalue{\??dimensionwidth\v!broad  }#value#dimension#content#extra{\setbox\b_assign_width\hbox{#content}#dimension\dimexpr\wd\b_assign_width+#extra\relax
                                                                     \setbox\b_assign_width\emptybox}
\setvalue{\??dimensionwidth\s!unknown}#value#dimension#content#extra{#dimension=#value\relax}

\unexpanded\def\assignwidth#value%
  {\csname\??dimensionwidth\ifcsname\??dimensionwidth#value\endcsname#value\else\s!unknown\fi\endcsname{#value}}

\protect \endinput
