font-set.mkvi /size: 6368 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=font-set,
3%D        version=2011.01.13, % (copied fron font-ini)
4%D          title=\CONTEXT\ Font Macros,
5%D       subtitle=Initial Loading,
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 Font Macros / Initial Loading}
15
16\unprotect
17
18%D Defining fonts using \type{\definebodyfont} takes time, so we
19%D prefer to predefine at least the Computer Modern Roman
20%D fonts. However, loading all those fonts at definition time
21%D would take both time and space. But even worse, once fonts
22%D are loaded into memory, their encoding vector is fixed,
23%D which is a handicap when we want to distribute the compact
24%D \type{fmt} files. So what we want to do is defining fonts in
25%D a way that postpones the loading. We accomplish this by only
26%D loading the fonts when we switch to another bodyfont size.
27%D Among the other alternatives, such as loading the font at
28%D the moment of activation and redefining the activation
29%D macro afterwards, this proved to be the most efficient
30%D alternative.
31%D
32%D The next few macros take care of the one exeption on this
33%D scheme. When at format generation time we load the default
34%D font file, the one that defines the Computer Modern Fonts,
35%D we don't want the fonts metrics to end up in the format
36%D file, so we temporary prohibit loading. This means that at
37%D runtime we have to load the default bodyfont size just before
38%D we start typesetting.
39
40% \enablemode[lmmath]
41
42\let\m_font_fallback_name\empty
43
44% keep as reference:
45%
46% \def\font_preloads_reset_nullfont % this is needed because some macro packages (tikz) misuse \nullfont
47%   {\dorecurse\plusseven{\fontdimen\recurselevel\nullfont\zeropoint}% keep en eye on this as:
48%    \clf_resetnullfont % in luatex 0.70 this will also do the previous
49%    \glet\font_preloads_reset_nullfont\relax}
50
51\def\font_preload_check_mode
52  {\doifelsemode{lmmath}
53     {\def\m_font_fallback_name{modern-designsize-virtual}}% this will stay
54     {\def\m_font_fallback_name{modern-designsize}}%       % this might become 'modern'
55   \glet\font_preload_check_mode\relax}
56
57\def\font_preload_default_fonts
58  {\font_preloads_reset
59   \font_preload_check_mode
60   \setupbodyfont[\m_font_fallback_name,\fontstyle,\fontbody]%
61   \showmessage\m!fonts6{fallback \m_font_fallback_name\space \fontstyle\normalspace\normalizedbodyfontsize}}
62
63\def\font_preload_default_fonts_mm
64  {\font_preload_check_mode
65   \writestatus\m!fonts{preloading \m_font_fallback_name\space (math)}%
66   \definetypeface[\fontclass][\s!mm][\s!math][\m_font_fallback_name][\s!default]%
67   \showmessage\m!fonts6{fallback \m_font_fallback_name\space mm \normalizedbodyfontsize}}
68
69\def\font_preload_default_fonts_tt
70  {\font_preload_check_mode
71   \writestatus\m!fonts{preloading \m_font_fallback_name\space (mono)}%
72   \definetypeface[\fontclass][\s!tt][\s!mono][\m_font_fallback_name][\s!default]%
73   \showmessage\m!fonts6{fallback \m_font_fallback_name\space tt \normalizedbodyfontsize}}
74
75\def\font_preloads_reset
76  {\glet\font_preload_default_fonts   \relax
77  %\glet\font_preload_default_fonts_tt\relax
78  %\glet\font_preload_default_fonts_mm\relax
79   \glet\font_preloads_zero_stage     \relax
80   \glet\font_preloads_first_stage    \relax
81   \glet\font_preloads_second_stage   \relax
82  %\glet\font_preloads_third_stage    \relax
83   \glet\fourthstagepreloadfonts      \relax
84   \global\everyhbox\emptytoks
85   \global\everyvbox\emptytoks
86   % old: \font_preloads_reset_nullfont, new:
87   \clf_resetnullfont}
88
89\appendtoks
90    \font_preloads_reset
91\to \everystartnotext
92
93\def\font_preloads_reset_checked
94  {\glet\font_preload_default_fonts_tt\relax
95   \glet\font_preload_default_fonts_mm\relax
96   \glet\font_preloads_third_stage    \relax
97%  \glet\font_preloads_fourth_stage   \relax
98  }
99
100\def\font_preloads_zero_stage_indeed
101  {\definedfont[\s!file:lmmono10-regular sa 1]}
102
103\unexpanded\def\font_preloads_zero_stage
104  {\writestatus\m!fonts{beware: no fonts are loaded yet, using 'lm mono' in box}%
105   \glet\font_preloads_zero_stage\font_preloads_zero_stage_indeed
106   \font_preloads_zero_stage}
107
108\unexpanded\def\font_preloads_first_stage % % *nofonts -> *preloadfonts
109  {\doifelsemode{*preloadfonts}
110     {\font_preload_default_fonts
111      \writestatus\m!fonts{preloading latin modern fonts (first stage)}}
112     {\writestatus\m!fonts{latin modern fonts are not preloaded}}}
113
114\unexpanded\def\font_preloads_second_stage
115  {\writestatus\m!fonts{preloading latin modern fonts (second stage)}%
116   \font_preload_default_fonts}
117
118\unexpanded\def\font_preloads_third_stage % always
119  {\ifx\fontclass\empty
120     \writestatus\m!fonts{preloading latin modern fonts (third stage)}%
121     \font_preload_default_fonts
122     \font_preloads_reset
123   \else
124     \font_preloads_reset
125     \push_macro_fontstyle
126     \ifcsname\??fontclass\fontclass\s!mm\s!features\endcsname \else
127       \font_preload_default_fonts_mm
128     \fi
129     \ifcsname\??fontclass\fontclass\s!tt\s!features\endcsname \else
130       \font_preload_default_fonts_tt
131     \fi
132     \pop_macro_fontstyle
133     \font_preloads_reset_checked % reset third, mm and tt
134     \setupbodyfont[\fontstyle]%
135   \fi}
136
137\unexpanded\def\font_preloads_fourth_stage
138  {\begingroup
139   %ifzeropt\fontcharwd\font\number`!\relax
140   \setbox\scratchbox\hpack{\tf c o n t e x t}%
141   \ifzeropt\wd\scratchbox
142     \writeline
143     \writestatus\m!fonts{!! No bodyfont has been defined and no defaults have been}%
144     \writestatus\m!fonts{!! loaded (maybe due to a missing \string\starttext).}%
145     \writeline
146   \fi
147   \font_preloads_reset
148   \endgroup}
149
150\appendtoks
151    \everyhbox{\font_preloads_zero_stage}%
152    \everyvbox{\font_preloads_zero_stage}%
153\to \everydump
154
155\unexpanded\def\font_preloads_at_every_job {\font_preloads_first_stage }
156\unexpanded\def\font_preloads_at_start_text{\font_preloads_second_stage}
157\unexpanded\def\font_preloads_at_stop_text {\font_preloads_fourth_stage}
158\unexpanded\def\font_preloads_at_definition{\font_preloads_third_stage
159                                            \glet\font_preloads_at_definition\relax}
160
161% \unexpanded\def\checkpreloadedbodyfont % no \let here
162%   {\font_preloads_at_start_text}
163
164\protect \endinput
165