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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
%D \module
%D [ file=font-sty,
%D version=2011.01.13, % (copied fron font-ini)
%D title=\CONTEXT\ Font Macros,
%D subtitle=features,
%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 Font Macros / Features}
\unprotect
%D Feature management.
%D
%D \starttyping
%D \definefontfeature[smallcaps][smcp=yes,script=latn]
%D \definefontfeature[smallcaps][SmallCapitals=yes,script=latn]
%D \definefontfeature[smallcaps][Small Capitals=yes,script=latn]
%D \definefontfeature[smallcaps][small capitals=yes,script=latn]
%D \definefontfeature[smallcaps][smallcapitals=yes,script=latn]
%D
%D \definedfont[cambria*smallcaps] test
%D
%D \starttext
%D \definefontfeature[basekerned][default][mode=base]
%D \definefontfeature[nodekerned][default][mode=node]
%D \definefontfeature[nonekerned][default][mode=base,kern=no]
%D \setupcolors[state=start]
%D \startoverlay
%D {\vbox{\red \definedfont[Serif*nonekerned at 12pt]\input tufte }}
%D {\vbox{\blue \definedfont[Serif*basekerned at 12pt]\input tufte }}
%D {\vbox{\green\definedfont[Serif*nodekerned at 12pt]\input tufte }}
%D \stopoverlay
%D \stoptext
%D
%D \enabletrackers[otf.kerns]
%D
%D \definefontfeature[withkern][default][mode=node]
%D \definefontfeature[nokern] [default][mode=node,kern=no]
%D \definefontfeature[single] [default][mode=node,cpsp=yes]
%D \definefontfeature[simple] [default][mode=node,cpsp=yes,kern=no]
%D
%D {\definedfont[Serif*default] [FGFGFGFGFGFGFGFGFGFGFGFGFG ABCDEFGHIJKLMNOPQRSTUVWXYZ] \par}
%D {\definedfont[Serif*nokern] [FGFGFGFGFGFGFGFGFGFGFGFGFG ABCDEFGHIJKLMNOPQRSTUVWXYZ] \par}
%D {\definedfont[Serif*single] [FGFGFGFGFGFGFGFGFGFGFGFGFG ABCDEFGHIJKLMNOPQRSTUVWXYZ] \par}
%D {\definedfont[Serif*simple] [FGFGFGFGFGFGFGFGFGFGFGFGFG ABCDEFGHIJKLMNOPQRSTUVWXYZ] \par}
%D \stoptyping
% \definefontfeature[slanted] [default][slant=.25]
% \definefontfeature[stretched][default][stretch=2]
%
% \start \definedfont[SerifBold*slanted at 20pt] \ruledhbox{Test!} \stop
% \start \definedfont[SerifBold*stretched at 20pt] \ruledhbox{Test!} \stop
%
% \definefontfeature[default] [liga=yes,texligatures=yes,texquotes=yes]
% \definefontfeature[default-caps][liga=yes,texligatures=yes,texquotes=yes,smcp=yes,script=latn]
%
% \starttypescript [serif] [palatino-nova-regular] [name]
% \definefontsynonym[Serif] [palatinonova-regular][features=default]
% \definefontsynonym[SerifCaps][palatinonova-regular][features=default-caps] % also sets Serif
% \stoptypescript
%
% \starttypescript [serif] [palatino-nova-regular] [name]
% \definefontsynonym[Serif] [palatinonova-regular*default]
% \definefontsynonym[SerifCaps] [palatinonova-regular*default-caps]
% \stoptypescript
%
% \definetypeface[mainface][rm][serif][palatino-nova-regular][default] \setupbodyfont[mainface]
%
% \starttext
% ``Test'' -- --- ff fi fl \sc ``Test'' -- --- ff fi fl
% \stoptext
%
% \definefontfeature
% [default-base]
% [script=latn,language=dflt,liga=yes,kern=yes,tlig=yes,trep=yes]
% \definefontfeature
% [default-node]
% [script=latn,language=dflt,liga=yes,kern=yes,tlig=yes,trep=yes,mode=node]
% \definefontfeature
% [default-none]
% [script=latn,language=dflt,liga=yes,kern=no, tlig=yes,trep=yes]
%
% \startoverlay
% {\vtop{\color[red] {\font\test=name:lmroman12regular*default-node \test \input ward \input zapf \input linden }}}
% {\vtop{\color[green]{\font\test=name:lmroman12regular*default-base \test \input ward \input zapf \input linden }}}
% {\vtop{\color[blue] {\font\test=name:lmroman12regular*default-none \test \input ward \input zapf \input linden }}}
% \stopoverlay
%
% \blank
%
% \startoverlay
% {\vtop{\color[red] {\font\test=name:texgyrepagella*default-node \test \input ward \input zapf \input linden }}}
% {\vtop{\color[green]{\font\test=name:texgyrepagella*default-base \test \input ward \input zapf \input linden }}}
% {\vtop{\color[blue] {\font\test=name:texgyrepagella*default-none \test \input ward \input zapf \input linden }}}
% \stopoverlay
%
% \blank
%
% \startoverlay
% {\vtop{\color[red] {\font\test=name:palatinonovaregular*default-node \test \input ward \input zapf \input linden }}}
% {\vtop{\color[green]{\font\test=name:palatinonovaregular*default-base \test \input ward \input zapf \input linden }}}
% {\vtop{\color[blue] {\font\test=name:palatinonovaregular*default-none \test \input ward \input zapf \input linden }}}
% \stopoverlay
%
% \startoverlay
% {\vtop{\color[red] {\font\test=name:OfficinaSerifBookITC*default-node \test \input ward \input zapf \input linden }}}
% {\vtop{\color[green]{\font\test=name:OfficinaSerifBookITC*default-base \test \input ward \input zapf \input linden }}}
% {\vtop{\color[blue] {\font\test=name:OfficinaSerifBookITC*default-none \test \input ward \input zapf \input linden }}}
% \stopoverlay
%
% \definefontfeature[superdefault][default][compose=yes]
%
% {\font\oeps=name:lmroman10regular*default at 30pt \oeps test \char7683}
% {\font\oeps=name:lmroman10regular*superdefault at 30pt \oeps test \char7683}
\unexpanded\def\definefontfeature
{\dotripleargument\font_basics_define_font_feature}
\def\font_basics_define_font_feature[#featureset][#parent][#settings]%
{\clf_definefontfeature{#featureset}{#parent}{#settings}}
\unexpanded\def\fontfeatureslist
{\dodoubleargument\font_basics_features_list}
\def\font_basics_features_list[#name][#separator]% todo: arg voor type
{\clf_featurelist{#name}{\detokenize{#separator}}}
\attribute\zerocount\zerocount % first in list, so fast match
% beware: these are global features on top of existing font features
\let\currentfeature \s!current
\let\m_font_feature_list \s!current
\let\m_font_feature_asked\empty
\newconstant\c_font_feature_state
% hashing at this end is slower
\unexpanded\def\addfeature {\doifelsenextoptionalcs\font_feature_add_yes \font_feature_add_nop }
\unexpanded\def\subtractfeature {\doifelsenextoptionalcs\font_feature_subtract_yes \font_feature_subtract_nop }
\unexpanded\def\replacefeature {\doifelsenextoptionalcs\font_feature_replace_yes \font_feature_replace_nop }
\unexpanded\def\resetandaddfeature{\doifelsenextoptionalcs\font_feature_reset_add_yes\font_feature_reset_add_nop}
\unexpanded\def\feature {\doifelsenextoptionalcs\font_feature_yes \font_feature_nop }
\unexpanded\def\font_feature_add_yes [#feature]{\edef\m_font_feature_asked{#feature}\font_feature_add}
\unexpanded\def\font_feature_add_nop #feature{\edef\m_font_feature_asked{#feature}\font_feature_add}
\unexpanded\def\font_feature_subtract_yes [#feature]{\edef\m_font_feature_asked{#feature}\font_feature_subtract}
\unexpanded\def\font_feature_subtract_nop #feature{\edef\m_font_feature_asked{#feature}\font_feature_subtract}
\unexpanded\def\font_feature_replace_yes [#feature]{\edef\m_font_feature_asked{#feature}\font_feature_replace}
\unexpanded\def\font_feature_replace_nop #feature{\edef\m_font_feature_asked{#feature}\font_feature_replace}
\unexpanded\def\font_feature_reset_add_yes[#feature]{\edef\m_font_feature_asked{#feature}\font_feature_reset_add}
\unexpanded\def\font_feature_reset_add_nop #feature{\edef\m_font_feature_asked{#feature}\font_feature_reset_add}
\let\doaddfeature \font_feature_add_nop % low level faster ones
\let\dosubtractfeature \font_feature_subtract_nop
\let\doreplacefeature \font_feature_replace_nop
\let\doresetandaddfeature\font_feature_reset_add_nop
\unexpanded\def\font_feature_add
{\ifnum\c_font_feature_state=\plusone
\ifx\m_font_feature_asked\currentfeature\else
\font_feature_add_indeed
\fi
\else
\font_feature_add_indeed
\fi}
\unexpanded\def\font_feature_add_indeed
{\clf_addfeature{\m_font_feature_list}{\m_font_feature_asked}%
\edef\m_font_feature_list{\m_font_feature_list+\m_font_feature_asked}% also + at the lua end
\c_font_feature_state\plusone
\let\currentfeature\m_font_feature_asked}
\unexpanded\def\font_feature_subtract
{\ifnum\c_font_feature_state=\minusone
\ifx\m_font_feature_asked\currentfeature\else
\font_feature_subtract_indeed
\fi
\else
\font_feature_subtract_indeed
\fi}
\unexpanded\def\font_feature_subtract_indeed
{\clf_subtractfeature{\m_font_feature_list}{\m_font_feature_asked}%
\edef\m_font_feature_list{\m_font_feature_list-\m_font_feature_asked}% also - at the lua end
\c_font_feature_state\minusone
\let\currentfeature\m_font_feature_asked}
\unexpanded\def\font_feature_replace
{\ifnum\c_font_feature_state=\zerocount
\ifx\m_font_feature_asked\currentfeature\else
\font_feature_replace_indeed
\fi
\else
\font_feature_replace_indeed
\fi}
\unexpanded\def\font_feature_replace_indeed
{\clf_replacefeature{\m_font_feature_list}{\m_font_feature_asked}%
\edef\m_font_feature_list{\m_font_feature_list=\m_font_feature_asked}% also = at the lua end
\c_font_feature_state\zerocount
\let\currentfeature\m_font_feature_asked}
\unexpanded\def\resetfeature
{\ifx\currentfeature\s!current \else
\font_feature_reset_indeed
\fi}
\unexpanded\def\font_feature_reset_indeed
{\let\m_font_feature_asked\empty
\let\currentfeature \s!current
\let\m_font_feature_list \s!current
\clf_resetfeature}
\unexpanded\def\revivefeature
{\ifx\currentfeature\s!current \else
\font_feature_revive_indeed
\fi}
\unexpanded\def\font_feature_revive_indeed
{\clf_revivefeature{\m_font_feature_list}}
\unexpanded\def\font_feature_reset_add
{\ifnum\c_font_feature_state=\plusone
\ifx\m_font_feature_asked\currentfeature\else
\font_feature_reset_add_indeed
\fi
\else
\font_feature_reset_add_indeed
\fi}
\unexpanded\def\font_feature_reset_add_indeed
{\clf_addfeature{\s!current}{\m_font_feature_asked}%
\edef\m_font_feature_list{\s!current+\m_font_feature_asked}% also + at the lua end
\c_font_feature_state\plusone
\let\currentfeature\m_font_feature_asked}
\installcorenamespace{featureyes}
\installcorenamespace{featurenop}
\unexpanded\def\font_feature_yes[#method]{\csname\??featureyes\ifcsname\??featureyes#1\endcsname#1\else\s!unknown\fi\endcsname}
\unexpanded\def\font_feature_nop #method{\csname\??featurenop\ifcsname\??featurenop#1\endcsname#1\else\s!unknown\fi\endcsname}
\letvalue{\??featureyes +}\addfeature
\letvalue{\??featurenop +}\addfeature
\letvalue{\??featureyes -}\subtractfeature
\letvalue{\??featurenop -}\subtractfeature
\letvalue{\??featureyes =}\replacefeature
\letvalue{\??featurenop =}\replacefeature
\letvalue{\??featureyes !}\resetandaddfeature
\letvalue{\??featurenop !}\resetandaddfeature
\letvalue{\??featureyes >}\revivefeature
\letvalue{\??featurenop >}\revivefeature
\letvalue{\??featureyes <}\resetfeature
\letvalue{\??featurenop <}\resetfeature
\letvalue{\??featureyes\v!more }\addfeature % add set to previous set and combine with font set
\letvalue{\??featurenop\v!more }\addfeature
\letvalue{\??featureyes\v!less }\subtractfeature % subtract set from previous set and combine with font set
\letvalue{\??featurenop\v!less }\subtractfeature
\letvalue{\??featureyes\v!new }\replacefeature % replace font set
\letvalue{\??featurenop\v!new }\replacefeature
\letvalue{\??featureyes\v!reset }\resetfeature % forget sets and revert to font set
\letvalue{\??featurenop\v!reset }\resetfeature
\letvalue{\??featureyes\v!default}\revivefeature % make sure the current set is used on top of the font set
\letvalue{\??featurenop\v!default}\revivefeature
\letvalue{\??featureyes\v!old }\revivefeature
\letvalue{\??featurenop\v!old }\revivefeature
\letvalue{\??featureyes\v!local }\resetandaddfeature
\letvalue{\??featurenop\v!local }\resetandaddfeature
\letvalue{\??featureyes\s!unknown}\empty
\letvalue{\??featurenop\s!unknown}\empty
% just for old times sake:
\unexpanded\def\featureattribute#feature%
{\clf_featureattribute{#feature}}
\unexpanded\def\setfontfeature#feature%
{\edef\currentfeature{#feature}%
\let\m_font_feature_list\currentfeature
\clf_setfontfeature{\currentfeature}}
\let\resetfontfeature\resetfeature
% these are obsolete (don't use them any longer)
\let\addfontfeaturetoset \font_feature_add_nop
\let\subtractfontfeaturefromset \font_feature_subtract_nop
\let\addfontfeaturetofont \font_feature_add_nop
\let\subtractfontfeaturefromfont\font_feature_subtract_nop
\let\setff\setfontfeature
\let\addfs\addfontfeaturetoset
\let\subfs\subtractfontfeaturefromset
\let\addff\addfontfeaturetofont
\let\subff\subtractfontfeaturefromfont
%D \macros
%D {os}
%D
%D In good old \TEX, the old style numerals were often taken
%D from the math fonts. No longer.
\definefontfeature
[just-os]
[mode=node,onum=yes]
%unexpanded\def\sc{\setfontfeature{smallcaps}}
\unexpanded\def\os{\setfontfeature{just-os}}
% \doifelsecurrentfonthasfeature{smcp}{YES}{NO}
% \doifelsecurrentfonthasfeature{crap}{YES}{NO}
% \doifelsecurrentfonthasfeature{kern}{YES}{NO}
\def\doifelsecurrentfonthasfeature#feature%
{\clf_doifelsecurrentfonthasfeature{#feature}}
\let\doifcurrentfonthasfeatureelse\doifelsecurrentfonthasfeature
% new:
\clf_registerlanguagefeatures
% also new
\unexpanded\def\useaddfontfeatureparameter#1% faster local variant
{\edef\m_font_feature_asked{#1\c!features}%
\ifx\m_font_feature_asked\empty\else
\font_feature_add
\fi}
\protect \endinput
|