Simple Text

Simple Text


 

Introduction

In this section of the course we will introduce a subset of PostScript  suitable for printing text. After completing this section you will know  enough PostScript to create text-only pages, using multiple fonts in a  variety of sizes.


 

Program "Hello World"

Our first PostScript program is one that simply prints the phrase "Hello World".


/Times-Roman findfont

36 scalefont

setfont

144 288 moveto

(Hello World.) show

showpage
 

The graphic depicts how the printed page would look, and the text is the  corresponding PostScript program. On a typical computer screen,  the samples in this document will  appear about 30% of life size. Your mileage may  vary.

We will define each of the PostScript commands appearing in the above  sample, and then we will return to this sample program, and examine it  step-by-step.


 

Positioning

x ymoveto-

moveto sets the current point to x y

The current point is the reference point used by many PostScript  commands, including the commands for placing text on the page.

Once set, the current point remains fixed in position on the paper,  until moved again.

The default coordinate system has the origin (zero-zero point) at the  lower left corner of page. The X-axis increases towards the right and  the Y-axis increase towards the top of the page.

The initial zero-zero point is always the physical corner of the paper, even  if the printer can't print all the way to the edge of the page.

By default, distances are specified in PostScript points (1/72 of an  inch).

This is only the default coordinate system. The location of the origin, the units for measurements, and even the  direction of the axis, may be changed.


 

Font Selection (findfont, scalefont,  setfont)

Before any text can be printed onto the page, you must select a font and a size.

PostScript actually uses a sequence of commands for font and size  selection. For now, we will treat a sequence of three commands as one  command. We will use these three commands together as a group. Do not  be tempted to try to use these commands individually, they don't do what  you think.

The commands we will use are:

/Font-Namefindfontsize scalefont  setfont -

 Where Font-Name is the name of the font, and size is the  desired size of the font. (Notice that there is a "/" appearing  immediately before the font name.) The dash (-) appearing at the end of  the above definition is not part of the command; its presence merely  indicates that the above sequence of commands do not return any values.  None of the commands we will discuss in this chapter return values. We use the convention of a "-" to indicate no returned value in an effort to match the style of the PostScript Language  Reference Manual

This sequence sets the current font.

The current font is the font/size combination that will be used  for subsequent text. You can change the current font at any time by  repeating the above commands.

Size is specified in units from the current coordinate system.  The default coordinate system is points. A size of "12" would  yield a 12 point font.

Font-Name must refer to a font which already exists inside the  printer.  The font may be either a built-in (ROM) font, or a previously  downloaded font. (A list of standard built-in fonts is at the end of  this chapter)

Font names must be exactly matched (case and punctuation are  important). Times-Roman is not the same as Times-roman, TimesRoman or TIMES-Roman


 

Painting text onto the page (show)

(text) show-

 The show operator paints text onto the page in  the current font starting at the current  point. The current point is repositioned to just after the  last letter painted.

The text to be painted should be enclosed in parenthesis and followed by  the show operator.

The diagrams in this course use the symbol to graphically indicate the location of the current point.

 

Current point before text is painted.

 

Current point after text is painted.

Once something is painted onto the page, it cannot be moved.

To print multiple lines, multiple show commands must be used, each preceded by an appropriate moveto command. Do not attempt to  place newline character or line breaks inside the parenthesis.

To place text onto the page findfont-scalefont-setfont is used for picking  the font, moveto is used for picking the location on the page, and show is  used for placing the text.


 

Printing the page (showpage)

-showpage-

 Remember the dashes (-) appearing before and after the showpage command should not actually appear in your PostScript program. These  dashes appear only in the documentation. The leading dash indicates that  this command takes no arguments, and the trailing dash indicates that the  command returns no values.

The showpage causes the page to actually be printed. Many other  page description languages use a ^L or form-feed for this function.

Many PostScript printers use a "Frame Buffer". (A Frame Buffer is an area of memory large enough  to hold an entire page. Each bit in the frame buffer corresponds to on  pixel on the printed page). The painting operators (including show) sets bits in the frame buffer, and the showpage operator  copies the bits from the frame buffer to the printed page.

In addition to printing,showpage performs a number of housekeeping functions, including resetting some of the printer's state.

  • The frame buffer is transferred to the page
  • The page is printed and ejected from the printer
  • The page is erased (the frame buffer is cleared)
  • The current point is cleared

showpage sets up a "clean slate" for the next page.

A common error is to leave off the showpage at the end of your  PostScript program. Your program may correctly specify the page you want  printed, but nothing will come out of the printer.

The symptom is that the printer generates no error, and no page comes out  of the printer. Without the showpage, your PostScript is still  legal, just useless. You have set bits in the frame buffer, but have  neglected to ask the printer to transfer the frame buffer to paper.


 

Program "Hello World " - Details

Before your PostScript program executes, the frame buffer (here  represented by a white rectangle) is empty.

To help you understand the PostScript coordinate system, our diagrams  include a graphical representation. The solid blue lines show the X and Y axis. The dashed blue lines are  shown every 100 units.


 


/Times-Roman findfont

36 scalefont

setfont
 

The findfont scalefont setfont sequence does not affect the  coordinate system at all, it merely sets the value of PostScript'scurrent font variable.

PostScript keeps track of various state variable. The collection of  variables that describe graphics are called the "graphics state" values. The current font variable is part of the graphics state (as are  the variables that track the coordinate system)


 


/Times-Roman findfont

36 scalefont

setfont

144 288 moveto

 

The moveto command sets the current point graphics state variable. Our  diagrams show the current point with the symbol.


 


/Times-Roman findfont

36 scalefont

setfont

144 288 moveto

(Hello World.) show
 

Notice that the text started at the current point, and the current point  was advanced by the width of the text. If we were not concerned about efficiency, we could have written the line

(Hello World.) show as

(Hel) show (lo Wor) show (ld.) show and gotten exactly the same output.



/Times-Roman findfont

36 scalefont

setfont

144 288 moveto

(Hello World.) show

showpage
 

After showpage prints the page, it clear out the frame buffer (including  clearing the current point)


PostScript Syntax

PostScript uses a "free form" syntax.

PostScript commands can appear anywhere on a line.

You can use one or more spaces between commands.

Wherever you have spaces you can have a line break.

If you wanted to make your PostScript program unreadable to humans, you  could place it all on one line.

PostScript will ignore anything that occurs between a "%" and the end  of line. This is called a comment.

By convention, the first line of a PostScript file should start with  the characters "%!". Some print spoolers check for the  "%!" before printing a PostScript file.


 

Program "Large Type" - Output

 

PostScript fonts are inherently scaleable. Typically, the font definition contains only the outlines of the characters. The actual bit maps for  the characters are generated on an as-needed basis.

Unlike other page description languages, PostScript allows you to specify  any size for a font.

If you use a size that is to small compared to the resolution of your  output device, the results may not be readable. On a 300 dpi printer  fonts smaller than 4 points are difficult to read. On a 600 dpi printer  you can read a 2 point font (if you have a magnifying glass).

Once the font size gets big relative to the sheet of paper, you may have  portions of characters extending off the page.

Hardware limitations in the printers prevent  most printers from printing all the way to the edge of the page. Any  marks too close to the edge of the paper will simply not print. This  hardware limit is typically 1/8 to 1/2 inch, depending on the model  printer you have.


 

Program "Large Type" - Source


/Helvetica-Bold findfont

300 scalefont

setfont

72 144 moveto

(Large Type) show
 

It is perfectly legal to print off the page. No error is generated.

Only those portions of the image that actually coincide with the printed  page will print. The rest are silently omitted.

In this example, all of the letters "Lar" will print,  only a portion of the letter "g" will print, and the  letters "e Type" will not print as they fall outside of the printable  area of the paper.

Exercise

Add you name near the upper right corner of the page using 1/4 inch  Helvetica.

Exercise 1 Solution


 

Fonts Available on All PostScript Printers

  • Times-Roman
  • Times-Italic
  • Times-Bold
  • Times-BoldItalic
  • Helvetica
  • Helvetica-Oblique
  • Helvetica-Bold
  • Helvetica-BoldOblique
  • Courier
  • Courier-Oblique
  • Courier-Bold
  • Courier-BoldOblique
  • Symbol Greek and some math characters

Capitalization of font names (and capitalization everything else in PostScript) is  important.

Many PostScript printers have additional fonts built into ROM, and all  PostScript printers allow you to download new fonts.

Printers that have the "Apple 35" font set (Like the LaserWriter II)  have these additional fonts:

  • AvantGarde-Book
  • AvantGarde-BookOblique
  • AvantGarde-Demi
  • AvantGarde-DemiOblique
  • Bookman-Demi
  • Bookman-DemiItalic
  • Bookman-Light
  • Bookman-LightItalic
  • Helvetica-Narrow
  • Helvetica-Narrow-Bold
  • Helvetica-Narrow-BoldOblique
  • Helvetica-Narrow-Oblique
  • NewCenturySchlbk-Roman
  • NewCenturySchlbk-Bold
  • NewCenturySchlbk-Italic
  • NewCenturySchlbk-BoldItalic
  • Palatino-Roman
  • Palatino-Bold
  • Palatino-Italic
  • Palatino-BoldItalic
  • ZapfChancery-MediumItalic
  • ZapfDingbats.


 

Review

  • findfont, scalefont, setfont
  • Capitalization of font names is important.
  • Sizes are specified in units.
  • Default units are printer's points.
  • setfont - sets the current font.
  • moveto - sets the current point.
  • show - paints text onto the page in the current font starting at the  current point.
  • showpage - actually prints onto the paper.

[Home] [Goals] [Intro] [Simple Text] [Simple CTM]

Copyright © 1998, Mefco, Inc., All Rights Reserved
"PostScript" is a registered trademark of
Adobe Systems, Inc.