• No results found

In setting columns of text (or “body copy”) there are often mar- gins observed on each side of the lines of text. These margins are usually specified as the amount of white space between the text and the edges of the paper, but this is not a very specific mea- surement when a document may be printed on more than one size of paper. A better measure probably is to specify the start- ing point of the text, and the line length of the text. These start- ing point for the text is certainly needed for setting with the PostScript language. There are four basic types of line layout that are in common use: centered, flush left, flush right, and justified. These are also sometimes referred to as centered, left- justified, right-justified, and fully-justified. In Figure 7.2 is an example with four text blocks, each of which is set in one of these styles.

One might also want to indent the first line of a paragraph of text or provide unusual borders around which to “flow” text. These can all be handled relatively easily if both the starting point of the text and the particular line length are maintained by the composing application.

figure 7.2

In listing 7-1 some procedures are defined that implement “rightshow” and “centershow”. These procedures do a fair amount of calculation, and are only appropriate if the widths of the strings cannot be determined at the host (for instance, they might be used in a printer emulator). Generally, the host appli- cation will already have determined precisely where the text should be placed, and can simply use moveto and show for all of the above styles.

These procedures combine the moveto and show operations. Both the x, y values of the location on the page and the string to be printed are passed on the operand stack. This is faster than doing separate name lookup and execution on both moveto and show. Notice that the margins are maintained by the host appli- cation, and an explicit location on the page is passed for each string.

Then this ebony bird beguiling my sad fan- cy into smiling, By the grave and stern decorum of the coun- tenance it wore, “Though thy crest be shorn and shaven, thou,” I said, “art sure no craven,

Ghastly grim and ancient Raven wander- ing from the Nightly shore—

Tell me what thy lord- ly name is on the Night’s Plutonian shore!”

Quoth the Raven “Nevermore.”

But the Raven, sitting lonely on the placid bust, spoke only, That one word, as if

his soul in that one word he did outpour.

Nothing farther then he uttered–not a feath-

er then he fluttered– Till I scarcely more than muttered “Other friends have flown before— On the morrow he will leave me, as my Hopes have flown before.” Quoth the Raven

“Nevermore.” an excerpt from

The Raven

by Edgar Allan Poe

February, 1845

Much I marvelled this un- gainly fowl to hear dis- course so plainly, Though its answer little meaning– little relevancy bore; For we cannot help agreeing that no sublunary being Ever yet was blessed with seeing bird above his chamber door— Bird or beast upon the sculp- tured bust above his cham- ber door, With such name as “Nevermore.”

listing 7-1

%!PS-Adobe-2.0

%%Title: margin procedures %%BeginProcSet: text-procs 1.0 0 % moveto-show /SH { %def moveto show } bind def % rightshow /RS { %def moveto

dup stringwidth neg exch neg exch rmoveto show

} bind def %centershow /CS { %def

moveto dup stringwidth 2 div neg exch 2 div neg exch rmoveto show

} bind def

%%EndProcSet: text-procs 1.0 0 %%EndProlog

/Times-Roman findfont 14 scalefont setfont (Centered about + current point) 306 140 CS (+Flush Left at current point) 72 120 SH (Flush Right at current point+) 560 120 RS showpage

%%Trailer

JUSTIFICATION

For standard text-setting, the natural letter spacing and word spacing should be used. Letters may be kerned to improve their visual spacing (see section 7.6), but the lines of text should usual- ly not be stretched in any way unless it is necessary to justify the text.

There are two levels of refinement for justifying a column of text:

• Provide careful hyphenation and word breaking to get the lines of text as close as possible to the correct length.

• Modify the word spacing as necessary to stretch the text to fit the necessary width of the line.

Under normal circumstances, the inter-letter spacing should not be modified at all. The legibility of text tends to suffer greatly when letter spacing is compromised. If hyphenation is not avail- able, or when it cannot be avoided, both word and letter spacing can be modified simultaneously with the awidthshow operator. The appropriate way to modify word spacing is to use the widthshow operator, which was designed with this purpose in mind. widthshow prints text just as show does, except that it modifies the character width of a particular character by the specified amount while it is printing it. By supplying a small amount by which to change the width of the space character, word spacing can be modified quite efficiently and easily. List- ing 7-2 contains an example of its use.

listing 7-2

%!PS-Adobe-2.0

%%Title: widthshow example /F {

findfont exch scalefont setfont } bind def

/W /widthshow load def %%EndProlog

%%BeginSetup

/sp 32 def % ASCII space %%EndSetup

36 745 moveto 24 /Times-Italic F

6 0 sp (PostScript Language Program Design) W showpage

The computation that needs to be performed is to determine the amount by which to modify the width of the space charac- ter. For justified text, the space modifier (SpaceMod) is the intended line width (LineWidth) less the width of the existing string (StringWidth) divided by the number of spaces in the string (Spaces). This computation can easily be performed by the host application if the character widths are known.

SpaceMod = (LineWidth - StringWidth) Spaces

This SpaceMod quantity is passed directly to the widthshow operator each time it is called. Notice that this value will be dif- ferent for every line of text, since there are likely to be differ- ent numbers of spaces (and different string widths) for each line.