October 90 - THE PERILS OF POSTSCRIPT--THE SEQUEL
THE PERILS OF POSTSCRIPT--THE SEQUEL
SCOTT "ZZ" ZIMMERMAN
Developers are discovering the advantages of using PostScript ® dictionaries in
applications, but along with the advantages come some perils. One peril awaits if you
download a dictionary using PostScriptHandle. Another can trip you up after
downloading a dictionary if you then download a font using the SetFont procedure I
described in develop, Issue 1. How to avoid these perils? Read on to learn some tricks
for dicts in picts.
More and more developers are beginning to use direct PostScript code in their
applications. In my "Perils of PostScript" article in develop, Issue 1, I addressed a
couple of problems that arise when you use PostScript code to print documents. In this
sequel, we'll look at some problems you will encounter if you attempt to use
PostScript dictionaries in your applications.
ABOUT POSTSCRIPT DICTIONARIES
A PostScript dictionary is a collection of predefined variables and/or procedures.
Using a PostScript dictionary can significantly reduce the size of the PostScript code
generated by your application and make it more efficient. For instance, consider a
large PostScript file in which the operatorcurrentpoint is used frequently. You can
define in your dictionary a PostScript procedure called cp that makes a call to the
currentpoint operator. You can then replace currentpoint with cp throughout the
file, thus reducing its size. Similarly, by defining a PostScript procedure to represent
a series of operators, you can express a compound operation much more efficiently.
And storing procedures in a dictionary that you create can also prevent you from
inadvertently redefining something that has already been defined.
One great example of a PostScript dictionary is the one used by the LaserWriter ®
driver, variously called LaserPrep (after the file it resides in, at least until System
7), AppleDict (the Apple name for it), and good ol' md (the PostScript name for it, and
the one I prefer to use). The LaserWriter driver generally uses one or more md
routines to perform a particular QuickDraw operation. (See the sidebar on the next
page for a review of how the LaserWriter driver works.) For example, a call to the
QuickDraw CopyBits routine is translated by the driver into a call to the db or
cdb operators stored in md. As another example, during font downloading the
LaserWriter driver uses bn and bu , both stored in md, to call save and
restore ( bn calls save and bu calls restore).If you want to record a piece of
PostScript code that references procedures contained in a dictionary, you must also
record the dictionary. I describe how to download a dictionary, and how to avoid the
pitfalls involved, in the next section.
Once your dictionary has been downloaded, you should be able to continue to reference
it until the end of the job. But alas, this is not so, at least until the new printing
architecture ships sometime after System 7. Under the current architecture, font
downloading interferes with PostScript dictionaries. I discuss this problem and how to
get around it under "The Perils of Font Downloading.
THE PERILS OF DICTIONARY DOWNLOADING
One of the easiest methods for downloading a PostScript dictionary is by using the