typo-krn.mkiv /size: 4715 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=typo-krn,
3%D        version=2009.03.27, % code moved from core-spa.mkiv
4%D          title=\CONTEXT\ Typesetting Macros,
5%D       subtitle=Spacing,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Typesetting Macros / Kerning}
15
16\unprotect
17
18\registerctxluafile{typo-krn}{}
19
20\definesystemattribute[kern][public]
21
22% more
23%
24% {\setcharacterkerning[extrakerning]\input davis\relax}
25
26\installcorenamespace{characterkerning}
27
28\installcommandhandler \??characterkerning {characterkerning} \??characterkerning
29
30\unexpanded\def\setcharacterkerning[#1]%
31  {\edef\currentcharacterkerning{#1}%
32   \ifx\currentcharacterkerning\s!reset
33     \resetcharacterkerning
34   \else
35     \typo_kerning_set
36   \fi}
37
38\def\typo_kerning_set
39  {\usecharacterkerningstyleandcolor\c!style\c!color % goodie, maybe also strut
40   \useaddfontfeatureparameter\characterkerningparameter
41   \clf_setcharacterkerning{\characterkerningparameter\c!factor}}
42
43\unexpanded\def\resetcharacterkerning % fast one
44  {\c_attr_kern\attributeunsetvalue}
45
46\appendtoks
47    \resetcharacterkerning
48\to \everyresettypesetting
49
50\definecharacterkerning [extrakerning] [\c!factor=.125] % used in manuals
51
52%D Added after discussion on list (posted by WS, adapted abit by HH)
53%D \unknown\ this needs to be interfaced (\type {\v!kerncharacters}).
54%D
55%D \starttyping
56%D \setuphead[section][style=\sca,textstyle={\kerncharacters[.5]}] \section{Section}
57%D \stoptyping
58%D
59%D We could combine this with the previous definition command but
60%D then we always would get a command defined which is not beforehand
61%D a good idea.
62
63% Here we need to keep the groupedcommand solution as it is
64% used as modifier.
65
66% \definecharacterkerning [\v!kerncharacters] [\c!factor=.125]
67% \definecharacterkerning [\v!letterspacing ] [\v!kerncharacters] [\c!features=letterspacing]
68%
69% \unexpanded\def\kerncharacters
70%   {\doifnextoptionalcselse\typo_kerning_apply_yes\typo_kerning_apply_nop}
71%
72% \def\typo_kerning_apply_yes[#1]%
73%   {\groupedcommand{\typo_kerning_apply_yes_indeed{#1}}\donothing}
74%
75% \def\typo_kerning_apply_nop
76%   {\groupedcommand\typo_kerning_apply_nop_indeed\donothing}
77%
78% \def\typo_kerning_apply_yes_indeed#1%
79%   {\let\currentcharacterkerning\v!kerncharacters
80%    \setupcurrentcharacterkerning[\c!factor=#1]%
81%    \typo_kerning_set}
82%
83% \def\typo_kerning_apply_nop_indeed
84%   {\let\currentcharacterkerning\v!kerncharacters
85%    \typo_kerning_set}
86
87\appendtoks
88  \setuevalue{\currentcharacterkerning}%
89    {\doifelsenextoptional
90       {\typo_kerning_apply_yes{\currentcharacterkerning}}%
91       {\typo_kerning_apply_nop{\currentcharacterkerning}}}%
92\to \everydefinecharacterkerning
93
94\unexpanded\def\typo_kerning_apply_yes#1[#2]%
95  {\groupedcommand{\typo_kerning_apply_yes_indeed{#1}{#2}}\donothing}
96
97\unexpanded\def\typo_kerning_apply_nop#1%
98  {\groupedcommand{\typo_kerning_apply_nop_indeed{#1}}\donothing}
99
100\def\typo_kerning_apply_yes_indeed#1#2%
101  {\edef\currentcharacterkerning{#1}%
102   \setupcurrentcharacterkerning[\c!factor=#2]%
103   \typo_kerning_set}
104
105\def\typo_kerning_apply_nop_indeed#1%
106  {\edef\currentcharacterkerning{#1}%
107   \typo_kerning_set}
108
109\definecharacterkerning [\v!kerncharacters] [\c!factor=.125]
110\definecharacterkerning [\v!letterspacing ] [\v!kerncharacters] [\c!features=letterspacing]
111
112%D \macros
113%D   {stretched}
114%D
115%D Stretching characters in a word is a sort of typographical
116%D murder. Nevertheless we support this manipulation for use in
117%D for instance titles.
118%D
119%D \starttyping
120%D \hbox to 5cm{\stretched{to the limit}}
121%D \stretched{to the limit}
122%D \stretched[width=10cm]{to the limit}
123%D \stoptyping
124%D
125%D \typebuffer
126%D
127%D or
128%D
129%D \startexample
130%D \getbuffer
131%D \stopexample
132%D
133%D \showsetup{stretched}
134%D
135%D This command replaces the old \MKII\ variant.
136
137\definecharacterkerning
138  [\v!stretched]
139  [\c!factor=\v!max,
140   \c!width=\availablehsize]
141
142\unexpanded\def\setupstretched
143  {\setupcharacterkerning[\v!stretched]}
144
145\unexpanded\def\stretched
146  {\dosingleempty\typo_kerning_stretched}
147
148\unexpanded\def\typo_kerning_stretched[#1]#2%
149  {\begingroup
150   \let\currentcharacterkerning\v!stretched
151   \iffirstargument
152     \setupcurrentcharacterkerning[#1]%
153   \fi
154   \edef\p_width{\characterkerningparameter\c!width}%
155   \ifx\p_width\empty \else
156     \hbox to \p_width
157   \fi
158   \bgroup
159   \usecharacterkerningstyleandcolor\c!style\c!color
160   \useaddfontfeatureparameter\characterkerningparameter
161   \typo_kerning_set
162   #2%
163   \egroup
164   \endgroup}
165
166\protect \endinput
167