• No results found

Positioning type on the page is accomplished in much the same way as a drawing action is started. A current point is first made using the moveto operator. The difference, however, is that the current point when made for type placement does not represent an actual point on a letterform, but represents its origin on its baseline. A letterform’s origin is slightly left and on the baseline of the character. See the g in figure 7–1. The following example prints a g. The + marks the location of 18 72 moveto, which is the character’s origin.

%!PS-Adobe-2.0 EPSF-1.2 %%Title:type placement1.eps %%BoundingBox:0 0 150 180

/Times-Bold findfont 200 scalefont setfont

18 72 moveto (g) show

Here’s an explanation of the program:

/Times-Bold findfont locates the font dictionary for Times-Bold.

200 scalefont scales the font to 200 point.

setfont makes Times-Bold the current font.

18 72 moveto establishes a current point. This point will be the character’s origin and will also be on the baseline.

The characters to be set are identified by being contained within parentheses. The “(” and “)” are special characters used to identify what is known as a “string” or group of characters to be used for some purpose. In this case, they will be painted on a page.

show paints the characters held within the “(” and “)” in the current font with

7.2

g

7–1

PS

type basics

59

the current color. In this case, the current font is Times-Bold and the current color is the default black.

In this example, the g will be painted with a 70% gray.

%!PS-Adobe-2.0 EPSF-1.2 %%Title:type placement2.eps %%BoundingBox:0 0 150 180

/Times-Bold findfont 200 scalefont setfont

18 72 moveto .3 setgray (g) show

After show in both preceding PostScript program examples, the new current point is located at the width of the character and on the baseline. See point b of figure 7–1. To illustrate this, notice how the line is drawn in the next example.

The beginning of the line is the current point located at the width of the character

g and on the baseline. 100 0 rlineto draws a path 100 points to the right of the current point. stroke then paints the path and initializes the current path.

g

PS

learn

60

type basics

%!PS-Adobe-2.0 EPSF-1.2 %%Title:type placement3.eps %%BoundingBox:0 0 225 180

/Times-Bold findfont 200 scalefont setfont 18 72 moveto .3 setgray (g) show 0 setgray 2 setlinewidth 100 0 rlineto stroke

When setting a series of characters to form a word, the character spacing is based on the font’s metric file. The font metric file contains character widths. Each character in line to be set references the previous character.

In figure 7–2 above, point a represents the first current point. Point b is the new current after the g is set. Point b therefore becomes the location for the origin of the character a. After a is set, point c becomes the new current point.

g

7–3

PS

learn

ga

a

b

c

figure 7–2

type basics

61

various font strategies

Since it is probable that a number of different fonts and sizes would be used on a page, following are a number of ideas for switching from one current font to another.

The first method would be to save the graphic state using gsave and grestore. In this way, there may be one font that you will continually return to in a PostScript program. An example would be:

%!PS-Adobe-2.0 EPSF-1.2 %%Title:type placement4.eps %%BoundingBox:0 -4 346 126

/Helvetica findfont 170 scalefont setfont

0 0 moveto (A) show

gsave

/Times-Bold findfont 48 scalefont setfont .3 setgray

10 10 moveto (aaaaaaaaaaaaaa) show grestore

(B) show % no moveto, current point from A still active

gsave

/StoneSerif-Bold findfont 48 scalefont setfont .5 setgray

10 40 moveto (bbbbbbbbbb) show grestore

(C) show % no moveto, current point from B still active

gsave

/Helvetica-Bold findfont 48 scalefont setfont .8 setgray 10 80 moveto (cccccccccccc) show grestore

7.3

AaaaaaaaaaaaaaabbbbbbbbbbBC

cccccccccccc

7–4

PS

learn

62

type basics

findfont 170 scalefont setfont, the current default value of black, and the new current point made after the (A) show.

The current font is then changed to /Helvetica-Bold findfont 48 scalefont setfont, the current value is changed to 0.3 setgray (70%), and a new current point is made with 10 10 moveto for the row of a’s.

grestore restores the current font back to /Helvetica findfont 170 scalefont setfont, the current value back to black, and the current point left after the (A) show.

The whole process then gets repeated for the rows of b’s and c’s.

A second strategy is to give different font settings a name. For example,

/H18 {/Helvetica findfont 18 scalefont setfont} def /H36 {/Helvetica findfont 36 scalefont setfont} def /H72 {/Helvetica findfont 72 scalefont setfont} def

A third option is to define

/f {findfont exch scalefont setfont} def

and use it by writing this:

18 /Helvetica f

The third method is used in this example. Note how the placement of individual characters is accomplished.

%!PS-Adobe-2.0 EPSF-1.2 %%Title:TYPE.eps

%%BoundingBox:0 0 190 50

/f {findfont exch scalefont setfont} def

68 /Helvetica-Bold f 0 0 moveto (T) show

72 /StoneSerif-SemiboldItalic f (Y) show

74 /Times-Bold f

6 0 rmoveto (P) show % move current 6 points right

68 /Helvetica-Oblique f

-8 0 rmoveto (E) show % move current -8 points left

TY

PE

PS

learn

type basics

63

Notice how rmoveto is used to kern the type right and left to correct the letterspacing. Kerning operators are explained in more detail in chapter 11, “advanced type.”

Related documents