You are here

How to use the PostScript interface?

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

  • Select the Print PostScript item in the canvas File menu. By default, a Postscript file with the name of the canvas.ps is generated.
  • Click in the canvas area, near the edges, with the right mouse button and select the Print item. You can select the name of the Postscript file. If the file name is xxx.ps, you will generate a Postscript file named xxx.ps. If the file name is xxx.eps, you generate an encapsulated Postscript file instead.
  • In your program (or macro), you can type:

    c1->Print("xxx.ps")
    

    or

    c1->Print("xxx.eps")
    

    This will generate a file corresponding to the picture in the canvas pointed by c1.

pad1->Print("xxx.ps")

prints only the picture in the pad pointed by pad1. The size of the Postcript picture, by default, is computed to keep the aspect ratio of the picture on the screen, where the size along x is always 20cm. You can set the size of the PostScript picture before generating the picture with a command such as:

TPostScript myps("myfile.ps",111);
myps.Range(xsize,ysize);
object->Draw();
myps.Close();
gStyle->SetPaperSize(xsize,ysize);

myps.Open();

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 theTPostScript 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

or:

GV.gsX11AlphaDevice: -sDEVICE=x11 -dTextAlphaBits=4 -dMaxBitmap=10000000 -dNOPLATFONTS

in the ~/.gv file (note that on some system, it may be required to run the gv-update-userconfig to validate this change 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: Patterns.gif

When the anti-aliasing is ON in gv it also makes the lines look much thicker than they are really.