Project 2, CISC181 honors, Spring 2004

Writing a font and plotting text

In this project, you will produce a font by describing the points that make up each character. You will then write a program that can read this font in from a file, and then plot the words on the command line in that font.

Part 0: Preparation

Before starting, complete the exercises at the following link:
http://copland.udel.edu/~pconrad/cisc181h/04S/labs/gnuplot.html
You do NOT have to turn in those exercises (the ones in gnuplot.html) for credit, but you should complete them at least far enough to familiarize yourself with the general idea of how to work with plotting characters in gnuplot.

Also, you should copy the files font.txt and readFontFile.cc from:

http://copland.udel.edu/~pconrad/cisc181h/04S/proj2/proj2

Part 1: Preparing the font.txt file

The font.txt data file has the following format:
A 0,0,0 0,4,0 2,8,0 4,4,0 4,0,1 0,4,0 4,4,2
D 0,0,0 0,8,0 4,6,0 4,2,0 0,0,2
F 0,0,0 0,8,0 3,8,1 0,4,0 2,4,2
H 0,8,0 0,0,1 0,4,0 4,4,1 4,8,0 4,0,2
The first character on the line is a character. The remaininder of the line consists of the points needed to draw that character. Each triple consists of an x,y,s value, where x and y are the (x,y) coordinate, and s is one of the following values: Your program should be able to work even with an incomplete font.txt file. That is, it should work properly for the letters that are defined in the font, and print a "box" for any character that is not defined in the font. The box consists of the outline formed by points (0,0,0) (4,0,0) (4,8,0) (0,8,0) (0,0,2)). You may collaborate with your fellow classmates on producing the font.txt file. That is, you may divide up the alphabet and share letters with one another. I suggest you do so by putting a link on your CISC181 web page to your font.txt file, and discussing among yourselves how to divide up the upper and lower case alphabet, numbers, and special characters.

There are 127 ASCII characters in all (see the table in Appendix B of Deitel/Deitel), and there are 14 of you. However, of these 127 characters, 31 of them are "non-printing" characters, and number 32 is the "space". So there are really only 95 characters. If you divide them up evenly, you should only have to do 6 or 7 characters each to have the entire printable 7-bit ASCII character set covered.

Part 2: Reading the font.txt file

The file readFontFile.cc illustrates how to read in the font.txt file.

What you want to do next is modify this file so that it will construct an array, declared as:

// declare an array of 127 pointers, each initialized to NULL.
Point *fontArray[127] = {NULL};

This array is indexed by the ASCII value of each character. As you read the data from the font.txt file, you will add pointers to linked lists into this array. For example, when you read the letter 'A' from the file, start reading each point. Allocate a struct point with:

p = new Point;
and fill in the values of p->x, p->y, and p->s from the values read in from the file. Set fontArray[letter] = p. Then, as you read each successive point, add it into the linked list. You'll need to keep a pointer "tail" to point to the end of the list as you add in each point.

Part 3: Printing the contents of argv[]

Now that your font array is loaded with the contents of font.dat, step through all the contents of the argv[] array. As you step through, you can use a loop such as the following to add each character to the output in the .dat file. As you add each character, you'll need to figure out what to set the xrange and yrange to (obviously, the more items in the argv array, the larger your yrange will have to be.)
for (int i=1; i<argc; i++)
  for (int j=0; j<strlen(argv[i]); j++)
    {
      // process character in argv[i][j]
    }

To sum up:

Your program should produce output based on the input on the command line. For example:
   
myplot HAPPY BIRTHDAY\!
will generate a myplot.dat and myplot.gnuplot file that will generate myplot.png, a file containing HAPPY BIRTHDAY!

To get an A grade, you should also allow for the case where the users passes in "-v" as the first command line parameter. If "-v" is the first command line parameter, that signifies "vertical". In this case, print the words down the page in the "on top of each other" style. For example:

myplot -v HAPPY BIRTHDAY\!
should be plotted as:
HAPPY
BIRTHDAY!

Note: to test your program with the "?", you will need to put a backslash on the command line. We can use the "banner" program (a unix utility) to illustarte. Try typing this at the Unix command prompt:

banner GOT MILK?
You'll probably get an error message "no match". Then try:
banner GOT MILK\?

You'll have to do the same thing when you test your program with "?". Note that there is nothing special you have to do in your program to make this work; this is something the shell does for you. The "\" will be gone by the time you read the command line parameter "MILK?" out of argv[2].


Phillip T Conrad
Last modified: Thu Apr 22 17:20:52 EDT 2004