home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3122 < prev    next >
Encoding:
Internet Message Format  |  1991-03-23  |  6.1 KB

  1. From: clewis@ferret.ocunix.on.ca (Chris Lewis)
  2. Newsgroups: comp.lang.postscript,alt.sources
  3. Subject: Paginating in Display Postscript - Solved
  4. Message-ID: <1991Mar23.050750.14133@ferret.ocunix.on.ca>
  5. Date: 23 Mar 91 05:07:50 GMT
  6.  
  7. Archive-name: dodps
  8.  
  9. I thought I'd let everybody know the solution I came up for
  10. paginating Display Postscript.  A similar approach can be
  11. used for GhostScript apparently.
  12.  
  13. There apparently isn't yet a formal Postscript previewer available
  14. directly from Adobe (there is one in NeXT though).
  15.  
  16. With Display Postscript, there is a program called "dpsexec" which
  17. is a mechanism for invoking it.  Dpsexec is a simple program that
  18. provides a simple interface to the Postscript engine.  Much like
  19. connecting a terminal directly to a Postscript printer's serial port.
  20. It seems as if dpsexec is supplied as source under the examples
  21. directory.
  22.  
  23. dpsexec doesn't have a mechanism for pausing the display at the end
  24. of each page so that you can look at it.  Hence lay the problem.
  25.  
  26. This note is a description of what I did, and is cross-posted to
  27. alt.sources so that the alt.sources archivers will pick it up.
  28. This is such a trivial little ditty, I didn't think it worth while
  29. to post to one of the moderated source groups.  I'd like to
  30. thank Paul Asente of Adobe for pointing out this (obvious) solution,
  31. as well as giving me a bit of an assist, for I don't have a Postscript
  32. Reference handy.  This facility will be in psroff 3.0.
  33.  
  34. This was done for a very specific application (my psroff to be
  35. precise), so your mileage for your purposes may vary (slightly)
  36.  
  37.     1) insert into the psroff prolog, some helper stuff:
  38.  
  39.     %    Are we display postscript?
  40.     /DPS? systemdict /viewclip known def
  41.  
  42.     /waitprompt {
  43.         /Times-Bold findfont 20 scalefont setfont
  44.         0 0 moveto show        % prompt
  45.         (%stdin) (r) file        % open stdin for reading
  46.         20 string readline        % read a line into the string
  47.                     % stack contains filled substring and
  48.                     % boolean indicating whether reached EOF
  49.         pop pop            % we don't need it anyways...
  50.     } def
  51.  
  52.        "viewclip" is a Postscript level II feature that is apparently
  53.        not going to be present on printers, and so its existence will tell
  54.        you that you're running under DPS.  I wanted to make things so that
  55.        it wasn't necessary to change the Postscript for printers versus DPS.
  56.  
  57.     2) redefine your showpage to invoke waitprompt before the real
  58.        showpage.  In Psroff, this is easy because I already had
  59.        wrapped the "real" showpage in another function that counts pages:
  60.        This is my ShowPage function:
  61.  
  62.     %    print current page.
  63.     /ShowPage {
  64.         DPS? {            % wait for input on page break.
  65.         (Select other window and hit enter to continue...) waitprompt
  66.         } if
  67.  
  68.         showpage
  69.         /pagecount pagecount 1 add def
  70.     } def
  71.  
  72.        As a more general solution,  you'll probably want to redefine
  73.        showpage to have the DPS? clause invoked before the real showpage.
  74.  
  75.        In DPS, this code will call waitprompt and display the message
  76.        at the lower left corner.  Since Psroff conforms to the DSC,
  77.        the fonts are resynched at the top of each page, so the the
  78.        "setfont" in waitprompt is promptly changed back to what it
  79.        should be at the top of the next page.  If your code isn't
  80.        DSC compliant, you may have to save/restore in waitprompt.
  81.  
  82.     3) Insert into the trailer, the following code:
  83.  
  84.     DPS? {
  85.         (^D to exit\n) print
  86.     } if
  87.  
  88.     Which prints on the interpreter window instructions on how to
  89.     exit DPS.
  90.  
  91.     4) I wrote the following shell script, which I called "dodps"
  92.        to invoke dpsexec:
  93.  
  94.     #! /bin/sh
  95.     # 2.1 91/03/15
  96.     trap "rm -f /tmp/cmd$$ \$delete; exit 0" 0 1 2 15
  97.     if [ "$1" = "-d" ]
  98.     then
  99.         delete=$2
  100.         shift
  101.     fi
  102.     if [ $# != 1 ]
  103.     then
  104.         echo "$0: Missing file argument" >&2
  105.         exit 1
  106.     fi
  107.     case $1 in
  108.         /*) file=$1
  109.         ;;
  110.         *) file=`pwd`/$1
  111.         ;;
  112.     esac
  113.     echo "($file) run" > /tmp/cmd$$
  114.     cat -u /tmp/cmd$$ /dev/tty | /usr/local/bin/dpsexec
  115.     rm -f /tmp/cmd$$
  116.  
  117.        You invoke this script by "dodps <postscript file name>".
  118.        The script forms a "(filename) run", and jams that into
  119.        the stdin of dpsexec, followed by /dev/tty, so your keystrokes
  120.        will get into the interpreter itself.  If you supply the
  121.        argument "-d", the file is deleted after the script terminates.
  122.        The program is crude, but does work.  I'll probably refine it
  123.        further for psroff.
  124.  
  125. This "kludge" behaves in the following way:
  126.  
  127.     - at the end of each page display, the "switch to other window and
  128.       hit enter" prompt appears in the postscript output window.
  129.       When you click on the interpreter window, it comes into the foreground.
  130.       The "enter" causes the current image to erase and the next image
  131.       to start to be written.  At this point you may have to click on the
  132.       Postscript output window fast so that you don't lose output.
  133.       (if you resize the image or move the window, you lose the output)
  134.     - At the end of the job, the same prompt will come up, but once you
  135.       hit enter, the "enter ^D to exit" message comes out on the interpreter
  136.       window, you hit "^D", and the interpreter quits.
  137.  
  138. Further notes on dpsexec: as shipped, dpsexec creates a default image
  139. window that would normally have to be resized (larger).  A real pain.
  140. Since the source for dpsexec comes with DPS, you can fix it.
  141.  
  142. I changed the following two lines:
  143.  
  144.     #define W_HEIGHT    512
  145.     #define W_WIDTH    512
  146.  
  147. to:
  148.   
  149.     #define W_HEIGHT    (11*72)
  150.     #define W_WIDTH    (9*72)
  151.  
  152. And then recompiled.  Thus, when dpsexec starts up, it's initial window
  153. will be big enough for 8.5x11 output.
  154.  
  155. A real kludge.  But it works well enough for my purposes.
  156.  
  157. [Oh, and yes, this was done on an RS/6000.  Your mileage may vary.
  158. The RS/6000 DPS interpreter is amazingly fast...]
  159. -- 
  160. Chris Lewis,
  161. clewis@ferret.ocunix.on.ca or ...uunet!mitel!cunews!latour!ecicrl!clewis
  162. Psroff support: psroff-request@eci386.uucp, or call 613-832-0541 (Canada)
  163. **** somebody's mailer is appending .bitnet to my From: address.  If you
  164. see this, please use the address in the signature, and send me a copy
  165. of the headers of the mail message with the .bitnet return address.  Thanks!
  166.