2
% This file is part of the Omega project, which
3
% is based in the web2c distribution of TeX.
5
% Copyright (c) 1994--2000 John Plaice and Yannis Haralambous
6
% applies only to the changes to the original vptovf.web.
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).
15
% Here is TeX material that gets inserted after \input webmac
16
\def\hang{\hangindent 3em\indent\ignorespaces}
18
\let\mc=\ninerm % medium caps for names like SAIL
20
\font\logo=logo10 % for the METAFONT logo
21
\def\MF{{\logo METAFONT}}
23
\def\(#1){} % this is used to make section names sort themselves better
24
\def\9#1{} % this is used for sort keys in the index
27
\def\contentspagenumber{201}
28
\def\topofcontents{\null
29
\def\titlepage{F} % include headline on the contents page
30
\def\rheader{\mainfont\hfil \contentspagenumber}
32
\centerline{\titlefont The {\ttitlefont OVP2OVF} processor}
34
\centerline{(Version 1.11, February 2000)}
36
\def\botofcontents{\vfill
37
\centerline{\hsize 5in\baselineskip9pt
38
\vbox{\ninerm\noindent
39
The preparation of this program
40
was supported in part by the National Science
41
Foundation and by the System Development Foundation. `\TeX' is a
42
trademark of the American Mathematical Society.}}}
43
\pageno=\contentspagenumber \advance\pageno by 1
46
The \.{OVP2OVF} utility program converts virtual-property-list (``\.{VPL}''
47
and ``\.{OVP}'') files into an equivalent pair of files called a virtual
48
font (``\.{OVF}'') file and an $\Omega$ font metric (``\.{OFM}'') file.
49
It also makes a thorough check of the given \.{VPL} or \.{OVP} file,
50
so that the \.{OVF} file should be acceptable to device drivers and
51
the \.{OFM} file should be acceptable to $\Omega$.
53
In the following documentation, all unchanged references to
54
the \.{VPtoVF} program and to \.{VPL}, \.{VF} and \.{TFM} files also apply to
55
the \.{OVP2OVF} program and to \.{OVP}, \.{OVF} and \.{OFM} files.
57
\indent\.{VPtoVF} is an extended version of the program \.{PLtoTF}, which
58
is part of the standard \TeX ware library.
59
\.{OVP2OVF} is an extended version of \.{VPtoVF} that allows
61
The idea of a virtual font was inspired by the work of David R. Fuchs
62
@^Fuchs, David Raymond@>
63
who designed a similar set of conventions in 1984 while developing a
64
device driver for ArborText, Inc. He wrote a somewhat similar program
67
The |banner| string defined here should be changed whenever \.{OVP2OVF}
70
@d banner=='This is OVP2OVF, Version 1.11'
71
{printed when the program starts}
73
@ This program is written entirely in standard \PASCAL, except that
74
it has to do some slightly system-dependent character code conversion
75
on input. Furthermore, lower case letters are used in error messages;
76
they could be converted to upper case if necessary. The input is read
77
from |vpl_file|, and the output is written on |vf_file| and |tfm_file|;
79
other remarks are written on the |output| file, which the user may
80
choose to assign to the terminal if the system permits it.
81
@^system dependencies@>
83
The term |print| is used instead of |write| when this program writes on
84
the |output| file, so that all such output can be easily deflected.
87
@d print_ln(#)==write_ln(#)
89
@p program OVP2OVF(@!vpl_file,@!vf_file,@!tfm_file,@!output);
90
const @<Constants in the outer block@>@/
91
type @<Types in the outer block@>@/
92
var @<Globals in the outer block@>@/
93
procedure initialize; {this procedure gets things started properly}
94
var @<Local variables for initialization@>@/
95
begin print_ln(banner);@/
96
@<Set initial values@>@/
99
@ The following parameters can be changed at compile time to extend or
100
reduce \.{VPtoVF}'s capacity.
103
@!ofm_type=0; {16-bit OFM; sufficient for most purposes}
104
@!max_char=65535; {the largest character number in a font}
105
@!xmax_char=65536; {|max_char|+1}
106
@!xxmax_char=65537;{|max_char|+2}
107
@!mem_size=262148; {|max_char|*4+8}
108
@!max_font=1000; {the largest font number}
109
@!xmax_font=1001; {|max_font|+1}
110
@!xxmax_font=1002; {|max_font|+2}
111
@!max_width=65535; {the largest character width number}
112
@!max_height=255; {the largest character height number}
113
@!max_depth=255; {the largest character depth number}
114
@!max_italic=255; {the largest character italic correction number}
115
@!buf_size=60; {length of lines displayed in error messages}
116
@!max_header_bytes=100; {four times the maximum number of words allowed in
117
the \.{TFM} file header block, must be 1024 or less}
118
@!vf_size=200000; {maximum length of |vf| data, in bytes}
119
@!max_stack=100; {maximum depth of simulated \.{DVI} stack}
120
@!max_param_words=100; {the maximum number of \.{fontdimen} parameters allowed}
121
@!max_lig_steps=800000; {maximum length of ligature program}
122
@!xmax_label=800001; {must be greater than |max_lig_steps|}
123
@!hash_size=130003; {preferably a prime number,
124
a bit larger than |max_lig_steps|, the number
125
of character pairs in lig/kern steps}
126
@!hash_mult=16007; {another prime}
127
@!max_kerns=100000; {the maximum number of distinct kern values}
129
@ Here are some macros for common programming idioms.
131
@d incr(#) == #:=#+1 {increase a variable by unity}
132
@d decr(#) == #:=#-1 {decrease a variable by unity}
133
@d do_nothing == {empty statement}
135
@* Property list description of font metric data.
136
The idea behind \.{VPL} files is that precise details about fonts, i.e., the
137
facts that are needed by typesetting routines like \TeX, sometimes have to
138
be supplied by hand. The nested property-list format provides a reasonably
139
convenient way to do this.
141
A good deal of computation is necessary to parse and process a
142
\.{VPL} file, so it would be inappropriate for \TeX\ itself to do this
143
every time it loads a font. \TeX\ deals only with the compact descriptions
144
of font metric data that appear in \.{TFM} files. Such data is so compact,
145
however, it is almost impossible for anybody but a computer to read it.
147
Device drivers also need a compact way to describe mappings from \TeX's idea
148
of a font to the actual characters a device can produce. They can do this
149
conveniently when given a packed sequence of bytes called a \.{VF} file.
151
The purpose of \.{VPtoVF} is to convert from a human-oriented file of text
152
to computer-oriented files of binary numbers. There's a companion program,
153
\.{VFtoVP}, which goes the other way.
161
@ A \.{VPL} file is like a \.{PL} file with a few extra features, so we
162
can begin to define it by reviewing the definition of \.{PL} files. The
163
material in the next few sections is copied from the program \.{PLtoTF}.
164
An \.{OVP} file is simply a \.{VPL} file that does not restrict fonts
167
A \.{PL} file is a list of entries of the form
168
$$\.{(PROPERTYNAME VALUE)}$$
169
where the property name is one of a finite set of names understood by
170
this program, and the value may itself in turn be a property list.
171
The idea is best understood by looking at an example, so let's consider
172
a fragment of the \.{PL} file for a hypothetical font.
173
$$\vbox{\halign{\.{#}\hfil\cr
176
(CODINGSCHEME ASCII)\cr
178
(DESIGNUNITS D 18)\cr
179
(COMMENT A COMMENT IS IGNORED)\cr
180
(COMMENT (EXCEPT THIS ONE ISN'T))\cr
181
(COMMENT (ACTUALLY IT IS, EVEN THOUGH\cr
182
\qquad\qquad IT SAYS IT ISN'T))\cr
184
\qquad (SLANT R -.25)\cr
185
\qquad (SPACE D 6)\cr
186
\qquad (SHRINK D 2)\cr
187
\qquad (STRETCH D 3)\cr
188
\qquad (XHEIGHT R 10.55)\cr
189
\qquad (QUAD D 18)\cr
192
\qquad (LABEL C f)\cr
193
\qquad (LIG C f O 200)\cr
195
\qquad (LABEL O 200)\cr
196
\qquad (LIG C i O 201)\cr
197
\qquad (KRN O 51 R 1.5)\cr
198
\qquad (/LIG C ? C f)\cr
202
\qquad (CHARWD D 6)\cr
203
\qquad (CHARHT R 13.5)\cr
204
\qquad (CHARIC R 1.5)\cr
206
This example says that the font whose metric information is being described
207
belongs to the hypothetical
208
\.{NOVA} family; its face code is medium italic extended;
209
and the characters appear in ASCII code positions. The design size is 10 points,
210
and all other sizes in this \.{PL} file are given in units such that 18 units
211
equals the design size. The font is slanted with a slope of $-.25$ (hence the
212
letters actually slant backward---perhaps that is why the family name is
213
\.{NOVA}). The normal space between words is 6 units (i.e., one third of
214
the 18-unit design size), with glue that shrinks by 2 units or stretches by 3.
215
The letters for which accents don't need to be raised or lowered are 10.55
216
units high, and one em equals 18 units.
218
The example ligature table is a bit trickier. It specifies that the
219
letter \.f followed by another \.f is changed to code @'200, while
220
code @'200 followed by \.i is changed to @'201; presumably codes @'200
221
and @'201 represent the ligatures `ff' and `ffi'. Moreover, in both cases
222
\.f and @'200, if the following character is the code @'51 (which is a
223
right parenthesis), an additional 1.5 units of space should be inserted
224
before the @'51. (The `\.{SKIP}~\.D~\.1' skips over one \.{LIG} or
225
\.{KRN} command, which in this case is the second \.{LIG}; in this way
226
two different ligature/kern programs can come together.)
227
Finally, if either \.f or @'200 is followed by a question mark,
228
the question mark is replaced by \.f and the ligature program is
229
started over. (Thus, the character pair `\.{f?}' would actually become
230
the ligature `ff', and `\.{ff?}' or `\.{f?f}' would become `fff'. To
231
avoid this restart procedure, the \.{/LIG} command could be replaced
232
by \.{/LIG>}; then `\.{f?} would become `f\kern0ptf' and `\.{f?f}'
233
would become `f\kern0ptff'.)
235
Character \.f itself is 6 units wide and 13.5 units tall, in this example.
236
Its depth is zero (since \.{CHARDP} is not given), and its italic correction
239
@ The example above illustrates most of the features found in \.{PL} files.
240
Note that some property names, like \.{FAMILY} or \.{COMMENT}, take a
241
string as their value; this string continues until the first unmatched
242
right parenthesis. But most property names, like \.{DESIGNSIZE} and \.{SLANT}
243
and \.{LABEL}, take a number as their value. This number can be expressed in
244
a variety of ways, indicated by a prefixed code; \.D stands for decimal,
245
\.H for hexadecimal, \.O for octal, \.R for real, \.C for character, and
246
\.F for ``face.'' Other property names, like \.{LIG}, take two numbers as
247
their value. And still other names, like \.{FONTDIMEN} and \.{LIGTABLE} and
248
\.{CHARACTER}, have more complicated values that involve property lists.
250
A property name is supposed to be used only in an appropriate property
251
list. For example, \.{CHARWD} shouldn't occur on the outer level or
252
within \.{FONTDIMEN}.
254
The individual property-and-value pairs in a property list can appear in
255
any order. For instance, `\.{SHRINK}' precedes `\.{STRETCH}' in the above
256
example, although the \.{TFM} file always puts the stretch parameter first.
257
One could even give the information about characters like `\.f' before
258
specifying the number of units in the design size, or before specifying the
259
ligature and kerning table. However, the \.{LIGTABLE} itself is an exception
260
to this rule; the individual elements of the \.{LIGTABLE} property list
261
can be reordered only to a certain extent without changing the meaning
264
If property-and-value pairs are omitted, a default value is used. For example,
265
we have already noted that the default for \.{CHARDP} is zero. The default
266
for {\sl every\/} numeric value is, in fact, zero, unless otherwise stated
269
If the same property name is used more than once, \.{VPtoVF} will not notice
270
the discrepancy; it simply uses the final value given. Once again, however, the
271
\.{LIGTABLE} is an exception to this rule; \.{VPtoVF} will complain if there
272
is more than one label for some character. And of course many of the
273
entries in the \.{LIGTABLE} property list have the same property name.
275
@ A \.{VPL} file also includes information about how to create each character,
276
by typesetting characters from other fonts and/or by drawing lines, etc.
277
Such information is the value of the `\.{MAP}' property, which can be
278
illustrated as follows:
279
$$\vbox{\halign{\.{#}\hfil\cr
280
(MAPFONT D 0 (FONTNAME Times-Roman))\cr
281
(MAPFONT D 1 (FONTNAME Symbol))\cr
282
(MAPFONT D 2 (FONTNAME cmr10)(FONTAT D 20))\cr
283
(CHARACTER O 0 (MAP (SELECTFONT D 1)(SETCHAR C G)))\cr
284
(CHARACTER O 76 (MAP (SETCHAR O 277)))\cr
285
(CHARACTER D 197 (MAP\cr
286
\qquad(PUSH)(SETCHAR C A)(POP)\cr
287
\qquad(MOVEUP R 0.937)(MOVERIGHT R 1.5)(SETCHAR O 312)))\cr
288
(CHARACTER O 200 (MAP (MOVEDOWN R 2.1)(SETRULE R 1 R 8)))\cr
289
(CHARACTER O 201 (MAP\cr
290
\qquad (SPECIAL ps: /SaveGray currentgray def .5 setgray)\cr
291
\qquad (SELECTFONT D 2)(SETCHAR C A)\cr
292
\qquad (SPECIAL ps: SaveGray setgray)))\cr
294
(These specifications appear in addition to the conventional \.{PL}
295
information. The \.{MAP} attribute can be mixed in with other attributes
296
like \.{CHARWD} or it can be given separately.)
298
In this example, the virtual font is composed of characters that can be
299
fabricated from three actual fonts, `\.{Times-Roman}',
300
`\.{Symbol}', and `\.{cmr10} \.{at} \.{20\\u}' (where \.{\\u}
301
is the unit size in this \.{VPL} file). Character |@'0| is typeset as
302
a `G' from the symbol font. Character |@'76| is typeset as character |@'277|
303
from the ordinary Times font. (If no other font is selected, font
304
number~0 is the default. If no \.{MAP} attribute is given, the default map
305
is a character of the same number in the default font.)
307
Character 197 (decimal) is more interesting: First an A is typeset (in the
308
default font Times), and this is enclosed by \.{PUSH} and \.{POP} so that
309
the original position is restored. Then the accent character |@'312| is
310
typeset, after moving up .937 units and right 1.5 units.
312
To typeset character |@'200| in this virtual font, we move down 2.1 units,
313
then typeset a rule that is 1 unit high and 8 units wide.
315
Finally, to typeset character |@'201|, we do something that requires a
316
special ability to interpret PostScript commands; this example
317
sets the PostScript ``color'' to 50\char`\%\ gray and typesets an `A'
318
from \.{cmr10} in that color.
320
In general, the \.{MAP} attribute of a virtual character can be any sequence
321
of typesetting commands that might appear in a page of a \.{DVI} file.
322
A single character might map into an entire page.
324
@ But instead of relying on a hypothetical example, let's consider a complete
325
grammar for \.{VPL} files, beginning with the (unchanged) grammatical rules
326
for \.{PL} files. At the outer level, the following property names
327
are valid in any \.{PL} file:
329
\yskip\hang\.{CHECKSUM} (four-byte value). The value, which should be a
330
nonnegative integer less than $2^{32}$, is used to identify a particular
331
version of a font; it should match the check sum value stored with the font
332
itself. An explicit check sum of zero is used to bypass
333
check sum testing. If no checksum is specified in the \.{VPL} file,
334
\.{VPtoVF} will compute the checksum that \MF\ would compute from the
337
\yskip\hang\.{DESIGNSIZE} (numeric value, default is 10). The value, which
338
should be a real number in the range |1.0<=x<2048|, represents the default
339
amount by which all quantities will be scaled if the font is not loaded
340
with an `\.{at}' specification. For example, if one says
341
`\.{\\font\\A=cmr10 at 15pt}' in \TeX\ language, the design size in the \.{TFM}
342
file is ignored and effectively replaced by 15 points; but if one simply
343
says `\.{\\font\\A=cmr10}' the stated design size is used. This quantity is
344
always in units of printer's points.
346
\yskip\hang\.{DESIGNUNITS} (numeric value, default is 1). The value
347
should be a positive real number; it says how many units equals the design
348
size (or the eventual `\.{at}' size, if the font is being scaled). For
349
example, suppose you have a font that has been digitized with 600 pixels per
350
em, and the design size is one em; then you could say `\.{(DESIGNUNITS R 600)}'
351
if you wanted to give all of your measurements in units of pixels.
353
\yskip\hang\.{CODINGSCHEME} (string value, default is `\.{UNSPECIFIED}').
354
The string should not contain parentheses, and its length must be less than 40.
355
It identifies the correspondence between the numeric codes and font characters.
356
(\TeX\ ignores this information, but other software programs make use of it.)
358
\yskip\hang\.{FAMILY} (string value, default is `\.{UNSPECIFIED}').
359
The string should not contain parentheses, and its length must be less than 20.
360
It identifies the name of the family to which this font belongs, e.g.,
361
`\.{HELVETICA}'. (\TeX\ ignores this information; but it is needed, for
362
example, when converting \.{DVI} files to \.{PRESS} files for Xerox
365
\yskip\hang\.{FACE} (one-byte value). This number, which must lie between
366
0 and 255 inclusive, is a subsidiary ident\-ifi\-ca\-tion of the font within its
367
family. For example, bold italic condensed fonts might have the same family name
368
as light roman extended fonts, differing only in their face byte. (\TeX\
369
ignores this information; but it is needed, for example, when converting
370
\.{DVI} files to \.{PRESS} files for Xerox equipment.)
372
\yskip\hang\.{SEVENBITSAFEFLAG} (string value, default is `\.{FALSE}'). The
373
value should start with either `\.T' (true) or `\.F' (false). If true, character
374
codes less than 128 cannot lead to codes of 128 or more via ligatures or
375
charlists or extensible characters. (\TeX82 ignores this flag, but older
376
versions of \TeX\ would only accept \.{TFM} files that were seven-bit safe.)
377
\.{VPtoVF} computes the correct value of this flag and gives an error message
378
only if a claimed ``true'' value is incorrect.
380
\yskip\hang\.{HEADER} (a one-byte value followed by a four-byte value).
381
The one-byte value should be between 18 and a maximum limit that can be
382
raised or lowered depending on the compile-time setting of |max_header_bytes|.
383
The four-byte value goes into the header word whose index is the one-byte
384
value; for example, to set |header[18]:=1|, one may write
385
`\.{(HEADER D 18 O 1)}'. This notation is used for header information that
386
is presently unnamed. (\TeX\ ignores it.)
388
\yskip\hang\.{FONTDIMEN} (property list value). See below for the names
389
allowed in this property list.
391
\yskip\hang\.{LIGTABLE} (property list value). See below for the rules
392
about this special kind of property list.
394
\yskip\hang\.{BOUNDARYCHAR} (integer value). If this character appears in
395
a \.{LIGTABLE} command, it matches ``end of word'' as well as itself.
396
If no boundary character is given and no \.{LABEL} \.{BOUNDARYCHAR} occurs
397
within \.{LIGTABLE}, word boundaries will not affect ligatures or kerning.
399
\yskip\hang\.{CHARACTER}. The value is an integer followed by
400
a property list. The integer represents the number of a character that is
401
present in the font; the property list of a character is defined below.
402
The default is an empty property list.
404
@ Numeric property list values can be given in various forms identified by
407
\yskip\hang\.C denotes an ASCII character, which should be a standard visible
408
character that is not a parenthesis. The numeric value will therefore be
409
between @'41 and @'176 but not @'50 or @'51.
411
\yskip\hang\.D denotes an unsigned decimal integer, which must be
412
less than $2^{32}$, i.e., at most `\.{D 4294967295}'.
414
\yskip\hang\.F denotes a three-letter Xerox face code; the admissible codes
415
are \.{MRR}, \.{MIR}, \.{BRR}, \.{BIR}, \.{LRR}, \.{LIR}, \.{MRC}, \.{MIC},
416
\.{BRC}, \.{BIC}, \.{LRC}, \.{LIC}, \.{MRE}, \.{MIE}, \.{BRE}, \.{BIE},
417
\.{LRE}, and \.{LIE}, denoting the integers 0 to 17, respectively.
419
\yskip\hang\.O denotes an unsigned octal integer, which must be less than
420
$2^{32}$, i.e., at most `\.{O 37777777777}'.
422
\yskip\hang\.H denotes an unsigned hexadecimal integer, which must be less than
423
$2^{32}$, i.e., at most `\.{H FFFFFFFF}'.
425
\yskip\hang\.R denotes a real number in decimal notation, optionally preceded
426
by a `\.+' or `\.-' sign, and optionally including a decimal point. The
427
absolute value must be less than 2048.
429
@ The property names allowed in a \.{FONTDIMEN} property list correspond to
430
various \TeX\ parameters, each of which has a (real) numeric value. All
431
of the parameters except \.{SLANT} are in design units. The admissible
432
names are \.{SLANT}, \.{SPACE}, \.{STRETCH}, \.{SHRINK}, \.{XHEIGHT},
433
\.{QUAD}, \.{EXTRASPACE}, \.{NUM1}, \.{NUM2}, \.{NUM3}, \.{DENOM1},
434
\.{DENOM2}, \.{SUP1}, \.{SUP2}, \.{SUP3}, \.{SUB1}, \.{SUB2}, \.{SUPDROP},
435
\.{SUBDROP}, \.{DELIM1}, \.{DELIM2}, and \.{AXISHEIGHT}, for parameters
436
1~to~22. The alternate names \.{DEFAULTRULETHICKNESS},
437
\.{BIGOPSPACING1}, \.{BIGOPSPACING2}, \.{BIGOPSPACING3},
438
\.{BIGOPSPACING4}, and \.{BIGOPSPACING5}, may also be used for parameters
441
The notation `\.{PARAMETER} $n$' provides another way to specify the
442
$n$th parameter; for example, `\.{(PARAMETER} \.{D 1 R -.25)}' is another way
443
to specify that the \.{SLANT} is $-0.25$. The value of $n$ must be positive
444
and less than |max_param_words|.
446
@ The elements of a \.{CHARACTER} property list can be of six different types.
448
\yskip\hang\.{CHARWD} (real value) denotes the character's width in
451
\yskip\hang\.{CHARHT} (real value) denotes the character's height in
454
\yskip\hang\.{CHARDP} (real value) denotes the character's depth in
457
\yskip\hang\.{CHARIC} (real value) denotes the character's italic correction in
460
\yskip\hang\.{NEXTLARGER} (integer value), specifies the character that
461
follows the present one in a ``charlist.'' The value must be the number of a
462
character in the font, and there must be no infinite cycles of supposedly
463
larger and larger characters.
465
\yskip\hang\.{VARCHAR} (property list value), specifies an extensible character.
466
This option and \.{NEXTLARGER} are mutually exclusive; i.e., they cannot
467
both be used within the same \.{CHARACTER} list.
470
The elements of a \.{VARCHAR} property list are either \.{TOP}, \.{MID},
471
\.{BOT} or \.{REP}; the values are integers, which must be zero or the number
472
of a character in the font. A zero value for \.{TOP}, \.{MID}, or \.{BOT} means
473
that the corresponding piece of the extensible character is absent. A nonzero
474
value, or a \.{REP} value of zero, denotes the character code used to make
475
up the top, middle, bottom, or replicated piece of an extensible character.
477
@ A \.{LIGTABLE} property list contains elements of four kinds, specifying a
478
program in a simple command language that \TeX\ uses for ligatures and kerns.
479
If several \.{LIGTABLE} lists appear, they are effectively concatenated into
482
\yskip\hang\.{LABEL} (integer value) means that the program for the
483
stated character value starts here. The integer must be the number of a
484
character in the font; its \.{CHARACTER} property list must not have a
485
\.{NEXTLARGER} or \.{VARCHAR} field. At least one \.{LIG} or \.{KRN} step
488
\yskip\hang\.{LABEL} \.{BOUNDARYCHAR} means that the program for
489
beginning-of-word ligatures starts here.
491
\yskip\hang\.{LIG} (two integer values). The instruction `\.{(LIG} $c$ $r$\.)'
492
means, ``If the next character is $c$, then insert character~$r$ and
493
possibly delete the current character and/or~$c$;
494
otherwise go on to the next instruction.''
495
Characters $r$ and $c$ must be present in the font. \.{LIG} may be immediately
496
preceded or followed by a slash, and then immediately followed by \.>
497
characters not exceeding the number of slashes. Thus there are eight
499
$$\hbox to .8\hsize{\.{LIG}\hfil\.{/LIG}\hfil\.{/LIG>}\hfil
500
\.{LIG/}\hfil\.{LIG/>}\hfil\.{/LIG/}\hfil\.{/LIG/>}\hfil\.{/LIG/>>}}$$
501
The slashes specify retention of the left or right original character; the
502
\.> signs specify passing over the result without further ligature processing.
504
\yskip\hang\.{KRN} (an integer value and a real value). The instruction
505
`\.{(KRN} $c$ $r$\.)' means, ``If the next character is $c$, then insert
506
a blank space of width $r$ between the current character character and $c$;
507
otherwise go on to the next intruction.'' The value of $r$, which is in
508
units of the design size, is often negative. Character code $c$ must exist
511
\yskip\hang\.{STOP} (no value). This instruction ends a ligature/kern program.
512
It must follow either a \.{LIG} or \.{KRN} instruction, not a \.{LABEL}
513
or \.{STOP} or \.{SKIP}.
515
\yskip\hang\.{SKIP} (value in the range |0..127|). This instruction specifies
516
continuation of a ligature/kern program after the specified number of \.{LIG}
517
or \.{KRN} has been skipped over. The number of subsequent \.{LIG} and \.{KRN}
518
instructions must therefore exceed this specified amount.
520
@ In addition to all these possibilities, the property name \.{COMMENT} is
521
allowed in any property list. Such comments are ignored.
523
@ So that is what \.{PL} files hold. In a \.{VPL} file additional
524
properties are recognized; two of these are valid on the outermost level:
526
\yskip\hang\.{VTITLE} (string value, default is empty). The value will be
527
reproduced at the beginning of the \.{VF} file (and printed on the terminal
528
by \.{VFtoVP} when it examines that file).
530
\yskip\hang\.{MAPFONT}. The value is a nonnegative integer followed by
531
a property list. The integer represents an identifying number for fonts
532
used in \.{MAP} attributes. The property list, which identifies the font and
533
relative size, is defined below.
536
And one additional ``virtual property'' is valid within a \.{CHARACTER}:
538
\yskip\hang\.{MAP}. The value is a property list consisting of typesetting
539
commands. Default is the single command \.{SETCHAR}~$c$, where $c$ is
540
the current character number.
542
@ The elements of a \.{MAPFONT} property list can be of the following types.
544
\yskip\hang\.{FONTNAME} (string value, default is \.{NULL}).
545
This is the font's identifying name.
547
\yskip\hang\.{FONTAREA} (string value, default is empty). If the font appears
548
in a nonstandard directory, according to local conventions, the directory
549
name is given here. (This is system dependent, just as in \.{DVI} files.)
551
\yskip\hang\.{FONTCHECKSUM} (four-byte value, default is zero). This value,
552
which should be a nonnegative integer less than $2^{32}$, can be used to
553
check that the font being referred to matches the intended font. If nonzero,
554
it should equal the \.{CHECKSUM} parameter in that font.
556
\yskip\hang\.{FONTAT} (numeric value, default is the \.{DESIGNUNITS} of the
557
present virtual font). This value is relative to the design units of
558
the present virtual font, hence it will be scaled when the virtual
559
font is magnified or reduced. It represents the value that will
560
effectively replace the design size of the font being referred to,
561
so that all characters will be scaled appropriately.
563
\yskip\hang\.{FONTDSIZE} (numeric value, default is 10). This value is
564
absolute, in units of printer's points. It should equal the \.{DESIGNSIZE}
565
parameter in the font being referred to.
569
string values contain parentheses, the parentheses must be balanced. Leading
570
blanks are removed from the strings, but trailing blanks are not.
572
@ Finally, the elements of a \.{MAP} property list are an ordered sequence
573
of typesetting commands chosen from among the following:
575
\yskip\hang\.{SELECTFONT} (four-byte integer value). The value must be the
576
number of a previously defined \.{MAPFONT}. This font (or more precisely, the
577
final font that is mapped to that code number, if two \.{MAPFONT} properties
578
happen to specify the same code) will be used in subsequent \.{SETCHAR}
579
instructions until overridden by another \.{SELECTFONT}. The first-specified
580
\.{MAPFONT} is implicitly selected before the first \.{SELECTFONT} in every
583
\yskip\hang\.{SETCHAR} (integer value). There must be a character of
584
this number in the currently selected font. (\.{VPtoVF} doesn't check that
585
the character is valid, but \.{VFtoVP} does.) That character is typeset at the
586
current position, and the typesetter moves right by the \.{CHARWD} in
587
that character's \.{TFM} file.
589
\yskip\hang\.{SETRULE} (two real values). The first value specifies height,
590
the second specifies width, in design units. If both height and width are
591
positive, a rule is typeset at the current position. Then the typesetter
592
moves right, by the specified width.
594
\yskip\hang\.{MOVERIGHT}, \.{MOVELEFT}, \.{MOVEUP}, \.{MOVEDOWN} (real
595
value). The typesetter moves its current position
596
by the number of design units specified.
598
\yskip\hang\.{PUSH} The current typesetter position is remembered, to
599
be restored on a subsequent \.{POP}.
601
\yskip\hang\.{POP} The current typesetter position is reset to where it
602
was on the most recent unmatched \.{PUSH}. The \.{PUSH} and \.{POP}
603
commands in any \.{MAP} must be properly nested like balanced parentheses.
605
\yskip\hang\.{SPECIAL} (string value). The subsequent characters, starting
606
with the first nonblank and ending just before the first `\.)' that has no
607
matching `\.(', are interpreted according to local conventions with the
608
same system-dependent meaning as a `special' (\\{xxx}) command
611
\yskip\hang\.{SPECIALHEX} (hexadecimal string value). The subsequent
612
nonblank characters before the next `\.)' must consist entirely of
613
hexadecimal digits, and they must contain an even number of such digits.
614
Each pair of hex digits specifies a byte, and this string of bytes is
615
treated just as the value of a \.{SPECIAL}. (This convention permits
616
arbitrary byte strings to be represented in an ordinary text file.)
618
@ Virtual font mapping is a recursive process, like macro expansion.
619
Thus, a \.{MAPFONT} might
620
specify another virtual font, whose characters are themselves mapped to
621
other fonts. As an example of this possibility, consider the
622
following curious file called \.{recurse.vpl}, which defines a
623
virtual font that is self-contained and self-referential:
624
$$\vbox{\halign{\.{#}\cr
625
(VTITLE Example of recursion)\cr
626
(MAPFONT D 0 (FONTNAME recurse)(FONTAT D 2))\cr
627
(CHARACTER C A (CHARWD D 1)(CHARHT D 1)(MAP (SETRULE D 1 D 1)))\cr
628
(CHARACTER C B (CHARWD D 2)(CHARHT D 2)(MAP (SETCHAR C A)))\cr
629
(CHARACTER C C (CHARWD D 4)(CHARHT D 4)(MAP (SETCHAR C B)))\cr
631
The design size is 10 points (the default), hence the character \.A
632
in font \.{recurse} is a $10\times10$ point black square. Character \.B
633
is typeset as character \.A in \.{recurse} {scaled} {2000}, hence it
634
is a $20\times20$ point black square. And character \.C is typeset as
635
character \.{B} in \.{recurse} {scaled} {2000}, hence its size is
638
Users are responsible for making sure that infinite recursion doesn't happen.
640
@ So that is what \.{VPL} files hold. From these rules,
641
you can guess (correctly) that \.{VPtoVF} operates in four main stages.
642
First it assigns the default values to all properties; then it scans
643
through the \.{VPL} file, changing property values as new ones are seen; then
644
it checks the information and corrects any problems; and finally it outputs
645
the \.{VF} and \.{TFM} files.
647
@ The next question is, ``What are \.{VF} and
648
\.{TFM} files?'' A complete answer to that question appears in the
649
documentation of the companion programs, \.{VFtoVP} and
650
\.{TFtoPL}, so the details will not
651
be repeated here. Suffice it to say that a \.{VF} or
652
\.{TFM} file stores all of the
653
relevant font information in a sequence of 8-bit bytes. The number of
654
bytes is always a multiple of 4, so we could regard the files
655
as sequences of 32-bit words; but \TeX\ uses the byte interpretation,
656
and so does \.{VPtoVF}. Note that the bytes are considered to be unsigned
660
@!vf_file:packed file of 0..255;
661
@!tfm_file:packed file of 0..255;
663
@ On some systems you may have to do something special to write a
664
packed file of bytes. For example, the following code didn't work
665
when it was first tried at Stanford, because packed files have to be
666
opened with a special switch setting on the \PASCAL\ that was used.
667
@^system dependencies@>
670
rewrite(vf_file); rewrite(tfm_file);
672
@* Basic input routines.
673
For the purposes of this program, a |byte| is an unsigned 16-bit quantity,
674
and an |ASCII_code| is an integer between @'40 and @'177. Such ASCII codes
675
correspond to one-character constants like \.{"A"} in \.{WEB} language.
678
@!byte=0..65535; {unsigned 16-bit quantity}
679
@!ASCII_code=@'40..@'177; {standard ASCII code numbers}
681
@ One of the things \.{VPtoVF} has to do is convert characters of strings
682
to ASCII form, since that is the code used for the family name and the
683
coding scheme in a \.{TFM} file. An array |xord| is used to do the
684
conversion from |char|; the method below should work with little or no change
685
on most \PASCAL\ systems.
686
@^system dependencies@>
688
@d first_ord=0 {ordinal number of the smallest element of |char|}
689
@d last_ord=127 {ordinal number of the largest element of |char|}
692
@!xord:array[char] of ASCII_code; {conversion table}
694
@ @<Local variables for init...@>=
695
@!k:integer; {all-purpose initialization index}
697
@ Characters that should not appear in \.{VPL} files (except in comments)
698
are mapped into @'177.
700
@d invalid_code=@'177 {code deserving an error message}
703
for k:=first_ord to last_ord do xord[chr(k)]:=invalid_code;
704
xord[' ']:=" "; xord['!']:="!"; xord['"']:=""""; xord['#']:="#";
705
xord['$']:="$"; xord['%']:="%"; xord['&']:="&"; xord['''']:="'";
706
xord['(']:="("; xord[')']:=")"; xord['*']:="*"; xord['+']:="+"; xord[',']:=",";
707
xord['-']:="-"; xord['.']:="."; xord['/']:="/"; xord['0']:="0"; xord['1']:="1";
708
xord['2']:="2"; xord['3']:="3"; xord['4']:="4"; xord['5']:="5"; xord['6']:="6";
709
xord['7']:="7"; xord['8']:="8"; xord['9']:="9"; xord[':']:=":"; xord[';']:=";";
710
xord['<']:="<"; xord['=']:="="; xord['>']:=">"; xord['?']:="?";
711
xord['@@']:="@@"; xord['A']:="A"; xord['B']:="B"; xord['C']:="C";
712
xord['D']:="D"; xord['E']:="E"; xord['F']:="F"; xord['G']:="G"; xord['H']:="H";
713
xord['I']:="I"; xord['J']:="J"; xord['K']:="K"; xord['L']:="L"; xord['M']:="M";
714
xord['N']:="N"; xord['O']:="O"; xord['P']:="P"; xord['Q']:="Q"; xord['R']:="R";
715
xord['S']:="S"; xord['T']:="T"; xord['U']:="U"; xord['V']:="V"; xord['W']:="W";
716
xord['X']:="X"; xord['Y']:="Y"; xord['Z']:="Z"; xord['[']:="["; xord['\']:="\";
717
xord[']']:="]"; xord['^']:="^"; xord['_']:="_"; xord['`']:="`"; xord['a']:="a";
718
xord['b']:="b"; xord['c']:="c"; xord['d']:="d"; xord['e']:="e"; xord['f']:="f";
719
xord['g']:="g"; xord['h']:="h"; xord['i']:="i"; xord['j']:="j"; xord['k']:="k";
720
xord['l']:="l"; xord['m']:="m"; xord['n']:="n"; xord['o']:="o"; xord['p']:="p";
721
xord['q']:="q"; xord['r']:="r"; xord['s']:="s"; xord['t']:="t"; xord['u']:="u";
722
xord['v']:="v"; xord['w']:="w"; xord['x']:="x"; xord['y']:="y"; xord['z']:="z";
723
xord['{']:="{"; xord['|']:="|"; xord['}']:="}"; xord['~']:="~";
725
@ In order to help catch errors of badly nested parentheses, \.{VPtoVF}
726
assumes that the user will begin each line with a number of blank spaces equal
727
to some constant times the number of open parentheses at the beginning of
728
that line. However, the program doesn't know in advance what the constant
729
is, nor does it want to print an error message on every line for a user
730
who has followed no consistent pattern of indentation.
732
Therefore the following strategy is adopted: If the user has been consistent
733
with indentation for ten or more lines, an indentation error will be
734
reported. The constant of indentation is reset on every line that should
735
have nonzero indentation.
738
@!line:integer; {the number of the current line}
739
@!good_indent:integer; {the number of lines since the last bad indentation}
740
@!indent: integer; {the number of spaces per open parenthesis, zero if unknown}
741
@!level: integer; {the current number of open parentheses}
744
line:=0; good_indent:=0; indent:=0; level:=0;
746
@ The input need not really be broken into lines of any maximum length, and
747
we could read it character by character without any buffering. But we shall
748
place it into a small buffer so that offending lines can be displayed in error
752
@!left_ln,@!right_ln:boolean; {are the left and right ends of the buffer
753
at end-of-line marks?}
754
@!limit:0..buf_size; {position of the last character present in the buffer}
755
@!loc:0..buf_size; {position of the last character read in the buffer}
756
@!buffer:array[1..buf_size] of char;
757
@!input_has_ended:boolean; {there is no more input to read}
760
limit:=0; loc:=0; left_ln:=true; right_ln:=true; input_has_ended:=false;
762
@ Just before each \.{CHARACTER} property list is evaluated, the character
763
code is printed in octal notation. Up to eight such codes appear on a line;
764
so we have a variable to keep track of how many are currently there.
767
@!chars_on_line:0..8; {the number of characters printed on the current line}
772
@ The following routine prints an error message and an indication of
773
where the error was detected. The error message should not include any
774
final punctuation, since this procedure supplies its own.
776
@d err_print(#)==begin if chars_on_line>0 then print_ln(' ');
777
print(#); show_error_context;
780
@p procedure show_error_context; {prints the current scanner location}
781
var k:0..buf_size; {an index into |buffer|}
782
begin print_ln(' (line ',line:1,').');
783
if not left_ln then print('...');
784
for k:=1 to loc do print(buffer[k]); {print the characters already scanned}
786
if not left_ln then print(' ');
787
for k:=1 to loc do print(' '); {space out the second line}
788
for k:=loc+1 to limit do print(buffer[k]); {print the characters yet unseen}
789
if right_ln then print_ln(' ')@+else print_ln('...');
793
@ Here is a procedure that does the right thing when we are done
794
reading the present contents of the buffer. It keeps |buffer[buf_size]|
795
empty, in order to avoid range errors on certain \PASCAL\ compilers.
797
An infinite sequence of right parentheses is placed at the end of the
798
file, so that the program is sure to get out of whatever level of nesting
801
On some systems it is desirable to modify this code so that tab marks
802
in the buffer are replaced by blank spaces. (Simply setting
803
|xord[chr(@'11)]:=" "| would not work; for example, two-line
804
error messages would not come out properly aligned.)
805
@^system dependencies@>
807
@p procedure fill_buffer;
808
begin left_ln:=right_ln; limit:=0; loc:=0;
809
if left_ln then begin
810
if line>0 then read_ln(vpl_file);
813
if eof(vpl_file) then begin
814
limit:=1; buffer[1]:=')'; right_ln:=false; input_has_ended:=true;
817
while (limit<buf_size-1)and(not eoln(vpl_file)) do begin
818
incr(limit); read(vpl_file,buffer[limit]);
820
buffer[limit+1]:=' '; right_ln:=eoln(vpl_file);
821
if left_ln then @<Set |loc| to the number of leading blanks in
822
the buffer, and check the indentation@>;
826
@ The interesting part about |fill_buffer| is the part that learns what
827
indentation conventions the user is following, if any.
829
@d bad_indent(#)==begin if good_indent>=10 then err_print(#);
830
good_indent:=0; indent:=0;
834
begin while (loc<limit)and(buffer[loc+1]=' ') do incr(loc);
835
if loc<limit then begin
837
if loc=0 then incr(good_indent)
838
else bad_indent('Warning: Indented line occurred at level zero')
839
@.Warning: Indented line...@>
840
else if indent=0 then
841
if loc mod level=0 then begin
842
indent:=loc div level; good_indent:=1;
845
else if indent*level=loc then incr(good_indent)
846
else bad_indent('Warning: Inconsistent indentation; ',
847
@.Warning: Inconsistent indentation...@>
848
'you are at parenthesis level ',level:1);
852
@* Basic scanning routines.
853
The global variable |cur_char| holds the ASCII code corresponding to the
854
character most recently read from the input buffer, or to a character that
855
has been substituted for the real one.
858
@!cur_char:ASCII_code; {we have just read this}
860
@ Here is a procedure that sets |cur_char| to an ASCII code for the
861
next character of input, if that character is a letter or digit or slash
863
it sets |cur_char:=" "|, and the input system will be poised to reread the
864
character that was rejected, whether or not it was a space.
865
Lower case letters are converted to upper case.
867
@p procedure get_keyword_char;
868
begin while (loc=limit)and(not right_ln) do fill_buffer;
869
if loc=limit then cur_char:=" " {end-of-line counts as a delimiter}
871
cur_char:=xord[buffer[loc+1]];
872
if cur_char>="a" then cur_char:=cur_char-@'40;
873
if ((cur_char>="0")and(cur_char<="9")) then incr(loc)
874
else if ((cur_char>="A")and(cur_char<="Z")) then incr(loc)
875
else if cur_char="/" then incr(loc)
876
else if cur_char=">" then incr(loc)
881
@ The following procedure sets |cur_char| to the next character code,
882
and converts lower case to upper case. If the character is a left or
883
right parenthesis, it will not be ``digested''; the character will
884
be read again and again, until the calling routine does something
885
like `|incr(loc)|' to get past it. Such special treatment of parentheses
886
insures that the structural information they contain won't be lost in
887
the midst of other error recovery operations.
889
@d backup==begin if (cur_char>")")or(cur_char<"(") then decr(loc);
890
end {undoes the effect of |get_next|}
892
@p procedure get_next; {sets |cur_char| to next, balks at parentheses}
893
begin while loc=limit do fill_buffer;
894
incr(loc); cur_char:=xord[buffer[loc]];
895
if cur_char>="a" then
896
if cur_char<="z" then cur_char:=cur_char-@'40 {uppercasify}
898
if cur_char=invalid_code then begin
899
err_print('Illegal character in the file');
900
@.Illegal character...@>
904
else if (cur_char<=")")and(cur_char>="(") then decr(loc);
907
@ Here's a procedure that scans a hexadecimal digit or a right parenthesis.
909
@p function get_hex:byte;
910
var @!a:integer; {partial result}
911
begin repeat get_next;
917
if cur_char<"A" then a:=-1 else a:=cur_char-"A"+10;
919
if (a<0)or(a>15) then begin
920
err_print('Illegal hexadecimal digit'); get_hex:=0;
921
@.Illegal hexadecimal digit@>
926
@ The next procedure is used to ignore the text of a comment, or to pass over
927
erroneous material. As such, it has the privilege of passing parentheses.
928
It stops after the first right parenthesis that drops the level below
929
the level in force when the procedure was called.
931
@p procedure skip_to_end_of_item;
932
var l:integer; {initial value of |level|}
934
while level>=l do begin
935
while loc=limit do fill_buffer;
937
if buffer[loc]=')' then decr(level)
938
else if buffer[loc]='(' then incr(level);
940
if input_has_ended then err_print('File ended unexpectedly: No closing ")"');
941
@.File ended unexpectedly...@>
942
cur_char:=" "; {now the right parenthesis has been read and digested}
945
@ A similar procedure copies the bytes remaining in an item. The copied bytes
946
go into an array |vf| that we'll declare later. Leading blanks are ignored.
950
if vf_ptr=vf_size then err_print('I''m out of memory---increase my vfsize!')
951
@.I'm out of memory...@>
955
@p procedure copy_to_end_of_item;
957
var l:integer; {initial value of |level|}
958
@!nonblank_found:boolean; {have we seen a nonblank character yet?}
959
begin l:=level; nonblank_found:=false;
961
while loc=limit do fill_buffer;
962
if buffer[loc+1]=')' then
963
if level=l then goto 30@+else decr(level);
965
if buffer[loc]='(' then incr(level);
966
if buffer[loc]<>' ' then nonblank_found:=true;
967
if nonblank_found then
968
if xord[buffer[loc]]=invalid_code then begin
969
err_print('Illegal character in the file');
970
@.Illegal character...@>
973
else vf_store(xord[buffer[loc]]);
977
@ Sometimes we merely want to skip past characters in the input until we
978
reach a left or a right parenthesis. For example, we do this whenever we
979
have finished scanning a property value and we hope that a right parenthesis
980
is next (except for possible blank spaces).
982
@d skip_to_paren==repeat get_next@;@+ until (cur_char="(")or(cur_char=")")
983
@d skip_error(#)==begin err_print(#); skip_to_paren;
984
end {this gets to the right parenthesis if something goes wrong}
985
@d flush_error(#)==begin err_print(#); skip_to_end_of_item;
986
end {this gets past the right parenthesis if something goes wrong}
988
@ After a property value has been scanned, we want to move just past the
989
right parenthesis that should come next in the input (except for possible
992
@p procedure finish_the_property; {do this when the value has been scanned}
993
begin while cur_char=" " do get_next;
994
if cur_char<>")" then err_print('Junk after property value will be ignored');
995
@.Junk after property value...@>
999
@* Scanning property names.
1000
We have to figure out the meaning of names that appear in the \.{VPL} file,
1001
by looking them up in a dictionary of known keywords. Keyword number $n$
1002
appears in locations |start[n]| through |start[n+1]-1| of an array called
1005
@d max_name_index=300 {upper bound on the number of keywords}
1006
@d max_letters=3000 {upper bound on the total length of all keywords}
1009
@!start:array[1..max_name_index] of 0..max_letters;
1010
@!dictionary:array[0..max_letters] of ASCII_code;
1011
@!start_ptr:0..max_name_index; {the first available place in |start|}
1012
@!dict_ptr:0..max_letters; {the first available place in |dictionary|}
1015
start_ptr:=1; start[1]:=0; dict_ptr:=0;
1017
@ When we are looking for a name, we put it into the |cur_name| array.
1018
When we have found it, the corresponding |start| index will go into
1019
the global variable |name_ptr|.
1021
@d longest_name=20 {length of \.{DEFAULTRULETHICKNESS}}
1024
@!cur_name:array[1..longest_name] of ASCII_code; {a name to look up}
1025
@!name_length:0..longest_name; {its length}
1026
@!name_ptr:0..max_name_index; {its ordinal number in the dictionary}
1028
@ A conventional hash table with linear probing (cf.\ Algorithm 6.4L
1029
in {\sl The Art of Computer Pro\-gram\-ming\/}) is used for the dictionary
1030
operations. If |nhash[h]=0|, the table position is empty, otherwise |nhash[h]|
1031
points into the |start| array.
1033
@d hash_prime=307 {size of the hash table}
1036
@!nhash:array[0..hash_prime-1] of 0..max_name_index;
1037
@!cur_hash:0..hash_prime-1; {current position in the hash table}
1040
@!h:0..hash_prime-1; {runs through the hash table}
1043
for h:=0 to hash_prime-1 do nhash[h]:=0;
1045
@ Since there is no chance of the hash table overflowing, the procedure
1046
is very simple. After |lookup| has done its work, |cur_hash| will point
1047
to the place where the given name was found, or where it should be inserted.
1049
@p procedure lookup; {finds |cur_name| in the dictionary}
1050
var k:0..longest_name; {index into |cur_name|}
1051
@!j:0..max_letters; {index into |dictionary|}
1052
@!not_found:boolean; {clumsy thing necessary to avoid |goto| statement}
1053
@!cur_hash_reset:boolean;
1054
begin @<Compute the hash code, |cur_hash|, for |cur_name|@>;
1056
cur_hash_reset:=false;
1057
while not_found do begin
1058
if (cur_hash=0) and (cur_hash_reset) then
1061
if cur_hash=0 then begin
1062
cur_hash:=hash_prime-1;
1063
cur_hash_reset:=true
1065
else decr(cur_hash);
1066
if nhash[cur_hash]=0 then not_found:=false
1068
j:=start[nhash[cur_hash]];
1069
if start[nhash[cur_hash]+1]=j+name_length then begin
1071
for k:=1 to name_length do
1072
if dictionary[j+k-1]<>cur_name[k] then not_found:=true;
1077
name_ptr:=nhash[cur_hash];
1080
@ @<Compute the hash...@>=
1081
cur_hash:=cur_name[1];
1082
for k:=2 to name_length do
1083
cur_hash:=(cur_hash+cur_hash+cur_name[k]) mod hash_prime
1085
@ The ``meaning'' of the keyword that begins at |start[k]| in the
1086
dictionary is kept in |equiv[k]|. The numeric |equiv| codes are given
1087
symbolic meanings by the following definitions.
1091
@d design_size_code=2
1092
@d design_units_code=3
1093
@d coding_scheme_code=4
1096
@d seven_bit_safe_flag_code=7
1098
@d font_dimen_code=9
1099
@d lig_table_code=10
1100
@d boundary_char_code=11
1101
@d virtual_title_code=12
1104
@d n_font_dir_code=15
1105
@d character_code=16
1106
@d font_name_code=21
1107
@d font_area_code=22
1108
@d font_checksum_code=23
1110
@d font_dsize_code=25
1111
@d parameter_code=30
1112
@d char_info_code=70
1123
@d prim_top_axis_bis=11
1125
@d prim_bot_axis_bis=13
1128
@d prim_base_slant=16
1130
@d sec_top_axis_bis=18
1132
@d sec_bot_axis_bis=20
1135
@d sec_base_slant=23
1136
@d char_wd_code=char_info_code+width
1137
@d char_ht_code=char_info_code+height
1138
@d char_dp_code=char_info_code+depth
1139
@d char_ic_code=char_info_code+italic
1140
@d sec_width_code=char_info_code+sec_width
1141
@d sec_height_code=char_info_code+sec_height
1142
@d sec_depth_code=char_info_code+sec_depth
1143
@d sec_italic_code=char_info_code+sec_italic
1144
@d accent_code=char_info_code+accent
1145
@d prim_top_axis_code=char_info_code+prim_top_axis
1146
@d prim_top_axis_bis_code=char_info_code+prim_top_axis_bis
1147
@d prim_bot_axis_code=char_info_code+prim_bot_axis
1148
@d prim_bot_axis_bis_code=char_info_code+prim_bot_axis_bis
1149
@d prim_mid_hor_code=char_info_code+prim_mid_hor
1150
@d prim_mid_vert_code=char_info_code+prim_mid_vert
1151
@d prim_base_slant_code=char_info_code+prim_base_slant
1152
@d sec_top_axis_code=char_info_code+sec_top_axis
1153
@d sec_top_axis_bis_code=char_info_code+sec_top_axis_bis
1154
@d sec_bot_axis_code=char_info_code+sec_bot_axis
1155
@d sec_bot_axis_bis_code=char_info_code+sec_bot_axis_bis
1156
@d sec_mid_hor_code=char_info_code+sec_mid_hor
1157
@d sec_mid_vert_code=char_info_code+sec_mid_vert
1158
@d sec_base_slant_code=char_info_code+sec_base_slant
1159
@d next_larger_code=100
1161
@d var_char_code=102
1162
@d select_font_code=110
1163
@d set_char_code=111
1164
@d set_rule_code=112
1165
@d move_right_code=113
1166
@d move_down_code=115
1170
@d special_hex_code=120
1176
@d ofm_level_code=140
1177
@d char_repeat_code=150
1178
@d char_ivalue_code=151
1179
@d char_fvalue_code=152
1180
@d char_mvalue_code=153
1181
@d char_rule_code=154
1182
@d char_glue_code=155
1183
@d char_penalty_code=156
1184
@d font_rule_code=160
1186
@d rule_width_code=162
1187
@d rule_height_code=163
1188
@d rule_depth_code=164
1189
@d font_glue_code=170
1191
@d glue_type_code=172
1192
@d glue_stretch_order_code=173
1193
@d glue_shrink_order_code=174
1194
@d glue_width_code=175
1195
@d glue_stretch_code=176
1196
@d glue_shrink_code=177
1197
@d glue_char_code=178
1198
@d glue_rule_code=179
1199
@d order_unit_code=181
1200
@d order_fi_code=182
1201
@d order_fil_code=183
1202
@d order_fill_code=184
1203
@d order_filll_code=185
1204
@d type_normal_code=186
1205
@d type_aleaders_code=187
1206
@d type_cleaders_code=188
1207
@d type_xleaders_code=189
1208
@d font_penalty_code=190
1210
@d penalty_val_code=192
1211
@d font_mvalue_code=200
1213
@d mvalue_val_code=202
1214
@d font_fvalue_code=210
1216
@d fvalue_val_code=212
1217
@d font_ivalue_code=220
1219
@d ivalue_val_code=222
1223
@d cpenglue_code=234
1235
@!equiv:array[0..max_name_index] of byte;
1236
@!cur_code:byte; {equivalent most recently found in |equiv|}
1238
@ We have to get the keywords into the hash table and into the dictionary in
1239
the first place (sigh). The procedure that does this has the desired
1240
|equiv| code as a parameter. In order to facilitate \.{WEB} macro writing
1241
for the initialization, the keyword being initialized is placed into the
1242
last positions of |cur_name|, instead of the first positions.
1244
@p procedure enter_name(v:byte); {|cur_name| goes into the dictionary}
1245
var k:0..longest_name;
1246
begin for k:=1 to name_length do
1247
cur_name[k]:=cur_name[k+longest_name-name_length];
1248
{now the name has been shifted into the correct position}
1249
lookup; {this sets |cur_hash| to the proper insertion place}
1250
nhash[cur_hash]:=start_ptr; equiv[start_ptr]:=v;
1251
for k:=1 to name_length do begin
1252
dictionary[dict_ptr]:=cur_name[k]; incr(dict_ptr);
1254
incr(start_ptr); start[start_ptr]:=dict_ptr;
1257
@ Here are the macros to load a name of up to 20 letters into the
1258
dictionary. For example, the macro |load5| is used for five-letter keywords.
1260
@d tail(#)==enter_name(#)
1261
@d t20(#)==cur_name[20]:=#;tail
1262
@d t19(#)==cur_name[19]:=#;t20
1263
@d t18(#)==cur_name[18]:=#;t19
1264
@d t17(#)==cur_name[17]:=#;t18
1265
@d t16(#)==cur_name[16]:=#;t17
1266
@d t15(#)==cur_name[15]:=#;t16
1267
@d t14(#)==cur_name[14]:=#;t15
1268
@d t13(#)==cur_name[13]:=#;t14
1269
@d t12(#)==cur_name[12]:=#;t13
1270
@d t11(#)==cur_name[11]:=#;t12
1271
@d t10(#)==cur_name[10]:=#;t11
1272
@d t9(#)==cur_name[9]:=#;t10
1273
@d t8(#)==cur_name[8]:=#;t9
1274
@d t7(#)==cur_name[7]:=#;t8
1275
@d t6(#)==cur_name[6]:=#;t7
1276
@d t5(#)==cur_name[5]:=#;t6
1277
@d t4(#)==cur_name[4]:=#;t5
1278
@d t3(#)==cur_name[3]:=#;t4
1279
@d t2(#)==cur_name[2]:=#;t3
1280
@d t1(#)==cur_name[1]:=#;t2
1281
@d load2==name_length:=2;t19
1282
@d load3==name_length:=3;t18
1283
@d load4==name_length:=4;t17
1284
@d load5==name_length:=5;t16
1285
@d load6==name_length:=6;t15
1286
@d load7==name_length:=7;t14
1287
@d load8==name_length:=8;t13
1288
@d load9==name_length:=9;t12
1289
@d load10==name_length:=10;t11
1290
@d load11==name_length:=11;t10
1291
@d load12==name_length:=12;t9
1292
@d load13==name_length:=13;t8
1293
@d load14==name_length:=14;t7
1294
@d load15==name_length:=15;t6
1295
@d load16==name_length:=16;t5
1296
@d load17==name_length:=17;t4
1297
@d load18==name_length:=18;t3
1298
@d load19==name_length:=19;t2
1299
@d load20==name_length:=20;t1
1301
@ (Thank goodness for keyboard macros in the text editor used to create this
1304
@<Enter all the \.{PL} names and their equivalents,
1305
except the parameter names@>=
1306
equiv[0]:=comment_code; {this is used after unknown keywords}
1307
load8("C")("H")("E")("C")("K")("S")("U")("M")(check_sum_code);@/
1308
load10("D")("E")("S")("I")("G")("N")("S")("I")("Z")("E")(design_size_code);@/
1309
load11("D")("E")("S")("I")("G")("N")
1310
("U")("N")("I")("T")("S")(design_units_code);@/
1311
load12("C")("O")("D")("I")("N")("G")
1312
("S")("C")("H")("E")("M")("E")(coding_scheme_code);@/
1313
load6("F")("A")("M")("I")("L")("Y")(family_code);@/
1314
load4("F")("A")("C")("E")(face_code);@/
1315
load16("S")("E")("V")("E")("N")("B")("I")("T")@/@t\hskip2em@>
1316
("S")("A")("F")("E")("F")("L")("A")("G")(seven_bit_safe_flag_code);@/
1317
load6("H")("E")("A")("D")("E")("R")(header_code);@/
1318
load9("F")("O")("N")("T")("D")("I")("M")("E")("N")(font_dimen_code);@/
1319
load8("L")("I")("G")("T")("A")("B")("L")("E")(lig_table_code);@/
1320
load12("B")("O")("U")("N")("D")("A")("R")("Y")("C")("H")("A")("R")
1321
(boundary_char_code);@/
1322
load9("C")("H")("A")("R")("A")("C")("T")("E")("R")(character_code);@/
1323
load9("P")("A")("R")("A")("M")("E")("T")("E")("R")(parameter_code);@/
1324
load6("C")("H")("A")("R")("W")("D")(char_wd_code);@/
1325
load6("C")("H")("A")("R")("H")("T")(char_ht_code);@/
1326
load6("C")("H")("A")("R")("D")("P")(char_dp_code);@/
1327
load6("C")("H")("A")("R")("I")("C")(char_ic_code);@/
1328
load5("S")("E")("C")("W")("D")(sec_width_code);@/
1329
load5("S")("E")("C")("H")("T")(sec_height_code);@/
1330
load5("S")("E")("C")("D")("P")(sec_depth_code);@/
1331
load5("S")("E")("C")("I")("C")(sec_italic_code);@/
1332
load6("A")("C")("C")("E")("N")("T")(accent_code);@/
1333
load11("P")("R")("I")("M")("T")("O")("P")("A")("X")("I")("S")(prim_top_axis_code);@/
1334
load14("P")("R")("I")("M")("T")("O")("P")("A")("X")("I")("S")("B")("I")("S")(prim_top_axis_bis_code);@/
1335
load11("P")("R")("I")("M")("B")("O")("T")("A")("X")("I")("S")(prim_bot_axis_code);@/
1336
load14("P")("R")("I")("M")("B")("O")("T")("A")("X")("I")("S")("B")("I")("S")(prim_bot_axis_bis_code);@/
1337
load10("P")("R")("I")("M")("M")("I")("D")("H")("O")("R")(prim_mid_hor_code);@/
1338
load10("P")("R")("I")("M")("M")("I")("D")("V")("E")("R")(prim_mid_vert_code);@/
1339
load13("P")("R")("I")("M")("B")("A")("S")("E")("S")("L")("A")("N")("T")(prim_base_slant_code);@/
1340
load10("S")("E")("C")("T")("O")("P")("A")("X")("I")("S")(sec_top_axis_code);@/
1341
load13("S")("E")("C")("T")("O")("P")("A")("X")("I")("S")("B")("I")("S")(sec_top_axis_bis_code);@/
1342
load10("S")("E")("C")("B")("O")("T")("A")("X")("I")("S")(sec_bot_axis_code);@/
1343
load13("S")("E")("C")("B")("O")("T")("A")("X")("I")("S")("B")("I")("S")(sec_bot_axis_bis_code);@/
1344
load9("S")("E")("C")("M")("I")("D")("H")("O")("R")(sec_mid_hor_code);@/
1345
load9("S")("E")("C")("M")("I")("D")("V")("E")("R")(sec_mid_vert_code);@/
1346
load12("S")("E")("C")("B")("A")("S")("E")("S")("L")("A")("N")("T")(sec_base_slant_code);@/
1347
load10("N")("E")("X")("T")("L")("A")("R")("G")("E")("R")(next_larger_code);@/
1348
load7("V")("A")("R")("C")("H")("A")("R")(var_char_code);@/
1349
load3("T")("O")("P")(var_char_code+1);@/
1350
load3("M")("I")("D")(var_char_code+2);@/
1351
load3("B")("O")("T")(var_char_code+3);@/
1352
load3("R")("E")("P")(var_char_code+4);@/
1353
load3("E")("X")("T")(var_char_code+4); {compatibility with older \.{PL} format}
1354
load7("C")("O")("M")("M")("E")("N")("T")(comment_code);@/
1355
load5("L")("A")("B")("E")("L")(label_code);@/
1356
load4("S")("T")("O")("P")(stop_code);@/
1357
load4("S")("K")("I")("P")(skip_code);@/
1358
load3("K")("R")("N")(krn_code);@/
1359
load3("L")("I")("G")(lig_code);@/
1360
load4("/")("L")("I")("G")(lig_code+2);@/
1361
load5("/")("L")("I")("G")(">")(lig_code+6);@/
1362
load4("L")("I")("G")("/")(lig_code+1);@/
1363
load5("L")("I")("G")("/")(">")(lig_code+5);@/
1364
load5("/")("L")("I")("G")("/")(lig_code+3);@/
1365
load6("/")("L")("I")("G")("/")(">")(lig_code+7);@/
1366
load7("/")("L")("I")("G")("/")(">")(">")(lig_code+11);@/
1367
load6("C")("L")("A")("B")("E")("L")(clabel_code);@/
1368
load4("C")("P")("E")("N")(cpen_code);@/
1369
load5("C")("G")("L")("U")("E")(cglue_code);@/
1370
load8("C")("P")("E")("N")("G")("L")("U")("E")(cpenglue_code);@/
1371
load4("C")("K")("R")("N")(ckrn_code);@/
1372
load8("O")("F")("M")("L")("E")("V")("E")("L")(ofm_level_code);@/
1373
load7("F")("O")("N")("T")("D")("I")("R")(font_dir_code);@/
1374
load8("N")("F")("O")("N")("T")("D")("I")("R")(n_font_dir_code);@/
1375
load10("C")("H")("A")("R")("R")("E")("P")("E")("A")("T")(char_repeat_code);@/
1376
load10("C")("H")("A")("R")("I")("V")("A")("L")("U")("E")(char_ivalue_code);@/
1377
load10("C")("H")("A")("R")("F")("V")("A")("L")("U")("E")(char_fvalue_code);@/
1378
load10("C")("H")("A")("R")("M")("V")("A")("L")("U")("E")(char_mvalue_code);@/
1379
load8("C")("H")("A")("R")("R")("U")("L")("E")(char_rule_code);@/
1380
load8("C")("H")("A")("R")("G")("L")("U")("E")(char_glue_code);@/
1381
load11("C")("H")("A")("R")("P")("E")("N")("A")("L")("T")("Y")(char_penalty_code);@/
1382
load8("F")("O")("N")("T")("R")("U")("L")("E")(font_rule_code);@/
1383
load4("R")("U")("L")("E")(rule_code);@/
1384
load6("R")("U")("L")("E")("W")("D")(rule_width_code);@/
1385
load6("R")("U")("L")("E")("H")("T")(rule_height_code);@/
1386
load6("R")("U")("L")("E")("D")("P")(rule_depth_code);@/
1387
load8("F")("O")("N")("T")("G")("L")("U")("E")(font_glue_code);@/
1388
load4("G")("L")("U")("E")(glue_code);@/
1389
load8("G")("L")("U")("E")("T")("Y")("P")("E")(glue_type_code);@/
1390
load16("G")("L")("U")("E")("S")("T")("R")("E")("T")("C")("H")("O")("R")("D")("E")("R")(glue_stretch_order_code);@/
1391
load15("G")("L")("U")("E")("S")("H")("R")("I")("N")("K")("O")("R")("D")("E")("R")(glue_shrink_order_code);@/
1392
load8("G")("L")("U")("E")("R")("U")("L")("E")(glue_rule_code);@/
1393
load8("G")("L")("U")("E")("C")("H")("A")("R")(glue_char_code);@/
1394
load6("G")("L")("U")("E")("W")("D")(glue_width_code);@/
1395
load11("G")("L")("U")("E")("S")("T")("R")("E")("T")("C")("H")(glue_stretch_code);@/
1396
load10("G")("L")("U")("E")("S")("H")("R")("I")("N")("K")(glue_shrink_code);@/
1397
load4("U")("N")("I")("T")(order_unit_code);@/
1398
load2("F")("I")(order_fi_code);@/
1399
load3("F")("I")("L")(order_fil_code);@/
1400
load4("F")("I")("L")("L")(order_fill_code);@/
1401
load5("F")("I")("L")("L")("L")(order_filll_code);@/
1402
load6("N")("O")("R")("M")("A")("L")(type_normal_code);@/
1403
load8("A")("L")("E")("A")("D")("E")("R")("S")(type_aleaders_code);@/
1404
load8("C")("L")("E")("A")("D")("E")("R")("S")(type_cleaders_code);@/
1405
load8("X")("L")("E")("A")("D")("E")("R")("S")(type_xleaders_code);@/
1406
load11("F")("O")("N")("T")("P")("E")("N")("A")("L")("T")("Y")(font_penalty_code);@/
1407
load7("P")("E")("N")("A")("L")("T")("Y")(penalty_code);@/
1408
load10("P")("E")("N")("A")("L")("T")("Y")("V")("A")("L")(penalty_val_code);@/
1409
load10("F")("O")("N")("T")("M")("V")("A")("L")("U")("E")(font_mvalue_code);@/
1410
load6("M")("V")("A")("L")("U")("E")(mvalue_code);@/
1411
load9("M")("V")("A")("L")("U")("E")("V")("A")("L")(mvalue_val_code);@/
1412
load10("F")("O")("N")("T")("F")("V")("A")("L")("U")("E")(font_fvalue_code);@/
1413
load6("F")("V")("A")("L")("U")("E")(fvalue_code);@/
1414
load9("F")("V")("A")("L")("U")("E")("V")("A")("L")(fvalue_val_code);@/
1415
load10("F")("O")("N")("T")("I")("V")("A")("L")("U")("E")(font_ivalue_code);@/
1416
load6("I")("V")("A")("L")("U")("E")(ivalue_code);@/
1417
load9("I")("V")("A")("L")("U")("E")("V")("A")("L")(ivalue_val_code);@/
1418
load2("T")("L")(TL_dir_code);
1419
load2("L")("T")(LT_dir_code);
1420
load2("T")("R")(TR_dir_code);
1421
load2("L")("B")(LB_dir_code);
1422
load2("B")("L")(BL_dir_code);
1423
load2("R")("T")(RT_dir_code);
1424
load2("B")("R")(BR_dir_code);
1425
load2("R")("B")(RB_dir_code);
1427
@ \.{VPL} files may contain the following in addition to the \.{PL} names.
1429
@<Enter all the \.{VPL} names@>=
1430
load6("V")("T")("I")("T")("L")("E")(virtual_title_code);@/
1431
load7("M")("A")("P")("F")("O")("N")("T")(map_font_code);@/
1432
load3("M")("A")("P")(map_code);@/
1433
load8("F")("O")("N")("T")("N")("A")("M")("E")(font_name_code);@/
1434
load8("F")("O")("N")("T")("A")("R")("E")("A")(font_area_code);@/
1435
load12("F")("O")("N")("T")
1436
("C")("H")("E")("C")("K")("S")("U")("M")(font_checksum_code);@/
1437
load6("F")("O")("N")("T")("A")("T")(font_at_code);@/
1438
load9("F")("O")("N")("T")("D")("S")("I")("Z")("E")(font_dsize_code);@/
1439
load10("S")("E")("L")("E")("C")("T")("F")("O")("N")("T")(select_font_code);@/
1440
load7("S")("E")("T")("C")("H")("A")("R")(set_char_code);@/
1441
load7("S")("E")("T")("R")("U")("L")("E")(set_rule_code);@/
1442
load9("M")("O")("V")("E")("R")("I")("G")("H")("T")(move_right_code);@/
1443
load8("M")("O")("V")("E")("L")("E")("F")("T")(move_right_code+1);@/
1444
load8("M")("O")("V")("E")("D")("O")("W")("N")(move_down_code);@/
1445
load6("M")("O")("V")("E")("U")("P")(move_down_code+1);@/
1446
load4("P")("U")("S")("H")(push_code);@/
1447
load3("P")("O")("P")(pop_code);@/
1448
load7("S")("P")("E")("C")("I")("A")("L")(special_code);@/
1449
load10("S")("P")("E")("C")("I")("A")("L")("H")("E")("X")(special_hex_code);@/
1451
@ @<Enter the parameter names@>=
1452
load5("S")("L")("A")("N")("T")(parameter_code+1);@/
1453
load5("S")("P")("A")("C")("E")(parameter_code+2);@/
1454
load7("S")("T")("R")("E")("T")("C")("H")(parameter_code+3);@/
1455
load6("S")("H")("R")("I")("N")("K")(parameter_code+4);@/
1456
load7("X")("H")("E")("I")("G")("H")("T")(parameter_code+5);@/
1457
load4("Q")("U")("A")("D")(parameter_code+6);@/
1458
load10("E")("X")("T")("R")("A")("S")("P")("A")("C")("E")(parameter_code+7);@/
1459
load4("N")("U")("M")("1")(parameter_code+8);@/
1460
load4("N")("U")("M")("2")(parameter_code+9);@/
1461
load4("N")("U")("M")("3")(parameter_code+10);@/
1462
load6("D")("E")("N")("O")("M")("1")(parameter_code+11);@/
1463
load6("D")("E")("N")("O")("M")("2")(parameter_code+12);@/
1464
load4("S")("U")("P")("1")(parameter_code+13);@/
1465
load4("S")("U")("P")("2")(parameter_code+14);@/
1466
load4("S")("U")("P")("3")(parameter_code+15);@/
1467
load4("S")("U")("B")("1")(parameter_code+16);@/
1468
load4("S")("U")("B")("2")(parameter_code+17);@/
1469
load7("S")("U")("P")("D")("R")("O")("P")(parameter_code+18);@/
1470
load7("S")("U")("B")("D")("R")("O")("P")(parameter_code+19);@/
1471
load6("D")("E")("L")("I")("M")("1")(parameter_code+20);@/
1472
load6("D")("E")("L")("I")("M")("2")(parameter_code+21);@/
1473
load10("A")("X")("I")("S")("H")("E")("I")("G")("H")("T")(parameter_code+22);@/
1474
load20("D")("E")("F")("A")("U")("L")("T")("R")("U")("L")("E")@/@t\hskip2em@>
1475
("T")("H")("I")("C")("K")("N")("E")("S")("S")(parameter_code+8);@/
1476
load13("B")("I")("G")("O")("P")
1477
("S")("P")("A")("C")("I")("N")("G")("1")(parameter_code+9);@/
1478
load13("B")("I")("G")("O")("P")
1479
("S")("P")("A")("C")("I")("N")("G")("2")(parameter_code+10);@/
1480
load13("B")("I")("G")("O")("P")
1481
("S")("P")("A")("C")("I")("N")("G")("3")(parameter_code+11);@/
1482
load13("B")("I")("G")("O")("P")
1483
("S")("P")("A")("C")("I")("N")("G")("4")(parameter_code+12);@/
1484
load13("B")("I")("G")("O")("P")
1485
("S")("P")("A")("C")("I")("N")("G")("5")(parameter_code+13);@/
1487
@ When a left parenthesis has been scanned, the following routine
1488
is used to interpret the keyword that follows, and to store the
1489
equivalent value in |cur_code|.
1491
@p procedure get_name;
1492
begin incr(loc); incr(level); {pass the left parenthesis}
1494
while cur_char=" " do get_next;
1495
if (cur_char>")")or(cur_char<"(") then decr(loc); {back up one character}
1496
name_length:=0; get_keyword_char; {prepare to scan the name}
1497
while cur_char<>" " do begin
1498
if name_length=longest_name then cur_name[1]:="X" {force error}
1499
else incr(name_length);
1500
cur_name[name_length]:=cur_char;
1504
if name_ptr=0 then err_print('Sorry, I don''t know that property name');
1505
@.Sorry, I don't know...@>
1506
cur_code:=equiv[name_ptr];
1509
@* Scanning numeric data.
1510
The next thing we need is a trio of subroutines to read the one-byte,
1511
four-byte, and real numbers that may appear as property values.
1512
These subroutines are careful to stick to numbers between $-2^{31}$
1513
and $2^{31}-1$, inclusive, so that a computer with two's complement
1514
32-bit arithmetic will not be interrupted by overflow.
1516
@ The first number scanner, which returns a one-byte value, surely has
1517
no problems of arithmetic overflow.
1519
@p function get_byte:byte; {scans a one-byte property value}
1520
var acc:integer; {an accumulator}
1521
@!t:ASCII_code; {the type of value to be scanned}
1522
begin repeat get_next;
1523
until cur_char<>" "; {skip the blanks before the type code}
1524
t:=cur_char; acc:=0;
1526
until cur_char<>" "; {skip the blanks after the type code}
1527
if t="C" then @<Scan an ASCII character code@>
1528
else if t="D" then @<Scan a small decimal number@>
1529
else if t="O" then @<Scan a small octal number@>
1530
else if t="H" then @<Scan a small hexadecimal number@>
1531
else if t="F" then @<Scan a face code@>
1532
else skip_error('You need "C" or "D" or "O" or "H" or "F" here');
1533
@.You need "C" or "D" ...here@>
1534
cur_char:=" "; get_byte:=acc;
1537
@ The |get_next| routine converts lower case to upper case, but it leaves
1538
the character in the buffer, so we can unconvert it.
1540
@<Scan an ASCII...@>=
1541
if (cur_char>=@'41)and(cur_char<=@'176)and
1542
((cur_char<"(")or(cur_char>")")) then
1543
acc:=xord[buffer[loc]]
1544
else skip_error('"C" value must be standard ASCII and not a paren')
1545
@:C value}\.{"C" value must be...@>
1547
@ @<Scan a small dec...@>=
1548
begin while (cur_char>="0")and(cur_char<="9") do begin
1549
acc:=acc*10+cur_char-"0";
1550
if acc>65535 then begin
1551
skip_error('This value shouldn''t exceed 65535');
1552
@.This value shouldn't...@>
1553
acc:=0; cur_char:=" ";
1560
@ @<Scan a small oct...@>=
1561
begin while (cur_char>="0")and(cur_char<="7") do begin
1562
acc:=acc*8+cur_char-"0";
1563
if acc>65535 then begin
1564
skip_error('This value shouldn''t exceed ''177777');
1565
@.This value shouldn't...@>
1566
acc:=0; cur_char:=" ";
1573
@ @<Scan a small hex...@>=
1574
begin while ((cur_char>="0")and(cur_char<="9"))or
1575
((cur_char>="A")and(cur_char<="F")) do begin
1576
if cur_char>="A" then cur_char:=cur_char+"0"+10-"A";
1577
acc:=acc*16+cur_char-"0";
1578
if acc>65535 then begin
1579
skip_error('This value shouldn''t exceed "FFFF');
1580
@.This value shouldn't...@>
1581
acc:=0; cur_char:=" ";
1588
@ @<Scan a face...@>=
1589
begin if cur_char="B" then acc:=2
1590
else if cur_char="L" then acc:=4
1591
else if cur_char<>"M" then acc:=18;
1593
if cur_char="I" then incr(acc)
1594
else if cur_char<>"R" then acc:=18;
1596
if cur_char="C" then acc:=acc+6
1597
else if cur_char="E" then acc:=acc+12
1598
else if cur_char<>"R" then acc:=18;
1599
if acc>=18 then begin
1600
skip_error('Illegal face code, I changed it to MRR');
1601
@.Illegal face code...@>
1606
@ The routine that scans a four-byte value puts its output into |cur_bytes|,
1607
which is a record containing (yes, you guessed it) four bytes.
1610
@!four_bytes=record @!b0:byte;@+@!b1:byte;@+@!b2:byte;@+@!b3:byte;@+end;
1612
@ @d c0==cur_bytes.b0
1618
@!cur_bytes:four_bytes; {a four-byte accumulator}
1619
@!zero_bytes:four_bytes; {four bytes all zero}
1622
zero_bytes.b0:=0; zero_bytes.b1:=0; zero_bytes.b2:=0; zero_bytes.b3:=0;
1624
@ Since the |get_four_bytes| routine is used very infrequently, no attempt
1625
has been made to make it fast; we only want it to work.
1626
This is no longer the case, but we hope it's not too slow.
1628
@p procedure get_four_bytes; {scans an unsigned constant and sets |four_bytes|}
1629
var c:integer; {local two-byte accumulator}
1630
@!r:integer; {radix}
1631
begin repeat get_next;
1632
until cur_char<>" "; {skip the blanks before the type code}
1633
r:=0; cur_bytes:=zero_bytes; {start with the accumulator zero}
1634
if cur_char="H" then r:=16
1635
else if cur_char="O" then r:=8
1636
else if cur_char="D" then r:=10
1637
else skip_error('Decimal ("D"), octal ("O"), or hex ("H") value needed here');
1638
@.Decimal ("D"), octal ("O"), or hex...@>
1641
until cur_char<>" "; {skip the blanks after the type code}
1642
while ((cur_char>="0")and(cur_char<="9"))or@|
1643
((cur_char>="A")and(cur_char<="F")) do
1644
@<Multiply by |r|, add |cur_char-"0"|, and |get_next|@>;
1648
function get_integer:integer; {scans an integer property value}
1649
begin get_four_bytes;
1650
get_integer:=(c0*@"1000000)+(c1*@"10000)+(c2*@"100)+c3;
1654
@ @<Multiply by |r|...@>=
1655
begin if cur_char>="A" then cur_char:=cur_char+"0"+10-"A";
1656
if cur_char>="0"+r then skip_error('Illegal digit')
1659
c:=c3*r+cur_char-"0"; c3:=c mod 256;@/
1660
c:=c2*r+c div 256; c2:=c mod 256;@/
1661
c:=c1*r+c div 256; c1:=c mod 256;@/
1665
cur_bytes:=zero_bytes;
1667
skip_error('Sorry, the maximum octal value is O 37777777777')
1668
@.Sorry, the maximum...@>
1670
skip_error('Sorry, the maximum decimal value is D 4294967295')
1671
else skip_error('Sorry, the maximum hex value is H FFFFFFFF');
1677
@ The remaining scanning routine is the most interesting. It scans a real
1678
constant and returns the nearest |fix_word| approximation to that constant.
1679
A |fix_word| is a 32-bit integer that represents a real value that
1680
has been multiplied by $2^{20}$. Since \.{VPtoVF} restricts the magnitude
1681
of reals to 2048, the |fix_word| will have a magnitude less than $2^{31}$.
1683
@d unity==@'4000000 {$2^{20}$, the |fix_word| 1.0}
1686
@!fix_word=integer; {a scaled real value with 20 bits of fraction}
1687
@!unsigned_integer=integer;
1689
@ When a real value is desired, we might as well treat `\.D' and `\.R'
1690
formats as if they were identical.
1692
@p function get_fix:fix_word; {scans a real property value}
1693
var negative:boolean; {was there a minus sign?}
1694
@!acc:integer; {an accumulator}
1695
@!int_part:integer; {the integer part}
1696
@!j:0..7; {the number of decimal places stored}
1697
begin repeat get_next;
1698
until cur_char<>" "; {skip the blanks before the type code}
1699
negative:=false; acc:=0; {start with the accumulators zero}
1700
if (cur_char<>"R")and(cur_char<>"D") then
1701
skip_error('An "R" or "D" value is needed here')
1702
@.An "R" or "D" ... needed here@>
1703
else begin @<Scan the blanks and/or signs after the type code@>;
1704
while (cur_char>="0") and (cur_char<="9") do
1705
@<Multiply by 10, add |cur_char-"0"|, and |get_next|@>;
1706
int_part:=acc; acc:=0;
1707
if cur_char="." then @<Scan the fraction part and put it in |acc|@>;
1708
if (acc>=unity)and(int_part=2047) then
1709
skip_error('Real constants must be less than 2048')
1710
@.Real constants must be...@>
1711
else acc:=int_part*unity+acc;
1713
if negative then get_fix:=-acc@+else get_fix:=acc;
1716
@ @<Scan the blanks...@>=
1718
if cur_char="-" then begin
1719
cur_char:=" "; negative:=true;
1721
else if cur_char="+" then cur_char:=" ";
1724
@ @<Multiply by 10...@>=
1725
begin acc:=acc*10+cur_char-"0";
1726
if acc>=2048 then begin
1727
skip_error('Real constants must be less than 2048');
1728
@.Real constants must be...@>
1729
acc:=0; cur_char:=" ";
1734
@ To scan the fraction $.d_1d_2\ldots\,$, we keep track of up to seven
1735
of the digits $d_j$. A correct result is obtained if we first compute
1736
$f^\prime=\lfloor 2^{21}(d_1\ldots d_j)/10^j\rfloor$, after which
1737
$f=\lfloor(f^\prime+1)/2\rfloor$. It is possible to have $f=1.0$.
1740
@!fraction_digits:array[1..7] of integer; {$2^{21}$ times $d_j$}
1742
@ @<Scan the frac...@>=
1743
begin j:=0; get_next;
1744
while (cur_char>="0")and(cur_char<="9") do begin
1746
incr(j); fraction_digits[j]:=@'10000000*(cur_char-"0");
1752
acc:=fraction_digits[j]+(acc div 10); decr(j);
1754
acc:=(acc+10) div 20;
1757
@* Storing the property values.
1758
When property values have been found, they are squirreled away in a bunch
1759
of arrays. The header information is unpacked into bytes in an array
1760
called |header_bytes|. The ligature/kerning program is stored in an array
1761
of type |four_bytes|.
1762
Another |four_bytes| array holds the specifications of extensible characters.
1763
The kerns and parameters are stored in separate arrays of |fix_word| values.
1764
Virtual font data goes into an array |vf| of single-byte values.
1766
We maintain information about at most |max_font+1| local fonts.
1768
Instead of storing the design size in the header array, we will keep it
1769
in a |fix_word| variable until the last minute. The number of units in the
1770
design size is also kept in a |fix_word|.
1773
@!header_bytes:array[header_index] of byte; {the header block}
1774
@!header_ptr:header_index; {the number of header bytes in use}
1775
@!design_size:fix_word; {the design size}
1776
@!design_units:fix_word; {reciprocal of the scaling factor}
1777
@!frozen_du:boolean; {have we used |design_units| irrevocably?}
1778
@!seven_bit_safe_flag:boolean; {does the file claim to be seven-bit-safe?}
1779
@!lig_kern:array[0..max_lig_steps] of four_bytes; {the ligature program}
1780
@!nl:unsigned_integer; {the number of ligature/kern instructions so far}
1781
@!min_nl:unsigned_integer; {the final value of |nl| must be at least this}
1782
@!kern:array[0..max_kerns] of fix_word; {the distinct kerning amounts}
1783
@!nk:0..max_kerns; {the number of entries of |kern|}
1784
@!exten:array[char_type] of four_bytes; {extensible character specs}
1785
@!ne:xchar_type; {the number of extensible characters}
1786
@!param:array[1..max_param_words] of fix_word; {\.{FONTDIMEN} parameters}
1787
@!np:0..max_param_words; {the largest parameter set nonzero}
1788
@!check_sum_specified:boolean; {did the user name the check sum?}
1789
@!bchar:xchar_type; {right boundary character, |xmax_char| if unspecified}
1790
@!font_dir:integer; {font direction}
1791
@!vf:array[0..vf_size] of byte; {stored bytes for \.{VF} file}
1792
@!vf_ptr:0..vf_size; {first unused location in |vf|}
1793
@!vtitle_start:0..vf_size; {starting location of \.{VTITLE} string}
1794
@!vtitle_length:byte; {length of \.{VTITLE} string}
1795
@!packet_start:array[char_type] of 0..vf_size;
1796
{beginning location of character packet}
1797
@!packet_length:array[char_type] of integer; {length of character packet}
1798
@!font_ptr:xfont_type; {number of distinct local fonts seen}
1799
@!cur_font:xfont_type; {number of the current local font}
1800
@!fname_start:array[font_type] of 0..vf_size; {beginning of local font name}
1801
@!fname_length:array[font_type] of byte; {length of local font name}
1802
@!farea_start:array[font_type] of 0..vf_size; {beginning of local font area}
1803
@!farea_length:array[font_type] of byte; {length of local font area}
1804
@!font_checksum:array[font_type] of four_bytes; {local font checksum}
1805
@!font_number:array[xfont_type] of integer; {local font id number}
1806
@!font_at:array[font_type] of fix_word; {local font ``at size''}
1807
@!font_dsize:array[font_type] of fix_word; {local font design size}
1810
@!char_type=0..max_char;
1811
@!xchar_type=0..xmax_char;
1812
@!xxchar_type=0..xxmax_char;
1813
@!font_type=0..max_font;
1814
@!xfont_type=0..xmax_font;
1815
@!header_index=0..max_header_bytes;
1819
@!d:header_index; {an index into |header_bytes|}
1821
@ We start by setting up the default values.
1824
@d design_size_loc=4
1825
@d coding_scheme_loc=8
1826
@d family_loc=coding_scheme_loc+40
1827
@d seven_flag_loc=family_loc+20
1828
@d face_loc=seven_flag_loc+3
1831
for d:=0 to 18*4-1 do header_bytes[d]:=0;
1832
header_bytes[8]:=11; header_bytes[9]:="U";
1833
header_bytes[10]:="N";
1834
header_bytes[11]:="S";
1835
header_bytes[12]:="P";
1836
header_bytes[13]:="E";
1837
header_bytes[14]:="C";
1838
header_bytes[15]:="I";
1839
header_bytes[16]:="F";
1840
header_bytes[17]:="I";
1841
header_bytes[18]:="E";
1842
header_bytes[19]:="D";
1844
for d:=family_loc to family_loc+11 do header_bytes[d]:=header_bytes[d-40];
1845
design_size:=10*unity; design_units:=unity; frozen_du:=false;
1846
seven_bit_safe_flag:=false;@/
1847
header_ptr:=18*4; nl:=0; min_nl:=0; nk:=0; ne:=0; np:=0;@/
1848
check_sum_specified:=false; bchar:=xmax_char;@/
1850
vf_ptr:=0; vtitle_start:=0; vtitle_length:=0; font_ptr:=0;
1851
for k:=0 to max_char do packet_start[k]:=vf_size;
1852
for k:=0 to 127 do packet_length[k]:=1;
1853
for k:=128 to 255 do packet_length[k]:=2;
1854
for k:=256 to max_char do packet_length[k]:=3;
1856
@ Most of the dimensions, however, go into the |memory| array. There are
1857
at most |max_char+2| widths, |max_char+2| heights,
1858
|max_char+2| depths, and |max_char+2| italic corrections,
1859
since the value 0 is required but it need not be used. So |memory| has room
1860
for |4*max_char+8| entries, each of which is a |fix_word|. An auxiliary table called
1861
|link| is used to link these words together in linear lists, so that
1862
sorting and other operations can be done conveniently.
1864
We also add four ``list head'' words to the |memory| and |link| arrays;
1865
these are in locations |width| through |italic|, i.e., 1 through 4.
1866
For example, |link[height]| points to the smallest element in
1867
the sorted list of distinct heights that have appeared so far, and
1868
|memory[height]| is the number of distinct heights.
1871
@!pointer=0..mem_size; {an index into memory}
1873
@ The arrays |char_wd|, |char_ht|, |char_dp|, and |char_ic| contain
1874
pointers to the |memory| array entries where the corresponding dimensions
1875
appear. Two other arrays, |char_tag| and |char_remainder|, hold
1876
the other information that \.{TFM} files pack into a |char_info_word|.
1878
@d no_tag=0 {vanilla character}
1879
@d lig_tag=1 {character has a ligature/kerning program}
1880
@d list_tag=2 {character has a successor in a charlist}
1881
@d ext_tag=3 {character is extensible}
1882
@d bchar_label==char_remainder[xmax_char]
1883
{beginning of ligature program for left boundary}
1886
@!memory:array[pointer] of fix_word; {character dimensions and kerns}
1887
@!mem_ptr:pointer; {largest |memory| word in use}
1888
@!link:array[pointer] of pointer; {to make lists of |memory| items}
1889
@!char_wd:array[char_type] of pointer; {pointers to the widths}
1890
@!char_ht:array[char_type] of pointer; {pointers to the heights}
1891
@!char_dp:array[char_type] of pointer; {pointers to the depths}
1892
@!char_ic:array[char_type] of pointer; {pointers to italic corrections}
1893
@!char_tag:array[char_type] of no_tag..ext_tag; {character tags}
1894
@!char_remainder:array[xchar_type] of xchar_type;
1895
{pointers to ligature labels,
1896
next larger characters, or extensible characters}
1897
@!top_width,@!top_height,@!top_depth,@!top_italic:integer;
1900
@!c:integer; {runs through all character codes}
1903
bchar_label:=xmax_label;
1904
for c:=0 to max_char do begin
1905
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;
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}
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.
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.
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
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 begin
1940
err_print('Memory overflow: too many widths, etc');
1941
@.Memory overflow...@>
1942
print_ln('Congratulations! It''s hard to make this error.');
1946
incr(mem_ptr); memory[mem_ptr]:=d;
1947
link[mem_ptr]:=link[p]; link[p]:=mem_ptr; incr(memory[h]);
1953
@ When these lists of dimensions are eventually written to the \.{OFM}
1954
file, we may have to do some rounding of values, because the \.{OFM} file
1955
allows at most 65536 widths, 256 heights, 256 depths, and 256 italic
1956
corrections. The following procedure takes a given list head |h| and a
1957
given dimension |d|, and returns the minimum $m$ such that the elements
1958
of the list can be covered by $m$ intervals of width $d$. It also sets
1959
|next_d| to the smallest value $d^\prime>d$ such that the covering found
1960
by this procedure would be different. In particular, if $d=0$ it computes
1961
the number of elements of the list, and sets |next_d| to the smallest
1962
distance between two list elements. (The covering by intervals of width
1963
|next_d| is not guaranteed to have fewer than $m$ elements, but in
1964
practice this seems to happen most of the time.)
1967
@!next_d:fix_word; {the next larger interval that is worth trying}
1969
@ Once again we can make good use of the fact that |memory[0]| is ``infinite.''
1971
@p function min_cover(@!h:pointer;@!d:fix_word):integer;
1972
var p:pointer; {the current node of interest}
1973
@!l:fix_word; {the least element covered by the current interval}
1974
@!m:integer; {the current size of the cover being generated}
1975
begin m:=0; p:=link[h]; next_d:=memory[0];
1977
incr(m); l:=memory[p];
1978
while memory[link[p]]<=l+d do p:=link[p];
1980
if memory[p]-l<next_d then next_d:=memory[p]-l;
1985
@ The following procedure uses |min_cover| to determine the smallest $d$
1986
such that a given list can be covered with at most a given number of
1989
@p function shorten(@!h:pointer;m:integer):fix_word; {finds best way to round}
1990
var d:fix_word; {the current trial interval length}
1991
@!k:integer; {the size of a minimum cover}
1992
begin if memory[h]>m then begin
1993
excess:=memory[h]-m;
1994
k:=min_cover(h,0); d:=next_d; {now the answer is at least |d|}
1995
repeat d:=d+d; k:=min_cover(h,d);
1996
until k<=m; {first we ascend rapidly until finding the range}
1997
d:=d div 2; k:=min_cover(h,d); {now we run through the feasible steps}
1999
d:=next_d; k:=min_cover(h,d);
2006
@ When we are nearly ready to output the \.{TFM} file, we will set
2007
|index[p]:=k| if the dimension in |memory[p]| is being rounded to the
2008
|k|th element of its list.
2011
@!index:array[pointer] of byte;
2012
@!excess:byte; {number of words to remove, if list is being shortened}
2014
@ Here is the procedure that sets the |index| values. It also shortens
2015
the list so that there is only one element per covering interval;
2016
the remaining elements are the midpoints of their clusters.
2018
@p procedure set_indices(@!h:pointer;@!d:fix_word); {reduces and indexes a list}
2019
var p:pointer; {the current node of interest}
2020
@!q:pointer; {trails one step behind |p|}
2021
@!m:byte; {index number of nodes in the current interval}
2022
@!l:fix_word; {least value in the current interval}
2023
begin q:=h; p:=link[q]; m:=0;
2025
incr(m); l:=memory[p]; index[p]:=m;
2026
while memory[link[p]]<=l+d do begin
2027
p:=link[p]; index[p]:=m; decr(excess);
2028
if excess=0 then d:=0;
2030
link[q]:=p; memory[p]:=l+(memory[p]-l) div 2; q:=p; p:=link[p];
2036
We're ready now to read and parse the \.{VPL} file, storing property
2040
@!c:integer; {the current character or byte being processed}
2041
@!cprime:char_type; {Processing for several characters together}
2042
@!crange:char_type; {ditto}
2043
@!x:fix_word; {current dimension of interest}
2044
@!k:integer; {general-purpose index}
2046
@ @<Read all the input@>=
2048
repeat while cur_char=" " do get_next;
2049
if cur_char="(" then @<Read a font property value@>
2050
else if (cur_char=")")and not input_has_ended then begin
2051
err_print('Extra right parenthesis');
2052
incr(loc); cur_char:=" ";
2054
@.Extra right parenthesis@>
2055
else if not input_has_ended then junk_error;
2056
until input_has_ended
2058
@ The |junk_error| routine just referred to is called when something
2059
appears in the forbidden area between properties of a property list.
2061
@p procedure junk_error; {gets past no man's land}
2062
begin err_print('There''s junk here that is not in parentheses');
2063
@.There's junk here...@>
2067
@ For each font property, we are supposed to read the data from the
2068
left parenthesis that is the current value of |cur_char| to the right
2069
parenthesis that matches it in the input. The main complication is
2070
to recover with reasonable grace from various error conditions that
2073
@<Read a font property value@>=
2075
if cur_code=comment_code then skip_to_end_of_item
2076
else if (cur_code<110) and (cur_code>character_code) then
2077
flush_error('This property name doesn''t belong on the outer level')
2078
else if (cur_code>=110) and ((cur_code mod 10)<>0) then
2079
flush_error('This property name doesn''t belong on the outer level')
2080
@.This property name doesn't belong...@>
2082
@<Read the font property value specified by |cur_code|@>;
2083
finish_the_property;
2087
@ @<Read the font property value spec...@>=
2089
check_sum_code: begin check_sum_specified:=true; read_four_bytes(check_sum_loc);
2091
design_size_code: @<Read the design size@>;
2092
design_units_code: @<Read the design units@>;
2093
coding_scheme_code: read_BCPL(coding_scheme_loc,40);
2094
family_code: read_BCPL(family_loc,20);
2095
face_code: begin c:=get_byte; if c>255 then begin
2096
err_print('FACE clipped to 255'); c:=255 end;
2097
header_bytes[face_loc]:=c
2099
seven_bit_safe_flag_code: @<Read the seven-bit-safe flag@>;
2100
header_code: @<Read an indexed header word@>;
2101
font_dimen_code: @<Read font parameter list@>;
2102
lig_table_code: read_lig_kern;
2103
boundary_char_code: bchar:=get_byte;
2104
virtual_title_code: begin vtitle_start:=vf_ptr; copy_to_end_of_item;
2105
if vf_ptr>vtitle_start+255 then begin
2106
err_print('VTITLE clipped to 255 characters'); vtitle_length:=255;
2107
@.VTITLE clipped...@>
2109
else vtitle_length:=vf_ptr-vtitle_start;
2111
map_font_code:@<Read a local font list@>;
2112
character_code: read_char_info;
2113
ofm_level_code: @<Read OFM level code@>;
2114
font_dir_code: @<Read font direction code@>;
2115
n_font_dir_code: @<Read natural font direction code@>;
2116
char_repeat_code: read_repeated_character_info;
2117
font_rule_code: read_font_rule_list;
2118
font_glue_code: read_font_glue_list;
2119
font_penalty_code: read_font_penalty_list;
2120
font_mvalue_code: read_font_mvalue_list;
2121
font_fvalue_code: read_font_fvalue_list;
2122
font_ivalue_code: read_font_ivalue_list;
2125
@ The |case| statement just given makes use of three subroutines that we
2126
haven't defined yet. The first of these puts a 32-bit octal quantity
2127
into four specified bytes of the header block.
2129
@p procedure read_four_bytes(l:header_index);
2130
begin get_four_bytes;
2131
header_bytes[l]:=c0;
2132
header_bytes[l+1]:=c1;
2133
header_bytes[l+2]:=c2;
2134
header_bytes[l+3]:=c3;
2137
@ The second little procedure is used to scan a string and to store it in
2138
the ``{\mc BCPL} format'' required by \.{TFM} files. The string is supposed
2139
to contain at most |n| bytes, including the first byte (which holds the
2140
length of the rest of the string).
2142
@p procedure read_BCPL(l:header_index;n:byte);
2145
while cur_char=" " do get_next;
2146
while (cur_char<>"(")and(cur_char<>")") do begin
2147
if k<l+n then incr(k);
2148
if k<l+n then header_bytes[k]:=cur_char;
2152
err_print('String is too long; its first ',n-1:1,
2153
@.String is too long...@>
2154
' characters will be kept'); decr(k);
2156
header_bytes[l]:=k-l;
2157
while k<l+n-1 do begin {tidy up the remaining bytes by setting them to nulls}
2158
incr(k); header_bytes[k]:=0;
2162
@ @<Read the design size@>=
2163
begin next_d:=get_fix;
2164
if next_d<unity then
2165
err_print('The design size must be at least 1')
2166
@.The design size must...@>
2167
else design_size:=next_d;
2170
@ @<Read the design units@>=
2171
begin next_d:=get_fix;
2173
err_print('The number of units per design size must be positive')
2174
@.The number of units...@>
2175
else if frozen_du then
2176
err_print('Sorry, it''s too late to change the design units')
2177
@.Sorry, it's too late...@>
2178
else design_units:=next_d;
2181
@ @<Read the seven-bit-safe...@>=
2182
begin while cur_char=" " do get_next;
2183
if cur_char="T" then seven_bit_safe_flag:=true
2184
else if cur_char="F" then seven_bit_safe_flag:=false
2185
else err_print('The flag value should be "TRUE" or "FALSE"');
2186
@.The flag value should be...@>
2190
@ @<Read an indexed header word@>=
2192
if c<18 then skip_error('HEADER indices should be 18 or more')
2193
@.HEADER indices...@>
2194
else if 4*c+4>max_header_bytes then
2195
skip_error('This HEADER index is too big for my present table size')
2196
@.This HEADER index is too big...@>
2198
while header_ptr<4*c+4 do begin
2199
header_bytes[header_ptr]:=0; incr(header_ptr);
2201
read_four_bytes(4*c);
2205
@ The remaining kinds of font property values that need to be read are
2206
those that involve property lists on higher levels. Each of these has a
2207
loop similar to the one that was used at level zero. Then we put the
2208
right parenthesis back so that `|finish_the_property|' will be happy;
2209
there is probably a more elegant way to do this.
2211
@d finish_inner_property_list==begin decr(loc); incr(level); cur_char:=")";
2214
@<Read font parameter list@>=
2215
begin while level=1 do
2216
begin while cur_char=" " do get_next;
2217
if cur_char="(" then @<Read a parameter value@>
2218
else if cur_char=")" then skip_to_end_of_item
2221
finish_inner_property_list;
2224
@ @<Read a parameter value@>=
2226
if cur_code=comment_code then skip_to_end_of_item
2227
else if (cur_code<parameter_code)or(cur_code>=char_wd_code) then
2228
flush_error('This property name doesn''t belong in a FONTDIMEN list')
2229
@.This property name doesn't belong...@>
2230
else begin if cur_code=parameter_code then c:=get_integer
2231
else c:=cur_code-parameter_code;
2232
if c=0 then flush_error('PARAMETER index must not be zero')
2233
@.PARAMETER index must not...@>
2234
else if c>max_param_words then
2235
flush_error('This PARAMETER index is too big for my present table size')
2236
@.This PARAMETER index is too big...@>
2239
incr(np); param[np]:=0;
2242
finish_the_property;
2247
@ @<Read a local font list@>=
2248
begin font_number[font_ptr]:=get_integer; cur_font:=0;
2249
while font_number[font_ptr]<>font_number[cur_font] do incr(cur_font);
2250
if cur_font=font_ptr then {it's a new font number}
2251
if font_ptr<xmax_font then @<Initialize a new local font@>
2252
else err_print('Sorry, too many different mapfonts');
2253
@.Sorry, too many different mapfonts@>
2254
if cur_font=font_ptr then skip_to_end_of_item
2255
else while level=1 do begin
2256
while cur_char=" " do get_next;
2257
if cur_char="(" then @<Read a local font property@>
2258
else if cur_char=")" then skip_to_end_of_item
2261
finish_inner_property_list;
2264
@ @<Initialize a new local font@>=
2265
begin incr(font_ptr);
2266
fname_start[cur_font]:=vf_size; fname_length[cur_font]:=4; {\.{NULL}}
2267
farea_start[cur_font]:=vf_size; farea_length[cur_font]:=0;
2268
font_checksum[cur_font]:=zero_bytes;
2269
font_at[cur_font]:=@'4000000; {denotes design size of this virtual font}
2270
font_dsize[cur_font]:=@'50000000; {the |fix_word| for 10}
2273
@ @<Read a local font property@>=
2275
if cur_code=comment_code then skip_to_end_of_item
2276
else if (cur_code<font_name_code)or(cur_code>font_dsize_code) then
2277
flush_error('This property name doesn''t belong in a MAPFONT list')
2278
@.This property name doesn't belong...@>
2281
font_name_code:@<Read a local font name@>;
2282
font_area_code:@<Read a local font area@>;
2283
font_checksum_code:begin
2284
get_four_bytes; font_checksum[cur_font]:=cur_bytes;
2286
font_at_code: begin frozen_du:=true;
2287
if design_units=unity then font_at[cur_font]:=get_fix
2288
else font_at[cur_font]:=round((get_fix/design_units)*1048576.0);
2290
font_dsize_code:font_dsize[cur_font]:=get_fix;
2291
end; {there are no other cases}
2292
finish_the_property;
2296
@ @<Read a local font name@>=
2297
begin fname_start[cur_font]:=vf_ptr; copy_to_end_of_item;
2298
if vf_ptr>fname_start[cur_font]+255 then begin
2299
err_print('FONTNAME clipped to 255 characters');
2300
@.FONTNAME clipped...@>
2301
fname_length[cur_font]:=255;
2303
else fname_length[cur_font]:=vf_ptr-fname_start[cur_font];
2306
@ @<Read a local font area@>=
2307
begin farea_start[cur_font]:=vf_ptr; copy_to_end_of_item;
2308
if vf_ptr>farea_start[cur_font]+255 then begin
2309
err_print('FONTAREA clipped to 255 characters');
2310
@.FONTAREA clipped...@>
2311
farea_length[cur_font]:=255;
2313
else farea_length[cur_font]:=vf_ptr-farea_start[cur_font];
2316
@ @<Read ligature/kern list@>=
2317
begin lk_step_ended:=false;
2319
begin while cur_char=" " do get_next;
2320
if cur_char="(" then read_lig_kern_command
2321
else if cur_char=")" then skip_to_end_of_item
2324
finish_inner_property_list;
2327
@ @<Read a ligature/kern command@>=
2329
if cur_code=comment_code then skip_to_end_of_item
2330
else if (cur_code>=label_code) and (cur_code<=(lig_code+11)) then begin
2332
label_code:@<Read a label step@>;
2333
stop_code:@<Read a stop step@>;
2334
skip_code:@<Read a skip step@>;
2335
krn_code:@<Read a kerning step@>;
2336
lig_code,lig_code+1,lig_code+2,lig_code+3,lig_code+5,lig_code+6,
2337
lig_code+7,lig_code+11:@<Read a ligature step@>;
2338
end; {there are no other cases |>=label_code|}
2339
finish_the_property;
2341
else if (cur_code>=clabel_code) and (cur_code<=cpenglue_code) then begin
2343
clabel_code:@<Read an extended label step@>;
2344
cpen_code:@<Read an extended penalty step@>;
2345
cglue_code:@<Read an extended glue step@>;
2346
cpenglue_code:@<Read an extended penalty/glue step@>;
2347
ckrn_code:@<Read an extended kern step@>;
2348
end; {there are no other cases |>=label_code|}
2349
finish_the_property;
2351
else flush_error('This property name doesn''t belong in a LIGTABLE list');
2352
@.This property name doesn't belong...@>
2355
@ When a character is about to be tagged, we call the following
2356
procedure so that an error message is given in case of multiple tags.
2358
@p procedure check_tag(c:byte); {print error if |c| already tagged}
2359
begin case char_tag[c] of
2361
lig_tag: err_print('This character already appeared in a LIGTABLE LABEL');
2362
@.This character already...@>
2363
list_tag: err_print('This character already has a NEXTLARGER spec');
2364
ext_tag: err_print('This character already has a VARCHAR spec');
2368
@ @<Read a label step@>=
2369
begin while cur_char=" " do get_next;
2370
if cur_char="B" then begin
2371
bchar_label:=nl; skip_to_paren; {\.{LABEL BOUNDARYCHAR}}
2374
backup; c:=get_byte;
2375
check_tag(c); char_tag[c]:=lig_tag; char_remainder[c]:=nl;
2377
if min_nl<=nl then min_nl:=nl+1;
2378
lk_step_ended:=false;
2381
@ @d stop_flag=128 {value indicating `\.{STOP}' in a lig/kern program}
2382
@d kern_flag=128 {op code for a kern step}
2385
@!lk_step_ended:boolean;
2386
{was the last \.{LIGTABLE} property \.{LIG} or \.{KRN}?}
2387
@!krn_ptr:0..max_kerns; {an index into |kern|}
2389
@ @<Read a stop step@>=
2390
if not lk_step_ended then
2391
err_print('STOP must follow LIG or KRN')
2392
@.STOP must follow LIG or KRN@>
2394
lig_kern[nl-1].b0:=lig_kern[nl-1].b0 div 256 * 256 + stop_flag;
2395
lk_step_ended:=false;
2398
@ @<Read a skip step@>=
2399
if not lk_step_ended then
2400
err_print('SKIP must follow LIG or KRN')
2401
@.SKIP must follow LIG or KRN@>
2404
if c>=128 then err_print('Maximum SKIP amount is 127')
2405
@.Maximum SKIP amount...@>
2406
else if nl+c>=max_lig_steps then
2407
err_print('Sorry, LIGTABLE too long for me to handle')
2408
@.Sorry, LIGTABLE too long...@>
2410
lig_kern[nl-1].b0:=c;
2411
if min_nl<=nl+c then min_nl:=nl+c+1;
2413
lk_step_ended:=false;
2416
@ @<Read a ligature step@>=
2417
begin lig_kern[nl].b0:=0;
2418
lig_kern[nl].b2:=cur_code-lig_code;
2419
lig_kern[nl].b1:=get_byte;
2420
lig_kern[nl].b3:=get_byte;
2421
if nl>=max_lig_steps-1 then
2422
err_print('Sorry, LIGTABLE too long for me to handle')
2423
@.Sorry, LIGTABLE too long...@>
2425
lk_step_ended:=true;
2428
@ @<Read a kerning step@>=
2429
begin lig_kern[nl].b0:=0; lig_kern[nl].b1:=get_byte;
2430
kern[nk]:=get_fix; krn_ptr:=0;
2431
while kern[krn_ptr]<>kern[nk] do incr(krn_ptr);
2432
if krn_ptr=nk then begin
2433
if nk<max_kerns then incr(nk)
2435
err_print('Sorry, too many different kerns for me to handle');
2436
@.Sorry, too many different kerns...@>
2440
if ofm_level=-1 then begin
2441
lig_kern[nl].b2:=kern_flag+(krn_ptr div 256);
2442
lig_kern[nl].b3:=krn_ptr mod 256;
2445
lig_kern[nl].b2:=kern_flag+(krn_ptr div 65536);
2446
lig_kern[nl].b3:=krn_ptr mod 65536;
2448
if nl>=max_lig_steps-1 then
2449
err_print('Sorry, LIGTABLE too long for me to handle')
2450
@.Sorry, LIGTABLE too long...@>
2452
lk_step_ended:=true;
2456
@!category_remainders:array[0..256] of integer;
2457
@!ivalue_category,@!max_ivalue_category:integer;
2458
@!glue_category,@!max_glue_category:integer;
2459
@!penalty_category,@!max_penalty_category:integer;
2462
for ivalue_category:=0 to 256 do begin
2463
category_remainders[ivalue_category]:=-1;
2465
max_ivalue_category:=-1;
2466
max_glue_category:=-1;
2467
max_penalty_category:=-1;
2469
@ @<Read an extended label step@>=
2472
category_remainders[c]:=nl;
2473
if max_ivalue_category<c then max_ivalue_category:=c;
2474
if min_nl<=nl then min_nl:=nl+1;
2475
lk_step_ended:=false;
2478
@ @<Read an extended penalty step@>=
2479
begin lig_kern[nl].b0:=256; lig_kern[nl].b1:=get_byte;
2480
lig_kern[nl].b2:=17;
2481
penalty_category:=get_byte;
2482
if max_penalty_category<penalty_category then
2483
max_penalty_category:=penalty_category;
2484
lig_kern[nl].b3:=penalty_category;
2485
if nl>=max_lig_steps-1 then
2486
err_print('Sorry, LIGTABLE too long for me to handle')
2487
@.Sorry, LIGTABLE too long...@>
2489
lk_step_ended:=true;
2492
@ @<Read an extended glue step@>=
2493
begin lig_kern[nl].b0:=256; lig_kern[nl].b1:=get_byte;
2494
lig_kern[nl].b2:=18;
2495
glue_category:=get_byte;
2496
if max_glue_category<glue_category then
2497
max_glue_category:=glue_category;
2498
lig_kern[nl].b3:=glue_category;
2499
if nl>=max_lig_steps-1 then
2500
err_print('Sorry, LIGTABLE too long for me to handle')
2501
@.Sorry, LIGTABLE too long...@>
2503
lk_step_ended:=true;
2506
@ @<Read an extended penalty/glue step@>=
2507
begin lig_kern[nl].b0:=256; lig_kern[nl].b1:=get_byte;
2508
lig_kern[nl].b2:=19;
2509
penalty_category:=get_byte;
2510
if max_penalty_category<penalty_category then
2511
max_penalty_category:=penalty_category;
2512
glue_category:=get_byte;
2513
if max_glue_category<glue_category then
2514
max_glue_category:=glue_category;
2515
lig_kern[nl].b3:=penalty_category*256+glue_category;
2516
if nl>=max_lig_steps-1 then
2517
err_print('Sorry, LIGTABLE too long for me to handle')
2518
@.Sorry, LIGTABLE too long...@>
2520
lk_step_ended:=true;
2523
@ @<Read an extended kern step@>=
2524
begin lig_kern[nl].b0:=256; lig_kern[nl].b1:=get_byte;
2525
lig_kern[nl].b2:=20;
2526
kern[nk]:=get_fix; krn_ptr:=0;
2527
while kern[krn_ptr]<>kern[nk] do incr(krn_ptr);
2528
if krn_ptr=nk then begin
2529
if nk<max_kerns then incr(nk)
2531
err_print('Sorry, too many different kerns for me to handle');
2532
@.Sorry, too many different kerns...@>
2536
if krn_ptr>65535 then
2537
err_print('Sorry, too many different kerns for me to handle');
2538
lig_kern[nl].b3:=krn_ptr;
2539
if nl>=max_lig_steps-1 then
2540
err_print('Sorry, LIGTABLE too long for me to handle')
2541
@.Sorry, LIGTABLE too long...@>
2543
lk_step_ended:=true;
2547
@!char_extended_tag:array [char_type] of boolean;
2550
for c:=0 to max_char do
2551
char_extended_tag[c]:=false;
2553
@ @<Finish up the extended font stuff@>=
2555
if max_penalty_category>0 then begin
2557
err_print('No PENALTY table')
2558
else if npp[0]<max_penalty_category then
2559
err_print('Not enough PENALTY entries');
2561
if max_glue_category>0 then begin
2563
err_print('No GLUE table')
2564
else if npg[0]<max_glue_category then
2565
err_print('Not enough GLUE entries');
2567
if max_ivalue_category>0 then begin
2569
err_print('No IVALUE table')
2570
else if npi[0]<max_ivalue_category then
2571
err_print('Not enough IVALUE entries')
2573
for c:=0 to max_char do begin
2574
if (char_wd[c]<>0) then begin
2575
for j:=0 to max_ivalue_category do
2576
if char_table[c,0]=j then begin
2577
if category_remainders[j]<>-1 then begin
2578
if char_tag[c]<>0 then
2579
err_print('Character already has a tag')
2581
char_extended_tag[c]:=true;
2582
char_remainder[c]:=category_remainders[j];
2593
tables_read:boolean;
2598
@ Finally we come to the part of \.{VPtoVF}'s input mechanism
2599
that is used most, the processing of individual character data.
2601
@<Read character info list@>=
2603
if not tables_read then begin
2604
@<Compute the new header information for OFM files@>;
2607
c:=get_byte; {read the character code that is being specified}
2608
@<Print |c| in hex notation@>;
2609
while level=1 do begin
2610
while cur_char=" " do get_next;
2611
if cur_char="(" then read_character_property
2612
else if cur_char=")" then skip_to_end_of_item
2615
if char_wd[c]=0 then char_wd[c]:=sort_in(width,0); {legitimatize |c|}
2616
finish_inner_property_list;
2620
@!char_original:array [0..max_char] of integer;
2621
@!char_repeats:array [0..max_char] of integer;
2623
@!needed_space,@!extra_bytes:integer;
2626
for ch_entry:=0 to max_char do begin
2627
char_original[ch_entry]:=ch_entry;
2628
char_repeats[ch_entry]:=0;
2631
@ @<Read repeated character info@>=
2633
if not tables_read then begin
2634
compute_new_header_ofm;
2637
c:=get_byte; {read the character code that is being specified}
2638
@<Print |c| in hex notation@>;
2639
crange:=get_byte; {read how many characters are being defined}
2640
if (crange<0) then begin
2641
err_print('Character ranges must be positive');
2644
if ((c+crange)>max_char) then begin
2645
err_print('Character range too large');
2648
print('-'); print_hex(c+crange);
2649
while level=1 do begin
2650
while cur_char=" " do get_next;
2651
if cur_char="(" then read_character_property
2652
else if cur_char=")" then skip_to_end_of_item
2655
if char_wd[c]=0 then char_wd[c]:=sort_in(width,0); {legitimatize |c|}
2656
finish_inner_property_list;
2658
for c:=(cprime+1) to (cprime+crange) do begin
2659
char_wd[c]:=char_wd[cprime];
2660
char_ht[c]:=char_ht[cprime];
2661
char_dp[c]:=char_dp[cprime];
2662
char_ic[c]:=char_ic[cprime];
2663
for tab:=0 to (nki+nkf+nkr+nkg+nkp-1) do begin
2664
char_table[c,tab]:= char_table[cprime,tab];
2669
@ Tables for character parameters
2671
@d char_param_tables==8
2674
@!char_table:array [0..max_char,0..char_param_tables] of integer;
2675
@!ch_table,@!ch_entry:integer;
2676
@!temp_value:integer;
2679
for c:=0 to max_char do
2680
for ch_table:=0 to char_param_tables do
2681
char_table[c,ch_table]:=0;
2683
@ @<Read a character property@>=
2685
if cur_code=comment_code then skip_to_end_of_item
2686
else if (cur_code<char_wd_code) or
2687
((cur_code>var_char_code) and not
2688
((cur_code>=char_ivalue_code) and (cur_code<=char_penalty_code)))
2690
flush_error('This property name doesn''t belong in a CHARACTER list')
2691
@.This property name doesn't belong...@>
2694
char_wd_code:char_wd[c]:=sort_in(width,get_fix);
2695
char_ht_code:char_ht[c]:=sort_in(height,get_fix);
2696
char_dp_code:char_dp[c]:=sort_in(depth,get_fix);
2697
char_ic_code:char_ic[c]:=sort_in(italic,get_fix);
2698
sec_width_code:temp_value:=get_fix;
2699
sec_height_code:temp_value:=get_fix;
2700
sec_depth_code:temp_value:=get_fix;
2701
sec_italic_code:temp_value:=get_fix;
2702
accent_code:temp_value:=get_fix;
2703
prim_top_axis_code:temp_value:=get_fix;
2704
prim_top_axis_bis_code:temp_value:=get_fix;
2705
prim_bot_axis_code:temp_value:=get_fix;
2706
prim_bot_axis_bis_code:temp_value:=get_fix;
2707
prim_mid_hor_code:temp_value:=get_fix;
2708
prim_mid_vert_code:temp_value:=get_fix;
2709
prim_base_slant_code:temp_value:=get_fix;
2710
sec_top_axis_code:temp_value:=get_fix;
2711
sec_top_axis_bis_code:temp_value:=get_fix;
2712
sec_bot_axis_code:temp_value:=get_fix;
2713
sec_bot_axis_bis_code:temp_value:=get_fix;
2714
sec_mid_hor_code:temp_value:=get_fix;
2715
sec_mid_vert_code:temp_value:=get_fix;
2716
sec_base_slant_code:temp_value:=get_fix;
2717
next_larger_code:begin check_tag(c); char_tag[c]:=list_tag;
2718
char_remainder[c]:=get_byte;
2720
map_code:read_packet(c);
2721
var_char_code:@<Read an extensible recipe for |c|@>;
2722
char_ivalue_code: begin
2723
ch_table:=get_integer;
2724
ch_entry:=get_integer;
2725
char_table[c,ch_table]:=ch_entry;
2726
if ch_table>nkci then nkci:=ch_table;
2728
char_fvalue_code: begin
2729
ch_table:=get_integer+nki;
2730
ch_entry:=get_integer;
2731
char_table[c,ch_table]:=ch_entry;
2732
if ch_table>nkcf then nkcf:=ch_table;
2734
char_mvalue_code: begin
2735
ch_table:=get_integer+nki+nkf;
2736
ch_entry:=get_integer;
2737
char_table[c,ch_table]:=ch_entry;
2738
if ch_table>nkcm then nkcm:=ch_table;
2740
char_rule_code: begin
2741
ch_table:=get_integer+nki+nkf+nkm;
2742
ch_entry:=get_integer;
2743
char_table[c,ch_table]:=ch_entry;
2744
if ch_table>nkcr then nkcr:=ch_table;
2746
char_glue_code: begin
2747
ch_table:=get_integer+nki+nkf+nkm+nkr;
2748
ch_entry:=get_integer;
2749
char_table[c,ch_table]:=ch_entry;
2750
if ch_table>nkcg then nkcg:=ch_table;
2752
char_penalty_code: begin
2753
ch_table:=get_integer+nki+nkf+nkm+nkr+nkg;
2754
ch_entry:=get_integer;
2755
char_table[c,ch_table]:=ch_entry;
2756
if ch_table>nkcp then nkcp:=ch_table;
2759
finish_the_property;
2763
@ @<Read an extensible r...@>=
2764
begin if ne=xmax_char then
2765
err_print('Sorry, too many VARCHAR specs')
2766
@.Sorry, too many VARCHAR specs@>
2768
check_tag(c); char_tag[c]:=ext_tag; char_remainder[c]:=ne;@/
2769
exten[ne]:=zero_bytes;
2770
while level=2 do begin
2771
while cur_char=" " do get_next;
2772
if cur_char="(" then @<Read an extensible piece@>
2773
else if cur_char=")" then skip_to_end_of_item
2777
finish_inner_property_list;
2781
@ @<Read an extensible p...@>=
2783
if cur_code=comment_code then skip_to_end_of_item
2784
else if (cur_code<var_char_code+1)or(cur_code>var_char_code+4) then
2785
flush_error('This property name doesn''t belong in a VARCHAR list')
2786
@.This property name doesn't belong...@>
2788
case cur_code-(var_char_code+1) of
2789
0:exten[ne].b0:=get_byte;
2790
1:exten[ne].b1:=get_byte;
2791
2:exten[ne].b2:=get_byte;
2792
3:exten[ne].b3:=get_byte;
2794
finish_the_property;
2798
@ The input routine is now complete except for the following code,
2799
which prints a progress report as the file is being read.
2802
@!HEX: packed array [1..32] of char;
2805
HEX:='0123456789ABCDEF';@/
2807
@ The array |dig| will hold a sequence of digits to be output.
2810
@!dig:array[0..32] of integer;
2812
@ Here, in fact, are two procedures that output
2813
|dig[j-1]|$\,\ldots\,$|dig[0]|, given $j>0$.
2815
@p procedure out_digs(j:integer); {outputs |j| digits}
2816
begin repeat decr(j); out(HEX[1+dig[j]]);
2820
procedure print_digs(j:integer); {prints |j| digits}
2821
begin repeat decr(j); print(HEX[1+dig[j]]);
2825
@ The |print_number| procedure indicates how |print_digs| can be used.
2826
This procedure can print in octal, decimal or hex notation.
2828
@d print_hex(#)==print_number(#,16)
2829
@d print_octal(#)==print_number(#,8)
2830
@d print_decimal(#)==print_number(#,10)
2832
@p procedure print_number(c:integer; form:integer); {prints value of
2834
var j:0..32; {index into |dig|}
2838
print_ln('Internal error: print_number (negative value)');
2842
print('''') {an apostrophe indicates the octal notation}
2843
else if form=16 then
2844
print('"') { a double apostrophe indicates the hexadecimal
2846
else if form<>10 then begin
2847
print_ln('Internal error: print_number (form)');
2850
while (c>0) or (j=0) do begin
2851
dig[j]:=c mod form; c:=c div form;
2857
@ @<Print |c| in hex...@>=
2858
begin if chars_on_line=8 then begin
2859
print_ln(' '); chars_on_line:=1;
2862
if chars_on_line>0 then print(' ');
2863
incr(chars_on_line);
2865
print_hex(c); {progress report}
2869
@* Assembling the mappings.
2870
Each \.{MAP} property is a sequence of \.{DVI} instructions, for which
2871
we need to know some of the opcodes.
2872
We add afterwards the definitions for outputting typesetting commands.
2874
@d set_char_0=0 {\.{DVI} command to typeset character 0 and move right}
2875
@d set1=128 {typeset a character and move right}
2876
@d set_rule=132 {typeset a rule and move right}
2877
@d push=141 {save the current positions}
2878
@d pop=142 {restore previous positions}
2879
@d right1=143 {move right}
2880
@d w0=147 {move right by |w|}
2881
@d w1=148 {move right and set |w|}
2882
@d x0=152 {move right by |x|}
2883
@d x1=153 {move right and set |x|}
2884
@d down1=157 {move down}
2885
@d y0=161 {move down by |y|}
2886
@d y1=162 {move down and set |y|}
2887
@d z0=166 {move down by |z|}
2888
@d z1=167 {move down and set |z|}
2889
@d fnt_num_0=171 {set current font to 0}
2890
@d fnt1=235 {set current font}
2891
@d xxx1=239 {extension to \.{DVI} primitives}
2892
@d xxx4=242 {potentially long extension to \.{DVI} primitives}
2893
@d fnt_def1=243 {define the meaning of a font number}
2894
@d pre=247 {preamble}
2895
@d post=248 {postamble beginning}
2896
@d Incr_Decr(#) == #
2897
@d Incr(#) == #:=#+Incr_Decr {increase a variable}
2900
if x>=0 then #(x div @"1000000)
2901
else begin Incr(x)(@"40000000); Incr(x)(@"40000000);
2902
#((x div @"1000000) + 128);
2904
x:=x mod @"1000000; #(x div @"10000);
2905
x:=x mod @"10000; #(x div @"100);
2909
if (x<@"100)and(x>=0) then begin
2910
if (o<>set1)or(x>127) then
2911
if (o=fnt1)and(x<64) then Incr(x)(fnt_num_0) @+ else #(o);
2914
if (x<@"10000)and(x>=0) then #(o+1) @+ else begin
2915
if (x<@"1000000)and(x>=0) then #(o+2) @+ else begin
2917
if x>=0 then #(x div @"1000000)
2919
Incr(x)(@"40000000); Incr(x)(@"40000000);
2920
#((x div @"1000000) + 128); x:=x mod @"1000000;
2922
#(x div @"10000); x:=x mod @"10000;
2924
#(x div @"10000); x:=x mod @"10000;
2926
#(x div @"100); x:=x mod @"100;
2931
procedure vf_store_set(@!x:integer);
2933
begin o:=set1; out_cmd(vf_store);
2936
procedure vfout_set(@!x:integer);
2938
begin o:=set1; out_cmd(vout);
2941
procedure vf_store_fnt(@!x:integer);
2943
begin o:=fnt1; out_cmd(vf_store);
2946
procedure vfout_fntdef(@!x:integer);
2948
begin o:=fnt_def1; out_cmd(vout);
2951
procedure vfout_char(@!x:integer);
2952
begin out_four(vout);
2956
@ We keep stacks of movement values, in order to optimize the \.{DVI} code
2960
@!hstack:array[0..max_stack] of 0..2; {number of known horizontal movements}
2961
@!vstack:array[0..max_stack] of 0..2; {number of known vertical movements}
2962
@!wstack,@!xstack,@!ystack,@!zstack:array[0..max_stack] of fix_word;
2963
@!stack_ptr:0..max_stack;
2965
@ The packet is built by straightforward assembly of \.{DVI} instructions.
2967
@p @<Declare the |vf_fix| procedure@>@;@/
2968
procedure read_packet(@!c:byte);
2969
var @!cc:char_type; {character being typeset}
2970
@!x:fix_word; {movement}
2971
@!h,@!v:0..2; {top of |hstack| and |vstack|}
2972
@!special_start:0..vf_size; {location of |xxx1| command}
2973
@!k:0..vf_size; {loop index}
2974
begin packet_start[c]:=vf_ptr; stack_ptr:=0; h:=0; v:=0;
2976
while level=2 do begin
2977
while cur_char=" " do get_next;
2978
if cur_char="(" then @<Read and assemble a list of \.{DVI} commands@>
2979
else if cur_char=")" then skip_to_end_of_item
2982
while stack_ptr>0 do begin
2983
err_print('Missing POP supplied');
2984
@.Missing POP supplied@>
2985
vf_store(pop); decr(stack_ptr);
2987
packet_length[c]:=vf_ptr-packet_start[c];
2988
finish_inner_property_list;
2991
@ @<Read and assemble a list of \.{DVI}...@>=
2993
if cur_code=comment_code then skip_to_end_of_item
2994
else if (cur_code<select_font_code)or(cur_code>special_hex_code) then
2995
flush_error('This property name doesn''t belong in a MAP list')
2996
@.This property name doesn't belong...@>
2999
select_font_code:@<Assemble a font selection@>;
3000
set_char_code:@<Assemble a typesetting instruction@>;
3001
set_rule_code:@<Assemble a rulesetting instruction@>;
3002
move_right_code,move_right_code+1:@<Assemble a horizontal movement@>;
3003
move_down_code,move_down_code+1:@<Assemble a vertical movement@>;
3004
push_code:@<Assemble a stack push@>;
3005
pop_code:@<Assemble a stack pop@>;
3006
special_code,special_hex_code:@<Assemble a special command@>;
3008
finish_the_property;
3012
@ @<Assemble a font selection@>=
3013
begin font_number[font_ptr]:=get_integer;
3015
while font_number[font_ptr]<>font_number[cur_font] do incr(cur_font);
3016
if cur_font=font_ptr then err_print('Undefined MAPFONT cannot be selected')
3017
@.Undefined MAPFONT...@>
3018
else vf_store_fnt(cur_font);
3021
@ @<Assemble a typesetting instruction@>=
3022
if cur_font=font_ptr then
3023
err_print('Character cannot be typeset in undefined font')
3024
@.Character cannot be typeset...@>
3026
cc:=get_byte; vf_store_set(cc);
3029
@ Here's a procedure that converts a |fix_word| to a sequence of
3032
@<Declare the |vf_fix|...@>=
3033
procedure vf_fix(@!opcode:byte;@!x:fix_word);
3034
var negative:boolean;
3035
@!k:0..4; {number of bytes to typeset}
3036
@!t:integer; {threshold}
3037
begin frozen_du:=true;
3038
if design_units<>unity then x:=round((x/design_units)*1048576.0);
3039
if x>0 then negative:=false
3040
else begin negative:=true; x:=-1-x;@+end;
3041
if opcode=0 then begin
3042
k:=4; t:=@'100000000;@+end
3046
t:=256*t+255; incr(k);
3048
vf_store(opcode+k-1); t:=t div 128 +1;
3050
repeat if negative then begin
3051
vf_store(255-(x div t)); negative:=false;
3052
x:=(x div t)*t+t-1-x;
3054
else vf_store((x div t) mod 256);
3055
decr(k); t:=t div 256;
3059
@ @<Assemble a rulesetting instruction@>=
3060
begin vf_store(set_rule); vf_fix(0,get_fix); vf_fix(0,get_fix);
3063
@ @<Assemble a horizontal movement@>=
3064
begin if cur_code=move_right_code then x:=get_fix@+else x:=-get_fix;
3066
wstack[stack_ptr]:=x; h:=1; vf_fix(w1,x);@+end
3067
else if x=wstack[stack_ptr] then vf_store(w0)
3068
else if h=1 then begin
3069
xstack[stack_ptr]:=x; h:=2; vf_fix(x1,x);@+end
3070
else if x=xstack[stack_ptr] then vf_store(x0)
3071
else vf_fix(right1,x);
3074
@ @<Assemble a vertical movement@>=
3075
begin if cur_code=move_down_code then x:=get_fix@+else x:=-get_fix;
3077
ystack[stack_ptr]:=x; v:=1; vf_fix(y1,x);@+end
3078
else if x=ystack[stack_ptr] then vf_store(y0)
3079
else if v=1 then begin
3080
zstack[stack_ptr]:=x; v:=2; vf_fix(z1,x);@+end
3081
else if x=zstack[stack_ptr] then vf_store(z0)
3082
else vf_fix(down1,x);
3085
@ @<Assemble a stack push@>=
3086
if stack_ptr=max_stack then {too pushy}
3087
err_print('Don''t push so much---stack is full!')
3088
@.Don't push so much...@>
3090
vf_store(push); hstack[stack_ptr]:=h; vstack[stack_ptr]:=v;
3091
incr(stack_ptr); h:=0; v:=0;
3094
@ @<Assemble a stack pop@>=
3096
err_print('Empty stack cannot be popped')
3099
vf_store(pop); decr(stack_ptr);
3100
h:=hstack[stack_ptr]; v:=vstack[stack_ptr];
3103
@ @<Assemble a special command@>=
3104
begin vf_store(xxx1); vf_store(0); {dummy length}
3105
special_start:=vf_ptr;
3106
if cur_code=special_code then copy_to_end_of_item
3109
if cur_char>")" then vf_store(x*16+get_hex);
3110
until cur_char<=")";
3112
if vf_ptr-special_start>255 then @<Convert |xxx1| command to |xxx4|@>
3113
else vf[special_start-1]:=vf_ptr-special_start;
3116
@ @<Convert |xxx1|...@>=
3117
if vf_ptr+3>vf_size then begin
3118
err_print('Special command being clipped---no room left!');
3119
@.Special command being clipped...@>
3120
vf_ptr:=special_start+255; vf[special_start-1]:=255;
3123
for k:=vf_ptr downto special_start do vf[k+3]:=vf[k];
3124
x:=vf_ptr-special_start; vf_ptr:=vf_ptr+3;
3125
vf[special_start-2]:=xxx4;
3126
vf[special_start-1]:=x div @'100000000;
3127
vf[special_start]:=(x div @'200000) mod 256;
3128
vf[special_start+1]:=(x div @'400) mod 256;
3129
vf[special_start+2]:=x mod 256;
3132
@* The checking and massaging phase.
3133
Once the whole \.{VPL} file has been read in, we must check it for consistency
3134
and correct any errors. This process consists mainly of running through
3135
the characters that exist and seeing if they refer to characters that
3136
don't exist. We also compute the true value of |seven_unsafe|; we make sure
3137
that the charlists and ligature programs contain no loops; and we
3138
shorten the lists of widths, heights, depths, and italic corrections,
3139
if necessary, to keep from exceeding the required maximum sizes.
3142
@!seven_unsafe:boolean; {do seven-bit characters generate eight-bit ones?}
3144
@ @<Correct and check the information@>=
3145
if nl>0 then @<Make sure the ligature/kerning program ends appropriately@>;
3146
seven_unsafe:=false;
3147
for c:=0 to max_char do if char_wd[c]<>0 then
3148
@<For all characters |g| generated by |c|,
3149
make sure that |char_wd[g]| is nonzero, and
3150
set |seven_unsafe| if |c<128<=g|@>;
3151
if bchar_label<xmax_label then begin
3152
c:=xmax_char; @<Check ligature program of |c|@>;
3154
if seven_bit_safe_flag and seven_unsafe then
3155
print_ln('The font is not really seven-bit-safe!');
3156
@.The font is not...safe@>
3157
@<Check for infinite ligature loops@>;
3158
@<Doublecheck the lig/kern commands and the extensible recipes@>;
3159
finish_extended_font;
3160
for c:=0 to max_char do
3161
@<Make sure that |c| is not the largest element of a charlist cycle@>;
3162
@<Put the width, height, depth, and italic lists into final form@>
3164
@ The checking that we need in several places is accomplished by three
3165
macros that are only slightly tricky.
3167
@d existence_tail(#)==begin char_wd[g]:=sort_in(width,0);
3168
print(#,' '); print_hex(c);
3169
print_ln(' had no CHARACTER spec.');
3172
@d check_existence_and_safety(#)==begin g:=#;
3173
if (g>=128)and(c<128) then seven_unsafe:=true;
3174
if char_wd[g]=0 then existence_tail
3175
@d check_existence(#)==begin g:=#;
3176
if char_wd[g]=0 then existence_tail
3178
@<For all characters |g| generated by |c|...@>=
3181
lig_tag: @<Check ligature program of |c|@>;
3182
list_tag: check_existence_and_safety(char_remainder[c])
3183
('The character NEXTLARGER than');
3184
@.The character NEXTLARGER...@>
3185
ext_tag:@<Check the pieces of |exten[c]|@>;
3188
@ @<Check the pieces...@>=
3189
begin if exten[char_remainder[c]].b0>0 then
3190
check_existence_and_safety(exten[char_remainder[c]].b0)
3191
('TOP piece of character');
3192
@.TOP piece of character...@>
3193
if exten[char_remainder[c]].b1>0 then
3194
check_existence_and_safety(exten[char_remainder[c]].b1)
3195
('MID piece of character');
3196
@.MID piece of character...@>
3197
if exten[char_remainder[c]].b2>0 then
3198
check_existence_and_safety(exten[char_remainder[c]].b2)
3199
('BOT piece of character');
3200
@.BOT piece of character...@>
3201
check_existence_and_safety(exten[char_remainder[c]].b3)
3202
('REP piece of character');
3203
@.REP piece of character...@>
3206
@ @<Make sure that |c| is not the largest element of a charlist cycle@>=
3207
if char_tag[c]=list_tag then begin
3208
g:=char_remainder[c];
3209
while (g<c)and(char_tag[g]=list_tag) do g:=char_remainder[g];
3211
char_tag[c]:=no_tag;
3212
print('A cycle of NEXTLARGER characters has been broken at ');
3213
@.A cycle of NEXTLARGER...@>
3214
print_hex(c); print_ln('.');
3219
@!delta:fix_word; {size of the intervals needed for rounding}
3221
@ @d round_message(#)==if delta>0 then print_ln('I had to round some ',
3222
@.I had to round...@>
3223
#,'s by ',(((delta+1) div 2)/@'4000000):1:7,' units.')
3225
@<Put the width, height, depth, and italic lists into final form@>=
3228
top_width:=255; top_depth:=15; top_height:=15; top_italic:=63;
3231
top_width:=65535; top_depth:=255; top_height:=255; top_italic:=255;
3234
top_width:=65535; top_depth:=255; top_height:=255; top_italic:=255;
3237
delta:=shorten(width,max_width); set_indices(width,delta);
3238
round_message('width');@/
3239
delta:=shorten(height,max_height); set_indices(height,delta);
3240
round_message('height');@/
3241
delta:=shorten(depth,max_depth); set_indices(depth,delta);
3242
round_message('depth');@/
3243
delta:=shorten(italic,max_italic); set_indices(italic,delta);
3244
round_message('italic correction');
3246
@ @d clear_lig_kern_entry== {make an unconditional \.{STOP}}
3247
lig_kern[nl].b0:=255; lig_kern[nl].b1:=0;
3248
lig_kern[nl].b2:=0; lig_kern[nl].b3:=0
3250
@<Make sure the ligature/kerning program ends...@>=
3251
begin if bchar_label<xmax_label then begin {make room for it}
3252
clear_lig_kern_entry; incr(nl);
3253
end; {|bchar_label| will be stored later}
3254
while min_nl>nl do begin
3255
clear_lig_kern_entry; incr(nl);
3257
if (lig_kern[nl-1].b0 mod 256)=0 then
3258
lig_kern[nl-1].b0:=lig_kern[nl-1].b0 div 256 * 256 + stop_flag;
3261
@ It's not trivial to check for infinite loops generated by repeated
3262
insertion of ligature characters. But fortunately there is a nice
3263
algorithm for such testing, copied here from the program \.{TFtoPL}
3264
where it is explained further.
3266
@d simple=0 {$f(x,y)=z$}
3267
@d left_z=1 {$f(x,y)=f(z,y)$}
3268
@d right_z=2 {$f(x,y)=f(x,z)$}
3269
@d both_z=3 {$f(x,y)=f(f(x,z),y)$}
3270
@d pending=4 {$f(x,y)$ is being evaluated}
3274
@!lig_ptr:0..max_lig_steps; {an index into |lig_kern|}
3275
@!hash:array[0..hash_size] of integer;
3276
@!class:array[0..hash_size] of simple..pending;
3277
@!lig_z:array[0..hash_size] of xxchar_type;
3278
@!hash_ptr:0..hash_size; {the number of nonzero entries in |hash|}
3279
@!hash_list:array[0..hash_size] of 0..hash_size; {list of those nonzero entries}
3280
@!h,@!hh:0..hash_size; {indices into the hash table}
3281
@!tt:indx; {temporary register}
3282
@!x_lig_cycle,@!y_lig_cycle:xchar_type; {problematic ligature pair}
3285
hash_ptr:=0; y_lig_cycle:=xmax_char;
3286
for k:=0 to hash_size do hash[k]:=0;
3288
@ @d lig_exam==lig_kern[lig_ptr].b1
3289
@d lig_gen==lig_kern[lig_ptr].b3
3292
begin lig_ptr:=char_remainder[c];
3293
repeat if hash_input(lig_ptr,c) then begin
3294
if lig_kern[lig_ptr].b2<kern_flag then begin
3295
if lig_exam<>bchar then
3296
check_existence(lig_exam)('LIG character examined by');
3297
@.LIG character examined...@>
3298
check_existence(lig_gen)('LIG character generated by');
3299
@.LIG character generated...@>
3300
if lig_gen>=128 then if(c<128)or(c=bchar) then
3301
if(lig_exam<128)or(lig_exam=bchar) then seven_unsafe:=true;
3303
else if lig_exam<>bchar then
3304
check_existence(lig_exam)('KRN character examined by');
3305
@.KRN character examined...@>
3307
if (lig_kern[lig_ptr].b0 mod 256)>=stop_flag then lig_ptr:=nl
3308
else lig_ptr:=lig_ptr+1+lig_kern[lig_ptr].b0;
3312
@ The |hash_input| procedure is copied from \.{TFtoPL}, but it is made
3313
into a boolean function that returns |false| if the ligature command
3314
was masked by a previous one.
3316
@p function hash_input(@!p,@!c:indx):boolean;
3317
{enter data for character |c| and command in location |p|, unless it isn't new}
3318
label 30; {go here for a quick exit}
3319
var @!cc:simple..both_z; {class of data being entered}
3320
@!zz:char_type; {function value or ligature character being entered}
3321
@!y:char_type; {the character after the cursor}
3322
@!key:integer; {value to be stored in |hash|}
3323
@!t:integer; {temporary register for swapping}
3324
begin if hash_ptr=hash_size then
3325
begin hash_input:=false; goto 30;@+end;
3326
@<Compute the command parameters |y|, |cc|, and |zz|@>;
3327
key:=xmax_char*c+y+1; h:=(hash_mult*(key mod hash_size)) mod hash_size;
3328
while hash[h]>0 do begin
3329
if hash[h]<=key then begin
3330
if hash[h]=key then begin
3331
hash_input:=false; goto 30; {unused ligature command}
3333
t:=hash[h]; hash[h]:=key; key:=t; {do ordered-hash-table insertion}
3334
t:=class[h]; class[h]:=cc; cc:=t; {namely, do a swap}
3335
t:=lig_z[h]; lig_z[h]:=zz; zz:=t;
3337
if h>0 then decr(h)@+else h:=hash_size;
3339
hash[h]:=key; class[h]:=cc; lig_z[h]:=zz;
3340
incr(hash_ptr); hash_list[hash_ptr]:=h;
3344
@ @<Compute the command param...@>=
3345
y:=lig_kern[p].b1; t:=lig_kern[p].b2; cc:=simple;
3347
if t>=kern_flag then zz:=y
3350
0,6:do_nothing; {\.{LIG},\.{/LIG>}}
3351
5,11:zz:=y; {\.{LIG/>}, \.{/LIG/>>}}
3352
1,7:cc:=left_z; {\.{LIG/}, \.{/LIG/>}}
3353
2:cc:=right_z; {\.{/LIG}}
3354
3:cc:=both_z; {\.{/LIG/}}
3355
end; {there are no other cases}
3358
@ (More good stuff from \.{TFtoPL}.)
3360
@p function f(@!h,@!x,@!y:indx):indx; forward;@t\2@>
3361
{compute $f$ for arguments known to be in |hash[h]|}
3362
function eval(@!x,@!y:indx):indx; {compute $f(x,y)$ with hashtable lookup}
3363
var @!key:integer; {value sought in hash table}
3364
begin key:=xmax_char*x+y+1; h:=(hash_mult*(key mod hash_size)) mod hash_size;
3365
while hash[h]>key do
3366
if h>0 then decr(h)@+else h:=hash_size;
3367
if hash[h]<key then eval:=y {not in ordered hash table}
3368
else eval:=f(h,x,y);
3371
@ Pascal's beastly convention for |forward| declarations prevents us from
3372
saying |function f(h,x,y:indx):indx| here.
3375
begin case class[h] of
3377
left_z: begin class[h]:=pending; lig_z[h]:=eval(lig_z[h],y); class[h]:=simple;
3379
right_z: begin class[h]:=pending; lig_z[h]:=eval(x,lig_z[h]); class[h]:=simple;
3381
both_z: begin class[h]:=pending; lig_z[h]:=eval(eval(x,lig_z[h]),y);
3384
pending: begin x_lig_cycle:=x; y_lig_cycle:=y;
3385
lig_z[h]:=xxmax_char; class[h]:=simple;
3386
end; {the value |xxmax_char| will break all cycles, since it's not in |hash|}
3387
end; {there are no other cases}
3391
@ @<Check for infinite...@>=
3392
if hash_ptr<hash_size then for hh:=1 to hash_ptr do begin
3394
if class[tt]>simple then {make sure $f$ is well defined}
3395
tt:=f(tt,(hash[tt]-1)div xmax_char,(hash[tt]-1)mod xmax_char);
3397
if(hash_ptr=hash_size)or(y_lig_cycle<xmax_char) then begin
3398
if hash_ptr<hash_size then begin
3399
print('Infinite ligature loop starting with ');
3400
@.Infinite ligature loop...@>
3401
if x_lig_cycle=xmax_char
3402
then print('boundary')@+else print_hex(x_lig_cycle);
3403
print(' and '); print_hex(y_lig_cycle); print_ln('!');
3405
else print_ln('Sorry, I haven''t room for so many ligature/kern pairs!');
3406
@.Sorry, I haven't room...@>
3407
print_ln('All ligatures will be cleared.');
3408
for c:=0 to max_char do if char_tag[c]=lig_tag then begin
3409
char_tag[c]:=no_tag; char_remainder[c]:=0;
3411
nl:=0; bchar:=xmax_char; bchar_label:=xmax_label;
3414
@ The lig/kern program may still contain references to nonexistent characters,
3415
if parts of that program are never used. Similarly, there may be extensible
3416
characters that are never used, because they were overridden by
3417
\.{NEXTLARGER}, say. This would produce an invalid \.{TFM} file; so we
3418
must fix such errors.
3420
@d double_check_tail(#)==@t\1@>if char_wd[0]=0
3421
then char_wd[0]:=sort_in(width,0);
3422
print('Unused ',#,' refers to nonexistent character ');
3423
print_hex(c); print_ln('!');
3426
@d double_check_lig(#)==begin c:=lig_kern[lig_ptr].#;
3427
if char_wd[c]=0 then if c<>bchar then
3428
begin lig_kern[lig_ptr].#:=0; double_check_tail
3429
@d double_check_ext(#)==begin c:=exten[g].#;
3430
if c>0 then if char_wd[c]=0 then
3431
begin exten[g].#:=0; double_check_tail
3432
@d double_check_rep(#)==begin c:=exten[g].#;
3433
if char_wd[c]=0 then
3434
begin exten[g].#:=0; double_check_tail
3437
if nl>0 then for lig_ptr:=0 to nl-1 do
3438
if (lig_kern[lig_ptr].b0 div 256)=0 then begin
3439
if lig_kern[lig_ptr].b2<kern_flag then begin
3440
if lig_kern[lig_ptr].b0<255 then begin
3441
double_check_lig(b1)('LIG step'); double_check_lig(b3)('LIG step');
3444
else double_check_lig(b1)('KRN step');
3446
@.Unused LIG step...@>
3447
@.Unused KRN step...@>
3448
if ne>0 then for g:=0 to ne-1 do begin
3449
double_check_ext(b0)('VARCHAR TOP');
3450
double_check_ext(b1)('VARCHAR MID');
3451
double_check_ext(b2)('VARCHAR BOT');
3452
double_check_rep(b3)('VARCHAR REP');
3453
@.Unused VARCHAR...@>
3456
@* The TFM output phase.
3457
Now that we know how to get all of the font data correctly stored in
3458
\.{VPtoVF}'s memory, it only remains to write the answers out.
3460
First of all, it is convenient to have an abbreviation for output to the
3463
@d out(#)==write(tfm_file,#)
3465
@p procedure out_int(@!x:integer);
3466
begin out_four(out);
3470
@ The general plan for producing \.{TFM} files is long but simple:
3472
@<Do the font metric output@>=
3473
compute_subfile_sizes;
3474
output_subfile_sizes;
3475
@<Output the header block@>;
3476
output_new_information_ofm;
3477
output_character_info;
3478
@<Output the dimensions themselves@>;
3479
@<Output the ligature/kern program@>;
3480
@<Output the extensible character recipes@>;
3481
@<Output the parameters@>
3483
@ A \.{TFM} file begins with 12 numbers that tell how big its subfiles are.
3484
We already know most of these numbers; for example, the number of distinct
3485
widths is |memory[width]+1|, where the $+1$ accounts for the zero width that
3486
is always supposed to be present. But we still should compute the beginning
3487
and ending character codes (|bc| and |ec|), the number of header words (|lh|),
3488
and the total number of words in the \.{TFM} file (|lf|).
3491
@!bc:char_type; {the smallest character code in the font}
3492
@!ec:char_type; {the largest character code in the font}
3493
@!lh:char_type; {the number of words in the header block}
3494
@!lf:unsigned_integer; {the number of words in the entire \.{TFM} file}
3495
@!not_found:boolean; {has a font character been found?}
3496
@!temp_width:fix_word; {width being used to compute a check sum}
3497
@!ncw,@!nco,@!npc:integer;
3499
@ It might turn out that no characters exist at all. But \.{VPtoVF} keeps
3500
going and writes the \.{TFM} anyway. In this case |ec| will be~0 and |bc|
3503
@<Compute the subfile sizes@>=
3506
lh:=header_ptr div 4;@/
3507
not_found:=true; bc:=0;
3509
if (char_wd[bc]>0)or(bc=255) then not_found:=false
3511
not_found:=true; ec:=255;
3513
if (char_wd[ec]>0)or(ec=0) then not_found:=false
3515
if bc>ec then bc:=1;
3516
incr(memory[width]); incr(memory[height]); incr(memory[depth]);
3517
incr(memory[italic]);@/
3518
@<Compute the ligature/kern program offset@>;
3519
lf:=6+lh+(ec-bc+1)+memory[width]+memory[height]+memory[depth]+
3520
memory[italic]+nl+lk_offset+nk+ne+np;
3523
lh:=header_ptr div 4;@/
3524
not_found:=true; bc:=0;
3526
if (char_wd[bc]>0)or(bc=max_char) then not_found:=false
3528
not_found:=true; ec:=max_char;
3530
if (char_wd[ec]>0)or(ec=0) then not_found:=false
3532
if bc>ec then bc:=1;
3533
incr(memory[width]); incr(memory[height]); incr(memory[depth]);
3534
incr(memory[italic]);@/
3535
@<Compute the ligature/kern program offset@>;
3536
lf:=14+lh+2*(ec-bc+1)+memory[width]+memory[height]+memory[depth]+
3537
memory[italic]+2*nl+lk_offset+nk+2*ne+np;
3540
lh:=header_ptr div 4;@/
3541
not_found:=true; bc:=0;
3543
if (char_wd[bc]>0)or(bc=max_char) then not_found:=false
3545
not_found:=true; ec:=max_char;
3547
if (char_wd[ec]>0)or(ec=0) then not_found:=false
3549
if bc>ec then bc:=1;
3550
incr(memory[width]); incr(memory[height]); incr(memory[depth]);
3551
incr(memory[italic]);@/
3552
@<Compute the ligature/kern program offset@>;
3553
@<Compute the character info size@>;
3554
lf:=29+lh+ncw+memory[width]+memory[height]+memory[depth]+
3555
memory[italic]+2*(nl+lk_offset)+nk+2*ne+np+
3556
nki+nwi+nkf+nwf+nkm+nwm+nkr+nwr+nkg+nwg+nkp+nwp;
3557
nco:=29+lh+nki+nwi+nkf+nwf+nkm+nwm+nkr+nwr+nkg+nwg+nkp+nwp;
3561
@ @d out_size(#)==out((#) div 256); out((#) mod 256)
3562
@d out_integer(#)==out((#) div @"1000000);
3563
out(((#) mod @"1000000) div @"10000);
3564
out(((#) mod @"10000) div @"100);
3567
@<Output the subfile sizes@>=
3570
out_size(lf); out_size(lh); out_size(bc); out_size(ec);
3571
out_size(memory[width]); out_size(memory[height]);
3572
out_size(memory[depth]); out_size(memory[italic]);
3573
out_size(nl+lk_offset); out_size(nk); out_size(ne); out_size(np);
3577
out_integer(lf); out_integer(lh); out_integer(bc); out_integer(ec);
3578
out_integer(memory[width]); out_integer(memory[height]);
3579
out_integer(memory[depth]); out_integer(memory[italic]);
3580
out_integer(nl+lk_offset); out_integer(nk);
3581
out_integer(ne); out_integer(np); out_integer(font_dir);
3585
out_integer(lf); out_integer(lh);
3586
out_integer(bc); out_integer(ec);
3587
out_integer(memory[width]); out_integer(memory[height]);
3588
out_integer(memory[depth]); out_integer(memory[italic]);
3589
out_integer(nl+lk_offset); out_integer(nk);
3590
out_integer(ne); out_integer(np); out_integer(font_dir);
3591
out_integer(nco); out_integer(ncw); out_integer(npc);
3592
out_integer(nki); out_integer(nwi); out_integer(nkf); out_integer(nwf);
3593
out_integer(nkm); out_integer(nwm); out_integer(nkr); out_integer(nwr);
3594
out_integer(nkg); out_integer(nwg); out_integer(nkp); out_integer(nwp);
3598
@ The routines that follow need a few temporary variables of different types.
3601
@!j:0..max_header_bytes; {index into |header_bytes|}
3602
@!p:pointer; {index into |memory|}
3603
@!q:width..italic; {runs through the list heads for dimensions}
3604
@!par_ptr:0..max_param_words; {runs through the parameters}
3606
@ The header block follows the subfile sizes. The necessary information all
3607
appears in |header_bytes|, except that the design size and the seven-bit-safe
3608
flag must still be set.
3610
@<Output the header block@>=
3611
if not check_sum_specified then @<Compute the check sum@>;
3612
header_bytes[design_size_loc]:=design_size div @'100000000;
3613
{this works since |design_size>0|}
3614
header_bytes[design_size_loc+1]:=(design_size div @'200000) mod 256;
3615
header_bytes[design_size_loc+2]:=(design_size div 256) mod 256;
3616
header_bytes[design_size_loc+3]:=design_size mod 256;
3617
if not seven_unsafe then header_bytes[seven_flag_loc]:=128;
3618
for j:=0 to header_ptr-1 do out(header_bytes[j]);
3620
@ @<Compute the check sum@>=
3621
begin c0:=bc; c1:=ec; c2:=bc; c3:=ec;
3622
for c:=bc to ec do if char_wd[c]>0 then begin
3623
temp_width:=memory[char_wd[c]];
3624
if design_units<>unity then
3625
temp_width:=round((temp_width/design_units)*1048576.0);
3626
temp_width:=temp_width + (c+4)*@'20000000; {this should be positive}
3627
c0:=(c0+c0+temp_width) mod 255;
3628
c1:=(c1+c1+temp_width) mod 253;
3629
c2:=(c2+c2+temp_width) mod 251;
3630
c3:=(c3+c3+temp_width) mod 247;
3632
header_bytes[check_sum_loc]:=c0;
3633
header_bytes[check_sum_loc+1]:=c1;
3634
header_bytes[check_sum_loc+2]:=c2;
3635
header_bytes[check_sum_loc+3]:=c3;
3642
@<Compute the character info size@>=
3643
if ofm_level=1 then begin
3646
npc:=nki+nkf+nkr+nkg+nkcp+1
3647
else if nkcg>-1 then
3648
npc:=nki+nkf+nkr+nkcg+1
3649
else if nkcr>-1 then
3651
else if nkcf>-1 then
3653
else if nkci>-1 then
3657
needed_space:=(12+npc*2) div 4;
3658
extra_bytes:=(needed_space*4) - (10+npc*2);
3659
for c:=bc to ec do begin
3660
if char_original[c]=c then begin
3663
while (not diff) and (cprime<=ec) do begin
3664
if index[char_wd[c]]<>index[char_wd[cprime]] then diff:=true;
3665
if index[char_ht[c]]<>index[char_ht[cprime]] then diff:=true;
3666
if index[char_dp[c]]<>index[char_dp[cprime]] then diff:=true;
3667
if index[char_ic[c]]<>index[char_ic[cprime]] then diff:=true;
3668
if char_remainder[c]<>char_remainder[cprime] then diff:=true;
3669
for tab:=0 to npc-1 do begin
3670
if char_table[c,tab]<>char_table[cprime,tab] then diff:=true;
3672
if not diff then begin
3673
char_original[cprime]:=c;
3677
if cprime>(c+1) then begin
3678
char_repeats[c]:=cprime-c-1;
3680
ncw:=ncw+needed_space;
3685
@ The next block contains packed |char_info|.
3687
@d out_two(#)==out((#) div 256); out((#) mod 256)
3689
@d out_three(#)==out((#) div 65536); out_two((#) mod 65536)
3692
@<Output the character info@>=
3697
out(index[char_wd[c]]);
3698
out(index[char_ht[c]]*16+index[char_dp[c]]);
3699
out(index[char_ic[c]]*4+char_tag[c]);
3700
out(char_remainder[c]);
3703
out(index[char_wd[c]] div 256); out(index[char_wd[c]] mod 256);
3704
out(index[char_ht[c]]); out(index[char_dp[c]]);
3705
out(index[char_ic[c]] div 64);out((index[char_ic[c]] mod 64)*4+char_tag[c]);
3706
out(char_remainder[c] div 256); out(char_remainder[c] mod 256);
3709
if c=char_original[c] then begin
3710
out(index[char_wd[c]] div 256); out(index[char_wd[c]] mod 256);
3711
out(index[char_ht[c]]); out(index[char_dp[c]]);
3712
out(index[char_ic[c]]);
3714
if char_extended_tag[c] then begin
3718
out(char_remainder[c] div 256); out(char_remainder[c] mod 256);
3719
out_size(char_repeats[c]);
3720
for tab:=0 to npc-1 do begin
3721
out(char_table[c,tab] div 256); out(char_table[c,tab] mod 256);
3723
for tab:=1 to extra_bytes do begin
3730
@ When a scaled quantity is output, we may need to divide it by |design_units|.
3731
The following subroutine takes care of this, using floating point arithmetic
3732
only if |design_units<>1.0|.
3734
@p procedure out_scaled(x:fix_word); {outputs a scaled |fix_word|}
3735
var @!n:byte; {the first byte after the sign}
3736
@!m:0..65535; {the two least significant bytes}
3737
begin if abs(x/design_units)>=16.0 then begin
3738
print_ln('The relative dimension ',x/@'4000000:1:3,
3740
@.The relative dimension...@>
3741
print(' (Must be less than 16*designsize');
3742
if design_units<>unity then print(' =',design_units/@'200000:1:3,
3744
print_ln(')'); x:=0;
3746
if design_units<>unity then x:=round((x/design_units)*1048576.0);
3748
out(255); x:=x+@'100000000;
3753
if x>=@'100000000 then x:=@'77777777;
3755
n:=x div @'200000; m:=x mod @'200000;
3756
out(n); out(m div 256); out(m mod 256);
3759
@ We have output the packed indices for individual characters.
3760
The scaled widths, heights, depths, and italic corrections are next.
3762
@<Output the dimensions themselves@>=
3763
for q:=width to italic do begin
3764
out(0); out(0); out(0); out(0); {output the zero word}
3765
p:=link[q]; {head of list}
3767
out_scaled(memory[p]);
3772
@ One embarrassing problem remains: The ligature/kern program might be very
3773
long, but the starting addresses in |char_remainder| can be at most~65535.
3774
Therefore we need to output some indirect address information; we want to
3775
compute |lk_offset| so that addition of |lk_offset| to all remainders makes
3776
all but |lk_offset| distinct remainders less than~65536.
3778
For this we need a sorted table of all relevant remainders.
3781
@!label_table:array[xchar_type] of record
3782
@!rr: -1..xmax_label; {sorted label values}
3783
@!cc: char_type; {associated characters}
3785
@!label_ptr:xchar_type; {index of highest entry in |label_table|}
3786
@!sort_ptr:xchar_type; {index into |label_table|}
3787
@!lk_offset:xchar_type; {smallest offset value that might work}
3788
@!t:0..xmax_label; {label value that is being redirected}
3789
@!extra_loc_needed:boolean; {do we need a special word for |bchar|?}
3791
@ @<Compute the ligature/kern program offset@>=
3792
@<Insert all labels into |label_table|@>;
3793
if bchar<xmax_char then begin
3794
extra_loc_needed:=true; lk_offset:=1;
3797
extra_loc_needed:=false; lk_offset:=0;
3799
@<Find the minimum |lk_offset| and adjust all remainders@>;
3800
if bchar_label<xmax_label then begin
3801
lig_kern[nl-1].b2:=(bchar_label+lk_offset)div 65536;
3802
lig_kern[nl-1].b3:=(bchar_label+lk_offset)mod 65536;
3805
@ @<Insert all labels...@>=
3806
label_ptr:=0; label_table[0].rr:=-1; {sentinel}
3807
for c:=bc to ec do if char_tag[c]=lig_tag then begin
3808
sort_ptr:=label_ptr; {there's a hole at position |sort_ptr+1|}
3809
while label_table[sort_ptr].rr>char_remainder[c] do begin
3810
label_table[sort_ptr+1]:=label_table[sort_ptr];
3811
decr(sort_ptr); {move the hole}
3813
label_table[sort_ptr+1].cc:=c;
3814
label_table[sort_ptr+1].rr:=char_remainder[c];
3818
@ @<Find the minimum |lk_offset| and adjust all remainders@>=
3819
begin sort_ptr:=label_ptr; {the largest unallocated label}
3820
if ofm_level=-1 then begin
3821
if label_table[sort_ptr].rr+lk_offset > 255 then begin
3822
lk_offset:=0; extra_loc_needed:=false; {location 0 can do double duty}
3823
repeat char_remainder[label_table[sort_ptr].cc]:=lk_offset;
3824
while label_table[sort_ptr-1].rr=label_table[sort_ptr].rr do begin
3825
decr(sort_ptr); char_remainder[label_table[sort_ptr].cc]:=lk_offset;
3827
incr(lk_offset); decr(sort_ptr);
3828
until lk_offset+label_table[sort_ptr].rr<256;
3829
{N.B.: |lk_offset=256| satisfies this when |sort_ptr=0|}
3833
if label_table[sort_ptr].rr+lk_offset > 65535 then begin
3834
lk_offset:=0; extra_loc_needed:=false; {location 0 can do double duty}
3835
repeat char_remainder[label_table[sort_ptr].cc]:=lk_offset;
3836
while label_table[sort_ptr-1].rr=label_table[sort_ptr].rr do begin
3837
decr(sort_ptr); char_remainder[label_table[sort_ptr].cc]:=lk_offset;
3839
incr(lk_offset); decr(sort_ptr);
3840
until lk_offset+label_table[sort_ptr].rr<65536;
3841
{N.B.: |lk_offset=65536| satisfies this when |sort_ptr=0|}
3845
while sort_ptr>0 do begin
3846
char_remainder[label_table[sort_ptr].cc]:=
3847
char_remainder[label_table[sort_ptr].cc]+lk_offset;
3852
@ @<Output the ligature/kern program@>=
3853
if ofm_level=-1 then begin
3854
if extra_loc_needed then begin {|lk_offset=1|}
3855
out(255); out(bchar); out(0); out(0);
3857
else for sort_ptr:=1 to lk_offset do begin {output the redirection specs}
3858
t:=label_table[label_ptr].rr;
3859
if bchar<256 then begin
3860
out(255); out(bchar);
3865
out_size(t+lk_offset);
3866
repeat decr(label_ptr); until label_table[label_ptr].rr<t;
3868
if nl>0 then for lig_ptr:=0 to nl-1 do begin
3869
out(lig_kern[lig_ptr].b0);
3870
out(lig_kern[lig_ptr].b1);
3871
out(lig_kern[lig_ptr].b2);
3872
out(lig_kern[lig_ptr].b3);
3874
if nk>0 then for krn_ptr:=0 to nk-1 do out_scaled(kern[krn_ptr])
3877
if extra_loc_needed then begin {|lk_offset=1|}
3878
out_size(255); out_size(bchar); out_size(0); out_size(0);
3880
else for sort_ptr:=1 to lk_offset do begin {output the redirection specs}
3881
t:=label_table[label_ptr].rr;
3882
if bchar<xmax_char then begin
3883
out_size(255); out_size(bchar);
3886
out_size(254); out_size(0);
3888
out_size((t+lk_offset) div 256);
3889
out_size((t+lk_offset) mod 256);
3890
repeat decr(label_ptr); until label_table[label_ptr].rr<t;
3892
if nl>0 then for lig_ptr:=0 to nl-1 do begin
3893
out_size(lig_kern[lig_ptr].b0);
3894
out_size(lig_kern[lig_ptr].b1);
3895
out_size(lig_kern[lig_ptr].b2);
3896
out_size(lig_kern[lig_ptr].b3);
3898
if nk>0 then for krn_ptr:=0 to nk-1 do out_scaled(kern[krn_ptr])
3901
@ @<Output the extensible character recipes@>=
3902
if ofm_level=-1 then begin
3903
if ne>0 then for c:=0 to ne-1 do begin
3911
if ne>0 then for c:=0 to ne-1 do begin
3912
out_size(exten[c].b0);
3913
out_size(exten[c].b1);
3914
out_size(exten[c].b2);
3915
out_size(exten[c].b3);
3919
@ For our grand finale, we wind everything up by outputting the parameters.
3921
@<Output the parameters@>=
3922
for par_ptr:=1 to np do begin
3924
@<Output the slant (|param[1]|) without scaling@>
3925
else out_scaled(param[par_ptr]);
3928
@ @<Output the slant...@>=
3929
begin if param[1]<0 then begin
3930
param[1]:=param[1]+@'10000000000;
3931
out((param[1] div @'100000000)+256-64);
3933
else out(param[1] div @'100000000);
3934
out((param[1] div @'200000) mod 256);
3935
out((param[1] div 256) mod 256);
3936
out(param[1] mod 256);
3939
@* The VF output phase.
3940
Output to |vf_file| is considerably simpler.
3942
@d id_byte=202 {current version of \.{VF} format}
3943
@d vout(#)==write(vf_file,#)
3946
@!vcount:integer; {number of bytes written to |vf_file|}
3948
@ We need a routine to output integers as four bytes. Negative values
3949
will never be less than $-2^{24}$.
3951
@p procedure vout_int(@!x:integer);
3952
begin if x>=0 then vout(x div @'100000000)
3954
vout(255); x:=x+@'100000000;
3956
vout((x div @'200000) mod 256);
3957
vout((x div @'400) mod 256); vout(x mod 256);
3960
@ @<Do the \.{VF} output@>=
3961
vout(pre); vout(id_byte); vout(vtitle_length);
3962
for k:=0 to vtitle_length-1 do vout(vf[vtitle_start+k]);
3963
for k:=check_sum_loc to design_size_loc+3 do vout(header_bytes[k]);
3964
vcount:=vtitle_length+11;
3965
for cur_font:=0 to font_ptr-1 do @<Output a local font definition@>;
3966
for c:=bc to ec do if char_wd[c]>0 then
3967
@<Output a packet for character |c|@>;
3968
repeat vout(post); incr(vcount);
3969
until vcount mod 4 = 0
3971
@ @<Output a local font definition@>=
3972
begin vfout_fntdef(cur_font);@/
3973
vout(font_checksum[cur_font].b0);
3974
vout(font_checksum[cur_font].b1);
3975
vout(font_checksum[cur_font].b2);
3976
vout(font_checksum[cur_font].b3);
3977
vout_int(font_at[cur_font]);
3978
vout_int(font_dsize[cur_font]);
3979
vout(farea_length[cur_font]);
3980
vout(fname_length[cur_font]);
3981
for k:=0 to farea_length[cur_font]-1 do vout(vf[farea_start[cur_font]+k]);
3982
if fname_start[cur_font]=vf_size then begin
3983
vout("N"); vout("U"); vout("L"); vout("L");
3985
else for k:=0 to fname_length[cur_font]-1 do vout(vf[fname_start[cur_font]+k]);
3986
vcount:=vcount+12+farea_length[cur_font]+fname_length[cur_font];
3989
@ @<Output a packet for character |c|@>=
3990
begin x:=memory[char_wd[c]];
3991
if design_units<>unity then x:=round((x/design_units)*1048576.0);
3992
if (packet_length[c]>241)or(x<0)or(x>=@'100000000)or(c<0)or(c>255) then begin
3993
vout(242); vout_int(packet_length[c]); vfout_char(c); vout_int(x);
3994
vcount:=vcount+13+packet_length[c];
3997
vout(packet_length[c]); vout(c); vout(x div @'200000);
3998
vout((x div @'400) mod 256); vout(x mod 256);
3999
vcount:=vcount+5+packet_length[c];
4001
if packet_start[c]=vf_size then
4003
else for k:=0 to packet_length[c]-1 do vout(vf[packet_start[c]+k]);
4006
@* The main program.
4007
The routines sketched out so far need to be packaged into separate procedures,
4008
on some systems, since some \PASCAL\ compilers place a strict limit on the
4009
size of a routine. The packaging is done here in an attempt to avoid some
4010
system-dependent changes.
4012
@p procedure param_enter;
4013
begin @<Enter the parameter names@>;
4016
procedure vpl_enter;
4017
begin @<Enter all the \.{VPL} names@>;
4020
procedure name_enter; {enter all names and their equivalents}
4021
begin @<Enter all the \.{PL} names...@>;
4022
vpl_enter; param_enter;
4025
procedure read_lig_kern;
4026
var @!krn_ptr:0..max_kerns; {an index into |kern|}
4027
@!c:byte; {runs through all character codes}
4028
begin @<Read ligature/kern list@>;
4031
procedure output_new_information_ofm;
4032
begin @<Output the new information for OFM files@>;
4035
procedure compute_new_header_ofm;
4036
begin @<Compute the new header information for OFM files@>;
4039
procedure finish_extended_font;
4040
begin @<Finish up the extended font stuff@>;
4043
procedure output_subfile_sizes;
4044
begin @<Output the subfile sizes@>;
4047
procedure compute_subfile_sizes;
4048
begin @<Compute the subfile sizes@>;
4051
procedure output_character_info;
4052
begin @<Output the character info@>;
4056
procedure read_font_rule_list;
4057
begin @<Read font rule list@>;
4060
procedure read_font_glue_list;
4061
begin @<Read font glue list@>;
4064
procedure read_font_penalty_list;
4065
begin @<Read font penalty list@>;
4068
procedure read_font_mvalue_list;
4069
begin @<Read font mvalue list@>;
4072
procedure read_font_fvalue_list;
4073
begin @<Read font fvalue list@>;
4076
procedure read_font_ivalue_list;
4077
begin @<Read font ivalue list@>;
4080
procedure read_repeated_character_info;
4081
begin @<Read repeated character info@>;
4084
procedure read_lig_kern_command;
4085
begin @<Read a ligature/kern command@>;
4088
procedure read_character_property;
4089
begin @<Read a character property@>;
4092
procedure read_char_info;
4093
begin @<Read character info list@>;
4096
procedure read_input;
4097
var @!c:byte; {header or parameter index}
4098
begin @<Read all the input@>;
4101
procedure corr_and_check;
4102
var @!c:xchar_type; {runs through all character codes}
4103
@!hh:0..hash_size; {an index into |hash_list|}
4104
@!lig_ptr:0..max_lig_steps; {an index into |lig_kern|}
4105
@!g:byte; {a character generated by the current character |c|}
4106
begin @<Correct and check the information@>
4109
procedure vf_output;
4110
var @!c:char_type; {runs through all character codes}
4111
@!cur_font:xfont_type; {runs through all local fonts}
4112
@!k:integer; {loop index}
4113
begin @<Do the \.{VF} output@>;
4116
@ Here is where \.{VPtoVF} begins and ends.
4118
@p begin initialize;@/
4120
read_input; print_ln('.');@/
4122
@<Do the font metric output@>;
4127
@!ofm_level:integer;
4130
ofm_level:=0; {Suppose that it is a level 0 OFM file}
4132
@ @<Read OFM level code@>=
4134
ofm_level:=get_integer;
4135
if (ofm_level<0) or (ofm_level>1) then begin
4136
flush_error('OFMLEVEL must be 0 or 1 -- 1 assumed');
4141
@ @<Read font direction code@>=
4145
until cur_char<>" ";
4147
"T": begin get_next;
4148
if cur_char="L" then font_dir:=0
4149
else if cur_char="R" then font_dir:=2;
4151
"B": begin get_next;
4152
if cur_char="L" then font_dir:=4
4153
else if cur_char="R" then font_dir:=6;
4155
"R": begin get_next;
4156
if cur_char="T" then font_dir:=5
4157
else if cur_char="B" then font_dir:=7;
4159
"L": begin get_next;
4160
if cur_char="T" then font_dir:=1
4161
else if cur_char="B" then font_dir:=3;
4164
while cur_char<>")" do get_next;
4165
if font_dir = -1 then begin
4166
flush_error('FONTDIR must be valid direction, -- TR assumed');
4171
@ @<Read natural font direction code@>=
4175
until cur_char<>" ";
4177
"T": begin get_next;
4178
if cur_char="L" then font_dir:=8
4179
else if cur_char="R" then font_dir:=10;
4181
"B": begin get_next;
4182
if cur_char="L" then font_dir:=12
4183
else if cur_char="R" then font_dir:=14;
4185
"R": begin get_next;
4186
if cur_char="T" then font_dir:=13
4187
else if cur_char="B" then font_dir:=15;
4189
"L": begin get_next;
4190
if cur_char="T" then font_dir:=9
4191
else if cur_char="B" then font_dir:=11;
4194
while cur_char<>")" do get_next;
4195
if font_dir = -1 then begin
4196
flush_error('NFONTDIR must be valid direction, -- TR assumed');
4202
Here are some general values for the various entries.
4203
They can all be changed.
4205
@d arrays_per_kind==20
4206
@d entries_per_array==200
4209
@!rule_arrays=arrays_per_kind;
4210
@!rule_entries=entries_per_array;
4213
rule_array_type=0..rule_arrays;
4214
rule_entry_type=0..rule_entries;
4218
rn_height: fix_word;
4223
@!rules:array[rule_array_type,rule_entry_type] of rule_node;
4224
@!npr:array[rule_array_type] of integer;
4232
for r_array := 0 to rule_arrays do begin
4234
@<Null out the rule@>;
4239
@ @<Read font rule list@>=
4242
flush_error('All parameter tables must appear before character info');
4243
r_array:=get_integer;
4244
if r_array>rule_arrays then
4245
flush_error('This FONTRULE table index is too big for my present size')
4246
else if r_array<0 then
4247
flush_error('This FONTRULE index is negative')
4249
if r_array>nkr then nkr:=r_array;
4250
while level=1 do begin
4251
while cur_char=" " do get_next;
4252
if cur_char="(" then @<Read a rule@>
4253
else if cur_char=")" then skip_to_end_of_item
4256
finish_inner_property_list;
4263
if cur_code=comment_code then skip_to_end_of_item
4264
else if cur_code<>rule_code then
4265
flush_error('This property name doesn''t belong in a RULE list')
4267
r_number:=get_integer;
4268
if r_number>rule_entries then
4269
flush_error('This RULE index is too big for my present table size')
4270
else if r_number<0 then
4271
flush_error('This RULE index is negative')
4273
while npr[r_array]<r_number do begin
4274
incr(npr[r_array]); @<Null out the rule@>;
4276
@<Read all of a rule's values@>;
4277
finish_the_property;
4282
@ @<Null out the rule@>=
4284
rules[r_array,npr[r_array]].rn_width:=0;
4285
rules[r_array,npr[r_array]].rn_depth:=0;
4286
rules[r_array,npr[r_array]].rn_height:=0;
4289
@ @<Read all of a rule's values@>=
4291
while level=2 do begin
4292
while cur_char=" " do get_next;
4293
if cur_char="(" then @<Read a single rule value@>
4294
else if cur_char=")" then skip_to_end_of_item
4297
finish_inner_property_list;
4300
@ @<Read a single rule value@>=
4305
rules[r_array,r_number].rn_width:=get_fix;
4307
rules[r_array,r_number].rn_height:=get_fix;
4309
rules[r_array,r_number].rn_depth:=get_fix;
4311
finish_the_property;
4314
@ @<Header information for rules@>=
4317
for r_array := 0 to nkr do begin
4319
nwr := nwr + 3*npr[r_array];
4324
@ @<Output the rules@>=
4326
for r_array:= 0 to nkr-1 do
4327
for r_number:=0 to npr[r_array]-1 do begin
4328
out_scaled(rules[r_array,r_number].rn_width);
4329
out_scaled(rules[r_array,r_number].rn_height);
4330
out_scaled(rules[r_array,r_number].rn_depth);
4334
@ @<Output the rule headers@>=
4336
for r_array:= 0 to nkr-1 do begin
4337
out_integer(npr[r_array]);
4342
@!glue_arrays=arrays_per_kind;
4343
@!glue_entries=entries_per_array;
4362
glue_array_type=0..glue_arrays;
4363
glue_entry_type=0..glue_entries;
4367
gn_stretch: fix_word;
4368
gn_shrink: fix_word;
4370
gn_arg_type: g_space..g_char;
4371
gn_stretch_order: integer;
4372
gn_shrink_order: integer;
4373
gn_argument: integer;
4377
@!glues:array[glue_array_type,glue_entry_type] of glue_node;
4378
@!npg:array[glue_array_type] of integer;
4387
for g_array := 0 to glue_arrays do
4390
@<Null out the glue@>;
4395
@ @<Read font glue list@>=
4398
flush_error('All parameter tables must appear before character info');
4399
g_array:=get_integer;
4400
if g_array>glue_arrays then
4401
flush_error('This FONTGLUE table index is too big for my present size')
4402
else if g_array<0 then
4403
flush_error('This FONTGLUE index is negative')
4405
if g_array>nkg then nkg:=g_array;
4406
while level=1 do begin
4407
while cur_char=" " do get_next;
4408
if cur_char="(" then @<Read a glue@>
4409
else if cur_char=")" then skip_to_end_of_item
4412
finish_inner_property_list;
4419
if cur_code=comment_code then skip_to_end_of_item
4420
else if cur_code<>glue_code then
4421
flush_error('This property name doesn''t belong in a GLUE list')
4423
g_number:=get_integer;
4424
if g_number>glue_entries then
4425
flush_error('This GLUE index is too big for my present table size')
4426
else if g_number<0 then
4427
flush_error('This GLUE index is negative')
4429
while npg[g_array]<g_number do begin
4430
incr(npg[g_array]); @<Null out the glue@>;
4432
@<Read all of a glue's values@>;
4433
finish_the_property;
4438
@ @<Null out the glue@>=
4440
glues[g_array,npg[g_array]].gn_width:=0;
4441
glues[g_array,npg[g_array]].gn_stretch:=0;
4442
glues[g_array,npg[g_array]].gn_shrink:=0;
4443
glues[g_array,npg[g_array]].gn_type:=0;
4444
glues[g_array,npg[g_array]].gn_arg_type:=0;
4445
glues[g_array,npg[g_array]].gn_stretch_order:=0;
4446
glues[g_array,npg[g_array]].gn_shrink_order:=0;
4447
glues[g_array,npg[g_array]].gn_argument:=0;
4450
@ @<Read all of a glue's values@>=
4452
while level=2 do begin
4453
while cur_char=" " do get_next;
4454
if cur_char="(" then @<Read a single glue value@>
4455
else if cur_char=")" then skip_to_end_of_item
4458
finish_inner_property_list;
4461
@ @<Read a single glue value@>=
4466
glues[g_array,g_number].gn_width:=get_fix;
4468
glues[g_array,g_number].gn_stretch:=get_fix;
4470
glues[g_array,g_number].gn_shrink:=get_fix;
4471
glue_type_code: begin
4472
g_byte:=get_integer;
4473
if (g_byte<0) or (g_byte>3) then begin
4476
glues[g_array,g_number].gn_type:=g_byte;
4478
glue_stretch_order_code: begin
4479
g_byte:=get_integer;
4480
if (g_byte<0) or (g_byte>4) then begin
4483
glues[g_array,g_number].gn_stretch_order:=g_byte;
4485
glue_shrink_order_code: begin
4486
g_byte:=get_integer;
4487
if (g_byte<0) or (g_byte>4) then begin
4490
glues[g_array,g_number].gn_shrink_order:=g_byte;
4492
glue_char_code: begin
4493
glues[g_array,g_number].gn_argument:=get_integer;
4494
glues[g_array,g_number].gn_arg_type:=g_char;
4496
glue_rule_code: begin
4497
glues[g_array,g_number].gn_argument:=get_integer;
4498
glues[g_array,g_number].gn_arg_type:=g_rule;
4501
finish_the_property;
4504
@ @<Header information for glues@>=
4507
for g_array := 0 to nkg do begin
4509
nwg := nwg + 4*npg[g_array];
4514
@ @<Output the glues@>=
4516
for g_array:= 0 to nkg-1 do
4517
for g_number:=0 to npg[g_array]-1 do begin
4518
g_byte:=glues[g_array,g_number].gn_type*16+
4519
glues[g_array,g_number].gn_arg_type;
4521
g_byte:=glues[g_array,g_number].gn_stretch_order*16+
4522
glues[g_array,g_number].gn_shrink_order;
4524
g_byte:=glues[g_array,g_number].gn_argument div 256;
4526
g_byte:=glues[g_array,g_number].gn_argument mod 256;
4528
out_scaled(glues[g_array,g_number].gn_width);
4529
out_scaled(glues[g_array,g_number].gn_stretch);
4530
out_scaled(glues[g_array,g_number].gn_shrink);
4534
@ @<Output the glue headers@>=
4536
for g_array:= 0 to nkg-1 do begin
4537
out_integer(npg[g_array]);
4542
@!penalty_arrays=arrays_per_kind;
4543
@!penalty_entries=entries_per_array;
4546
penalty_array_type=0..penalty_arrays;
4547
penalty_entry_type=0..penalty_entries;
4554
@!penalties:array[penalty_array_type,penalty_entry_type] of penalty_node;
4555
@!npp:array[penalty_array_type] of integer;
4563
for p_array := 0 to penalty_arrays do begin
4565
@<Null out the penalty@>;
4570
@ @<Read font penalty list@>=
4573
flush_error('All parameter tables must appear before character info');
4574
p_array:=get_integer;
4575
if p_array>penalty_arrays then
4576
flush_error('This FONTPENALTY table index is too big for my present size')
4577
else if p_array<0 then
4578
flush_error('This FONTPENALTY index is negative')
4580
if p_array>nkp then nkp:=p_array;
4581
while level=1 do begin
4582
while cur_char=" " do get_next;
4583
if cur_char="(" then @<Read a penalty@>
4584
else if cur_char=")" then skip_to_end_of_item
4587
finish_inner_property_list;
4591
@ @<Read a penalty@>=
4594
if cur_code=comment_code then skip_to_end_of_item
4595
else if cur_code<>penalty_code then
4596
flush_error('This property name doesn''t belong in a PENALTY list')
4598
p_number:=get_integer;
4599
if p_number>penalty_entries then
4600
flush_error('This PENALTY index is too big for my present table size')
4601
else if p_number<0 then
4602
flush_error('This PENALTY index is negative')
4604
while npp[p_array]<p_number do begin
4605
incr(npp[p_array]); @<Null out the penalty@>;
4607
@<Read all of a penalty's values@>;
4608
finish_the_property;
4613
@ @<Null out the penalty@>=
4615
penalties[p_array,npp[p_array]].pn_val:=0;
4618
@ @<Read all of a penalty's values@>=
4620
while level=2 do begin
4621
while cur_char=" " do get_next;
4622
if cur_char="(" then @<Read a single penalty value@>
4623
else if cur_char=")" then skip_to_end_of_item
4626
finish_inner_property_list;
4629
@ @<Read a single penalty value@>=
4634
penalties[p_array,p_number].pn_val:=get_integer;
4636
finish_the_property;
4639
@ @<Header information for penalties@>=
4642
for p_array := 0 to nkp do begin
4644
nwp := nwp + npp[p_array];
4649
@ @<Output the penalties@>=
4651
for p_array:= 0 to nkp-1 do
4652
for p_number:=0 to npp[p_array]-1 do begin
4653
out_integer(penalties[p_array,p_number].pn_val);
4657
@ @<Output the penalty headers@>=
4659
for p_array:= 0 to nkp-1 do begin
4660
out_integer(npp[p_array]);
4665
@!mvalue_arrays=arrays_per_kind;
4666
@!mvalue_entries=entries_per_array;
4669
mvalue_array_type=0..mvalue_arrays;
4670
mvalue_entry_type=0..mvalue_entries;
4677
@!mvalues:array[mvalue_array_type,mvalue_entry_type] of mvalue_node;
4678
@!npm:array[mvalue_array_type] of integer;
4686
for m_array := 0 to mvalue_arrays do begin
4688
@<Null out the mvalue@>;
4693
@ @<Read font mvalue list@>=
4696
flush_error('All parameter tables must appear before character info');
4697
m_array:=get_integer;
4698
if m_array>mvalue_arrays then
4699
flush_error('This FONTMVALUE table index is too big for my present size')
4700
else if m_array<0 then
4701
flush_error('This FONTMVALUE index is negative')
4703
if m_array>nkm then nkm:=m_array;
4704
while level=1 do begin
4705
while cur_char=" " do get_next;
4706
if cur_char="(" then @<Read an mvalue@>
4707
else if cur_char=")" then skip_to_end_of_item
4710
finish_inner_property_list;
4714
@ @<Read an mvalue@>=
4717
if cur_code=comment_code then skip_to_end_of_item
4718
else if cur_code<>mvalue_code then
4719
flush_error('This property name doesn''t belong in an MVALUE list')
4721
m_number:=get_integer;
4722
if m_number>mvalue_entries then
4723
flush_error('This MVALUE index is too big for my present table size')
4724
else if m_number<0 then
4725
flush_error('This MVALUE index is negative')
4727
while npm[m_array]<m_number do begin
4728
incr(npm[m_array]); @<Null out the mvalue@>;
4730
@<Read all of an mvalue's values@>;
4731
finish_the_property;
4736
@ @<Null out the mvalue@>=
4738
mvalues[m_array,npm[m_array]].fn_val:=0;
4741
@ @<Read all of an mvalue's values@>=
4743
while level=2 do begin
4744
while cur_char=" " do get_next;
4745
if cur_char="(" then @<Read a single mvalue value@>
4746
else if cur_char=")" then skip_to_end_of_item
4749
finish_inner_property_list;
4752
@ @<Read a single mvalue value@>=
4757
mvalues[m_array,m_number].fn_val:=get_fix;
4759
finish_the_property;
4762
@ @<Header information for mvalues@>=
4765
for m_array := 0 to nkm do begin
4767
nwm := nwm + npm[m_array];
4772
@ @<Output the mvalues@>=
4774
for m_array:= 0 to nkm-1 do
4775
for m_number:=0 to npm[m_array]-1 do begin
4776
out_scaled(mvalues[m_array,m_number].fn_val);
4780
@ @<Output the mvalue headers@>=
4782
for m_array:= 0 to nkm-1 do begin
4783
out_integer(npm[m_array]);
4788
@!fvalue_arrays=arrays_per_kind;
4789
@!fvalue_entries=entries_per_array;
4792
fvalue_array_type=0..fvalue_arrays;
4793
fvalue_entry_type=0..fvalue_entries;
4800
@!fvalues:array[fvalue_array_type,fvalue_entry_type] of fvalue_node;
4801
@!npf:array[fvalue_array_type] of integer;
4809
for f_array := 0 to fvalue_arrays do begin
4811
@<Null out the fvalue@>;
4816
@ @<Read font fvalue list@>=
4819
flush_error('All parameter tables must appear before character info');
4820
f_array:=get_integer;
4821
if f_array>fvalue_arrays then
4822
flush_error('This FONTFVALUE table index is too big for my present size')
4823
else if f_array<0 then
4824
flush_error('This FONTFVALUE index is negative')
4826
if f_array>nkf then nkf:=f_array;
4827
while level=1 do begin
4828
while cur_char=" " do get_next;
4829
if cur_char="(" then @<Read an fvalue@>
4830
else if cur_char=")" then skip_to_end_of_item
4833
finish_inner_property_list;
4837
@ @<Read an fvalue@>=
4840
if cur_code=comment_code then skip_to_end_of_item
4841
else if cur_code<>fvalue_code then
4842
flush_error('This property name doesn''t belong in an FVALUE list')
4844
f_number:=get_integer;
4845
if f_number>fvalue_entries then
4846
flush_error('This FVALUE index is too big for my present table size')
4847
else if f_number<0 then
4848
flush_error('This FVALUE index is negative')
4850
while npf[f_array]<f_number do begin
4851
incr(npf[f_array]); @<Null out the fvalue@>;
4853
@<Read all of an fvalue's values@>;
4854
finish_the_property;
4859
@ @<Null out the fvalue@>=
4861
fvalues[f_array,npf[f_array]].fn_val:=0;
4864
@ @<Read all of an fvalue's values@>=
4866
while level=2 do begin
4867
while cur_char=" " do get_next;
4868
if cur_char="(" then @<Read a single fvalue value@>
4869
else if cur_char=")" then skip_to_end_of_item
4872
finish_inner_property_list;
4875
@ @<Read a single fvalue value@>=
4880
fvalues[f_array,f_number].fn_val:=get_fix;
4882
finish_the_property;
4885
@ @<Header information for fvalues@>=
4888
for f_array := 0 to nkf do begin
4890
nwf := nwf + npf[f_array];
4895
@ @<Output the fvalues@>=
4897
for f_array:= 0 to nkf-1 do
4898
for f_number:=0 to npf[f_array]-1 do begin
4899
out_scaled(fvalues[f_array,f_number].fn_val);
4903
@ @<Output the fvalue headers@>=
4905
for f_array:= 0 to nkf-1 do begin
4906
out_integer(npf[f_array]);
4911
@!ivalue_arrays=arrays_per_kind;
4912
@!ivalue_entries=entries_per_array;
4915
ivalue_array_type=0..ivalue_arrays;
4916
ivalue_entry_type=0..ivalue_entries;
4923
@!ivalues:array[ivalue_array_type,ivalue_entry_type] of ivalue_node;
4924
@!npi:array[ivalue_array_type] of integer;
4925
@!font_i_array:boolean;
4933
for i_array := 0 to ivalue_arrays do begin
4935
@<Null out the ivalue@>;
4940
@ @<Read font ivalue list@>=
4943
flush_error('All parameter tables must appear before character info');
4944
i_array:=get_integer;
4945
if i_array>ivalue_arrays then
4946
flush_error('This FONTIVALUE table index is too big for my present size')
4947
else if i_array<0 then
4948
flush_error('This FONTIVALUE index is negative')
4950
if i_array>nki then nki:=i_array;
4951
while level=1 do begin
4952
while cur_char=" " do get_next;
4953
if cur_char="(" then @<Read an ivalue@>
4954
else if cur_char=")" then skip_to_end_of_item
4957
finish_inner_property_list;
4961
@ @<Read an ivalue@>=
4964
if cur_code=comment_code then skip_to_end_of_item
4965
else if cur_code<>ivalue_code then
4966
flush_error('This property name doesn''t belong in an IVALUE list')
4968
i_number:=get_integer;
4969
if i_number>ivalue_entries then
4970
flush_error('This IVALUE index is too big for my present table size')
4971
else if i_number<0 then
4972
flush_error('This IVALUE index is negative')
4974
while npi[i_array]<i_number do begin
4975
incr(npi[i_array]); @<Null out the ivalue@>;
4977
@<Read all of an ivalue's values@>;
4978
finish_the_property;
4983
@ @<Null out the ivalue@>=
4985
ivalues[i_array,npi[i_array]].in_val:=0;
4988
@ @<Read all of an ivalue's values@>=
4990
while level=2 do begin
4991
while cur_char=" " do get_next;
4992
if cur_char="(" then @<Read a single ivalue value@>
4993
else if cur_char=")" then skip_to_end_of_item
4996
finish_inner_property_list;
4999
@ @<Read a single ivalue value@>=
5004
ivalues[i_array,i_number].in_val:=get_integer;
5006
finish_the_property;
5009
@ @<Header information for ivalues@>=
5012
for i_array := 0 to nki do begin
5014
nwi := nwi + npi[i_array];
5019
@ @<Output the ivalues@>=
5021
for i_array:= 0 to nki-1 do
5022
for i_number:=0 to npi[i_array]-1 do begin
5023
out_integer(ivalues[i_array,i_number].in_val);
5027
@ @<Output the ivalue headers@>=
5029
for i_array:= 0 to nki-1 do begin
5030
out_integer(npi[i_array]);
5034
@ @<Compute the new header information for OFM files@>=
5036
@<Header information for ivalues@>;
5037
@<Header information for fvalues@>;
5038
@<Header information for mvalues@>;
5039
@<Header information for rules@>;
5040
@<Header information for glues@>;
5041
@<Header information for penalties@>;
5044
@ @<Output the new information for OFM files@>=
5046
@<Output the ivalue headers@>;
5047
@<Output the fvalue headers@>;
5048
@<Output the mvalue headers@>;
5049
@<Output the rule headers@>;
5050
@<Output the glue headers@>;
5051
@<Output the penalty headers@>;
5052
@<Output the ivalues@>;
5053
@<Output the fvalues@>;
5054
@<Output the rules@>;
5055
@<Output the glues@>;
5056
@<Output the penalties@>;
5059
@* System-dependent changes.
5060
This section should be replaced, if necessary, by changes to the program
5061
that are necessary to make \.{VPtoVF} work at a particular installation.
5062
It is usually best to design your change file so that all changes to
5063
previous sections preserve the section numbering; then everybody's version
5064
will be consistent with the printed program. More extensive changes,
5065
which introduce new sections, can be inserted here; then only the index
5066
itself will get a new section number.
5067
@^system dependencies@>
5070
Pointers to error messages appear here together with the section numbers
5071
where each ident\-i\-fier is used.