Debian Codegraph @

texk/web2c/omegaware/ovp2ovf.web

raw
1 %
2 % This file is part of the Omega project, which
3 % is based in the web2c distribution of TeX.
4 %
5 % Copyright (c) 1994--2000 John Plaice and Yannis Haralambous
6 % applies only to the changes to the original vptovf.web.
7 %
8 % This program by D. E. Knuth is not copyrighted and can be used freely.
9 % Version 1 was implemented in December 1989.
10 % Version 1.1 fixed some for-loop indices for stricter Pascal (April 1990).
11 % Version 1.2 fixed `nonexistent char 0' bug, and a bit more (September 1990).
12 % Version 1.3 has more robust `out_scaled' (March 1991).
13 % Version 1.4 (March 1995) initialized lk_step_ended (Armin K\"ollner).
14 % Version 1.5 (August 1998) corrected vf_fix(0) (Wayne Sullivan).
15 % Version 1.6 (January 2014) corrected possible end-of-line glitch (Ken Nakano),
16 % and get_fix now treats -- as + (Peter Breitenlohner).
17
18 % Version 1.0 of OVP2OVF (Month Year).
19 % Version 1.11 (February 2000).
20 % Version 1.12 (September 2009) various bug fixes by Peter Breitenlohner.
21 % Version 1.13 (January 2014) more bug fixes.
22
23 % Here is TeX material that gets inserted after \input webmac
24 \def\hang{\hangindent 3em\indent\ignorespaces}
25 \font\ninerm=cmr9
26 \let\mc=\ninerm % medium caps for names like SAIL
27 \def\PASCAL{Pascal}
28 \font\logo=logo10 % for the METAFONT logo
29 \def\MF{{\logo METAFONT}}
30
31 \def\(#1){} % this is used to make section names sort themselves better
32 \def\9#1{} % this is used for sort keys in the index
33
34 \def\title{OVP2OVF}
35 \def\contentspagenumber{201}
36 \def\topofcontents{\null
37 \titlefalse % include headline on the contents page
38 \def\rheader{\mainfont\hfil \contentspagenumber}
39 \vfill
40 \centerline{\titlefont The {\ttitlefont OVP2OVF} processor}
41 \vskip 15pt
42 \centerline{(Version 1.13, January 2014)}
43 \vfill}
44 \def\botofcontents{\vfill
45 \centerline{\hsize 5in\baselineskip9pt
46 \vbox{\ninerm\noindent
47 The preparation of this program
48 was supported in part by the National Science
49 Foundation and by the System Development Foundation. `\TeX' is a
50 trademark of the American Mathematical Society.}}}
51 \pageno=\contentspagenumber \advance\pageno by 1
52
53 @* Introduction.
54 The \.{OVP2OVF} utility program converts virtual-property-list (``\.{VPL}''
55 and ``\.{OVP}'') files into an equivalent pair of files called a virtual
56 font (``\.{OVF}'') file and an $\Omega$ font metric (``\.{OFM}'') file.
57 It also makes a thorough check of the given \.{VPL} or \.{OVP} file,
58 so that the \.{OVF} file should be acceptable to device drivers and
59 the \.{OFM} file should be acceptable to $\Omega$.
60
61 In the following documentation, all unchanged references to
62 the \.{VPtoVF} program and to \.{VPL}, \.{VF} and \.{TFM} files also apply to
63 the \.{OVP2OVF} program and to \.{OVP}, \.{OVF} and \.{OFM} files.
64
65 \indent\.{VPtoVF} is an extended version of the program \.{PLtoTF}, which
66 is part of the standard \TeX ware library.
67 \.{OVP2OVF} is an extended version of \.{VPtoVF} that allows
68 much larger fonts.
69 The idea of a virtual font was inspired by the work of David R. Fuchs
70 @^Fuchs, David Raymond@>
71 who designed a similar set of conventions in 1984 while developing a
72 device driver for ArborText, Inc. He wrote a somewhat similar program
73 called \.{PLFONT}.
74
75 The |banner| string defined here should be changed whenever \.{OVP2OVF}
76 gets modified.
77
78 @d banner=='This is OVP2OVF, Version 1.13' {printed when the program starts}
79
80 @ This program is written entirely in standard \PASCAL, except that
81 it has to do some slightly system-dependent character code conversion
82 on input. Furthermore, lower case letters are used in error messages;
83 they could be converted to upper case if necessary. The input is read
84 from |vpl_file|, and the output is written on |vf_file| and |tfm_file|;
85 error messages and
86 other remarks are written on the |output| file, which the user may
87 choose to assign to the terminal if the system permits it.
88 @^system dependencies@>
89
90 The term |print| is used instead of |write| when this program writes on
91 the |output| file, so that all such output can be easily deflected.
92
93 @d print(#)==write(#)
94 @d print_ln(#)==write_ln(#)
95
96 @p program OVP2OVF(@!vpl_file,@!vf_file,@!tfm_file,@!output);
97 label @<Labels in the outer block@>@/
98 const @<Constants in the outer block@>@/
99 type @<Types in the outer block@>@/
100 var @<Globals in the outer block@>@/
101 procedure initialize; {this procedure gets things started properly}
102 var @<Local variables for initialization@>@/
103 begin print_ln(banner);@/
104 @<Set initial values@>@/
105 end;
106
107 @ If the program has to stop prematurely, it goes to the
108 `|final_end|' (addition in OVP2OVF).
109
110 @d final_end=9999 {label for the end of it all}
111
112 @<Labels...@>=final_end;
113
114 @ The following parameters can be changed at compile time to extend or
115 reduce \.{VPtoVF}'s capacity.
116
117 @d char_max=@"FFFF
118 @d xchar_max=char_max+1
119 @d xxchar_max=xchar_max+1
120 @d mem_max=xxchar_max+xxchar_max+xxchar_max+xxchar_max
121 @#
122 @d width_max=@"FFFF
123
124 @<Constants...@>=
125 @!ofm_type=0; {16-bit OFM; sufficient for most purposes}
126 @!max_char=char_max; {the largest character number in a font}
127 @!xmax_char=xchar_max; {|max_char|+1}
128 @!xxmax_char=xxchar_max;{|max_char|+2}
129 @!mem_size=mem_max; {|max_char|*4+8}
130 @!max_font=1000; {the largest font number}
131 @!xmax_font=1001; {|max_font|+1}
132 @!xxmax_font=1002; {|max_font|+2}
133 @!max_width=width_max; {the largest character width number}
134 @!max_height=255; {the largest character height number}
135 @!max_depth=255; {the largest character depth number}
136 @!max_italic=255; {the largest character italic correction number}
137 @!buf_size=60; {length of lines displayed in error messages}
138 @!max_header_bytes=100; {four times the maximum number of words allowed in
139 the \.{TFM} file header block, must be 1024 or less}
140 @!vf_size=200000; {maximum length of |vf| data, in bytes}
141 @!max_stack=100; {maximum depth of simulated \.{DVI} stack}
142 @!max_param_words=100; {the maximum number of \.{fontdimen} parameters allowed}
143 @!max_lig_steps=800000; {maximum length of ligature program}
144 @!xmax_label=800001; {must be greater than |max_lig_steps|}
145 @!hash_size=130003; {preferably a prime number, a bit larger than |max_lig_steps|, the number
146 of character pairs in lig/kern steps}
147 @!hash_mult=16007; {another prime}
148 @!max_kerns=100000; {the maximum number of distinct kern values}
149
150 @ Here are some macros for common programming idioms.
151
152 @d incr(#) == #:=#+1 {increase a variable by unity}
153 @d decr(#) == #:=#-1 {decrease a variable by unity}
154 @d do_nothing == {empty statement}
155
156 @* Property list description of font metric data.
157 The idea behind \.{VPL} files is that precise details about fonts, i.e., the
158 facts that are needed by typesetting routines like \TeX, sometimes have to
159 be supplied by hand. The nested property-list format provides a reasonably
160 convenient way to do this.
161
162 A good deal of computation is necessary to parse and process a
163 \.{VPL} file, so it would be inappropriate for \TeX\ itself to do this
164 every time it loads a font. \TeX\ deals only with the compact descriptions
165 of font metric data that appear in \.{TFM} files. Such data is so compact,
166 however, it is almost impossible for anybody but a computer to read it.
167
168 Device drivers also need a compact way to describe mappings from \TeX's idea
169 of a font to the actual characters a device can produce. They can do this
170 conveniently when given a packed sequence of bytes called a \.{VF} file.
171
172 The purpose of \.{VPtoVF} is to convert from a human-oriented file of text
173 to computer-oriented files of binary numbers. There's a companion program,
174 \.{VFtoVP}, which goes the other way.
175
176 @<Glob...@>=
177 @!vpl_file:text;
178
179 @ @<Set init...@>=
180 reset(vpl_file);
181
182 @ A \.{VPL} file is like a \.{PL} file with a few extra features, so we
183 can begin to define it by reviewing the definition of \.{PL} files. The
184 material in the next few sections is copied from the program \.{PLtoTF}.
185 An \.{OVP} file is simply a \.{VPL} file that does not restrict fonts
186 to 256 characters.
187
188 A \.{PL} file is a list of entries of the form
189 $$\.{(PROPERTYNAME VALUE)}$$
190 where the property name is one of a finite set of names understood by
191 this program, and the value may itself in turn be a property list.
192 The idea is best understood by looking at an example, so let's consider
193 a fragment of the \.{PL} file for a hypothetical font.
194 $$\vbox{\halign{\.{#}\hfil\cr
195 (FAMILY NOVA)\cr
196 (FACE F MIE)\cr
197 (CODINGSCHEME ASCII)\cr
198 (DESIGNSIZE D 10)\cr
199 (DESIGNUNITS D 18)\cr
200 (COMMENT A COMMENT IS IGNORED)\cr
201 (COMMENT (EXCEPT THIS ONE ISN'T))\cr
202 (COMMENT (ACTUALLY IT IS, EVEN THOUGH\cr
203 \qquad\qquad IT SAYS IT ISN'T))\cr
204 (FONTDIMEN\cr
205 \qquad (SLANT R -.25)\cr
206 \qquad (SPACE D 6)\cr
207 \qquad (SHRINK D 2)\cr
208 \qquad (STRETCH D 3)\cr
209 \qquad (XHEIGHT R 10.55)\cr
210 \qquad (QUAD D 18)\cr
211 \qquad )\cr
212 (LIGTABLE\cr
213 \qquad (LABEL C f)\cr
214 \qquad (LIG C f O 200)\cr
215 \qquad (SKIP D 1)\cr
216 \qquad (LABEL O 200)\cr
217 \qquad (LIG C i O 201)\cr
218 \qquad (KRN O 51 R 1.5)\cr
219 \qquad (/LIG C ? C f)\cr
220 \qquad (STOP)\cr
221 \qquad )\cr
222 (CHARACTER C f\cr
223 \qquad (CHARWD D 6)\cr
224 \qquad (CHARHT R 13.5)\cr
225 \qquad (CHARIC R 1.5)\cr
226 \qquad )\cr}}$$
227 This example says that the font whose metric information is being described
228 belongs to the hypothetical
229 \.{NOVA} family; its face code is medium italic extended;
230 and the characters appear in ASCII code positions. The design size is 10 points,
231 and all other sizes in this \.{PL} file are given in units such that 18 units
232 equals the design size. The font is slanted with a slope of $-.25$ (hence the
233 letters actually slant backward---perhaps that is why the family name is
234 \.{NOVA}). The normal space between words is 6 units (i.e., one third of
235 the 18-unit design size), with glue that shrinks by 2 units or stretches by 3.
236 The letters for which accents don't need to be raised or lowered are 10.55
237 units high, and one em equals 18 units.
238
239 The example ligature table is a bit trickier. It specifies that the
240 letter \.f followed by another \.f is changed to code @'200, while
241 code @'200 followed by \.i is changed to @'201; presumably codes @'200
242 and @'201 represent the ligatures `ff' and `ffi'. Moreover, in both cases
243 \.f and @'200, if the following character is the code @'51 (which is a
244 right parenthesis), an additional 1.5 units of space should be inserted
245 before the @'51. (The `\.{SKIP}~\.D~\.1' skips over one \.{LIG} or
246 \.{KRN} command, which in this case is the second \.{LIG}; in this way
247 two different ligature/kern programs can come together.)
248 Finally, if either \.f or @'200 is followed by a question mark,
249 the question mark is replaced by \.f and the ligature program is
250 started over. (Thus, the character pair `\.{f?}' would actually become
251 the ligature `ff', and `\.{ff?}' or `\.{f?f}' would become `fff'. To
252 avoid this restart procedure, the \.{/LIG} command could be replaced
253 by \.{/LIG>}; then `\.{f?}' would become `f\kern0ptf' and `\.{f?f}'
254 would become `f\kern0ptff'.)
255
256 Character \.f itself is 6 units wide and 13.5 units tall, in this example.
257 Its depth is zero (since \.{CHARDP} is not given), and its italic correction
258 is 1.5 units.
259
260 @ The example above illustrates most of the features found in \.{PL} files.
261 Note that some property names, like \.{FAMILY} or \.{COMMENT}, take a
262 string as their value; this string continues until the first unmatched
263 right parenthesis. But most property names, like \.{DESIGNSIZE} and \.{SLANT}
264 and \.{LABEL}, take a number as their value. This number can be expressed in
265 a variety of ways, indicated by a prefixed code; \.D stands for decimal,
266 \.H for hexadecimal, \.O for octal, \.R for real, \.C for character, and
267 \.F for ``face.'' Other property names, like \.{LIG}, take two numbers as
268 their value. And still other names, like \.{FONTDIMEN} and \.{LIGTABLE} and
269 \.{CHARACTER}, have more complicated values that involve property lists.
270
271 A property name is supposed to be used only in an appropriate property
272 list. For example, \.{CHARWD} shouldn't occur on the outer level or
273 within \.{FONTDIMEN}.
274
275 The individual property-and-value pairs in a property list can appear in
276 any order. For instance, `\.{SHRINK}' precedes `\.{STRETCH}' in the example
277 above, although the \.{TFM} file always puts the stretch parameter first.
278 One could even give the information about characters like `\.f' before
279 specifying the number of units in the design size, or before specifying the
280 ligature and kerning table. However, the \.{LIGTABLE} itself is an exception
281 to this rule; the individual elements of the \.{LIGTABLE} property list
282 can be reordered only to a certain extent without changing the meaning
283 of that table.
284
285 If property-and-value pairs are omitted, a default value is used. For example,
286 we have already noted that the default for \.{CHARDP} is zero. The default
287 for {\sl every\/} numeric value is, in fact, zero, unless otherwise stated
288 below.
289
290 If the same property name is used more than once, \.{VPtoVF} will not notice
291 the discrepancy; it simply uses the final value given. Once again, however, the
292 \.{LIGTABLE} is an exception to this rule; \.{VPtoVF} will complain if there
293 is more than one label for some character. And of course many of the
294 entries in the \.{LIGTABLE} property list have the same property name.
295
296 @ A \.{VPL} file also includes information about how to create each character,
297 by typesetting characters from other fonts and/or by drawing lines, etc.
298 Such information is the value of the `\.{MAP}' property, which can be
299 illustrated as follows:
300 $$\vbox{\halign{\.{#}\hfil\cr
301 (MAPFONT D 0 (FONTNAME Times-Roman))\cr
302 (MAPFONT D 1 (FONTNAME Symbol))\cr
303 (MAPFONT D 2 (FONTNAME cmr10)(FONTAT D 20))\cr
304 (CHARACTER O 0 (MAP (SELECTFONT D 1)(SETCHAR C G)))\cr
305 (CHARACTER O 76 (MAP (SETCHAR O 277)))\cr
306 (CHARACTER D 197 (MAP\cr
307 \qquad(PUSH)(SETCHAR C A)(POP)\cr
308 \qquad(MOVEUP R 0.937)(MOVERIGHT R 1.5)(SETCHAR O 312)))\cr
309 (CHARACTER O 200 (MAP (MOVEDOWN R 2.1)(SETRULE R 1 R 8)))\cr
310 (CHARACTER O 201 (MAP\cr
311 \qquad (SPECIAL ps: /SaveGray currentgray def .5 setgray)\cr
312 \qquad (SELECTFONT D 2)(SETCHAR C A)\cr
313 \qquad (SPECIAL ps: SaveGray setgray)))\cr
314 }}$$
315 (These specifications appear in addition to the conventional \.{PL}
316 information. The \.{MAP} attribute can be mixed in with other attributes
317 like \.{CHARWD} or it can be given separately.)
318
319 In this example, the virtual font is composed of characters that can be
320 fabricated from three actual fonts, `\.{Times-Roman}',
321 `\.{Symbol}', and `\.{cmr10} \.{at} \.{20\\u}' (where \.{\\u}
322 is the unit size in this \.{VPL} file). Character |@'0| is typeset as
323 a `G' from the symbol font. Character |@'76| is typeset as character |@'277|
324 from the ordinary Times font. (If no other font is selected, font
325 number~0 is the default. If no \.{MAP} attribute is given, the default map
326 is a character of the same number in the default font.)
327
328 Character 197 (decimal) is more interesting: First an A is typeset (in the
329 default font Times), and this is enclosed by \.{PUSH} and \.{POP} so that
330 the original position is restored. Then the accent character |@'312| is
331 typeset, after moving up .937 units and right 1.5 units.
332
333 To typeset character |@'200| in this virtual font, we move down 2.1 units,
334 then typeset a rule that is 1 unit high and 8 units wide.
335
336 Finally, to typeset character |@'201|, we do something that requires a
337 special ability to interpret PostScript commands; this example
338 sets the PostScript ``color'' to 50\char`\%\ gray and typesets an `A'
339 from \.{cmr10} \.{at} \.{20\\u} in that color.
340
341 In general, the \.{MAP} attribute of a virtual character can be any sequence
342 of typesetting commands that might appear in a page of a \.{DVI} file.
343 A single character might map into an entire page.
344
345 @ But instead of relying on a hypothetical example, let's consider a complete
346 grammar for \.{VPL} files, beginning with the (unchanged) grammatical rules
347 for \.{PL} files. At the outer level, the following property names
348 are valid in any \.{PL} file:
349
350 \yskip\hang\.{CHECKSUM} (four-byte value). The value, which should be a
351 nonnegative integer less than $2^{32}$, is used to identify a particular
352 version of a font; it should match the check sum value stored with the font
353 itself. An explicit check sum of zero is used to bypass
354 check sum testing. If no checksum is specified in the \.{VPL} file,
355 \.{VPtoVF} will compute the checksum that \MF\ would compute from the
356 same data.
357
358 \yskip\hang\.{DESIGNSIZE} (numeric value, default is 10). The value, which
359 should be a real number in the range |1.0<=x<2048|, represents the default
360 amount by which all quantities will be scaled if the font is not loaded
361 with an `\.{at}' specification. For example, if one says
362 `\.{\\font\\A=cmr10 at 15pt}' in \TeX\ language, the design size in the \.{TFM}
363 file is ignored and effectively replaced by 15 points; but if one simply
364 says `\.{\\font\\A=cmr10}' the stated design size is used. This quantity is
365 always in units of printer's points.
366
367 \yskip\hang\.{DESIGNUNITS} (numeric value, default is 1). The value
368 should be a positive real number; it says how many units equals the design
369 size (or the eventual `\.{at}' size, if the font is being scaled). For
370 example, suppose you have a font that has been digitized with 600 pixels per
371 em, and the design size is one em; then you could say `\.{(DESIGNUNITS R 600)}'
372 if you wanted to give all of your measurements in units of pixels.
373
374 \yskip\hang\.{CODINGSCHEME} (string value, default is `\.{UNSPECIFIED}').
375 The string should not contain parentheses, and its length must be less than 40.
376 It identifies the correspondence between the numeric codes and font characters.
377 (\TeX\ ignores this information, but other software programs make use of it.)
378
379 \yskip\hang\.{FAMILY} (string value, default is `\.{UNSPECIFIED}').
380 The string should not contain parentheses, and its length must be less than 20.
381 It identifies the name of the family to which this font belongs, e.g.,
382 `\.{HELVETICA}'. (\TeX\ ignores this information; but it is needed, for
383 example, when converting \.{DVI} files to \.{PRESS} files for Xerox
384 equipment.)
385
386 \yskip\hang\.{FACE} (one-byte value). This number, which must lie between
387 0 and 255 inclusive, is a subsidiary ident\-ifi\-ca\-tion of the font within its
388 family. For example, bold italic condensed fonts might have the same family name
389 as light roman extended fonts, differing only in their face byte. (\TeX\
390 ignores this information; but it is needed, for example, when converting
391 \.{DVI} files to \.{PRESS} files for Xerox equipment.)
392
393 \yskip\hang\.{SEVENBITSAFEFLAG} (string value, default is `\.{FALSE}'). The
394 value should start with either `\.T' (true) or `\.F' (false). If true, character
395 codes less than 128 cannot lead to codes of 128 or more via ligatures or
396 charlists or extensible characters. (\TeX82 ignores this flag, but older
397 versions of \TeX\ would only accept \.{TFM} files that were seven-bit safe.)
398 \.{VPtoVF} computes the correct value of this flag and gives an error message
399 only if a claimed ``true'' value is incorrect.
400
401 \yskip\hang\.{HEADER} (a one-byte value followed by a four-byte value).
402 The one-byte value should be between 18 and a maximum limit that can be
403 raised or lowered depending on the compile-time setting of |max_header_bytes|.
404 The four-byte value goes into the header word whose index is the one-byte
405 value; for example, to set |header[18]:=1|, one may write
406 `\.{(HEADER D 18 O 1)}'. This notation is used for header information that
407 is presently unnamed. (\TeX\ ignores it.)
408
409 \yskip\hang\.{FONTDIMEN} (property list value). See below for the names
410 allowed in this property list.
411
412 \yskip\hang\.{LIGTABLE} (property list value). See below for the rules
413 about this special kind of property list.
414
415 \yskip\hang\.{BOUNDARYCHAR} (integer value). If this character appears in
416 a \.{LIGTABLE} command, it matches ``end of word'' as well as itself.
417 If no boundary character is given and no \.{LABEL} \.{BOUNDARYCHAR} occurs
418 within \.{LIGTABLE}, word boundaries will not affect ligatures or kerning.
419
420 \yskip\hang\.{CHARACTER}. The value is an integer followed by
421 a property list. The integer represents the number of a character that is
422 present in the font; the property list of a character is defined below.
423 The default is an empty property list.
424
425 @ Numeric property list values can be given in various forms identified by
426 a prefixed letter.
427
428 \yskip\hang\.C denotes an ASCII character, which should be a standard visible
429 character that is not a parenthesis. The numeric value will therefore be
430 between @'41 and @'176 but not @'50 or @'51.
431
432 \yskip\hang\.D denotes an unsigned decimal integer, which must be
433 less than $2^{32}$, i.e., at most `\.{D 4294967295}'.
434
435 \yskip\hang\.F denotes a three-letter Xerox face code; the admissible codes
436 are \.{MRR}, \.{MIR}, \.{BRR}, \.{BIR}, \.{LRR}, \.{LIR}, \.{MRC}, \.{MIC},
437 \.{BRC}, \.{BIC}, \.{LRC}, \.{LIC}, \.{MRE}, \.{MIE}, \.{BRE}, \.{BIE},
438 \.{LRE}, and \.{LIE}, denoting the integers 0 to 17, respectively.
439
440 \yskip\hang\.O denotes an unsigned octal integer, which must be less than
441 $2^{32}$, i.e., at most `\.{O 37777777777}'.
442
443 \yskip\hang\.H denotes an unsigned hexadecimal integer, which must be less than
444 $2^{32}$, i.e., at most `\.{H FFFFFFFF}'.
445
446 \yskip\hang\.R denotes a real number in decimal notation, optionally preceded
447 by a `\.+' or `\.-' sign, and optionally including a decimal point. The
448 absolute value must be less than 2048.
449
450 @ The property names allowed in a \.{FONTDIMEN} property list correspond to
451 various \TeX\ parameters, each of which has a (real) numeric value. All
452 of the parameters except \.{SLANT} are in design units. The admissible
453 names are \.{SLANT}, \.{SPACE}, \.{STRETCH}, \.{SHRINK}, \.{XHEIGHT},
454 \.{QUAD}, \.{EXTRASPACE}, \.{NUM1}, \.{NUM2}, \.{NUM3}, \.{DENOM1},
455 \.{DENOM2}, \.{SUP1}, \.{SUP2}, \.{SUP3}, \.{SUB1}, \.{SUB2}, \.{SUPDROP},
456 \.{SUBDROP}, \.{DELIM1}, \.{DELIM2}, and \.{AXISHEIGHT}, for parameters
457 1~to~22. The alternate names \.{DEFAULTRULETHICKNESS},
458 \.{BIGOPSPACING1}, \.{BIGOPSPACING2}, \.{BIGOPSPACING3},
459 \.{BIGOPSPACING4}, and \.{BIGOPSPACING5}, may also be used for parameters
460 8 to 13.
461
462 The notation `\.{PARAMETER} $n$' provides another way to specify the
463 $n$th parameter; for example, `\.{(PARAMETER} \.{D 1 R -.25)}' is another way
464 to specify that the \.{SLANT} is $-0.25$. The value of $n$ must be positive
465 and less than |max_param_words|.
466
467 @ The elements of a \.{CHARACTER} property list can be of six different types.
468
469 \yskip\hang\.{CHARWD} (real value) denotes the character's width in
470 design units.
471
472 \yskip\hang\.{CHARHT} (real value) denotes the character's height in
473 design units.
474
475 \yskip\hang\.{CHARDP} (real value) denotes the character's depth in
476 design units.
477
478 \yskip\hang\.{CHARIC} (real value) denotes the character's italic correction in
479 design units.
480
481 \yskip\hang\.{NEXTLARGER} (integer value), specifies the character that
482 follows the present one in a ``charlist.'' The value must be the number of a
483 character in the font, and there must be no infinite cycles of supposedly
484 larger and larger characters.
485
486 \yskip\hang\.{VARCHAR} (property list value), specifies an extensible character.
487 This option and \.{NEXTLARGER} are mutually exclusive; i.e., they cannot
488 both be used within the same \.{CHARACTER} list.
489
490 \yskip\noindent
491 The elements of a \.{VARCHAR} property list are either \.{TOP}, \.{MID},
492 \.{BOT} or \.{REP}; the values are integers, which must be zero or the number
493 of a character in the font. A zero value for \.{TOP}, \.{MID}, or \.{BOT} means
494 that the corresponding piece of the extensible character is absent. A nonzero
495 value, or a \.{REP} value of zero, denotes the character code used to make
496 up the top, middle, bottom, or replicated piece of an extensible character.
497
498 @ A \.{LIGTABLE} property list contains elements of four kinds, specifying a
499 program in a simple command language that \TeX\ uses for ligatures and kerns.
500 If several \.{LIGTABLE} lists appear, they are effectively concatenated into
501 a single list.
502
503 \yskip\hang\.{LABEL} (integer value) means that the program for the
504 stated character value starts here. The integer must be the number of a
505 character in the font; its \.{CHARACTER} property list must not have a
506 \.{NEXTLARGER} or \.{VARCHAR} field. At least one \.{LIG} or \.{KRN} step
507 must follow.
508
509 \yskip\hang\.{LABEL} \.{BOUNDARYCHAR} means that the program for
510 beginning-of-word ligatures starts here.
511
512 \yskip\hang\.{LIG} (two integer values). The instruction `\.{(LIG} $c$ $r$\.)'
513 means, ``If the next character is $c$, then insert character~$r$ and
514 possibly delete the current character and/or~$c$;
515 otherwise go on to the next instruction.''
516 Characters $r$ and $c$ must be present in the font. \.{LIG} may be immediately
517 preceded or followed by a slash, and then immediately followed by \.>
518 characters not exceeding the number of slashes. Thus there are eight
519 possible forms:
520 $$\hbox to .8\hsize{\.{LIG}\hfil\.{/LIG}\hfil\.{/LIG>}\hfil
521 \.{LIG/}\hfil\.{LIG/>}\hfil\.{/LIG/}\hfil\.{/LIG/>}\hfil\.{/LIG/>>}}$$
522 The slashes specify retention of the left or right original character; the
523 \.> signs specify passing over the result without further ligature processing.
524
525 \yskip\hang\.{KRN} (an integer value and a real value). The instruction
526 `\.{(KRN} $c$ $r$\.)' means, ``If the next character is $c$, then insert
527 a blank space of width $r$ between the current character character and $c$;
528 otherwise go on to the next intruction.'' The value of $r$, which is in
529 design units, is often negative. Character code $c$ must exist
530 in the font.
531
532 \yskip\hang\.{STOP} (no value). This instruction ends a ligature/kern program.
533 It must follow either a \.{LIG} or \.{KRN} instruction, not a \.{LABEL}
534 or \.{STOP} or \.{SKIP}.
535
536 \yskip\hang\.{SKIP} (value in the range |0..127|). This instruction specifies
537 continuation of a ligature/kern program after the specified number of \.{LIG}
538 or \.{KRN} steps has been skipped over. The number of subsequent \.{LIG} and
539 \.{KRN} instructions must therefore exceed this specified amount.
540
541 @ In addition to all these possibilities, the property name \.{COMMENT} is
542 allowed in any property list. Such comments are ignored.
543
544 @ So that is what \.{PL} files hold. In a \.{VPL} file additional
545 properties are recognized; two of these are valid on the outermost level:
546
547 \yskip\hang\.{VTITLE} (string value, default is empty). The value will be
548 reproduced at the beginning of the \.{VF} file (and printed on the terminal
549 by \.{VFtoVP} when it examines that file).
550
551 \yskip\hang\.{MAPFONT}. The value is a nonnegative integer followed by
552 a property list. The integer represents an identifying number for fonts
553 used in \.{MAP} attributes. The property list, which identifies the font and
554 relative size, is defined below.
555
556 \yskip\noindent
557 And one additional ``virtual property'' is valid within a \.{CHARACTER}:
558
559 \yskip\hang\.{MAP}. The value is a property list consisting of typesetting
560 commands. Default is the single command \.{SETCHAR}~$c$, where $c$ is
561 the current character number.
562
563 @ The elements of a \.{MAPFONT} property list can be of the following types.
564
565 \yskip\hang\.{FONTNAME} (string value, default is \.{NULL}).
566 This is the font's identifying name.
567
568 \yskip\hang\.{FONTAREA} (string value, default is empty). If the font appears
569 in a nonstandard directory, according to local conventions, the directory
570 name is given here. (This is system dependent, just as in \.{DVI} files.)
571
572 \yskip\hang\.{FONTCHECKSUM} (four-byte value, default is zero). This value,
573 which should be a nonnegative integer less than $2^{32}$, can be used to
574 check that the font being referred to matches the intended font. If nonzero,
575 it should equal the \.{CHECKSUM} parameter in that font.
576
577 \yskip\hang\.{FONTAT} (numeric value, default is the \.{DESIGNUNITS} of the
578 present virtual font). This value is relative to the design units of
579 the present virtual font, hence it will be scaled when the virtual
580 font is magnified or reduced. It represents the value that will
581 effectively replace the design size of the font being referred to,
582 so that all characters will be scaled appropriately.
583
584 \yskip\hang\.{FONTDSIZE} (numeric value, default is 10). This value is
585 absolute, in units of printer's points. It should equal the \.{DESIGNSIZE}
586 parameter in the font being referred to.
587
588 \yskip\noindent
589 If any of the
590 string values contain parentheses, the parentheses must be balanced. Leading
591 blanks are removed from the strings, but trailing blanks are not.
592
593 @ Finally, the elements of a \.{MAP} property list are an ordered sequence
594 of typesetting commands chosen from among the following:
595
596 \yskip\hang\.{SELECTFONT} (four-byte integer value). The value must be the
597 number of a previously defined \.{MAPFONT}. This font (or more precisely, the
598 final font that is mapped to that code number, if two \.{MAPFONT} properties
599 happen to specify the same code) will be used in subsequent \.{SETCHAR}
600 instructions until overridden by another \.{SELECTFONT}. The first-specified
601 \.{MAPFONT} is implicitly selected before the first \.{SELECTFONT} in every
602 character's map.
603
604 \yskip\hang\.{SETCHAR} (integer value). There must be a character of
605 this number in the currently selected font. (\.{VPtoVF} doesn't check that
606 the character is valid, but \.{VFtoVP} does.) That character is typeset at the
607 current position, and the typesetter moves right by the \.{CHARWD} in
608 that character's \.{TFM} file.
609
610 \yskip\hang\.{SETRULE} (two real values). The first value specifies height,
611 the second specifies width, in design units. If both height and width are
612 positive, a rule is typeset at the current position. Then the typesetter
613 moves right, by the specified width.
614
615 \yskip\hang\.{MOVERIGHT}, \.{MOVELEFT}, \.{MOVEUP}, \.{MOVEDOWN} (real
616 value). The typesetter moves its current position
617 by the number of design units specified.
618
619 \yskip\hang\.{PUSH}. The current typesetter position is remembered, to
620 be restored on a subsequent \.{POP}.
621
622 \yskip\hang\.{POP}. The current typesetter position is reset to where it
623 was on the most recent unmatched \.{PUSH}. The \.{PUSH} and \.{POP}
624 commands in any \.{MAP} must be properly nested like balanced parentheses.
625
626 \yskip\hang\.{SPECIAL} (string value). The subsequent characters, starting
627 with the first nonblank and ending just before the first `\.)' that has no
628 matching `\.(', are interpreted according to local conventions with the
629 same system-dependent meaning as a `special' (\\{xxx}) command
630 in a \.{DVI} file.
631
632 \yskip\hang\.{SPECIALHEX} (hexadecimal string value). The subsequent
633 nonblank characters before the next `\.)' must consist entirely of
634 hexadecimal digits, and they must contain an even number of such digits.
635 Each pair of hex digits specifies a byte, and this string of bytes is
636 treated just as the value of a \.{SPECIAL}. (This convention permits
637 arbitrary byte strings to be represented in an ordinary text file.)
638
639 @ Virtual font mapping is a recursive process, like macro expansion.
640 Thus, a \.{MAPFONT} might
641 specify another virtual font, whose characters are themselves mapped to
642 other fonts. As an example of this possibility, consider the
643 following curious file called \.{recurse.vpl}, which defines a
644 virtual font that is self-contained and self-referential:
645 $$\vbox{\halign{\.{#}\cr
646 (VTITLE Example of recursion)\cr
647 (MAPFONT D 0 (FONTNAME recurse)(FONTAT D 2))\cr
648 (CHARACTER C A (CHARWD D 1)(CHARHT D 1)(MAP (SETRULE D 1 D 1)))\cr
649 (CHARACTER C B (CHARWD D 2)(CHARHT D 2)(MAP (SETCHAR C A)))\cr
650 (CHARACTER C C (CHARWD D 4)(CHARHT D 4)(MAP (SETCHAR C B)))\cr
651 }}$$
652 The design size is 10 points (the default), hence the character \.A
653 in font \.{recurse} is a $10\times10$ point black square. Character \.B
654 is typeset as character \.A in \.{recurse} {scaled} {2000}, hence it
655 is a $20\times20$ point black square. And character \.C is typeset as
656 character \.{B} in \.{recurse} {scaled} {2000}, hence its size is
657 $40\times40$.
658
659 Users are responsible for making sure that infinite recursion doesn't happen.
660
661 @ So that is what \.{VPL} files hold. From these rules,
662 you can guess (correctly) that \.{VPtoVF} operates in four main stages.
663 First it assigns the default values to all properties; then it scans
664 through the \.{VPL} file, changing property values as new ones are seen; then
665 it checks the information and corrects any problems; and finally it outputs
666 the \.{VF} and \.{TFM} files.
667
668 @ The next question is, ``What are \.{VF} and
669 \.{TFM} files?'' A complete answer to that question appears in the
670 documentation of the companion programs, \.{VFtoVP} and
671 \.{TFtoPL}, so the details will not
672 be repeated here. Suffice it to say that a \.{VF} or
673 \.{TFM} file stores all of the
674 relevant font information in a sequence of 8-bit bytes. The number of
675 bytes is always a multiple of 4, so we could regard the files
676 as sequences of 32-bit words; but \TeX\ uses the byte interpretation,
677 and so does \.{VPtoVF}. Note that the bytes are considered to be unsigned
678 numbers.
679
680 @<Glob...@>=
681 @!vf_file:packed file of 0..255;
682 @!tfm_file:packed file of 0..255;
683
684 @ On some systems you may have to do something special to write a
685 packed file of bytes. For example, the following code didn't work
686 when it was first tried at Stanford, because packed files have to be
687 opened with a special switch setting on the \PASCAL\ that was used.
688 @^system dependencies@>
689
690 @<Set init...@>=
691 rewrite(vf_file); rewrite(tfm_file);
692
693 @* Basic input routines.
694 For the purposes of this program, a |byte| is an unsigned 16-bit quantity,
695 and an |ASCII_code| is an integer between @'40 and @'177. Such ASCII codes
696 correspond to one-character constants like \.{"A"} in \.{WEB} language.
697
698 @<Types...@>=
699 @!byte=0..65535; {unsigned 16-bit quantity}
700 @!ASCII_code=@'40..@'177; {standard ASCII code numbers}
701
702 @ One of the things \.{VPtoVF} has to do is convert characters of strings
703 to ASCII form, since that is the code used for the family name and the
704 coding scheme in a \.{TFM} file. An array |xord| is used to do the
705 conversion from |char|; the method below should work with little or no change
706 on most \PASCAL\ systems.
707 @^system dependencies@>
708
709 @d first_ord=0 {ordinal number of the smallest element of |char|}
710 @d last_ord=127 {ordinal number of the largest element of |char|}
711
712 @<Global...@>=
713 @!xord:array[char] of ASCII_code; {conversion table}
714
715 @ @<Local variables for init...@>=
716 @!k:integer; {all-purpose initialization index}
717
718 @ Characters that should not appear in \.{VPL} files (except in comments)
719 are mapped into @'177.
720
721 @d invalid_code=@'177 {code deserving an error message}
722
723 @<Set init...@>=
724 for k:=first_ord to last_ord do xord[chr(k)]:=invalid_code;
725 xord[' ']:=" "; xord['!']:="!"; xord['"']:=""""; xord['#']:="#";
726 xord['$']:="$"; xord['%']:="%"; xord['&']:="&"; xord['''']:="'";
727 xord['(']:="("; xord[')']:=")"; xord['*']:="*"; xord['+']:="+"; xord[',']:=",";
728 xord['-']:="-"; xord['.']:="."; xord['/']:="/"; xord['0']:="0"; xord['1']:="1";
729 xord['2']:="2"; xord['3']:="3"; xord['4']:="4"; xord['5']:="5"; xord['6']:="6";
730 xord['7']:="7"; xord['8']:="8"; xord['9']:="9"; xord[':']:=":"; xord[';']:=";";
731 xord['<']:="<"; xord['=']:="="; xord['>']:=">"; xord['?']:="?";
732 xord['@@']:="@@"; xord['A']:="A"; xord['B']:="B"; xord['C']:="C";
733 xord['D']:="D"; xord['E']:="E"; xord['F']:="F"; xord['G']:="G"; xord['H']:="H";
734 xord['I']:="I"; xord['J']:="J"; xord['K']:="K"; xord['L']:="L"; xord['M']:="M";
735 xord['N']:="N"; xord['O']:="O"; xord['P']:="P"; xord['Q']:="Q"; xord['R']:="R";
736 xord['S']:="S"; xord['T']:="T"; xord['U']:="U"; xord['V']:="V"; xord['W']:="W";
737 xord['X']:="X"; xord['Y']:="Y"; xord['Z']:="Z"; xord['[']:="["; xord['\']:="\";
738 xord[']']:="]"; xord['^']:="^"; xord['_']:="_"; xord['`']:="`"; xord['a']:="a";
739 xord['b']:="b"; xord['c']:="c"; xord['d']:="d"; xord['e']:="e"; xord['f']:="f";
740 xord['g']:="g"; xord['h']:="h"; xord['i']:="i"; xord['j']:="j"; xord['k']:="k";
741 xord['l']:="l"; xord['m']:="m"; xord['n']:="n"; xord['o']:="o"; xord['p']:="p";
742 xord['q']:="q"; xord['r']:="r"; xord['s']:="s"; xord['t']:="t"; xord['u']:="u";
743 xord['v']:="v"; xord['w']:="w"; xord['x']:="x"; xord['y']:="y"; xord['z']:="z";
744 xord['{']:="{"; xord['|']:="|"; xord['}']:="}"; xord['~']:="~";
745
746 @ In order to help catch errors of badly nested parentheses, \.{VPtoVF}
747 assumes that the user will begin each line with a number of blank spaces equal
748 to some constant times the number of open parentheses at the beginning of
749 that line. However, the program doesn't know in advance what the constant
750 is, nor does it want to print an error message on every line for a user
751 who has followed no consistent pattern of indentation.
752
753 Therefore the following strategy is adopted: If the user has been consistent
754 with indentation for ten or more lines, an indentation error will be
755 reported. The constant of indentation is reset on every line that should
756 have nonzero indentation.
757
758 @<Glob...@>=
759 @!line:integer; {the number of the current line}
760 @!good_indent:integer; {the number of lines since the last bad indentation}
761 @!indent: integer; {the number of spaces per open parenthesis, zero if unknown}
762 @!level: integer; {the current number of open parentheses}
763
764 @ @<Set init...@>=
765 line:=0; good_indent:=0; indent:=0; level:=0;
766
767 @ The input need not really be broken into lines of any maximum length, and
768 we could read it character by character without any buffering. But we shall
769 place it into a small buffer so that offending lines can be displayed in error
770 messages.
771
772 @<Glob...@>=
773 @!left_ln,@!right_ln:boolean; {are the left and right ends of the buffer
774 at end-of-line marks?}
775 @!limit:0..buf_size; {position of the last character present in the buffer}
776 @!loc:0..buf_size; {position of the last character read in the buffer}
777 @!buffer:array[1..buf_size] of char;
778 @!input_has_ended:boolean; {there is no more input to read}
779
780 @ @<Set init...@>=
781 limit:=0; loc:=0; left_ln:=true; right_ln:=true; input_has_ended:=false;
782
783 @ Just before each \.{CHARACTER} property list is evaluated, the character
784 code is printed in octal notation. Up to eight such codes appear on a line;
785 so we have a variable to keep track of how many are currently there.
786
787 @<Glob...@>=
788 @!chars_on_line:0..9; {the number of characters printed on the current line}
789
790 @ @<Set init...@>=
791 chars_on_line:=0;
792
793 @ The following routine prints an error message and an indication of
794 where the error was detected. The error message should not include any
795 final punctuation, since this procedure supplies its own.
796
797 @d err_print(#)==begin if chars_on_line>0 then print_ln(' ');
798 print(#); show_error_context;
799 end
800
801 @p procedure show_error_context; {prints the current scanner location}
802 var k:0..buf_size; {an index into |buffer|}
803 begin print_ln(' (line ',line:1,').');
804 if not left_ln then print('...');
805 for k:=1 to loc do print(buffer[k]); {print the characters already scanned}
806 print_ln(' ');
807 if not left_ln then print(' ');
808 for k:=1 to loc do print(' '); {space out the second line}
809 for k:=loc+1 to limit do print(buffer[k]); {print the characters yet unseen}
810 if right_ln then print_ln(' ')@+else print_ln('...');
811 chars_on_line:=0;
812 end;
813
814 @ Here is a procedure that does the right thing when we are done
815 reading the present contents of the buffer. It keeps |buffer[buf_size]|
816 empty, in order to avoid range errors on certain \PASCAL\ compilers.
817
818 An infinite sequence of right parentheses is placed at the end of the
819 file, so that the program is sure to get out of whatever level of nesting
820 it is in.
821
822 On some systems it is desirable to modify this code so that tab marks
823 in the buffer are replaced by blank spaces. (Simply setting
824 |xord[chr(@'11)]:=" "| would not work; for example, two-line
825 error messages would not come out properly aligned.)
826 @^system dependencies@>
827
828 @p procedure fill_buffer;
829 begin left_ln:=right_ln; limit:=0; loc:=0;
830 if left_ln then
831 begin if line>0 then read_ln(vpl_file);
832 incr(line);
833 end;
834 if eof(vpl_file) then
835 begin limit:=1; buffer[1]:=')'; right_ln:=false; input_has_ended:=true;
836 end
837 else begin while (limit<buf_size-2)and(not eoln(vpl_file)) do
838 begin incr(limit); read(vpl_file,buffer[limit]);
839 end;
840 buffer[limit+1]:=' '; right_ln:=eoln(vpl_file);
841 if right_ln then begin incr(limit); buffer[limit+1]:=' ';
842 end;
843 if left_ln then @<Set |loc| to the number of leading blanks in
844 the buffer, and check the indentation@>;
845 end;
846 end;
847
848 @ The interesting part about |fill_buffer| is the part that learns what
849 indentation conventions the user is following, if any.
850
851 @d bad_indent(#)==begin if good_indent>=10 then err_print(#);
852 good_indent:=0; indent:=0;
853 end
854
855 @<Set |loc|...@>=
856 begin while (loc<limit)and(buffer[loc+1]=' ') do incr(loc);
857 if loc<limit then
858 begin if level=0 then
859 if loc=0 then incr(good_indent)
860 else bad_indent('Warning: Indented line occurred at level zero')
861 @.Warning: Indented line...@>
862 else if indent=0 then
863 if loc mod level=0 then
864 begin indent:=loc div level; good_indent:=1;
865 end
866 else good_indent:=0
867 else if indent*level=loc then incr(good_indent)
868 else bad_indent('Warning: Inconsistent indentation; ',
869 @.Warning: Inconsistent indentation...@>
870 'you are at parenthesis level ',level:1);
871 end;
872 end
873
874 @* Basic scanning routines.
875 The global variable |cur_char| holds the ASCII code corresponding to the
876 character most recently read from the input buffer, or to a character that
877 has been substituted for the real one.
878
879 @<Global...@>=
880 @!cur_char:ASCII_code; {we have just read this}
881
882 @ Here is a procedure that sets |cur_char| to an ASCII code for the
883 next character of input, if that character is a letter or digit or slash
884 or \.>. Otherwise
885 it sets |cur_char:=" "|, and the input system will be poised to reread the
886 character that was rejected, whether or not it was a space.
887 Lower case letters are converted to upper case.
888
889 @p procedure get_keyword_char;
890 begin while (loc=limit)and(not right_ln) do fill_buffer;
891 if loc=limit then cur_char:=" " {end-of-line counts as a delimiter}
892 else begin cur_char:=xord[buffer[loc+1]];
893 if cur_char>="a" then cur_char:=cur_char-@'40;
894 if ((cur_char>="0")and(cur_char<="9")) then incr(loc)
895 else if ((cur_char>="A")and(cur_char<="Z")) then incr(loc)
896 else if cur_char="/" then incr(loc)
897 else if cur_char=">" then incr(loc)
898 else cur_char:=" ";
899 end;
900 end;
901
902 @ The following procedure sets |cur_char| to the next character code,
903 and converts lower case to upper case. If the character is a left or
904 right parenthesis, it will not be ``digested''; the character will
905 be read again and again, until the calling routine does something
906 like `|incr(loc)|' to get past it. Such special treatment of parentheses
907 insures that the structural information they contain won't be lost in
908 the midst of other error recovery operations.
909
910 @d backup==begin if (cur_char>")")or(cur_char<"(") then decr(loc);
911 end {undoes the effect of |get_next|}
912
913 @p procedure get_next; {sets |cur_char| to next, balks at parentheses}
914 begin while loc=limit do fill_buffer;
915 incr(loc); cur_char:=xord[buffer[loc]];
916 if cur_char>="a" then
917 if cur_char<="z" then cur_char:=cur_char-@'40 {uppercasify}
918 else begin
919 if cur_char=invalid_code then
920 begin err_print('Illegal character in the file');
921 @.Illegal character...@>
922 cur_char:="?";
923 end;
924 end
925 else if (cur_char<=")")and(cur_char>="(") then decr(loc);
926 end;
927
928 @ Here's a procedure that scans a hexadecimal digit or a right parenthesis.
929
930 @p function get_hex:byte;
931 var @!a:integer; {partial result}
932 begin repeat get_next;
933 until cur_char<>" ";
934 a:=cur_char-")";
935 if a>0 then
936 begin a:=cur_char-"0";
937 if cur_char>"9" then
938 if cur_char<"A" then a:=-1 else a:=cur_char-"A"+10;
939 end;
940 if (a<0)or(a>15) then
941 begin err_print('Illegal hexadecimal digit'); get_hex:=0;
942 @.Illegal hexadecimal digit@>
943 end
944 else get_hex:=a;
945 end;
946
947 @ The next procedure is used to ignore the text of a comment, or to pass over
948 erroneous material. As such, it has the privilege of passing parentheses.
949 It stops after the first right parenthesis that drops the level below
950 the level in force when the procedure was called.
951
952 @p procedure skip_to_end_of_item;
953 var l:integer; {initial value of |level|}
954 begin l:=level;
955 while level>=l do
956 begin while loc=limit do fill_buffer;
957 incr(loc);
958 if buffer[loc]=')' then decr(level)
959 else if buffer[loc]='(' then incr(level);
960 end;
961 if input_has_ended then err_print('File ended unexpectedly: No closing ")"');
962 @.File ended unexpectedly...@>
963 cur_char:=" "; {now the right parenthesis has been read and digested}
964 end;
965
966 @ A similar procedure copies the bytes remaining in an item. The copied bytes
967 go into an array |vf| that we'll declare later. Leading blanks are ignored.
968
969 @d vf_store(#)==
970 begin vf[vf_ptr]:=#;
971 if vf_ptr=vf_size then err_print('I''m out of memory---increase my vfsize!')
972 @.I'm out of memory...@>
973 else incr(vf_ptr);
974 end
975
976 @p procedure copy_to_end_of_item;
977 label 30;
978 var l:integer; {initial value of |level|}
979 @!nonblank_found:boolean; {have we seen a nonblank character yet?}
980 begin l:=level; nonblank_found:=false;
981 while true do
982 begin while loc=limit do fill_buffer;
983 if buffer[loc+1]=')' then
984 if level=l then goto 30@+else decr(level);
985 incr(loc);
986 if buffer[loc]='(' then incr(level);
987 if buffer[loc]<>' ' then nonblank_found:=true;
988 if nonblank_found then
989 if xord[buffer[loc]]=invalid_code then
990 begin err_print('Illegal character in the file');
991 @.Illegal character...@>
992 vf_store("?");
993 end
994 else vf_store(xord[buffer[loc]]);
995 end;
996 30:end;
997
998 @ Sometimes we merely want to skip past characters in the input until we
999 reach a left or a right parenthesis. For example, we do this whenever we
1000 have finished scanning a property value and we hope that a right parenthesis
1001 is next (except for possible blank spaces).
1002
1003 @d skip_to_paren==repeat get_next@;@+ until (cur_char="(")or(cur_char=")")
1004 @d skip_error(#)==begin err_print(#); skip_to_paren;
1005 end {this gets to the right parenthesis if something goes wrong}
1006 @d flush_error(#)==begin err_print(#); skip_to_end_of_item;
1007 end {this gets past the right parenthesis if something goes wrong}
1008
1009 @ After a property value has been scanned, we want to move just past the
1010 right parenthesis that should come next in the input (except for possible
1011 blank spaces).
1012
1013 @p procedure finish_the_property; {do this when the value has been scanned}
1014 begin while cur_char=" " do get_next;
1015 if cur_char<>")" then err_print('Junk after property value will be ignored');
1016 @.Junk after property value...@>
1017 skip_to_end_of_item;
1018 end;
1019
1020 @* Scanning property names.
1021 We have to figure out the meaning of names that appear in the \.{VPL} file,
1022 by looking them up in a dictionary of known keywords. Keyword number $n$
1023 appears in locations |start[n]| through |start[n+1]-1| of an array called
1024 |dictionary|.
1025
1026 @d max_name_index=300 {upper bound on the number of keywords}
1027 @d max_letters=3000 {upper bound on the total length of all keywords}
1028
1029 @<Global...@>=
1030 @!start:array[1..max_name_index] of 0..max_letters;
1031 @!dictionary:array[0..max_letters] of ASCII_code;
1032 @!start_ptr:0..max_name_index; {the first available place in |start|}
1033 @!dict_ptr:0..max_letters; {the first available place in |dictionary|}
1034
1035 @ @<Set init...@>=
1036 start_ptr:=1; start[1]:=0; dict_ptr:=0;
1037
1038 @ When we are looking for a name, we put it into the |cur_name| array.
1039 When we have found it, the corresponding |start| index will go into
1040 the global variable |name_ptr|.
1041
1042 @d longest_name=20 {length of \.{DEFAULTRULETHICKNESS}}
1043
1044 @<Glob...@>=
1045 @!cur_name:array[1..longest_name] of ASCII_code; {a name to look up}
1046 @!name_length:0..longest_name; {its length}
1047 @!name_ptr:0..max_name_index; {its ordinal number in the dictionary}
1048
1049 @ A conventional hash table with linear probing (cf.\ Algorithm 6.4L
1050 in {\sl The Art of Computer Pro\-gram\-ming\/}) is used for the dictionary
1051 operations. If |nhash[h]=0|, the table position is empty, otherwise |nhash[h]|
1052 points into the |start| array.
1053
1054 @d hash_prime=307 {size of the hash table}
1055
1056 @<Glob...@>=
1057 @!nhash:array[0..hash_prime-1] of 0..max_name_index;
1058 @!cur_hash:0..hash_prime-1; {current position in the hash table}
1059
1060 @ @<Local...@>=
1061 @!h:0..hash_prime-1; {runs through the hash table}
1062
1063 @ @<Set init...@>=
1064 for h:=0 to hash_prime-1 do nhash[h]:=0;
1065
1066 @ Since there is no chance of the hash table overflowing, the procedure
1067 is very simple. After |lookup| has done its work, |cur_hash| will point
1068 to the place where the given name was found, or where it should be inserted.
1069
1070 @p procedure lookup; {finds |cur_name| in the dictionary}
1071 var k:0..longest_name; {index into |cur_name|}
1072 @!j:0..max_letters; {index into |dictionary|}
1073 @!not_found:boolean; {clumsy thing necessary to avoid |goto| statement}
1074 @!cur_hash_reset:boolean;
1075 begin @<Compute the hash code, |cur_hash|, for |cur_name|@>;
1076 not_found:=true;
1077 cur_hash_reset:=false;
1078 while not_found do begin
1079 if (cur_hash=0) and (cur_hash_reset) then
1080 not_found:=false
1081 else begin
1082 if cur_hash=0 then begin
1083 cur_hash:=hash_prime-1;
1084 cur_hash_reset:=true
1085 end
1086 else decr(cur_hash);
1087 if nhash[cur_hash]=0 then not_found:=false
1088 else begin
1089 j:=start[nhash[cur_hash]];
1090 if start[nhash[cur_hash]+1]=j+name_length then begin
1091 not_found:=false;
1092 for k:=1 to name_length do
1093 if dictionary[j+k-1]<>cur_name[k] then not_found:=true;
1094 end
1095 end
1096 end
1097 end;
1098 name_ptr:=nhash[cur_hash];
1099 end;
1100
1101 @ @<Compute the hash...@>=
1102 cur_hash:=cur_name[1];
1103 for k:=2 to name_length do
1104 cur_hash:=(cur_hash+cur_hash+cur_name[k]) mod hash_prime
1105
1106 @ The ``meaning'' of the keyword that begins at |start[k]| in the
1107 dictionary is kept in |equiv[k]|. The numeric |equiv| codes are given
1108 symbolic meanings by the following definitions.
1109
1110 @d comment_code=0
1111 @#{property names at the outer level}
1112 @d check_sum_code=1
1113 @d design_size_code=2
1114 @d design_units_code=3
1115 @d coding_scheme_code=4
1116 @d family_code=5
1117 @d face_code=6
1118 @d seven_bit_safe_flag_code=7
1119 @d header_code= 8
1120 @d font_dimen_code=9
1121 @d lig_table_code=10
1122 @d boundary_char_code=11
1123 @d virtual_title_code=12
1124 @d map_font_code=13
1125 @d character_code=14
1126 @d font_dir_code=15
1127 @d n_font_dir_code=16
1128 @d ofm_level_code=17
1129 @d font_rule_code=18
1130 @d font_glue_code=19
1131 @d font_penalty_code=20
1132 @d font_mvalue_code=21
1133 @d font_fvalue_code=22
1134 @d font_ivalue_code=23
1135 @d char_repeat_code=24
1136 @#{property names in a FONTDIMEN list}
1137 @d parameter_code=30
1138 @#{property names in a CHARACTER list}
1139 @d char_info_code=70
1140 @d width=1
1141 @d height=2
1142 @d depth=3
1143 @d italic=4
1144 @d sec_width=5
1145 @d sec_height=6
1146 @d sec_depth=7
1147 @d sec_italic=8
1148 @d accent=9
1149 @d prim_top_axis=10
1150 @d prim_top_axis_bis=11
1151 @d prim_bot_axis=12
1152 @d prim_bot_axis_bis=13
1153 @d prim_mid_hor=14
1154 @d prim_mid_vert=15
1155 @d prim_base_slant=16
1156 @d sec_top_axis=17
1157 @d sec_top_axis_bis=18
1158 @d sec_bot_axis=19
1159 @d sec_bot_axis_bis=20
1160 @d sec_mid_hor=21
1161 @d sec_mid_vert=22
1162 @d sec_base_slant=23
1163 @d char_wd_code=char_info_code+width
1164 @d char_ht_code=char_info_code+height
1165 @d char_dp_code=char_info_code+depth
1166 @d char_ic_code=char_info_code+italic
1167 @d sec_width_code=char_info_code+sec_width
1168 @d sec_height_code=char_info_code+sec_height
1169 @d sec_depth_code=char_info_code+sec_depth
1170 @d sec_italic_code=char_info_code+sec_italic
1171 @d accent_code=char_info_code+accent
1172 @d prim_top_axis_code=char_info_code+prim_top_axis
1173 @d prim_top_axis_bis_code=char_info_code+prim_top_axis_bis
1174 @d prim_bot_axis_code=char_info_code+prim_bot_axis
1175 @d prim_bot_axis_bis_code=char_info_code+prim_bot_axis_bis
1176 @d prim_mid_hor_code=char_info_code+prim_mid_hor
1177 @d prim_mid_vert_code=char_info_code+prim_mid_vert
1178 @d prim_base_slant_code=char_info_code+prim_base_slant
1179 @d sec_top_axis_code=char_info_code+sec_top_axis
1180 @d sec_top_axis_bis_code=char_info_code+sec_top_axis_bis
1181 @d sec_bot_axis_code=char_info_code+sec_bot_axis
1182 @d sec_bot_axis_bis_code=char_info_code+sec_bot_axis_bis
1183 @d sec_mid_hor_code=char_info_code+sec_mid_hor
1184 @d sec_mid_vert_code=char_info_code+sec_mid_vert
1185 @d sec_base_slant_code=char_info_code+sec_base_slant
1186 @d next_larger_code=100
1187 @d map_code=101
1188 @d char_ivalue_code=111
1189 @d char_fvalue_code=112
1190 @d char_mvalue_code=113
1191 @d char_rule_code=114
1192 @d char_glue_code=115
1193 @d char_penalty_code=116
1194 @d var_char_code=117
1195 @#{property names in a LIGTABLE list}
1196 @d label_code=130
1197 @d stop_code=131
1198 @d skip_code=132
1199 @d krn_code=133
1200 @d lig_code=134
1201 @d clabel_code=150
1202 @d cpen_code=151
1203 @d cglue_code=152
1204 @d cpenglue_code=153
1205 @d ckrn_code=154
1206 @#{property names in a FONTRULE list}
1207 @d rule_code=161
1208 @d rule_width_code=162
1209 @d rule_height_code=163
1210 @d rule_depth_code=164
1211 @#{property names in a FONTGLUE list}
1212 @d glue_code=171
1213 @d glue_type_code=172
1214 @d glue_stretch_order_code=173
1215 @d glue_shrink_order_code=174
1216 @d glue_width_code=175
1217 @d glue_stretch_code=176
1218 @d glue_shrink_code=177
1219 @d glue_char_code=178
1220 @d glue_rule_code=179
1221 @#{property names in a FONTPENALTY list}
1222 @d penalty_code=191
1223 @d penalty_val_code=192
1224 @#{property names in a FONTMVALUE list}
1225 @d mvalue_code=193
1226 @d mvalue_val_code=194
1227 @#{property names in a FONTFVALUE list}
1228 @d fvalue_code=195
1229 @d fvalue_val_code=196
1230 @#{property names in a FONTIVALUE list}
1231 @d ivalue_code=197
1232 @d ivalue_val_code=198
1233 @#{property names in a MAPFONT list}
1234 @d font_name_code=200
1235 @d font_area_code=201
1236 @d font_checksum_code=202
1237 @d font_at_code=203
1238 @d font_dsize_code=204
1239 @#{property names in a MAP list}
1240 @d select_font_code=210
1241 @d set_char_code=211
1242 @d set_rule_code=212
1243 @d move_right_code=213
1244 @d move_down_code=215
1245 @d push_code=217
1246 @d pop_code=218
1247 @d special_code=219
1248 @d special_hex_code=220
1249
1250 @<Glo...@>=
1251 @!equiv:array[0..max_name_index] of byte;
1252 @!cur_code:byte; {equivalent most recently found in |equiv|}
1253
1254 @ We have to get the keywords into the hash table and into the dictionary in
1255 the first place (sigh). The procedure that does this has the desired
1256 |equiv| code as a parameter. In order to facilitate \.{WEB} macro writing
1257 for the initialization, the keyword being initialized is placed into the
1258 last positions of |cur_name|, instead of the first positions.
1259
1260 @p procedure enter_name(v:byte); {|cur_name| goes into the dictionary}
1261 var k:0..longest_name;
1262 begin for k:=1 to name_length do
1263 cur_name[k]:=cur_name[k+longest_name-name_length];
1264 {now the name has been shifted into the correct position}
1265 lookup; {this sets |cur_hash| to the proper insertion place}
1266 nhash[cur_hash]:=start_ptr; equiv[start_ptr]:=v;
1267 for k:=1 to name_length do
1268 begin dictionary[dict_ptr]:=cur_name[k]; incr(dict_ptr);
1269 end;
1270 incr(start_ptr); start[start_ptr]:=dict_ptr;
1271 end;
1272
1273 @ Here are the macros to load a name of up to 20 letters into the
1274 dictionary. For example, the macro |load5| is used for five-letter keywords.
1275
1276 @d tail(#)==enter_name(#)
1277 @d t20(#)==cur_name[20]:=#;tail
1278 @d t19(#)==cur_name[19]:=#;t20
1279 @d t18(#)==cur_name[18]:=#;t19
1280 @d t17(#)==cur_name[17]:=#;t18
1281 @d t16(#)==cur_name[16]:=#;t17
1282 @d t15(#)==cur_name[15]:=#;t16
1283 @d t14(#)==cur_name[14]:=#;t15
1284 @d t13(#)==cur_name[13]:=#;t14
1285 @d t12(#)==cur_name[12]:=#;t13
1286 @d t11(#)==cur_name[11]:=#;t12
1287 @d t10(#)==cur_name[10]:=#;t11
1288 @d t9(#)==cur_name[9]:=#;t10
1289 @d t8(#)==cur_name[8]:=#;t9
1290 @d t7(#)==cur_name[7]:=#;t8
1291 @d t6(#)==cur_name[6]:=#;t7
1292 @d t5(#)==cur_name[5]:=#;t6
1293 @d t4(#)==cur_name[4]:=#;t5
1294 @d t3(#)==cur_name[3]:=#;t4
1295 @d t2(#)==cur_name[2]:=#;t3
1296 @d t1(#)==cur_name[1]:=#;t2
1297 @d load2==name_length:=2;t19
1298 @d load3==name_length:=3;t18
1299 @d load4==name_length:=4;t17
1300 @d load5==name_length:=5;t16
1301 @d load6==name_length:=6;t15
1302 @d load7==name_length:=7;t14
1303 @d load8==name_length:=8;t13
1304 @d load9==name_length:=9;t12
1305 @d load10==name_length:=10;t11
1306 @d load11==name_length:=11;t10
1307 @d load12==name_length:=12;t9
1308 @d load13==name_length:=13;t8
1309 @d load14==name_length:=14;t7
1310 @d load15==name_length:=15;t6
1311 @d load16==name_length:=16;t5
1312 @d load17==name_length:=17;t4
1313 @d load18==name_length:=18;t3
1314 @d load19==name_length:=19;t2
1315 @d load20==name_length:=20;t1
1316
1317 @ (Thank goodness for keyboard macros in the text editor used to create this
1318 \.{WEB} file.)
1319
1320 @<Enter all the \.{PL} names and their equivalents,
1321 except the parameter names@>=
1322 equiv[0]:=comment_code; {this is used after unknown keywords}
1323 load8("C")("H")("E")("C")("K")("S")("U")("M")(check_sum_code);@/
1324 load10("D")("E")("S")("I")("G")("N")("S")("I")("Z")("E")(design_size_code);@/
1325 load11("D")("E")("S")("I")("G")("N")
1326 ("U")("N")("I")("T")("S")(design_units_code);@/
1327 load12("C")("O")("D")("I")("N")("G")
1328 ("S")("C")("H")("E")("M")("E")(coding_scheme_code);@/
1329 load6("F")("A")("M")("I")("L")("Y")(family_code);@/
1330 load4("F")("A")("C")("E")(face_code);@/
1331 load16("S")("E")("V")("E")("N")("B")("I")("T")@/@t\hskip2em@>
1332 ("S")("A")("F")("E")("F")("L")("A")("G")(seven_bit_safe_flag_code);@/
1333 load6("H")("E")("A")("D")("E")("R")(header_code);@/
1334 load9("F")("O")("N")("T")("D")("I")("M")("E")("N")(font_dimen_code);@/
1335 load8("L")("I")("G")("T")("A")("B")("L")("E")(lig_table_code);@/
1336 load12("B")("O")("U")("N")("D")("A")("R")("Y")("C")("H")("A")("R")
1337 (boundary_char_code);@/
1338 load9("C")("H")("A")("R")("A")("C")("T")("E")("R")(character_code);@/
1339 load9("P")("A")("R")("A")("M")("E")("T")("E")("R")(parameter_code);@/
1340 load6("C")("H")("A")("R")("W")("D")(char_wd_code);@/
1341 load6("C")("H")("A")("R")("H")("T")(char_ht_code);@/
1342 load6("C")("H")("A")("R")("D")("P")(char_dp_code);@/
1343 load6("C")("H")("A")("R")("I")("C")(char_ic_code);@/
1344 load5("S")("E")("C")("W")("D")(sec_width_code);@/
1345 load5("S")("E")("C")("H")("T")(sec_height_code);@/
1346 load5("S")("E")("C")("D")("P")(sec_depth_code);@/
1347 load5("S")("E")("C")("I")("C")(sec_italic_code);@/
1348 load6("A")("C")("C")("E")("N")("T")(accent_code);@/
1349 load11("P")("R")("I")("M")("T")("O")("P")("A")("X")("I")("S")(prim_top_axis_code);@/
1350 load14("P")("R")("I")("M")("T")("O")("P")("A")("X")("I")("S")("B")("I")("S")(prim_top_axis_bis_code);@/
1351 load11("P")("R")("I")("M")("B")("O")("T")("A")("X")("I")("S")(prim_bot_axis_code);@/
1352 load14("P")("R")("I")("M")("B")("O")("T")("A")("X")("I")("S")("B")("I")("S")(prim_bot_axis_bis_code);@/
1353 load10("P")("R")("I")("M")("M")("I")("D")("H")("O")("R")(prim_mid_hor_code);@/
1354 load10("P")("R")("I")("M")("M")("I")("D")("V")("E")("R")(prim_mid_vert_code);@/
1355 load13("P")("R")("I")("M")("B")("A")("S")("E")("S")("L")("A")("N")("T")(prim_base_slant_code);@/
1356 load10("S")("E")("C")("T")("O")("P")("A")("X")("I")("S")(sec_top_axis_code);@/
1357 load13("S")("E")("C")("T")("O")("P")("A")("X")("I")("S")("B")("I")("S")(sec_top_axis_bis_code);@/
1358 load10("S")("E")("C")("B")("O")("T")("A")("X")("I")("S")(sec_bot_axis_code);@/
1359 load13("S")("E")("C")("B")("O")("T")("A")("X")("I")("S")("B")("I")("S")(sec_bot_axis_bis_code);@/
1360 load9("S")("E")("C")("M")("I")("D")("H")("O")("R")(sec_mid_hor_code);@/
1361 load9("S")("E")("C")("M")("I")("D")("V")("E")("R")(sec_mid_vert_code);@/
1362 load12("S")("E")("C")("B")("A")("S")("E")("S")("L")("A")("N")("T")(sec_base_slant_code);@/
1363 load10("N")("E")("X")("T")("L")("A")("R")("G")("E")("R")(next_larger_code);@/
1364 load7("V")("A")("R")("C")("H")("A")("R")(var_char_code);@/
1365 load3("T")("O")("P")(var_char_code+1);@/
1366 load3("M")("I")("D")(var_char_code+2);@/
1367 load3("B")("O")("T")(var_char_code+3);@/
1368 load3("R")("E")("P")(var_char_code+4);@/
1369 load3("E")("X")("T")(var_char_code+4); {compatibility with older \.{PL} format}
1370 load7("C")("O")("M")("M")("E")("N")("T")(comment_code);@/
1371 load5("L")("A")("B")("E")("L")(label_code);@/
1372 load4("S")("T")("O")("P")(stop_code);@/
1373 load4("S")("K")("I")("P")(skip_code);@/
1374 load3("K")("R")("N")(krn_code);@/
1375 load3("L")("I")("G")(lig_code);@/
1376 load4("/")("L")("I")("G")(lig_code+2);@/
1377 load5("/")("L")("I")("G")(">")(lig_code+6);@/
1378 load4("L")("I")("G")("/")(lig_code+1);@/
1379 load5("L")("I")("G")("/")(">")(lig_code+5);@/
1380 load5("/")("L")("I")("G")("/")(lig_code+3);@/
1381 load6("/")("L")("I")("G")("/")(">")(lig_code+7);@/
1382 load7("/")("L")("I")("G")("/")(">")(">")(lig_code+11);@/
1383 load6("C")("L")("A")("B")("E")("L")(clabel_code);@/
1384 load4("C")("P")("E")("N")(cpen_code);@/
1385 load5("C")("G")("L")("U")("E")(cglue_code);@/
1386 load8("C")("P")("E")("N")("G")("L")("U")("E")(cpenglue_code);@/
1387 load4("C")("K")("R")("N")(ckrn_code);@/
1388 load8("O")("F")("M")("L")("E")("V")("E")("L")(ofm_level_code);@/
1389 load7("F")("O")("N")("T")("D")("I")("R")(font_dir_code);@/
1390 load8("N")("F")("O")("N")("T")("D")("I")("R")(n_font_dir_code);@/
1391 load14("N")("A")("T")("U")("R")("A")("L")("F")("O")("N")("T")("D")("I")("R")(n_font_dir_code);
1392 {compatibility with \.{omegafonts} (\.{C}) version}
1393 load10("C")("H")("A")("R")("R")("E")("P")("E")("A")("T")(char_repeat_code);@/
1394 load10("C")("H")("A")("R")("I")("V")("A")("L")("U")("E")(char_ivalue_code);@/
1395 load10("C")("H")("A")("R")("F")("V")("A")("L")("U")("E")(char_fvalue_code);@/
1396 load10("C")("H")("A")("R")("M")("V")("A")("L")("U")("E")(char_mvalue_code);@/
1397 load8("C")("H")("A")("R")("R")("U")("L")("E")(char_rule_code);@/
1398 load8("C")("H")("A")("R")("G")("L")("U")("E")(char_glue_code);@/
1399 load11("C")("H")("A")("R")("P")("E")("N")("A")("L")("T")("Y")(char_penalty_code);@/
1400 load8("F")("O")("N")("T")("R")("U")("L")("E")(font_rule_code);@/
1401 load4("R")("U")("L")("E")(rule_code);@/
1402 load6("R")("U")("L")("E")("W")("D")(rule_width_code);@/
1403 load6("R")("U")("L")("E")("H")("T")(rule_height_code);@/
1404 load6("R")("U")("L")("E")("D")("P")(rule_depth_code);@/
1405 load8("F")("O")("N")("T")("G")("L")("U")("E")(font_glue_code);@/
1406 load4("G")("L")("U")("E")(glue_code);@/
1407 load8("G")("L")("U")("E")("T")("Y")("P")("E")(glue_type_code);@/
1408 load16("G")("L")("U")("E")("S")("T")("R")("E")("T")("C")("H")("O")("R")("D")("E")("R")(glue_stretch_order_code);@/
1409 load15("G")("L")("U")("E")("S")("H")("R")("I")("N")("K")("O")("R")("D")("E")("R")(glue_shrink_order_code);@/
1410 load8("G")("L")("U")("E")("R")("U")("L")("E")(glue_rule_code);@/
1411 load8("G")("L")("U")("E")("C")("H")("A")("R")(glue_char_code);@/
1412 load6("G")("L")("U")("E")("W")("D")(glue_width_code);@/
1413 load11("G")("L")("U")("E")("S")("T")("R")("E")("T")("C")("H")(glue_stretch_code);@/
1414 load10("G")("L")("U")("E")("S")("H")("R")("I")("N")("K")(glue_shrink_code);@/
1415 load11("F")("O")("N")("T")("P")("E")("N")("A")("L")("T")("Y")(font_penalty_code);@/
1416 load7("P")("E")("N")("A")("L")("T")("Y")(penalty_code);@/
1417 load10("P")("E")("N")("A")("L")("T")("Y")("V")("A")("L")(penalty_val_code);@/
1418 load10("F")("O")("N")("T")("M")("V")("A")("L")("U")("E")(font_mvalue_code);@/
1419 load6("M")("V")("A")("L")("U")("E")(mvalue_code);@/
1420 load9("M")("V")("A")("L")("U")("E")("V")("A")("L")(mvalue_val_code);@/
1421 load10("F")("O")("N")("T")("F")("V")("A")("L")("U")("E")(font_fvalue_code);@/
1422 load6("F")("V")("A")("L")("U")("E")(fvalue_code);@/
1423 load9("F")("V")("A")("L")("U")("E")("V")("A")("L")(fvalue_val_code);@/
1424 load10("F")("O")("N")("T")("I")("V")("A")("L")("U")("E")(font_ivalue_code);@/
1425 load6("I")("V")("A")("L")("U")("E")(ivalue_code);@/
1426 load9("I")("V")("A")("L")("U")("E")("V")("A")("L")(ivalue_val_code);@/
1427
1428 @ \.{VPL} files may contain the following in addition to the \.{PL} names.
1429
1430 @<Enter all the \.{VPL} names@>=
1431 load6("V")("T")("I")("T")("L")("E")(virtual_title_code);@/
1432 load7("M")("A")("P")("F")("O")("N")("T")(map_font_code);@/
1433 load3("M")("A")("P")(map_code);@/
1434 load8("F")("O")("N")("T")("N")("A")("M")("E")(font_name_code);@/
1435 load8("F")("O")("N")("T")("A")("R")("E")("A")(font_area_code);@/
1436 load12("F")("O")("N")("T")
1437 ("C")("H")("E")("C")("K")("S")("U")("M")(font_checksum_code);@/
1438 load6("F")("O")("N")("T")("A")("T")(font_at_code);@/
1439 load9("F")("O")("N")("T")("D")("S")("I")("Z")("E")(font_dsize_code);@/
1440 load10("S")("E")("L")("E")("C")("T")("F")("O")("N")("T")(select_font_code);@/
1441 load7("S")("E")("T")("C")("H")("A")("R")(set_char_code);@/
1442 load7("S")("E")("T")("R")("U")("L")("E")(set_rule_code);@/
1443 load9("M")("O")("V")("E")("R")("I")("G")("H")("T")(move_right_code);@/
1444 load8("M")("O")("V")("E")("L")("E")("F")("T")(move_right_code+1);@/
1445 load8("M")("O")("V")("E")("D")("O")("W")("N")(move_down_code);@/
1446 load6("M")("O")("V")("E")("U")("P")(move_down_code+1);@/
1447 load4("P")("U")("S")("H")(push_code);@/
1448 load3("P")("O")("P")(pop_code);@/
1449 load7("S")("P")("E")("C")("I")("A")("L")(special_code);@/
1450 load10("S")("P")("E")("C")("I")("A")("L")("H")("E")("X")(special_hex_code);@/
1451
1452 @ @<Enter the parameter names@>=
1453 load5("S")("L")("A")("N")("T")(parameter_code+1);@/
1454 load5("S")("P")("A")("C")("E")(parameter_code+2);@/
1455 load7("S")("T")("R")("E")("T")("C")("H")(parameter_code+3);@/
1456 load6("S")("H")("R")("I")("N")("K")(parameter_code+4);@/
1457 load7("X")("H")("E")("I")("G")("H")("T")(parameter_code+5);@/
1458 load4("Q")("U")("A")("D")(parameter_code+6);@/
1459 load10("E")("X")("T")("R")("A")("S")("P")("A")("C")("E")(parameter_code+7);@/
1460 load4("N")("U")("M")("1")(parameter_code+8);@/
1461 load4("N")("U")("M")("2")(parameter_code+9);@/
1462 load4("N")("U")("M")("3")(parameter_code+10);@/
1463 load6("D")("E")("N")("O")("M")("1")(parameter_code+11);@/
1464 load6("D")("E")("N")("O")("M")("2")(parameter_code+12);@/
1465 load4("S")("U")("P")("1")(parameter_code+13);@/
1466 load4("S")("U")("P")("2")(parameter_code+14);@/
1467 load4("S")("U")("P")("3")(parameter_code+15);@/
1468 load4("S")("U")("B")("1")(parameter_code+16);@/
1469 load4("S")("U")("B")("2")(parameter_code+17);@/
1470 load7("S")("U")("P")("D")("R")("O")("P")(parameter_code+18);@/
1471 load7("S")("U")("B")("D")("R")("O")("P")(parameter_code+19);@/
1472 load6("D")("E")("L")("I")("M")("1")(parameter_code+20);@/
1473 load6("D")("E")("L")("I")("M")("2")(parameter_code+21);@/
1474 load10("A")("X")("I")("S")("H")("E")("I")("G")("H")("T")(parameter_code+22);@/
1475 load20("D")("E")("F")("A")("U")("L")("T")("R")("U")("L")("E")@/@t\hskip2em@>
1476 ("T")("H")("I")("C")("K")("N")("E")("S")("S")(parameter_code+8);@/
1477 load13("B")("I")("G")("O")("P")
1478 ("S")("P")("A")("C")("I")("N")("G")("1")(parameter_code+9);@/
1479 load13("B")("I")("G")("O")("P")
1480 ("S")("P")("A")("C")("I")("N")("G")("2")(parameter_code+10);@/
1481 load13("B")("I")("G")("O")("P")
1482 ("S")("P")("A")("C")("I")("N")("G")("3")(parameter_code+11);@/
1483 load13("B")("I")("G")("O")("P")
1484 ("S")("P")("A")("C")("I")("N")("G")("4")(parameter_code+12);@/
1485 load13("B")("I")("G")("O")("P")
1486 ("S")("P")("A")("C")("I")("N")("G")("5")(parameter_code+13);@/
1487
1488 @ When a left parenthesis has been scanned, the following routine
1489 is used to interpret the keyword that follows, and to store the
1490 equivalent value in |cur_code|.
1491
1492 @p procedure get_name;
1493 begin incr(loc); incr(level); {pass the left parenthesis}
1494 cur_char:=" ";
1495 while cur_char=" " do get_next;
1496 if (cur_char>")")or(cur_char<"(") then decr(loc); {back up one character}
1497 name_length:=0; get_keyword_char; {prepare to scan the name}
1498 while cur_char<>" " do
1499 begin if name_length=longest_name then cur_name[1]:="X" {force error}
1500 else incr(name_length);
1501 cur_name[name_length]:=cur_char;
1502 get_keyword_char;
1503 end;
1504 lookup;
1505 if name_ptr=0 then err_print('Sorry, I don''t know that property name');
1506 @.Sorry, I don't know...@>
1507 cur_code:=equiv[name_ptr];
1508 end;
1509
1510 @* Scanning numeric data.
1511 The next thing we need is a trio of subroutines to read the one-byte,
1512 four-byte, and real numbers that may appear as property values.
1513 These subroutines are careful to stick to numbers between $-2^{31}$
1514 and $2^{31}-1$, inclusive, so that a computer with two's complement
1515 32-bit arithmetic will not be interrupted by overflow.
1516
1517 @ The first number scanner, which returns a one-byte value, surely has
1518 no problems of arithmetic overflow.
1519
1520 @p function get_byte:byte; {scans a one-byte property value}
1521 var acc:integer; {an accumulator}
1522 @!t:ASCII_code; {the type of value to be scanned}
1523 begin repeat get_next;
1524 until cur_char<>" "; {skip the blanks before the type code}
1525 t:=cur_char; acc:=0;
1526 repeat get_next;
1527 until cur_char<>" "; {skip the blanks after the type code}
1528 if t="C" then @<Scan an ASCII character code@>
1529 else if t="D" then @<Scan a small decimal number@>
1530 else if t="O" then @<Scan a small octal number@>
1531 else if t="H" then @<Scan a small hexadecimal number@>
1532 else if t="F" then @<Scan a face code@>
1533 else skip_error('You need "C" or "D" or "O" or "H" or "F" here');
1534 @.You need "C" or "D" ...here@>
1535 cur_char:=" "; get_byte:=acc;
1536 end;
1537
1538 @ The |get_next| routine converts lower case to upper case, but it leaves
1539 the character in the buffer, so we can unconvert it.
1540
1541 @<Scan an ASCII...@>=
1542 if (cur_char>=@'41)and(cur_char<=@'176)and
1543 ((cur_char<"(")or(cur_char>")")) then
1544 acc:=xord[buffer[loc]]
1545 else skip_error('"C" value must be standard ASCII and not a paren')
1546 @:C value}\.{"C" value must be...@>
1547
1548 @ @<Scan a small dec...@>=
1549 begin while (cur_char>="0")and(cur_char<="9") do
1550 begin acc:=acc*10+cur_char-"0";
1551 if acc>char_max then
1552 begin skip_error('This value shouldn''t exceed 65535');
1553 @.This value shouldn't...@>
1554 acc:=0; cur_char:=" ";
1555 end
1556 else get_next;
1557 end;
1558 backup;
1559 end
1560
1561 @ @<Scan a small oct...@>=
1562 begin while (cur_char>="0")and(cur_char<="7") do
1563 begin acc:=acc*8+cur_char-"0";
1564 if acc>char_max then
1565 begin skip_error('This value shouldn''t exceed ''177777');
1566 @.This value shouldn't...@>
1567 acc:=0; cur_char:=" ";
1568 end
1569 else get_next;
1570 end;
1571 backup;
1572 end
1573
1574 @ @<Scan a small hex...@>=
1575 begin while ((cur_char>="0")and(cur_char<="9"))or
1576 ((cur_char>="A")and(cur_char<="F")) do
1577 begin if cur_char>="A" then cur_char:=cur_char+"0"+10-"A";
1578 acc:=acc*16+cur_char-"0";
1579 if acc>char_max then
1580 begin skip_error('This value shouldn''t exceed "FFFF');
1581 @.This value shouldn't...@>
1582 acc:=0; cur_char:=" ";
1583 end
1584 else get_next;
1585 end;
1586 backup;
1587 end
1588
1589 @ @<Scan a face...@>=
1590 begin if cur_char="B" then acc:=2
1591 else if cur_char="L" then acc:=4
1592 else if cur_char<>"M" then acc:=18;
1593 get_next;
1594 if cur_char="I" then incr(acc)
1595 else if cur_char<>"R" then acc:=18;
1596 get_next;
1597 if cur_char="C" then acc:=acc+6
1598 else if cur_char="E" then acc:=acc+12
1599 else if cur_char<>"R" then acc:=18;
1600 if acc>=18 then
1601 begin skip_error('Illegal face code, I changed it to MRR');
1602 @.Illegal face code...@>
1603 acc:=0;
1604 end;
1605 end
1606
1607 @ The routine that scans a four-byte value puts its output into |cur_bytes|,
1608 which is a record containing (yes, you guessed it) four bytes.
1609
1610 @<Types...@>=
1611 @!four_bytes=record @!b0:byte;@+@!b1:byte;@+@!b2:byte;@+@!b3:byte;@+end;
1612
1613 @ @d c0==cur_bytes.b0
1614 @d c1==cur_bytes.b1
1615 @d c2==cur_bytes.b2
1616 @d c3==cur_bytes.b3
1617
1618 @<Glob...@>=
1619 @!cur_bytes:four_bytes; {a four-byte accumulator}
1620 @!zero_bytes:four_bytes; {four bytes all zero}
1621
1622 @ @<Set init...@>=
1623 zero_bytes.b0:=0; zero_bytes.b1:=0; zero_bytes.b2:=0; zero_bytes.b3:=0;
1624
1625 @ Since the |get_four_bytes| routine is used very infrequently, no attempt
1626 has been made to make it fast; we only want it to work.
1627 This is no longer the case, but we hope it's not too slow.
1628
1629 @p procedure get_four_bytes; {scans an unsigned constant and sets |four_bytes|}
1630 var c:integer; {local two-byte accumulator}
1631 @!r:integer; {radix}
1632 begin repeat get_next;
1633 until cur_char<>" "; {skip the blanks before the type code}
1634 r:=0; cur_bytes:=zero_bytes; {start with the accumulator zero}
1635 if cur_char="H" then r:=16
1636 else if cur_char="O" then r:=8
1637 else if cur_char="D" then r:=10
1638 else skip_error('Decimal ("D"), octal ("O"), or hex ("H") value needed here');
1639 @.Decimal ("D"), octal ("O"), or hex...@>
1640 if r>0 then
1641 begin repeat get_next;
1642 until cur_char<>" "; {skip the blanks after the type code}
1643 while ((cur_char>="0")and(cur_char<="9"))or@|
1644 ((cur_char>="A")and(cur_char<="F")) do
1645 @<Multiply by |r|, add |cur_char-"0"|, and |get_next|@>;
1646 end;
1647 end;
1648
1649 function get_integer:integer; {scans an integer property value}
1650 var @!a:integer; {accumulator}
1651 begin get_four_bytes;
1652 a:=c0;
1653 if a>=@"80 then a:=a-@"100;
1654 get_integer:=(a*@"1000000)+(c1*@"10000)+(c2*@"100)+c3;
1655 end;
1656
1657 @ @<Multiply by |r|...@>=
1658 begin if cur_char>="A" then cur_char:=cur_char+"0"+10-"A";
1659 if cur_char>="0"+r then skip_error('Illegal digit')
1660 @.Illegal digit@>
1661 else begin c:=c3*r+cur_char-"0"; c3:=c mod 256;@/
1662 c:=c2*r+c div 256; c2:=c mod 256;@/
1663 c:=c1*r+c div 256; c1:=c mod 256;@/
1664 c:=c0*r+c div 256;
1665 if c<256 then c0:=c
1666 else begin cur_bytes:=zero_bytes;
1667 if r=8 then
1668 skip_error('Sorry, the maximum octal value is O 37777777777')
1669 @.Sorry, the maximum...@>
1670 else if r=10 then
1671 skip_error('Sorry, the maximum decimal value is D 4294967295')
1672 else skip_error('Sorry, the maximum hex value is H FFFFFFFF');
1673 end;
1674 get_next;
1675 end;
1676 end
1677
1678 @ The remaining scanning routine is the most interesting. It scans a real
1679 constant and returns the nearest |fix_word| approximation to that constant.
1680 A |fix_word| is a 32-bit integer that represents a real value that
1681 has been multiplied by $2^{20}$. Since \.{VPtoVF} restricts the magnitude
1682 of reals to 2048, the |fix_word| will have a magnitude less than $2^{31}$.
1683
1684 @d unity==@'4000000 {$2^{20}$, the |fix_word| 1.0}
1685
1686 @<Types...@>=
1687 @!fix_word=integer; {a scaled real value with 20 bits of fraction}
1688 @!unsigned_integer=integer;
1689
1690 @ When a real value is desired, we might as well treat `\.D' and `\.R'
1691 formats as if they were identical.
1692
1693 @p function get_fix:fix_word; {scans a real property value}
1694 var negative:boolean; {was there a minus sign?}
1695 @!acc:integer; {an accumulator}
1696 @!int_part:integer; {the integer part}
1697 @!j:0..7; {the number of decimal places stored}
1698 begin repeat get_next;
1699 until cur_char<>" "; {skip the blanks before the type code}
1700 negative:=false; acc:=0; {start with the accumulators zero}
1701 if (cur_char<>"R")and(cur_char<>"D") then
1702 skip_error('An "R" or "D" value is needed here')
1703 @.An "R" or "D" ... needed here@>
1704 else begin @<Scan the blanks and/or signs after the type code@>;
1705 while (cur_char>="0") and (cur_char<="9") do
1706 @<Multiply by 10, add |cur_char-"0"|, and |get_next|@>;
1707 int_part:=acc; acc:=0;
1708 if cur_char="." then @<Scan the fraction part and put it in |acc|@>;
1709 if (acc>=unity)and(int_part=2047) then
1710 skip_error('Real constants must be less than 2048')
1711 @.Real constants must be...@>
1712 else acc:=int_part*unity+acc;
1713 end;
1714 if negative then get_fix:=-acc@+else get_fix:=acc;
1715 end;
1716
1717 @ @<Scan the blanks...@>=
1718 repeat get_next;
1719 if cur_char="-" then
1720 begin cur_char:=" "; negative:=not negative;
1721 end
1722 else if cur_char="+" then cur_char:=" ";
1723 until cur_char<>" "
1724
1725 @ @<Multiply by 10...@>=
1726 begin acc:=acc*10+cur_char-"0";
1727 if acc>=2048 then
1728 begin skip_error('Real constants must be less than 2048');
1729 @.Real constants must be...@>
1730 acc:=0; cur_char:=" ";
1731 end
1732 else get_next;
1733 end
1734
1735 @ To scan the fraction $.d_1d_2\ldots\,$, we keep track of up to seven
1736 of the digits $d_j$. A correct result is obtained if we first compute
1737 $f^\prime=\lfloor 2^{21}(d_1\ldots d_j)/10^j\rfloor$, after which
1738 $f=\lfloor(f^\prime+1)/2\rfloor$. It is possible to have $f=1.0$.
1739
1740 @<Glob...@>=
1741 @!fraction_digits:array[1..7] of integer; {$2^{21}$ times $d_j$}
1742
1743 @ @<Scan the frac...@>=
1744 begin j:=0; get_next;
1745 while (cur_char>="0")and(cur_char<="9") do
1746 begin if j<7 then
1747 begin incr(j); fraction_digits[j]:=@'10000000*(cur_char-"0");
1748 end;
1749 get_next;
1750 end;
1751 acc:=0;
1752 while j>0 do
1753 begin acc:=fraction_digits[j]+(acc div 10); decr(j);
1754 end;
1755 acc:=(acc+10) div 20;
1756 end
1757
1758 @* Storing the property values.
1759 When property values have been found, they are squirreled away in a bunch
1760 of arrays. The header information is unpacked into bytes in an array
1761 called |header_bytes|. The ligature/kerning program is stored in an array
1762 of type |four_bytes|.
1763 Another |four_bytes| array holds the specifications of extensible characters.
1764 The kerns and parameters are stored in separate arrays of |fix_word| values.
1765 Virtual font data goes into an array |vf| of single-byte values.
1766
1767 We maintain information about at most |max_font+1| local fonts.
1768
1769 Instead of storing the design size in the header array, we will keep it
1770 in a |fix_word| variable until the last minute. The number of units in the
1771 design size is also kept in a |fix_word|.
1772
1773 @<Glob...@>=
1774 @!header_bytes:array[header_index] of byte; {the header block}
1775 @!header_ptr:header_index; {the number of header bytes in use}
1776 @!design_size:fix_word; {the design size}
1777 @!design_units:fix_word; {reciprocal of the scaling factor}
1778 @!frozen_du:boolean; {have we used |design_units| irrevocably?}
1779 @!seven_bit_safe_flag:boolean; {does the file claim to be seven-bit-safe?}
1780 @!lig_kern:array[0..max_lig_steps] of four_bytes; {the ligature program}
1781 @!nl:unsigned_integer; {the number of ligature/kern instructions so far}
1782 @!min_nl:unsigned_integer; {the final value of |nl| must be at least this}
1783 @!kern:array[0..max_kerns] of fix_word; {the distinct kerning amounts}
1784 @!nk:0..max_kerns; {the number of entries of |kern|}
1785 @!exten:array[char_type] of four_bytes; {extensible character specs}
1786 @!ne:xchar_type; {the number of extensible characters}
1787 @!param:array[1..max_param_words] of fix_word; {\.{FONTDIMEN} parameters}
1788 @!np:0..max_param_words; {the largest parameter set nonzero}
1789 @!check_sum_specified:boolean; {did the user name the check sum?}
1790 @!bchar:xchar_type; {right boundary character, |xmax_char| if unspecified}
1791 @!font_dir:integer; {font direction}
1792 @!vf:array[0..vf_size] of byte; {stored bytes for \.{VF} file}
1793 @!vf_ptr:0..vf_size; {first unused location in |vf|}
1794 @!vtitle_start:0..vf_size; {starting location of \.{VTITLE} string}
1795 @!vtitle_length:byte; {length of \.{VTITLE} string}
1796 @!packet_start:array[char_type] of 0..vf_size;
1797 {beginning location of character packet}
1798 @!packet_length:array[char_type] of integer; {length of character packet}
1799 @!font_ptr:xfont_type; {number of distinct local fonts seen}
1800 @!cur_font:xfont_type; {number of the current local font}
1801 @!fname_start:array[font_type] of 0..vf_size; {beginning of local font name}
1802 @!fname_length:array[font_type] of byte; {length of local font name}
1803 @!farea_start:array[font_type] of 0..vf_size; {beginning of local font area}
1804 @!farea_length:array[font_type] of byte; {length of local font area}
1805 @!font_checksum:array[font_type] of four_bytes; {local font checksum}
1806 @!font_number:array[xfont_type] of integer; {local font id number}
1807 @!font_at:array[font_type] of fix_word; {local font ``at size''}
1808 @!font_dsize:array[font_type] of fix_word; {local font design size}
1809
1810 @ @<Types...@>=
1811 @!char_type=0..max_char;
1812 @!xchar_type=0..xmax_char;
1813 @!xxchar_type=0..xxmax_char;
1814 @!font_type=0..max_font;
1815 @!xfont_type=0..xmax_font;
1816 @!header_index=0..max_header_bytes;
1817 @!indx=xxchar_type;
1818
1819 @ @<Local...@>=
1820 @!d:header_index; {an index into |header_bytes|}
1821
1822 @ We start by setting up the default values.
1823
1824 @d check_sum_loc=0
1825 @d design_size_loc=4
1826 @d coding_scheme_loc=8
1827 @d family_loc=coding_scheme_loc+40
1828 @d seven_flag_loc=family_loc+20
1829 @d face_loc=seven_flag_loc+3
1830
1831 @<Set init...@>=
1832 for d:=0 to 18*4-1 do header_bytes[d]:=0;
1833 header_bytes[8]:=11; header_bytes[9]:="U";
1834 header_bytes[10]:="N";
1835 header_bytes[11]:="S";
1836 header_bytes[12]:="P";
1837 header_bytes[13]:="E";
1838 header_bytes[14]:="C";
1839 header_bytes[15]:="I";
1840 header_bytes[16]:="F";
1841 header_bytes[17]:="I";
1842 header_bytes[18]:="E";
1843 header_bytes[19]:="D";
1844 @.UNSPECIFIED@>
1845 for d:=family_loc to family_loc+11 do header_bytes[d]:=header_bytes[d-40];
1846 design_size:=10*unity; design_units:=unity; frozen_du:=false;
1847 seven_bit_safe_flag:=false;@/
1848 header_ptr:=18*4; nl:=0; min_nl:=0; nk:=0; ne:=0; np:=0;@/
1849 check_sum_specified:=false; bchar:=xmax_char;@/
1850 font_dir:=0;
1851 vf_ptr:=0; vtitle_start:=0; vtitle_length:=0; font_ptr:=0;
1852 for k:=0 to max_char do packet_start[k]:=vf_size;
1853 for k:=0 to 127 do packet_length[k]:=1;
1854 for k:=128 to 255 do packet_length[k]:=2;
1855 for k:=256 to max_char do packet_length[k]:=3;
1856
1857 @ Most of the dimensions, however, go into the |memory| array. There are
1858 at most |max_char+2| widths, |max_char+2| heights,
1859 |max_char+2| depths, and |max_char+2| italic corrections,
1860 since the value 0 is required but it need not be used. So |memory| has room
1861 for |4*max_char+8| entries, each of which is a |fix_word|. An auxiliary table called
1862 |link| is used to link these words together in linear lists, so that
1863 sorting and other operations can be done conveniently.
1864
1865 We also add four ``list head'' words to the |memory| and |link| arrays;
1866 these are in locations |width| through |italic|, i.e., 1 through 4.
1867 For example, |link[height]| points to the smallest element in
1868 the sorted list of distinct heights that have appeared so far, and
1869 |memory[height]| is the number of distinct heights.
1870
1871 @<Types...@>=
1872 @!pointer=0..mem_size; {an index into memory}
1873
1874 @ The arrays |char_wd|, |char_ht|, |char_dp|, and |char_ic| contain
1875 pointers to the |memory| array entries where the corresponding dimensions
1876 appear. Two other arrays, |char_tag| and |char_remainder|, hold
1877 the other information that \.{TFM} files pack into a |char_info_word|.
1878
1879 @d no_tag=0 {vanilla character}
1880 @d lig_tag=1 {character has a ligature/kerning program}
1881 @d list_tag=2 {character has a successor in a charlist}
1882 @d ext_tag=3 {character is extensible}
1883 @d bchar_label==char_remainder[xmax_char]
1884 {beginning of ligature program for left boundary}
1885
1886 @<Glob...@>=
1887 @!memory:array[pointer] of fix_word; {character dimensions and kerns}
1888 @!mem_ptr:pointer; {largest |memory| word in use}
1889 @!link:array[pointer] of pointer; {to make lists of |memory| items}
1890 @!char_wd:array[char_type] of pointer; {pointers to the widths}
1891 @!char_ht:array[char_type] of pointer; {pointers to the heights}
1892 @!char_dp:array[char_type] of pointer; {pointers to the depths}
1893 @!char_ic:array[char_type] of pointer; {pointers to italic corrections}
1894 @!char_tag:array[char_type] of no_tag..ext_tag; {character tags}
1895 @!char_remainder:array[xchar_type] of xchar_type; {pointers to ligature labels,
1896 next larger characters, or extensible characters}
1897 @!top_width,@!top_height,@!top_depth,@!top_italic:integer;
1898
1899 @ @<Local...@>=
1900 @!c:integer; {runs through all character codes}
1901
1902 @ @<Set init...@>=
1903 bchar_label:=xmax_label;
1904 for c:=0 to max_char do
1905 begin char_wd[c]:=0; char_ht[c]:=0; char_dp[c]:=0; char_ic[c]:=0;@/
1906 char_tag[c]:=no_tag; char_remainder[c]:=0;
1907 end;
1908 memory[0]:=@'17777777777; {an ``infinite'' element at the end of the lists}
1909 memory[width]:=0; link[width]:=0; {width list is empty}
1910 memory[height]:=0; link[height]:=0; {height list is empty}
1911 memory[depth]:=0; link[depth]:=0; {depth list is empty}
1912 memory[italic]:=0; link[italic]:=0; {italic list is empty}
1913 mem_ptr:=italic;
1914
1915 @ As an example of these data structures, let us consider the simple
1916 routine that inserts a potentially new element into one of the dimension
1917 lists. The first parameter indicates the list head (i.e., |h=width| for
1918 the width list, etc.); the second parameter is the value that is to be
1919 inserted into the list if it is not already present. The procedure
1920 returns the value of the location where the dimension appears in |memory|.
1921 The fact that |memory[0]| is larger than any legal dimension makes the
1922 algorithm particularly short.
1923
1924 We do have to handle two somewhat subtle situations. A width of zero must be
1925 put into the list, so that a zero-width character in the font will not appear
1926 to be nonexistent (i.e., so that its |char_wd| index will not be zero), but
1927 this does not need to be done for heights, depths, or italic corrections.
1928 Furthermore, it is necessary to test for memory overflow even though we
1929 have provided room for the maximum number of different dimensions in any
1930 legal font, since the \.{VPL} file might foolishly give any number of
1931 different sizes to the same character.
1932
1933 @p function sort_in(@!h:pointer;@!d:fix_word):pointer; {inserts into list}
1934 var p:pointer; {the current node of interest}
1935 begin if (d=0)and(h<>width) then sort_in:=0
1936 else begin p:=h;
1937 while d>=memory[link[p]] do p:=link[p];
1938 if (d=memory[p])and(p<>h) then sort_in:=p
1939 else if mem_ptr=mem_size then
1940 begin err_print('Memory overflow: too many widths, etc');
1941 @.Memory overflow...@>
1942 print_ln('Congratulations! It''s hard to make this error.');
1943 sort_in:=p;
1944 end
1945 else begin incr(mem_ptr); memory[mem_ptr]:=d;
1946 link[mem_ptr]:=link[p]; link[p]:=mem_ptr; incr(memory[h]);
1947 sort_in:=mem_ptr;
1948 end;
1949 end;
1950 end;
1951
1952 @ When these lists of dimensions are eventually written to the \.{OFM}
1953 file, we may have to do some rounding of values, because the \.{OFM} file
1954 allows at most 65536 widths, 256 heights, 256 depths, and 256 italic
1955 corrections. The following procedure takes a given list head |h| and a
1956 given dimension |d|, and returns the minimum $m$ such that the elements of
1957 the list can be covered by $m$ intervals of width $d$. It also sets
1958 |next_d| to the smallest value $d^\prime>d$ such that the covering found
1959 by this procedure would be different. In particular, if $d=0$ it computes
1960 the number of elements of the list, and sets |next_d| to the smallest
1961 distance between two list elements. (The covering by intervals of width
1962 |next_d| is not guaranteed to have fewer than $m$ elements, but in practice
1963 this seems to happen most of the time.)
1964
1965 @<Glob...@>=
1966 @!next_d:fix_word; {the next larger interval that is worth trying}
1967
1968 @ Once again we can make good use of the fact that |memory[0]| is ``infinite.''
1969
1970 @p function min_cover(@!h:pointer;@!d:fix_word):integer;
1971 var p:pointer; {the current node of interest}
1972 @!l:fix_word; {the least element covered by the current interval}
1973 @!m:integer; {the current size of the cover being generated}
1974 begin m:=0; p:=link[h]; next_d:=memory[0];
1975 while p<>0 do
1976 begin incr(m); l:=memory[p];
1977 while memory[link[p]]<=l+d do p:=link[p];
1978 p:=link[p];
1979 if memory[p]-l<next_d then next_d:=memory[p]-l;
1980 end;
1981 min_cover:=m;
1982 end;
1983
1984 @ The following procedure uses |min_cover| to determine the smallest $d$
1985 such that a given list can be covered with at most a given number of
1986 intervals.
1987
1988 @p function shorten(@!h:pointer;m:integer):fix_word; {finds best way to round}
1989 var d:fix_word; {the current trial interval length}
1990 @!k:integer; {the size of a minimum cover}
1991 begin if memory[h]>m then
1992 begin excess:=memory[h]-m;
1993 k:=min_cover(h,0); d:=next_d; {now the answer is at least |d|}
1994 repeat d:=d+d; k:=min_cover(h,d);
1995 until k<=m; {first we ascend rapidly until finding the range}
1996 d:=d div 2; k:=min_cover(h,d); {now we run through the feasible steps}
1997 while k>m do
1998 begin d:=next_d; k:=min_cover(h,d);
1999 end;
2000 shorten:=d;
2001 end
2002 else shorten:=0;
2003 end;
2004
2005 @ When we are nearly ready to output the \.{TFM} file, we will set
2006 |index[p]:=k| if the dimension in |memory[p]| is being rounded to the
2007 |k|th element of its list.
2008
2009 @<Glob...@>=
2010 @!index:array[pointer] of byte;
2011 @!excess:byte; {number of words to remove, if list is being shortened}
2012
2013 @ Here is the procedure that sets the |index| values. It also shortens
2014 the list so that there is only one element per covering interval;
2015 the remaining elements are the midpoints of their clusters.
2016
2017 @p procedure set_indices(@!h:pointer;@!d:fix_word); {reduces and indexes a list}
2018 var p:pointer; {the current node of interest}
2019 @!q:pointer; {trails one step behind |p|}
2020 @!m:byte; {index number of nodes in the current interval}
2021 @!l:fix_word; {least value in the current interval}
2022 begin q:=h; p:=link[q]; m:=0;
2023 while p<>0 do
2024 begin incr(m); l:=memory[p]; index[p]:=m;
2025 while memory[link[p]]<=l+d do
2026 begin p:=link[p]; index[p]:=m; decr(excess);
2027 if excess=0 then d:=0;
2028 end;
2029 link[q]:=p; memory[p]:=l+(memory[p]-l) div 2; q:=p; p:=link[p];
2030 end;
2031 memory[h]:=m;
2032 end;
2033
2034 @* The input phase.
2035 We're ready now to read and parse the \.{VPL} file, storing property
2036 values as we go.
2037
2038 @<Glob...@>=
2039 @!c:integer; {the current character or byte being processed}
2040 @!cprime:char_type; {Processing for several characters together}
2041 @!crange:char_type; {ditto}
2042 @!x:fix_word; {current dimension of interest}
2043 @!k:integer; {general-purpose index}
2044
2045 @ @<Read all the input@>=
2046 cur_char:=" ";
2047 repeat while cur_char=" " do get_next;
2048 if cur_char="(" then @<Read a font property value@>
2049 else if (cur_char=")")and not input_has_ended then
2050 begin err_print('Extra right parenthesis');
2051 incr(loc); cur_char:=" ";
2052 end
2053 @.Extra right parenthesis@>
2054 else if not input_has_ended then junk_error;
2055 until input_has_ended
2056
2057 @ The |junk_error| routine just referred to is called when something
2058 appears in the forbidden area between properties of a property list.
2059
2060 @p procedure junk_error; {gets past no man's land}
2061 begin err_print('There''s junk here that is not in parentheses');
2062 @.There's junk here...@>
2063 skip_to_paren;
2064 end;
2065
2066 @ For each font property, we are supposed to read the data from the
2067 left parenthesis that is the current value of |cur_char| to the right
2068 parenthesis that matches it in the input. The main complication is
2069 to recover with reasonable grace from various error conditions that might arise.
2070
2071 @<Read a font property value@>=
2072 begin get_name;
2073 if cur_code=comment_code then skip_to_end_of_item
2074 else if cur_code>char_repeat_code then
2075 flush_error('This property name doesn''t belong on the outer level')
2076 @.This property name doesn't belong...@>
2077 else begin @<Read the font property value specified by |cur_code|@>;
2078 finish_the_property;
2079 end;
2080 end
2081
2082 @ @<Read the font property value spec...@>=
2083 case cur_code of
2084 check_sum_code: begin check_sum_specified:=true; read_four_bytes(check_sum_loc);
2085 end;
2086 design_size_code: @<Read the design size@>;
2087 design_units_code: @<Read the design units@>;
2088 coding_scheme_code: read_BCPL(coding_scheme_loc,40);
2089 family_code: read_BCPL(family_loc,20);
2090 face_code: begin c:=get_byte; if c>255 then
2091 begin err_print('FACE clipped to 255'); c:=255 end;
2092 header_bytes[face_loc]:=c
2093 end;
2094 seven_bit_safe_flag_code: @<Read the seven-bit-safe flag@>;
2095 header_code: @<Read an indexed header word@>;
2096 font_dimen_code: @<Read font parameter list@>;
2097 lig_table_code: read_lig_kern;
2098 boundary_char_code: bchar:=get_byte;
2099 virtual_title_code: begin vtitle_start:=vf_ptr; copy_to_end_of_item;
2100 if vf_ptr>vtitle_start+255 then
2101 begin err_print('VTITLE clipped to 255 characters'); vtitle_length:=255;
2102 @.VTITLE clipped...@>
2103 end
2104 else vtitle_length:=vf_ptr-vtitle_start;
2105 end;
2106 map_font_code:@<Read a local font list@>;
2107 character_code: read_char_info;
2108 ofm_level_code: @<Read OFM level code@>;
2109 font_dir_code: @<Read font direction code@>;
2110 n_font_dir_code: @<Read natural font direction code@>;
2111 char_repeat_code: read_repeated_character_info;
2112 font_rule_code: read_font_rule_list;
2113 font_glue_code: read_font_glue_list;
2114 font_penalty_code: read_font_penalty_list;
2115 font_mvalue_code: read_font_mvalue_list;
2116 font_fvalue_code: read_font_fvalue_list;
2117 font_ivalue_code: read_font_ivalue_list;
2118 end
2119
2120 @ The |case| statement just given makes use of three subroutines that we
2121 haven't defined yet. The first of these puts a 32-bit octal quantity
2122 into four specified bytes of the header block.
2123
2124 @p procedure read_four_bytes(l:header_index);
2125 begin get_four_bytes;
2126 header_bytes[l]:=c0;
2127 header_bytes[l+1]:=c1;
2128 header_bytes[l+2]:=c2;
2129 header_bytes[l+3]:=c3;
2130 end;
2131
2132 @ The second little procedure is used to scan a string and to store it in
2133 the ``{\mc BCPL} format'' required by \.{TFM} files. The string is supposed
2134 to contain at most |n| bytes, including the first byte (which holds the
2135 length of the rest of the string).
2136
2137 @p procedure read_BCPL(l:header_index;n:byte);
2138 var k:header_index;
2139 begin k:=l;
2140 while cur_char=" " do get_next;
2141 while (cur_char<>"(")and(cur_char<>")") do
2142 begin if k<l+n then incr(k);
2143 if k<l+n then header_bytes[k]:=cur_char;
2144 get_next;
2145 end;
2146 if k=l+n then
2147 begin err_print('String is too long; its first ',n-1:1,
2148 @.String is too long...@>
2149 ' characters will be kept'); decr(k);
2150 end;
2151 header_bytes[l]:=k-l;
2152 while k<l+n-1 do {tidy up the remaining bytes by setting them to nulls}
2153 begin incr(k); header_bytes[k]:=0;
2154 end;
2155 end;
2156
2157 @ @<Read the design size@>=
2158 begin next_d:=get_fix;
2159 if next_d<unity then
2160 err_print('The design size must be at least 1')
2161 @.The design size must...@>
2162 else design_size:=next_d;
2163 end
2164
2165 @ @<Read the design units@>=
2166 begin next_d:=get_fix;
2167 if next_d<=0 then
2168 err_print('The number of units per design size must be positive')
2169 @.The number of units...@>
2170 else if frozen_du then
2171 err_print('Sorry, it''s too late to change the design units')
2172 @.Sorry, it's too late...@>
2173 else design_units:=next_d;
2174 end
2175
2176 @ @<Read the seven-bit-safe...@>=
2177 begin while cur_char=" " do get_next;
2178 if cur_char="T" then seven_bit_safe_flag:=true
2179 else if cur_char="F" then seven_bit_safe_flag:=false
2180 else err_print('The flag value should be "TRUE" or "FALSE"');
2181 @.The flag value should be...@>
2182 skip_to_paren;
2183 end
2184
2185 @ @<Read an indexed header word@>=
2186 begin c:=get_byte;
2187 if c<18 then skip_error('HEADER indices should be 18 or more')
2188 @.HEADER indices...@>
2189 else if 4*c+4>max_header_bytes then
2190 skip_error('This HEADER index is too big for my present table size')
2191 @.This HEADER index is too big...@>
2192 else begin
2193 while header_ptr<4*c+4 do
2194 begin header_bytes[header_ptr]:=0; incr(header_ptr);
2195 end;
2196 read_four_bytes(4*c);
2197 end;
2198 end
2199
2200 @ The remaining kinds of font property values that need to be read are
2201 those that involve property lists on higher levels. Each of these has a
2202 loop similar to the one that was used at level zero. Then we put the
2203 right parenthesis back so that `|finish_the_property|' will be happy;
2204 there is probably a more elegant way to do this.
2205
2206 @d finish_inner_property_list==begin decr(loc); incr(level); cur_char:=")";
2207 end
2208
2209 @<Read font parameter list@>=
2210 begin while level=1 do
2211 begin while cur_char=" " do get_next;
2212 if cur_char="(" then @<Read a parameter value@>
2213 else if cur_char=")" then skip_to_end_of_item
2214 else junk_error;
2215 end;
2216 finish_inner_property_list;
2217 end
2218
2219 @ @<Read a parameter value@>=
2220 begin get_name;
2221 if cur_code=comment_code then skip_to_end_of_item
2222 else if (cur_code<parameter_code)or(cur_code>=char_wd_code) then
2223 flush_error('This property name doesn''t belong in a FONTDIMEN list')
2224 @.This property name doesn't belong...@>
2225 else begin if cur_code=parameter_code then c:=get_integer
2226 else c:=cur_code-parameter_code;
2227 if c<1 then flush_error('PARAMETER index must be at least 1')
2228 @.PARAMETER index must be...@>
2229 else if c>max_param_words then
2230 flush_error('This PARAMETER index is too big for my present table size')
2231 @.This PARAMETER index is too big...@>
2232 else begin while np<c do
2233 begin incr(np); param[np]:=0;
2234 end;
2235 param[c]:=get_fix;
2236 finish_the_property;
2237 end;
2238 end;
2239 end
2240
2241 @ @<Read a local font list@>=
2242 begin font_number[font_ptr]:=get_integer; cur_font:=0;
2243 while font_number[font_ptr]<>font_number[cur_font] do incr(cur_font);
2244 if cur_font=font_ptr then {it's a new font number}
2245 if font_ptr<xmax_font then @<Initialize a new local font@>
2246 else err_print('Sorry, too many different mapfonts');
2247 @.Sorry, too many different mapfonts@>
2248 if cur_font=font_ptr then skip_to_end_of_item
2249 else while level=1 do
2250 begin while cur_char=" " do get_next;
2251 if cur_char="(" then @<Read a local font property@>
2252 else if cur_char=")" then skip_to_end_of_item
2253 else junk_error;
2254 end;
2255 finish_inner_property_list;
2256 end
2257
2258 @ @<Initialize a new local font@>=
2259 begin incr(font_ptr);
2260 fname_start[cur_font]:=vf_size; fname_length[cur_font]:=4; {\.{NULL}}
2261 farea_start[cur_font]:=vf_size; farea_length[cur_font]:=0;
2262 font_checksum[cur_font]:=zero_bytes;
2263 font_at[cur_font]:=@'4000000; {denotes design size of this virtual font}
2264 font_dsize[cur_font]:=@'50000000; {the |fix_word| for 10}
2265 end
2266
2267 @ @<Read a local font property@>=
2268 begin get_name;
2269 if cur_code=comment_code then skip_to_end_of_item
2270 else if (cur_code<font_name_code)or(cur_code>font_dsize_code) then
2271 flush_error('This property name doesn''t belong in a MAPFONT list')
2272 @.This property name doesn't belong...@>
2273 else begin case cur_code of
2274 font_name_code:@<Read a local font name@>;
2275 font_area_code:@<Read a local font area@>;
2276 font_checksum_code:begin get_four_bytes; font_checksum[cur_font]:=cur_bytes;
2277 end;
2278 font_at_code: begin frozen_du:=true;
2279 if design_units=unity then font_at[cur_font]:=get_fix
2280 else font_at[cur_font]:=round((get_fix/design_units)*1048576.0);
2281 end;
2282 font_dsize_code:font_dsize[cur_font]:=get_fix;
2283 end; {there are no other cases}
2284 finish_the_property;
2285 end;
2286 end
2287
2288 @ @<Read a local font name@>=
2289 begin fname_start[cur_font]:=vf_ptr; copy_to_end_of_item;
2290 if vf_ptr>fname_start[cur_font]+255 then
2291 begin err_print('FONTNAME clipped to 255 characters');
2292 @.FONTNAME clipped...@>
2293 fname_length[cur_font]:=255;
2294 end
2295 else fname_length[cur_font]:=vf_ptr-fname_start[cur_font];
2296 end
2297
2298 @ @<Read a local font area@>=
2299 begin farea_start[cur_font]:=vf_ptr; copy_to_end_of_item;
2300 if vf_ptr>farea_start[cur_font]+255 then
2301 begin err_print('FONTAREA clipped to 255 characters');
2302 @.FONTAREA clipped...@>
2303 farea_length[cur_font]:=255;
2304 end
2305 else farea_length[cur_font]:=vf_ptr-farea_start[cur_font];
2306 end
2307
2308 @ @<Read ligature/kern list@>=
2309 begin lk_step_ended:=false;
2310 while level=1 do
2311 begin while cur_char=" " do get_next;
2312 if cur_char="(" then read_lig_kern_command
2313 else if cur_char=")" then skip_to_end_of_item
2314 else junk_error;
2315 end;
2316 finish_inner_property_list;
2317 end
2318
2319 @ @<Read a ligature/kern command@>=
2320 begin get_name;
2321 if cur_code=comment_code then skip_to_end_of_item
2322 else if (cur_code<label_code)or(cur_code>ckrn_code) then
2323 flush_error('This property name doesn''t belong in a LIGTABLE list')
2324 @.This property name doesn't belong...@>
2325 else begin case cur_code of
2326 label_code:@<Read a label step@>;
2327 stop_code:@<Read a stop step@>;
2328 skip_code:@<Read a skip step@>;
2329 krn_code:@<Read a kerning step@>;
2330 lig_code,lig_code+1,lig_code+2,lig_code+3,lig_code+5,lig_code+6,lig_code+7,
2331 lig_code+11:@<Read a ligature step@>;
2332 clabel_code:@<Read an extended label step@>;
2333 cpen_code:@<Read an extended penalty step@>;
2334 cglue_code:@<Read an extended glue step@>;
2335 cpenglue_code:@<Read an extended penalty/glue step@>;
2336 ckrn_code:@<Read an extended kern step@>;
2337 end; {there are no other cases |>=label_code| and |<=ckrn_code|}
2338 finish_the_property;
2339 end;
2340 end
2341
2342 @ When a character is about to be tagged, we call the following
2343 procedure so that an error message is given in case of multiple tags.
2344
2345 @p procedure check_tag(c:integer); {print error if |c| already tagged}
2346 begin case char_tag[c] of
2347 no_tag: do_nothing;
2348 lig_tag: err_print('This character already appeared in a LIGTABLE LABEL');
2349 @.This character already...@>
2350 list_tag: err_print('This character already has a NEXTLARGER spec');
2351 ext_tag: err_print('This character already has a VARCHAR spec');
2352 end;
2353 end;
2354
2355 @ @<Read a label step@>=
2356 begin while cur_char=" " do get_next;
2357 if cur_char="B" then
2358 begin bchar_label:=nl; skip_to_paren; {\.{LABEL BOUNDARYCHAR}}
2359 end
2360 else begin backup; c:=get_byte;
2361 check_tag(c); char_tag[c]:=lig_tag; char_remainder[c]:=nl;
2362 end;
2363 if min_nl<=nl then min_nl:=nl+1;
2364 lk_step_ended:=false;
2365 end
2366
2367 @ @d stop_flag=128 {value indicating `\.{STOP}' in a lig/kern program}
2368 @d kern_flag=128 {op code for a kern step}
2369
2370 @<Globals...@>=
2371 @!lk_step_ended:boolean;
2372 {was the last \.{LIGTABLE} property \.{LIG} or \.{KRN}?}
2373 @!krn_ptr:0..max_kerns; {an index into |kern|}
2374
2375 @ @<Read a stop step@>=
2376 if not lk_step_ended then
2377 err_print('STOP must follow LIG or KRN')
2378 @.STOP must follow LIG or KRN@>
2379 else begin
2380 lig_kern[nl-1].b0:=lig_kern[nl-1].b0 div 256 * 256 + stop_flag;
2381 lk_step_ended:=false;
2382 end
2383
2384 @ @<Read a skip step@>=
2385 if not lk_step_ended then
2386 err_print('SKIP must follow LIG or KRN')
2387 @.SKIP must follow LIG or KRN@>
2388 else begin c:=get_byte;
2389 if c>=128 then err_print('Maximum SKIP amount is 127')
2390 @.Maximum SKIP amount...@>
2391 else if nl+c>=max_lig_steps then
2392 err_print('Sorry, LIGTABLE too long for me to handle')
2393 @.Sorry, LIGTABLE too long...@>
2394 else begin lig_kern[nl-1].b0:=c;
2395 if min_nl<=nl+c then min_nl:=nl+c+1;
2396 end;
2397 lk_step_ended:=false;
2398 end
2399
2400 @ @<Read a ligature step@>=
2401 begin lig_kern[nl].b0:=0;
2402 lig_kern[nl].b2:=cur_code-lig_code;
2403 lig_kern[nl].b1:=get_byte;
2404 lig_kern[nl].b3:=get_byte;
2405 if nl>=max_lig_steps-1 then
2406 err_print('Sorry, LIGTABLE too long for me to handle')
2407 @.Sorry, LIGTABLE too long...@>
2408 else incr(nl);
2409 lk_step_ended:=true;
2410 end
2411
2412 @ @<Read a kerning step@>=
2413 begin lig_kern[nl].b0:=0; lig_kern[nl].b1:=get_byte;
2414 kern[nk]:=get_fix; krn_ptr:=0;
2415 while kern[krn_ptr]<>kern[nk] do incr(krn_ptr);
2416 if krn_ptr=nk then
2417 begin if nk<max_kerns then incr(nk)
2418 else begin err_print('Sorry, too many different kerns for me to handle');
2419 @.Sorry, too many different kerns...@>
2420 decr(krn_ptr);
2421 end;
2422 end;
2423 if ofm_level=-1 then begin
2424 lig_kern[nl].b2:=kern_flag+(krn_ptr div 256);
2425 lig_kern[nl].b3:=krn_ptr mod 256;
2426 end
2427 else begin
2428 lig_kern[nl].b2:=kern_flag+(krn_ptr div 65536);
2429 lig_kern[nl].b3:=krn_ptr mod 65536;
2430 end;
2431 if nl>=max_lig_steps-1 then
2432 err_print('Sorry, LIGTABLE too long for me to handle')
2433 @.Sorry, LIGTABLE too long...@>
2434 else incr(nl);
2435 lk_step_ended:=true;
2436 end
2437
2438 @ @<Global...@>=
2439 @!category_remainders:array[0..256] of integer;
2440 @!ivalue_category,@!max_ivalue_category:integer;
2441 @!glue_category,@!max_glue_category:integer;
2442 @!penalty_category,@!max_penalty_category:integer;
2443
2444 @ @<Set init...@>=
2445 for ivalue_category:=0 to 256 do
2446 begin category_remainders[ivalue_category]:=-1;
2447 end;
2448 max_ivalue_category:=-1;
2449 max_glue_category:=-1;
2450 max_penalty_category:=-1;
2451
2452 @ @<Read an extended label step@>=
2453 begin c:=get_byte;
2454 category_remainders[c]:=nl;
2455 if max_ivalue_category<c then max_ivalue_category:=c;
2456 if min_nl<=nl then min_nl:=nl+1;
2457 lk_step_ended:=false;
2458 end
2459
2460 @ @<Read an extended penalty step@>=
2461 begin lig_kern[nl].b0:=256; lig_kern[nl].b1:=get_byte;
2462 lig_kern[nl].b2:=17;
2463 penalty_category:=get_byte;
2464 if max_penalty_category<penalty_category then
2465 max_penalty_category:=penalty_category;
2466 lig_kern[nl].b3:=penalty_category;
2467 if nl>=max_lig_steps-1 then
2468 err_print('Sorry, LIGTABLE too long for me to handle')
2469 @.Sorry, LIGTABLE too long...@>
2470 else incr(nl);
2471 lk_step_ended:=true;
2472 end
2473
2474 @ @<Read an extended glue step@>=
2475 begin lig_kern[nl].b0:=256; lig_kern[nl].b1:=get_byte;
2476 lig_kern[nl].b2:=18;
2477 glue_category:=get_byte;
2478 if max_glue_category<glue_category then
2479 max_glue_category:=glue_category;
2480 lig_kern[nl].b3:=glue_category;
2481 if nl>=max_lig_steps-1 then
2482 err_print('Sorry, LIGTABLE too long for me to handle')
2483 @.Sorry, LIGTABLE too long...@>
2484 else incr(nl);
2485 lk_step_ended:=true;
2486 end
2487
2488 @ @<Read an extended penalty/glue step@>=
2489 begin lig_kern[nl].b0:=256; lig_kern[nl].b1:=get_byte;
2490 lig_kern[nl].b2:=19;
2491 penalty_category:=get_byte;
2492 if max_penalty_category<penalty_category then
2493 max_penalty_category:=penalty_category;
2494 glue_category:=get_byte;
2495 if max_glue_category<glue_category then
2496 max_glue_category:=glue_category;
2497 lig_kern[nl].b3:=penalty_category*256+glue_category;
2498 if nl>=max_lig_steps-1 then
2499 err_print('Sorry, LIGTABLE too long for me to handle')
2500 @.Sorry, LIGTABLE too long...@>
2501 else incr(nl);
2502 lk_step_ended:=true;
2503 end
2504
2505 @ @<Read an extended kern step@>=
2506 begin lig_kern[nl].b0:=256; lig_kern[nl].b1:=get_byte;
2507 lig_kern[nl].b2:=20;
2508 kern[nk]:=get_fix; krn_ptr:=0;
2509 while kern[krn_ptr]<>kern[nk] do incr(krn_ptr);
2510 if krn_ptr=nk then
2511 begin if nk<max_kerns then incr(nk)
2512 else begin err_print('Sorry, too many different kerns for me to handle');
2513 @.Sorry, too many different kerns...@>
2514 decr(krn_ptr);
2515 end;
2516 end;
2517 if krn_ptr>65535 then
2518 err_print('Sorry, too many different kerns for me to handle');
2519 lig_kern[nl].b3:=krn_ptr;
2520 if nl>=max_lig_steps-1 then
2521 err_print('Sorry, LIGTABLE too long for me to handle')
2522 @.Sorry, LIGTABLE too long...@>
2523 else incr(nl);
2524 lk_step_ended:=true;
2525 end
2526
2527 @ @<Globals...@>=
2528 @!char_extended_tag:array [char_type] of boolean;
2529
2530 @ @<Set init...@>=
2531 for c:=0 to max_char do
2532 char_extended_tag[c]:=false;
2533
2534 @ @<Finish up the extended font stuff@>=
2535 begin
2536 if max_penalty_category>0 then begin
2537 if nkp=0 then
2538 err_print('No PENALTY table')
2539 else if npp[0]<max_penalty_category then
2540 err_print('Not enough PENALTY entries');
2541 end;
2542 if max_glue_category>0 then begin
2543 if nkg=0 then
2544 err_print('No GLUE table')
2545 else if npg[0]<max_glue_category then
2546 err_print('Not enough GLUE entries');
2547 end;
2548 if max_ivalue_category>0 then begin
2549 if nki=0 then
2550 err_print('No IVALUE table')
2551 else if npi[0]<max_ivalue_category then
2552 err_print('Not enough IVALUE entries')
2553 else begin
2554 for c:=0 to max_char do begin
2555 if (char_wd[c]<>0) then begin
2556 for j:=0 to max_ivalue_category do
2557 if char_table[c,0]=j then begin
2558 if category_remainders[j]<>-1 then begin
2559 if char_tag[c]<>0 then
2560 err_print('Character already has a tag')
2561 else begin
2562 char_extended_tag[c]:=true;
2563 char_remainder[c]:=category_remainders[j];
2564 end;
2565 end;
2566 end;
2567 end;
2568 end;
2569 end;
2570 end;
2571 end
2572
2573 @ @<Global...@>=
2574 tables_read:boolean;
2575
2576 @ @<Set init...@>=
2577 tables_read:=false;
2578
2579 @ Finally we come to the part of \.{VPtoVF}'s input mechanism
2580 that is used most, the processing of individual character data.
2581
2582 @<Read character info list@>=
2583 begin
2584 if not tables_read then begin
2585 @<Compute the new header information for OFM files@>;
2586 tables_read:=true;
2587 end;
2588 c:=get_byte; {read the character code that is being specified}
2589 @<Print |c| in hex notation@>;
2590 while level=1 do
2591 begin while cur_char=" " do get_next;
2592 if cur_char="(" then read_character_property
2593 else if cur_char=")" then skip_to_end_of_item
2594 else junk_error;
2595 end;
2596 if char_wd[c]=0 then char_wd[c]:=sort_in(width,0); {legitimatize |c|}
2597 finish_inner_property_list;
2598 end
2599
2600 @ @<Globals...@>=
2601 @!char_original:array [0..max_char] of integer;
2602 @!char_repeats:array [0..max_char] of integer;
2603 @!diff:boolean;
2604 @!needed_space,@!extra_bytes:integer;
2605
2606 @ @<Set init...@>=
2607 for ch_entry:=0 to max_char do begin
2608 char_original[ch_entry]:=ch_entry;
2609 char_repeats[ch_entry]:=0;
2610 end;
2611
2612 @ @<Read repeated character info@>=
2613 begin
2614 if not tables_read then begin
2615 compute_new_header_ofm;
2616 tables_read:=true;
2617 end;
2618 c:=get_byte; {read the character code that is being specified}
2619 @<Print |c| in hex notation@>;
2620 crange:=get_byte; {read how many characters are being defined}
2621 if (crange<0) then begin
2622 err_print('Character ranges must be positive');
2623 crange:=0;
2624 end;
2625 if ((c+crange)>max_char) then begin
2626 err_print('Character range too large');
2627 crange:=0;
2628 end;
2629 print('-'); print_hex(c+crange); incr(chars_on_line);
2630 while level=1 do begin
2631 while cur_char=" " do get_next;
2632 if cur_char="(" then read_character_property
2633 else if cur_char=")" then skip_to_end_of_item
2634 else junk_error;
2635 end;
2636 if char_wd[c]=0 then char_wd[c]:=sort_in(width,0); {legitimatize |c|}
2637 finish_inner_property_list;
2638 cprime:=c;
2639 for c:=(cprime+1) to (cprime+crange) do begin
2640 char_wd[c]:=char_wd[cprime];
2641 char_ht[c]:=char_ht[cprime];
2642 char_dp[c]:=char_dp[cprime];
2643 char_ic[c]:=char_ic[cprime];
2644 char_tag[c]:=char_tag[cprime];
2645 char_remainder[c]:=char_remainder[cprime];
2646 packet_start[c]:=packet_start[cprime];
2647 packet_length[c]:=packet_length[cprime];
2648 for tab:=0 to (nki+nkf+nkm+nkr+nkg+nkp-1) do begin
2649 char_table[c,tab]:= char_table[cprime,tab];
2650 end;
2651 end;
2652 end
2653
2654 @ Tables for character parameters
2655
2656 @d char_param_tables==8
2657
2658 @<Globals...@>=
2659 @!char_table:array [0..max_char,0..char_param_tables] of integer;
2660 @!ch_table,@!ch_entry:integer;
2661 @!temp_value:integer;
2662
2663 @ @<Set init...@>=
2664 for c:=0 to max_char do
2665 for ch_table:=0 to char_param_tables do
2666 char_table[c,ch_table]:=0;
2667
2668 @ @d get_char_table_entry(#)==
2669 begin ch_table:=get_integer;
2670 if (ch_table<0)or(ch_table>=#) then
2671 flush_error('Character property index out of range')
2672 @.Character property index...@>
2673 else begin get_char_table_entry_end
2674 @d get_char_table_entry_end(#)==
2675 ch_table:=ch_table+#;
2676 if ch_table>char_param_tables then
2677 flush_error('Character property exceeds table size')
2678 @.Character property exceeds...@>
2679 else begin
2680 if ch_table>npc then npc:=ch_table;
2681 char_table[c,ch_table]:=get_integer;
2682 end;
2683 end;
2684 end
2685
2686 @<Read a character property@>=
2687 begin get_name;
2688 if cur_code=comment_code then skip_to_end_of_item
2689 else if (cur_code<char_wd_code)or(cur_code>var_char_code) then
2690 flush_error('This property name doesn''t belong in a CHARACTER list')
2691 @.This property name doesn't belong...@>
2692 else begin case cur_code of
2693 char_wd_code:char_wd[c]:=sort_in(width,get_fix);
2694 char_ht_code:char_ht[c]:=sort_in(height,get_fix);
2695 char_dp_code:char_dp[c]:=sort_in(depth,get_fix);
2696 char_ic_code:char_ic[c]:=sort_in(italic,get_fix);
2697 sec_width_code,
2698 sec_height_code,
2699 sec_depth_code,
2700 sec_italic_code,
2701 accent_code,
2702 prim_top_axis_code,
2703 prim_top_axis_bis_code,
2704 prim_bot_axis_code,
2705 prim_bot_axis_bis_code,
2706 prim_mid_hor_code,
2707 prim_mid_vert_code,
2708 prim_base_slant_code,
2709 sec_top_axis_code,
2710 sec_top_axis_bis_code,
2711 sec_bot_axis_code,
2712 sec_bot_axis_bis_code,
2713 sec_mid_hor_code,
2714 sec_mid_vert_code,
2715 sec_base_slant_code:temp_value:=get_fix;
2716 next_larger_code:begin check_tag(c); char_tag[c]:=list_tag;
2717 char_remainder[c]:=get_byte;
2718 end;
2719 map_code:read_packet(c);
2720 var_char_code:@<Read an extensible recipe for |c|@>;
2721 char_ivalue_code: get_char_table_entry(nki)(0);
2722 char_fvalue_code: get_char_table_entry(nkf)(nki);
2723 char_mvalue_code: get_char_table_entry(nkm)(nki+nkf);
2724 char_rule_code: get_char_table_entry(nkr)(nki+nkf+nkm);
2725 char_glue_code: get_char_table_entry(nkg)(nki+nkf+nkm+nkr);
2726 char_penalty_code: get_char_table_entry(nkp)(nki+nkf+nkm+nkr+nkg);
2727 end;@/
2728 finish_the_property;
2729 end;
2730 end
2731
2732 @ @<Read an extensible r...@>=
2733 begin if ne=xmax_char then
2734 err_print('Sorry, too many VARCHAR specs')
2735 @.Sorry, too many VARCHAR specs@>
2736 else begin check_tag(c); char_tag[c]:=ext_tag; char_remainder[c]:=ne;@/
2737 exten[ne]:=zero_bytes;
2738 while level=2 do
2739 begin while cur_char=" " do get_next;
2740 if cur_char="(" then @<Read an extensible piece@>
2741 else if cur_char=")" then skip_to_end_of_item
2742 else junk_error;
2743 end;
2744 incr(ne);
2745 finish_inner_property_list;
2746 end;
2747 end
2748
2749 @ @<Read an extensible p...@>=
2750 begin get_name;
2751 if cur_code=comment_code then skip_to_end_of_item
2752 else if (cur_code<var_char_code+1)or(cur_code>var_char_code+4) then
2753 flush_error('This property name doesn''t belong in a VARCHAR list')
2754 @.This property name doesn't belong...@>
2755 else begin case cur_code-(var_char_code+1) of
2756 0:exten[ne].b0:=get_byte;
2757 1:exten[ne].b1:=get_byte;
2758 2:exten[ne].b2:=get_byte;
2759 3:exten[ne].b3:=get_byte;
2760 end;@/
2761 finish_the_property;
2762 end;
2763 end
2764
2765 @ The input routine is now complete except for the following code,
2766 which prints a progress report as the file is being read.
2767
2768 @ @<Glob...@>=
2769 @!HEX: packed array [1..16] of char;
2770
2771 @ @<Set init...@>=
2772 HEX:='0123456789ABCDEF';@/
2773
2774 @ The array |dig| will hold a sequence of digits to be output.
2775
2776 @<Glob...@>=
2777 @!dig:array[0..32] of integer;
2778
2779 @ Here, in fact, is a procedure that prints
2780 |dig[j-1]|$\,\ldots\,$|dig[0]|, given $j>0$.
2781
2782 @p procedure print_digs(j:integer); {prints |j| digits}
2783 begin repeat decr(j); print(HEX[1+dig[j]]);
2784 until j=0;
2785 end;
2786
2787 @ The |print_number| procedure indicates how |print_digs| can be used.
2788 This procedure can print in octal, decimal or hex notation.
2789
2790 @d print_hex(#)==print_number(#,16)
2791 @d print_octal(#)==print_number(#,8)
2792 @d print_decimal(#)==print_number(#,10)
2793
2794 @p procedure print_number(c:integer; form:integer); {prints value of
2795 |c|}
2796 var j:0..32; {index into |dig|}
2797 begin
2798 j:=0;
2799 if (c<0) then begin
2800 print_ln('Internal error: print_number (negative value)');
2801 c:=0;
2802 end;
2803 if form=8 then
2804 print('''') {an apostrophe indicates the octal notation}
2805 else if form=16 then
2806 print('"') { a double apostrophe indicates the hexadecimal
2807 notation}
2808 else if form<>10 then begin
2809 print_ln('Internal error: print_number (form)');
2810 form:=16;
2811 end;
2812 while (c>0) or (j=0) do begin
2813 dig[j]:=c mod form; c:=c div form;
2814 j:=j+1;
2815 end;
2816 print_digs(j);
2817 end;
2818
2819 @ @<Print |c| in hex...@>=
2820 begin if chars_on_line>=8 then begin
2821 print_ln(' '); chars_on_line:=1;
2822 end
2823 else begin
2824 if chars_on_line>0 then print(' ');
2825 incr(chars_on_line);
2826 end;
2827 print_hex(c); {progress report}
2828 end
2829
2830
2831 @* Assembling the mappings.
2832 Each \.{MAP} property is a sequence of \.{DVI} instructions, for which
2833 we need to know some of the opcodes.
2834 We add afterwards the definitions for outputting typesetting commands.
2835
2836 @d set_char_0=0 {\.{DVI} command to typeset character 0 and move right}
2837 @d set1=128 {typeset a character and move right}
2838 @d set_rule=132 {typeset a rule and move right}
2839 @d push=141 {save the current positions}
2840 @d pop=142 {restore previous positions}
2841 @d right1=143 {move right}
2842 @d w0=147 {move right by |w|}
2843 @d w1=148 {move right and set |w|}
2844 @d x0=152 {move right by |x|}
2845 @d x1=153 {move right and set |x|}
2846 @d down1=157 {move down}
2847 @d y0=161 {move down by |y|}
2848 @d y1=162 {move down and set |y|}
2849 @d z0=166 {move down by |z|}
2850 @d z1=167 {move down and set |z|}
2851 @d fnt_num_0=171 {set current font to 0}
2852 @d fnt1=235 {set current font}
2853 @d xxx1=239 {extension to \.{DVI} primitives}
2854 @d xxx4=242 {potentially long extension to \.{DVI} primitives}
2855 @d fnt_def1=243 {define the meaning of a font number}
2856 @d pre=247 {preamble}
2857 @d post=248 {postamble beginning}
2858 @d Incr_Decr(#) == #
2859 @d Incr(#) == #:=#+Incr_Decr {increase a variable}
2860
2861 @d out_four(#) ==
2862 if x>=0 then #(x div @"1000000)
2863 else begin Incr(x)(@"40000000); Incr(x)(@"40000000);
2864 #((x div @"1000000) + 128);
2865 end;
2866 x:=x mod @"1000000; #(x div @"10000);
2867 x:=x mod @"10000; #(x div @"100);
2868 #(x mod @"100)
2869
2870 @d out_cmd(#) ==
2871 if (x<@"100)and(x>=0) then begin
2872 if (o<>set1)or(x>127) then
2873 if (o=fnt1)and(x<64) then Incr(x)(fnt_num_0) @+ else #(o);
2874 end
2875 else begin
2876 if (x<@"10000)and(x>=0) then #(o+1) @+ else begin
2877 if (x<@"1000000)and(x>=0) then #(o+2) @+ else begin
2878 #(o+3);
2879 if x>=0 then #(x div @"1000000)
2880 else begin
2881 Incr(x)(@"40000000); Incr(x)(@"40000000);
2882 #((x div @"1000000) + 128); x:=x mod @"1000000;
2883 end;
2884 #(x div @"10000); x:=x mod @"10000;
2885 end;
2886 #(x div @"10000); x:=x mod @"10000;
2887 end;
2888 #(x div @"100); x:=x mod @"100;
2889 end;
2890 #(x)
2891
2892 @p
2893 procedure vf_store_set(@!x:integer);
2894 var @!o:byte;
2895 begin o:=set1; out_cmd(vf_store);
2896 end;
2897
2898 procedure vfout_set(@!x:integer);
2899 var @!o:byte;
2900 begin o:=set1; out_cmd(vout);
2901 end;
2902
2903 procedure vf_store_fnt(@!x:integer);
2904 var @!o:byte;
2905 begin o:=fnt1; out_cmd(vf_store);
2906 end;
2907
2908 procedure vfout_fntdef(@!x:integer);
2909 var @!o:byte;
2910 begin o:=fnt_def1; out_cmd(vout);
2911 end;
2912
2913 procedure vfout_char(@!x:integer);
2914 begin out_four(vout);
2915 end;
2916
2917
2918 @ We keep stacks of movement values, in order to optimize the \.{DVI} code
2919 in simple cases.
2920
2921 @<Glob...@>=
2922 @!hstack:array[0..max_stack] of 0..2; {number of known horizontal movements}
2923 @!vstack:array[0..max_stack] of 0..2; {number of known vertical movements}
2924 @!wstack,@!xstack,@!ystack,@!zstack:array[0..max_stack] of fix_word;
2925 @!stack_ptr:0..max_stack;
2926
2927 @ The packet is built by straightforward assembly of \.{DVI} instructions.
2928
2929 @p @<Declare the |vf_fix| procedure@>@;@/
2930 procedure read_packet(@!c:byte);
2931 var @!cc:char_type; {character being typeset}
2932 @!x:fix_word; {movement}
2933 @!h,@!v:0..2; {top of |hstack| and |vstack|}
2934 @!special_start:0..vf_size; {location of |xxx1| command}
2935 @!k:0..vf_size; {loop index}
2936 begin packet_start[c]:=vf_ptr; stack_ptr:=0; h:=0; v:=0;
2937 cur_font:=0;
2938 while level=2 do
2939 begin while cur_char=" " do get_next;
2940 if cur_char="(" then @<Read and assemble a list of \.{DVI} commands@>
2941 else if cur_char=")" then skip_to_end_of_item
2942 else junk_error;
2943 end;
2944 while stack_ptr>0 do
2945 begin err_print('Missing POP supplied');
2946 @.Missing POP supplied@>
2947 vf_store(pop); decr(stack_ptr);
2948 end;
2949 packet_length[c]:=vf_ptr-packet_start[c];
2950 finish_inner_property_list;
2951 end;
2952
2953 @ @<Read and assemble a list of \.{DVI}...@>=
2954 begin get_name;
2955 if cur_code=comment_code then skip_to_end_of_item
2956 else if (cur_code<select_font_code)or(cur_code>special_hex_code) then
2957 flush_error('This property name doesn''t belong in a MAP list')
2958 @.This property name doesn't belong...@>
2959 else begin case cur_code of
2960 select_font_code:@<Assemble a font selection@>;
2961 set_char_code:@<Assemble a typesetting instruction@>;
2962 set_rule_code:@<Assemble a rulesetting instruction@>;
2963 move_right_code,move_right_code+1:@<Assemble a horizontal movement@>;
2964 move_down_code,move_down_code+1:@<Assemble a vertical movement@>;
2965 push_code:@<Assemble a stack push@>;
2966 pop_code:@<Assemble a stack pop@>;
2967 special_code,special_hex_code:@<Assemble a special command@>;
2968 end;@/
2969 finish_the_property;
2970 end;
2971 end
2972
2973 @ @<Assemble a font selection@>=
2974 begin font_number[font_ptr]:=get_integer;
2975 cur_font:=0;
2976 while font_number[font_ptr]<>font_number[cur_font] do incr(cur_font);
2977 if cur_font=font_ptr then err_print('Undefined MAPFONT cannot be selected')
2978 @.Undefined MAPFONT...@>
2979 else vf_store_fnt(cur_font);
2980 end
2981
2982 @ @<Assemble a typesetting instruction@>=
2983 if cur_font=font_ptr then
2984 err_print('Character cannot be typeset in undefined font')
2985 @.Character cannot be typeset...@>
2986 else begin cc:=get_byte;
2987 vf_store_set(cc);
2988 end
2989
2990 @ Here's a procedure that converts a |fix_word| to a sequence of
2991 \.{DVI} bytes.
2992
2993 @<Declare the |vf_fix|...@>=
2994 procedure vf_fix(@!opcode:byte;@!x:fix_word);
2995 var negative:boolean;
2996 @!k:0..4; {number of bytes to typeset}
2997 @!t:integer; {threshold}
2998 begin frozen_du:=true;
2999 if design_units<>unity then x:=round((x/design_units)*1048576.0);
3000 if x>=0 then negative:=false
3001 else begin negative:=true; x:=-1-x;@+end;
3002 if opcode=0 then
3003 begin k:=4; t:=@'100000000;@+end
3004 else begin t:=127; k:=1;
3005 while x>t do
3006 begin t:=256*t+255; incr(k);
3007 end;
3008 vf_store(opcode+k-1); t:=t div 128 +1;
3009 end;
3010 repeat if negative then
3011 begin vf_store(255-(x div t)); negative:=false;
3012 x:=(x div t)*t+t-1-x;
3013 end
3014 else vf_store((x div t) mod 256);
3015 decr(k); t:=t div 256;
3016 until k=0;
3017 end;
3018
3019 @ @<Assemble a rulesetting instruction@>=
3020 begin vf_store(set_rule); vf_fix(0,get_fix); vf_fix(0,get_fix);
3021 end
3022
3023 @ @<Assemble a horizontal movement@>=
3024 begin if cur_code=move_right_code then x:=get_fix@+else x:=-get_fix;
3025 if h=0 then
3026 begin wstack[stack_ptr]:=x; h:=1; vf_fix(w1,x);@+end
3027 else if x=wstack[stack_ptr] then vf_store(w0)
3028 else if h=1 then
3029 begin xstack[stack_ptr]:=x; h:=2; vf_fix(x1,x);@+end
3030 else if x=xstack[stack_ptr] then vf_store(x0)
3031 else vf_fix(right1,x);
3032 end
3033
3034 @ @<Assemble a vertical movement@>=
3035 begin if cur_code=move_down_code then x:=get_fix@+else x:=-get_fix;
3036 if v=0 then
3037 begin ystack[stack_ptr]:=x; v:=1; vf_fix(y1,x);@+end
3038 else if x=ystack[stack_ptr] then vf_store(y0)
3039 else if v=1
3040 then begin zstack[stack_ptr]:=x; v:=2; vf_fix(z1,x);@+end
3041 else if x=zstack[stack_ptr] then vf_store(z0)
3042 else vf_fix(down1,x);
3043 end
3044
3045 @ @<Assemble a stack push@>=
3046 if stack_ptr=max_stack then {too pushy}
3047 err_print('Don''t push so much---stack is full!')
3048 @.Don't push so much...@>
3049 else begin vf_store(push); hstack[stack_ptr]:=h; vstack[stack_ptr]:=v;
3050 incr(stack_ptr); h:=0; v:=0;
3051 end
3052
3053 @ @<Assemble a stack pop@>=
3054 if stack_ptr=0 then
3055 err_print('Empty stack cannot be popped')
3056 @.Empty stack...@>
3057 else begin vf_store(pop); decr(stack_ptr);
3058 h:=hstack[stack_ptr]; v:=vstack[stack_ptr];
3059 end
3060
3061 @ @<Assemble a special command@>=
3062 begin vf_store(xxx1); vf_store(0); {dummy length}
3063 special_start:=vf_ptr;
3064 if cur_code=special_code then copy_to_end_of_item
3065 else begin repeat x:=get_hex;
3066 if cur_char>")" then vf_store(x*16+get_hex);
3067 until cur_char<=")";
3068 end;
3069 if vf_ptr-special_start>255 then @<Convert |xxx1| command to |xxx4|@>
3070 else vf[special_start-1]:=vf_ptr-special_start;
3071 end
3072
3073 @ @<Convert |xxx1|...@>=
3074 if vf_ptr+3>vf_size then
3075 begin err_print('Special command being clipped---no room left!');
3076 @.Special command being clipped...@>
3077 vf_ptr:=special_start+255; vf[special_start-1]:=255;
3078 end
3079 else begin for k:=vf_ptr downto special_start do vf[k+3]:=vf[k];
3080 x:=vf_ptr-special_start; vf_ptr:=vf_ptr+3;
3081 vf[special_start-2]:=xxx4;
3082 vf[special_start-1]:=x div @'100000000;
3083 vf[special_start]:=(x div @'200000) mod 256;
3084 vf[special_start+1]:=(x div @'400) mod 256;
3085 vf[special_start+2]:=x mod 256;
3086 end
3087
3088 @* The checking and massaging phase.
3089 Once the whole \.{VPL} file has been read in, we must check it for consistency
3090 and correct any errors. This process consists mainly of running through
3091 the characters that exist and seeing if they refer to characters that
3092 don't exist. We also compute the true value of |seven_unsafe|; we make sure
3093 that the charlists and ligature programs contain no loops; and we
3094 shorten the lists of widths, heights, depths, and italic corrections,
3095 if necessary, to keep from exceeding the required maximum sizes.
3096
3097 @<Glob...@>=
3098 @!seven_unsafe:boolean; {do seven-bit characters generate eight-bit ones?}
3099
3100 @ @<Correct and check the information@>=
3101 if nl>0 then @<Make sure the ligature/kerning program ends appropriately@>;
3102 seven_unsafe:=false;
3103 for c:=0 to max_char do if char_wd[c]<>0 then
3104 @<For all characters |g| generated by |c|,
3105 make sure that |char_wd[g]| is nonzero, and
3106 set |seven_unsafe| if |c<128<=g|@>;
3107 if bchar_label<xmax_label then
3108 begin c:=xmax_char; @<Check ligature program of |c|@>;
3109 end;
3110 if seven_bit_safe_flag and seven_unsafe then
3111 print_ln('The font is not really seven-bit-safe!');
3112 @.The font is not...safe@>
3113 @<Check for infinite ligature loops@>;
3114 @<Doublecheck the lig/kern commands and the extensible recipes@>;
3115 finish_extended_font;
3116 for c:=0 to max_char do
3117 @<Make sure that |c| is not the largest element of a charlist cycle@>;
3118 @<Put the width, height, depth, and italic lists into final form@>
3119
3120 @ The checking that we need in several places is accomplished by three
3121 macros that are only slightly tricky.
3122
3123 @d existence_tail(#)==begin char_wd[g]:=sort_in(width,0);
3124 print(#,' '); print_hex(c);
3125 print_ln(' had no CHARACTER spec.');
3126 end;
3127 end
3128 @d check_existence_and_safety(#)==begin g:=#;
3129 if (g>=128)and(c<128) then seven_unsafe:=true;
3130 if char_wd[g]=0 then existence_tail
3131 @d check_existence(#)==begin g:=#;
3132 if char_wd[g]=0 then existence_tail
3133
3134 @<For all characters |g| generated by |c|...@>=
3135 case char_tag[c] of
3136 no_tag: do_nothing;
3137 lig_tag: @<Check ligature program of |c|@>;
3138 list_tag: check_existence_and_safety(char_remainder[c])
3139 ('The character NEXTLARGER than');
3140 @.The character NEXTLARGER...@>
3141 ext_tag:@<Check the pieces of |exten[c]|@>;
3142 end
3143
3144 @ @<Check the pieces...@>=
3145 begin if exten[char_remainder[c]].b0>0 then
3146 check_existence_and_safety(exten[char_remainder[c]].b0)
3147 ('TOP piece of character');
3148 @.TOP piece of character...@>
3149 if exten[char_remainder[c]].b1>0 then
3150 check_existence_and_safety(exten[char_remainder[c]].b1)
3151 ('MID piece of character');
3152 @.MID piece of character...@>
3153 if exten[char_remainder[c]].b2>0 then
3154 check_existence_and_safety(exten[char_remainder[c]].b2)
3155 ('BOT piece of character');
3156 @.BOT piece of character...@>
3157 check_existence_and_safety(exten[char_remainder[c]].b3)
3158 ('REP piece of character');
3159 @.REP piece of character...@>
3160 end
3161
3162 @ @<Make sure that |c| is not the largest element of a charlist cycle@>=
3163 if char_tag[c]=list_tag then
3164 begin g:=char_remainder[c];
3165 while (g<c)and(char_tag[g]=list_tag) do g:=char_remainder[g];
3166 if g=c then
3167 begin char_tag[c]:=no_tag;
3168 print('A cycle of NEXTLARGER characters has been broken at ');
3169 @.A cycle of NEXTLARGER...@>
3170 print_hex(c); print_ln('.');
3171 end;
3172 end
3173
3174 @ @<Glob...@>=
3175 @!delta:fix_word; {size of the intervals needed for rounding}
3176
3177 @ @d round_message(#)==if delta>0 then print_ln('I had to round some ',
3178 @.I had to round...@>
3179 #,'s by ',(((delta+1) div 2)/@'4000000):1:7,' units.')
3180
3181 @<Put the width, height, depth, and italic lists into final form@>=
3182 case ofm_level of
3183 -1: begin
3184 top_width:=255; top_depth:=15; top_height:=15; top_italic:=63;
3185 end;
3186 0: begin
3187 top_width:=65535; top_depth:=255; top_height:=255; top_italic:=255;
3188 end;
3189 1: begin
3190 top_width:=65535; top_depth:=255; top_height:=255; top_italic:=255;
3191 end;
3192 end;
3193 delta:=shorten(width,top_width); set_indices(width,delta);
3194 round_message('width');@/
3195 delta:=shorten(height,top_height); set_indices(height,delta);
3196 round_message('height');@/
3197 delta:=shorten(depth,top_depth); set_indices(depth,delta);
3198 round_message('depth');@/
3199 delta:=shorten(italic,top_italic); set_indices(italic,delta);
3200 round_message('italic correction');
3201
3202 @ @d clear_lig_kern_entry== {make an unconditional \.{STOP}}
3203 lig_kern[nl].b0:=255; lig_kern[nl].b1:=0;
3204 lig_kern[nl].b2:=0; lig_kern[nl].b3:=0
3205
3206 @<Make sure the ligature/kerning program ends...@>=
3207 begin if bchar_label<xmax_label then {make room for it}
3208 begin clear_lig_kern_entry; incr(nl);
3209 end; {|bchar_label| will be stored later}
3210 while min_nl>nl do
3211 begin clear_lig_kern_entry; incr(nl);
3212 end;
3213 if (lig_kern[nl-1].b0 mod 256)=0 then
3214 lig_kern[nl-1].b0:=lig_kern[nl-1].b0 div 256 * 256 + stop_flag;
3215 end
3216
3217 @ It's not trivial to check for infinite loops generated by repeated
3218 insertion of ligature characters. But fortunately there is a nice
3219 algorithm for such testing, copied here from the program \.{TFtoPL}
3220 where it is explained further.
3221
3222 @d simple=0 {$f(x,y)=z$}
3223 @d left_z=1 {$f(x,y)=f(z,y)$}
3224 @d right_z=2 {$f(x,y)=f(x,z)$}
3225 @d both_z=3 {$f(x,y)=f(f(x,z),y)$}
3226 @d pending=4 {$f(x,y)$ is being evaluated}
3227
3228
3229 @ @<Glo...@>=
3230 @!lig_ptr:0..max_lig_steps; {an index into |lig_kern|}
3231 @!hash:array[0..hash_size] of integer64;
3232 @!class:array[0..hash_size] of simple..pending;
3233 @!lig_z:array[0..hash_size] of xxchar_type;
3234 @!hash_ptr:0..hash_size; {the number of nonzero entries in |hash|}
3235 @!hash_list:array[0..hash_size] of 0..hash_size; {list of those nonzero entries}
3236 @!h,@!hh:0..hash_size; {indices into the hash table}
3237 @!tt:indx; {temporary register}
3238 @!x_lig_cycle,@!y_lig_cycle:xchar_type; {problematic ligature pair}
3239
3240 @ @<Set init...@>=
3241 hash_ptr:=0; y_lig_cycle:=xmax_char;
3242 for k:=0 to hash_size do hash[k]:=0;
3243
3244 @ @d lig_exam==lig_kern[lig_ptr].b1
3245 @d lig_gen==lig_kern[lig_ptr].b3
3246
3247 @<Check lig...@>=
3248 begin lig_ptr:=char_remainder[c];
3249 if lig_kern[lig_ptr].b0<256 then
3250 begin
3251 repeat if hash_input(lig_ptr,c) then begin
3252 if lig_kern[lig_ptr].b2<kern_flag then begin
3253 if lig_exam<>bchar then
3254 check_existence(lig_exam)('LIG character examined by');
3255 @.LIG character examined...@>
3256 check_existence(lig_gen)('LIG character generated by');
3257 @.LIG character generated...@>
3258 if lig_gen>=128 then if(c<128)or(c=bchar) then
3259 if(lig_exam<128)or(lig_exam=bchar) then seven_unsafe:=true;
3260 end
3261 else if lig_exam<>bchar then
3262 check_existence(lig_exam)('KRN character examined by');
3263 @.KRN character examined...@>
3264 end;
3265 if lig_kern[lig_ptr].b0>=stop_flag then lig_ptr:=nl
3266 else lig_ptr:=lig_ptr+1+lig_kern[lig_ptr].b0;
3267 until lig_ptr>=nl;
3268 end;
3269 end
3270
3271 @ The |hash_input| procedure is copied from \.{TFtoPL}, but it is made
3272 into a boolean function that returns |false| if the ligature command
3273 was masked by a previous one.
3274
3275 @p function hash_input(@!p,@!c:indx):boolean;
3276 {enter data for character |c| and command in location |p|, unless it isn't new}
3277 label 30; {go here for a quick exit}
3278 var @!cc:simple..both_z; {class of data being entered}
3279 @!zz:char_type; {function value or ligature character being entered}
3280 @!y:char_type; {the character after the cursor}
3281 @!key:integer64; {value to be stored in |hash|}
3282 @!t64:integer64; {temporary register for swapping}
3283 @!t:integer; {temporary register for swapping}
3284 begin if hash_ptr=hash_size then
3285 begin hash_input:=false; goto 30;@+end;
3286 @<Compute the command parameters |y|, |cc|, and |zz|@>;
3287 key:=int64cast(xmax_char)*c+y+1; h:=(hash_mult*key) mod hash_size;
3288 while hash[h]>0 do
3289 begin if hash[h]<=key then
3290 begin if hash[h]=key then
3291 begin hash_input:=false; goto 30; {unused ligature command}
3292 end;
3293 t64:=hash[h]; hash[h]:=key; key:=t64; {do ordered-hash-table insertion}
3294 t:=class[h]; class[h]:=cc; cc:=t; {namely, do a swap}
3295 t:=lig_z[h]; lig_z[h]:=zz; zz:=t;
3296 end;
3297 if h>0 then decr(h)@+else h:=hash_size;
3298 end;
3299 hash[h]:=key; class[h]:=cc; lig_z[h]:=zz;
3300 incr(hash_ptr); hash_list[hash_ptr]:=h;
3301 hash_input:=true;
3302 30:end;
3303
3304 @ @<Compute the command param...@>=
3305 y:=lig_kern[p].b1; t:=lig_kern[p].b2; cc:=simple;
3306 zz:=lig_kern[p].b3;
3307 if t>=kern_flag then zz:=y
3308 else begin case t of
3309 0,6:do_nothing; {\.{LIG},\.{/LIG>}}
3310 5,11:zz:=y; {\.{LIG/>}, \.{/LIG/>>}}
3311 1,7:cc:=left_z; {\.{LIG/}, \.{/LIG/>}}
3312 2:cc:=right_z; {\.{/LIG}}
3313 3:cc:=both_z; {\.{/LIG/}}
3314 end; {there are no other cases}
3315 end
3316
3317 @ (More good stuff from \.{TFtoPL}.)
3318
3319 @p function f(@!h,@!x,@!y:indx):indx; forward;@t\2@>
3320 {compute $f$ for arguments known to be in |hash[h]|}
3321 function eval(@!x,@!y:indx):indx; {compute $f(x,y)$ with hashtable lookup}
3322 var @!key:integer64; {value sought in hash table}
3323 begin key:=int64cast(xmax_char)*x+y+1; h:=(hash_mult*key) mod hash_size;
3324 while hash[h]>key do
3325 if h>0 then decr(h)@+else h:=hash_size;
3326 if hash[h]<key then eval:=y {not in ordered hash table}
3327 else eval:=f(h,x,y);
3328 end;
3329
3330 @ Pascal's beastly convention for |forward| declarations prevents us from
3331 saying |function f(h,x,y:indx):indx| here.
3332
3333 @p function f;
3334 begin case class[h] of
3335 simple: do_nothing;
3336 left_z: begin class[h]:=pending; lig_z[h]:=eval(lig_z[h],y); class[h]:=simple;
3337 end;
3338 right_z: begin class[h]:=pending; lig_z[h]:=eval(x,lig_z[h]); class[h]:=simple;
3339 end;
3340 both_z: begin class[h]:=pending; lig_z[h]:=eval(eval(x,lig_z[h]),y);
3341 class[h]:=simple;
3342 end;
3343 pending: begin x_lig_cycle:=x; y_lig_cycle:=y; lig_z[h]:=xxmax_char; class[h]:=simple;
3344 end; {the value |xxmax_char| will break all cycles, since it's not in |hash|}
3345 end; {there are no other cases}
3346 f:=lig_z[h];
3347 end;
3348
3349 @ @<Check for infinite...@>=
3350 if hash_ptr<hash_size then for hh:=1 to hash_ptr do
3351 begin tt:=hash_list[hh];
3352 if class[tt]>simple then {make sure $f$ is well defined}
3353 tt:=f(tt,(hash[tt]-1)div xmax_char,(hash[tt]-1)mod xmax_char);
3354 end;
3355 if(hash_ptr=hash_size)or(y_lig_cycle<xmax_char) then
3356 begin if hash_ptr<hash_size then
3357 begin print('Infinite ligature loop starting with ');
3358 @.Infinite ligature loop...@>
3359 if x_lig_cycle=xmax_char then print('boundary')@+else print_hex(x_lig_cycle);
3360 print(' and '); print_hex(y_lig_cycle); print_ln('!');
3361 end
3362 else print_ln('Sorry, I haven''t room for so many ligature/kern pairs!');
3363 @.Sorry, I haven't room...@>
3364 print_ln('All ligatures will be cleared.');
3365 for c:=0 to max_char do if char_tag[c]=lig_tag then
3366 begin char_tag[c]:=no_tag; char_remainder[c]:=0;
3367 end;
3368 nl:=0; bchar:=xmax_char; bchar_label:=xmax_label;
3369 end
3370
3371 @ The lig/kern program may still contain references to nonexistent characters,
3372 if parts of that program are never used. Similarly, there may be extensible
3373 characters that are never used, because they were overridden by
3374 \.{NEXTLARGER}, say. This would produce an invalid \.{TFM} file; so we
3375 must fix such errors.
3376
3377 @d double_check_tail(#)==@t\1@>if char_wd[0]=0
3378 then char_wd[0]:=sort_in(width,0);
3379 print('Unused ',#,' refers to nonexistent character ');
3380 print_hex(c); print_ln('!');
3381 end;
3382 end
3383 @d double_check_lig(#)==begin c:=lig_kern[lig_ptr].#;
3384 if char_wd[c]=0 then if c<>bchar then
3385 begin lig_kern[lig_ptr].#:=0; double_check_tail
3386 @d double_check_ext(#)==begin c:=exten[g].#;
3387 if c>0 then if char_wd[c]=0 then
3388 begin exten[g].#:=0; double_check_tail
3389 @d double_check_rep(#)==begin c:=exten[g].#;
3390 if char_wd[c]=0 then
3391 begin exten[g].#:=0; double_check_tail
3392
3393 @<Doublecheck...@>=
3394 if nl>0 then for lig_ptr:=0 to nl-1 do
3395 if (lig_kern[lig_ptr].b0 div 256)=0 then begin
3396 if lig_kern[lig_ptr].b2<kern_flag then begin
3397 if lig_kern[lig_ptr].b0<255 then begin
3398 double_check_lig(b1)('LIG step'); double_check_lig(b3)('LIG step');
3399 end;
3400 end
3401 else double_check_lig(b1)('KRN step');
3402 end;
3403 @.Unused LIG step...@>
3404 @.Unused KRN step...@>
3405 if ne>0 then for g:=0 to ne-1 do
3406 begin double_check_ext(b0)('VARCHAR TOP');
3407 double_check_ext(b1)('VARCHAR MID');
3408 double_check_ext(b2)('VARCHAR BOT');
3409 double_check_rep(b3)('VARCHAR REP');
3410 @.Unused VARCHAR...@>
3411 end
3412
3413 @* The TFM output phase.
3414 Now that we know how to get all of the font data correctly stored in
3415 \.{VPtoVF}'s memory, it only remains to write the answers out.
3416
3417 First of all, it is convenient to have an abbreviation for output to the
3418 \.{TFM} file:
3419
3420 @d out(#)==write(tfm_file,#)
3421
3422 @p procedure out_int(@!x:integer);
3423 begin out_four(out);
3424 end;
3425
3426
3427 @ The general plan for producing \.{TFM} files is long but simple:
3428
3429 @<Do the font metric output@>=
3430 compute_subfile_sizes;
3431 output_subfile_sizes;
3432 @<Output the header block@>;
3433 output_new_information_ofm;
3434 output_character_info;
3435 @<Output the dimensions themselves@>;
3436 @<Output the ligature/kern program@>;
3437 @<Output the extensible character recipes@>;
3438 @<Output the parameters@>
3439
3440 @ A \.{TFM} file begins with 12 numbers that tell how big its subfiles are.
3441 We already know most of these numbers; for example, the number of distinct
3442 widths is |memory[width]+1|, where the $+1$ accounts for the zero width that
3443 is always supposed to be present. But we still should compute the beginning
3444 and ending character codes (|bc| and |ec|), the number of header words (|lh|),
3445 and the total number of words in the \.{TFM} file (|lf|).
3446
3447 @<Gl...@>=
3448 @!bc:char_type; {the smallest character code in the font}
3449 @!ec:char_type; {the largest character code in the font}
3450 @!lh:char_type; {the number of words in the header block}
3451 @!lf:unsigned_integer; {the number of words in the entire \.{TFM} file}
3452 @!not_found:boolean; {has a font character been found?}
3453 @!temp_width:fix_word; {width being used to compute a check sum}
3454 @!ncw,@!nco,@!npc:integer;
3455
3456 @ @<Set init...@>=
3457 npc:=-1;
3458
3459 @ It might turn out that no characters exist at all. But \.{VPtoVF} keeps
3460 going and writes the \.{TFM} anyway. In this case |ec| will be~0 and |bc|
3461 will be~1.
3462
3463 @<Compute the subfile sizes@>=
3464 lh:=header_ptr div 4;@/
3465 not_found:=true; bc:=0;
3466 if (ofm_level=-1) then ec:=255 @+ else ec:=max_char; {only temporary}
3467 while not_found do
3468 if (char_wd[bc]>0)or(bc=ec) then not_found:=false
3469 else incr(bc);
3470 not_found:=true; ec:=max_char;
3471 while not_found do
3472 if (char_wd[ec]>0)or(ec=0) then not_found:=false
3473 else decr(ec);
3474 if (ofm_level=-1)and(ec>255) then begin
3475 print('Char '); print_hex(ec);
3476 print_ln(' too big for TFM (max "FF); use OFM file!');
3477 goto final_end;
3478 end;
3479 if bc>ec then bc:=1;
3480 incr(memory[width]); incr(memory[height]); incr(memory[depth]);
3481 incr(memory[italic]);@/
3482 @<Compute the ligature/kern program offset@>;
3483 case ofm_level of
3484 -1: begin
3485 lf:=6+lh+(ec-bc+1)+memory[width]+memory[height]+memory[depth]+
3486 memory[italic]+nl+lk_offset+nk+ne+np;
3487 end;
3488 0: begin
3489 lf:=14+lh+2*(ec-bc+1)+memory[width]+memory[height]+memory[depth]+
3490 memory[italic]+2*(nl+lk_offset)+nk+2*ne+np;
3491 end;
3492 1: begin
3493 @<Compute the character info size@>;
3494 lf:=29+lh+ncw+memory[width]+memory[height]+memory[depth]+
3495 memory[italic]+2*(nl+lk_offset)+nk+2*ne+np+
3496 nki+nwi+nkf+nwf+nkm+nwm+nkr+nwr+nkg+nwg+nkp+nwp;
3497 nco:=29+lh+nki+nwi+nkf+nwf+nkm+nwm+nkr+nwr+nkg+nwg+nkp+nwp;
3498 end;
3499 end;
3500
3501 @ @d out_size(#)==out((#) div 256); out((#) mod 256)
3502 @d out_integer(#)==out((#) div @"1000000);
3503 out(((#) mod @"1000000) div @"10000);
3504 out(((#) mod @"10000) div @"100);
3505 out((#) mod @"100)
3506
3507 @<Output the subfile sizes@>=
3508 case ofm_level of
3509 -1: begin
3510 out_size(lf); out_size(lh); out_size(bc); out_size(ec);
3511 out_size(memory[width]); out_size(memory[height]);
3512 out_size(memory[depth]); out_size(memory[italic]);
3513 out_size(nl+lk_offset); out_size(nk); out_size(ne); out_size(np);
3514 end;
3515 0: begin
3516 out_integer(0);
3517 out_integer(lf); out_integer(lh); out_integer(bc); out_integer(ec);
3518 out_integer(memory[width]); out_integer(memory[height]);
3519 out_integer(memory[depth]); out_integer(memory[italic]);
3520 out_integer(nl+lk_offset); out_integer(nk);
3521 out_integer(ne); out_integer(np); out_integer(font_dir);
3522 end;
3523 1: begin
3524 out_integer(1);
3525 out_integer(lf); out_integer(lh);
3526 out_integer(bc); out_integer(ec);
3527 out_integer(memory[width]); out_integer(memory[height]);
3528 out_integer(memory[depth]); out_integer(memory[italic]);
3529 out_integer(nl+lk_offset); out_integer(nk);
3530 out_integer(ne); out_integer(np); out_integer(font_dir);
3531 out_integer(nco); out_integer(ncw); out_integer(npc);
3532 out_integer(nki); out_integer(nwi); out_integer(nkf); out_integer(nwf);
3533 out_integer(nkm); out_integer(nwm); out_integer(nkr); out_integer(nwr);
3534 out_integer(nkg); out_integer(nwg); out_integer(nkp); out_integer(nwp);
3535 end;
3536 end;
3537
3538 @ The routines that follow need a few temporary variables of different types.
3539
3540 @<Gl...@>=
3541 @!j:0..max_header_bytes; {index into |header_bytes|}
3542 @!p:pointer; {index into |memory|}
3543 @!q:width..italic; {runs through the list heads for dimensions}
3544 @!par_ptr:0..max_param_words; {runs through the parameters}
3545
3546 @ The header block follows the subfile sizes. The necessary information all
3547 appears in |header_bytes|, except that the design size and the seven-bit-safe
3548 flag must still be set.
3549
3550 @<Output the header block@>=
3551 if not check_sum_specified then @<Compute the check sum@>;
3552 header_bytes[design_size_loc]:=design_size div @'100000000;
3553 {this works since |design_size>0|}
3554 header_bytes[design_size_loc+1]:=(design_size div @'200000) mod 256;
3555 header_bytes[design_size_loc+2]:=(design_size div 256) mod 256;
3556 header_bytes[design_size_loc+3]:=design_size mod 256;
3557 if (not seven_unsafe)and(ofm_level=-1) then header_bytes[seven_flag_loc]:=128;
3558 for j:=0 to header_ptr-1 do out(header_bytes[j]);
3559
3560 @ @<Compute the check sum@>=
3561 begin c0:=bc; c1:=ec; c2:=bc; c3:=ec;
3562 for c:=bc to ec do if char_wd[c]>0 then
3563 begin temp_width:=memory[char_wd[c]];
3564 if design_units<>unity then
3565 temp_width:=round((temp_width/design_units)*1048576.0);
3566 temp_width:=temp_width + (c+4)*@'20000000; {this should be positive}
3567 c0:=(c0+c0+temp_width) mod 255;
3568 c1:=(c1+c1+temp_width) mod 253;
3569 c2:=(c2+c2+temp_width) mod 251;
3570 c3:=(c3+c3+temp_width) mod 247;
3571 end;
3572 header_bytes[check_sum_loc]:=c0;
3573 header_bytes[check_sum_loc+1]:=c1;
3574 header_bytes[check_sum_loc+2]:=c2;
3575 header_bytes[check_sum_loc+3]:=c3;
3576 end
3577
3578 @ @<Global...@>=
3579 @!tab:integer;
3580
3581 @
3582 @<Compute the character info size@>=
3583 if ofm_level=1 then begin
3584 ncw:=0;
3585 incr(npc);
3586 needed_space:=(12+npc*2) div 4;
3587 extra_bytes:=(needed_space*4) - (10+npc*2);
3588 for c:=bc to ec do begin
3589 if char_original[c]=c then begin
3590 cprime:=c+1;
3591 diff:=false;
3592 while (not diff) and (cprime<=ec) do begin
3593 if index[char_wd[c]]<>index[char_wd[cprime]] then diff:=true;
3594 if index[char_ht[c]]<>index[char_ht[cprime]] then diff:=true;
3595 if index[char_dp[c]]<>index[char_dp[cprime]] then diff:=true;
3596 if index[char_ic[c]]<>index[char_ic[cprime]] then diff:=true;
3597 if char_tag[c]<>char_tag[cprime] then diff:=true;
3598 if char_remainder[c]<>char_remainder[cprime] then diff:=true;
3599 for tab:=0 to npc-1 do begin
3600 if char_table[c,tab]<>char_table[cprime,tab] then diff:=true;
3601 end;
3602 if not diff then begin
3603 char_original[cprime]:=c;
3604 cprime:=cprime+1;
3605 end;
3606 end;
3607 if cprime>(c+1) then begin
3608 char_repeats[c]:=cprime-c-1;
3609 end;
3610 ncw:=ncw+needed_space;
3611 end;
3612 end;
3613 end;
3614
3615 @ The next block contains packed |char_info|.
3616
3617 @d out_two(#)==out((#) div 256); out((#) mod 256)
3618
3619 @d out_three(#)==out((#) div 65536); out_two((#) mod 65536)
3620
3621
3622 @<Output the character info@>=
3623 index[0]:=0;
3624 for c:=bc to ec do
3625 case ofm_level of
3626 -1: begin
3627 out(index[char_wd[c]]);
3628 out(index[char_ht[c]]*16+index[char_dp[c]]);
3629 out(index[char_ic[c]]*4+char_tag[c]);
3630 out(char_remainder[c]);
3631 end;
3632 0: begin
3633 out(index[char_wd[c]] div 256); out(index[char_wd[c]] mod 256);
3634 out(index[char_ht[c]]); out(index[char_dp[c]]);
3635 out(index[char_ic[c]]); out(char_tag[c]);
3636 out(char_remainder[c] div 256); out(char_remainder[c] mod 256);
3637 end;
3638 1: begin
3639 if c=char_original[c] then begin
3640 out(index[char_wd[c]] div 256); out(index[char_wd[c]] mod 256);
3641 out(index[char_ht[c]]); out(index[char_dp[c]]);
3642 out(index[char_ic[c]]);
3643 tab:=char_tag[c];
3644 if char_extended_tag[c] then begin
3645 tab:=5;
3646 end;
3647 out(tab);
3648 out(char_remainder[c] div 256); out(char_remainder[c] mod 256);
3649 out_size(char_repeats[c]);
3650 for tab:=0 to npc-1 do begin
3651 out(char_table[c,tab] div 256); out(char_table[c,tab] mod 256);
3652 end;
3653 for tab:=1 to extra_bytes do begin
3654 out(0);
3655 end;
3656 end;
3657 end;
3658 end;
3659
3660 @ When a scaled quantity is output, we may need to divide it by |design_units|.
3661 The following subroutine takes care of this, using floating point arithmetic
3662 only if |design_units<>1.0|.
3663
3664 @p procedure out_scaled(x:fix_word); {outputs a scaled |fix_word|}
3665 var @!n:byte; {the first byte after the sign}
3666 @!m:0..65535; {the two least significant bytes}
3667 begin if abs(x/design_units)>=16.0 then
3668 begin print_ln('The relative dimension ',x/@'4000000:1:3,
3669 ' is too large.');
3670 @.The relative dimension...@>
3671 print(' (Must be less than 16*designsize');
3672 if design_units<>unity then print(' =',design_units/@'200000:1:3,
3673 ' designunits');
3674 print_ln(')'); x:=0;
3675 end;
3676 if design_units<>unity then x:=round((x/design_units)*1048576.0);
3677 if x<0 then
3678 begin out(255); x:=x+@'100000000;
3679 if x<=0 then x:=1;
3680 end
3681 else begin out(0);
3682 if x>=@'100000000 then x:=@'77777777;
3683 end;
3684 n:=x div @'200000; m:=x mod @'200000;
3685 out(n); out(m div 256); out(m mod 256);
3686 end;
3687
3688 @ We have output the packed indices for individual characters.
3689 The scaled widths, heights, depths, and italic corrections are next.
3690
3691 @<Output the dimensions themselves@>=
3692 for q:=width to italic do
3693 begin out(0); out(0); out(0); out(0); {output the zero word}
3694 p:=link[q]; {head of list}
3695 while p>0 do
3696 begin out_scaled(memory[p]);
3697 p:=link[p];
3698 end;
3699 end;
3700
3701 @ One embarrassing problem remains: The ligature/kern program might be very
3702 long, but the starting addresses in |char_remainder| can be at most~65535.
3703 Therefore we need to output some indirect address information; we want to
3704 compute |lk_offset| so that addition of |lk_offset| to all remainders makes
3705 all but |lk_offset| distinct remainders less than~65536.
3706
3707 For this we need a sorted table of all relevant remainders.
3708
3709 @<Glob...@>=
3710 @!label_table:array[xchar_type] of record
3711 @!rr: -1..xmax_label; {sorted label values}
3712 @!cc: char_type; {associated characters}
3713 end;
3714 @!label_ptr:xchar_type; {index of highest entry in |label_table|}
3715 @!sort_ptr:xchar_type; {index into |label_table|}
3716 @!lk_offset:xchar_type; {smallest offset value that might work}
3717 @!t:0..xmax_label; {label value that is being redirected}
3718 @!extra_loc_needed:boolean; {do we need a special word for |bchar|?}
3719
3720 @ @<Compute the ligature/kern program offset@>=
3721 @<Insert all labels into |label_table|@>;
3722 if bchar<xmax_char then
3723 begin extra_loc_needed:=true; lk_offset:=1;
3724 end
3725 else begin extra_loc_needed:=false; lk_offset:=0;
3726 end;
3727 @<Find the minimum |lk_offset| and adjust all remainders@>;
3728 if bchar_label<xmax_label then begin
3729 if ofm_level=-1 then begin
3730 lig_kern[nl-1].b2:=(bchar_label+lk_offset)div 256;
3731 lig_kern[nl-1].b3:=(bchar_label+lk_offset)mod 256;
3732 end
3733 else begin
3734 lig_kern[nl-1].b2:=(bchar_label+lk_offset)div 65536;
3735 lig_kern[nl-1].b3:=(bchar_label+lk_offset)mod 65536;
3736 end
3737 end
3738
3739 @ @<Insert all labels...@>=
3740 label_ptr:=0; label_table[0].rr:=-1; {sentinel}
3741 for c:=bc to ec do if char_tag[c]=lig_tag then
3742 begin sort_ptr:=label_ptr; {there's a hole at position |sort_ptr+1|}
3743 while label_table[sort_ptr].rr>char_remainder[c] do
3744 begin label_table[sort_ptr+1]:=label_table[sort_ptr];
3745 decr(sort_ptr); {move the hole}
3746 end;
3747 label_table[sort_ptr+1].cc:=c;
3748 label_table[sort_ptr+1].rr:=char_remainder[c];
3749 incr(label_ptr);
3750 end
3751
3752 @ @<Find the minimum |lk_offset| and adjust all remainders@>=
3753 begin sort_ptr:=label_ptr; {the largest unallocated label}
3754 if ofm_level=-1 then begin
3755 if label_table[sort_ptr].rr+lk_offset > 255 then begin
3756 lk_offset:=0; extra_loc_needed:=false; {location 0 can do double duty}
3757 repeat char_remainder[label_table[sort_ptr].cc]:=lk_offset;
3758 while label_table[sort_ptr-1].rr=label_table[sort_ptr].rr do begin
3759 decr(sort_ptr); char_remainder[label_table[sort_ptr].cc]:=lk_offset;
3760 end;
3761 incr(lk_offset); decr(sort_ptr);
3762 until lk_offset+label_table[sort_ptr].rr<256;
3763 {N.B.: |lk_offset=256| satisfies this when |sort_ptr=0|}
3764 end;
3765 end
3766 else begin
3767 if label_table[sort_ptr].rr+lk_offset > 65535 then begin
3768 lk_offset:=0; extra_loc_needed:=false; {location 0 can do double duty}
3769 repeat char_remainder[label_table[sort_ptr].cc]:=lk_offset;
3770 while label_table[sort_ptr-1].rr=label_table[sort_ptr].rr do begin
3771 decr(sort_ptr); char_remainder[label_table[sort_ptr].cc]:=lk_offset;
3772 end;
3773 incr(lk_offset); decr(sort_ptr);
3774 until lk_offset+label_table[sort_ptr].rr<65536;
3775 {N.B.: |lk_offset=65536| satisfies this when |sort_ptr=0|}
3776 end;
3777 end;
3778 if lk_offset>0 then while sort_ptr>0 do
3779 begin char_remainder[label_table[sort_ptr].cc]:=
3780 char_remainder[label_table[sort_ptr].cc]+lk_offset;
3781 decr(sort_ptr);
3782 end;
3783 end
3784
3785 @ @<Output the ligature/kern program@>=
3786 if ofm_level=-1 then begin
3787 if extra_loc_needed then begin {|lk_offset=1|}
3788 out(255); out(bchar); out(0); out(0);
3789 end
3790 else for sort_ptr:=1 to lk_offset do begin {output the redirection specs}
3791 t:=label_table[label_ptr].rr;
3792 if bchar<256 then begin
3793 out(255); out(bchar);
3794 end
3795 else begin
3796 out(254); out(0);
3797 end;
3798 out_size(t+lk_offset);
3799 repeat decr(label_ptr); until label_table[label_ptr].rr<t;
3800 end;
3801 if nl>0 then for lig_ptr:=0 to nl-1 do begin
3802 out(lig_kern[lig_ptr].b0);
3803 out(lig_kern[lig_ptr].b1);
3804 out(lig_kern[lig_ptr].b2);
3805 out(lig_kern[lig_ptr].b3);
3806 end;
3807 if nk>0 then for krn_ptr:=0 to nk-1 do out_scaled(kern[krn_ptr])
3808 end
3809 else begin
3810 if extra_loc_needed then begin {|lk_offset=1|}
3811 out_size(255); out_size(bchar); out_size(0); out_size(0);
3812 end
3813 else for sort_ptr:=1 to lk_offset do begin {output the redirection specs}
3814 t:=label_table[label_ptr].rr;
3815 if bchar<xmax_char then begin
3816 out_size(255); out_size(bchar);
3817 end
3818 else begin
3819 out_size(254); out_size(0);
3820 end;
3821 out_size((t+lk_offset) div 256);
3822 out_size((t+lk_offset) mod 256);
3823 repeat decr(label_ptr); until label_table[label_ptr].rr<t;
3824 end;
3825 if nl>0 then for lig_ptr:=0 to nl-1 do begin
3826 out_size(lig_kern[lig_ptr].b0);
3827 out_size(lig_kern[lig_ptr].b1);
3828 out_size(lig_kern[lig_ptr].b2);
3829 out_size(lig_kern[lig_ptr].b3);
3830 end;
3831 if nk>0 then for krn_ptr:=0 to nk-1 do out_scaled(kern[krn_ptr])
3832 end
3833
3834 @ @<Output the extensible character recipes@>=
3835 if ofm_level=-1 then begin
3836 if ne>0 then for c:=0 to ne-1 do begin
3837 out(exten[c].b0);
3838 out(exten[c].b1);
3839 out(exten[c].b2);
3840 out(exten[c].b3);
3841 end;
3842 end
3843 else begin
3844 if ne>0 then for c:=0 to ne-1 do begin
3845 out_size(exten[c].b0);
3846 out_size(exten[c].b1);
3847 out_size(exten[c].b2);
3848 out_size(exten[c].b3);
3849 end;
3850 end;
3851
3852 @ For our grand finale, we wind everything up by outputting the parameters.
3853
3854 @<Output the parameters@>=
3855 for par_ptr:=1 to np do
3856 begin if par_ptr=1 then
3857 @<Output the slant (|param[1]|) without scaling@>
3858 else out_scaled(param[par_ptr]);
3859 end
3860
3861 @ @<Output the slant...@>=
3862 begin if param[1]<0 then
3863 begin param[1]:=param[1]+@'10000000000;
3864 out((param[1] div @'100000000)+256-64);
3865 end
3866 else out(param[1] div @'100000000);
3867 out((param[1] div @'200000) mod 256);
3868 out((param[1] div 256) mod 256);
3869 out(param[1] mod 256);
3870 end
3871
3872 @* The VF output phase.
3873 Output to |vf_file| is considerably simpler.
3874
3875 @d id_byte=202 {current version of \.{VF} format}
3876 @d vout(#)==write(vf_file,#)
3877
3878 @<Glob...@>=
3879 @!vcount:integer; {number of bytes written to |vf_file|}
3880
3881 @ We need a routine to output integers as four bytes. Negative values
3882 will never be less than $-2^{24}$.
3883
3884 @p procedure vout_int(@!x:integer);
3885 begin if x>=0 then vout(x div @'100000000)
3886 else begin vout(255); x:=x+@'100000000;
3887 end;
3888 vout((x div @'200000) mod 256);
3889 vout((x div @'400) mod 256); vout(x mod 256);
3890 end;
3891
3892 @ @<Do the \.{VF} output@>=
3893 vout(pre); vout(id_byte); vout(vtitle_length);
3894 for k:=0 to vtitle_length-1 do vout(vf[vtitle_start+k]);
3895 for k:=check_sum_loc to design_size_loc+3 do vout(header_bytes[k]);
3896 vcount:=vtitle_length+11;
3897 for cur_font:=0 to font_ptr-1 do @<Output a local font definition@>;
3898 for c:=bc to ec do if char_wd[c]>0 then
3899 @<Output a packet for character |c|@>;
3900 repeat vout(post); incr(vcount);
3901 until vcount mod 4 = 0
3902
3903 @ @<Output a local font definition@>=
3904 begin vfout_fntdef(cur_font);@/
3905 vout(font_checksum[cur_font].b0);
3906 vout(font_checksum[cur_font].b1);
3907 vout(font_checksum[cur_font].b2);
3908 vout(font_checksum[cur_font].b3);
3909 vout_int(font_at[cur_font]);
3910 vout_int(font_dsize[cur_font]);
3911 vout(farea_length[cur_font]);
3912 vout(fname_length[cur_font]);
3913 for k:=0 to farea_length[cur_font]-1 do vout(vf[farea_start[cur_font]+k]);
3914 if fname_start[cur_font]=vf_size then
3915 begin vout("N"); vout("U"); vout("L"); vout("L");
3916 end
3917 else for k:=0 to fname_length[cur_font]-1 do vout(vf[fname_start[cur_font]+k]);
3918 vcount:=vcount+12+farea_length[cur_font]+fname_length[cur_font];
3919 end
3920
3921 @ @<Output a packet for character |c|@>=
3922 begin x:=memory[char_wd[c]];
3923 if design_units<>unity then x:=round((x/design_units)*1048576.0);
3924 if (packet_length[c]>241)or(x<0)or(x>=@'100000000)or(c<0)or(c>255) then
3925 begin vout(242); vout_int(packet_length[c]); vfout_char(c); vout_int(x);
3926 vcount:=vcount+13+packet_length[c];
3927 end
3928 else begin vout(packet_length[c]); vout(c); vout(x div @'200000);
3929 vout((x div @'400) mod 256); vout(x mod 256);
3930 vcount:=vcount+5+packet_length[c];
3931 end;
3932 if packet_start[c]=vf_size then
3933 vfout_set(c)
3934 else for k:=0 to packet_length[c]-1 do vout(vf[packet_start[c]+k]);
3935 end
3936
3937 @* The main program.
3938 The routines sketched out so far need to be packaged into separate procedures,
3939 on some systems, since some \PASCAL\ compilers place a strict limit on the
3940 size of a routine. The packaging is done here in an attempt to avoid some
3941 system-dependent changes.
3942
3943 @p procedure param_enter;
3944 begin @<Enter the parameter names@>;
3945 end;
3946 @#
3947 procedure vpl_enter;
3948 begin @<Enter all the \.{VPL} names@>;
3949 end;
3950 @#
3951 procedure name_enter; {enter all names and their equivalents}
3952 begin @<Enter all the \.{PL} names...@>;
3953 vpl_enter; param_enter;
3954 end;
3955 @#
3956 procedure read_lig_kern;
3957 var @!krn_ptr:0..max_kerns; {an index into |kern|}
3958 @!c:byte; {runs through all character codes}
3959 begin @<Read ligature/kern list@>;
3960 end;
3961 @#
3962 procedure output_new_information_ofm;
3963 begin @<Output the new information for OFM files@>;
3964 end;
3965 @#
3966 procedure compute_new_header_ofm;
3967 begin @<Compute the new header information for OFM files@>;
3968 end;
3969 @#
3970 procedure finish_extended_font;
3971 begin @<Finish up the extended font stuff@>;
3972 end;
3973 @#
3974 procedure output_subfile_sizes;
3975 begin @<Output the subfile sizes@>;
3976 end;
3977 @#
3978 procedure compute_subfile_sizes;
3979 begin @<Compute the subfile sizes@>;
3980 end;
3981 @#
3982 procedure output_character_info;
3983 begin @<Output the character info@>;
3984 end;
3985 @#
3986 @#
3987 procedure read_font_rule_list;
3988 begin @<Read font rule list@>;
3989 end;
3990 @#
3991 procedure read_font_glue_list;
3992 begin @<Read font glue list@>;
3993 end;
3994 @#
3995 procedure read_font_penalty_list;
3996 begin @<Read font penalty list@>;
3997 end;
3998 @#
3999 procedure read_font_mvalue_list;
4000 begin @<Read font mvalue list@>;
4001 end;
4002 @#
4003 procedure read_font_fvalue_list;
4004 begin @<Read font fvalue list@>;
4005 end;
4006 @#
4007 procedure read_font_ivalue_list;
4008 begin @<Read font ivalue list@>;
4009 end;
4010 @#
4011 procedure read_repeated_character_info;
4012 begin @<Read repeated character info@>;
4013 end;
4014 @#
4015 procedure read_lig_kern_command;
4016 begin @<Read a ligature/kern command@>;
4017 end;
4018 @#
4019 procedure read_character_property;
4020 begin @<Read a character property@>;
4021 end;
4022 @#
4023 procedure read_char_info;
4024 begin @<Read character info list@>;
4025 end;
4026 @#
4027 procedure read_input;
4028 var @!c:byte; {header or parameter index}
4029 begin @<Read all the input@>;
4030 end;
4031 @#
4032 procedure corr_and_check;
4033 var @!c:xchar_type; {runs through all character codes}
4034 @!hh:0..hash_size; {an index into |hash_list|}
4035 @!lig_ptr:0..max_lig_steps; {an index into |lig_kern|}
4036 @!g:byte; {a character generated by the current character |c|}
4037 begin @<Correct and check the information@>
4038 end;
4039 @#
4040 procedure vf_output;
4041 var @!c:char_type; {runs through all character codes}
4042 @!cur_font:xfont_type; {runs through all local fonts}
4043 @!k:integer; {loop index}
4044 begin @<Do the \.{VF} output@>;
4045 end;
4046
4047 @ Here is where \.{VPtoVF} begins and ends.
4048
4049 @p begin initialize;@/
4050 name_enter;@/
4051 read_input; print_ln('.');@/
4052 corr_and_check;@/
4053 @<Do the font metric output@>;
4054 vf_output;
4055 final_end:
4056 end.
4057
4058 @ @<Global...@>=
4059 @!ofm_level:integer;
4060
4061 @ @<Set init...@>=
4062 ofm_level:=-1; {Suppose that it is a TFM file}
4063
4064 @ @<Read OFM level code@>=
4065 begin
4066 ofm_level:=get_integer;
4067 if (ofm_level<0) or (ofm_level>1) then begin
4068 flush_error('OFMLEVEL must be 0 or 1 -- 1 assumed');
4069 ofm_level:=1;
4070 end;
4071 end
4072
4073 @ @<Read font direction code@>=
4074 begin
4075 font_dir:=-1;
4076 repeat get_next;
4077 until cur_char<>" ";
4078 case cur_char of
4079 "T": begin get_next;
4080 if cur_char="L" then font_dir:=0
4081 else if cur_char="R" then font_dir:=2;
4082 end;
4083 "B": begin get_next;
4084 if cur_char="L" then font_dir:=4
4085 else if cur_char="R" then font_dir:=6;
4086 end;
4087 "R": begin get_next;
4088 if cur_char="T" then font_dir:=5
4089 else if cur_char="B" then font_dir:=7;
4090 end;
4091 "L": begin get_next;
4092 if cur_char="T" then font_dir:=1
4093 else if cur_char="B" then font_dir:=3;
4094 end;
4095 end;
4096 while cur_char<>")" do get_next;
4097 if font_dir = -1 then begin
4098 flush_error('FONTDIR must be valid direction, -- TL assumed');
4099 font_dir:=0;
4100 end;
4101 end
4102
4103 @ @<Read natural font direction code@>=
4104 begin
4105 font_dir:=-1;
4106 repeat get_next;
4107 until cur_char<>" ";
4108 case cur_char of
4109 "T": begin get_next;
4110 if cur_char="L" then font_dir:=8
4111 else if cur_char="R" then font_dir:=10;
4112 end;
4113 "B": begin get_next;
4114 if cur_char="L" then font_dir:=12
4115 else if cur_char="R" then font_dir:=14;
4116 end;
4117 "R": begin get_next;
4118 if cur_char="T" then font_dir:=13
4119 else if cur_char="B" then font_dir:=15;
4120 end;
4121 "L": begin get_next;
4122 if cur_char="T" then font_dir:=9
4123 else if cur_char="B" then font_dir:=11;
4124 end;
4125 end;
4126 while cur_char<>")" do get_next;
4127 if font_dir = -1 then begin
4128 flush_error('NFONTDIR must be valid direction, -- TL assumed');
4129 font_dir:=8;
4130 end;
4131 end
4132
4133 @
4134 Here are some general values for the various entries.
4135 They can all be changed.
4136
4137 @d arrays_per_kind==20
4138 @d entries_per_array==200
4139
4140 @ @<Constants...@>=
4141 @!rule_arrays=arrays_per_kind;
4142 @!rule_entries=entries_per_array;
4143
4144 @ @<Types...@>=
4145 rule_array_type=0..rule_arrays;
4146 rule_entry_type=0..rule_entries;
4147 rule_node=
4148 record
4149 rn_width: fix_word;
4150 rn_height: fix_word;
4151 rn_depth: fix_word;
4152 end;
4153
4154 @ @<Global...@>=
4155 @!rules:array[rule_array_type,rule_entry_type] of rule_node;
4156 @!npr:array[rule_array_type] of integer;
4157 @!nkr:integer;
4158 @!nwr:integer;
4159 @!r_array:integer;
4160 @!r_number:integer;
4161
4162 @ @<Set init...@>=
4163 for r_array := 0 to rule_arrays do begin
4164 npr[r_array]:=0;
4165 @<Null out the rule@>;
4166 end;
4167 nkr:=-1;
4168
4169 @ @<Read font rule list@>=
4170 begin
4171 if tables_read then
4172 flush_error('All parameter tables must appear before character info');
4173 r_array:=get_integer;
4174 if r_array>rule_arrays then
4175 flush_error('This FONTRULE table index is too big for my present size')
4176 else if r_array<0 then
4177 flush_error('This FONTRULE index is negative')
4178 else begin
4179 if r_array>nkr then nkr:=r_array;
4180 while level=1 do begin
4181 while cur_char=" " do get_next;
4182 if cur_char="(" then @<Read a rule@>
4183 else if cur_char=")" then skip_to_end_of_item
4184 else junk_error;
4185 end;
4186 finish_inner_property_list;
4187 end;
4188 end
4189
4190 @ @<Read a rule@>=
4191 begin
4192 get_name;
4193 if cur_code=comment_code then skip_to_end_of_item
4194 else if cur_code<>rule_code then
4195 flush_error('This property name doesn''t belong in a FONTRULE list')
4196 else begin
4197 r_number:=get_integer;
4198 if r_number>rule_entries then
4199 flush_error('This RULE index is too big for my present table size')
4200 else if r_number<0 then
4201 flush_error('This RULE index is negative')
4202 else begin
4203 while npr[r_array]<r_number do begin
4204 incr(npr[r_array]); @<Null out the rule@>;
4205 end;
4206 @<Read all of a rule's values@>;
4207 finish_the_property;
4208 end;
4209 end;
4210 end
4211
4212 @ @<Null out the rule@>=
4213 begin
4214 rules[r_array,npr[r_array]].rn_width:=0;
4215 rules[r_array,npr[r_array]].rn_depth:=0;
4216 rules[r_array,npr[r_array]].rn_height:=0;
4217 end
4218
4219 @ @<Read all of a rule's values@>=
4220 begin
4221 while level=2 do begin
4222 while cur_char=" " do get_next;
4223 if cur_char="(" then @<Read a single rule value@>
4224 else if cur_char=")" then skip_to_end_of_item
4225 else junk_error;
4226 end;
4227 finish_inner_property_list;
4228 end
4229
4230 @ @<Read a single rule value@>=
4231 begin
4232 get_name;
4233 if cur_code=comment_code then skip_to_end_of_item
4234 else if (cur_code<rule_width_code)or(cur_code>rule_depth_code) then
4235 flush_error('This property name doesn''t belong in a RULE list')
4236 else begin
4237 case cur_code of
4238 rule_width_code:
4239 rules[r_array,r_number].rn_width:=get_fix;
4240 rule_height_code:
4241 rules[r_array,r_number].rn_height:=get_fix;
4242 rule_depth_code:
4243 rules[r_array,r_number].rn_depth:=get_fix;
4244 end;
4245 finish_the_property;
4246 end;
4247 end
4248
4249 @ @<Header information for rules@>=
4250 begin
4251 nwr:=0;
4252 for r_array := 0 to nkr do begin
4253 incr(npr[r_array]);
4254 nwr := nwr + 3*npr[r_array];
4255 end;
4256 incr(nkr);
4257 end
4258
4259 @ @<Output the rules@>=
4260 begin
4261 for r_array:= 0 to nkr-1 do
4262 for r_number:=0 to npr[r_array]-1 do begin
4263 out_scaled(rules[r_array,r_number].rn_width);
4264 out_scaled(rules[r_array,r_number].rn_height);
4265 out_scaled(rules[r_array,r_number].rn_depth);
4266 end;
4267 end
4268
4269 @ @<Output the rule headers@>=
4270 begin
4271 for r_array:= 0 to nkr-1 do begin
4272 out_integer(npr[r_array]);
4273 end;
4274 end
4275
4276 @ @<Constants...@>=
4277 @!glue_arrays=arrays_per_kind;
4278 @!glue_entries=entries_per_array;
4279
4280 @
4281 @d t_normal==0
4282 @d t_aleaders==1
4283 @d t_cleaders==2
4284 @d t_xleaders==3
4285
4286 @d o_unit==0
4287 @d o_fi==1
4288 @d o_fil==2
4289 @d o_fill==3
4290 @d o_filll==4
4291
4292 @d g_space==0
4293 @d g_rule==1
4294 @d g_char==2
4295
4296 @<Types...@>=
4297 glue_array_type=0..glue_arrays;
4298 glue_entry_type=0..glue_entries;
4299 glue_node=
4300 record
4301 gn_width: fix_word;
4302 gn_stretch: fix_word;
4303 gn_shrink: fix_word;
4304 gn_type: integer;
4305 gn_arg_type: g_space..g_char;
4306 gn_stretch_order: integer;
4307 gn_shrink_order: integer;
4308 gn_argument: integer;
4309 end;
4310
4311 @ @<Global...@>=
4312 @!glues:array[glue_array_type,glue_entry_type] of glue_node;
4313 @!npg:array[glue_array_type] of integer;
4314 @!nkg:integer;
4315 @!nwg:integer;
4316 @!g_array:integer;
4317 @!g_byte:integer;
4318 @!g_number:integer;
4319
4320 @ @<Set init...@>=
4321 for g_array := 0 to glue_arrays do
4322 begin
4323 npg[g_array]:=0;
4324 @<Null out the glue@>;
4325 end;
4326 nkg:=-1;
4327
4328 @ @<Read font glue list@>=
4329 begin
4330 if tables_read then
4331 flush_error('All parameter tables must appear before character info');
4332 g_array:=get_integer;
4333 if g_array>glue_arrays then
4334 flush_error('This FONTGLUE table index is too big for my present size')
4335 else if g_array<0 then
4336 flush_error('This FONTGLUE index is negative')
4337 else begin
4338 if g_array>nkg then nkg:=g_array;
4339 while level=1 do begin
4340 while cur_char=" " do get_next;
4341 if cur_char="(" then @<Read a glue@>
4342 else if cur_char=")" then skip_to_end_of_item
4343 else junk_error;
4344 end;
4345 finish_inner_property_list;
4346 end;
4347 end
4348
4349 @ @<Read a glue@>=
4350 begin
4351 get_name;
4352 if cur_code=comment_code then skip_to_end_of_item
4353 else if cur_code<>glue_code then
4354 flush_error('This property name doesn''t belong in a FONTGLUE list')
4355 else begin
4356 g_number:=get_integer;
4357 if g_number>glue_entries then
4358 flush_error('This GLUE index is too big for my present table size')
4359 else if g_number<0 then
4360 flush_error('This GLUE index is negative')
4361 else begin
4362 while npg[g_array]<g_number do begin
4363 incr(npg[g_array]); @<Null out the glue@>;
4364 end;
4365 @<Read all of a glue's values@>;
4366 finish_the_property;
4367 end;
4368 end;
4369 end
4370
4371 @ @<Null out the glue@>=
4372 begin
4373 glues[g_array,npg[g_array]].gn_width:=0;
4374 glues[g_array,npg[g_array]].gn_stretch:=0;
4375 glues[g_array,npg[g_array]].gn_shrink:=0;
4376 glues[g_array,npg[g_array]].gn_type:=0;
4377 glues[g_array,npg[g_array]].gn_arg_type:=0;
4378 glues[g_array,npg[g_array]].gn_stretch_order:=0;
4379 glues[g_array,npg[g_array]].gn_shrink_order:=0;
4380 glues[g_array,npg[g_array]].gn_argument:=0;
4381 end
4382
4383 @ @<Read all of a glue's values@>=
4384 begin
4385 while level=2 do begin
4386 while cur_char=" " do get_next;
4387 if cur_char="(" then @<Read a single glue value@>
4388 else if cur_char=")" then skip_to_end_of_item
4389 else junk_error;
4390 end;
4391 finish_inner_property_list;
4392 end
4393
4394 @ @<Read a single glue value@>=
4395 begin
4396 get_name;
4397 if cur_code=comment_code then skip_to_end_of_item
4398 else if (cur_code<glue_type_code)or(cur_code>glue_rule_code) then
4399 flush_error('This property name doesn''t belong in a GLUE list')
4400 else begin
4401 case cur_code of
4402 glue_width_code:
4403 glues[g_array,g_number].gn_width:=get_fix;
4404 glue_stretch_code:
4405 glues[g_array,g_number].gn_stretch:=get_fix;
4406 glue_shrink_code:
4407 glues[g_array,g_number].gn_shrink:=get_fix;
4408 glue_type_code: begin
4409 g_byte:=get_integer;
4410 if (g_byte<0) or (g_byte>3) then begin
4411 g_byte:=0;
4412 end;
4413 glues[g_array,g_number].gn_type:=g_byte;
4414 end;
4415 glue_stretch_order_code: begin
4416 g_byte:=get_integer;
4417 if (g_byte<0) or (g_byte>4) then begin
4418 g_byte:=0;
4419 end;
4420 glues[g_array,g_number].gn_stretch_order:=g_byte;
4421 end;
4422 glue_shrink_order_code: begin
4423 g_byte:=get_integer;
4424 if (g_byte<0) or (g_byte>4) then begin
4425 g_byte:=0;
4426 end;
4427 glues[g_array,g_number].gn_shrink_order:=g_byte;
4428 end;
4429 glue_char_code: begin
4430 glues[g_array,g_number].gn_argument:=get_integer;
4431 glues[g_array,g_number].gn_arg_type:=g_char;
4432 end;
4433 glue_rule_code: begin
4434 glues[g_array,g_number].gn_argument:=get_integer;
4435 glues[g_array,g_number].gn_arg_type:=g_rule;
4436 end;
4437 end;
4438 finish_the_property;
4439 end;
4440 end
4441
4442 @ @<Header information for glues@>=
4443 begin
4444 nwg:=0;
4445 for g_array := 0 to nkg do begin
4446 incr(npg[g_array]);
4447 nwg := nwg + 4*npg[g_array];
4448 end;
4449 incr(nkg);
4450 end
4451
4452 @ @<Output the glues@>=
4453 begin
4454 for g_array:= 0 to nkg-1 do
4455 for g_number:=0 to npg[g_array]-1 do begin
4456 g_byte:=glues[g_array,g_number].gn_type*16+
4457 glues[g_array,g_number].gn_arg_type;
4458 out(g_byte);
4459 g_byte:=glues[g_array,g_number].gn_stretch_order*16+
4460 glues[g_array,g_number].gn_shrink_order;
4461 out(g_byte);
4462 g_byte:=glues[g_array,g_number].gn_argument div 256;
4463 out(g_byte);
4464 g_byte:=glues[g_array,g_number].gn_argument mod 256;
4465 out(g_byte);
4466 out_scaled(glues[g_array,g_number].gn_width);
4467 out_scaled(glues[g_array,g_number].gn_stretch);
4468 out_scaled(glues[g_array,g_number].gn_shrink);
4469 end;
4470 end
4471
4472 @ @<Output the glue headers@>=
4473 begin
4474 for g_array:= 0 to nkg-1 do begin
4475 out_integer(npg[g_array]);
4476 end;
4477 end
4478
4479 @ @<Constants...@>=
4480 @!penalty_arrays=arrays_per_kind;
4481 @!penalty_entries=entries_per_array;
4482
4483 @ @<Types...@>=
4484 penalty_array_type=0..penalty_arrays;
4485 penalty_entry_type=0..penalty_entries;
4486 penalty_node=
4487 record
4488 pn_val: integer;
4489 end;
4490
4491 @ @<Global...@>=
4492 @!penalties:array[penalty_array_type,penalty_entry_type] of penalty_node;
4493 @!npp:array[penalty_array_type] of integer;
4494 @!nkp:integer;
4495 @!nwp:integer;
4496 @!p_array:integer;
4497 @!p_number:integer;
4498
4499 @ @<Set init...@>=
4500 for p_array := 0 to penalty_arrays do begin
4501 npp[p_array]:=0;
4502 @<Null out the penalty@>;
4503 end;
4504 nkp:=-1;
4505
4506 @ @<Read font penalty list@>=
4507 begin
4508 if tables_read then
4509 flush_error('All parameter tables must appear before character info');
4510 p_array:=get_integer;
4511 if p_array>penalty_arrays then
4512 flush_error('This FONTPENALTY table index is too big for my present size')
4513 else if p_array<0 then
4514 flush_error('This FONTPENALTY index is negative')
4515 else begin
4516 if p_array>nkp then nkp:=p_array;
4517 while level=1 do begin
4518 while cur_char=" " do get_next;
4519 if cur_char="(" then @<Read a penalty@>
4520 else if cur_char=")" then skip_to_end_of_item
4521 else junk_error;
4522 end;
4523 finish_inner_property_list;
4524 end;
4525 end
4526
4527 @ @<Read a penalty@>=
4528 begin
4529 get_name;
4530 if cur_code=comment_code then skip_to_end_of_item
4531 else if cur_code<>penalty_code then
4532 flush_error('This property name doesn''t belong in a FONTPENALTY list')
4533 else begin
4534 p_number:=get_integer;
4535 if p_number>penalty_entries then
4536 flush_error('This PENALTY index is too big for my present table size')
4537 else if p_number<0 then
4538 flush_error('This PENALTY index is negative')
4539 else begin
4540 while npp[p_array]<p_number do begin
4541 incr(npp[p_array]); @<Null out the penalty@>;
4542 end;
4543 @<Read all of a penalty's values@>;
4544 finish_the_property;
4545 end;
4546 end;
4547 end
4548
4549 @ @<Null out the penalty@>=
4550 begin
4551 penalties[p_array,npp[p_array]].pn_val:=0;
4552 end
4553
4554 @ @<Read all of a penalty's values@>=
4555 begin
4556 while level=2 do begin
4557 while cur_char=" " do get_next;
4558 if cur_char="(" then @<Read a single penalty value@>
4559 else if cur_char=")" then skip_to_end_of_item
4560 else junk_error;
4561 end;
4562 finish_inner_property_list;
4563 end
4564
4565 @ @<Read a single penalty value@>=
4566 begin
4567 get_name;
4568 if cur_code=comment_code then skip_to_end_of_item
4569 else if cur_code<>penalty_val_code then
4570 flush_error('This property name doesn''t belong in a PENALTY list')
4571 else begin
4572 penalties[p_array,p_number].pn_val:=get_integer;
4573 finish_the_property;
4574 end;
4575 end
4576
4577 @ @<Header information for penalties@>=
4578 begin
4579 nwp:=0;
4580 for p_array := 0 to nkp do begin
4581 incr(npp[p_array]);
4582 nwp := nwp + npp[p_array];
4583 end;
4584 incr(nkp);
4585 end
4586
4587 @ @<Output the penalties@>=
4588 begin
4589 for p_array:= 0 to nkp-1 do
4590 for p_number:=0 to npp[p_array]-1 do begin
4591 out_int(penalties[p_array,p_number].pn_val);
4592 end;
4593 end
4594
4595 @ @<Output the penalty headers@>=
4596 begin
4597 for p_array:= 0 to nkp-1 do begin
4598 out_integer(npp[p_array]);
4599 end;
4600 end
4601
4602 @ @<Constants...@>=
4603 @!mvalue_arrays=arrays_per_kind;
4604 @!mvalue_entries=entries_per_array;
4605
4606 @ @<Types...@>=
4607 mvalue_array_type=0..mvalue_arrays;
4608 mvalue_entry_type=0..mvalue_entries;
4609 mvalue_node=
4610 record
4611 fn_val: fix_word;
4612 end;
4613
4614 @ @<Global...@>=
4615 @!mvalues:array[mvalue_array_type,mvalue_entry_type] of mvalue_node;
4616 @!npm:array[mvalue_array_type] of integer;
4617 @!nkm:integer;
4618 @!nwm:integer;
4619 @!m_array:integer;
4620 @!m_number:integer;
4621
4622 @ @<Set init...@>=
4623 for m_array := 0 to mvalue_arrays do begin
4624 npm[m_array]:=0;
4625 @<Null out the mvalue@>;
4626 end;
4627 nkm:=-1;
4628
4629 @ @<Read font mvalue list@>=
4630 begin
4631 if tables_read then
4632 flush_error('All parameter tables must appear before character info');
4633 m_array:=get_integer;
4634 if m_array>mvalue_arrays then
4635 flush_error('This FONTMVALUE table index is too big for my present size')
4636 else if m_array<0 then
4637 flush_error('This FONTMVALUE index is negative')
4638 else begin
4639 if m_array>nkm then nkm:=m_array;
4640 while level=1 do begin
4641 while cur_char=" " do get_next;
4642 if cur_char="(" then @<Read an mvalue@>
4643 else if cur_char=")" then skip_to_end_of_item
4644 else junk_error;
4645 end;
4646 finish_inner_property_list;
4647 end;
4648 end
4649
4650 @ @<Read an mvalue@>=
4651 begin
4652 get_name;
4653 if cur_code=comment_code then skip_to_end_of_item
4654 else if cur_code<>mvalue_code then
4655 flush_error('This property name doesn''t belong in an FONTMVALUE list')
4656 else begin
4657 m_number:=get_integer;
4658 if m_number>mvalue_entries then
4659 flush_error('This MVALUE index is too big for my present table size')
4660 else if m_number<0 then
4661 flush_error('This MVALUE index is negative')
4662 else begin
4663 while npm[m_array]<m_number do begin
4664 incr(npm[m_array]); @<Null out the mvalue@>;
4665 end;
4666 @<Read all of an mvalue's values@>;
4667 finish_the_property;
4668 end;
4669 end;
4670 end
4671
4672 @ @<Null out the mvalue@>=
4673 begin
4674 mvalues[m_array,npm[m_array]].fn_val:=0;
4675 end
4676
4677 @ @<Read all of an mvalue's values@>=
4678 begin
4679 while level=2 do begin
4680 while cur_char=" " do get_next;
4681 if cur_char="(" then @<Read a single mvalue value@>
4682 else if cur_char=")" then skip_to_end_of_item
4683 else junk_error;
4684 end;
4685 finish_inner_property_list;
4686 end
4687
4688 @ @<Read a single mvalue value@>=
4689 begin
4690 get_name;
4691 if cur_code=comment_code then skip_to_end_of_item
4692 else if cur_code<>mvalue_val_code then
4693 flush_error('This property name doesn''t belong in a MVALUE list')
4694 else begin
4695 mvalues[m_array,m_number].fn_val:=get_fix;
4696 finish_the_property;
4697 end;
4698 end
4699
4700 @ @<Header information for mvalues@>=
4701 begin
4702 nwm:=0;
4703 for m_array := 0 to nkm do begin
4704 incr(npm[m_array]);
4705 nwm := nwm + npm[m_array];
4706 end;
4707 incr(nkm);
4708 end
4709
4710 @ @<Output the mvalues@>=
4711 begin
4712 for m_array:= 0 to nkm-1 do
4713 for m_number:=0 to npm[m_array]-1 do begin
4714 out_scaled(mvalues[m_array,m_number].fn_val);
4715 end;
4716 end
4717
4718 @ @<Output the mvalue headers@>=
4719 begin
4720 for m_array:= 0 to nkm-1 do begin
4721 out_integer(npm[m_array]);
4722 end;
4723 end
4724
4725 @ @<Constants...@>=
4726 @!fvalue_arrays=arrays_per_kind;
4727 @!fvalue_entries=entries_per_array;
4728
4729 @ @<Types...@>=
4730 fvalue_array_type=0..fvalue_arrays;
4731 fvalue_entry_type=0..fvalue_entries;
4732 fvalue_node=
4733 record
4734 fn_val: fix_word;
4735 end;
4736
4737 @ @<Global...@>=
4738 @!fvalues:array[fvalue_array_type,fvalue_entry_type] of fvalue_node;
4739 @!npf:array[fvalue_array_type] of integer;
4740 @!nkf:integer;
4741 @!nwf:integer;
4742 @!f_array:integer;
4743 @!f_number:integer;
4744
4745 @ @<Set init...@>=
4746 for f_array := 0 to fvalue_arrays do begin
4747 npf[f_array]:=0;
4748 @<Null out the fvalue@>;
4749 end;
4750 nkf:=-1;
4751
4752 @ @<Read font fvalue list@>=
4753 begin
4754 if tables_read then
4755 flush_error('All parameter tables must appear before character info');
4756 f_array:=get_integer;
4757 if f_array>fvalue_arrays then
4758 flush_error('This FONTFVALUE table index is too big for my present size')
4759 else if f_array<0 then
4760 flush_error('This FONTFVALUE index is negative')
4761 else begin
4762 if f_array>nkf then nkf:=f_array;
4763 while level=1 do begin
4764 while cur_char=" " do get_next;
4765 if cur_char="(" then @<Read an fvalue@>
4766 else if cur_char=")" then skip_to_end_of_item
4767 else junk_error;
4768 end;
4769 finish_inner_property_list;
4770 end;
4771 end
4772
4773 @ @<Read an fvalue@>=
4774 begin
4775 get_name;
4776 if cur_code=comment_code then skip_to_end_of_item
4777 else if cur_code<>fvalue_code then
4778 flush_error('This property name doesn''t belong in an FONTFVALUE list')
4779 else begin
4780 f_number:=get_integer;
4781 if f_number>fvalue_entries then
4782 flush_error('This FVALUE index is too big for my present table size')
4783 else if f_number<0 then
4784 flush_error('This FVALUE index is negative')
4785 else begin
4786 while npf[f_array]<f_number do begin
4787 incr(npf[f_array]); @<Null out the fvalue@>;
4788 end;
4789 @<Read all of an fvalue's values@>;
4790 finish_the_property;
4791 end;
4792 end;
4793 end
4794
4795 @ @<Null out the fvalue@>=
4796 begin
4797 fvalues[f_array,npf[f_array]].fn_val:=0;
4798 end
4799
4800 @ @<Read all of an fvalue's values@>=
4801 begin
4802 while level=2 do begin
4803 while cur_char=" " do get_next;
4804 if cur_char="(" then @<Read a single fvalue value@>
4805 else if cur_char=")" then skip_to_end_of_item
4806 else junk_error;
4807 end;
4808 finish_inner_property_list;
4809 end
4810
4811 @ @<Read a single fvalue value@>=
4812 begin
4813 get_name;
4814 if cur_code=comment_code then skip_to_end_of_item
4815 else if cur_code<>fvalue_val_code then
4816 flush_error('This property name doesn''t belong in a FVALUE list')
4817 else begin
4818 fvalues[f_array,f_number].fn_val:=get_fix;
4819 finish_the_property;
4820 end;
4821 end
4822
4823 @ @<Header information for fvalues@>=
4824 begin
4825 nwf:=0;
4826 for f_array := 0 to nkf do begin
4827 incr(npf[f_array]);
4828 nwf := nwf + npf[f_array];
4829 end;
4830 incr(nkf);
4831 end
4832
4833 @ @<Output the fvalues@>=
4834 begin
4835 for f_array:= 0 to nkf-1 do
4836 for f_number:=0 to npf[f_array]-1 do begin
4837 out_scaled(fvalues[f_array,f_number].fn_val);
4838 end;
4839 end
4840
4841 @ @<Output the fvalue headers@>=
4842 begin
4843 for f_array:= 0 to nkf-1 do begin
4844 out_integer(npf[f_array]);
4845 end;
4846 end
4847
4848 @ @<Constants...@>=
4849 @!ivalue_arrays=arrays_per_kind;
4850 @!ivalue_entries=entries_per_array;
4851
4852 @ @<Types...@>=
4853 ivalue_array_type=0..ivalue_arrays;
4854 ivalue_entry_type=0..ivalue_entries;
4855 ivalue_node=
4856 record
4857 in_val: integer;
4858 end;
4859
4860 @ @<Global...@>=
4861 @!ivalues:array[ivalue_array_type,ivalue_entry_type] of ivalue_node;
4862 @!npi:array[ivalue_array_type] of integer;
4863 @!font_i_array:boolean;
4864 @!nki:integer;
4865 @!nwi:integer;
4866 @!i_array:integer;
4867 @!i_number:integer;
4868
4869 @ @<Set init...@>=
4870 for i_array := 0 to ivalue_arrays do begin
4871 npi[i_array]:=0;
4872 @<Null out the ivalue@>;
4873 end;
4874 nki:=-1;
4875
4876 @ @<Read font ivalue list@>=
4877 begin
4878 if tables_read then
4879 flush_error('All parameter tables must appear before character info');
4880 i_array:=get_integer;
4881 if i_array>ivalue_arrays then
4882 flush_error('This FONTIVALUE table index is too big for my present size')
4883 else if i_array<0 then
4884 flush_error('This FONTIVALUE index is negative')
4885 else begin
4886 if i_array>nki then nki:=i_array;
4887 while level=1 do begin
4888 while cur_char=" " do get_next;
4889 if cur_char="(" then @<Read an ivalue@>
4890 else if cur_char=")" then skip_to_end_of_item
4891 else junk_error;
4892 end;
4893 finish_inner_property_list;
4894 end;
4895 end
4896
4897 @ @<Read an ivalue@>=
4898 begin
4899 get_name;
4900 if cur_code=comment_code then skip_to_end_of_item
4901 else if cur_code<>ivalue_code then
4902 flush_error('This property name doesn''t belong in an FONTIVALUE list')
4903 else begin
4904 i_number:=get_integer;
4905 if i_number>ivalue_entries then
4906 flush_error('This IVALUE index is too big for my present table size')
4907 else if i_number<0 then
4908 flush_error('This IVALUE index is negative')
4909 else begin
4910 while npi[i_array]<i_number do begin
4911 incr(npi[i_array]); @<Null out the ivalue@>;
4912 end;
4913 @<Read all of an ivalue's values@>;
4914 finish_the_property;
4915 end;
4916 end;
4917 end
4918
4919 @ @<Null out the ivalue@>=
4920 begin
4921 ivalues[i_array,npi[i_array]].in_val:=0;
4922 end
4923
4924 @ @<Read all of an ivalue's values@>=
4925 begin
4926 while level=2 do begin
4927 while cur_char=" " do get_next;
4928 if cur_char="(" then @<Read a single ivalue value@>
4929 else if cur_char=")" then skip_to_end_of_item
4930 else junk_error;
4931 end;
4932 finish_inner_property_list;
4933 end
4934
4935 @ @<Read a single ivalue value@>=
4936 begin
4937 get_name;
4938 if cur_code=comment_code then skip_to_end_of_item
4939 else if cur_code<>ivalue_val_code then
4940 flush_error('This property name doesn''t belong in a IVALUE list')
4941 else begin
4942 ivalues[i_array,i_number].in_val:=get_integer;
4943 finish_the_property;
4944 end;
4945 end
4946
4947 @ @<Header information for ivalues@>=
4948 begin
4949 nwi:=0;
4950 for i_array := 0 to nki do begin
4951 incr(npi[i_array]);
4952 nwi := nwi + npi[i_array];
4953 end;
4954 incr(nki);
4955 end
4956
4957 @ @<Output the ivalues@>=
4958 begin
4959 for i_array:= 0 to nki-1 do
4960 for i_number:=0 to npi[i_array]-1 do begin
4961 out_int(ivalues[i_array,i_number].in_val);
4962 end;
4963 end
4964
4965 @ @<Output the ivalue headers@>=
4966 begin
4967 for i_array:= 0 to nki-1 do begin
4968 out_integer(npi[i_array]);
4969 end;
4970 end
4971
4972 @ @<Compute the new header information for OFM files@>=
4973 begin
4974 @<Header information for ivalues@>;
4975 @<Header information for fvalues@>;
4976 @<Header information for mvalues@>;
4977 @<Header information for rules@>;
4978 @<Header information for glues@>;
4979 @<Header information for penalties@>;
4980 end
4981
4982 @ @<Output the new information for OFM files@>=
4983 begin
4984 @<Output the ivalue headers@>;
4985 @<Output the fvalue headers@>;
4986 @<Output the mvalue headers@>;
4987 @<Output the rule headers@>;
4988 @<Output the glue headers@>;
4989 @<Output the penalty headers@>;
4990 @<Output the ivalues@>;
4991 @<Output the fvalues@>;
4992 @<Output the mvalues@>;
4993 @<Output the rules@>;
4994 @<Output the glues@>;
4995 @<Output the penalties@>;
4996 end
4997
4998 @* System-dependent changes.
4999 This section should be replaced, if necessary, by changes to the program
5000 that are necessary to make \.{VPtoVF} work at a particular installation.
5001 It is usually best to design your change file so that all changes to
5002 previous sections preserve the section numbering; then everybody's version
5003 will be consistent with the printed program. More extensive changes,
5004 which introduce new sections, can be inserted here; then only the index
5005 itself will get a new section number.
5006 @^system dependencies@>
5007
5008 @* Index.
5009 Pointers to error messages appear here together with the section numbers
5010 where each ident\-i\-fier is used.