Page description language from Adobe Postscript Page description language from Adobe
Copyright 2000, Georgia Tech Story History Basics Paths Drawing simple geometric shapes Working with Coordinate Systems Drawing ellipses Ghostscript and GSview 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech History Before Postscript (pre 1984) Dot matrix printers with poor quality output High quality printers with proprietary languages John Warnock at Xerox Parc created Interpress Couldn’t convince management to sell it Left Xerox and created Adobe with his old boss Abode created Postscript (1984) First used with Apple LaserWriter and Aldus PageMaker Desktop publishing took off See http://users.belgacom.net/prepresspanic/postscript/history/history.htm for more of the history. Dot matrix printers are like a computer screen in that the printer has a resolution of dots (pixels) per inch. John Warnock and Chuck Geschke were the founders of Adobe. For years the Apple LaserWriters had faster processors than the Macs they were connected to. 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech What is Postscript? A language for printing text and graphics. Advantages Device independent Manufactures license the interpreter Specifications are freely available Levels 1 (1985), 2 (1994), and 3 (1998) 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Basics Interpreted, stack-based language like FORTH 3 4 add Put 3 on the stack Put 4 on the stack add takes the top two items off the stack and adds them and puts the result on the stack This is also called postfix notation. 11/19/2018 Copyright 2000, Georgia Tech
Postscript files are Text Postscript is written in ASCII characters Use % for comment % draw a vertical line newpath 216 288 moveto 216 432 lineto stroke showpage Using GSView to View x is 3 inches from left y is 6 inches from bottom x is 3 inches from left y is 4 inches from bottom 11/19/2018 Copyright 2000, Georgia Tech
Default Coordinate System Origin is lower left corner of page X increases to left Y increases going up Units are 1/72 inches So 72 units in an inch Origin 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Like Drawing by Hand Start with the current page being empty Draw things on the page Things drawn on top of other things will obscure them When you are done send the page to the printer 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Postscript uses Paths What is a path? Set of connected and disconnected points, lines, and curves that describe shapes and their positions 11/19/2018 Copyright 2000, Georgia Tech
What can you do with a Path? A path can be Stroked (like using a pen to draw it) Filled (like using a paint can to fill it) Used as a clipping boundary (like using a stencil) 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Defining a Path Use newpath to start a path newpath Use moveto to move the pen to a point on the page (but nothing draws yet) 216 288 moveto Use lineto to create a line from the previous point to the current point 216 432 lineto 11/19/2018 Copyright 2000, Georgia Tech
Disconnected Path Example This will draw two unconnected lines newpath 72 72 moveto 144 72 rlineto 144 360 moveto 0 -72 rlineto stroke showpage Using GSView to View 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Relative Positioning Using rlineto uses the x and y as relative to the current position Positive values X right Y up Negative values X left Y down Can use rmoveto as well To move relative to the current position -x +y +x+y -x -y +x-y 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Drawing a Rectangle newpath 270 360 moveto 0 72 rlineto 144 0 rlineto 0 -72 rlineto -144 0 rlineto stroke showpage second third first The moveto moves the pen to 3.75 inches from left and 5 inches from the bottom of the page. The 0 72 rlineto draws a 1 inch line up from that position in y. The 144 0 draws the top of the rectangle going 2 inches to the right. The 0 -72 draws the right side of the rectangle by going down 1 inch in y. The -144 0 draws the bottom of the rectangle by going left in x 2 inches. fourth start 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Drawing a Polygon newpath 270 360 moveto 200 340 lineto 230 320 lineto 310 320 lineto 330 340 lineto closepath stroke showpage 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Closing the Polygon Use closepath to go from last point to the last moveto point does a mitered join lineto lineto lineto moveto closepath lineto lineto 11/19/2018 Copyright 2000, Georgia Tech
Working with Coordinates The default user coordinates are at the bottom left of the current page But the user coordinates can be Translated – moves the origin x y translate Scaled – change the size of the units x y scale Rotated – rotates the axes counterclockwise angle rotate 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Graphics State What is in the graphics state? Current path, gray value, line width, user coordinate system Save the state to return to it later gsave Restore a saved state grestore 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Using Graphics State newpath 270 360 moveto 0 72 rlineto 144 0 rlineto 0 -72 rlineto -144 0 rlineto gsave .5 setgray fill grestore stroke showpage Save current graphics state The fill command clears the current path. So, we save the current path with gsave and restore it to outline the border of the rectangle. Clears current path Restore the saved graphics state including path 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Drawing Arcs The arc operator draws arcs (and circles) Center is at centerX and centerY Radius of radius Arc drawing starts at beginAngle from x axis and counter clockwise to endAngle centerX centerY radius beginAngle endAngle arc Example: 300 365 100 0 90 arc The example starts at 0 degrees from the x axis, so on the x axis and goes counterclockwise to 90 degrees. The center is at 300 in x and 365 in y with a radius of 100 units. You can also draw arcs clockwise using arcn. 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Drawing a Circle Use arc with a begin angle of 0 and an end angle of 360 Example 300 365 72 0 360 arc 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech How to Draw Ellipses? Use the arc operator But, first scale the user coordinate system Example newpath 1 .75 scale 300 365 72 0 360 arc stroke showpage 1 .75 scale 1 .5 scale .5 1 scale To draw a ellipse you draw a circle but first scale the user coordinate system to match the ratio of the width to the height. 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Defining Variables Use the def operator to define variables /ppi 72 def % define the points per inch var 10 ppi mul % multiply 10 * 72 /ppi ppi 1 add def %add 1 to current value The /ppi means put the literal on the stack and don’t look up the value of it in the dictionary 11/19/2018 Copyright 2000, Georgia Tech
Postscript Dictionaries Map keys to values System dictionary Maps predefined operators to actions User dictionary Maps names to user defined variables and procedures Looks in user dictionary first then system You can actually create more dictionaries. 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Procedures A procedure is a set of operations grouped together with a name It is stored in the user dictionary with the name as the key and the operations as the value Example /inch {72 mul} def 5 inch (results in 5 * 72) 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Creating a Procedure Create a box procedure /box { 72 0 rlineto 0 72 rlineto -72 0 rlineto closepath} def 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Using a Procedure newpath 252 324 moveto box 270 360 moveto box 360 480 moveto box stroke showpage 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Printing Text Find the font in the font dictionary Returns a one-point size font Scale the font to the desired size Size is specified by the minimum vertical separation needed between lines of text 12 point font needs 12 points between lines of text A point is 1/72 of an inch Set the scaled font to the current font Show the text 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Fonts and Typefaces What is a font? A collection of characters with a unified design. An implementation of a typeface. Typeface The design used in a font Typeface families A set of typefaces designed to work together Examples: Times-Roman, Helvetica, Courier 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Example with Fonts % show ‘Hello World’ in times roman /Times-Roman findfont 24 scalefont setfont 72 200 moveto (Hello World) show showpage 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Postscript Operators Add 3 4 add → 7 Subtract 8 4 sub → 4 Multiply 6 8 mul → 48 Divide 13 8 div → 1.625 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Stack Operators clear Removes all items from the stack 6 7 8 clear → nothing on stack dup Duplicates the top item on the stack 6 7 8 dup → 6 7 8 8 pop Remove the top item from the stack 6 7 8 pop → 6 7 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Painting Operators fill Fill the current path with the current color setgray Set the current color .5 setgray (1 is white and 0 is black) setlinewidth Set the current line width (x/72 units) 4 setlinewidth % 4/72 units wide 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech Ghostscript What is it? Ghostscript is an interpreter for the PostScript page description language Has 3 licenses Aladdin Free Public License (AFPL) allows free use but not commercial distribution Where to get it? http://www.ghostscript.com/ http://www.cs.wisc.edu/~ghost/ There is also a GNU license version of Ghostscript. Ghostscript was originally created by L. Peter Deutsch, President of Aladdin Enterprises. 11/19/2018 Copyright 2000, Georgia Tech
Copyright 2000, Georgia Tech GSview What is it? A PostScript previewer based on Ghostscript by Ghostgum Software Pty Ltd A graphical user interface for Ghostscript Where to get it? http://www.cs.wisc.edu/~ghost/gsview/ You must have Ghostscript installed to use GSview. 11/19/2018 Copyright 2000, Georgia Tech