1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Typescript Macros Initialization}
15
16\registerctxluafile{typeini}{}
17
18
19
20
21
22
23
24
25
26
27
28\unprotect
29
30\definesystemvariable {ts}
31
32\newcount \c_font_typescripts_n_of_preloaded
33\newconditional\c_font_typescripts_quit
34\newtoks \c_font_typescripts_document
35\newconditional\c_font_typescripts_preload
36\newconditional\c_font_typescripts_first_pass \settrue\c_font_typescripts_first_pass
37
38\newif \iftypescriptfound
39\newif \iftracetypescripts
40
41\newtoks \everybeforedefinetypeface
42\newtoks \everyafterdefinetypeface
43
44\let\typescriptfiles \empty
45\let\currenttypescripts\empty
46\let\currenttypefile \empty
47
48\installmacrostack\currenttypefile
49
50\let\typescriptone \empty
51\let\typescripttwo \empty
52\let\typescriptthree\empty
53
54\installmacrostack\typescriptone
55\installmacrostack\typescripttwo
56\installmacrostack\typescriptthree
57
58\let\fontclassstyle \empty
59
60\installmacrostack\fontclassstyle
61
62\let\m_font_typescripts_one \empty
63\let\m_font_typescripts_two \empty
64\let\m_font_typescripts_three\empty
65\let\m_font_typescripts_check\empty
66\let\m_font_typescripts_match\empty
67
68\installmacrostack\m_font_typescripts_one
69\installmacrostack\m_font_typescripts_two
70\installmacrostack\m_font_typescripts_three
71
72\let\t_font_typescripts\relax
73
74\installcorenamespace{typescriptcache}
75\installcorenamespace{typescriptfiles}
76\installcorenamespace{typescriptonce}
77\installcorenamespace{typescriptsynonyms}
78\installcorenamespace{typescriptprefix}
79\installcorenamespace{typescriptinheritances}
80\installcorenamespace{typescriptdefaultstyles}
81\installcorenamespace{typescriptrelatives}
82
83\definesystemvariable{ts}
84
85
86
87\let\typescriptmethod\plusone
88\let\typescriptstate \plustwo
89
90\installmacrostack\typescriptmethod
91\installmacrostack\typescriptstate
92
93\unexpanded\def\starttypescriptcollection
94 {\dosingleempty\font_typescripts_collection_start}
95
96\def\font_typescripts_collection_start[#tag]
97 {}
98
99\let\stoptypescriptcollection\relax
100
101\unexpanded\def\usetypescriptfile[#filename]
102 {\doifelse{#filename}\v!reset
103 {\let\typescriptfiles\empty}
104 {\splitfilename{#filename}
105 \addtocommalist\splitoffbase\typescriptfiles}}
106
107\unexpanded\def\usetypescript {\dotripleempty\font_typescripts_use_one}
108\unexpanded\def\usetypescriptexact{\dotripleempty\font_typescripts_use_two}
109
110\def\font_typescripts_use_one{\let\typescriptmethod\plusone\font_typescripts_use}
111\def\font_typescripts_use_two{\let\typescriptmethod\plustwo\font_typescripts_use}
112
113\installmacrostack\stoptypescript
114
115\unexpanded\def\font_typescripts_use[#one][#two][#three]
116 {\push_macro_m_font_typescripts_one
117 \push_macro_m_font_typescripts_two
118 \push_macro_m_font_typescripts_three
119 \edef\m_font_typescripts_one {\truetypescript{#one}}
120 \edef\m_font_typescripts_two {\truetypescript{#two}}
121 \edef\m_font_typescripts_three{\truetypescript{#three}}
122 \push_macro_typescriptone
123 \push_macro_typescripttwo
124 \push_macro_typescriptthree
125 \push_macro_typescriptmethod
126 \push_macro_typescriptstate
127 \push_macro_stoptypescript
128 \typescriptfoundfalse
129 \let\typescriptstate\plusone
130 \iftracetypescripts
131 \writestatus\m!fonts{request: [\m_font_typescripts_one] [\m_font_typescripts_two] [\m_font_typescripts_three]}
132 \fi
133 \ifhmode
134 \font_typescripts_use_inline
135 \else
136 \font_typescripts_use_display
137 \fi
138 \setfalse\c_font_typescripts_first_pass
139 \pop_macro_stoptypescript
140 \pop_macro_typescriptstate
141 \pop_macro_typescriptmethod
142 \pop_macro_typescriptthree
143 \pop_macro_typescripttwo
144 \pop_macro_typescriptone
145 \pop_macro_m_font_typescripts_three
146 \pop_macro_m_font_typescripts_two
147 \pop_macro_m_font_typescripts_one}
148
149\def\font_typescripts_use_display
150 {\processcommacommand[\typescriptfiles]\font_typescripts_load_file
151 \the\c_font_typescripts_document}
152
153\let\font_typescripts_use_inline\font_typescripts_use_display
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\unexpanded\def\preloadtypescripts
180 {\ifproductionrun\settrue\c_font_typescripts_preload\fi}
181
182\prependtoks
183 \preloadtypescripts
184\to \everyjob
185
186
187
188
189\unexpanded\def\loadtypescriptfile[#1]
190 {\push_macro_typescriptstate
191 \let\typescriptstate\plustwo
192 \clf_loadtypescriptfile{#1}
193 \pop_macro_typescriptstate}
194
195\unexpanded\def\loadfoundtypescriptfile#1#2
196 {\startreadingfile
197 \unprotect
198 \pushendofline
199 \input{#2}
200 \popendofline
201 \protect
202 \stopreadingfile}
203
204\unexpanded\def\quittypescriptscanning
205 {\settrue\c_font_typescripts_quit}
206
207\def\font_typescripts_start_store#definitions\stoptypescript
208 {\global\advance\c_font_typescripts_n_of_preloaded\plusone
209 \expandafter\normalgdef\csname\??typescriptcache\the\c_font_typescripts_n_of_preloaded\endcsname
210 {\starttypescript#definitions\stoptypescript}
211 \gtoksapp\t_font_typescripts\expandafter
212 {\csname\??typescriptcache\the\c_font_typescripts_n_of_preloaded\endcsname}}
213
214\def\font_typescripts_collection_start_store#definitions\stoptypescriptcollection
215 {\global\advance\c_font_typescripts_n_of_preloaded\plusone
216 \expandafter\normalgdef\csname\??typescriptcache\the\c_font_typescripts_n_of_preloaded\endcsname
217 {\starttypescriptcollection#definitions\stoptypescriptcollection}
218 \gtoksapp\t_font_typescripts\expandafter
219 {\csname\??typescriptcache\the\c_font_typescripts_n_of_preloaded\endcsname}}
220
221\def\font_typescripts_load_file#filename
222 {\setfalse\c_font_typescripts_quit
223 \push_macro_currenttypefile
224 \def\currenttypefile{#filename}
225 \ifconditional\c_font_typescripts_preload
226 \font_typescript_process_typescript_file_and_store
227 \else
228 \font_typescript_process_typescript_file
229 \fi
230 \pop_macro_currenttypefile
231 \ifconditional\c_font_typescripts_quit
232 \quitcommalist
233 \setfalse\c_font_typescripts_quit
234 \fi}
235
236\def\font_typescript_process_typescript_file_and_store
237 {\expandafter\let\expandafter\t_font_typescripts\csname\??typescriptfiles\currenttypefile\endcsname
238 \ifx\t_font_typescripts\relax
239 \font_typescript_process_typescript_store_indeed
240 \fi
241 \the\t_font_typescripts}
242
243\def\font_typescript_process_typescript_store_indeed
244 {\newtoks\t_font_typescripts
245 \begingroup
246 \let\starttypescript \font_typescripts_start_store
247 \let\starttypescriptcollection\font_typescripts_collection_start_store
248 \font_typescript_process_typescript_file
249 \endgroup
250 \expandafter\let\csname\??typescriptfiles\currenttypefile\endcsname\t_font_typescripts}
251
252\def\font_typescript_process_typescript_file
253 {\clf_doprocesstypescriptfile{\currenttypefile}}
254
255\unexpanded\def\usetypescriptonce
256 {\dotripleempty\font_typescripts_use_once}
257
258\def\font_typescripts_use_once[#one][#two][#three]
259 {\ifcsname\??typescriptonce#one:#two:#three\endcsname
260 \writestatus\m!fonts{once (#one) (#two) (#three)}
261 \else
262 \expandafter\let\csname\??typescriptonce#one:#two:#three\endcsname\relax
263 \font_typescripts_use[#one][#two][#three]
264 \fi}
265
266
267
268\unexpanded\def\definetypescriptsynonym
269 {\dodoubleempty\font_typescripts_synonym_define}
270
271\def\font_typescripts_synonym_define[#name][#synonym]
272 {\ifsecondargument\setevalue{\??typescriptsynonyms#name}{#synonym}\fi}
273
274\def\truetypescript#name
275 {\ifcsname\??typescriptsynonyms#name\endcsname
276
277 \expandafter\truetypescript\lastnamedcs
278 \else
279 #name
280 \fi}
281
282
283
284
285
286
287
288\prependtoks
289 \settrue\c_font_typescripts_first_pass
290\to \everyjob
291
292\unexpanded\def\starttypescript
293 {\ifcase\typescriptstate
294
295 \expandafter\font_typescripts_start_gobble
296 \or
297
298 \expandafter\font_typescripts_start_process
299 \or
300
301 \expandafter\font_typescripts_start_document
302 \else
303
304 \expandafter\font_typescripts_start_gobble
305 \fi}
306
307\def\font_typescripts_start_gobble#definitions\stoptypescript{}
308
309\def\font_typescripts_start_document#definitions\stoptypescript
310 {\toksapp\c_font_typescripts_document{\starttypescript#definitions\stoptypescript}}
311
312\def\font_typescripts_start_process
313 {\let\typescriptone \m_font_typescripts_one
314 \let\typescripttwo \m_font_typescripts_two
315 \let\typescriptthree\m_font_typescripts_three
316 \let\m_font_typescripts_match\empty
317 \doifelsenextoptionalcs\font_typescripts_start_process_one\font_typescripts_start_process_all}
318
319\def\font_typescripts_start_process_all
320 {\ifconditional\c_font_typescripts_first_pass
321 \expandafter\font_typescripts_start_process_indeed
322 \else
323
324
325
326 \expandafter\font_typescripts_start_gobble
327 \fi}
328
329\def\font_typescripts_show_match
330 {\writestatus\m!fonts{match:\ifx\currenttypefile\relax\space *\fi \m_font_typescripts_match}}
331
332\def\font_typescripts_start_process_yes
333 {\ifdone
334 \typescriptfoundtrue
335 \iftracetypescripts\font_typescripts_show_match\fi
336 \expandafter\font_typescripts_start_process_indeed
337 \else
338 \expandafter\font_typescripts_start_gobble
339 \fi}
340
341\def\font_typescripts_start_process_one
342 {\font_typescripts_check\m_font_typescripts_one\typescriptone\font_typescripts_start_process_again_one}
343
344\def\font_typescripts_start_process_two
345 {\font_typescripts_check\m_font_typescripts_two\typescripttwo\font_typescripts_start_process_again_two}
346
347\def\font_typescripts_start_process_three
348 {\font_typescripts_check\m_font_typescripts_three\typescriptthree\font_typescripts_start_process_again_three}
349
350\def\font_typescripts_start_process_again_one
351 {\doifelsenextoptionalcs\font_typescripts_start_process_two\font_typescripts_start_process_yes}
352
353\def\font_typescripts_start_process_again_two
354 {\doifelsenextoptionalcs\font_typescripts_start_process_three\font_typescripts_start_process_yes}
355
356\let\font_typescripts_start_process_again_three\font_typescripts_start_process_yes
357
358\def\font_typescripts_start_process_indeed
359 {\push_macro_fontclass}
360
361\unexpanded\def\stoptypescript
362 {\pop_macro_fontclass}
363
364\def\font_typescripts_check#asked#target#followup[#value]
365 {\donefalse
366 \edef\m_font_typescripts_check{#value}
367 \ifx\m_font_typescripts_check\empty
368 \ifcase\typescriptmethod\or\donetrue\fi
369 \else\ifx#asked\s!all
370 \donetrue
371 \else\ifx\m_font_typescripts_check\s!all
372 \donetrue
373 \else\ifx#asked\m_font_typescripts_check
374 \donetrue
375 \let#target\m_font_typescripts_check
376 \else
377 \doifelsecommon\m_font_typescripts_check#asked\donetrue\donefalse
378 \ifdone
379 \let#target\commalistelement
380 \fi
381 \fi\fi\fi\fi
382 \ifdone
383 \iftracetypescripts\extendtypescriptmatch\fi
384 \expandafter#followup
385 \else
386 \expandafter\font_typescripts_start_gobble
387 \fi}
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412\def\extendtypescriptmatch
413 {\edef\m_font_typescripts_match{\m_font_typescripts_match\space[\m_font_typescripts_check]}}
414
415
416
417
418\unexpanded\def\loadmapfile{\dosingleempty\font_map_load_file}
419\unexpanded\def\loadmapline{\dodoubleempty\font_map_load_line}
420
421\def\font_map_load_file[#filename]
422 {\clf_loadmapfile{#filename}}
423
424\def\font_map_load_line[#kind][#data]
425 {\clf_loadmapline{#kind}{#data}}
426
427\unexpanded\def\forgetmapfiles
428 {\clf_resetmapfiles}
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444\unexpanded\def\definetypescriptprefix
445 {\dodoubleargument\font_typescripts_define_prefix}
446
447\def\font_typescripts_define_prefix[#name][#prefix]
448 {\setgvalue{\??typescriptprefix#name}{#prefix}}
449
450
451
452
453
454
455
456
457\def\typescriptprefix#name
458
459 {\ifcsname\??typescriptprefix#name\endcsname\lastnamedcs\else#name\fi}
460
461
462
463
464
465
466
467
468
469
470\unexpanded\def\definetypeface
471 {\dosixtupleargument\font_typefaces_define}
472
473\appendtoks
474 \font_helpers_reset_fontclass_math_families\fontclass
475\to \everybeforedefinetypeface
476
477
478
479\settrue\autotypescripts
480
481\unexpanded\def\trycurrentfontclass#typeface
482 {\ifconditional\autotypescripts
483 \usetypescript[#typeface]
484 \ifcsname\??fontclassyes#typeface\endcsname
485 \edef\fontclass{#typeface}
486 \else
487 \iftracetypescripts\writestatus\m!fonts{auto load typescript file 1: [#typeface]}\fi
488 \usetypescriptfile[#typeface]
489 \usetypescript[#typeface]
490 \ifcsname\??fontclassyes#typeface\endcsname
491 \edef\fontclass{#typeface}
492 \else
493
494 \letvalueempty{\??fontclassnop#typeface}
495 \fi
496 \fi
497 \else
498
499 \letvalueempty{\??fontclassnop#typeface}
500 \fi}
501
502
503
504\def\font_typefaces_define
505 {\iffifthargument
506 \singleexpandafter\font_typefaces_define_a
507 \else\iffourthargument
508 \doubleexpandafter\font_typefaces_define_b
509 \else\ifthirdargument
510 \tripleexpandafter\font_typefaces_define_c
511 \else
512 \tripleexpandafter\font_typefaces_define_d
513 \fi\fi\fi}
514
515\def\font_typefaces_define_a[#name][#style][#fontshape][#fontname][#fontsize][#settings]
516 {\iftracetypescripts\writestatus\m!fonts{define: [#name] [#style] [#fontshape] [#fontname]}\fi
517 \font_typefaces_define_indeed[#name][#style]
518 \font_typefaces_defining_start{#name}{#style}{#settings}
519 \font_typescripts_use_one[#fontshape][#fontname][\s!name]
520 \iftypescriptfound
521
522 \else
523 \ifconditional\autotypescripts
524 \iftracetypescripts\writestatus\m!fonts{auto load typescript file 2: [#fontname]}\fi
525 \usetypescriptfile[#fontname]
526 \font_typescripts_use_one[#fontshape][#fontname][\s!name]
527 \fi
528 \fi
529 \font_typescripts_use_one[#fontshape][#fontsize][\s!size]
530 \font_typefaces_defining_stop}
531
532\def\font_typefaces_define_b[#name][#style][#fontshape][#fontname][#dummya][#dummyb]
533 {\font_typefaces_define_a[#name][#style][#fontshape][#fontname][\s!default][#dummyb]}
534
535\def\font_typefaces_define_c[#name][#style][#dummya][#dummyb][#dummyc][#dummyd]
536 {\font_typefaces_define_indeed[#name][#style]}
537
538\def\font_typefaces_define_d[#name][#specification][#dummya][#dummyb][#dummyc][#dummyd]
539 {\clf_definetypeface{#name}{#specification}}
540
541\def\font_typefaces_define_indeed[#name][#style]
542 {\doifsomething{#name}
543 {\ifcsname\??typescriptdefaultstyles#name\endcsname \else
544 \registerfontclass{#name}
545 \setxvalue{\??typescriptdefaultstyles#name}{#style}
546 \fi
547 \ifcsname#name\endcsname \else
548 \setugvalue{#name}{\switchtotypeface[#name][#style]}
549 \fi}}
550
551\def\font_typefaces_defining_start#name#style#settings
552 {\let\@@tsrscale \!!plusone
553 \let\@@tsfeatures \empty
554 \let\@@tsfallbacks \empty
555 \let\@@tsgoodies \empty
556 \let\@@tsdirection \empty
557 \let\@@tsdesignsize\empty
558 \geteparameters[\??ts][#settings]
559 \push_macro_fontclass
560 \push_macro_fontclassstyle
561 \setcurrentfontclass{#name}
562 \savefontclassparameters{#style}\@@tsrscale\@@tsfeatures\@@tsfallbacks\@@tsgoodies\@@tsdesignsize\@@tsdirection
563 \the\everybeforedefinetypeface}
564
565\def\tsvar#key#default
566 {\expandafter\ifx\csname\??ts#key\endcsname\empty
567 #default
568 \else
569 \csname\??ts#key\endcsname
570 \fi}
571
572\def\font_typefaces_defining_stop
573 {\the\everyafterdefinetypeface
574 \pop_macro_fontclassstyle
575 \pop_macro_fontclass}
576
577\def\dofastdefinetypeface#name#style#fontshape#fontsize#settings
578 {\font_typefaces_define_indeed[#name][#style]
579 \font_typefaces_defining_start{#name}{#style}{#settings}
580 \font_typescripts_use_one[#fontshape][#fontsize][\s!size]
581 \font_typefaces_defining_stop}
582
583\unexpanded\def\setuptypeface
584 {\dodoubleempty\font_typefaces_setup}
585
586\unexpanded\def\switchtotypeface
587 {\dodoubleempty\font_typefaces_switch}
588
589\def\font_typefaces_setup[#class][#settings]
590 {\setcurrentfontclass{#class}
591 \let\globalfontclass\fontclass
592 \ifsecondargument
593 \setupbodyfont[#settings]
594 \else\ifx\fontclass\empty
595 \setupbodyfont[\s!rm]
596 \else\ifcsname\??typescriptdefaultstyles\fontclass\endcsname
597
598 \expandafter\setupbodyfont\expandafter[\lastnamedcs]
599 \else
600 \setupbodyfont[\s!rm]
601 \fi \fi \fi
602 \ifmmode\mr\else\tf\fi}
603
604\def\font_typefaces_switch[#class][#settings]
605 {\setcurrentfontclass{#class}
606 \let\globalfontclass\globalfontclass
607 \ifsecondargument
608 \switchtobodyfont[#settings]
609 \else\ifx\fontclass\empty
610 \switchtobodyfont[\s!rm]
611 \else\ifcsname\??typescriptdefaultstyles\fontclass\endcsname
612
613 \expandafter\switchtobodyfont\expandafter[\lastnamedcs]
614 \else
615 \switchtobodyfont[\s!rm]
616 \fi \fi \fi
617 \ifmmode\mr\else\tf\fi}
618
619
620
621
622
623
624
625
626
627
628\unexpanded\def\inherittypeface
629 {\dotripleempty\font_typescripts_inherit_indeed}
630
631\def\font_typescripts_inherit_indeed[#name][#styles][#parentclass]
632 {\doifelsenothing{#styles}
633 {\font_typescripts_inherit_indeed[#name][\s!rm,\s!ss,\s!tt,\s!mm][\fontclass]}
634 {\doifnot{#name}{#parentclass}
635 {\glet\font_typescripts_inherit_check\font_typescripts_inherit_check_indeed
636 \def\font_typescripts_inherit_check_step#style{\setevalue{\??typescriptinheritances#name:#style}{#parentclass}}
637 \processcommalist[#styles]\font_typescripts_inherit_check_step}}}
638
639\let\font_typescripts_inherit_check_step\relax
640
641
642
643\def\font_typescripts_inherit_check_indeed#name
644 {\ifcsname\??typescriptinheritances\fontclass:#name\endcsname
645
646 \expandafter\let\expandafter\fontclass\lastnamedcs
647 \fi}
648
649\let\font_typescripts_inherit_check\gobbleoneargument
650
651
652
653
654
655
656
657
658
659
660
661\def\v_font_string_d
662 {\expandafter\ifx\csname\??typescriptdefaultstyles\fontclass\endcsname\s!rm \s!Serif \else
663 \expandafter\ifx\csname\??typescriptdefaultstyles\fontclass\endcsname\s!ss \s!Sans \else
664 \expandafter\ifx\csname\??typescriptdefaultstyles\fontclass\endcsname\s!tt \s!Mono \else
665 \s!Serif \fi\fi\fi}
666
667\unexpanded\def\font_helpers_set_fontstyle_of_fontclass
668 {\ifx\fontclass\empty
669 \let\fontstyle\s!rm
670 \else\ifcsname\??typescriptdefaultstyles\fontclass\endcsname
671
672 \edef\fontstyle{\lastnamedcs}
673 \else
674 \let\fontstyle\s!rm
675 \fi\fi}
676
677\protect \endinput
678 |