Well, the gurus may smile (or worse), but for me, some (basic) un*x
features still appear to me as visions from God. So when I came upon
this way of solving some graphics problems, I decided to waste list
bandwidth on it, in hope of somebody finding it useful. So here goes:

Problem:
to produce advanced (but not dynamic, not moving, animated or so)
graphics output, graphs, reports and so, for viewing and optional
printout, without having to make a full blown X program.

Solution:
Generate graphics inside program as PostScript source, use both for
display and printouts.

How:
Postscript is basically an ascii text, Forth-like (reverse (perverse)
polish notation) language for describing the graphical appearance of
something, invented by Adobe. Possibilities are stunning and in full
colors. Pointers to two comprehensive Postscript pages (random, there
are many):
        http://www.geocities.com/SiliconValley/5682/postscript.html
        http://www.cs.wisc.edu/~ghost/

>From within your program, generate a Postscript (temporary) file by
basic fopen, fprintf, fputs, fclose or whatever way you prefer to make
an ascii file. Then cause the file (assuming X is up and
ghostscript/view is installed) to be viewed with something like
        system("ghostview <name of file>");
which start ghostview (or gv) in a separate window, while your program
pauses (could also be done with members of the exec* family, if your
program should continue.). In the Ghostview window, hitting the "print"
button typically produces a hardcopy, "quit" will cause ghostview to
exeit and the "system" call (or whatever method used for execution) to
return.

If only a hardcopy is needed, one could do
        system("lpr <name of file>")
provided lpr has a smart filter recognizing PostScript (this is standard
on at least RedHats distributions). In this case X doesnt enter into it.
svgalib postscript viwers probably exist.

And:
I have not tried it, but it is probably possible to dispose with the
temporary file and do something like
        FILE * handle = popen( "ghostview -", "w" );
        fprintf( handle, ... );
        pclose( handle );
        <disclaimer: syntax by memory>
It should be possible to display one page at a time or rewrite the same
page this way.

It is fairly easy to make a library encapsulating these actions an
providing the program surface with a suitable set of primitives (I am
working on such a library, but it isnt ready yet).

Hope some might find this useful,
Niels Hald Pedersen,
[EMAIL PROTECTED]

Reply via email to