pscript.icn: Procedure for explicitly writing PostScript

procedure epsheader:       write PostScript header
procedure psprotect:       escape special PostScript characters

link pscript
February 21, 2003; Gregg M. Townsend
This file is in the public domain.

This file contains procedures for writing PostScript output explicitly,
as contrasted with the procedures in psrecord.icn that write PostScript
as a side effect of normal graphics calls.

epsheader(f, x, y, w, h, flags) writes an Encapsulated PostScript
file header and initializes the PostScript coordinate system.

psprotect(s) adds escapes to protect characters that are special in
PostScript strings, notably parentheses and backslash.
____________________________________________________________

epsheader(f, x, y, w, h, flags) aids the creation of an Encapsulated
PostScript file by writing a header.  An EPS file can either be
incorporated as part of a larger document or sent directly to a
PostScript printer.

Epsheader() writes the first portion of the PostScript output to file
f; the calling program then generates the rest.  It is the caller's
responsibility to ensure that the rest of the file conforms to the
requirements for EPS files as documented in the PostScript Reference
Manual, second edition.

(x,y,w,h) specify the range of coordinates that are to be used in the
generated PostScript code.  Epsheader() generates PostScript commands
that center this region on the page and clip anything outside it.

If the flags string contains the letter "r" and abs(w) > abs(h), the
coordinate system is rotated to place the region in "landscape" mode.

The generated header also defines an "inch" operator that can be used
for absolute measurements as shown in the example below.

Usage example:

     f := open(filename, "w") | stop("can't open ", filename)
     epsheader(f, x, y, w, h)
     write(f, ".07 inch setlinewidth")
     write(f, x1, " ", y1, " moveto ", x2, " ", y2, " lineto stroke")
        ...
     write(f, "showpage")
____________________________________________________________

psprotect(s) adds a backslash character before each parenthesis or
backslash in s.  These characters are special in PostScript strings.
The characters \n \r \t \b \f are also replaced by escape sequences,
for readability, although this is not required by PostScript.

Source code | Program Library Page | Icon Home Page