PostScript
File:PostScript 3.svg | |
Paradigm | multi-paradigm: stack-based, procedural |
---|---|
Designed by | John Warnock & Chuck Geschke |
Developer | Adobe Systems |
First appeared | 1982 |
Stable release | PostScript 3
/ 1997 |
Typing discipline | dynamic, strong |
Major implementations | |
Adobe PostScript, TrueImage, Ghostscript | |
Influenced by | |
Forth | |
Influenced | |
Filename extension |
.ps |
---|---|
Internet media type |
application/postscript |
Uniform Type Identifier (UTI) | com.adobe.postscript |
Magic number | %! |
Developed by | Adobe Systems |
Type of format | printing file format |
Extended to | Encapsulated PostScript |
PostScript (PS) is a page description language and programming language used primarily in the electronic and desktop publishing areas.
History
The concepts of the PostScript language were seeded in 1976 when John Warnock was working at Evans & Sutherland, a famous computer graphics company. At that time John Warnock was developing an interpreter for a large three-dimensional graphics database of New York harbor. Warnock conceived the Design System language to process the graphics, very similar to the Forth programming language.
Concurrently, researchers at Xerox PARC had developed the first laser printer and had recognized the need for a standard means of defining page images. In 1975-76 a team led by Bob Sproull developed the Press format, which was eventually used in the Xerox Star system to drive laser printers. But Press, a data format rather than a language, lacked flexibility, and PARC mounted the InterPress effort to create a successor.
In 1978 Evans and Sutherland asked Warnock to move from the San Francisco Bay Area to their main headquarters in Utah, but he was not interested in moving. He then joined Xerox PARC to work with Martin Newell. They rewrote Design System to create JaM (for "John and Martin") which was used for VLSI design and the investigation of type and graphics printing. This work later evolved and expanded into the InterPress language.
Warnock left with Chuck Geschke and founded Adobe Systems in December 1982. They created a simpler language, similar to InterPress, called PostScript, which went on the market in 1984. At about this time they were visited by Steve Jobs, who urged them to adapt PostScript to be used as the language for driving laser printers.
In March of 1985, the Apple LaserWriter was the first printer to ship with PostScript, sparking the desktop publishing (DTP) revolution in the mid-1980s. The combination of technical merits and widespread availability made PostScript a language of choice for graphical output for printing applications. For a time an interpreter (sometimes referred to as a RIP -for Raster Image Processor) for the PostScript language was a common component of laser printers, into the 1990s.
Once the de facto standard for electronic distribution of final documents meant for publication, PostScript is steadily being supplanted by one of its own descendants, the Portable Document Format or PDF in this area. By 2001 there were fewer printer models which came with support for PostScript, largely due to the growing competition from much cheaper non-PostScript ink jet printers (PostScript interpreters added significantly to printer cost), and new software-based methods to render PostScript images on the computer, making them suitable for any printer (PDF provided one such method). The use of a PostScript laser printer still can, however, significantly reduce the CPU workload involved in printing documents, transferring the work of rendering PostScript images from the computer to the printer.
PostScript Level 1
The PostScript language has had two major upgrades. The first version, known as PostScript Level 1, was introduced in 1984.
PostScript Level 2
PostScript Level 2 was introduced in 1991, and included several improvements: improved speed and reliability, support for in-RIP separations, image decompression (for example, JPEG images could be rendered by a PostScript program), support for composite fonts, and the form mechanism for caching reusable content.
PostScript 3
PostScript 3 (Adobe dropped the "level" terminology in favor of simple versioning) came at the end of 1997, and along with many new dictionary-based versions of older operators, introduced better color handling, and new filters (which allow in-program compression/decompression, program chunking, and advanced error-handling).
PostScript 3 was significant in terms of replacing the existing proprietary color electronic prepress systems, then widely used for magazine production, through the introduction of smooth shading operations with up to 4096 shades of grey (rather than the 256 available in PostScript 2), as well as DeviceN, a color space that allowed the addition of additional ink colors (called spot colors) into composite color pages.
Use in printing
Before PostScript
Prior to the introduction of PostScript, printers were designed to print character output given the text—typically in ASCII—as input. There were a number of technologies for this task, but most shared the property that the glyphs were physically difficult to change, as they were stamped onto typewriter keys, bands of metal, or optical plates.
This changed to some degree with the increasing popularity of dot matrix printers. The characters on these systems were "drawn" as a series of dots, the proper dots to use defined as a font table inside the printer. As they grew in sophistication, dot matrix printers started including several built-in fonts from which the user could select, and some models allowed users to upload their own custom glyphs into the printer.
Dot matrix printers also introduced the ability to print raster graphics. The graphics were interpreted by the computer and sent as a series of dots to the printer using a series of escape sequences. These printer control languages varied from printer to printer, requiring program authors to create numerous drivers.
Vector graphics printing was left to special-purpose devices, called plotters. Plotters did share a common command language, HPGL, but were of limited use for anything other than printing graphics. In addition, they tended to be expensive and slow, and thus rare.
PostScript printing
Laser printers combine the best features of both printers and plotters. Like plotters, laser printers offer high quality line art, and like dot-matrix printers, they are able to generate pages of text and raster graphics. Unlike either printers or plotters, however, a laser printer makes it possible to position high-quality graphics and text on the same page. PostScript made it possible to fully exploit these characteristics, by offering a single control language that could be used on any brand of printer.
PostScript went beyond the typical printer control language and was a complete programming language of its own. Many applications can transform a document into a PostScript program whose execution will result in the original document. This program can be sent to an interpreter in a printer, which results in a printed document, or to one inside another application, which will display the document on-screen. Since the document-program is the same regardless of its destination, it is called device-independent.
PostScript is noteworthy for implementing on-the fly rasterization; everything, even text, is specified in terms of straight lines and cubic Bézier curves (previously found only in CAD applications), which allows arbitrary scaling, rotating and other transformations. When the PostScript program is interpreted, the interpreter converts these instructions into the dots needed to form the output. For this reason PostScript interpreters are also sometimes called PostScript Raster Image Processors, or RIPs.
Font handling
Almost as complex as PostScript itself was its handling of fonts. The rich font system used the PS graphics primitives to draw glyphs as line art, which could then be rendered at any resolution. Though this sounds like a reasonably straightforward concept, there were a number of typographic issues that had to be considered.
One is that fonts do not actually scale linearly at small sizes; features of the glyphs will become proportionally too large or small and they start to "look wrong." PostScript avoided this problem with the inclusion of hints which could be saved along with the font outlines. Basically they are additional information in horizontal or vertical bands that help identify the features in each letter that are important for the rasterizer to maintain. The result was significantly better-looking fonts even at low resolution; it had formerly been believed that hand-tuned bitmap fonts were required for this task.
At the time, the technology for including these hints in fonts was carefully guarded, and the hinted fonts were compressed and encrypted into what Adobe called a Type 1 Font (also known as PostScript Type 1 Font, PS1, T1 or Adobe Type 1). Type 1 was effectively a simplification of the PS system to store outline information only, as opposed to being a complete language (PDF is similar in this regard). Adobe would then sell licenses to the Type 1 technology to those wanting to add hints to their own fonts. Those who did not license the technology were left with the Type 3 Font (also known as, PostScript Type 3 Font, PS3 or T3). Type 3 fonts allowed for all the sophistication of the PostScript language, but without the standardized approach to hinting. Other differences further added to the confusion.
Type 2 was designed to be used with the Compact Font Format (CFF), and were implemented for a compact representation of the glyph description procedures to reduce the overall font file size. The CFF/Type2 format later became the basis for Type 1 OpenType fonts.
CID-keyed font format was also designed, to solve the problems in the OCF/Type 0 fonts, for addressing the complex Asian-language (CJK) encoding and very large character set issues. CID-keyed font format can be used with the Type 1 font format for standard CID-keyed fonts, or Type 2 for CID-keyed OpenType fonts.
Adobe's rates were widely considered to be prohibitively high, and it was this issue[citation needed] that led Apple to design their own system, TrueType, around 1991. Immediately following the announcement of TrueType, Adobe published the specification for the Type 1 font format. Retail tools such as Altsys Fontographer (Acquired by Macromedia in January 1995, owned by FontLab since May 2005) added the ability to create Type 1 fonts. Since then, many free Type 1 fonts have been released; for instance, the fonts used with the TeX typesetting system are available in this format.
In the early 1990s there were several other systems for storing outline-based fonts, developed by Bitstream and METAFONT for instance, but none included a general-purpose printing solution and they were therefore not widely used as a result.
In the late 1990s, Adobe joined Microsoft in developing OpenType, essentially a functional superset of the Type 1 and TrueType formats. When printed to a PostScript output device, the unneeded parts of the OpenType font are omitted, and what is sent to the device by the driver is the same as it would be for a TrueType or Type 1 font, depending on which kind of outlines were present in the OpenType font.
Other implementations
In the 1980s, Adobe got most of their revenue from the licensing fees for their implementation of PostScript for printers, known as a raster image processor or RIP. As a number of new RISC-based platforms became available in the mid 1980s, some found Adobe's support of the new machines to be lacking.
This and issues of cost led to third-party implementations of PostScript becoming common, particularly in low-cost printers (where the licensing fee was the sticking point) or in high-end typesetting equipment (where the quest for speed demanded support for new platforms faster than Adobe could provide). At one point, Microsoft and Apple teamed up to try to unseat Adobe's laser printer monopoly, Microsoft licensing to Apple a PostScript-compatible interpreter it had bought called TrueImage, and Apple licensing to Microsoft its new font format, TrueType. (Apple ended up reaching an accord with Adobe and licensed genuine PostScript for its printers, but TrueType became the standard outline font technology for both Windows and the Macintosh.) Some third-party PostScript-compatible interpreters are still widely used in printers, particularly PhoenixPage, which is standard in black-and-white Hewlett-Packard laser printers (as of 2006).
Many basic, inexpensive laser printers don't support PostScript, instead coming with drivers that simply rasterize the platform's native graphics formats rather than converting them to PostScript first. When PostScript support is needed for such a printer, a free PostScript-compatible interpreter called Ghostscript can be used. Ghostscript prints PostScript documents on non-PostScript printers using the CPU of the host computer to do the rasterization, sending the result as a single large bitmap to the printer. Ghostscript can also be used to preview PostScript documents on a computer monitor and to convert PostScript pages into raster graphics such as TIFF and PNG, and vector formats such as PDF.
Very high-resolution devices, such as imagesetters or CTP platesetters, in which resolutions exceeding 2500 dpi are common, still require external RIPs with large amounts of memory and hard drive space. Very high-end laser printer systems (known as digital presses) also use an external RIP to separate the more readily-upgradable computer from the specialized printing hardware. Companies such as EFI and Xitron specialize in such RIP software.
Use as a display system
With PostScript becoming a de facto standard for printed output, it was natural to consider using the same language for describing the screen output as well. The rapid increase in CPU power in the late 1980s, combined with an interest in windowing systems, led to several attempts to create a display system that used PostScript as its primary display technology.
There are a number of advantages to using PS as the display system. One is that the fonts on other systems required the user to keep not only bitmaps for the screen, but also Type 1 for the printer. Using PS on the display would eliminate this and require only one set. Another advantage is that it allows for the "dumbing down" of printers. When the LaserWriter was released it was the most powerful (and expensive) machine in Apple's lineup, a result of needing considerable processing power and memory to render the page at a "high" resolution of 300 dpi in a reasonable amount of time. In contrast, the 400-dpi printer that shipped with the NeXT platform contained no image renderer at all, instead using the computer's CPU to do the rendering and passing the rendered page as a bitmap to the printer. (See also GDI printer.)
The main advantage in using PostScript as a windowing system is that it allows one to write desktop publishing (DTP) and other graphically-intensive applications with a single set of graphics routines. The same code that generates bitmaps for the window can be used to generate bitmaps for the printer without any translation. DTP applications on traditional systems require the programmer to construct the GUI editor in the platform's own graphics system (for example, QuickDraw on the Macintosh, or Graphics Device Interface (GDI) on Microsoft Windows) and then write additional code to translate the graphics into proper PostScript for printing. This often takes up most of the programming effort on such projects[citation needed] and is a major source of bugs.
The two main examples of PostScript as a display technology are Display PostScript (DPS) and NeWS. They differed dramatically in terms of where the display logic was applied; in DPS the view system was left to the hosting OS, whereas under NeWS the entire display was written in PS and ran in a single complex interpreter.
The language
PostScript is a Turing-complete programming language. Typically, PostScript programs are not produced by humans, but by other programs. However, it is possible to produce graphics or to perform calculations by hand-crafting PostScript programs.
PostScript is an interpreted, stack-based language similar to Forth but with strong dynamic typing, data structures inspired by those found in Lisp, scoped memory and, since language level 2, garbage collection. The language syntax uses reverse Polish notation, which makes parentheses unnecessary, but reading a program requires some practice, because one has to keep the layout of the stack in mind. Most operators (what other languages term functions) take their arguments from the stack, and place their results onto the stack. Literals (for example numbers) have the effect of placing a copy of themselves on the stack. Sophisticated data structures can be built on the array and dictionary types, but cannot be declared to the type system, which sees them all only as arrays and dictionaries, so any further typing discipline to be applied to such user-defined "types" is left to the code that implements them.
Arithmetic
Example:
3 4 add 5 1 sub mul
will compute (3 + 4) × (5 − 1)
Named variables
PostScript variables are placed on a dictionary stack where everything that is not a literal is looked up. On a match, the current value stored under the name is pushed (or rather, executed — see below). If a variable that is not in the dictionary stack is searched for, it is termed a mismatch, resulting in an error. To place something in the current dictionary (i.e. the topmost dictionary on the dictionary stack) one needs the def operator, which takes a name and a value as its arguments. Names are constructed by prefixing (or quoting) with a slash. So
/x1 15 def
will first push the name "x1" on the stack, then the value 15, then execute def which will take both from the stack, and write 15 into the current dictionary under the name "x1". Later occurrences of "x1" (not to be confused with "/x1") will push 15 onto the stack as long as the variable is unchanged. This code will increment the content of x1 by 2, assuming x1 is already present in the current dictionary:
/x1 x1 2 add def
Stack operators
Several Postscript operators rearrange or manipulate the stack: duplicate (dup), discard (pop) and exchange (exch) operate on elements at the top of the stack, whereas roll rotates a specified section of the stack, copy duplicates a specified portion, and index lets you access the stack like an array.
Procedure definitions
Some programming utility is offered by { and }. The opening brace puts the interpreter in deferred execution mode, so that everything is just placed on the stack, even operators and other executable objects. The one exception is the closing brace, which takes everything put on the stack since the opening brace, bundles it up into an (anonymous) procedure, and places that on the stack.
This construct is used in various ways, for subroutine definition (the anonymous procedure is assigned to a variable), loops, conditionals, etc. Example:
x1 0 eq { 0 } { 1 x1 div } ifelse
This code first uses the eq operator to test whether the value of x1 is equal to 0; depending on the outcome eq will push true or false onto the stack. After that, two procedures are pushed onto the stack. Then ifelse is executed, which takes three arguments from the stack, and will execute either the second (if the third is true) or first (if the third is false). In summary, 0 results if x1 is 0, 1/x1 is the result for all other cases.
/inc3 { 3 add } def
Here def is used to place something in the current dictionary, only this time it is a procedure instead of a simple integer. This works because the values coming from the dictionary are executed, not just pushed (as simplistically stated above). Since executing a literal amounts to pushing it, that did not make a difference before. Now executing "inc3" will first look it up in the dictionary, find the procedure object representing "{ 3 add }" and execute that. One value must reside on the stack for this to work, since add needs two arguments, only one of which is given in the procedure itself. Naturally, one passes arguments to procedures by placing them on the stack, so we can simply view "inc3" as a procedure that takes one argument. Example call:
71 inc3
will put 71 on the stack, which inc3 will increment by three, for a final result of 74.
Procedures are simply executable arrays, so they can also be created 'manually':
/inc3 [ 3 /add load ] cvx def
Warning: the above will only work if add is still an operator. If it had been redefined as a procedure an additional exec would be required. However, the exec operator may similarly have been redefined... the solution of which is left as an exercise for the reader!
Graphics manipulations
To produce graphics, PostScript uses an ordinary cartesian coordinate system.
100 200 moveto 300 400 lineto stroke
moves the "cursor" to the point with coordinates (100, 200) and then draws a line to the point (300, 400).
50 70 moveto 100 200 50 80 100 100 curveto stroke
produces a cubic Bézier curve from (50, 70) to (100, 100) with control points (100, 200) and (50, 80).
250 250 moveto (Wikipedia) show
will create the text "Wikipedia" at coordinate location (250, 250), rendered in a preselected font (using a possible command string such as /Courier findfont 12 scalefont setfont)
Graphics are initially produced in the "user coordinate system" and may then optionally be rotated, scaled or skewed before being copied to the "device coordinate system" specifying the final output.
200 300 translate 45 rotate
will translate the contents of the user coordinate system 200 points upwards, 300 points to the right and rotate it 45 degrees before they are copied to the device coordinate system.
The character "%" is used to introduce comments in PostScript programs. As a general convention, every PostScript program should start with the characters "%!" so that all devices will properly interpret it as PostScript.
"Hello world"
And finally, a Hello World program, the customary way to show a small example of a complete program in a given language, might look like this in Postscript:
%!PS /Courier findfont 20 scalefont setfont 72 500 moveto (Hello world!) show showpage
or if the output device has a console
%!PS (Hello world!) =
See also
![](http://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/40px-Wikibooks-logo-en-noslogan.svg.png)
- Adobe Systems
- Ghostscript
- Portable Document Format (PDF)
- Document Structuring Conventions (DSC)
- Vector graphics
- Typeface, List of typefaces
- Computer font
- Display PostScript
- Encapsulated PostScript
- Reverse Polish Notation
- PostScript Printer Description (PPD) drivers.
References
This article is based on material taken from the Free On-line Dictionary of Computing prior to 1 November 2008 and incorporated under the "relicensing" terms of the GFDL, version 1.3 or later.
External links
- PostScript Language Reference, third edition (PLR3), plus its Supplement, is the de facto defining work, known as "The Red Book" on account of its covers. The first edition covered PostScript Level 1, the second edition covered a greatly expanded language known as PostScript Level 2, and includes documentation for Display PostScript as well. The third edition covers PostScript 3 (with this version, Adobe dropped "level" from the name) but no longer includes DPS.
- PostScript Language Tutorial and Cookbook is the corresponding introductory text, known as "The Blue Book" on account of its covers.
- PostScript language program design is "The Green Book".
- A First Guide to PostScript
- Adobe: PostScript vs. PDF - Official introductory comparison of PS, EPS vs. PDF.
- Mathematical Illustrations: A Manual of Geometry and PostScript — a book by Bill Casselman.
- Thinking in PostScript, 1990 by Glenn Reid, Addison-Wesley — available online courtesy of the author. A thorough tutorial.
- The Type 1 Font Format (PDF file).
- Direct use of the PostScript language, further discussion of PostScript in programming-language terms
- PostScript and Ghostscript Resources - Program tools for working with PostScript
- Troubleshooting PostScript errors - Overview of PostScript errors and solutions or work-arounds to get rid of them
PostScript hacks
- Life in PostScript - a PostScript version of Conway's Game of Life
- Ghostscript 7.05 reader/converter for .PS and PDF for DOS
- PostScript fractals
- PostScript barcodes
- PostScript HTML renderer
- A PostScript raytracer, from Ray Tracing News, September 5 1988, Volume 1, Number 8 .
- An IRC Bot written in PostScript