Mercurial > emacs
comparison lisp/ps-print.el @ 16870:4a5fa29f79d6
(ps-print-version): Fix value.
(cl lisp-float-type): Require them.
(ps-number-of-columns ps-*-font-size): Try to select defaults
better suited when `ps-landscape-mode' is non-nil.
(ps-*-faces): Change default for Font Lock mode faces when
`ps-print-color-p' is nil.
(ps-right-header): Replace `time-stamp-yy/mm/dd'
by `time-stamp-mon-dd-yyyy'.
(ps-end-file ps-begin-page): Fix bug in page count for Ghostview.
(ps-generate-postscript-with-faces): Replace `ps-sorter' by
`car-less-than-car'.
(ps-plot ps-generate): Replace `%d' by `%3d'.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 16 Jan 1997 05:09:21 +0000 |
parents | 032601b9959b |
children | 18731f7e2c73 |
comparison
equal
deleted
inserted
replaced
16869:16ef2bd09de7 | 16870:4a5fa29f79d6 |
---|---|
1 ;;; ps-print.el --- Jim's Pretty-Good PostScript Generator for Emacs 19. | 1 ;;; ps-print.el --- Jim's Pretty-Good PostScript Generator for Emacs 19. |
2 | 2 |
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 <thompson@wg2.waii.com> | 5 ;; Author: Jim Thompson (was <thompson@wg2.waii.com>) |
6 ;; Maintainer: duthen@cegelec-red.fr (Jacques Duthen Prestataire) | 6 ;; Maintainer: Jacques Duthen <duthen@cegelec-red.fr> |
7 ;; Keywords: print, PostScript | 7 ;; Keywords: print, PostScript |
8 ;; Time-stamp: <97/01/09 13:52:08 duthen> | |
9 ;; Version: 3.04 | |
10 | |
11 (defconst ps-print-version "3.04" | |
12 "ps-print.el, v 3.04 <97/01/09 duthen> | |
13 | |
14 Jack's last change version -- this file may have been edited as part of | |
15 Emacs without changes to the version number. When reporting bugs, | |
16 please also report the version of Emacs, if any, that ps-print was | |
17 distributed with. | |
18 | |
19 Please send all bug fixes and enhancements to | |
20 Jacques Duthen <duthen@cegelec-red.fr>. | |
21 ") | |
8 | 22 |
9 ;; This file is part of GNU Emacs. | 23 ;; This file is part of GNU Emacs. |
10 | 24 |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | 25 ;; GNU Emacs is free software; you can redistribute it and/or modify |
12 ;; it under the terms of the GNU General Public License as published by | 26 ;; it under the terms of the GNU General Public License as published by |
20 | 34 |
21 ;; You should have received a copy of the GNU General Public License | 35 ;; You should have received a copy of the GNU General Public License |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 36 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 37 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
24 ;; Boston, MA 02111-1307, USA. | 38 ;; Boston, MA 02111-1307, USA. |
25 | |
26 ;; LCD Archive Entry: | |
27 ;; ps-print|James C. Thompson|thompson@wg2.waii.com| | |
28 ;; Jim's Pretty-Good PostScript Generator for Emacs 19 (ps-print)| | |
29 ;; 26-Feb-1994|2.8|~/packages/ps-print.el| | |
30 | |
31 ;; 3.03 [jack] Sept 27, 1996 Jacques Duthen <duthen@cegelec-red.fr> | |
32 ;; Merge 31 diffs between 19.29 and 19.34 | |
33 | |
34 ;; 3.02 [jack] June 26, 1996 Jacques Duthen <duthen@cegelec-red.fr> | |
35 ;; Add new page dimensions to `ps-page-dimensions-database' for `paper-type' | |
36 ;; Improve landscape mode `ps-landscape-mode' and multiple columns | |
37 ;; printing `ps-number-of-columns': | |
38 ;; The text and the margins are no more scaled. | |
39 ;; Simplify the semantics of `ps-inter-column' (space between columns). | |
40 ;; Add error checking for negative `ps-print-width' and `ps-print-height'. | |
41 ;; Change the semantics of `ps-top-margin' which is now the TOP MARGIN, | |
42 ;; and add `ps-header-offset' instead of having `ps-top-margin' split in 2. | |
43 ;; Add `ps-header-font-family', `ps-header-font-size' and | |
44 ;; `ps-header-title-font-size' to control the header. | |
45 ;; Add `ps-header-line-pad'. | |
46 ;; Change the semantics of `ps-font-info-database' to have symbolic | |
47 ;; font families. | |
48 ;; Add new fonts to `ps-font-info-database': `Courier' `Helvetica' | |
49 ;; `Times' `Palatino' `Helvetica-Narrow' `NewCenturySchlbk' | |
50 ;; Make public `ps-font-family' and `ps-font-size' so that the user | |
51 ;; can directly control the text font and size without loading ps-print. | |
52 ;; Add error checking for unknown font families and a message giving | |
53 ;; the exhaustive list of available font families. | |
54 ;; Document how to install a new font family. | |
55 ;; Add `/ReportAllFontInfo' to get all the font families of the printer. | |
56 ;; Add the possibility to make `mixed' font families. | |
57 ;; Add `ps-setup' to get the current setup. | |
58 ;; Add tools `ps-line-lengths' `ps-nb-pages-buffer' `ps-nb-pages-region' | |
59 ;; to help choose the font size. | |
60 ;; Split `ps-print-prologue' in two to insert info from header fonts | |
61 ;; Replace indexes by macro `ps-page-dimensions-get-width' | |
62 ;; to get access to the dimensions list. | |
63 ;; Add `ps-select-font' inside `ps-get-page-dimensions'. | |
64 ;; Fix the "clumsy" `ps-page-height' management. | |
65 ;; Move `ps-get-page-dimensions' to the beginning of `ps-begin-file' | |
66 ;; to get early error checking. | |
67 ;; Add sample setup `ps-jack-setup'. | |
68 ;; | |
69 ;; Rewrite a lot of postscript code and add comments inside it | |
70 ;; (maybe they should not (or optionally) be included in the generated | |
71 ;; Postscript). | |
72 ;; Translate the origin to (lm, bm) to simplify the other moves. | |
73 ;; Fix bug in `/HeaderOffset' with `/PrintStartY'. | |
74 ;; Fix bug in `/SetHeaderLines'. | |
75 ;; Change `/ReportFontInfo' for use by `/ReportAllFontInfo'. | |
76 ;; | |
77 | |
78 ;; 3.01 [jack] June 4, 1996 Jacques Duthen <duthen@cegelec-red.fr> | |
79 ;; Manage float value for every variable representing a size. | |
80 ;; Add `ps-font-info-database' `ps-inter-column' | |
81 | |
82 ;; 3.00 [jack] May 17, 1996 Jacques Duthen <duthen@cegelec-red.fr> | |
83 ;; based on 2.8 Jim's Pretty-Good version: | |
84 ;; Add `ps-landscape-mode' and `ps-number-of-columns' | |
85 ;; for dumb multi-column landscape mode. | |
86 | |
87 ;; Baseline-version: 2.8. (Jim's last change version -- this | |
88 ;; file may have been edited as part of Emacs without changes to the | |
89 ;; version number. When reporting bugs, please also report the | |
90 ;; version of Emacs, if any, that ps-print was distributed with.) | |
91 | 39 |
92 ;;; Commentary: | 40 ;;; Commentary: |
93 | 41 |
94 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
95 ;; | 43 ;; |
657 ;; Jim | 605 ;; Jim |
658 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 606 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
659 | 607 |
660 ;;; Code: | 608 ;;; Code: |
661 | 609 |
662 (defconst ps-print-version "3.01" | 610 (eval-when-compile |
663 "ps-print.el,v 3.01 1996/06/13 18:12 jack | 611 (require 'cl)) |
664 | 612 |
665 Jack's last change version -- this file may have been edited as part of | 613 (unless (featurep 'lisp-float-type) |
666 Emacs without changes to the version number. When reporting bugs, | 614 (error "`ps-print' requires floating point support")) |
667 please also report the version of Emacs, if any, that ps-print was | |
668 distributed with. | |
669 | |
670 Please send all bug fixes and enhancements to | |
671 Jacques Duthen <duthen@cegelec-red.fr>. | |
672 ") | |
673 | 615 |
674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 616 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
675 ;; User Variables: | 617 ;; User Variables: |
676 | 618 |
677 ;;; Interface to the command system | 619 ;;; Interface to the command system |
718 "*List associating a symbolic paper type to its width and height. | 660 "*List associating a symbolic paper type to its width and height. |
719 see `ps-paper-type'.") | 661 see `ps-paper-type'.") |
720 | 662 |
721 (defvar ps-paper-type 'letter | 663 (defvar ps-paper-type 'letter |
722 "*Specifies the size of paper to format for. | 664 "*Specifies the size of paper to format for. |
723 Should be one of the paper types defined in `ps-page-dimensions-database': | 665 Should be one of the paper types defined in `ps-page-dimensions-database', for |
724 `letter', `legal', `a4'...") | 666 example `letter', `legal' or `a4'.") |
725 | 667 |
726 (defvar ps-landscape-mode 'nil | 668 (defvar ps-landscape-mode 'nil |
727 "*Non-nil means print in landscape mode.") | 669 "*Non-nil means print in landscape mode.") |
728 | 670 |
729 (defvar ps-number-of-columns 1 | 671 (defvar ps-number-of-columns (if ps-landscape-mode 2 1) |
730 "*Specifies the number of columns") | 672 "*Specifies the number of columns") |
731 | 673 |
732 ;;; Horizontal layout | 674 ;;; Horizontal layout |
733 | 675 |
734 ;; ------------------------------------------ | 676 ;; ------------------------------------------ |
869 You can get all the fonts of YOUR printer using `ReportAllFontInfo'.") | 811 You can get all the fonts of YOUR printer using `ReportAllFontInfo'.") |
870 | 812 |
871 (defvar ps-font-family 'Courier | 813 (defvar ps-font-family 'Courier |
872 "Font family name for ordinary text, when generating Postscript.") | 814 "Font family name for ordinary text, when generating Postscript.") |
873 | 815 |
874 (defvar ps-font-size 8.5 | 816 (defvar ps-font-size (if ps-landscape-mode 7 8.5) |
875 "Font size, in points, for ordinary text, when generating Postscript.") | 817 "Font size, in points, for ordinary text, when generating Postscript.") |
876 | 818 |
877 (defvar ps-header-font-family 'Helvetica | 819 (defvar ps-header-font-family 'Helvetica |
878 "Font family name for text in the header, when generating Postscript.") | 820 "Font family name for text in the header, when generating Postscript.") |
879 | 821 |
880 (defvar ps-header-font-size 12 | 822 (defvar ps-header-font-size (if ps-landscape-mode 10 12) |
881 "Font size, in points, for text in the header, when generating Postscript.") | 823 "Font size, in points, for text in the header, when generating Postscript.") |
882 | 824 |
883 (defvar ps-header-title-font-size 14 | 825 (defvar ps-header-title-font-size (if ps-landscape-mode 12 14) |
884 "Font size, in points, for the top line of text in the header, | 826 "Font size, in points, for the top line of text in the header, |
885 when generating Postscript.") | 827 when generating Postscript.") |
886 | 828 |
887 ;;; Colors | 829 ;;; Colors |
888 | 830 |
900 (defvar ps-auto-font-detect t | 842 (defvar ps-auto-font-detect t |
901 "*Non-nil means automatically detect bold/italic face attributes. | 843 "*Non-nil means automatically detect bold/italic face attributes. |
902 nil means rely solely on the lists `ps-bold-faces', `ps-italic-faces', | 844 nil means rely solely on the lists `ps-bold-faces', `ps-italic-faces', |
903 and `ps-underlined-faces'.") | 845 and `ps-underlined-faces'.") |
904 | 846 |
905 (defvar ps-bold-faces '() | 847 (defvar ps-bold-faces |
848 (unless ps-print-color-p | |
849 '(font-lock-function-name-face | |
850 font-lock-builtin-face | |
851 font-lock-variable-name-face | |
852 font-lock-keyword-face | |
853 font-lock-warning-face)) | |
906 "*A list of the \(non-bold\) faces that should be printed in bold font. | 854 "*A list of the \(non-bold\) faces that should be printed in bold font. |
907 This applies to generating Postscript.") | 855 This applies to generating Postscript.") |
908 | 856 |
909 (defvar ps-italic-faces '() | 857 (defvar ps-italic-faces |
858 (unless ps-print-color-p | |
859 '(font-lock-variable-name-face | |
860 font-lock-string-face | |
861 font-lock-comment-face | |
862 font-lock-warning-face)) | |
910 "*A list of the \(non-italic\) faces that should be printed in italic font. | 863 "*A list of the \(non-italic\) faces that should be printed in italic font. |
911 This applies to generating Postscript.") | 864 This applies to generating Postscript.") |
912 | 865 |
913 (defvar ps-underlined-faces '() | 866 (defvar ps-underlined-faces |
867 (unless ps-print-color-p | |
868 '(font-lock-function-name-face | |
869 font-lock-type-face | |
870 font-lock-reference-face | |
871 font-lock-warning-face)) | |
914 "*A list of the \(non-underlined\) faces that should be printed underlined. | 872 "*A list of the \(non-underlined\) faces that should be printed underlined. |
915 This applies to generating Postscript.") | 873 This applies to generating Postscript.") |
916 | 874 |
917 (defvar ps-left-header | 875 (defvar ps-left-header |
918 (list 'ps-get-buffer-name 'ps-header-dirpart) | 876 (list 'ps-get-buffer-name 'ps-header-dirpart) |
932 In either case, function or variable, the string value has PostScript | 890 In either case, function or variable, the string value has PostScript |
933 string delimiters added to it.") | 891 string delimiters added to it.") |
934 (make-variable-buffer-local 'ps-left-header) | 892 (make-variable-buffer-local 'ps-left-header) |
935 | 893 |
936 (defvar ps-right-header | 894 (defvar ps-right-header |
937 (list "/pagenumberstring load" 'time-stamp-yy/mm/dd 'time-stamp-hh:mm:ss) | 895 (list "/pagenumberstring load" 'time-stamp-mon-dd-yyyy 'time-stamp-hh:mm:ss) |
938 "*The items to display (each on a line) on the right part of the page header. | 896 "*The items to display (each on a line) on the right part of the page header. |
939 This applies to generating Postscript. | 897 This applies to generating Postscript. |
940 | 898 |
941 See the variable `ps-left-header' for a description of the format of | 899 See the variable `ps-left-header' for a description of the format of |
942 this variable.") | 900 this variable.") |
2163 (setq ps-page-count 0)) | 2121 (setq ps-page-count 0)) |
2164 | 2122 |
2165 (defun ps-end-file () | 2123 (defun ps-end-file () |
2166 (ps-output "\nEndDoc\n\n") | 2124 (ps-output "\nEndDoc\n\n") |
2167 (ps-output "%%Trailer\n") | 2125 (ps-output "%%Trailer\n") |
2168 (ps-output "%%Pages: " (format "%d\n" ps-showpage-count))) | 2126 (ps-output (format "%%%%Pages: %d\n" (1+ (/ (1- ps-page-count) |
2127 ps-number-of-columns))))) | |
2169 | 2128 |
2170 (defun ps-next-page () | 2129 (defun ps-next-page () |
2171 (ps-end-page) | 2130 (ps-end-page) |
2172 (ps-flush-output) | 2131 (ps-flush-output) |
2173 (ps-begin-page)) | 2132 (ps-begin-page)) |
2175 (defun ps-begin-page (&optional dummypage) | 2134 (defun ps-begin-page (&optional dummypage) |
2176 (ps-get-page-dimensions) | 2135 (ps-get-page-dimensions) |
2177 (setq ps-width-remaining ps-print-width) | 2136 (setq ps-width-remaining ps-print-width) |
2178 (setq ps-height-remaining ps-print-height) | 2137 (setq ps-height-remaining ps-print-height) |
2179 | 2138 |
2180 (setq ps-page-count (+ ps-page-count 1)) | 2139 ;; Print only when a new real page begins. |
2181 | 2140 (when (zerop (mod ps-page-count ps-number-of-columns)) |
2182 (ps-output "\n%%Page: " | 2141 (ps-output (format "\n%%%%Page: %d %d\n" |
2183 (format "%d %d\n" ps-page-count (+ 1 ps-showpage-count))) | 2142 (1+ (/ ps-page-count ps-number-of-columns)) |
2143 (1+ (/ ps-page-count ps-number-of-columns))))) | |
2144 | |
2184 (ps-output "BeginDSCPage\n") | 2145 (ps-output "BeginDSCPage\n") |
2185 (ps-output (format "/PageNumber %d def\n" ps-page-count)) | 2146 (ps-output (format "/PageNumber %d def\n" (incf ps-page-count))) |
2186 (ps-output "/PageCount 0 def\n") | 2147 (ps-output "/PageCount 0 def\n") |
2187 | 2148 |
2188 (if ps-print-header | 2149 (when ps-print-header |
2189 (progn | 2150 (ps-generate-header "HeaderLinesLeft" ps-left-header) |
2190 (ps-generate-header "HeaderLinesLeft" ps-left-header) | 2151 (ps-generate-header "HeaderLinesRight" ps-right-header) |
2191 (ps-generate-header "HeaderLinesRight" ps-right-header) | 2152 (ps-output (format "%d SetHeaderLines\n" ps-header-lines))) |
2192 (ps-output (format "%d SetHeaderLines\n" ps-header-lines)))) | |
2193 | 2153 |
2194 (ps-output "BeginPage\n") | 2154 (ps-output "BeginPage\n") |
2195 (ps-set-font ps-current-font) | 2155 (ps-set-font ps-current-font) |
2196 (ps-set-bg ps-current-bg) | 2156 (ps-set-bg ps-current-bg) |
2197 (ps-set-color ps-current-color) | 2157 (ps-set-color ps-current-color) |
2274 (setq ps-razchunk q-done) | 2234 (setq ps-razchunk q-done) |
2275 (setq foo | 2235 (setq foo |
2276 (if (< q-todo 100) | 2236 (if (< q-todo 100) |
2277 (/ (* 100 q-done) q-todo) | 2237 (/ (* 100 q-done) q-todo) |
2278 (/ q-done (/ q-todo 100)))) | 2238 (/ q-done (/ q-todo 100)))) |
2279 (message "Formatting...%d%%" foo)))))) | 2239 (message "Formatting...%3d%%" foo)))))) |
2280 | 2240 |
2281 (defun ps-set-font (font) | 2241 (defun ps-set-font (font) |
2282 (setq ps-current-font font) | 2242 (setq ps-current-font font) |
2283 (ps-output (format "/f%d F\n" ps-current-font))) | 2243 (ps-output (format "/f%d F\n" ps-current-font))) |
2284 | 2244 |
2487 | 2447 |
2488 (defun ps-mapper (extent list) | 2448 (defun ps-mapper (extent list) |
2489 (nconc list (list (list (extent-start-position extent) 'push extent) | 2449 (nconc list (list (list (extent-start-position extent) 'push extent) |
2490 (list (extent-end-position extent) 'pull extent))) | 2450 (list (extent-end-position extent) 'pull extent))) |
2491 nil) | 2451 nil) |
2492 | |
2493 (defun ps-sorter (a b) | |
2494 (< (car a) (car b))) | |
2495 | 2452 |
2496 (defun ps-extent-sorter (a b) | 2453 (defun ps-extent-sorter (a b) |
2497 (< (extent-priority a) (extent-priority b))) | 2454 (< (extent-priority a) (extent-priority b))) |
2498 | 2455 |
2499 (defun ps-print-ensure-fontified (start end) | 2456 (defun ps-print-ensure-fontified (start end) |
2526 (eq ps-print-emacs-type 'xemacs)) | 2483 (eq ps-print-emacs-type 'xemacs)) |
2527 ;; Build the list of extents... | 2484 ;; Build the list of extents... |
2528 (let ((a (cons 'dummy nil)) | 2485 (let ((a (cons 'dummy nil)) |
2529 record type extent extent-list) | 2486 record type extent extent-list) |
2530 (map-extents 'ps-mapper nil from to a) | 2487 (map-extents 'ps-mapper nil from to a) |
2531 (setq a (cdr a)) | 2488 (setq a (sort (cdr a) 'car-less-than-car)) |
2532 (setq a (sort a 'ps-sorter)) | |
2533 | 2489 |
2534 (setq extent-list nil) | 2490 (setq extent-list nil) |
2535 | 2491 |
2536 ;; Loop through the extents... | 2492 ;; Loop through the extents... |
2537 (while a | 2493 (while a |
2638 ;; are copied into ps-spool-buffer. | 2594 ;; are copied into ps-spool-buffer. |
2639 (inhibit-read-only t)) | 2595 (inhibit-read-only t)) |
2640 (save-restriction | 2596 (save-restriction |
2641 (narrow-to-region from to) | 2597 (narrow-to-region from to) |
2642 (if ps-razzle-dazzle | 2598 (if ps-razzle-dazzle |
2643 (message "Formatting...%d%%" (setq ps-razchunk 0))) | 2599 (message "Formatting...%3d%%" (setq ps-razchunk 0))) |
2644 (set-buffer buffer) | 2600 (set-buffer buffer) |
2645 (setq ps-source-buffer buffer) | 2601 (setq ps-source-buffer buffer) |
2646 (setq ps-spool-buffer (get-buffer-create ps-spool-buffer-name)) | 2602 (setq ps-spool-buffer (get-buffer-create ps-spool-buffer-name)) |
2647 (ps-init-output-queue) | 2603 (ps-init-output-queue) |
2648 (let (safe-marker completed-safely needs-begin-file) | 2604 (let (safe-marker completed-safely needs-begin-file) |