How to use the PostScript interface


To generate a Postscript (or encapsulated ps) file corresponding to a single image in a canvas, you can:

Special characters

The following characters have a special action on the Postscript file:
       `   : go to greek
       '   : go to special
       ~   : go to ZapfDingbats
       ?   : go to subscript
       ^   : go to superscript
       !   : go to normal level of script
       &   : backspace one character
       #   : end of greek or of ZapfDingbats

These special characters are printed as such on the screen. To generate one of these characters on the Postscript file, you must escape it with the escape character "@".

The use of these special characters is illustrated in several macros referenced by the TPostScript constructor.

Writing several canvases to the same Postscript file

The following sequence writes the canvas to "c1.ps" and closes the ps file:

    TCanvas c1("c1");
    h1.Draw();
    c1.Print("c1.ps");

If the Postscript file name finishes with "(", the file remains opened (it is not closed). If the Postscript file name finishes with ")" and the file has been opened with "(", the file is closed.

Example:

 {
    TCanvas c1("c1");
    h1.Draw();
    c1.Print("c1.ps(");  // write canvas and keep the ps file open
    h2.Draw();
    c1.Print("c1.ps");   // canvas is added to "c1.ps"
    h3.Draw();
    c1.Print("c1.ps)");  // canvas is added to "c1.ps" and ps file is closed
 }

The TCanvas::Print("file.ps(") mechanism is very useful, but it can be a little inconvenient to have the action of opening/closing a file being atomic with printing a page. Particularly if pages are being generated in some loop one needs to detect the special cases of first and last page and then munge the argument to Print() accordingly.

The "[" and "]" can be used instead of "(" and ")" as shown below.

Example:

    c1.Print("file.ps[");        // No actual print, just open file.ps

    for (int i=0; i<10; ++i) {
       // fill canvas for context i
       // ...

       c1.Print("file.ps");      // Actually print canvas to the file
    }  // end loop
    
    c1.Print("file.ps]");        // No actual print, just close the file   


WARNING: Patterns (hatches) do not appear on the PostScript files when displayed with gv.

When a PostScript file is visualized with gv the patterns and hatches do not appear. This is a known bug in gv: by default gv visualizes PostScript files with anti-aliasing turned ON. Turn it OFF (by pressing the key "a" in the gv window) and the patterns will appear. The patterns appear correctly when the file is printed.

To disable the anti-aliasing by default in gv you can put the line:
GV.antialias:           False
in the ~/.gv file.

The convert command uses also ghostscript to deal with PS files. So, patterns in a PS files will not be properly converted with the default convert options. To have the patterns properly converted use:
convert +antialias c1.ps c1.gif 
The valid patterns are:

Rene Brun, Fons Rademakers
Last update 11/11/04 by Olivier Couet