type-ini.mkvi /size: 22 Kb    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=type-ini,
3%D        version=2001.03.05,
4%D          title=\CONTEXT\ Typescript Macros,
5%D       subtitle=Initialization,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Typescript Macros / Initialization}
15
16\registerctxluafile{type-ini}{}
17
18%D The default fontclass is empty. We could demand always using fontclasses, and
19%D then make the calling macros simplier (always assume fontclass) but apart from
20%D downward compatibility issues, it would make global, class spanning definitions a
21%D pain. Some day we will introduce a default class.
22%D
23%D The \type {type-ini} and \type {font-ini} modules come as a pair and have mutual
24%D dependencies.
25%D
26%D At some point we will only store in memory so some code can go away.
27
28\unprotect
29
30\definesystemvariable {ts} % TypeScript / for the moment we keep this one
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              % will become a mode
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 % public, used in typescripts
51\let\typescripttwo  \empty % public, used in typescripts
52\let\typescriptthree\empty % public, used in typescripts
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 % uses as synonym
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} % TypeScript
84
85% tricky ... here we push/pop ... so \let
86
87\let\typescriptmethod\plusone % 1: empty==all==true  2: empty==false
88\let\typescriptstate \plustwo % 1: process 2: store
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 % why
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% % not yet:
156%
157% \newsignal\d_font_typescripts_signal
158%
159% \def\font_typescripts_use_inline
160%   {\ifhmode
161%      \kern\d_font_typescripts_signal
162%    \fi
163%    \font_typescripts_use_display
164%    \ifhmode
165%      \ifdim\lastkern=\d_font_typescripts_signal
166%        \unkern
167%      \else
168%        \removeunwantedspaces
169%        \ifdim\lastkern=\d_font_typescripts_signal
170%          \unkern
171%        \else
172%          % messy typescript 2
173%        \fi
174%      \fi
175%    \else
176%      % messy typescript 1
177%    \fi}
178
179\unexpanded\def\preloadtypescripts
180  {\ifproductionrun\settrue\c_font_typescripts_preload\fi}
181
182\prependtoks
183    \preloadtypescripts
184\to \everyjob
185
186%D The next will change .. we can load a file inside a typescript but as the state is
187%D 1 then, it doesn't get stored without doing that explicitly
188
189\unexpanded\def\loadtypescriptfile[#1]%
190  {\push_macro_typescriptstate
191   \let\typescriptstate\plustwo % assumes 2 at the outer level
192   \clf_loadtypescriptfile{#1}%
193   \pop_macro_typescriptstate}
194
195\unexpanded\def\loadfoundtypescriptfile#1#2% name foundname / not a user command
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} % public
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 % is \relaxed elsewhere
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% \definetypescriptsynonym[lbr][cmr]
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% recursive so no \lastnamedcs
275  {\ifcsname\??typescriptsynonyms#name\endcsname
276    %\expandafter\truetypescript\csname\??typescriptsynonyms#name\endcsname
277     \expandafter\truetypescript\lastnamedcs
278   \else
279     #name%
280   \fi}
281
282% script [serif] [default]         [size]
283% script [serif] [computer-modern] [size]
284% script [serif] [computer-modern] [ec]
285% script [serif] [computer-modern] [name]
286% script [serif] [computer-modern] [special]
287
288\prependtoks
289    \settrue\c_font_typescripts_first_pass
290\to \everyjob
291
292\unexpanded\def\starttypescript
293  {\ifcase\typescriptstate
294     % 0 = skip
295     \expandafter\font_typescripts_start_gobble
296   \or
297     % 1 = process
298     \expandafter\font_typescripts_start_process
299   \or
300     % 2 = store
301     \expandafter\font_typescripts_start_document
302   \else
303     % ? = skip
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 % could be a faster \doifelsenextoptionalif needed
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 % could be a \let
320  {\ifconditional\c_font_typescripts_first_pass
321     \expandafter\font_typescripts_start_process_indeed
322   \else
323     % skip this since it may do unwanted resets, like
324     % setting symbolic font names to unknown, especially
325     % in run time user type scripts
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]% script use value next
365  {\donefalse
366   \edef\m_font_typescripts_check{#value}%
367   \ifx\m_font_typescripts_check\empty % no longer needed / met
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 % saves 10% trace so probably faster too
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% \def\font_typescripts_check#asked#target#followup[#value]% script use value next
390%   {\donefalse
391%    \edef\m_font_typescripts_check{#value}%
392%    \ifx\m_font_typescripts_check\empty % no longer needed / met
393%      \ifcase\typescriptmethod\or\donetrue\fi
394%    \else\ifx#asked\s!all
395%      \donetrue
396%    \else\ifx\m_font_typescripts_check\s!all
397%      \donetrue
398%    \else\ifx#asked\m_font_typescripts_check % saves 10% trace so probably faster too
399%      \donetrue
400%      \let#target\m_font_typescripts_check
401%    \else\ifcondition\hascommonargumentcondition\m_font_typescripts_check#asked%
402%      \donetrue
403%      \let#target\commalistelement
404%    \fi\fi\fi\fi\fi
405%    \ifdone
406%      \iftracetypescripts\extendtypescriptmatch\fi
407%      \expandafter#followup%
408%    \else
409%      \expandafter\font_typescripts_start_gobble
410%    \fi}
411
412\def\extendtypescriptmatch
413  {\edef\m_font_typescripts_match{\m_font_typescripts_match\space[\m_font_typescripts_check]}}
414
415%D Map files will go away in \LUATEX, but till that happens we use stripped down
416%D support for loading them.
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% \prependtoks
431%     \loadmapfile[mkiv-base.map]% can't we preload this one?
432% \to \everystarttext
433
434%D A handy shortcut:
435
436% \definetypescriptprefix[serif][Serif]
437% \definetypescriptprefix[sans] [Sans]
438% \definetypescriptprefix[mono] [Mono]
439%
440%\starttypescript [serif,sans,mono] [handling,hanging,hz] [pure,normal,hz,quality]
441%  \setupfontsynonym [\typescriptprefix\typescriptone] [handling=\typescriptthree]
442% \stoptypescript
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}} % made global
449
450% without testing:
451%
452% \def\typescriptprefix#name%
453%   {\csname\??typescriptprefix#name\endcsname}
454%
455% with testing:
456
457\def\typescriptprefix#name%
458 %{\ifcsname\??typescriptprefix#name\endcsname\csname\??typescriptprefix#name\endcsname\else#name\fi}
459  {\ifcsname\??typescriptprefix#name\endcsname\lastnamedcs\else#name\fi}
460
461% defining typefaces:
462%
463% \definetypeface [joke] [rm]
464% \definetypeface [joke] [rm] [settings]
465% \definetypeface [joke] [rm] [serif] [lucida]
466% \definetypeface [joke] [rm] [serif] [lucida] [size]
467% \definetypeface [joke] [rm] [serif] [lucida] [size] [settings]
468% \definetypeface [joke] [specification]
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%D This hooks into the font switcher:
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         % todo: message
494         \letvalueempty{\??fontclassnop#typeface}%
495       \fi
496     \fi
497   \else
498     % todo: message
499     \letvalueempty{\??fontclassnop#typeface}%
500   \fi}
501
502%D Now we define:
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]% [\s!name,\s!default]%
520     \iftypescriptfound
521       % we're okay
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]% [\s!name,\s!default]%
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]% use definitions in lfg file
539  {\clf_definetypeface{#name}{#specification}}
540
541\def\font_typefaces_define_indeed[#name][#style]% saveguard against redefinition
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 % as we push/pop
553   \let\@@tsfeatures  \empty
554   \let\@@tsfallbacks \empty
555   \let\@@tsgoodies   \empty
556   \let\@@tsdirection \empty
557   \let\@@tsdesignsize\empty
558   \geteparameters[\??ts][#settings]% todo raw
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% undocumented and unofficial
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% called from the lua end (via case d)
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% [class] [settings]
584  {\dodoubleempty\font_typefaces_setup}
585
586\unexpanded\def\switchtotypeface% [class] [settings]
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    %\setupbodyfont[\csname\??typescriptdefaultstyles\fontclass\endcsname]%
598     \expandafter\setupbodyfont\expandafter[\lastnamedcs]%
599   \else
600     \setupbodyfont[\s!rm]%
601   \fi \fi \fi
602   \ifmmode\mr\else\tf\fi} % needed ?
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    %\switchtobodyfont[\csname\??typescriptdefaultstyles\fontclass\endcsname]%
613     \expandafter\switchtobodyfont\expandafter[\lastnamedcs]%
614   \else
615     \switchtobodyfont[\s!rm]%
616   \fi \fi \fi
617   \ifmmode\mr\else\tf\fi} % needed ?
618
619%D For Taco:
620%D
621%D \starttyping
622%D \inherittypeface[palatino][rm][postscript]
623%D \inherittypeface[palatino][rm][\fontclass]
624%D \inherittypeface[palatino][rm] % == \fontclass
625%D \inherittypeface[palatino] % == [rm,ss,tt,mm]
626%D \stoptyping
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%D This hooks into the font mechanism with:
642
643\def\font_typescripts_inherit_check_indeed#name% called often
644  {\ifcsname\??typescriptinheritances\fontclass:#name\endcsname
645    %\expandafter\let\expandafter\fontclass\csname\??typescriptinheritances\fontclass:#name\endcsname
646     \expandafter\let\expandafter\fontclass\lastnamedcs
647   \fi}
648
649\let\font_typescripts_inherit_check\gobbleoneargument
650
651% not yet:
652%
653% \def\font_helpers_check_relative_font_id
654%   {\ifcsname\??typescriptrelatives\fontclass\endcsname
655%      \expandafter\let\expandafter\relativefontid\csname\??typescriptrelatives\fontclass\endcsname
656%    \else
657%      \expandafter\normalxdef\csname\??typescriptrelatives\fontclass\endcsname{\the\lastfontid}%
658%      \let\relativefontid\minusone
659%    \fi}
660
661\def\v_font_string_d % default fontstyle (expands to \s!Serif in font-ini)
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    %\edef\fontstyle{\csname\??typescriptdefaultstyles\fontclass\endcsname}%
672     \edef\fontstyle{\lastnamedcs}%
673   \else
674     \let\fontstyle\s!rm
675   \fi\fi}
676
677\protect \endinput
678