|
 |
CS 3723/3721
Programming Languages
Introduction
|
|
Introduction
(Taken from the start of the
BlueBook.)
The POSTSCRIPT language is a programming language designed
to convey a description of virtually any desired page to a printer.
It possesses a wide range of graphic operators that may be combined
in any manner. It contains variables and allows the combining
of operators into more complex procedures and functions.
POSTSCRIPT page descriptions are programs to be run by an interpreter.
POSTSCRIPT programs are usually generated by application
programs running on other computers. However, many
POSTSCRIPT printers, including the Apple LaserWriter, have an
interactive state in which the user may program directly in
POSTSCRIPT.
- POSTSCRIPT AS A PAGE DESCRIPTION LANGUAGE
POSTSCRIPT has a large selection of graphics operators that allow
it to precisely describe a desired page. These operators control
the placement of three types of graphics objects:
- Text in a wide variety of typefaces can be placed on a page
in any position, orientation, and scale.
- Geometric figures can be constructed using POSTSCRIPT
graphics operators. These describe the locations of straight
lines and curves of any size, orientation, and width, as well
as filled spaces of any size, shape, and color.
- Sampled Images of digitized photographs, free-hand
sketches, or any other image may be placed on a page in
any scale or orientation.
All graphic objects may be easily rotated, scaled, and clipped to
a specified portion of the output page.
POSTSCRIPT Imaging Model
An imaging model is the set of rules that are incorporated into
the design of a graphics system. The POSTSCRIPT imaging model
is very similar to the model we instinctively adopt when we draw
by hand.
The POSTSCRIPT model considers an image to be built up by
placing ink on a page in selected areas. The ink may form letters,
lines, filled shapes, or halftone representations of photographs.
The ink itself may be black, white, colored, or any shade of gray.
These elements may be cropped to a boundary of any shape as
they are placed on the page. Once the page has been built up to
the desired form, it may be printed on an output device.
Three concepts are central to the implementation of the
POSTSCRIPT imaging model:
- Current Page: The current page is the "ideal page" on which
POSTSCRIPT draws. It is independent of the capabilities of the
printer being used.
When a program begins, the current page is completely empty.
POSTSCRIPT painting operators place marks on the current page,
each of which completely obscures marks that they may overlay.
Once the current page is completely described, it is sent to the
printer, which reproduces the page as well as it can.
It is important to remember that no matter what color a mark
has--white, gray, black, or color--it is put onto the current
page as if it were applied with opaque paint.
- Current Path: The current path is a set of connected and dis-
connected points, lines, and curves that together describe shapes
and their positions. There is no restriction to the shapes that may
be defined by the current path; they may be convex or concave,
even self-intersecting. The elements of the current path are
specified in terms of their positions on the current page. The
resolution of the printer in use in no way constrains the definition
of the path.
The current path is not itself a mark on the current page.
POSTSCRIPT path operators define the current path, but do not
mark the page. Once a path has been defined, it can be stroked
onto the current page (resulting in a line drawn along the path),
filled (yielding solid regions of ink), or used as a clipping boundary.
- Clipping Path: The current clipping path is the boundary of
the area that may be drawn upon. Initially, the clipping path
matches the printer's default paper size. The clipping path may
be changed to any size and shape desired. If an imaging operator
tries to mark the current page outside of the current clipping
path, only those parts of the mark that fall within the clipping
path will actually be drawn onto the current page.
Coordinate Systems
Positions on a page are described as x and y pairs in a coordinate
system imposed on the page.
Every output device has a built-in coordinate system by which it
addresses points on a page. We call this built-in coordinate system,
idiosyncratic to each device, device space. Device space
varies widely from printer to printer; there is no uniformity in the
placement of coordinate origins or in horizontal and vertical
scaling.
Positions on the POSTSCRIPT current page are described in terms
of a user coordinate system or user space. This coordinate system
is independent of the printer's device space. Coordinates in a
POSTSCRIPT program are automatically transformed from user
space into the printer's device space before printing the current
page. User space thus provides a coordinate system within which
a page may be described without regard for the particular
machine on which the page is to be printed.
The POSTSCRIPT user space can be altered in three ways. The
coordinate system's origin may be translated, moved to any
point in user space. The axes may be rotated to any orientation.
The axes may be scaled to any degree desired; the scaling may
be different in the x and y directions. A sophisticated user may
specify any linear transformation from user space to device
space. Thus, coordinates in a POSTSCRIPT program are changeable
with respect to the current page, since they are described
from within a coordinate system that may slide around, turn,
shrink, or expand.
- POSTSCRIPT AS A PROGRAMMING LANGUAGE
About one-third of the POSTSCRIPT language is devoted to
graphics. The remainder makes up an entirely general computer
programming language. The POSTSCRIPT language contains elements
of many other programming languages, but most closely
resembles the FORTH language.
POSTSCRIPT Stack
POSTSCRIPT reserves a piece of memory called a stack for the
data with which it is working. The stack behaves like a stack of
books. The last book placed on the stack is the first book that
will later be removed. Similarly, numbers, strings, and other
pieces of data placed on the stack will be removed in reverse
order, the last item added to the stack being the first retrieved.
Postfix Notation
POSTSCRIPT operators that require numbers or other data, such
as add and sub, retrieve that data from the stack. To use an
operator, one must first place the data it requires, its operands,
on the stack, and then call the operator. The operator will place
its own results on the stack. This style of programming, in which
the operands are specified before the operator, is referred to as
postfix notation.
POSTSCRIPT Data Types
POSTSCRIPT supports many data types common to other languages,
including reals, booleans, arrays, and strings. The
POSTSCRIPT language also defines object types such as
dictionary and mark. For descriptions of all the POSTSCRIPT data
and object types, refer to the POSTSCRIPT Language Reference
Manual.
POSTSCRIPT Flexibility
POSTSCRIPT is an extremely flexible language. Functions that do
not exist, but which would be useful for an application, can be
defined and then used like other POSTSCRIPT operators. Thus,
POSTSCRIPT is not a fixed tool within whose limits an application
must be written, but is an environment that can be
changed to match the task at hand. Pieces of one page description
can be used to compose other, more complicated pages.
Such pieces can be used in their original form or translated,
rotated, and scaled to form a myriad of new composite pages.
Printable Programs
POSTSCRIPT programs are written entirely in printable ASCII
characters. This allows them to be handled as ordinary text files
by the vast majority of communication and computer file
systems. In addition, it ensures that a POSTSCRIPT program will
be as easy for a person to read as the structure of the program
allows.
( Revision date: 2015-01-03.
Please use ISO 8601,
the International Standard.)
|