print filters for PostScript printers

xtdn at levels.sait.edu.au xtdn at levels.sait.edu.au
Mon Feb 25 08:14:25 AEST 1991


tony at uhcmtg.phys.hawaii.edu (Antonio Querubin) writes:
> I'm looking for some printing filters for PostScript printers (most of the
> printers are LaserWriters) that will allow me to print plain text files.

Below is what I used to use (when I had a PS printer).  Prepend it to your
ascii file and feed it to your PS printer.


-----------------------------------------------------------------
% ascii to PS.  By David Newall (ccdn at sait.edu.au).
% from an original idea by Bevin Steer (ccbjs at sait.edu.au).

/cm {28.346457 mul} def

% define margins.
/topmargin 28.89 cm def
/leftmargin 2 cm def
/botmargin 0.82 cm def

/bufsize 2048 def               % read input into this buffer
/inputbuf bufsize string def

/plainfont (Courier) def
/boldfont (Courier-Bold) def
/italicfont (Courier-Oblique) def
/bolditalicfont (Courier-BoldOblique) def
/bold false def
/italic false def

/fontscale 10 def                % = 72/(0.6*12cpi)
/linespace 12 def                % = 72/lpi
/charspace {(0) stringwidth pop} def


/newmargins {
        /topmargin topmargin FBtry fontscale mul sub def
        /botmargin botmargin FBbly fontscale mul sub def
        /leftmargin leftmargin FBblx fontscale mul sub def
} def


/newfont {
        dup /curfont exch def
        findfont fontscale scalefont setfont
        currentfont begin /FontBBox load end cvx exec
        1000 div /FBtry exch def
        1000 div /FBtrx exch def
        1000 div /FBbly exch def
        1000 div /FBblx exch def
} def



% print the page if it has ink on it.  leave cursor at top, left corner
/printFF {
        usedpage {
                copypage erasepage
                /usedpage false def
        } if
        leftmargin topmargin moveto
} def



% backspace cursor
/printBS {
        currentpoint exch charspace sub
        dup leftmargin lt {pop leftmargin} if
        exch moveto
} def


% move cursor down one line, and to left margin.  print page if past
% bottom margin
/printNL {
        leftmargin currentpoint linespace sub exch pop
        dup botmargin lt
        {pop pop printFF} {moveto} ifelse
} def


% position cursor to next tab stop
/printHT {
        currentpoint exch charspace 2 div add   % allow for rounding error
        leftmargin sub                          % horiz offset from leftmargin
        tabspace div truncate 1 add             % => next tab field
        tabspace mul leftmargin add exch moveto
} def


% move the cursor to the left margin
/printCR {
        leftmargin currentpoint exch pop moveto
} def


/BS <08> def
/HT <09> def
/LF <0A> def
/CR <0D> def
/FF <0C> def
/SP ( )  def

% print inputbuf
/printbuf {

        % iteratively prints the buffer by recursively breaking the
        % input into <text> <control-char> <remainder>; printing <text>;
        % and performing the action implied by <control-char>.

        % <input> <control> search => <remainder> <control> <text> true
        %                     or      <input> false

        {
                /stop true def
                BS search { printbuf pop printBS /stop false def } if
                HT search { printbuf pop printHT /stop false def } if
                LF search { printbuf pop printNL /stop false def } if
                CR search { printbuf pop printCR /stop false def } if
                FF search { printbuf pop printFF /stop false def } if
                SP search { printbuf     show    /stop false def } if
                stop { exit } if
        } loop

        % top of stack is <text> for printing -- no interpretable
        % control characters here!

        dup length 0 eq {pop} {show /usedpage true def} ifelse

} def



/printstdin {

        /usedpage false def
        /input (%stdin) (r) file def

        plainfont
        newfont
        newmargins
        printFF

        /tabspace 8 charspace mul def

        {
                % read a chunk
                input inputbuf readstring not

                % exit if EOF
                {dup length 0 eq
                        {pop exit} if
                } if

                % print the buffer
                printbuf
        } loop
        printFF

} def
printstdin
-----------------------------------------------------------------


David Newall, who no longer works       Phone:  +61 8 344 2008
for SA Institute of Technology          E-mail: xtdn at lux.sait.edu.au
                "Life is uncertain:  Eat dessert first"



More information about the Comp.unix.questions mailing list