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\let\currentstyleparameter \empty
185\let\currentdetokenizedstyleparameter\empty
186
187\unexpanded\def\dousestyleparameter#value
188 {\edef\currentstyleparameter{#value}
189 \ifx\currentstyleparameter\empty\else
190 \expandafter\dousecurrentstyleparameter
191 \fi}
192
193\unexpanded\def\dousestylehashparameter#hash#parameter
194 {\ifcsname#hash#parameter\endcsname
195 \expandafter\dousestyleparameter\lastnamedcs
196 \fi}
197
198\unexpanded\def\dousecurrentstyleparameter
199 {\edef\currentdetokenizedstyleparameter{\detokenize\expandafter{\currentstyleparameter}}
200 \settrue\fontattributeisset
201 \ifcsname\??alternativestyle\currentdetokenizedstyleparameter\endcsname
202 \lastnamedcs
203 \else\ifcsname\currentdetokenizedstyleparameter\endcsname
204 \lastnamedcs
205 \else
206 \currentstyleparameter
207 \fi\fi}
208
209\let\dosetfontattribute\dousestylehashparameter
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226\installcorenamespace{style}
227\installcorenamespace{stylecheck}
228\installcorenamespace{stylehack}
229
230\installcommandhandler \??style {style} \??style
231
232\setupstyle
233 [
234
235 \c!method=\v!command]
236
237\appendtoks
238 \letvalue{\??stylecheck\currentstyle}\relax
239 \edef\p_method{\styleparameter\c!method}
240 \ifx\p_method\v!command
241 \setuevalue{\e!start\currentstyle}{\font_styles_apply_start{\currentstyle}}
242 \setuevalue{\e!stop \currentstyle}{\font_styles_apply_stop}
243 \setuevalue {\currentstyle}{\font_styles_apply_grouped{\currentstyle}}
244 \fi
245\to \everydefinestyle
246
247\unexpanded\def\font_styles_apply_start#name
248 {\begingroup
249 \font_styles_use_defined{#name}}
250
251\unexpanded\def\font_styles_apply_stop
252 {\endgroup}
253
254\unexpanded\def\font_styles_apply_grouped#name
255 {\bgroup
256 \def\g_style{\font_styles_use_defined{#name}}
257 \afterassignment\g_style
258 \let\nexttoken}
259
260\unexpanded\def\font_styles_use_defined#name
261 {\edef\currentstyle{#name}
262 \usestylestyleandcolor\c!style\c!color}
263
264\unexpanded\def\font_styles_use_generic#specification
265 {\let\currentstyle\s!unknown
266 \letstyleparameter\c!style\empty
267 \letstyleparameter\c!color\empty
268 \setupcurrentstyle[#specification]
269 \usestylestyleandcolor\c!style\c!color}
270
271
272
273\installcorenamespace{styleargument}
274
275\unexpanded\def\style[#name]
276 {\csname\??styleargument
277 \ifcsname\??stylecheck#name\endcsname
278 2
279 \else\ifcsname\??stylehack#name\endcsname
280 4
281 \else\ifcsname#name\endcsname
282 1
283 \else
284 3
285 \fi\fi\fi
286 \endcsname{#name}}
287
288
289
290
291\setvalue{\??styleargument1}#name
292 {\expandafter\triggergroupedcommandcs\begincsname#name\endcsname}
293
294
295
296
297\setvalue{\??styleargument2}#name
298 {\triggergroupedcommand{\font_styles_use_defined{#name}}}
299
300\setvalue{\??styleargument3}#specification
301 {\doifelseassignment{#specification}\font_styles_assignment\font_styles_direct{#specification}}
302
303\setvalue{\??styleargument4}#name
304 {\expandafter\triggergroupedcommandcs\begincsname\??stylehack#name\endcsname}
305
306\setvalue{\??stylehack\s!math}
307 {\groupedcommand\normalstartimath\normalstopimath}
308
309
310
311
312\def\font_styles_assignment#specification{\triggergroupedcommand{\font_styles_use_generic{#specification}}}
313\def\font_styles_direct #specification{\triggergroupedcommand{\definedfont[#specification]}}
314
315
316
317\installcorenamespace{styleenvironment}
318
319\unexpanded\def\startstyle[#name]
320 {\begingroup
321 \csname\??styleenvironment
322 \ifcsname\??stylecheck#name\endcsname
323 2
324 \else\ifcsname#name\endcsname
325 1
326 \else
327 3
328 \fi\fi
329 \endcsname{#name}}
330
331\unexpanded\def\stopstyle
332 {\endgroup
333 \autoinsertnextspace}
334
335\setvalue{\??styleenvironment1}#name
336 {\csname#name\endcsname}
337
338\setvalue{\??styleenvironment2}#name
339 {\font_styles_use_defined{#name}}
340
341\setvalue{\??styleenvironment3}#specification
342 {\doifelseassignment{#specification}\font_styles_start_assignment\font_styles_start_direct{#specification}}
343
344\def\font_styles_start_assignment#specification{\font_styles_use_generic{#specification}}
345\def\font_styles_start_direct #specification{\definedfont[#specification]\relax}
346
347
348
349
350
351
352
353
354
355
356
357
358
359\installcorenamespace{stylecollection}
360
361\unexpanded\def\definestylecollection
362 {\dosingleargument\font_styles_define_style_collection}
363
364\def\font_styles_define_style_collection[#name]
365 {\iffirstargument
366 \setuvalue{#name}{\styleinstance[#name]}
367 \def\font_styles_define_style_collection_a#style
368 {\def\font_styles_define_style_collection_b#alternative{\undefinevalue{\??stylecollection#name:#style:#alternative}}
369 \font_helpers_process_alternative_list\font_styles_define_style_collection_b
370 \font_styles_define_style_collection_b\s!default}
371 \font_helpers_process_style_list\font_styles_define_style_collection_a
372 \font_styles_define_style_collection_a\s!default
373 \fi}
374
375\let\font_styles_define_style_collection_a\relax
376\let\font_styles_define_style_collection_b\relax
377
378\unexpanded\def\definestyleinstance
379 {\doquadrupleargument\font_styles_define_style_instance}
380
381\def\font_styles_define_style_instance[#instance][#2][#3][#4]
382 {\iffirstargument
383 \ifcsname#instance\endcsname\else\font_styles_define_style_collection[#instance]\fi
384 \fi
385 \iffourthargument
386 \setvalue{\??stylecollection#instance:#2:#3}{#4}
387 \else\ifthirdargument
388 \setvalue{\??stylecollection#instance::#2}{#3}
389 \else\ifsecondargument
390 \letvalueempty{\??stylecollection#instance::#2}
391 \fi\fi\fi}
392
393
394
395
396
397
398
399
400\unexpanded\def\styleinstance[#instance]
401 {\csname\??stylecollection#instance:
402 \ifcsname\??stylecollection#instance:\fontstyle:\fontalternative\endcsname
403 \fontstyle:\fontalternative
404 \else\ifcsname\??stylecollection#instance:\fontstyle:\s!default\endcsname
405 \fontstyle:\s!default
406 \else\ifcsname\??stylecollection#instance::\fontalternative\endcsname
407 :\fontalternative
408 \else
409 :\s!default
410 \fi\fi\fi
411 \endcsname}
412
413
414
415
416
417
418
419
420\unexpanded\edef\vsone#character{#character\normalUchar"FE00 }
421\unexpanded\edef\vstwo#character{#character\normalUchar"FE01 }
422
423
424
425
426\unexpanded\def\doattributes#1#2#3#4
427 {\begingroup
428 \dousestylehashparameter{#1}{#2}
429 \dousecolorhashparameter{#1}{#3}
430 #4
431 \endgroup}
432
433\unexpanded\def\dostartattributes#1#2#3
434 {\begingroup
435 \dousestylehashparameter{#1}{#2}
436 \dousecolorhashparameter{#1}{#3}}
437
438\let\dostopattributes\endgroup
439
440
441
442\newconditional\c_font_styles_math
443
444\unexpanded\def\font_styles_math_reset
445 {\setfalse\c_font_styles_math}
446
447\unexpanded\def\font_styles_math_start
448 {\ifconditional\c_font_styles_math
449 \startimath
450 \fi
451 \relax}
452
453\unexpanded\def\font_styles_math_stop
454 {\relax
455 \ifconditional\c_font_styles_math
456 \stopimath
457 \fi}
458
459\definealternativestyle[\v!math][\settrue\c_font_styles_math]
460
461\protect \endinput
462 |