[alt.sources] Paginating in Display Postscript - Solved

clewis@ferret.ocunix.on.ca (Chris Lewis) (03/23/91)

Archive-name: dodps

I thought I'd let everybody know the solution I came up for
paginating Display Postscript.  A similar approach can be
used for GhostScript apparently.

There apparently isn't yet a formal Postscript previewer available
directly from Adobe (there is one in NeXT though).

With Display Postscript, there is a program called "dpsexec" which
is a mechanism for invoking it.  Dpsexec is a simple program that
provides a simple interface to the Postscript engine.  Much like
connecting a terminal directly to a Postscript printer's serial port.
It seems as if dpsexec is supplied as source under the examples
directory.

dpsexec doesn't have a mechanism for pausing the display at the end
of each page so that you can look at it.  Hence lay the problem.

This note is a description of what I did, and is cross-posted to
alt.sources so that the alt.sources archivers will pick it up.
This is such a trivial little ditty, I didn't think it worth while
to post to one of the moderated source groups.  I'd like to
thank Paul Asente of Adobe for pointing out this (obvious) solution,
as well as giving me a bit of an assist, for I don't have a Postscript
Reference handy.  This facility will be in psroff 3.0.

This was done for a very specific application (my psroff to be
precise), so your mileage for your purposes may vary (slightly)

    1) insert into the psroff prolog, some helper stuff:

	%	Are we display postscript?
	/DPS? systemdict /viewclip known def

	/waitprompt {
	    /Times-Bold findfont 20 scalefont setfont
	    0 0 moveto show		% prompt
	    (%stdin) (r) file		% open stdin for reading
	    20 string readline		% read a line into the string
					% stack contains filled substring and
					% boolean indicating whether reached EOF
	    pop pop			% we don't need it anyways...
	} def

       "viewclip" is a Postscript level II feature that is apparently
       not going to be present on printers, and so its existence will tell
       you that you're running under DPS.  I wanted to make things so that
       it wasn't necessary to change the Postscript for printers versus DPS.

    2) redefine your showpage to invoke waitprompt before the real
       showpage.  In Psroff, this is easy because I already had
       wrapped the "real" showpage in another function that counts pages:
       This is my ShowPage function:

	%	print current page.
	/ShowPage {
	    DPS? {			% wait for input on page break.
		(Select other window and hit enter to continue...) waitprompt
	    } if

	    showpage
	    /pagecount pagecount 1 add def
	} def

       As a more general solution,  you'll probably want to redefine
       showpage to have the DPS? clause invoked before the real showpage.

       In DPS, this code will call waitprompt and display the message
       at the lower left corner.  Since Psroff conforms to the DSC,
       the fonts are resynched at the top of each page, so the the
       "setfont" in waitprompt is promptly changed back to what it
       should be at the top of the next page.  If your code isn't
       DSC compliant, you may have to save/restore in waitprompt.

    3) Insert into the trailer, the following code:

	DPS? {
	    (^D to exit\n) print
	} if

	Which prints on the interpreter window instructions on how to
	exit DPS.

    4) I wrote the following shell script, which I called "dodps"
       to invoke dpsexec:

	#! /bin/sh
	# 2.1 91/03/15
	trap "rm -f /tmp/cmd$$ \$delete; exit 0" 0 1 2 15
	if [ "$1" = "-d" ]
	then
	    delete=$2
	    shift
	fi
	if [ $# != 1 ]
	then
	    echo "$0: Missing file argument" >&2
	    exit 1
	fi
	case $1 in
	    /*) file=$1
		;;
	    *) file=`pwd`/$1
		;;
	esac
	echo "($file) run" > /tmp/cmd$$
	cat -u /tmp/cmd$$ /dev/tty | /usr/local/bin/dpsexec
	rm -f /tmp/cmd$$

       You invoke this script by "dodps <postscript file name>".
       The script forms a "(filename) run", and jams that into
       the stdin of dpsexec, followed by /dev/tty, so your keystrokes
       will get into the interpreter itself.  If you supply the
       argument "-d", the file is deleted after the script terminates.
       The program is crude, but does work.  I'll probably refine it
       further for psroff.

This "kludge" behaves in the following way:

    - at the end of each page display, the "switch to other window and
      hit enter" prompt appears in the postscript output window.
      When you click on the interpreter window, it comes into the foreground.
      The "enter" causes the current image to erase and the next image
      to start to be written.  At this point you may have to click on the
      Postscript output window fast so that you don't lose output.
      (if you resize the image or move the window, you lose the output)
    - At the end of the job, the same prompt will come up, but once you
      hit enter, the "enter ^D to exit" message comes out on the interpreter
      window, you hit "^D", and the interpreter quits.

Further notes on dpsexec: as shipped, dpsexec creates a default image
window that would normally have to be resized (larger).  A real pain.
Since the source for dpsexec comes with DPS, you can fix it.

I changed the following two lines:

    #define W_HEIGHT	512
    #define W_WIDTH	512

to:
  
    #define W_HEIGHT	(11*72)
    #define W_WIDTH	(9*72)

And then recompiled.  Thus, when dpsexec starts up, it's initial window
will be big enough for 8.5x11 output.

A real kludge.  But it works well enough for my purposes.

[Oh, and yes, this was done on an RS/6000.  Your mileage may vary.
The RS/6000 DPS interpreter is amazingly fast...]
-- 
Chris Lewis,
clewis@ferret.ocunix.on.ca or ...uunet!mitel!cunews!latour!ecicrl!clewis
Psroff support: psroff-request@eci386.uucp, or call 613-832-0541 (Canada)
**** somebody's mailer is appending .bitnet to my From: address.  If you
see this, please use the address in the signature, and send me a copy
of the headers of the mail message with the .bitnet return address.  Thanks!