1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus
{
loading
}{
ConTeXt
Font
Macros
Styles
}
15
16\unprotect
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\installcorenamespace
{
alternativestyles
}
45\installcorenamespace
{
alternativestyle
}
46
47\installsetuponlycommandhandler
\??alternativestyles
{
alternativestyles
}
48
49\setnewconstant
\c_font_current_alternative_style_index
\plusone
50
51\unexpanded
\def
\definealternativestyle
52 {
\dotripleempty
\font_basics_define_alternative_style
}
53
54\def
\font_basics_define_alternative_style
[#
commands
][#
variantone
][#
varianttwo
]
55 {
\processcommalist
[#
commands
]
{
\font_basics_define_alternative_style_indeed
{
#
variantone
}{
#
varianttwo
}}}
56
57\let
\definestyle\definealternativestyle
58
59\newconstant
\c_fonts_basics_alternative_style_method
60
61\def
\font_basics_define_alternative_style_indeed
#
variantone
#
varianttwo
#
command
62 {
\setuvalue
{
\??alternativestyle
#
command
}{
\font_helpers_apply_alternative_style
{
#
variantone
}{
#
varianttwo
}}
63 \ifcsname
#
command
\endcsname
64
65 \else\ifnum
\c_fonts_basics_alternative_style_method
=
\plusone
66 \ifthirdargument
67 \setuevalue
{
#
command
}{
\triggergroupedcommandcs
\begincsname
\??alternativestyle
#
command
\endcsname
}
68 \else
69 \setuvalue
{
#
command
}{
\triggergroupedcommand
{
#
variantone
}}
70 \fi
71 \else
72 \setuvalue
{
#
command
}{
\triggergroupedcommand
{
#
variantone
}}
73 \fi\fi
}
74
75\def
\font_helpers_apply_alternative_style
76 {
\ifcase
\c_font_current_alternative_style_index
77 \expandafter
\gobbletwoarguments
78 \or
79 \expandafter
\firstoftwoarguments
80 \or
81 \expandafter
\secondoftwoarguments
82 \else
83 \expandafter
\firstoftwoarguments
84 \fi
}
85
86\def
\applyalternativestyle
#
name
87 {
\begincsname
\??alternativestyle
#
name
\endcsname
}
88
89\appendtoks
90 \doifelse
{
\alternativestylesparameter
\c!method
}
\v!auto
91 {
\c_fonts_basics_alternative_style_method
\plusone
}
92 {
\c_fonts_basics_alternative_style_method
\zerocount
}
93\to
\everysetupalternativestyles
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\let
\m_current_convert_font
\empty
147\let
\m_current_convert_font_dt
\empty
148
149\unexpanded
\def
\doconvertfont
#
specification
150 {
\edef
\m_current_convert_font
{
#
specification
}
151 \ifx
\m_current_convert_font
\empty
152
153 \else
154 \expandafter
\font_helpers_do_convert_font
155 \fi
}
156
157\def
\font_helpers_do_convert_font
158 {
\edef
\m_current_convert_font_dt
{
\detokenize\expandafter
{
\m_current_convert_font
}}
159 \ifcsname
\??alternativestyle
\m_current_convert_font_dt
\endcsname
160 \expandafter\lastnamedcs
161 \else\ifcsname
\m_current_convert_font_dt
\endcsname
162 \doubleexpandafter
\lastnamedcs
163 \else
164 \doubleexpandafter
\m_current_convert_font
165 \fi\fi
}
166
167
168
169
170
171
172
173
174
175
176
177\unexpanded
\def
\dontconvertfont
{
\c_font_current_alternative_style_index
\plustwo
}
178\unexpanded
\def
\redoconvertfont
{
\c_font_current_alternative_style_index
\plusone
}
179
180
181
182\setfalse
\fontattributeisset
183
184\unexpanded
\def
\dousestyleparameter
#
value
185 {
\edef
\currentstyleparameter
{
#
value
}
186 \ifx
\currentstyleparameter
\empty
\else
187 \expandafter
\dousecurrentstyleparameter
188 \fi
}
189
190\unexpanded
\def
\dousestylehashparameter
#
hash
#
parameter
191 {
\ifcsname
#
hash
#
parameter
\endcsname
192 \expandafter
\dousestyleparameter
\lastnamedcs
193 \fi
}
194
195\unexpanded
\def
\dousecurrentstyleparameter
196 {
\edef
\detokenizedstyleparameter
{
\detokenize\expandafter
{
\currentstyleparameter
}}
197 \settrue
\fontattributeisset
198 \ifcsname
\??alternativestyle
\detokenizedstyleparameter
\endcsname
199 \lastnamedcs
200 \else\ifcsname
\detokenizedstyleparameter
\endcsname
201 \lastnamedcs
202 \else
203 \currentstyleparameter
204 \fi\fi
}
205
206\let
\dosetfontattribute
\dousestylehashparameter
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223\installcorenamespace
{
style
}
224\installcorenamespace
{
stylecheck
}
225\installcorenamespace
{
stylehack
}
226
227\installcommandhandler
\??style
{
style
}
\??style
228
229\setupstyle
230 [
231
232 \c!method
=
\v!command
]
233
234\appendtoks
235 \letvalue
{
\??stylecheck
\currentstyle
}
\relax
236 \edef
\p_method
{
\styleparameter
\c!method
}
237 \ifx
\p_method
\v!command
238 \setuevalue
{
\e!start
\currentstyle
}{
\font_styles_apply_start
{
\currentstyle
}}
239 \setuevalue
{
\e!stop
\currentstyle
}{
\font_styles_apply_stop
}
240 \setuevalue
{
\currentstyle
}{
\font_styles_apply_grouped
{
\currentstyle
}}
241 \fi
242\to
\everydefinestyle
243
244\unexpanded
\def
\font_styles_apply_start
#
name
245 {
\begingroup
246 \font_styles_use_defined
{
#
name
}}
247
248\unexpanded
\def
\font_styles_apply_stop
249 {
\endgroup
}
250
251\unexpanded
\def
\font_styles_apply_grouped
#
name
252 {
\bgroup
253 \def
\g_style
{
\font_styles_use_defined
{
#
name
}}
254 \afterassignment
\g_style
255 \let
\nexttoken
}
256
257\unexpanded
\def
\font_styles_use_defined
#
name
258 {
\edef
\currentstyle
{
#
name
}
259 \usestylestyleandcolor
\c!style\c!color
}
260
261\unexpanded
\def
\font_styles_use_generic
#
specification
262 {
\let
\currentstyle
\s!unknown
263 \letstyleparameter
\c!style
\empty
264 \letstyleparameter
\c!color
\empty
265 \setupcurrentstyle
[#
specification
]
266 \usestylestyleandcolor
\c!style\c!color
}
267
268
269
270\installcorenamespace
{
styleargument
}
271
272\unexpanded
\def
\style
[#
name
]
273 {
\csname
\??styleargument
274 \ifcsname
\??stylecheck
#
name
\endcsname
275 2
276 \else\ifcsname
\??stylehack
#
name
\endcsname
277 4
278 \else\ifcsname
#
name
\endcsname
279 1
280 \else
281 3
282 \fi\fi\fi
283 \endcsname
{
#
name
}}
284
285
286
287
288\setvalue
{
\??styleargument
1
}
#
name
289 {
\expandafter
\triggergroupedcommandcs
\begincsname
#
name
\endcsname
}
290
291
292
293
294\setvalue
{
\??styleargument
2
}
#
name
295 {
\triggergroupedcommand
{
\font_styles_use_defined
{
#
name
}}}
296
297\setvalue
{
\??styleargument
3
}
#
specification
298 {
\doifelseassignment
{
#
specification
}
\font_styles_assignment
\font_styles_direct
{
#
specification
}}
299
300\setvalue
{
\??styleargument
4
}
#
name
301 {
\expandafter
\triggergroupedcommandcs
\begincsname
\??stylehack
#
name
\endcsname
}
302
303\setvalue
{
\??stylehack\s!math
}
304 {
\groupedcommand\normalstartimath\normalstopimath
}
305
306
307
308
309\def
\font_styles_assignment
#
specification
{
\triggergroupedcommand
{
\font_styles_use_generic
{
#
specification
}}}
310\def
\font_styles_direct
#
specification
{
\triggergroupedcommand
{
\definedfont
[#
specification
]
}}
311
312
313
314\installcorenamespace
{
styleenvironment
}
315
316\unexpanded
\def
\startstyle
[#
name
]
317 {
\begingroup
318 \csname
\??styleenvironment
319 \ifcsname
\??stylecheck
#
name
\endcsname
320 2
321 \else\ifcsname
#
name
\endcsname
322 1
323 \else
324 3
325 \fi\fi
326 \endcsname
{
#
name
}}
327
328\unexpanded
\def
\stopstyle
329 {
\endgroup
330 \autoinsertnextspace
}
331
332\setvalue
{
\??styleenvironment
1
}
#
name
333 {
\csname
#
name
\endcsname
}
334
335\setvalue
{
\??styleenvironment
2
}
#
name
336 {
\font_styles_use_defined
{
#
name
}}
337
338\setvalue
{
\??styleenvironment
3
}
#
specification
339 {
\doifelseassignment
{
#
specification
}
\font_styles_start_assignment
\font_styles_start_direct
{
#
specification
}}
340
341\def
\font_styles_start_assignment
#
specification
{
\font_styles_use_generic
{
#
specification
}}
342\def
\font_styles_start_direct
#
specification
{
\definedfont
[#
specification
]
\relax
}
343
344
345
346
347
348
349
350
351
352
353
354
355
356\installcorenamespace
{
stylecollection
}
357
358\unexpanded
\def
\definestylecollection
359 {
\dosingleargument
\font_styles_define_style_collection
}
360
361\def
\font_styles_define_style_collection
[#
name
]
362 {
\iffirstargument
363 \setuvalue
{
#
name
}{
\styleinstance
[#
name
]
}
364 \def
\font_styles_define_style_collection_a
#
style
365 {
\def
\font_styles_define_style_collection_b
#
alternative
{
\undefinevalue
{
\??stylecollection
#
name
:
#
style
:
#
alternative
}}
366 \font_helpers_process_alternative_list
\font_styles_define_style_collection_b
367 \font_styles_define_style_collection_b
\s!default
}
368 \font_helpers_process_style_list
\font_styles_define_style_collection_a
369 \font_styles_define_style_collection_a
\s!default
370 \fi
}
371
372\let
\font_styles_define_style_collection_a
\relax
373\let
\font_styles_define_style_collection_b
\relax
374
375\unexpanded
\def
\definestyleinstance
376 {
\doquadrupleargument
\font_styles_define_style_instance
}
377
378\def
\font_styles_define_style_instance
[#
instance
][#
2
][#
3
][#
4
]
379 {
\iffirstargument
380 \ifcsname
#
instance
\endcsname\else
\font_styles_define_style_collection
[#
instance
]
\fi
381 \fi
382 \iffourthargument
383 \setvalue
{
\??stylecollection
#
instance
:
#
2
:
#
3
}{
#
4
}
384 \else
\ifthirdargument
385 \setvalue
{
\??stylecollection
#
instance
:
:
#
2
}{
#
3
}
386 \else
\ifsecondargument
387 \letvalueempty
{
\??stylecollection
#
instance
:
:
#
2
}
388 \fi\fi\fi
}
389
390
391
392
393
394
395
396
397\unexpanded
\def
\styleinstance
[#
instance
]
398 {
\csname
\??stylecollection
#
instance
:
399 \ifcsname
\??stylecollection
#
instance
:
\fontstyle
:
\fontalternative
\endcsname
400 \fontstyle
:
\fontalternative
401 \else\ifcsname
\??stylecollection
#
instance
:
\fontstyle
:
\s!default
\endcsname
402 \fontstyle
:
\s!default
403 \else\ifcsname
\??stylecollection
#
instance
:
:
\fontalternative
\endcsname
404 :
\fontalternative
405 \else
406 :
\s!default
407 \fi\fi\fi
408 \endcsname
}
409
410
411
412
413
414
415
416
417\unexpanded
\edef
\vsone
#
character
{
#
character
\normalUchar
"
FE
0
0
}
418\unexpanded
\edef
\vstwo
#
character
{
#
character
\normalUchar
"
FE
0
1
}
419
420
421
422
423\unexpanded
\def
\doattributes
#
1
#
2
#
3
#
4
424 {
\begingroup
425 \dousestylehashparameter
{
#
1
}{
#
2
}
426 \dousecolorhashparameter
{
#
1
}{
#
3
}
427 #
4
428 \endgroup
}
429
430\unexpanded
\def
\dostartattributes
#
1
#
2
#
3
431 {
\begingroup
432 \dousestylehashparameter
{
#
1
}{
#
2
}
433 \dousecolorhashparameter
{
#
1
}{
#
3
}}
434
435\let
\dostopattributes
\endgroup
436
437
438
439\newconditional
\c_font_styles_math
440
441\unexpanded
\def
\font_styles_math_reset
442 {
\setfalse
\c_font_styles_math
}
443
444\unexpanded
\def
\font_styles_math_start
445 {
\ifconditional
\c_font_styles_math
446 \startimath
447 \fi
448 \relax
}
449
450\unexpanded
\def
\font_styles_math_stop
451 {
\relax
452 \ifconditional
\c_font_styles_math
453 \stopimath
454 \fi
}
455
456\definealternativestyle
[
\v!math
][
\settrue
\c_font_styles_math
]
457
458\protect
\endinput
459