<< . .

. 13
( : 45)



. . >>

height
|
|

Baseline
Reference point’ •
’ ‘
depth

← width ’
’ ’
The example characters in previous chapters have all had zero depth, but we
will soon be seeing examples in which both height and depth are relevant.
A character shape need not ¬t inside the boundaries of its box. Indeed,
italic and slanted letters are put into ordinary boxes just as if they were not
slanted, so they frequently stick out at the right. For example, the letter ˜g™
in the font you are now reading (cmr10) can be compared with the ˜g™ in the
corresponding slanted font (cmsl10):

(A figure will be inserted here; too bad you can™t see it now.
It shows two g™s, as claimed. In fact, the same figure ap-
peared on page 63 of The TeXbook.)




The slanted ˜g™ has been drawn as if its box were skewed right at the top and
left at the bottom, keeping the baseline ¬xed; but TEX is told in both cases that
the box is 5 pt wide, 4.3055 pt high, and 1.9444 pt deep. Slanted letters will be
102 Chapter 12: Boxes


spaced properly in spite of the fact that their boxes have been straightened up, italic correction
beginchar
because the letters will match correctly at the baseline. sharped
w
Boxes also have a fourth dimension called the italic correction, which gives h
d
TEX additional information about whether or not a letter protrudes at the
graph paper
right. For example, the italic correction for an unslanted ˜g™ in cmr10 is 0.1389 pt, drift
while the corresponding slanted letter in cmsl10 has an italic correction of 0.8565 pt. endchar
The italic correction is added to a box™s width when math formulas like g2 or g 2 are
being typeset, and also in other cases as explained in The TEXbook.

Plain ™s beginchar command establishes the width, height,
and depth of a box. These dimensions should be given in terms of “sharped”
quantities that do not vary with the resolution or magni¬cation, because the size
of a character™s type box should not depend in any way on the device that will
be used to output that character. It is important to be able to de¬ne documents
that will not change even though the technology for printing those documents is
continually evolving. can be used to produce fonts for new devices
by introducing new “modes,” as we have seen in Chapter 11, but the new fonts
should still give the same box dimensions to each character. Then the device-
independent ¬les output by TEX will not have to be changed in any way when
they are printed or displayed with the help of new equipment.
The three dimensions in a beginchar command are given in reverse
alphabetical order: First comes the width, then the height, then the depth. The
beginchar routine converts these quantities into pixel units and assigns them
to the three variables w , h , and d . In fact, beginchar rounds these dimensions
to the nearest whole number of pixels; hence w, h, and d will always be integers.
™s pixels are like squares on graph paper, with pixel bound-
aries at points with integer coordinates. The left edge of the type box lies on
the line x = 0, and the right edge lies on the line x = w; we have y = h on the
top edge and y = ’d on the bottom edge. There are w pixels in each row and
h + d in each column, so there are exactly wh + wd pixels inside the type box.
Since w, h, and d are integers, they probably do not exactly match
the box dimensions that are assumed by device-independent typesetting systems
like TEX. Some characters will be a fraction of a pixel too wide; others will be a
fraction of a pixel too narrow. However, it™s still possible to obtain satisfactory
results if the pixel boxes are stacked together based on their w values and if the
accumulated error is removed in the spaces between words, provided that the box
positions do not drift too far away from their true device-independent locations.
A designer should strive to obtain letterforms that work well together when they
are placed together in boxes that are an integer number of pixels wide.
You might not like the value of w that beginchar computes by rounding the
device-independent width to the nearest pixel boundary. For example, you
might want to make the letter ˜m™ one pixel wider, at certain resolutions, so that its
three stems are equally spaced or so that it will go better with your ˜n™. In such a case
you can assign a new value to w, at any time between beginchar and endchar. This
Chapter 12: Boxes 103


new value will not a¬ect the device-independent box width assumed by TEX, but it dvi
parenthesis
should be respected by the software that typesets dvi ¬les using your font.
Computer Modern
meta-design
Here™s an example of a character that has nonzero width, height, and axis
depth; it™s the left parenthesis in Computer Modern fonts like cmr10. Computer ¬lldraw
soft
Modern typefaces are generated by programs that involve lots of pa- crisp
rameters, so this example also illustrates the principles of “meta-design”: Many
di¬erent varieties of left parentheses can be drawn by this one program. But
let™s focus our attention ¬rst on the comparatively simple way in which the box
dimensions are established and used, before looking into the details of how a
meta-parenthesis has actually been speci¬ed. (0,h) (w,h)
"Left parenthesis";
numeric ht #, dp #;
ht # = body height #; .5[ht #, ’dp #] = axis #;
beginchar ("(", 7u#, ht #, dp #);
italcorr ht # — slant ’ .5u#;
pickup ¬ne.nib ;
penpos1 (hair ’ ¬ne , 0); (Figure 12a will be
penpos2 (.75[thin , thick ] ’ ¬ne , 0); inserted here; too bad
you can™t see it now.)
penpos3 (hair ’ ¬ne , 0);
rt x1r = rt x3r = w ’ u; lft x2l = x1 ’ 4u;
top y1 = h; y2 = .5[y1 , y3 ] = axis ;
¬lldraw z1l {(z2l ’ z1l ) xscaled 3} . . . z2l
. . . {(z3l ’ z2l ) xscaled 3}z3l
- - z3r {(z2r ’ z3r ) xscaled 3} . . . z2r
. . . {(z1r ’ z2r ) xscaled 3}z1r - - cycle;
(0,’d) (w,’d)
penlabels(1, 2, 3); endchar;
The width of this left parenthesis is 7u#, where u# is an ad hoc pa-
rameter that ¬gures in all the widths of the Computer Modern characters. The
height and depth have been calculated in such a way that the top and bot-
tom of the bounding box are equally distant from an imaginary line called the
axis, which is important in mathematical typesetting. (For example, TEX puts
the bar line at the axis in fractions like 1 ; many symbols like ˜+™ and ˜=™,
2
as well as parentheses, are centered on the axis line.) Our example program
puts the axis midway between the top and bottom of the type by saying that
˜.5[ht #, ’dp #] = axis #™. We also place the top at position ˜ht # = body height #™ ;
here body height # is the height of the tallest characters in the entire typeface.
It turns out that body height # is exactly 7.5pt # in cmr10, and axis # = 2.5pt #;
hence dp # = 2.5pt #, and the parenthesis is exactly 10 pt tall.
The program for ˜(™ uses a ¬lldraw command, which we haven™t seen
before in this book; it™s basically a combination of ¬ll and draw, where the ¬lling
is done with the currently-picked-up pen. Some of the Computer Modern fonts
have characters with “soft” edges while others have “crisp” edges; the di¬erence
is due to the pen that is used to ¬lldraw the shapes. This pen is a circle whose
104 Chapter 12: Boxes


diameter is called ¬ne ; when ¬ne is fairly large, ¬lldraw will produce rounded ¬ne
hairline
corners, but when ¬ne = 0 (as it is in cmr10) the corners will be sharp. proof
The statement ˜penpos1 (hair ’¬ne , 0)™ makes the breadth of a simulated
broad-edge pen equal to hair ’ ¬ne at position 1; i.e., the distance between z1l
and z1r will be hair ’ ¬ne . We will be ¬lling a region between z1l and z1r with
a circle-shaped pen nib whose diameter is ¬ne ; the center of that nib will pass
through z1l and z1r , hence the pen will e¬ectively add 1 ¬ne to the breadth of
2
the stroke at either side. The overall breadth at position 1 will therefore be
2 ¬ne + (hair ’ ¬ne ) + 2 ¬ne = hair . (Computer Modern™s “hairline thickness”
1 1

parameter, which governs the breadth of the thinnest strokes, is called hair .)
Similarly, the statement ˜penpos2 (.75[thin , thick ] ’ ¬ne , 0)™ makes the overall
breadth of the pen at position 2 equal to .75[thin , thick ], which is 3 of the way
4
between two other parameters that govern stroke breadths in Computer Modern
routines. If ¬ne is increased while hair , thin , and thick stay the same, the e¬ect
will simply be to produce more rounded corners at positions 1 and 3, with little
or no e¬ect on the rest of the shape, provided that ¬ne doesn™t get so large that
it exceeds hair .
Here, for example, are ¬ve di¬erent left parentheses, drawn by our ex-
ample program with various settings of the parameters:
cmr10 cmbx10 cmvtt10 cmssdc10 cmti10




(Figure 12c will be in-
(Figure 12d will be
serted here; too bad (Figure 12e will be
(Figure 12a will be (Figure 12b will be in- inserted here; too
you can™t see it now.) inserted here; too
inserted here; too bad serted here; too bad you bad you can™t see it bad you can™t see it
you can™t see it now.) can™t see it now.) now.) now.)




u= 20 u= 23 u= 21 u= 19 u = 18.4
ht = 270 ht = 270 ht = 250 ht = 270 ht = 270
axis = 90 axis = 90 axis = 110 axis = 95 axis = 90
¬ne = 0 ¬ne = 0 ¬ne = 22 ¬ne = 8 ¬ne = 7
hair = 8 hair = 13 hair = 22 hair = 23 hair = 8
thin = 9 thin = 17 thin = 25 thin = 40 thin = 11
thick = 25 thick = 41 thick = 25 thick = 40 thick = 23
Parameter values are shown here in proof mode pixel units, 36 to the point.
Chapter 12: Boxes 105


(Thus, for example, the value of u# in cmr10 is 20 pt #.) Since cmbx10 is a “bold slanted
36
italic correction
extended” font, its unit width u is slightly larger than the unit width of cmr10, italcorr
and its pen widths (especially thick ) are signi¬cantly larger. The “variable- slant
width typewriter” font cmvtt10 has soft edges and strokes of almost uniform
thickness, because ¬ne and hair are almost as large as thin and thick . This font
also has a raised axis and a smaller height. An intermediate situation occurs
in cmssdc10, a “sans serif demibold condensed” font that is similar to the type
used in the chapter titles of this book; thick = thin in this font, but hairlines are
noticeably thinner, and ¬ne provides slightly rounded corners. The “text italic”
font cmti10 has rounded ends, and the character shape has been slanted by .25;
this means that each point (x, y) has been moved to position (x + .25y, y), in the
path that is ¬lled by ¬lldraw.
The vertical line just to the right of the italic left parenthesis shows the italic
correction of that character, i.e., the fourth box dimension mentioned earlier.
This quantity was de¬ned by the statement ˜italcorr ht # —slant ’.5u#™ in our program;
here slant is a parameter of Computer Modern that is zero in all the unslanted fonts,
but slant = .25 in the case of cmti10. The expression following italcorr should always
be given in sharped units. If the value is negative, the italic correction will be zero;
otherwise the italic correction will be the stated amount.
The author has obtained satisfactory results by making the italic correction
roughly equal to .5u plus the maximum amount by which the character sticks
out to the right of its box. For example, the top right end of the left parenthesis will be
nearly at position (w ’ u, ht ) before slanting, so its x coordinate after slanting will be
w ’ u + ht — slant ; this will be the rightmost point of the character, if we assume that
slant ≥ 0. Adding .5u, subtracting w, and rewriting in terms of sharped units gives the
stated formula. Notice that when slant = 0 the statement reduces to ˜italcorr ’.5u#™;
this means that unslanted left parentheses will have an italic correction of zero.
EXERCISE 12.1
Write a program for right parentheses, to go with these left parentheses.

The reader should bear in mind that the conventions of plain
and of Computer Modern are not hardwired into the language; they
are merely examples of how a person might use the system, and other typefaces
may well be better served by quite di¬erent approaches. Our program for left
parentheses makes use of beginchar, endchar, italcorr, penlabels, pickup,
penpos , lft , rt , top , z , and ¬lldraw, all of which are de¬ned somewhat arbitrarily
in Appendix B as part of the plain base; it also uses the quantities u , body height ,
axis , ¬ne , hair , thin , thick , and slant , all of which are arbitrary parameters that
the author decided to introduce in his programs for Computer Modern. Once
you understand how to use arbitrary conventions like these, you will be able to
modify them to suit your own purposes.
EXERCISE 12.2
(For people who know TEX.) It™s fairly clear that the width of a type box is
important for typesetting, but what use does TEX make of the height and depth?
106 Chapter 12: Boxes


The primitive commands by which actually learns the dimensions charwd
charht
of each box are rarely used directly, since they are intended to be embedded
chardp
in higher-level commands like beginchar and italcorr. But if you must know how charic
things are done at the low level, here is the secret: There are four internal quantities shipout
charcode
called charwd , charht , chardp , and charic , whose values at the time of every shipout location
command are assumed to be the box dimensions for the character being shipped out, in c code
charext
units of printer™s points. (See the de¬nitions of beginchar and italcorr in Appendix B
oriental
for examples of how these quantities can be manipulated.) chardx
dvi
Besides charwd and its cousins, also has four other internal vari- drift
ables whose values are recorded at the time of every shipout: w
charexists
charcode is rounded to the nearest integer and then converted to a number dangerous bend
between 0 and 255, by adding or subtracting multiples of 256 if necessary; this “c code”
is the location of the character within its font.
charext is rounded to the nearest integer; the resulting number is a secondary
code that can be used to distinguish between two or more characters with equal c codes.
(TEX ignores charext and assumes that each font contains at most 256 characters; but
extensions to TEX for oriental languages can use charext to handle much larger fonts.)
chardx and chardy represent horizontal and vertical escapement in units of
pixels. (Some typesetting systems use both of these device-dependent amounts to
change their current position on a page, just after typesetting each character. Other sys-
tems, like the dvi software associated with TEX, assume that chardy = 0 but use chardx
as the horizontal escapement whenever a horizontal movement by chardx does not cause
the subsequent position to drift too far from the device-independent position de¬ned by
accumulated charwd values. Plain ™s endchar routine keeps chardy = 0,
but sets chardx := w just before shipping a character to the output. This explains why
a change to w will a¬ect the spacing between adjacent letters, as discussed earlier.)
Two characters with the same c code should have the same box dimensions and
escapements; otherwise the second character will override the speci¬cations of
the ¬rst. The boolean expression ˜charexists c™ can be used to determine whether or
not a character with a particular c code has already been shipped out.
Let™s conclude this chapter by contemplating a program that gen-
erates the “dangerous bend” symbol, since that symbol appears so often in
this book. It™s a custom-made character intended to be used only at the very beginnings
of paragraphs in which the baselines of the text are exactly 11 pt apart. Therefore it
extends below its baseline by 11 pt; but it is put into a box of depth zero, because TEX
would otherwise think that the ¬rst line of the paragraph contains an extremely deep
character, and such depth would cause the second line to be moved down.
baselinedistance # := 11pt #; de¬ne pixels(baselinedistance );
heavyline # := 50/36pt #; de¬ne blacker pixels(heavyline );
beginchar (127, 25u#, h height # + border #, 0); "Dangerous bend symbol";
pickup pencircle scaled rulethickness ; top y1 = 25 h; lft x4 = 0;
27
x1 +x1 = x1a +x1b = x4b +x2a = x4 +x2 = x4a +x2b = x3b +x3a = x3 +x3 = w;
x4a = x4b = x4 + u; x3b = x1a = x1 ’ 2u;
y4 + y4 = y4a + y4b = y3b + y1a = y3 + y1 = y3a + y1b = y2b + y2a = y2 + y2 = 0;
2 4
y1a = y1b = y1 ’ 27 h; y4b = y2a = y4 + 27 h;
Chapter 12: Boxes 107


draw z1a . . z1 . . z1b - - - z2a . . z2 . . z2b - - - beginchar
location
z3a . . z3 . . z3b - - - z4a . . z4 . . z4b - - - cycle; % the signboard

x10 = x11 = x12 = x13 = .5w ’ u; x14 = x15 = x16 = x17 = w ’ x10 ; intersectionpoint
y10 = y14 = 28 h; bot y13 = ’baselinedistance ; HAGGARD
27
COLBURN
z11 = (z10 . . z13 ) intersectionpoint (z1a {z1a ’ z4b } . . z1 {right });
y15 = y11 ; y16 = y12 = ’y11 ; y17 = y20 = y21 = y13 ;
draw z11 - - z10 - - z14 - - z15 ; draw z12 - - z13 ; draw z16 - - z17 ; % the signpost
x20 = w ’ x21 ; x21 ’ x20 = 16u; draw z20 - - z21 ; % ground level
x36 = w ’ x31 ; x36 ’ x31 = 8u; x32 = x33 = x36 ; x31 = x34 = x35 ;
y31 = ’y36 = 12 h; y32 = ’y35 = 27 h; y33 = ’y34 = 27 h;
9 3
27
pickup pencircle scaled heavyline ;
draw z32 {z32 ’ z31 } . . z33 - - - z34 . . z35 {z36 ’ z35 }; % the dangerous bend
pickup penrazor xscaled heavyline rotated (angle(z32 ’ z31 ) + 90);
draw z31 - - z32 ; draw z35 - - z36 ; % upper and lower bars
labels(1a, 1b, 2a, 2b, 3a, 3b, 4a, 4b, range 1 thru 36); endchar;


This program has sev-
eral noteworthy points
of interest: (1) The ¬rst
parameter to beginchar
here is 127, not a string;
this puts the character
into font location 127.
(2) A sequence of equa-
tions like ˜a = w ’ b; a =
w ’ b ™ can conveniently
be shortened to ˜a + b =
a + b = w™. (3) Three
hyphens ˜- - -™ is an ab-
breviation for a line with
(Figure 12f will be inserted here; too bad you can™t see it now.)
“in¬nite” tension, i.e.,
an almost straight line
that connects smoothly
to its curved neighbors.
(4) An ˜intersectionpoint™
operation ¬nds out where
two paths cross; we™ll
learn more about this in
Chapter 14.


Well, we are in the same box.
” RIDER HAGGARD, Dawn (1884)

A story, too,
may be boxed.
” DOROTHY COLBURN, Newspaper Nomenclature (1927)
(page 108)




13
Drawing, Filling,
and Erasing
Chapter 13: Drawing, Filling, and Erasing 109


The pictures that produces are made up of tiny pixels that are either graph paper
¬ll
“on” or “o¬”; therefore you might imagine that the computer works behind the un¬ll
scenes with some sort of graph paper, and that it darkens some of the squares coordinates
whenever you tell it to draw a line or to ¬ll a region.
™s internal graph paper is actually more sophisticated than
this. Pixels aren™t simply “on” or “o¬” when is working on a picture;
they can be “doubly on” or “triply o¬.” Each pixel contains a small integer value,
and when a character is ¬nally shipped out to a font the black pixels are those
whose value is greater than zero. For example, the two commands
¬ll (0, 3) - - (9, 3) - - (9, 6) - - (0, 6) - - cycle;
¬ll (3, 0) - - (3, 9) - - (6, 9) - - (6, 0) - - cycle
yield the following 9 — 9 pattern of pixel values:
000111000
000111000
000111000
111222111
111222111
111222111
000111000
000111000
000111000

Pixels that have been ¬lled twice now have a value of 2.
When a simple region is “¬lled,” its pixel values are all increased by 1;
when it is “un¬lled,” they are all decreased by 1. The command
un¬ll (1, 4) - - (8, 4) - - (8, 5) - - (1, 5) - - cycle
will therefore change the pattern above to
000111000
000111000
000111000
111222111
100111001
111222111
000111000
000111000
000111000

The pixels in the center have not been erased (i.e., they will still be black if this
picture is output to a font), because they still have a positive value.
Incidentally, this example illustrates the fact that the edges between
™s pixels are lines that have integer coordinates, just as the squares
on graph paper do. For example, the lower left ˜0™ in the 9 — 9 array above
corresponds to the pixel whose boundary is ˜(0, 0) - - (1, 0) - - (1, 1) - - (0, 1) - -
cycle™. The (x, y) coordinates of the points inside this pixel lie between 0 and 1.
EXERCISE 13.1
What are the (x, y) coordinates of the four corners of the middle pixel in the
9 — 9 array?
EXERCISE 13.2
What picture would have been obtained if the un¬ll command had been given
before the two ¬ll commands in the examples above?

<< . .

. 13
( : 45)



. . >>