COMP15 Fall 20XX
Due: Thursday, September 30, 11:00PM
Some kinds of information are best communicated visually using computer graphics. Pictures, diagrams, etc. can be rendered to a wide variety of devices such as display screens and printers. PostScript is an industry-standard, device independent page description language. A PostScript program describes what to draw on one or more pages: text, images, lines, arcs, etc. The PostScript language provides a flexible means to control the placement, orientation, scale and attributes (grey scale, fill pattern) of the primitive graphic forms that it supports.
Writing PostScript primitives is a tedious and error prone process. This project will develop a reusable module that hides some of the details of the PostScript language in order to make graphics programming easier. The module virtualizes the concept of a PostScript file and exports an application programming interface (API) that is similar to a simple graphics device. (The API is an abstraction of a simple graphics device.)
Modules wishing to use the API must include the declaration of the module interface and make calls through the API. A calling module performs the following sequence of operations to draw a picture:
The user may preview the finished PostScript file using the Ghostscript previewer (gs) or print the file to get hard-copy.
The objectives for this project are:
Two files are provided: psfile.h, which is the declaration of the PostscriptFile class and its interface, and psfile.cpp, which is the definition of the PostscriptFile class and the function main. These two files will help get you started with the project. You need to copy these files from the directory /g/15/class/project2 to your own working directory and read through the existing implementation to get more information.
The existing implementation is incomplete. You will need to add new method functions to psfile.cpp to fully implement the interface. An informal interface specification is given below. Here are some additional requirements to be satisfied:
Once you have completed the basic assignment, you can try adding more PostScript primitives. The specified set is, errrr, pretty basic. By the way, you will need to draw text for the eighth assignment. Of course, you must test what you build. Extra challenges are always above the call of duty and are for extra credit.
Be sure to read the on-line tutorials on PostScript and C++ file input/output. Just take the links from the COMP15 schedule page. The PostScript write-up has links to the Adobe PostScript tutorial and reference manuals (the "blue" and "red books.")
Use the provide system to submit the finished program:
provide comp15 a2 psfile.h psfile.cppBe sure you are completely satisfied with your work before submitting!
Function: PostscriptFile(char *filename) ; Purpose: Initializes a new PostscriptFile object; Opens the specified file for writing Parameters: filename: Name of the file to create and open (pointer to C string) Returns: Nothing Error conditions: Cannot create (open) file Function: ~PostscriptFile() ; Purpose: Closes the output file before the PostscriptFile object is destroyed Parameters: None Returns: Nothing Function initgraphics() ; Purpose: Emits the PostScript initgraphics primitive; "Emit" is a fancy word for "write" Parameters: None Returns: Nothing Function: void showpage() ; Purpose: Emits the PostScript showpage primitive Parameters: None Returns: Nothing Function: void gsave() ; Purpose: Emits the PostScript gsave primitive Parameters: None Returns: Nothing Function: void grestore() ; Purpose: Emits the PostScript grestore primitive Parameters: None Returns: Nothing Function: void scale(double sx, double sy) ; Purpose: Emits the PostScript scale primitive and its parameters Parameters: sx: X scale factor for coordinate transformations sy: Y scale factor for coordinate transformations Returns: Nothing Function: void rotate(double angle) ; Purpose: Emits the PostScript rotate primitive and its parameter Parameters: angle: Angle of rotation for coordinate transformations (degrees) Returns: Nothing Function: void translate(int tx, int ty) ; Purpose: tx: X translation offset for coordinate transformations ty: Y translation offset for coordinate transformations Parameters: None Returns: Nothing Function: void line(int x1, int y1, int x2, int y2) ; Purpose: Describe a line from the first point to the second point; Emit necessary PostScript primitives Parameters: x1: X coordinate of first point y1: Y coordinate of first point x2: X coordinate of second point y2: Y coordinate of second point Returns: Nothing Function: void rect(int x, int y, int width, int height) ; Purpose: Describe a rectangle; Emit necessary PostScript primitives Parameters: x: X coordinate of the lower left corner of the rectangle y: Y coordinate of the lower left corner of the rectangle width: Size of the rectangle in the X direction height: Size of the rectangle in the Y direction Returns: Nothing Function: void circle(int x, int y, int radius) ; Purpose: Describe a circle centered at the specified point and having the specified radius; Emit necessary PostScript primitives Parameters: x: X coordinate of center point y: Y coordinate of center point radius: Radius of the circle Returns: NothingCopyright © 2004-2013 Paul J. Drongowski