From xemacs-m  Wed Jan 29 22:37:41 1997
Received: from mecca.spd.louisville.edu (mecca.spd.louisville.edu [136.165.40.148])
          by xemacs.org (8.8.4/8.8.4) with SMTP
	  id WAA09513 for <xemacs-beta@xemacs.org>; Wed, 29 Jan 1997 22:37:39 -0600 (CST)
Received: (from tjchol01@localhost) by mecca.spd.louisville.edu (950413.SGI.8.6.12/950213.SGI.AUTOCF) id XAA23040; Wed, 29 Jan 1997 23:37:37 -0500
Date: Wed, 29 Jan 1997 23:37:37 -0500
Message-Id: <199701300437.XAA23040@mecca.spd.louisville.edu>
From: "Tomasz J. Cholewo" <tjchol01@mecca.spd.louisville.edu>
To: duthen@cegelec-red.fr
CC: xemacs-beta@xemacs.org
Subject: [patch] ps-print.el PostScript DSC conformance
Mime-Version: 1.0 (generated by tm-edit 7.100)
Content-Type: text/plain; charset=US-ASCII

Hi,

Postscript files generated by ps-print.el 3.05 (xemacs-20.0-b92) do not
conform to Adobe DSC specification.  `EndDoc' function is placed before
a `%%Trailer' comment which sometimes leads to premature restoration of
saved interpreter state.  This makes creating 4-up booklets using
PostScript utilities like pstops in most cases impossible.
Additionally, the end of a prolog should by marked by an `%%EndProlog'
comment (not `%%EndPrologue').  Also, the "%%PS-Adobe-1.0" string was
hardcoded in the function `ps-generate'.

The following patch corrects these problems and some minor typos and
additionally attempts to make ps-print output more DSC 3.0 like.

Tom
======================== CUT HERE ==============
diff -dbur xemacs-20.0-b92/lisp/packages/ps-print.el xemacs-20.0-b93/lisp/packages/ps-print.el
--- xemacs-20.0-b92/lisp/packages/ps-print.el	Thu Jan 23 00:29:35 1997
+++ xemacs-20.0-b93/lisp/packages/ps-print.el	Wed Jan 29 23:21:25 1997
@@ -5,7 +5,7 @@
 ;; Author:     Jim Thompson (was <thompson@wg2.waii.com>)
 ;; Maintainer: Jacques Duthen <duthen@cegelec-red.fr>
 ;; Keywords:   print, PostScript
-;; Time-stamp: <97/01/17 16:41:00 duthen>
+;; Time-stamp: <97/01/29 23:21:25 tjchol01>
 ;; Version:    3.05

 (defconst ps-print-version "3.05"
@@ -490,10 +490,10 @@
 ;; ------------------------
 ;;
 ;; To use a new font family, you MUST first teach ps-print
-;; this font, ie add its information to `ps-font-info-database',
+;; this font, i.e., add its information to `ps-font-info-database',
 ;; otherwise ps-print cannot correctly place line and page breaks.
 ;;
-;; For example, assuming `Helvetica' is unkown,
+;; For example, assuming `Helvetica' is unknown,
 ;; you first need to do the following ONLY ONCE:
 ;;
 ;; - create a new buffer
@@ -603,12 +603,12 @@
 ;; left and right margins and the font size.  On UN*X systems, do:
 ;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
 ;; to determine the longest lines of your file.
-;; Then, the command `ps-line-lengths' will give you the correspondance
+;; Then, the command `ps-line-lengths' will give you the correspondence
 ;; between a line length (number of characters) and the maximum font
 ;; size which doesn't wrap such a line with the current ps-print setup.
 ;;
 ;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
-;; the correspondance between a number of pages and the maximum font
+;; the correspondence between a number of pages and the maximum font
 ;; size which allow the number of lines of the current buffer or of
 ;; its current region to fit in this number of pages.
 ;; Note: line folding is not taken into account in this process
@@ -1017,7 +1017,7 @@
 (defvar ps-razzle-dazzle t
   "*Non-nil means report progress while formatting buffer.")

-(defvar ps-adobe-tag "%!PS-Adobe-1.0\n"
+(defvar ps-adobe-tag "%!PS-Adobe-3.0\n"
   "*Contains the header line identifying the output as PostScript.
 By default, `ps-adobe-tag' contains the standard identifier.  Some
 printers require slightly different versions of this line.")
@@ -1166,7 +1166,7 @@

 ;;;###autoload
 (defun ps-line-lengths ()
-  "*Display the correspondance between a line length and a font size,
+  "*Display the correspondence between a line length and a font size,
 using the current ps-print setup.
 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
   (interactive)
@@ -1174,7 +1174,7 @@

 ;;;###autoload
 (defun ps-nb-pages-buffer (nb-lines)
-  "*Display an approximate correspondance between a font size and the number
+  "*Display an approximate correspondence between a font size and the number
 of pages the current buffer would require to print
 using the current ps-print setup."
   (interactive (list (count-lines (point-min) (point-max))))
@@ -1182,7 +1182,7 @@

 ;;;###autoload
 (defun ps-nb-pages-region (nb-lines)
-  "*Display an approximate correspondance between a font size and the number
+  "*Display an approximate correspondence between a font size and the number
 of pages the current region would require to print
 using the current ps-print setup."
   (interactive (list (count-lines (mark) (point))))
@@ -1825,7 +1825,7 @@
 ;; Internal functions

 (defun ps-line-lengths-internal ()
-  "Display the correspondance between a line length and a font size,
+  "Display the correspondence between a line length and a font size,
 using the current ps-print setup.
 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
   (let ((buf (get-buffer-create "*Line-lengths*"))
@@ -1863,7 +1863,7 @@
     (display-buffer buf 'not-this-window)))

 (defun ps-nb-pages (nb-lines)
-  "Display an approximate correspondance between a font size and the number
+  "Display an approximate correspondence between a font size and the number
 of pages the number of lines would require to print
 using the current ps-print setup."
   (let ((buf (get-buffer-create "*Nb-Pages*"))
@@ -2114,7 +2114,7 @@
   (ps-flush-output)

   ;; Check to see that the file exists and is readable; if not, throw
-  ;; and error.
+  ;; an error.
   (if (not (file-readable-p fname))
       (error "Could not read file `%s'" fname))

@@ -2173,13 +2173,10 @@
   (ps-output "%%Creator: " (user-full-name) "\n")
   (ps-output "%%CreationDate: "
 	     (time-stamp-hh:mm:ss) " " (time-stamp-mon-dd-yyyy) "\n")
-  (ps-output "%% DocumentFonts: "
-	     ps-font " " ps-font-bold " " ps-font-italic " "
-	     ps-font-bold-italic " "
-	     ps-header-font " " ps-header-title-font "\n")
   (ps-output "%%Pages: (atend)\n")
   (ps-output "%%EndComments\n\n")

+  (ps-output "%%BeginProlog\n")
   (ps-output-boolean "LandscapeMode"             ps-landscape-mode)
   (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns))

@@ -2204,6 +2201,10 @@
   (ps-output (format "/LineHeight   %s def\n" ps-line-height))

   (ps-output ps-print-prologue-1)
+  (ps-output "%%EndProlog\n\n")
+
+
+  (ps-output "%%BeginSetup\n")

   ;; Header fonts
   (ps-output				; /h0 14 /Helvetica-Bold Font
@@ -2220,7 +2221,8 @@
   (ps-output (format "/f3 %s /%s DefFont\n" ps-font-size ps-font-bold-italic))

   (ps-output "\nBeginDoc\n\n")
-  (ps-output "%%EndPrologue\n"))
+  (ps-output "%%EndSetup\n")
+)

 (defun ps-header-dirpart ()
   (let ((fname (buffer-file-name)))
@@ -2244,10 +2246,11 @@
   (setq ps-page-count 0))

 (defun ps-end-file ()
-  (ps-output "\nEndDoc\n\n")
-  (ps-output "%%Trailer\n")
+  (ps-output "\n\n%%Trailer\n")
   (ps-output (format "%%%%Pages: %d\n" (1+ (/ (1- ps-page-count)
-					      ps-number-of-columns)))))
+					      ps-number-of-columns))))
+  (ps-output "EndDoc\n")
+  (ps-output "%%EOF\n"))

 (defun ps-next-page ()
   (ps-end-page)
@@ -2747,7 +2750,7 @@
 	      (set-marker safe-marker (point-max))

 	      (goto-char (point-min))
-	      (if (looking-at (regexp-quote "%!PS-Adobe-1.0"))
+	      (if (looking-at (regexp-quote ps-adobe-tag))
 		  nil
 		(setq needs-begin-file t))
 	      (save-excursion

