NETB131 Programming Project 
Programming language
PostScript
An overview


Ilija Jovanov, F40681

                                                              

Preface:
1.)History and Special Features
2.)"Hello World" Program
3.)Fundamental Data Types (integer, floating point, string) and Assignment Operator
4.)Basic Control Flow (conditional and loop statements)
5.)Functions - syntax, writing and using functions, example
6.)Arrays - syntax, definition, example
7.)Compilers
8.)Projects and Software in PostScript
9.)Standard
10.) References


1.)History and Special Features

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


2.)"Hello World" Program

%!PS


/Courier findfont


20 scalefont


setfont


72 500 moveto


(Hello world!) show


showpage

Or if the output device has a console:

%!PS


(Hello world!) =


3.)Fundamental Data Types (integer, floating point, string) and Assignment Operator

Numbers:
- Signed integers, such as


123 -98 43445 0 +17


-Real numbers, such as


-002 34.5 -3.62 123.6e10 1.0E-5 1E6 -1. 0.0


- Radix numbers, such as


8#1777 16#FFFE 2#1000
Example:

3 4 add 5 1 sub m

will compute (3 + 4) × (5 − 1)

Strings:


There are three conventions for quoting a literal string object:


-
As literal text, enclosed in ( and )


-
As hexadecimal data, enclosed in < and >


-
As ASCII base-85 data, enclosed in <~ and ~> (LanguageLevel 2)


Example:

(Hello, world!) show    % Typeset "Hello, world!"

 

Assignment Operator:
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.This program doesn't have assignment operator. Arithmetic in C:

grade = (test1 + test2 + test3 + final ) / 4;
counter = counter + 1;

Arithmetic in PostScript

/grade test1 test2 add test3 add final add 4 div def
/counter counter 1 add def


4.)Basic Control Flow (conditional and loop statements)

Loops:


There are three loops in postscript.  The first is the repeat loop. 
1.)The form of this loop is:

num {op} rep

This will do op num times.


2.)Then there is the for loop with the form:

Start inc end {op} for

3.)The final loop is the loop with the form:

{op} loop

This loop will need to have an exit statement inside of it to terminate if not then you have an infinite loop (the best kind).

Here is an example of a repeat loop used in a procedure called harmonic:

/harmonic
{    /num 0 def
 /current 1 def
{/num 1 current div num add def
/current current 1 add def
} repeat
num
} def


5.)Functions - syntax, writing and using functions, example

Functions:
The PostScript language includes operators and procedures that take arguments

off the operand stack and put their results back on the stack. The add operator,

for example, pops two arguments, which must be numbers, and pushes the sum

of those numbers back on the stack. add could be viewed as a function with two

input values and one output value.

Similarly, the following procedure computes the average and the square root of

the product of two numbers:

{ 2 copy add


2 div


3 1 roll mul


sqrt


}


6.)Arrays - syntax, definition, example

Arrays:


The characters [ and ] are self-delimiting tokens that specify the construction of

an array. For example, the program fragment:


[ 123 /abc (xyz)

results in the construction of an array object containing the integer object 123,

the literal name object abc, and the string object xyz. Each token within the

brackets is executed in turn.

The [ and ] characters are special syntax for names that, when executed, invoke

PostScript operators that collect objects and construct an array containing them.

Thus the example

[ 123 /abc (xyz) ]

contains these five tokens:


The name object [


The integer object 123


The literal name object abc


The string object xyz


The name object ]



7.)Compilers

-A postscript interpreter with previewers for serval systems and many fonts.


-hp2ps is an HP-GL interpreter that is written in Postscript. It runs mostly on the printer itself. There is a small C program, provided mainly to circumvent Postscript's problems with the ^C character, which is a prominent part of HPGL's text support. The C program is not necessary if the HP-GL does not contain text, or uses a different label terminator.


8.)Projects and Software

-Epson StylusRIP


-PageMaker
-Adobe


9.)Standard


10.)References

http://en.wikipedia.org/wiki/PostScript#Use_in_printing


http://www-cdf.fnal.gov/offline/PostScript/BLUEBOOK.PDF


http://www.adobe.com/products/postscript/pdfs/PLRM.pdf


http://www.tailrecursive.org/postscript/postscript.html
http://www-cdf.fnal.gov/offline/PostScript