summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/typo-krn.mkiv
blob: 6d6126542bfda297b1f9749295c0e73a44155827 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
%D \module
%D   [       file=typo-krn,
%D        version=2009.03.27, % code moved from core-spa.mkiv
%D          title=\CONTEXT\ Typesetting Macros,
%D       subtitle=Spacing,
%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 / Kerning}

\unprotect

\registerctxluafile{typo-krn}{1.001}

\definesystemattribute[kern][public]

% more
%
% {\setcharacterkerning[extrakerning]\input davis\relax}

\installcorenamespace{characterkerning}

\installcommandhandler \??characterkerning {characterkerning} \??characterkerning

\unexpanded\def\setcharacterkerning[#1]%
  {\edef\currentcharacterkerning{#1}%
   \ifx\currentcharacterkerning\s!reset
     \resetcharacterkerning
   \else
     \typo_kerning_set
   \fi}

\def\typo_kerning_set
  {\usecharacterkerningstyleandcolor\c!style\c!color % goodie, maybe also strut
   \useaddfontfeatureparameter\characterkerningparameter
   \clf_setcharacterkerning{\characterkerningparameter\c!factor}}

\unexpanded\def\resetcharacterkerning % fast one
  {\attribute\kernattribute\attributeunsetvalue}

\appendtoks
    \resetcharacterkerning
\to \everyresettypesetting

\definecharacterkerning [extrakerning] [\c!factor=.125] % used in manuals

%D Added after discussion on list (posted by WS, adapted abit by HH)
%D \unknown\ this needs to be interfaced (\type {\v!kerncharacters}).
%D
%D \starttyping
%D \setuphead[section][style=\sca,textstyle={\kerncharacters[.5]}] \section{Section}
%D \stoptyping
%D
%D We could combine this with the previous definition command but
%D then we always would get a command defined which is not beforehand
%D a good idea.

% Here we need to keep the groupedcommand solution as it is
% used as modifier.

% \definecharacterkerning [\v!kerncharacters] [\c!factor=.125]
% \definecharacterkerning [\v!letterspacing ] [\v!kerncharacters] [\c!features=letterspacing]
%
% \unexpanded\def\kerncharacters
%   {\doifnextoptionalcselse\typo_kerning_apply_yes\typo_kerning_apply_nop}
%
% \def\typo_kerning_apply_yes[#1]%
%   {\groupedcommand{\typo_kerning_apply_yes_indeed{#1}}\donothing}
%
% \def\typo_kerning_apply_nop
%   {\groupedcommand\typo_kerning_apply_nop_indeed\donothing}
%
% \def\typo_kerning_apply_yes_indeed#1%
%   {\let\currentcharacterkerning\v!kerncharacters
%    \setupcurrentcharacterkerning[\c!factor=#1]%
%    \typo_kerning_set}
%
% \def\typo_kerning_apply_nop_indeed
%   {\let\currentcharacterkerning\v!kerncharacters
%    \typo_kerning_set}

\appendtoks
  \setuevalue{\currentcharacterkerning}%
    {\doifelsenextoptional
       {\typo_kerning_apply_yes{\currentcharacterkerning}}%
       {\typo_kerning_apply_nop{\currentcharacterkerning}}}%
\to \everydefinecharacterkerning

\unexpanded\def\typo_kerning_apply_yes#1[#2]%
  {\groupedcommand{\typo_kerning_apply_yes_indeed{#1}{#2}}\donothing}

\unexpanded\def\typo_kerning_apply_nop#1%
  {\groupedcommand{\typo_kerning_apply_nop_indeed{#1}}\donothing}

\def\typo_kerning_apply_yes_indeed#1#2%
  {\edef\currentcharacterkerning{#1}%
   \setupcurrentcharacterkerning[\c!factor=#2]%
   \typo_kerning_set}

\def\typo_kerning_apply_nop_indeed#1%
  {\edef\currentcharacterkerning{#1}%
   \typo_kerning_set}

\definecharacterkerning [\v!kerncharacters] [\c!factor=.125]
\definecharacterkerning [\v!letterspacing ] [\v!kerncharacters] [\c!features=letterspacing]

%D \macros
%D   {stretched}
%D
%D Stretching characters in a word is a sort of typographical
%D murder. Nevertheless we support this manipulation for use in
%D for instance titles.
%D
%D \starttyping
%D \hbox to 5cm{\stretched{to the limit}}
%D \stretched{to the limit}
%D \stretched[width=10cm]{to the limit}
%D \stoptyping
%D
%D \typebuffer
%D
%D or
%D
%D \startexample
%D \getbuffer
%D \stopexample
%D
%D \showsetup{stretched}
%D
%D This command replaces the old \MKII\ variant.

\definecharacterkerning
  [\v!stretched]
  [\c!factor=\v!max,
   \c!width=\availablehsize]

\unexpanded\def\setupstretched
  {\setupcharacterkerning[\v!stretched]}

\unexpanded\def\stretched
  {\dosingleempty\typo_kerning_stretched}

\unexpanded\def\typo_kerning_stretched[#1]#2%
  {\begingroup
   \let\currentcharacterkerning\v!stretched
   \iffirstargument
     \setupcurrentcharacterkerning[#1]%
   \fi
   \edef\p_width{\characterkerningparameter\c!width}%
   \ifx\p_width\empty \else
     \hbox to \p_width
   \fi
   \bgroup
   \usecharacterkerningstyleandcolor\c!style\c!color
   \useaddfontfeatureparameter\characterkerningparameter
   \typo_kerning_set
   #2%
   \egroup
   \endgroup}

\protect \endinput