typo-krn.mkxl /size: 4014 b    last modification: 2023-12-21 09:44
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}{autosuffix}
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\permanent\protected\def\setcharacterkerning[#1]%
31  {\cdef\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\permanent\protected\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) \unknown\ this
53%D 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 then we always
60%D would get a command defined which is not beforehand a good idea.
61%D
62%D Here we need to keep the groupedcommand solution as it is used as modifier.
63
64\appendtoks
65  \frozen\instance\protected\edefcsname\currentcharacterkerning\endcsname
66    {\doifelsenextoptional
67       {\typo_kerning_apply_yes{\currentcharacterkerning}}%
68       {\typo_kerning_apply_nop{\currentcharacterkerning}}}%
69\to \everydefinecharacterkerning
70
71\protected\def\typo_kerning_apply_yes#1[#2]%
72  {\groupedcommand{\typo_kerning_apply_yes_indeed{#1}{#2}}\donothing}
73
74\protected\def\typo_kerning_apply_nop#1%
75  {\groupedcommand{\typo_kerning_apply_nop_indeed{#1}}\donothing}
76
77\def\typo_kerning_apply_yes_indeed#1#2%
78  {\cdef\currentcharacterkerning{#1}%
79   \setupcurrentcharacterkerning[\c!factor=#2]%
80   \typo_kerning_set}
81
82\def\typo_kerning_apply_nop_indeed#1%
83  {\cdef\currentcharacterkerning{#1}%
84   \typo_kerning_set}
85
86\definecharacterkerning [\v!kerncharacters] [\c!factor=.125]
87\definecharacterkerning [\v!letterspacing ] [\v!kerncharacters] [\c!features=letterspacing]
88
89%D \macros
90%D   {stretched}
91%D
92%D Stretching characters in a word is a sort of typographical murder. Nevertheless
93%D we support this manipulation for use in for instance titles.
94%D
95%D \starttyping
96%D \hbox to 5cm{\stretched{to the limit}}
97%D \stretched{to the limit}
98%D \stretched[width=10cm]{to the limit}
99%D \stoptyping
100%D
101%D \typebuffer
102%D
103%D or
104%D
105%D \startexample
106%D \getbuffer
107%D \stopexample
108%D
109%D \showsetup{stretched}
110%D
111%D This command replaces the old \MKII\ variant.
112
113\definecharacterkerning
114  [\v!stretched]
115  [\c!factor=\v!max,
116   \c!width=\availablehsize]
117
118\permanent\protected\def\setupstretched
119  {\setupcharacterkerning[\v!stretched]}
120
121\pushoverloadmode
122
123\enforced\permanent\tolerant\protected\def\stretched[#S#1]#:#2%
124  {\begingroup
125   \let\currentcharacterkerning\v!stretched
126   \ifparameter#1\or
127     \setupcurrentcharacterkerning[#1]%
128   \fi
129   \edef\p_width{\characterkerningparameter\c!width}%
130   \ifempty\p_width \else
131     \hbox to \p_width
132   \fi
133   \bgroup
134   \usecharacterkerningstyleandcolor\c!style\c!color
135   \useaddfontfeatureparameter\characterkerningparameter
136   \typo_kerning_set
137   #2%
138   \egroup
139   \endgroup}
140
141\popoverloadmode
142
143\protect \endinput
144