comparison lisp/packages/ps-print.el @ 88:821dec489c24 r20-0

Import from CVS: tag r20-0
author cvs
date Mon, 13 Aug 2007 09:09:59 +0200
parents 6a378aca36af
children dbb370e3c29e
comparison
equal deleted inserted replaced
87:7df2982f5c17 88:821dec489c24
3 ;; Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc. 3 ;; Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
4 4
5 ;; Author: Jim Thompson (was <thompson@wg2.waii.com>) 5 ;; Author: Jim Thompson (was <thompson@wg2.waii.com>)
6 ;; Maintainer: Jacques Duthen <duthen@cegelec-red.fr> 6 ;; Maintainer: Jacques Duthen <duthen@cegelec-red.fr>
7 ;; Keywords: print, PostScript 7 ;; Keywords: print, PostScript
8 ;; Time-stamp: <97/01/17 16:41:00 duthen> 8 ;; Time-stamp: <97/01/29 23:21:25 tjchol01>
9 ;; Version: 3.05 9 ;; Version: 3.05
10 10
11 (defconst ps-print-version "3.05" 11 (defconst ps-print-version "3.05"
12 "ps-print.el, v 3.05 <97/01/17 duthen> 12 "ps-print.el, v 3.05 <97/01/17 duthen>
13 13
488 ;; 488 ;;
489 ;; Adding a new font family 489 ;; Adding a new font family
490 ;; ------------------------ 490 ;; ------------------------
491 ;; 491 ;;
492 ;; To use a new font family, you MUST first teach ps-print 492 ;; To use a new font family, you MUST first teach ps-print
493 ;; this font, ie add its information to `ps-font-info-database', 493 ;; this font, i.e., add its information to `ps-font-info-database',
494 ;; otherwise ps-print cannot correctly place line and page breaks. 494 ;; otherwise ps-print cannot correctly place line and page breaks.
495 ;; 495 ;;
496 ;; For example, assuming `Helvetica' is unkown, 496 ;; For example, assuming `Helvetica' is unknown,
497 ;; you first need to do the following ONLY ONCE: 497 ;; you first need to do the following ONLY ONCE:
498 ;; 498 ;;
499 ;; - create a new buffer 499 ;; - create a new buffer
500 ;; - generate the PostScript image to a file (C-u M-x ps-print-buffer) 500 ;; - generate the PostScript image to a file (C-u M-x ps-print-buffer)
501 ;; - open this file and find the line: 501 ;; - open this file and find the line:
601 ;; 601 ;;
602 ;; To avoid wrapping too many lines, you may want to adjust the 602 ;; To avoid wrapping too many lines, you may want to adjust the
603 ;; left and right margins and the font size. On UN*X systems, do: 603 ;; left and right margins and the font size. On UN*X systems, do:
604 ;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head 604 ;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
605 ;; to determine the longest lines of your file. 605 ;; to determine the longest lines of your file.
606 ;; Then, the command `ps-line-lengths' will give you the correspondance 606 ;; Then, the command `ps-line-lengths' will give you the correspondence
607 ;; between a line length (number of characters) and the maximum font 607 ;; between a line length (number of characters) and the maximum font
608 ;; size which doesn't wrap such a line with the current ps-print setup. 608 ;; size which doesn't wrap such a line with the current ps-print setup.
609 ;; 609 ;;
610 ;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display 610 ;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
611 ;; the correspondance between a number of pages and the maximum font 611 ;; the correspondence between a number of pages and the maximum font
612 ;; size which allow the number of lines of the current buffer or of 612 ;; size which allow the number of lines of the current buffer or of
613 ;; its current region to fit in this number of pages. 613 ;; its current region to fit in this number of pages.
614 ;; Note: line folding is not taken into account in this process 614 ;; Note: line folding is not taken into account in this process
615 ;; and could change the results. 615 ;; and could change the results.
616 ;; 616 ;;
1015 (make-variable-buffer-local 'ps-right-header) 1015 (make-variable-buffer-local 'ps-right-header)
1016 1016
1017 (defvar ps-razzle-dazzle t 1017 (defvar ps-razzle-dazzle t
1018 "*Non-nil means report progress while formatting buffer.") 1018 "*Non-nil means report progress while formatting buffer.")
1019 1019
1020 (defvar ps-adobe-tag "%!PS-Adobe-1.0\n" 1020 (defvar ps-adobe-tag "%!PS-Adobe-3.0\n"
1021 "*Contains the header line identifying the output as PostScript. 1021 "*Contains the header line identifying the output as PostScript.
1022 By default, `ps-adobe-tag' contains the standard identifier. Some 1022 By default, `ps-adobe-tag' contains the standard identifier. Some
1023 printers require slightly different versions of this line.") 1023 printers require slightly different versions of this line.")
1024 1024
1025 (defvar ps-build-face-reference t 1025 (defvar ps-build-face-reference t
1164 (interactive (list (ps-print-preprint current-prefix-arg))) 1164 (interactive (list (ps-print-preprint current-prefix-arg)))
1165 (ps-do-despool filename)) 1165 (ps-do-despool filename))
1166 1166
1167 ;;;###autoload 1167 ;;;###autoload
1168 (defun ps-line-lengths () 1168 (defun ps-line-lengths ()
1169 "*Display the correspondance between a line length and a font size, 1169 "*Display the correspondence between a line length and a font size,
1170 using the current ps-print setup. 1170 using the current ps-print setup.
1171 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head" 1171 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
1172 (interactive) 1172 (interactive)
1173 (ps-line-lengths-internal)) 1173 (ps-line-lengths-internal))
1174 1174
1175 ;;;###autoload 1175 ;;;###autoload
1176 (defun ps-nb-pages-buffer (nb-lines) 1176 (defun ps-nb-pages-buffer (nb-lines)
1177 "*Display an approximate correspondance between a font size and the number 1177 "*Display an approximate correspondence between a font size and the number
1178 of pages the current buffer would require to print 1178 of pages the current buffer would require to print
1179 using the current ps-print setup." 1179 using the current ps-print setup."
1180 (interactive (list (count-lines (point-min) (point-max)))) 1180 (interactive (list (count-lines (point-min) (point-max))))
1181 (ps-nb-pages nb-lines)) 1181 (ps-nb-pages nb-lines))
1182 1182
1183 ;;;###autoload 1183 ;;;###autoload
1184 (defun ps-nb-pages-region (nb-lines) 1184 (defun ps-nb-pages-region (nb-lines)
1185 "*Display an approximate correspondance between a font size and the number 1185 "*Display an approximate correspondence between a font size and the number
1186 of pages the current region would require to print 1186 of pages the current region would require to print
1187 using the current ps-print setup." 1187 using the current ps-print setup."
1188 (interactive (list (count-lines (mark) (point)))) 1188 (interactive (list (count-lines (mark) (point))))
1189 (ps-nb-pages nb-lines)) 1189 (ps-nb-pages nb-lines))
1190 1190
1823 1823
1824 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1824 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1825 ;; Internal functions 1825 ;; Internal functions
1826 1826
1827 (defun ps-line-lengths-internal () 1827 (defun ps-line-lengths-internal ()
1828 "Display the correspondance between a line length and a font size, 1828 "Display the correspondence between a line length and a font size,
1829 using the current ps-print setup. 1829 using the current ps-print setup.
1830 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head" 1830 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
1831 (let ((buf (get-buffer-create "*Line-lengths*")) 1831 (let ((buf (get-buffer-create "*Line-lengths*"))
1832 (ifs ps-font-size) ; initial font size 1832 (ifs ps-font-size) ; initial font size
1833 (icw ps-avg-char-width) ; initial character width 1833 (icw ps-avg-char-width) ; initial character width
1861 (setq nb-cpl (1+ nb-cpl))) 1861 (setq nb-cpl (1+ nb-cpl)))
1862 (insert "\n") 1862 (insert "\n")
1863 (display-buffer buf 'not-this-window))) 1863 (display-buffer buf 'not-this-window)))
1864 1864
1865 (defun ps-nb-pages (nb-lines) 1865 (defun ps-nb-pages (nb-lines)
1866 "Display an approximate correspondance between a font size and the number 1866 "Display an approximate correspondence between a font size and the number
1867 of pages the number of lines would require to print 1867 of pages the number of lines would require to print
1868 using the current ps-print setup." 1868 using the current ps-print setup."
1869 (let ((buf (get-buffer-create "*Nb-Pages*")) 1869 (let ((buf (get-buffer-create "*Nb-Pages*"))
1870 (ifs ps-font-size) ; initial font size 1870 (ifs ps-font-size) ; initial font size
1871 (ilh ps-line-height) ; initial line height 1871 (ilh ps-line-height) ; initial line height
2112 2112
2113 (defun ps-insert-file (fname) 2113 (defun ps-insert-file (fname)
2114 (ps-flush-output) 2114 (ps-flush-output)
2115 2115
2116 ;; Check to see that the file exists and is readable; if not, throw 2116 ;; Check to see that the file exists and is readable; if not, throw
2117 ;; and error. 2117 ;; an error.
2118 (if (not (file-readable-p fname)) 2118 (if (not (file-readable-p fname))
2119 (error "Could not read file `%s'" fname)) 2119 (error "Could not read file `%s'" fname))
2120 2120
2121 (save-excursion 2121 (save-excursion
2122 (set-buffer ps-spool-buffer) 2122 (set-buffer ps-spool-buffer)
2171 (ps-output "%%Title: " (buffer-name) "\n") ;Take job name from name of 2171 (ps-output "%%Title: " (buffer-name) "\n") ;Take job name from name of
2172 ;first buffer printed 2172 ;first buffer printed
2173 (ps-output "%%Creator: " (user-full-name) "\n") 2173 (ps-output "%%Creator: " (user-full-name) "\n")
2174 (ps-output "%%CreationDate: " 2174 (ps-output "%%CreationDate: "
2175 (time-stamp-hh:mm:ss) " " (time-stamp-mon-dd-yyyy) "\n") 2175 (time-stamp-hh:mm:ss) " " (time-stamp-mon-dd-yyyy) "\n")
2176 (ps-output "%% DocumentFonts: "
2177 ps-font " " ps-font-bold " " ps-font-italic " "
2178 ps-font-bold-italic " "
2179 ps-header-font " " ps-header-title-font "\n")
2180 (ps-output "%%Pages: (atend)\n") 2176 (ps-output "%%Pages: (atend)\n")
2181 (ps-output "%%EndComments\n\n") 2177 (ps-output "%%EndComments\n\n")
2182 2178
2179 (ps-output "%%BeginProlog\n")
2183 (ps-output-boolean "LandscapeMode" ps-landscape-mode) 2180 (ps-output-boolean "LandscapeMode" ps-landscape-mode)
2184 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns)) 2181 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns))
2185 2182
2186 (ps-output (format "/LandscapePageHeight %s def\n" ps-landscape-page-height)) 2183 (ps-output (format "/LandscapePageHeight %s def\n" ps-landscape-page-height))
2187 (ps-output (format "/PrintWidth %s def\n" ps-print-width)) 2184 (ps-output (format "/PrintWidth %s def\n" ps-print-width))
2202 (ps-output-boolean "Duplex" ps-spool-duplex) 2199 (ps-output-boolean "Duplex" ps-spool-duplex)
2203 2200
2204 (ps-output (format "/LineHeight %s def\n" ps-line-height)) 2201 (ps-output (format "/LineHeight %s def\n" ps-line-height))
2205 2202
2206 (ps-output ps-print-prologue-1) 2203 (ps-output ps-print-prologue-1)
2204 (ps-output "%%EndProlog\n\n")
2205
2206
2207 (ps-output "%%BeginSetup\n")
2207 2208
2208 ;; Header fonts 2209 ;; Header fonts
2209 (ps-output ; /h0 14 /Helvetica-Bold Font 2210 (ps-output ; /h0 14 /Helvetica-Bold Font
2210 (format "/h0 %s /%s DefFont\n" ps-header-title-font-size ps-header-title-font)) 2211 (format "/h0 %s /%s DefFont\n" ps-header-title-font-size ps-header-title-font))
2211 (ps-output ; /h1 12 /Helvetica Font 2212 (ps-output ; /h1 12 /Helvetica Font
2218 (ps-output (format "/f1 %s /%s DefFont\n" ps-font-size ps-font-bold)) 2219 (ps-output (format "/f1 %s /%s DefFont\n" ps-font-size ps-font-bold))
2219 (ps-output (format "/f2 %s /%s DefFont\n" ps-font-size ps-font-italic)) 2220 (ps-output (format "/f2 %s /%s DefFont\n" ps-font-size ps-font-italic))
2220 (ps-output (format "/f3 %s /%s DefFont\n" ps-font-size ps-font-bold-italic)) 2221 (ps-output (format "/f3 %s /%s DefFont\n" ps-font-size ps-font-bold-italic))
2221 2222
2222 (ps-output "\nBeginDoc\n\n") 2223 (ps-output "\nBeginDoc\n\n")
2223 (ps-output "%%EndPrologue\n")) 2224 (ps-output "%%EndSetup\n")
2225 )
2224 2226
2225 (defun ps-header-dirpart () 2227 (defun ps-header-dirpart ()
2226 (let ((fname (buffer-file-name))) 2228 (let ((fname (buffer-file-name)))
2227 (if fname 2229 (if fname
2228 (if (string-equal (buffer-name) (file-name-nondirectory fname)) 2230 (if (string-equal (buffer-name) (file-name-nondirectory fname))
2242 2244
2243 (defun ps-begin-job () 2245 (defun ps-begin-job ()
2244 (setq ps-page-count 0)) 2246 (setq ps-page-count 0))
2245 2247
2246 (defun ps-end-file () 2248 (defun ps-end-file ()
2247 (ps-output "\nEndDoc\n\n") 2249 (ps-output "\n\n%%Trailer\n")
2248 (ps-output "%%Trailer\n")
2249 (ps-output (format "%%%%Pages: %d\n" (1+ (/ (1- ps-page-count) 2250 (ps-output (format "%%%%Pages: %d\n" (1+ (/ (1- ps-page-count)
2250 ps-number-of-columns))))) 2251 ps-number-of-columns))))
2252 (ps-output "EndDoc\n")
2253 (ps-output "%%EOF\n"))
2251 2254
2252 (defun ps-next-page () 2255 (defun ps-next-page ()
2253 (ps-end-page) 2256 (ps-end-page)
2254 (ps-flush-output) 2257 (ps-flush-output)
2255 (ps-begin-page)) 2258 (ps-begin-page))
2745 ;; the end of this marker onwards. 2748 ;; the end of this marker onwards.
2746 (setq safe-marker (make-marker)) 2749 (setq safe-marker (make-marker))
2747 (set-marker safe-marker (point-max)) 2750 (set-marker safe-marker (point-max))
2748 2751
2749 (goto-char (point-min)) 2752 (goto-char (point-min))
2750 (if (looking-at (regexp-quote "%!PS-Adobe-1.0")) 2753 (if (looking-at (regexp-quote ps-adobe-tag))
2751 nil 2754 nil
2752 (setq needs-begin-file t)) 2755 (setq needs-begin-file t))
2753 (save-excursion 2756 (save-excursion
2754 (set-buffer ps-source-buffer) 2757 (set-buffer ps-source-buffer)
2755 (if needs-begin-file (ps-begin-file)) 2758 (if needs-begin-file (ps-begin-file))