cs349 - s10 - Lecture 32
CS349 - Implementing User Interfaces - Spring 2010
Public Service Annoucements
- Assignment 4.
Lecture 32 - PostScript
PostScript was created as a `page description language', which means that
it was designed to have the ability to put onto the output of a printer
anything that the printer can print. `Anything that a printer can print' has
an easy definition:
- writePixel( colour, x, y ).
What does this mean?
- 600 x 600 x 8.5 x 11 ~ 300 MColours
Once upon a time this was a big deal, but not any more
- at 100 Mbps this is just 3 x (bits/Colour) seconds
- and gigabit ethernet is increasingly common,
- including inside high end printers.
Actually, it means something much more serious
- knowing all the pecularities of the printer that is printing - how do
printers actually work
- start with a bit-map (pixel-map)
- write the bit-map to a charged cylinder using a laser and a
mirror
- drag the cylinder through the toner
- roll the cylinder over the paper
- heat the paper to fuse the toner
- every printer is different, and needs a different set of pixels written
In practice this is a serious problem for the printer maker
- All kinds of `secret' information about your printer has to be made
available to the maker of the operating system.
- The quality of the operating system implementation determines the
quality that users obtain from your printer.
Printer makers promoted a different model
- Application writes a program in a `printer command language'
- lpr sends the program to the printer
- The printer executes the program to produce the page, factoring in its
own peculiarities.
Very attractive feature of this model is
- The same print engine produces different quality output on different
printers, and is sold at different prices.
Obviously, there's a `natural monopoly' among competing `printer command
languages'.
- John Warnock: Xerox -> Adobe, followed by the Interpress fiasco.
General principles
- Stack-based language: why "stack"? why "language"?
- Transformation-based geometry: why "geometry"? why
"transformation"?
Pen-based drawing model: why "drawing model"? why "pen"?
- current page (drawing surface)
- current coordinate system
- moved around by a collection of transformation operators
- actually `nothing but' a transformation matrix
- which is applied to any point handed to the system
- important difference between moving coordinate systems and moving
objects within a coordinate system
- current clipping region
- used to determine which geometry actually gets to the page
- current path
- accumulator for geometry
- put onto the current page by explicit requests
- current position
- used when adding things to the path
- current coordinate system
- used when interpreting numbers as positions
- current graphics context
- consulted at the point when
stroke or
fill is used.
- current dictionary
- contains a collection of definitions that are the current context
of the computation
- the top of a stack of dictionaries
- used to change the current context, just like in other programming
languages. What does this mean?
Two distinct coordinate systems
- User coordinate system
- what was called above the current coordinate system
- rooted in the page
- units are 1/72 of an inch
- Device coordinate system
- depends on the display device
- suitable transformation is performed in the device driver
Examples
- Draw a square
newpath
0 0 moveto
1 0 lineto
1 1 lineto
0 1 lineto
closepath
stroke
showpage
Comments
newpath zeros the current path
closepath fills in the last edge, guarantees that the
path is closed, fixes up the corners
stroke adds the current path to the current page
showpage outputs the current page and clears it.
- Define a filled square
/square
{ newpath
0 0 moveto
1 0 lineto
1 1 lineto
0 1 lineto
closepath
fill } def
Comments
fill paints the pixels enclosed by the path
def puts the key square into the dictionary, defined
as the (executable) array of characters enclosed in braces.
- Draw many squares
/square
{ newpath
0 0 moveto
1 0 lineto
1 1 lineto
0 1 lineto
closepath
fill } def
square
100 100 translate
square
100 100 translate
square
showpage
Comments
square puts its definition on top of the stack
translate moves the user corrdinate system to a new
position on the page
Giving arguments to a procedure
/square
{ newpath
0 0 moveto
1 0 lineto
1 1 lineto
0 1 lineto
closepath
fill } def
/translatedSquare
{ translate
square } def
0 0 translatedSquare
100 100 translatedSquare
100 100 translatedSquare
Comments:
0 is put on the stack
0 is put on the stack
{translate square} is put on the stack and executed as if
it is a program
translate is executed, consuming the two arguments
square is executed
Return to: