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