Debian Codegraph @

texmf-dist/tex/plain/zztex/zzfont.tex

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %
3 % Module: ZzTeX Font Facilities
4 %
5 % Synopsis: This module contains all the macros necessary to define type
6 % sizes, styles, and fonts.
7 %
8 % Author: Paul C. Anagnostopoulos
9 % Created: 28 August 1989
10 %
11 % Copyright 1989--2020 by Paul C. Anagnostopoulos
12 % under The MIT License (opensource.org/licenses/MIT)
13 %
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
16 % Baselines & Struts
17 % --------- - ------
18
19
20 \zremovePlaindef \strutbox
21 \definebox{\strutbox} % Strut for current type size.
22
23 \def \strut {%
24 \relax
25 \if \mathmodep
26 \copy \strutbox
27 \else
28 \unhcopy \strutbox
29 \fi}
30
31 \def \normalbaselines {%
32 \baselineskip = \the\baselinemultiplier\normalbaselineskip
33 \lineskiplimit = \normallineskiplimit
34 \lineskip = \normallineskip}
35
36 % Type Style & Size Definition
37 % ---- ----- - ---- ----------
38
39
40 % The following character set encodings are available. Odd numbers
41 % indicate italic; numbers > 20 indicate monospaced.
42
43 \chardef \encoderoman = 0 % Roman. %^encoding
44 \chardef \encodeitalic = 1 % Italic. %^encoding
45 \chardef \encodemathitalic = 3 % Math italic. %^encoding
46 \chardef \encodemathsymbol = 4 % Math symbols. %^encoding
47 \chardef \encodemathextended = 6 % Math extended symbols. %^encoding
48 \chardef \encodematharrow = 8 % Math arrows. %^encoding
49 \chardef \encodeother = 10 % Generic. %^encoding
50 \chardef \encodemono = 22 % Monospaced. %^encoding
51 \chardef \encodemonoitalic = 23 % Monospaced italic. %^encoding
52
53 \setlist \zfsizelist = {}
54 \setlist \zfstylelist = {}
55
56
57 \def \definetypestyle #1#2{% {\name}{\encoding}
58 \append{#1}{\zfstylelist}%
59 \zfwithfam{\zdeffam}{#1}%
60 \zfwithmat{\def}{#1}{\zfl}{}%
61 \zfwithmat{\xdef}{#1}{\zen}{#2}}
62
63 \def \definetypesize #1#2{% {\name}{size/baseline}
64 \append{#1}{\zfsizelist}%
65 \zdefsize #1#2/%
66 \zdefstrut #1#2/%
67 \zfbldsize{#1}}
68
69 \def \zdefsize #1#2/#3/{% \name size/baseline/
70 \zfwithmat{\xdef}{#1}{\zsz}{#2pt}}
71
72 \def \zdefstrut #1#2/#3/{% \name size/baseline/
73 {\calculate \tdimena = {#3pt,P,70}%
74 \tdimenb = #3pt\relax
75 \advance \tdimenb by -\tdimena
76 \zfwithmat{\xdef}{#1}{\zst}{height \the\tdimena\space depth \the\tdimenb}}}
77
78
79 % A few useful predicates.
80
81 \def \typestylep #1{% {\style}
82 \xtokeqlp{\the\typestyle}{#1}}
83
84 \def \italicencodingp {%
85 \oddp{\typeencoding}}
86
87 \def \monoencodingp {%
88 \gtrp{\typeencoding}{20}}
89
90 % Commands to set font parameters.
91
92 \def \setstylefontparam #1#2#3{% {\style}{param}{value}
93 \zfwithmat\maplistlf {#1}{\zfl}{%
94 \zfsetfp{##1}{#2}{#3}}}
95
96 \def \setstylehyphenchar #1#2{% {\style}{number}
97 \setstylefontparam{#1}{-2}{#2}}
98
99 \def \setstyleskewchar #1#2{% {\style}{number}
100 \setstylefontparam{#1}{-1}{#2}}
101
102 \def \zfsetfp #1#2#3{% {font}{param}{value}
103 \if \eqlp{#2}{-2}%
104 \hyphenchar #1=#3\relax
105 \else\if \eqlp{#2}{-1}%
106 \skewchar #1=#3\relax
107 \else
108 \fontdimen#2#1=#3\relax
109 \fi\fi}
110
111 % Style Relations
112 % ----- ---------
113
114
115 \def \definestylerelation #1#2#3{% {\style}{\relation}{\style}
116 \zfwithmat{\gdef}{#1}{#2}{#3}%
117 \gdef #2{\bgroup \zfrelstyle{#2}%
118 \if \italicencodingp \aftergroup \/\fi
119 \let \znext}}
120
121 \def \zfrelstyle #1{% {\relation}
122 \if \mathmodep
123 \ztoksa = \expandaftertwice{\zfmat\math#1}%
124 \expandafter\ifx \the\ztoksa\relax
125 \zfnorelstyle{math}{#1}%
126 \fi
127 \else
128 \ztoksa = \expandafterthrice{\expandafter\zfmat\the\typestyle#1}%
129 \expandafter\ifx \the\ztoksa\relax
130 \zfnorelstyle{\the\typestyle}{#1}%
131 \fi
132 \fi
133 \the\ztoksa}
134
135 \def \zfnorelstyle #1#2{%
136 \error{norelstyle}
137 {The current `#1' style has no related style for `\string#2'}}
138
139 % Font Definition
140 % ---- ----------
141
142
143 \setlist \ztfmlist = {}%
144
145
146 \def \definefont #1#2{% {\name}{tfm at size}
147 \global\font #1 = #2\relax
148 \zregistertfm #2\zmark
149 \if \zcommonencoding
150 \if \andp{\dimposp{\fontdimen7#1}}{\dimlssp{\fontdimen7#1}{.1pt}}%
151 \fontdimen7#1 = \fontdimen2#1\relax % Unlock it.
152 \else\if \dimeqlp{\fontdimen7#1}{\fontdimen2#1}
153 \relax % Already unlocked.
154 \else
155 \error{lockedfont}{The TFM for font `#2' is locked}%
156 \fi\fi
157 \fi}
158
159 \def \zregistertfm #1 #2\zmark{% tfm at size\zmark
160 \member{\ztfmreg}{#1}{\ztfmlist}%
161 \if \notp{\ztfmreg}\append{#1}{\ztfmlist}\fi}
162
163 \def \fontinterwordspacing #1#2{% {font}{factor}
164 \fontdimen2#1= #2\fontdimen2#1%
165 \fontdimen3#1= #2\fontdimen3#1%
166 \fontdimen4#1= #2\fontdimen4#1%
167 \fontdimen7#1= #2\fontdimen7#1}
168
169 % Font Selection
170 % ---- ---------
171
172
173 \definetoks{\typesizename} % Current type size name.
174 \definedimen{\typesize}{0pt} % Current type size in points.
175 \definetoks{\typestyle} % Current type style.
176 \definecount{\typeencoding}{0} % Current type encoding.
177
178
179 % Equal signs and by's have been omitted for the sake of efficiency.
180
181 \def \setfont #1#2#3{% {\size}{\style}{\font}
182 \setfontmath{#1}{#2}{#3}{\nullfont}{\nullfont}}
183
184 \def \setfontmath #1#2#3#4#5{% {\size}{\style}{\text}{\script}{\scriptscript}
185 \edef \zfam {\zffam{#2}}%
186 \zfwithmat{\xdef}{#1}{#2}{%
187 \textfont \zfam #3%
188 \scriptfont \zfam #4%
189 \scriptscriptfont \zfam #5%
190 \def \noexpand#2{%
191 \typestyle {\noexpand#2}%
192 \typeencoding \zfmat{#2}{\zen}%
193 #3%
194 \fam \zfam}}%
195 \zfbldsize{#1}%
196 \zfaddfont{#2}{#3}%
197 \zfaddfont{#2}{#4}%
198 \zfaddfont{#2}{#5}}
199
200 \def \zfbldsize #1{% {\size}
201 {\gdef #1{}
202 \maplist{\zfaddstyle{#1}{##1}}{\zfstylelist}%
203 \ztoksa \expandafter{#1}%
204 \xdef #1{%
205 \typesizename {\noexpand#1}%
206 \typesize \zfmat{#1}{\zsz}%
207 \the\ztoksa
208 \setbox\strutbox \hbox{\vrule \zfmat{#1}{\zst} width 0pt}%
209 \normalbaselineskip \ht\strutbox
210 \advance \normalbaselineskip \dp\strutbox
211 \noexpand\normalbaselines
212 \typestyle {none}\nullfont \fam -1\relax}}}
213
214 \def \zfaddstyle #1#2{% {\size}{\style}
215 \ztoksa \expandafter{#1}%
216 \ztoksb \expandaftertwice{\zfmat{#1}{#2}}%
217 \expandafter\ifx \the\ztoksb\relax
218 \xdef #1{\the\ztoksa
219 \noexpand\zclearfam{\zffam{#2}}%
220 \def \noexpand#2{\noexpand\zfundef{\noexpand#1}{\noexpand#2}}}%
221 \else
222 \xdef #1{\the\ztoksa \the\ztoksb}%
223 \fi}
224
225 \def \zfaddfont #1#2{% {\style}{font}
226 \zfwithmat{\appendlf}{#1}{\zfl}{#2}}
227
228
229 % This macro clears out a family so TeX can't set math in it.
230
231 \def \zclearfam #1{% {family}
232 \textfont #1 \nullfont
233 \scriptfont #1 \nullfont
234 \scriptscriptfont #1 \nullfont}
235
236 % This macro is called if the user selects a type style that has no font
237 % in the current size.
238
239 \def \zfundef #1#2{% {\size}{\style}
240 \error{nofontset}
241 {No font has been set for size `\string#1' style `\string#2'}}
242
243 % Miscellaneous
244 % -------------
245
246
247 % The following definition allows the user to write:
248 % \withfont{\bf Hi there}
249
250 \let \withfont = \relax
251
252 % This macro helps with defining math fonts.
253
254 \def \definemathfonts #1#2#3#4#5#6{% {prefix}{rm-font}{mit}{msy}{mex}{size}
255 \edef \znext {%
256 \noexpand\definefont{\name{#1rm}}{#2 at #6}%
257 \noexpand\definefont{\name{#1mit}}{#3 at #6}%
258 \noexpand\definefont{\name{#1msy}}{#4 at #6}%
259 \noexpand\definefont{\name{#1mex}}{#5 at #6}}%
260 \znext}
261
262 % This macro helps with setting math fonts.
263
264 \def \setmathfonts #1#2#3#4{% {\size}{\text}{\script}{\scriptscript}
265 \edef \znext {%
266 \noexpand\setfontmath{\noexpand#1}{\noexpand\rm}%
267 {\name{#2rm}}{\name{#3rm}}{\name{#4rm}}%
268 \noexpand\setfontmath{\noexpand#1}{\noexpand\mit}%
269 {\name{#2mit}}{\name{#3mit}}{\name{#4mit}}%
270 \noexpand\setfontmath{\noexpand#1}{\noexpand\msy}%
271 {\name{#2msy}}{\name{#3msy}}{\name{#4msy}}%
272 \noexpand\setfontmath{\noexpand#1}{\noexpand\mex}%
273 {\name{#2mex}}{\name{#2mex}}{\name{#2mex}}}%
274 \znext}
275
276 % Measuring Things
277 % --------- ------
278
279
280 \definebox{\zmeasbox}
281
282
283 \def \measureascenderheight #1{% {\dimen}
284 \zsetmeasbox{bdfhijklt}%
285 #1 = \ht\zmeasbox}
286
287 \def \measurecapheight #1{% {\dimen}
288 \zsetmeasbox{ABCDEFGHIJKLMNOPQRSTUVWXYZ}%
289 #1 = \ht\zmeasbox}
290
291 \def \measuredescenderdepth #1{% {\dimen}
292 \zsetmeasbox{gjpqy}%
293 #1 = \dp\zmeasbox}
294
295 \def \measuredigitheight #1{% {\dimen}
296 \zsetmeasbox{0123456789}%
297 #1 = \ht\zmeasbox}
298
299 \def \measuredigitwidth #1{% {\dimen}
300 \zsetmeasbox{0}%
301 #1 = \wd\zmeasbox}
302
303 \def \measureemwidth #1{% {\dimen}
304 #1 = 1em}
305
306 \def \measurespacewidth #1{% {\dimen}
307 #1 = \fontdimen2\font}
308
309 \def \measurexheight #1{% {\dimen}
310 #1 = 1ex}
311
312 \def \measuretextwidth #1#2{% {\dimen}{text}
313 \zsetmeasbox{#2}%
314 #1 = \wd\zmeasbox}
315
316 \def \measuretextheight #1#2{% {\dimen}{text}
317 \zsetmeasbox{#2}%
318 #1 = \ht\zmeasbox}
319
320 \def \measuretextdepth #1#2{% {\dimen}{text}
321 \zsetmeasbox{#2}%
322 #1 = \dp\zmeasbox}
323
324 \def \zsetmeasbox #1{\setbox\zmeasbox = \hbox{#1}}
325
326 \def \definewidthdimen #1#2{% {\dimen}{text}
327 \definedimen{#1}{0pt}%
328 \measuretextwidth{#1}{#2}}
329
330 % Utilities
331 % ---------
332
333
334 \def \zfmat #1#2{% {\size}{\style}
335 \csname zf\expandafter\discardtok \string#1%
336 \expandafter\discardtok \string#2\endcsname}
337
338 \def \zfwithmat #1#2#3{% {\command}{\size}{\style}
339 \expandafter#1\csname zf\expandafter\discardtok \string#2%
340 \expandafter\discardtok \string#3\endcsname}
341
342
343 \def \zffam #1{% {\style}
344 \csname \expandafter\discardtok \string#1fam\endcsname}
345
346 \def \zfwithfam #1#2{% {\command}{\style}
347 \expandafter#1\csname \expandafter\discardtok \string#2fam\endcsname}
348
349 % Built-in Styles
350 % -------- ------
351
352
353 \zremovePlaindef \itfam
354 \zremovePlaindef \bffam
355 \zremovePlaindef \ttfam
356
357 % Family Name
358 \definetypestyle{\rm}{\encoderoman} % 0 RoMan
359 \definetypestyle{\mit}{\encodemathitalic} % 1 Math ITalic
360 \definetypestyle{\msy}{\encodemathsymbol} % 2 Math SYmbol
361 \definetypestyle{\mex}{\encodemathextended} % 3 Math EXtended symbol
362 \definetypestyle{\cal}{\encoderoman} % 4 CALigraphic letters
363 \definetypestyle{\bbb}{\encoderoman} % 5 BlackBoard Bold
364 \definetypestyle{\it}{\encodeitalic} % 6 ITalic
365 \definetypestyle{\bf}{\encoderoman} % 7 Bold Face
366 \definetypestyle{\bi}{\encodeitalic} % 8 Bold Italic
367 \definetypestyle{\tt}{\encodemono} % 9 monospaced (TypewriTer)
368
369 % Note: style \math is reserved for math mode.
370
371 \definestylerelation{\math}{\bbbold}{\bbb}
372 \definestylerelation{\math}{\bold}{\bf}
373 \definestylerelation{\rm}{\bold}{\bf}
374 \definestylerelation{\it}{\bold}{\bi}
375 \definestylerelation{\math}{\callig}{\cal}
376 \definestylerelation{\rm}{\callig}{\cal}
377 \definestylerelation{\rm}{\emph}{\it}
378 \definestylerelation{\it}{\emph}{\rm}
379 \definestylerelation{\bf}{\emph}{\bi}
380 \definestylerelation{\bi}{\emph}{\bf}
381 \definestylerelation{\math}{\fraktur}{\frk}
382 \definestylerelation{\tt}{\meta}{\it}
383 \definestylerelation{\math}{\roman}{\rm}
384 \definestylerelation{\rm}{\roman}{\rm}
385 \definestylerelation{\it}{\roman}{\rm}
386 \definestylerelation{\bf}{\roman}{\rm}
387 \definestylerelation{\tt}{\roman}{\rm}
388 \definestylerelation{\rm}{\smallcaps}{\sc}
389
390 % We do not define any sizes or fonts. They just take up memory.
391
392 % Doodad Font
393 % ------ ----
394
395
396 \def \zrequiredoodad #1#2{% {\name}{size}
397 \if \undefinedp{\zfdoodad#2}%
398 \withname\definefont {\zfdoodad#2}{zztexorn at #2}%
399 \fi
400 \edef \znext {\let \noexpand#1\name{\zfdoodad#2}}%
401 \znext}
402
403 % Font Style Summary
404 % ---- ----- -------
405
406
407 {\catcode`\_ = \catactive
408
409 \gdef \zfontsummary #1{% {font-list?}
410 {\def _{\space}%
411 \writelog{}%
412 \writelog{Type Styles:}%
413 \writelog{}%
414 \writelog{Name_____Math Family}%
415 \writelog{----_____-----------}%
416 \maplist{\zfsone{##1}}{\zfstylelist}%
417 \if #1%
418 \writelog{}%
419 \maplist{\writelog{ZzTeX: Font used: ##1}}{\ztfmlist}%
420 \fi
421 \writelog{}}}
422
423 \gdef \zfsone #1{%
424 \tcounta = \name{#1fam}%
425 \writelog{\string #1______%
426 \if \lssp{\tcounta}{10}%
427 _\number\tcounta
428 \else\if \lssp{\tcounta}{15}%
429 \number\tcounta
430 \else
431 ---%
432 \fi\fi}}
433
434 }% \catcode
435
436 % TFM List File
437 % --- ---- ----
438
439
440 \definewrite{\ztfmlistfile}
441
442
443 \def \zopentfmlist {%
444 \if \zcommonencoding
445 \immediate\openout \ztfmlistfile = tfmlist.zzz\relax
446 \immediate\write \ztfmlistfile {\jobname}%
447 \fi}
448
449 \def \zwritetfmlist {%
450 \if \zcommonencoding
451 \maplist{\immediate\write \ztfmlistfile {##1}}{\ztfmlist}%
452 \immediate\closeout \ztfmlistfile
453 \fi}