0
|
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.
|
0
|
4
|
82
|
5 ;; Author: Jim Thompson (was <thompson@wg2.waii.com>)
|
|
6 ;; Maintainer: Jacques Duthen <duthen@cegelec-red.fr>
|
|
7 ;; Keywords: print, PostScript
|
88
|
8 ;; Time-stamp: <97/01/29 23:21:25 tjchol01>
|
82
|
9 ;; Version: 3.05
|
|
10
|
|
11 (defconst ps-print-version "3.05"
|
|
12 "ps-print.el, v 3.05 <97/01/17 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 ")
|
|
22
|
|
23 ;; This file is part of GNU Emacs.
|
|
24
|
|
25 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
26 ;; it under the terms of the GNU General Public License as published by
|
0
|
27 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
28 ;; any later version.
|
|
29
|
82
|
30 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
31 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
32 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
33 ;; GNU General Public License for more details.
|
0
|
34
|
|
35 ;; You should have received a copy of the GNU General Public License
|
82
|
36 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
37 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
38 ;; Boston, MA 02111-1307, USA.
|
0
|
39
|
|
40 ;; LCD Archive Entry:
|
|
41 ;; ps-print|James C. Thompson|thompson@wg2.waii.com|
|
|
42 ;; Jim's Pretty-Good PostScript Generator for Emacs 19 (ps-print)|
|
|
43 ;; 26-Feb-1994|2.8|~/packages/ps-print.el|
|
|
44
|
82
|
45 ;; 3.05 [jack] <97/01/16 duthen>
|
|
46 ;; Ben Wing <ben@666.com> took ps-print.el from the official 19.34
|
|
47 ;; GNU distribution:
|
|
48 ;; -rw-rw-r-- 1 duthen 69315 Jul 22 1996 ps-print.el
|
|
49 ;; He patched it for XEmacs.
|
|
50 ;; Steven L Baur <steve@miranova.com> sent me this version which has
|
|
51 ;; 26 diffs with 19.34.
|
|
52 ;; I merge these 26 diffs into my 3.04 version.
|
|
53
|
|
54 ;; `ps-paper-type': ###autoload.
|
|
55 ;; `ps-print-color-p' `ps-color-values': Replace pixel-components by
|
|
56 ;; color-instance-rgb-components for XEmacs.
|
|
57 ;; `ps-color-device': New function to dynamically test the device
|
|
58 ;; color capability, added where ps-print-color-p is tested.
|
|
59 ;; `ps-xemacs-face-kind-p': Fixed.
|
|
60 ;; `ps-do-despool': Permit dynamic evaluation at print time of
|
|
61 ;; ps-lpr-switches.
|
|
62 ;; `ps-eval-switch' `ps-flatten-list' `ps-flatten-list-1': New for
|
|
63 ;; the previous feature.
|
|
64 ;; `ps-gnus-print-article-from-summary': Updated for Gnus 5.
|
|
65
|
|
66
|
|
67 ;; 3.04 [jack] after [simon] Oct 8, 1996 Simon Marshall <simon@gnu.ai.mit.edu>
|
|
68 ;; `ps-print-version':
|
|
69 ;; Fix value.
|
|
70 ;; `cl' `lisp-float-type':
|
|
71 ;; Require them.
|
|
72 ;; `ps-number-of-columns' `ps-*-font-size':
|
|
73 ;; Try to select defaults better suited when `ps-landscape-mode' is non-nil.
|
|
74 ;; `ps-*-faces':
|
|
75 ;; Change default for Font Lock mode faces when `ps-print-color-p' is nil.
|
|
76 ;; `ps-right-header':
|
|
77 ;; Replace `time-stamp-yy/mm/dd' by `time-stamp-mon-dd-yyyy'.
|
|
78 ;; `ps-end-file' `ps-begin-page':
|
|
79 ;; Fix bug in page count for Ghostview.
|
|
80 ;; `ps-generate-postscript-with-faces':
|
|
81 ;; Replace `ps-sorter' by `car-less-than-car'.
|
|
82 ;; `ps-plot' `ps-generate':
|
|
83 ;; Replace `%d' by `%3d'.
|
|
84
|
|
85 ;; 3.03 [jack] Sept 27, 1996 Jacques Duthen <duthen@cegelec-red.fr>
|
|
86 ;; Merge 31 diffs between 19.29 and 19.34
|
|
87
|
|
88 ;; 3.02 [jack] June 26, 1996 Jacques Duthen <duthen@cegelec-red.fr>
|
|
89 ;; Add new page dimensions to `ps-page-dimensions-database' for `paper-type'
|
|
90 ;; Improve landscape mode `ps-landscape-mode' and multiple columns
|
|
91 ;; printing `ps-number-of-columns':
|
|
92 ;; The text and the margins are no more scaled.
|
|
93 ;; Simplify the semantics of `ps-inter-column' (space between columns).
|
|
94 ;; Add error checking for negative `ps-print-width' and `ps-print-height'.
|
|
95 ;; Change the semantics of `ps-top-margin' which is now the TOP MARGIN,
|
|
96 ;; and add `ps-header-offset' instead of having `ps-top-margin' split in 2.
|
|
97 ;; Add `ps-header-font-family', `ps-header-font-size' and
|
|
98 ;; `ps-header-title-font-size' to control the header.
|
|
99 ;; Add `ps-header-line-pad'.
|
|
100 ;; Change the semantics of `ps-font-info-database' to have symbolic
|
|
101 ;; font families.
|
|
102 ;; Add new fonts to `ps-font-info-database': `Courier' `Helvetica'
|
|
103 ;; `Times' `Palatino' `Helvetica-Narrow' `NewCenturySchlbk'
|
|
104 ;; Make public `ps-font-family' and `ps-font-size' so that the user
|
|
105 ;; can directly control the text font and size without loading ps-print.
|
|
106 ;; Add error checking for unknown font families and a message giving
|
|
107 ;; the exhaustive list of available font families.
|
|
108 ;; Document how to install a new font family.
|
|
109 ;; Add `/ReportAllFontInfo' to get all the font families of the printer.
|
|
110 ;; Add the possibility to make `mixed' font families.
|
|
111 ;; Add `ps-setup' to get the current setup.
|
|
112 ;; Add tools `ps-line-lengths' `ps-nb-pages-buffer' `ps-nb-pages-region'
|
|
113 ;; to help choose the font size.
|
|
114 ;; Split `ps-print-prologue' in two to insert info from header fonts
|
|
115 ;; Replace indexes by macro `ps-page-dimensions-get-width'
|
|
116 ;; to get access to the dimensions list.
|
|
117 ;; Add `ps-select-font' inside `ps-get-page-dimensions'.
|
|
118 ;; Fix the "clumsy" `ps-page-height' management.
|
|
119 ;; Move `ps-get-page-dimensions' to the beginning of `ps-begin-file'
|
|
120 ;; to get early error checking.
|
|
121 ;; Add sample setup `ps-jack-setup'.
|
|
122 ;;
|
|
123 ;; Rewrite a lot of postscript code and add comments inside it
|
|
124 ;; (maybe they should not (or optionally) be included in the generated
|
|
125 ;; Postscript).
|
|
126 ;; Translate the origin to (lm, bm) to simplify the other moves.
|
|
127 ;; Fix bug in `/HeaderOffset' with `/PrintStartY'.
|
|
128 ;; Fix bug in `/SetHeaderLines'.
|
|
129 ;; Change `/ReportFontInfo' for use by `/ReportAllFontInfo'.
|
|
130
|
|
131 ;; 3.01 [jack] June 4, 1996 Jacques Duthen <duthen@cegelec-red.fr>
|
|
132 ;; Manage float value for every variable representing a size.
|
|
133 ;; Add `ps-font-info-database' `ps-inter-column'
|
|
134
|
|
135 ;; 3.00 [jack] May 17, 1996 Jacques Duthen <duthen@cegelec-red.fr>
|
|
136 ;; based on 2.8 Jim's Pretty-Good version:
|
|
137 ;; Add `ps-landscape-mode' and `ps-number-of-columns'
|
|
138 ;; for dumb multi-column landscape mode.
|
|
139
|
0
|
140 ;; Baseline-version: 2.8. (Jim's last change version -- this
|
|
141 ;; file may have been edited as part of Emacs without changes to the
|
|
142 ;; version number. When reporting bugs, please also report the
|
|
143 ;; version of Emacs, if any, that ps-print was distributed with.)
|
|
144
|
|
145 ;;; Commentary:
|
|
146
|
|
147 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
148 ;;
|
|
149 ;; About ps-print
|
|
150 ;; --------------
|
82
|
151 ;;
|
0
|
152 ;; This package provides printing of Emacs buffers on PostScript
|
|
153 ;; printers; the buffer's bold and italic text attributes are
|
|
154 ;; preserved in the printer output. Ps-print is intended for use with
|
|
155 ;; Emacs 19 or Lucid Emacs, together with a fontifying package such as
|
|
156 ;; font-lock or hilit.
|
|
157 ;;
|
82
|
158 ;;
|
0
|
159 ;; Using ps-print
|
|
160 ;; --------------
|
|
161 ;;
|
|
162 ;; The Commands
|
|
163 ;;
|
|
164 ;; Ps-print provides eight commands for generating PostScript images
|
|
165 ;; of Emacs buffers:
|
|
166 ;;
|
|
167 ;; ps-print-buffer
|
|
168 ;; ps-print-buffer-with-faces
|
|
169 ;; ps-print-region
|
|
170 ;; ps-print-region-with-faces
|
|
171 ;; ps-spool-buffer
|
|
172 ;; ps-spool-buffer-with-faces
|
|
173 ;; ps-spool-region
|
|
174 ;; ps-spool-region-with-faces
|
|
175 ;;
|
|
176 ;; These commands all perform essentially the same function: they
|
|
177 ;; generate PostScript images suitable for printing on a PostScript
|
|
178 ;; printer or displaying with GhostScript. These commands are
|
|
179 ;; collectively referred to as "ps-print- commands".
|
|
180 ;;
|
|
181 ;; The word "print" or "spool" in the command name determines when the
|
|
182 ;; PostScript image is sent to the printer:
|
|
183 ;;
|
|
184 ;; print - The PostScript image is immediately sent to the
|
|
185 ;; printer;
|
|
186 ;;
|
|
187 ;; spool - The PostScript image is saved temporarily in an
|
|
188 ;; Emacs buffer. Many images may be spooled locally
|
|
189 ;; before printing them. To send the spooled images
|
82
|
190 ;; to the printer, use the command `ps-despool'.
|
0
|
191 ;;
|
|
192 ;; The spooling mechanism was designed for printing lots of small
|
|
193 ;; files (mail messages or netnews articles) to save paper that would
|
|
194 ;; otherwise be wasted on banner pages, and to make it easier to find
|
|
195 ;; your output at the printer (it's easier to pick up one 50-page
|
|
196 ;; printout than to find 50 single-page printouts).
|
|
197 ;;
|
82
|
198 ;; Ps-print has a hook in the `kill-emacs-hooks' so that you won't
|
2
|
199 ;; accidentally quit from Emacs while you have unprinted PostScript
|
0
|
200 ;; waiting in the spool buffer. If you do attempt to exit with
|
|
201 ;; spooled PostScript, you'll be asked if you want to print it, and if
|
|
202 ;; you decline, you'll be asked to confirm the exit; this is modeled
|
|
203 ;; on the confirmation that Emacs uses for modified buffers.
|
|
204 ;;
|
|
205 ;; The word "buffer" or "region" in the command name determines how
|
|
206 ;; much of the buffer is printed:
|
|
207 ;;
|
|
208 ;; buffer - Print the entire buffer.
|
|
209 ;;
|
|
210 ;; region - Print just the current region.
|
|
211 ;;
|
|
212 ;; The -with-faces suffix on the command name means that the command
|
|
213 ;; will include font, color, and underline information in the
|
|
214 ;; PostScript image, so the printed image can look as pretty as the
|
|
215 ;; buffer. The ps-print- commands without the -with-faces suffix
|
|
216 ;; don't include font, color, or underline information; images printed
|
|
217 ;; with these commands aren't as pretty, but are faster to generate.
|
|
218 ;;
|
|
219 ;; Two ps-print- command examples:
|
|
220 ;;
|
|
221 ;; ps-print-buffer - print the entire buffer,
|
|
222 ;; without font, color, or
|
|
223 ;; underline information, and
|
|
224 ;; send it immediately to the
|
|
225 ;; printer.
|
|
226 ;;
|
|
227 ;; ps-spool-region-with-faces - print just the current region;
|
|
228 ;; include font, color, and
|
|
229 ;; underline information, and
|
|
230 ;; spool the image in Emacs to
|
|
231 ;; send to the printer later.
|
|
232 ;;
|
|
233 ;;
|
|
234 ;; Invoking Ps-Print
|
82
|
235 ;; -----------------
|
0
|
236 ;;
|
|
237 ;; To print your buffer, type
|
|
238 ;;
|
|
239 ;; M-x ps-print-buffer
|
|
240 ;;
|
|
241 ;; or substitute one of the other seven ps-print- commands. The
|
|
242 ;; command will generate the PostScript image and print or spool it as
|
|
243 ;; specified. By giving the command a prefix argument
|
|
244 ;;
|
|
245 ;; C-u M-x ps-print-buffer
|
|
246 ;;
|
|
247 ;; it will save the PostScript image to a file instead of sending it
|
|
248 ;; to the printer; you will be prompted for the name of the file to
|
|
249 ;; save the image to. The prefix argument is ignored by the commands
|
|
250 ;; that spool their images, but you may save the spooled images to a
|
82
|
251 ;; file by giving a prefix argument to `ps-despool':
|
0
|
252 ;;
|
|
253 ;; C-u M-x ps-despool
|
|
254 ;;
|
82
|
255 ;; When invoked this way, `ps-despool' will prompt you for the name of
|
0
|
256 ;; the file to save to.
|
|
257 ;;
|
82
|
258 ;; Any of the `ps-print-' commands can be bound to keys; I recommend
|
|
259 ;; binding `ps-spool-buffer-with-faces', `ps-spool-region-with-faces',
|
|
260 ;; and `ps-despool'. Here are the bindings I use on my Sun 4 keyboard:
|
0
|
261 ;;
|
|
262 ;; (global-set-key 'f22 'ps-spool-buffer-with-faces) ;f22 is prsc
|
|
263 ;; (global-set-key '(shift f22) 'ps-spool-region-with-faces)
|
|
264 ;; (global-set-key '(control f22) 'ps-despool)
|
|
265 ;;
|
|
266 ;;
|
|
267 ;; The Printer Interface
|
82
|
268 ;; ---------------------
|
0
|
269 ;;
|
82
|
270 ;; The variables `ps-lpr-command' and `ps-lpr-switches' determine what
|
70
|
271 ;; command is used to send the PostScript images to the printer, and
|
82
|
272 ;; what arguments to give the command. These are analogous to
|
|
273 ;; `lpr-command' and `lpr-switches'.
|
16
|
274 ;;
|
82
|
275 ;; Make sure that they contain appropriate values for your system;
|
|
276 ;; see the usage notes below and the documentation of these variables.
|
|
277 ;;
|
|
278 ;; NOTE: `ps-lpr-command' and `ps-lpr-switches' take their initial values
|
|
279 ;; from the variables `lpr-command' and `lpr-switches'. If you have
|
|
280 ;; `lpr-command' set to invoke a pretty-printer such as `enscript',
|
|
281 ;; then ps-print won't work properly. `ps-lpr-command' must name
|
0
|
282 ;; a program that does not format the files it prints.
|
|
283 ;;
|
|
284 ;;
|
82
|
285 ;; The Page Layout
|
|
286 ;; ---------------
|
0
|
287 ;;
|
82
|
288 ;; All dimensions are floats in PostScript points.
|
|
289 ;; 1 inch == 2.54 cm == 72 points
|
|
290 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
|
0
|
291 ;;
|
82
|
292 ;; The variable `ps-paper-type' determines the size of paper ps-print
|
|
293 ;; formats for; it should contain one of the symbols:
|
|
294 ;; `a4' `a3' `letter' `legal' `letter-small' `tabloid'
|
|
295 ;; `ledger' `statement' `executive' `a4small' `b4' `b5'
|
0
|
296 ;;
|
82
|
297 ;; The variable `ps-landscape-mode' determines the orientation
|
|
298 ;; of the printing on the page:
|
|
299 ;; nil means `portrait' mode, non-nil means `landscape' mode.
|
|
300 ;; There is no oblique mode yet, though this is easy to do in ps.
|
|
301
|
|
302 ;; In landscape mode, the text is NOT scaled: you may print 70 lines
|
|
303 ;; in portrait mode and only 50 lignes in landscape mode.
|
|
304 ;; The margins represent margins in the printed paper:
|
|
305 ;; the top margin is the margin between the top of the page
|
|
306 ;; and the printed header, whatever the orientation is.
|
0
|
307 ;;
|
82
|
308 ;; The variable `ps-number-of-columns' determines the number of columns
|
|
309 ;; both in landscape and portrait mode.
|
|
310 ;; You can use:
|
|
311 ;; - (the standard) one column portrait mode
|
|
312 ;; - (my favorite) two columns landscape mode (which spares trees)
|
|
313 ;; but also
|
|
314 ;; - one column landscape mode for files with very long lines.
|
|
315 ;; - multi-column portrait or landscape mode
|
0
|
316 ;;
|
|
317 ;;
|
82
|
318 ;; Horizontal layout
|
|
319 ;; -----------------
|
|
320 ;;
|
|
321 ;; The horizontal layout is determined by the variables
|
|
322 ;; `ps-left-margin' `ps-inter-column' `ps-right-margin'
|
|
323 ;; as follows:
|
|
324 ;;
|
|
325 ;; ------------------------------------------
|
|
326 ;; | | | | | | | |
|
|
327 ;; | lm | text | ic | text | ic | text | rm |
|
|
328 ;; | | | | | | | |
|
|
329 ;; ------------------------------------------
|
|
330 ;;
|
|
331 ;; If `ps-number-of-columns' is 1, `ps-inter-column' is not relevant.
|
|
332 ;; Usually, lm = rm > 0 and ic = lm
|
|
333 ;; If (ic < 0), the text of adjacent columns can overlap.
|
|
334 ;;
|
|
335 ;;
|
|
336 ;; Vertical layout
|
|
337 ;; ---------------
|
0
|
338 ;;
|
82
|
339 ;; The vertical layout is determined by the variables
|
|
340 ;; `ps-bottom-margin' `ps-top-margin' `ps-header-offset'
|
|
341 ;; as follows:
|
|
342 ;;
|
|
343 ;; |--------| |--------|
|
|
344 ;; | tm | | tm |
|
|
345 ;; |--------| |--------|
|
|
346 ;; | header | | |
|
|
347 ;; |--------| | |
|
|
348 ;; | ho | | |
|
|
349 ;; |--------| or | text |
|
|
350 ;; | | | |
|
|
351 ;; | text | | |
|
|
352 ;; | | | |
|
|
353 ;; |--------| |--------|
|
|
354 ;; | bm | | bm |
|
|
355 ;; |--------| |--------|
|
|
356 ;;
|
|
357 ;; If `ps-print-header' is nil, `ps-header-offset' is not relevant.
|
|
358 ;; The margins represent margins in the printed paper:
|
|
359 ;; the top margin is the margin between the top of the page
|
|
360 ;; and the printed header, whatever the orientation is.
|
0
|
361 ;;
|
|
362 ;;
|
|
363 ;; Headers
|
82
|
364 ;; -------
|
0
|
365 ;;
|
82
|
366 ;; Ps-print can print headers at the top of each column; the default
|
0
|
367 ;; headers contain the following four items: on the left, the name of
|
|
368 ;; the buffer and, if the buffer is visiting a file, the file's
|
82
|
369 ;; directory; on the right, the page number and date of printing.
|
|
370 ;; The default headers look something like this:
|
0
|
371 ;;
|
|
372 ;; ps-print.el 1/21
|
|
373 ;; /home/jct/emacs-lisp/ps/new 94/12/31
|
|
374 ;;
|
|
375 ;; When printing on duplex printers, left and right are reversed so
|
82
|
376 ;; that the page numbers are toward the outside (cf. `ps-spool-duplex').
|
|
377 ;;
|
|
378 ;; Headers are configurable:
|
|
379 ;; To turn them off completely, set `ps-print-header' to nil.
|
|
380 ;; To turn off the header's gaudy framing box,
|
|
381 ;; set `ps-print-header-frame' to nil.
|
0
|
382 ;;
|
82
|
383 ;; The font family and size of text in the header are determined
|
|
384 ;; by the variables `ps-header-font-family', `ps-header-font-size' and
|
|
385 ;; `ps-header-title-font-size' (see below).
|
|
386 ;;
|
|
387 ;; The variable `ps-header-line-pad' determines the portion of a header
|
|
388 ;; title line height to insert between the header frame and the text
|
|
389 ;; it contains, both in the vertical and horizontal directions:
|
|
390 ;; .5 means half a line.
|
|
391
|
|
392 ;; Page numbers are printed in `n/m' format, indicating page n of m pages;
|
|
393 ;; to omit the total page count and just print the page number,
|
|
394 ;; set `ps-show-n-of-n' to nil.
|
0
|
395 ;;
|
|
396 ;; The amount of information in the header can be changed by changing
|
82
|
397 ;; the number of lines. To show less, set `ps-header-lines' to 1, and
|
0
|
398 ;; the header will show only the buffer name and page number. To show
|
82
|
399 ;; more, set `ps-header-lines' to 3, and the header will show the time of
|
0
|
400 ;; printing below the date.
|
|
401 ;;
|
|
402 ;; To change the content of the headers, change the variables
|
82
|
403 ;; `ps-left-header' and `ps-right-header'.
|
|
404 ;; These variables are lists, specifying top-to-bottom the text
|
|
405 ;; to display on the left or right side of the header.
|
|
406 ;; Each element of the list should be a string or a symbol.
|
|
407 ;; Strings are inserted directly into the PostScript arrays,
|
|
408 ;; and should contain the PostScript string delimiters '(' and ')'.
|
0
|
409 ;;
|
|
410 ;; Symbols in the header format lists can either represent functions
|
|
411 ;; or variables. Functions are called, and should return a string to
|
|
412 ;; show in the header. Variables should contain strings to display in
|
|
413 ;; the header. In either case, function or variable, the PostScript
|
82
|
414 ;; string delimiters are added by ps-print, and should not be part of
|
0
|
415 ;; the returned value.
|
|
416 ;;
|
|
417 ;; Here's an example: say we want the left header to display the text
|
|
418 ;;
|
|
419 ;; Moe
|
|
420 ;; Larry
|
|
421 ;; Curly
|
|
422 ;;
|
|
423 ;; where we have a function to return "Moe"
|
|
424 ;;
|
|
425 ;; (defun moe-func ()
|
|
426 ;; "Moe")
|
|
427 ;;
|
|
428 ;; a variable specifying "Larry"
|
|
429 ;;
|
|
430 ;; (setq larry-var "Larry")
|
|
431 ;;
|
82
|
432 ;; and a literal for "Curly". Here's how `ps-left-header' should be
|
0
|
433 ;; set:
|
|
434 ;;
|
|
435 ;; (setq ps-left-header (list 'moe-func 'larry-var "(Curly)"))
|
|
436 ;;
|
|
437 ;; Note that Curly has the PostScript string delimiters inside his
|
82
|
438 ;; quotes -- those aren't misplaced lisp delimiters!
|
|
439 ;;
|
|
440 ;; Without them, PostScript would attempt to call the undefined
|
|
441 ;; function Curly, which would result in a PostScript error.
|
|
442 ;;
|
|
443 ;; Since most printers don't report PostScript errors except by
|
|
444 ;; aborting the print job, this kind of error can be hard to track down.
|
|
445 ;;
|
|
446 ;; Consider yourself warned!
|
0
|
447 ;;
|
|
448 ;;
|
|
449 ;; Duplex Printers
|
82
|
450 ;; ---------------
|
0
|
451 ;;
|
|
452 ;; If you have a duplex-capable printer (one that prints both sides of
|
82
|
453 ;; the paper), set `ps-spool-duplex' to t.
|
|
454 ;; Ps-print will insert blank pages to make sure each buffer starts
|
|
455 ;; on the correct side of the paper.
|
|
456 ;; Don't forget to set `ps-lpr-switches' to select duplex printing
|
|
457 ;; for your printer.
|
|
458 ;;
|
|
459 ;;
|
|
460 ;; Font managing
|
|
461 ;; -------------
|
|
462 ;;
|
|
463 ;; Ps-print now knows rather precisely some fonts:
|
|
464 ;; the variable `ps-font-info-database' contains information
|
|
465 ;; for a list of font families (currently mainly `Courier' `Helvetica'
|
|
466 ;; `Times' `Palatino' `Helvetica-Narrow' `NewCenturySchlbk').
|
|
467 ;; Each font family contains the font names for standard, bold, italic
|
|
468 ;; and bold-italic characters, a reference size (usually 10) and the
|
|
469 ;; corresponding line height, width of a space and average character width.
|
0
|
470 ;;
|
82
|
471 ;; The variable `ps-font-family' determines which font family
|
|
472 ;; is to be used for ordinary text.
|
|
473 ;; If its value does not correspond to a known font family,
|
|
474 ;; an error message is printed into the `*Messages*' buffer,
|
|
475 ;; which lists the currently available font families.
|
16
|
476 ;;
|
82
|
477 ;; The variable `ps-font-size' determines the size (in points)
|
|
478 ;; of the font for ordinary text, when generating Postscript.
|
|
479 ;; Its value is a float.
|
|
480 ;;
|
|
481 ;; Similarly, the variable `ps-header-font-family' determines
|
|
482 ;; which font family is to be used for text in the header.
|
|
483 ;; The variable `ps-header-font-size' determines the font size,
|
|
484 ;; in points, for text in the header.
|
|
485 ;; The variable `ps-header-title-font-size' determines the font size,
|
|
486 ;; in points, for the top line of text in the header.
|
|
487 ;;
|
|
488 ;;
|
|
489 ;; Adding a new font family
|
|
490 ;; ------------------------
|
|
491 ;;
|
|
492 ;; To use a new font family, you MUST first teach ps-print
|
88
|
493 ;; this font, i.e., add its information to `ps-font-info-database',
|
82
|
494 ;; otherwise ps-print cannot correctly place line and page breaks.
|
|
495 ;;
|
88
|
496 ;; For example, assuming `Helvetica' is unknown,
|
82
|
497 ;; you first need to do the following ONLY ONCE:
|
|
498 ;;
|
|
499 ;; - create a new buffer
|
|
500 ;; - generate the PostScript image to a file (C-u M-x ps-print-buffer)
|
|
501 ;; - open this file and find the line:
|
|
502 ;; `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
|
|
503 ;; - delete the leading `%' (which is the Postscript comment character)
|
|
504 ;; - replace in this line `Courier' by the new font (say `Helvetica')
|
|
505 ;; to get the line:
|
|
506 ;; `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
|
|
507 ;; - send this file to the printer (or to ghostscript).
|
|
508 ;; You should read the following on the output page:
|
|
509 ;;
|
|
510 ;; For Helvetica 10 point, the line height is 11.56, the space width is 2.78
|
|
511 ;; and a crude estimate of average character width is 5.09243
|
|
512 ;;
|
|
513 ;; - Add these values to the `ps-font-info-database':
|
|
514 ;; (setq ps-font-info-database
|
|
515 ;; (append
|
|
516 ;; '((Helvetica ; the family name
|
|
517 ;; "Helvetica" "Helvetica-Bold" "Helvetica-Oblique" "Helvetica-BoldOblique"
|
|
518 ;; 10.0 11.56 2.78 5.09243))
|
|
519 ;; ps-font-info-database))
|
|
520 ;; - Now you can use this font family with any size:
|
|
521 ;; (setq ps-font-family 'Helvetica)
|
|
522 ;; - if you want to use this family in another emacs session, you must
|
|
523 ;; put into your `~/.emacs':
|
|
524 ;; (require 'ps-print)
|
|
525 ;; (setq ps-font-info-database (append ...)))
|
|
526 ;; if you don't want to load ps-print, you have to copy the whole value:
|
|
527 ;; (setq ps-font-info-database '(<your stuff> <the standard stuff>))
|
|
528 ;; or, if you can wait until the `ps-print-hook' is implemented, do:
|
|
529 ;; (add-hook 'ps-print-hook '(setq ps-font-info-database (append ...)))
|
|
530 ;; This does not work yet, since there is no `ps-print-hook' yet.
|
0
|
531 ;;
|
82
|
532 ;; You can create new `mixed' font families like:
|
|
533 ;; (my-mixed-family
|
|
534 ;; "Courier-Bold" "Helvetica"
|
|
535 ;; "Zapf-Chancery-MediumItalic" "NewCenturySchlbk-BoldItalic"
|
|
536 ;; 10.0 10.55 6.0 6.0)
|
|
537 ;; Now you can use your new font family with any size:
|
|
538 ;; (setq ps-font-family 'my-mixed-family)
|
|
539 ;;
|
|
540 ;; You can get information on all the fonts resident in YOUR printer
|
|
541 ;; by uncommenting the line:
|
|
542 ;; % 3 cm 20 cm moveto ReportAllFontInfo showpage
|
|
543 ;;
|
|
544 ;; The postscript file should be sent to YOUR postscript printer.
|
|
545 ;; If you send it to ghostscript or to another postscript printer,
|
|
546 ;; you may get slightly different results.
|
|
547 ;; Anyway, as ghostscript fonts are autoload, you won't get
|
|
548 ;; much font info.
|
|
549 ;;
|
|
550 ;;
|
|
551 ;; How Ps-Print Deals With Faces
|
|
552 ;; -----------------------------
|
|
553 ;;
|
|
554 ;; The ps-print-*-with-faces commands attempt to determine which faces
|
|
555 ;; should be printed in bold or italic, but their guesses aren't
|
|
556 ;; always right. For example, you might want to map colors into faces
|
|
557 ;; so that blue faces print in bold, and red faces in italic.
|
|
558 ;;
|
|
559 ;; It is possible to force ps-print to consider specific faces bold or
|
|
560 ;; italic, no matter what font they are displayed in, by setting the
|
|
561 ;; variables `ps-bold-faces' and `ps-italic-faces'. These variables
|
|
562 ;; contain lists of faces that ps-print should consider bold or
|
|
563 ;; italic; to set them, put code like the following into your .emacs
|
|
564 ;; file:
|
|
565 ;;
|
|
566 ;; (setq ps-bold-faces '(my-blue-face))
|
|
567 ;; (setq ps-italic-faces '(my-red-face))
|
|
568 ;;
|
|
569 ;; Faces like bold-italic that are both bold and italic should go in
|
|
570 ;; *both* lists.
|
0
|
571 ;;
|
82
|
572 ;; Ps-print keeps internal lists of which fonts are bold and which are
|
|
573 ;; italic; these lists are built the first time you invoke ps-print.
|
|
574 ;; For the sake of efficiency, the lists are built only once; the same
|
|
575 ;; lists are referred in later invocations of ps-print.
|
|
576 ;;
|
|
577 ;; Because these lists are built only once, it's possible for them to
|
|
578 ;; get out of sync, if a face changes, or if new faces are added. To
|
|
579 ;; get the lists back in sync, you can set the variable
|
|
580 ;; `ps-build-face-reference' to t, and the lists will be rebuilt the
|
|
581 ;; next time ps-print is invoked.
|
|
582 ;;
|
|
583 ;;
|
|
584 ;; How Ps-Print Deals With Color
|
|
585 ;; -----------------------------
|
|
586 ;;
|
|
587 ;; Ps-print detects faces with foreground and background colors
|
|
588 ;; defined and embeds color information in the PostScript image.
|
|
589 ;; The default foreground and background colors are defined by the
|
|
590 ;; variables `ps-default-fg' and `ps-default-bg'.
|
|
591 ;; On black-and-white printers, colors are displayed in grayscale.
|
|
592 ;; To turn off color output, set `ps-print-color-p' to nil.
|
|
593 ;;
|
|
594 ;;
|
|
595 ;; Utilities
|
|
596 ;; ---------
|
|
597 ;;
|
|
598 ;; Some tools are provided to help you customize your font setup.
|
|
599 ;;
|
|
600 ;; `ps-setup' returns (some part of) the current setup.
|
|
601 ;;
|
|
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:
|
|
604 ;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
|
|
605 ;; to determine the longest lines of your file.
|
88
|
606 ;; Then, the command `ps-line-lengths' will give you the correspondence
|
82
|
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.
|
|
609 ;;
|
|
610 ;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
|
88
|
611 ;; the correspondence between a number of pages and the maximum font
|
82
|
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.
|
|
614 ;; Note: line folding is not taken into account in this process
|
|
615 ;; and could change the results.
|
|
616 ;;
|
|
617 ;;
|
0
|
618 ;; New since version 1.5
|
|
619 ;; ---------------------
|
82
|
620 ;;
|
70
|
621 ;; Color output capability.
|
0
|
622 ;; Automatic detection of font attributes (bold, italic).
|
82
|
623 ;; Configurable headers with page numbers.
|
|
624 ;; Slightly faster.
|
|
625 ;; Support for different paper sizes.
|
|
626 ;; Better conformance to PostScript Document Structure Conventions.
|
70
|
627 ;;
|
0
|
628 ;;
|
82
|
629 ;; New since version 2.8
|
|
630 ;; ---------------------
|
|
631 ;;
|
|
632 ;; [jack] 960517 Jacques Duthen <duthen@cegelec-red.fr>
|
0
|
633 ;;
|
82
|
634 ;; Font familiy and float size for text and header.
|
|
635 ;; Landscape mode.
|
|
636 ;; Multiple columns.
|
|
637 ;; Tools for page setup.
|
0
|
638 ;;
|
|
639 ;;
|
|
640 ;; Known bugs and limitations of ps-print:
|
|
641 ;; --------------------------------------
|
82
|
642 ;;
|
0
|
643 ;; Although color printing will work in XEmacs 19.12, it doesn't work
|
|
644 ;; well; in particular, bold or italic fonts don't print in the right
|
|
645 ;; background color.
|
|
646 ;;
|
|
647 ;; Invisible properties aren't correctly ignored in XEmacs 19.12.
|
|
648 ;;
|
|
649 ;; Automatic font-attribute detection doesn't work well, especially
|
|
650 ;; with hilit19 and older versions of get-create-face. Users having
|
82
|
651 ;; problems with auto-font detection should use the lists
|
|
652 ;; `ps-italic-faces' and `ps-bold-faces' and/or turn off automatic
|
|
653 ;; detection by setting `ps-auto-font-detect' to nil.
|
0
|
654 ;;
|
|
655 ;; Automatic font-attribute detection doesn't work with XEmacs 19.12
|
82
|
656 ;; in tty mode; use the lists `ps-italic-faces' and `ps-bold-faces'
|
0
|
657 ;; instead.
|
|
658 ;;
|
|
659 ;; Still too slow; could use some hand-optimization.
|
|
660 ;;
|
|
661 ;; ASCII Control characters other than tab, linefeed and pagefeed are
|
|
662 ;; not handled.
|
|
663 ;;
|
|
664 ;; Default background color isn't working.
|
|
665 ;;
|
|
666 ;; Faces are always treated as opaque.
|
|
667 ;;
|
|
668 ;; Epoch and Emacs 18 not supported. At all.
|
|
669 ;;
|
82
|
670 ;; Fixed-pitch fonts work better for line folding, but are not required.
|
0
|
671 ;;
|
82
|
672 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' don't take care
|
|
673 ;; of folding lines.
|
|
674 ;;
|
|
675 ;;
|
|
676 ;; Things to change:
|
|
677 ;; ----------------
|
70
|
678 ;;
|
82
|
679 ;; Add `ps-print-hook' (I don't know how to do that (yet!)).
|
|
680 ;; Add 4-up capability (really needed?).
|
|
681 ;; Add line numbers (should not be too hard).
|
|
682 ;; Add `ps-non-bold-faces' and `ps-non-italic-faces' (should be easy).
|
|
683 ;; Put one header per page over the columns (easy but needed?).
|
|
684 ;; Improve the memory management for big files (hard?).
|
|
685 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' should take care
|
|
686 ;; of folding lines.
|
0
|
687 ;;
|
|
688 ;;
|
|
689 ;; Acknowledgements
|
|
690 ;; ----------------
|
82
|
691 ;; Thanks to Jim Thompson <?@?> for the 2.8 version I started from.
|
|
692 ;; [jack]
|
|
693 ;;
|
0
|
694 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for adding support for
|
|
695 ;; color and the invisible property.
|
|
696 ;;
|
|
697 ;; Thanks to Avishai Yacobi, avishaiy@mcil.comm.mot.com, for writing
|
|
698 ;; the initial port to Emacs 19. His code is no longer part of
|
|
699 ;; ps-print, but his work is still appreciated.
|
|
700 ;;
|
|
701 ;; Thanks to Remi Houdaille and Michel Train, michel@metasoft.fdn.org,
|
|
702 ;; for adding underline support. Their code also is no longer part of
|
|
703 ;; ps-print, but their efforts are not forgotten.
|
|
704 ;;
|
|
705 ;; Thanks also to all of you who mailed code to add features to
|
|
706 ;; ps-print; although I didn't use your code, I still appreciate your
|
|
707 ;; sharing it with me.
|
|
708 ;;
|
|
709 ;; Thanks to all who mailed comments, encouragement, and criticism.
|
|
710 ;; Thanks also to all who responded to my survey; I had too many
|
|
711 ;; responses to reply to them all, but I greatly appreciate your
|
|
712 ;; interest.
|
|
713 ;;
|
|
714 ;; Jim
|
|
715 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
716
|
|
717 ;;; Code:
|
|
718
|
82
|
719 (eval-when-compile
|
|
720 (require 'cl))
|
|
721
|
|
722 (unless (featurep 'lisp-float-type)
|
|
723 (error "`ps-print' requires floating point support"))
|
0
|
724
|
|
725 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
726 ;; User Variables:
|
|
727
|
82
|
728 ;;; Interface to the command system
|
|
729
|
0
|
730 (defvar ps-lpr-command lpr-command
|
|
731 "*The shell command for printing a PostScript file.")
|
|
732
|
|
733 (defvar ps-lpr-switches lpr-switches
|
|
734 "*A list of extra switches to pass to `ps-lpr-command'.")
|
|
735
|
82
|
736 ;;; Page layout
|
|
737
|
|
738 ;; All page dimensions are in PostScript points.
|
|
739 ;; 1 inch == 2.54 cm == 72 points
|
|
740 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
|
|
741
|
|
742 ;; Letter 8.5 inch x 11.0 inch
|
|
743 ;; Legal 8.5 inch x 14.0 inch
|
|
744 ;; A4 8.26 inch x 11.69 inch = 21.0 cm x 29.7 cm
|
|
745
|
|
746 ;; LetterSmall 7.68 inch x 10.16 inch
|
|
747 ;; Tabloid 11.0 inch x 17.0 inch
|
|
748 ;; Ledger 17.0 inch x 11.0 inch
|
|
749 ;; Statement 5.5 inch x 8.5 inch
|
|
750 ;; Executive 7.5 inch x 10.0 inch
|
|
751 ;; A3 11.69 inch x 16.5 inch = 29.7 cm x 42.0 cm
|
|
752 ;; A4Small 7.47 inch x 10.85 inch
|
|
753 ;; B4 10.125 inch x 14.33 inch
|
|
754 ;; B5 7.16 inch x 10.125 inch
|
|
755
|
|
756 (defvar ps-page-dimensions-database
|
|
757 (list (list 'a4 (/ (* 72 21.0) 2.54) (/ (* 72 29.7) 2.54))
|
|
758 (list 'a3 (/ (* 72 29.7) 2.54) (/ (* 72 42.0) 2.54))
|
|
759 (list 'letter (* 72 8.5) (* 72 11.0))
|
|
760 (list 'legal (* 72 8.5) (* 72 14.0))
|
|
761 (list 'letter-small (* 72 7.68) (* 72 10.16))
|
|
762 (list 'tabloid (* 72 11.0) (* 72 17.0))
|
|
763 (list 'ledger (* 72 17.0) (* 72 11.0))
|
|
764 (list 'statement (* 72 5.5) (* 72 8.5))
|
|
765 (list 'executive (* 72 7.5) (* 72 10.0))
|
|
766 (list 'a4small (* 72 7.47) (* 72 10.85))
|
|
767 (list 'b4 (* 72 10.125) (* 72 14.33))
|
|
768 (list 'b5 (* 72 7.16) (* 72 10.125)))
|
|
769 "*List associating a symbolic paper type to its width and height.
|
|
770 see `ps-paper-type'.")
|
0
|
771
|
|
772 ;;;###autoload
|
82
|
773 (defvar ps-paper-type 'letter
|
|
774 "*Specifies the size of paper to format for.
|
|
775 Should be one of the paper types defined in `ps-page-dimensions-database', for
|
|
776 example `letter', `legal' or `a4'.")
|
|
777
|
|
778 (defvar ps-landscape-mode 'nil
|
|
779 "*Non-nil means print in landscape mode.")
|
|
780
|
|
781 (defvar ps-number-of-columns (if ps-landscape-mode 2 1)
|
|
782 "*Specifies the number of columns")
|
|
783
|
|
784 ;;; Horizontal layout
|
|
785
|
|
786 ;; ------------------------------------------
|
|
787 ;; | | | | | | | |
|
|
788 ;; | lm | text | ic | text | ic | text | rm |
|
|
789 ;; | | | | | | | |
|
|
790 ;; ------------------------------------------
|
|
791
|
|
792 (defvar ps-left-margin (/ (* 72 2.0) 2.54) ; 2 cm
|
|
793 "*Left margin in points (1/72 inch).")
|
|
794
|
|
795 (defvar ps-right-margin (/ (* 72 2.0) 2.54) ; 2 cm
|
|
796 "*Right margin in points (1/72 inch).")
|
|
797
|
|
798 (defvar ps-inter-column (/ (* 72 2.0) 2.54) ; 2 cm
|
|
799 "*Horizontal space between columns in points (1/72 inch).")
|
|
800
|
|
801 ;;; Vertical layout
|
|
802
|
|
803 ;; |--------|
|
|
804 ;; | tm |
|
|
805 ;; |--------|
|
|
806 ;; | header |
|
|
807 ;; |--------|
|
|
808 ;; | ho |
|
|
809 ;; |--------|
|
|
810 ;; | text |
|
|
811 ;; |--------|
|
|
812 ;; | bm |
|
|
813 ;; |--------|
|
|
814
|
|
815 (defvar ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
|
|
816 "*Bottom margin in points (1/72 inch).")
|
|
817
|
|
818 (defvar ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
|
|
819 "*Top margin in points (1/72 inch).")
|
|
820
|
|
821 (defvar ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
|
|
822 "*Vertical space in points (1/72 inch) between the main text and the header.")
|
|
823
|
|
824 (defvar ps-header-line-pad 0.15
|
|
825 "*Portion of a header title line height to insert between the header frame
|
|
826 and the text it contains, both in the vertical and horizontal directions.")
|
|
827
|
|
828 ;;; Header setup
|
0
|
829
|
|
830 (defvar ps-print-header t
|
|
831 "*Non-nil means print a header at the top of each page.
|
|
832 By default, the header displays the buffer name, page number, and, if
|
|
833 the buffer is visiting a file, the file's directory. Headers are
|
|
834 customizable by changing variables `ps-header-left' and
|
|
835 `ps-header-right'.")
|
|
836
|
|
837 (defvar ps-print-header-frame t
|
|
838 "*Non-nil means draw a gaudy frame around the header.")
|
|
839
|
82
|
840 (defvar ps-header-lines 2
|
|
841 "*Number of lines to display in page header, when generating Postscript.")
|
|
842 (make-variable-buffer-local 'ps-header-lines)
|
|
843
|
0
|
844 (defvar ps-show-n-of-n t
|
|
845 "*Non-nil means show page numbers as N/M, meaning page N of M.
|
|
846 Note: page numbers are displayed as part of headers, see variable
|
|
847 `ps-print-headers'.")
|
|
848
|
82
|
849 (defvar ps-spool-duplex nil ; Not many people have duplex
|
|
850 ; printers, so default to nil.
|
|
851 "*Non-nil indicates spooling is for a two-sided printer.
|
|
852 For a duplex printer, the `ps-spool-*' commands will insert blank pages
|
|
853 as needed between print jobs so that the next buffer printed will
|
|
854 start on the right page. Also, if headers are turned on, the headers
|
|
855 will be reversed on duplex printers so that the page numbers fall to
|
|
856 the left on even-numbered pages.")
|
|
857
|
|
858 ;;; Fonts
|
|
859
|
|
860 (defvar ps-font-info-database
|
|
861 '((Courier ; the family key
|
|
862 "Courier" "Courier-Bold" "Courier-Oblique" "Courier-BoldOblique"
|
|
863 10.0 10.55 6.0 6.0)
|
|
864 (Helvetica ; the family key
|
|
865 "Helvetica" "Helvetica-Bold" "Helvetica-Oblique" "Helvetica-BoldOblique"
|
|
866 10.0 11.56 2.78 5.09243)
|
|
867 (Times
|
|
868 "Times-Roman" "Times-Bold" "Times-Italic" "Times-BoldItalic"
|
|
869 10.0 11.0 2.5 4.71432)
|
|
870 (Palatino
|
|
871 "Palatino-Roman" "Palatino-Bold" "Palatino-Italic" "Palatino-BoldItalic"
|
|
872 10.0 12.1 2.5 5.08676)
|
|
873 (Helvetica-Narrow
|
|
874 "Helvetica-Narrow" "Helvetica-Narrow-Bold"
|
|
875 "Helvetica-Narrow-Oblique" "Helvetica-Narrow-BoldOblique"
|
|
876 10.0 11.56 2.2796 4.17579)
|
|
877 (NewCenturySchlbk
|
|
878 "NewCenturySchlbk-Roman" "NewCenturySchlbk-Bold"
|
|
879 "NewCenturySchlbk-Italic" "NewCenturySchlbk-BoldItalic"
|
|
880 10.0 12.15 2.78 5.31162)
|
|
881 ;; got no bold for the next ones
|
|
882 (AvantGarde-Book
|
|
883 "AvantGarde-Book" "AvantGarde-Book"
|
|
884 "AvantGarde-BookOblique" "AvantGarde-BookOblique"
|
|
885 10.0 11.77 2.77 5.45189)
|
|
886 (AvantGarde-Demi
|
|
887 "AvantGarde-Demi" "AvantGarde-Demi"
|
|
888 "AvantGarde-DemiOblique" "AvantGarde-DemiOblique"
|
|
889 10.0 12.72 2.8 5.51351)
|
|
890 (Bookman-Demi
|
|
891 "Bookman-Demi" "Bookman-Demi"
|
|
892 "Bookman-DemiItalic" "Bookman-DemiItalic"
|
|
893 10.0 11.77 3.4 6.05946)
|
|
894 (Bookman-Light
|
|
895 "Bookman-Light" "Bookman-Light"
|
|
896 "Bookman-LightItalic" "Bookman-LightItalic"
|
|
897 10.0 11.79 3.2 5.67027)
|
|
898 ;; got no bold and no italic for the next ones
|
|
899 (Symbol
|
|
900 "Symbol" "Symbol" "Symbol" "Symbol"
|
|
901 10.0 13.03 2.5 3.24324)
|
|
902 (Zapf-Dingbats
|
|
903 "Zapf-Dingbats" "Zapf-Dingbats" "Zapf-Dingbats" "Zapf-Dingbats"
|
|
904 10.0 9.63 2.78 2.78)
|
|
905 (Zapf-Chancery-MediumItalic
|
|
906 "Zapf-Chancery-MediumItalic" "Zapf-Chancery-MediumItalic"
|
|
907 "Zapf-Chancery-MediumItalic" "Zapf-Chancery-MediumItalic"
|
|
908 10.0 11.45 2.2 4.10811)
|
|
909 )
|
|
910 "*Font info database: font family (the key), name, bold, italic, bold-italic,
|
|
911 reference size, line height, space width, average character width.
|
|
912 To get the info for another specific font (say Helvetica), do the following:
|
|
913 - create a new buffer
|
|
914 - generate the PostScript image to a file (C-u M-x ps-print-buffer)
|
|
915 - open this file and delete the leading `%' (which is the Postscript
|
|
916 comment character) from the line
|
|
917 `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
|
|
918 to get the line
|
|
919 `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
|
|
920 - add the values to `ps-font-info-database'.
|
|
921 You can get all the fonts of YOUR printer using `ReportAllFontInfo'.")
|
|
922
|
|
923 (defvar ps-font-family 'Courier
|
|
924 "Font family name for ordinary text, when generating Postscript.")
|
|
925
|
|
926 (defvar ps-font-size (if ps-landscape-mode 7 8.5)
|
|
927 "Font size, in points, for ordinary text, when generating Postscript.")
|
|
928
|
|
929 (defvar ps-header-font-family 'Helvetica
|
|
930 "Font family name for text in the header, when generating Postscript.")
|
|
931
|
|
932 (defvar ps-header-font-size (if ps-landscape-mode 10 12)
|
|
933 "Font size, in points, for text in the header, when generating Postscript.")
|
|
934
|
|
935 (defvar ps-header-title-font-size (if ps-landscape-mode 12 14)
|
|
936 "Font size, in points, for the top line of text in the header,
|
|
937 when generating Postscript.")
|
|
938
|
|
939 ;;; Colors
|
|
940
|
0
|
941 ;;;###autoload
|
2
|
942 ;;; The 19.33 fsf version includes a test on pixel components instead
|
|
943 ;;; of color-instance-rgb-components
|
82
|
944 (defvar ps-print-color-p (or (fboundp 'x-color-values) ; fsf
|
|
945 (fboundp 'color-instance-rgb-components))
|
0
|
946 ; xemacs
|
82
|
947 ; Printing color requires x-color-values.
|
0
|
948 "*If non-nil, print the buffer's text in color.")
|
|
949
|
|
950 (defvar ps-default-fg '(0.0 0.0 0.0)
|
|
951 "*RGB values of the default foreground color. Defaults to black.")
|
|
952
|
|
953 (defvar ps-default-bg '(1.0 1.0 1.0)
|
|
954 "*RGB values of the default background color. Defaults to white.")
|
|
955
|
|
956 (defvar ps-auto-font-detect t
|
|
957 "*Non-nil means automatically detect bold/italic face attributes.
|
|
958 nil means rely solely on the lists `ps-bold-faces', `ps-italic-faces',
|
|
959 and `ps-underlined-faces'.")
|
|
960
|
82
|
961 (defvar ps-bold-faces
|
|
962 (unless ps-print-color-p
|
|
963 '(font-lock-function-name-face
|
|
964 font-lock-builtin-face
|
|
965 font-lock-variable-name-face
|
|
966 font-lock-keyword-face
|
|
967 font-lock-warning-face))
|
0
|
968 "*A list of the \(non-bold\) faces that should be printed in bold font.
|
|
969 This applies to generating Postscript.")
|
|
970
|
82
|
971 (defvar ps-italic-faces
|
|
972 (unless ps-print-color-p
|
|
973 '(font-lock-variable-name-face
|
|
974 font-lock-string-face
|
|
975 font-lock-comment-face
|
|
976 font-lock-warning-face))
|
0
|
977 "*A list of the \(non-italic\) faces that should be printed in italic font.
|
|
978 This applies to generating Postscript.")
|
|
979
|
82
|
980 (defvar ps-underlined-faces
|
|
981 (unless ps-print-color-p
|
|
982 '(font-lock-function-name-face
|
|
983 font-lock-type-face
|
|
984 font-lock-reference-face
|
|
985 font-lock-warning-face))
|
0
|
986 "*A list of the \(non-underlined\) faces that should be printed underlined.
|
|
987 This applies to generating Postscript.")
|
|
988
|
|
989 (defvar ps-left-header
|
|
990 (list 'ps-get-buffer-name 'ps-header-dirpart)
|
82
|
991 "*The items to display (each on a line) on the left part of the page header.
|
0
|
992 This applies to generating Postscript.
|
|
993
|
|
994 The value should be a list of strings and symbols, each representing an
|
|
995 entry in the PostScript array HeaderLinesLeft.
|
|
996
|
|
997 Strings are inserted unchanged into the array; those representing
|
|
998 PostScript string literals should be delimited with PostScript string
|
|
999 delimiters '(' and ')'.
|
|
1000
|
|
1001 For symbols with bound functions, the function is called and should
|
|
1002 return a string to be inserted into the array. For symbols with bound
|
|
1003 values, the value should be a string to be inserted into the array.
|
|
1004 In either case, function or variable, the string value has PostScript
|
|
1005 string delimiters added to it.")
|
|
1006 (make-variable-buffer-local 'ps-left-header)
|
|
1007
|
|
1008 (defvar ps-right-header
|
82
|
1009 (list "/pagenumberstring load" 'time-stamp-mon-dd-yyyy 'time-stamp-hh:mm:ss)
|
|
1010 "*The items to display (each on a line) on the right part of the page header.
|
0
|
1011 This applies to generating Postscript.
|
|
1012
|
|
1013 See the variable `ps-left-header' for a description of the format of
|
|
1014 this variable.")
|
|
1015 (make-variable-buffer-local 'ps-right-header)
|
|
1016
|
|
1017 (defvar ps-razzle-dazzle t
|
|
1018 "*Non-nil means report progress while formatting buffer.")
|
|
1019
|
88
|
1020 (defvar ps-adobe-tag "%!PS-Adobe-3.0\n"
|
0
|
1021 "*Contains the header line identifying the output as PostScript.
|
|
1022 By default, `ps-adobe-tag' contains the standard identifier. Some
|
|
1023 printers require slightly different versions of this line.")
|
|
1024
|
|
1025 (defvar ps-build-face-reference t
|
|
1026 "*Non-nil means build the reference face lists.
|
|
1027
|
|
1028 Ps-print sets this value to nil after it builds its internal reference
|
|
1029 lists of bold and italic faces. By settings its value back to t, you
|
|
1030 can force ps-print to rebuild the lists the next time you invoke one
|
|
1031 of the ...-with-faces commands.
|
|
1032
|
|
1033 You should set this value back to t after you change the attributes of
|
|
1034 any face, or create new faces. Most users shouldn't have to worry
|
|
1035 about its setting, though.")
|
|
1036
|
|
1037 (defvar ps-always-build-face-reference nil
|
|
1038 "*Non-nil means always rebuild the reference face lists.
|
|
1039
|
|
1040 If this variable is non-nil, ps-print will rebuild its internal
|
|
1041 reference lists of bold and italic faces *every* time one of the
|
|
1042 -with-faces commands is called. Most users shouldn't need to set this
|
|
1043 variable.")
|
|
1044
|
|
1045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1046 ;; User commands
|
|
1047
|
|
1048 ;;;###autoload
|
|
1049 (defun ps-print-buffer (&optional filename)
|
|
1050 "Generate and print a PostScript image of the buffer.
|
|
1051
|
|
1052 When called with a numeric prefix argument (C-u), prompts the user for
|
|
1053 the name of a file to save the PostScript image in, instead of sending
|
|
1054 it to the printer.
|
|
1055
|
|
1056 More specifically, the FILENAME argument is treated as follows: if it
|
|
1057 is nil, send the image to the printer. If FILENAME is a string, save
|
|
1058 the PostScript image in a file with that name. If FILENAME is a
|
|
1059 number, prompt the user for the name of the file to save in."
|
|
1060
|
|
1061 (interactive (list (ps-print-preprint current-prefix-arg)))
|
|
1062 (ps-generate (current-buffer) (point-min) (point-max)
|
|
1063 'ps-generate-postscript)
|
|
1064 (ps-do-despool filename))
|
|
1065
|
|
1066
|
|
1067 ;;;###autoload
|
|
1068 (defun ps-print-buffer-with-faces (&optional filename)
|
|
1069 "Generate and print a PostScript image of the buffer.
|
|
1070 Like `ps-print-buffer', but includes font, color, and underline
|
2
|
1071 information in the generated image. This command works only if you
|
|
1072 are using a window system, so it has a way to determine color values."
|
0
|
1073 (interactive (list (ps-print-preprint current-prefix-arg)))
|
|
1074 (ps-generate (current-buffer) (point-min) (point-max)
|
|
1075 'ps-generate-postscript-with-faces)
|
|
1076 (ps-do-despool filename))
|
|
1077
|
|
1078
|
|
1079 ;;;###autoload
|
|
1080 (defun ps-print-region (from to &optional filename)
|
|
1081 "Generate and print a PostScript image of the region.
|
|
1082 Like `ps-print-buffer', but prints just the current region."
|
|
1083
|
|
1084 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
|
|
1085 (ps-generate (current-buffer) from to
|
|
1086 'ps-generate-postscript)
|
|
1087 (ps-do-despool filename))
|
|
1088
|
|
1089
|
|
1090 ;;;###autoload
|
|
1091 (defun ps-print-region-with-faces (from to &optional filename)
|
|
1092 "Generate and print a PostScript image of the region.
|
|
1093 Like `ps-print-region', but includes font, color, and underline
|
2
|
1094 information in the generated image. This command works only if you
|
|
1095 are using a window system, so it has a way to determine color values."
|
0
|
1096
|
|
1097 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
|
|
1098 (ps-generate (current-buffer) from to
|
|
1099 'ps-generate-postscript-with-faces)
|
|
1100 (ps-do-despool filename))
|
|
1101
|
|
1102
|
|
1103 ;;;###autoload
|
|
1104 (defun ps-spool-buffer ()
|
|
1105 "Generate and spool a PostScript image of the buffer.
|
|
1106 Like `ps-print-buffer' except that the PostScript image is saved in a
|
|
1107 local buffer to be sent to the printer later.
|
|
1108
|
|
1109 Use the command `ps-despool' to send the spooled images to the printer."
|
|
1110 (interactive)
|
|
1111 (ps-generate (current-buffer) (point-min) (point-max)
|
|
1112 'ps-generate-postscript))
|
|
1113
|
|
1114
|
|
1115 ;;;###autoload
|
|
1116 (defun ps-spool-buffer-with-faces ()
|
|
1117 "Generate and spool a PostScript image of the buffer.
|
|
1118 Like `ps-spool-buffer', but includes font, color, and underline
|
2
|
1119 information in the generated image. This command works only if you
|
|
1120 are using a window system, so it has a way to determine color values.
|
0
|
1121
|
|
1122 Use the command `ps-despool' to send the spooled images to the printer."
|
|
1123
|
|
1124 (interactive)
|
|
1125 (ps-generate (current-buffer) (point-min) (point-max)
|
|
1126 'ps-generate-postscript-with-faces))
|
|
1127
|
|
1128
|
|
1129 ;;;###autoload
|
|
1130 (defun ps-spool-region (from to)
|
|
1131 "Generate a PostScript image of the region and spool locally.
|
|
1132 Like `ps-spool-buffer', but spools just the current region.
|
|
1133
|
|
1134 Use the command `ps-despool' to send the spooled images to the printer."
|
|
1135 (interactive "r")
|
|
1136 (ps-generate (current-buffer) from to
|
|
1137 'ps-generate-postscript))
|
|
1138
|
|
1139
|
|
1140 ;;;###autoload
|
|
1141 (defun ps-spool-region-with-faces (from to)
|
|
1142 "Generate a PostScript image of the region and spool locally.
|
|
1143 Like `ps-spool-region', but includes font, color, and underline
|
2
|
1144 information in the generated image. This command works only if you
|
|
1145 are using a window system, so it has a way to determine color values.
|
0
|
1146
|
|
1147 Use the command `ps-despool' to send the spooled images to the printer."
|
|
1148 (interactive "r")
|
|
1149 (ps-generate (current-buffer) from to
|
|
1150 'ps-generate-postscript-with-faces))
|
|
1151
|
|
1152 ;;;###autoload
|
|
1153 (defun ps-despool (&optional filename)
|
|
1154 "Send the spooled PostScript to the printer.
|
|
1155
|
|
1156 When called with a numeric prefix argument (C-u), prompt the user for
|
|
1157 the name of a file to save the spooled PostScript in, instead of sending
|
|
1158 it to the printer.
|
|
1159
|
|
1160 More specifically, the FILENAME argument is treated as follows: if it
|
|
1161 is nil, send the image to the printer. If FILENAME is a string, save
|
|
1162 the PostScript image in a file with that name. If FILENAME is a
|
|
1163 number, prompt the user for the name of the file to save in."
|
|
1164 (interactive (list (ps-print-preprint current-prefix-arg)))
|
|
1165 (ps-do-despool filename))
|
|
1166
|
82
|
1167 ;;;###autoload
|
|
1168 (defun ps-line-lengths ()
|
88
|
1169 "*Display the correspondence between a line length and a font size,
|
82
|
1170 using the current ps-print setup.
|
|
1171 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
|
|
1172 (interactive)
|
|
1173 (ps-line-lengths-internal))
|
|
1174
|
|
1175 ;;;###autoload
|
|
1176 (defun ps-nb-pages-buffer (nb-lines)
|
88
|
1177 "*Display an approximate correspondence between a font size and the number
|
82
|
1178 of pages the current buffer would require to print
|
|
1179 using the current ps-print setup."
|
|
1180 (interactive (list (count-lines (point-min) (point-max))))
|
|
1181 (ps-nb-pages nb-lines))
|
|
1182
|
|
1183 ;;;###autoload
|
|
1184 (defun ps-nb-pages-region (nb-lines)
|
88
|
1185 "*Display an approximate correspondence between a font size and the number
|
82
|
1186 of pages the current region would require to print
|
|
1187 using the current ps-print setup."
|
|
1188 (interactive (list (count-lines (mark) (point))))
|
|
1189 (ps-nb-pages nb-lines))
|
|
1190
|
|
1191 ;;;###autoload
|
|
1192 (defun ps-setup ()
|
|
1193 "*Return the current setup"
|
|
1194 (format "
|
|
1195 (setq ps-print-color-p %s
|
|
1196 ps-lpr-command \"%s\"
|
|
1197 ps-lpr-switches %s
|
|
1198
|
|
1199 ps-paper-type '%s
|
|
1200 ps-landscape-mode %s
|
|
1201 ps-number-of-columns %s
|
|
1202
|
|
1203 ps-left-margin %s
|
|
1204 ps-right-margin %s
|
|
1205 ps-inter-column %s
|
|
1206 ps-bottom-margin %s
|
|
1207 ps-top-margin %s
|
|
1208 ps-header-offset %s
|
|
1209 ps-header-line-pad %s
|
|
1210 ps-print-header %s
|
|
1211 ps-print-header-frame %s
|
|
1212 ps-header-lines %s
|
|
1213 ps-show-n-of-n %s
|
|
1214 ps-spool-duplex %s
|
|
1215
|
|
1216 ps-font-family '%s
|
|
1217 ps-font-size %s
|
|
1218 ps-header-font-family '%s
|
|
1219 ps-header-font-size %s
|
|
1220 ps-header-title-font-size %s)
|
|
1221 "
|
|
1222 ps-print-color-p
|
|
1223 ps-lpr-command
|
|
1224 ps-lpr-switches
|
|
1225 ps-paper-type
|
|
1226 ps-landscape-mode
|
|
1227 ps-number-of-columns
|
|
1228 ps-left-margin
|
|
1229 ps-right-margin
|
|
1230 ps-inter-column
|
|
1231 ps-bottom-margin
|
|
1232 ps-top-margin
|
|
1233 ps-header-offset
|
|
1234 ps-header-line-pad
|
|
1235 ps-print-header
|
|
1236 ps-print-header-frame
|
|
1237 ps-header-lines
|
|
1238 ps-show-n-of-n
|
|
1239 ps-spool-duplex
|
|
1240 ps-font-family
|
|
1241 ps-font-size
|
|
1242 ps-header-font-family
|
|
1243 ps-header-font-size
|
|
1244 ps-header-title-font-size))
|
|
1245
|
0
|
1246 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1247 ;; Utility functions and variables:
|
|
1248
|
|
1249 (defvar ps-print-emacs-type
|
|
1250 (cond ((string-match "XEmacs" emacs-version) 'xemacs)
|
|
1251 ((string-match "Lucid" emacs-version) 'lucid)
|
|
1252 ((string-match "Epoch" emacs-version) 'epoch)
|
|
1253 (t 'emacs)))
|
|
1254
|
|
1255 (if (or (eq ps-print-emacs-type 'lucid)
|
|
1256 (eq ps-print-emacs-type 'xemacs))
|
|
1257 (if (< emacs-minor-version 12)
|
|
1258 (setq ps-print-color-p nil))
|
|
1259 (require 'faces)) ; face-font, face-underline-p,
|
|
1260 ; x-font-regexp
|
|
1261
|
82
|
1262 ;; Return t if the device (which can be changed during an emacs
|
|
1263 ;; session) can handle colors.
|
|
1264 ;; This is function is not yet implemented for GNU emacs.
|
|
1265 (defun ps-color-device ()
|
0
|
1266 (if (and (eq ps-print-emacs-type 'xemacs)
|
|
1267 (>= emacs-minor-version 12))
|
|
1268 (eq (device-class) 'color)
|
|
1269 t))
|
|
1270
|
|
1271 (require 'time-stamp)
|
|
1272
|
82
|
1273 (defvar ps-font nil
|
|
1274 "Font family name for ordinary text, when generating Postscript.")
|
|
1275
|
|
1276 (defvar ps-font-bold nil
|
|
1277 "Font family name for bold text, when generating Postscript.")
|
|
1278
|
|
1279 (defvar ps-font-italic nil
|
|
1280 "Font family name for italic text, when generating Postscript.")
|
|
1281
|
|
1282 (defvar ps-font-bold-italic nil
|
|
1283 "Font family name for bold italic text, when generating Postscript.")
|
|
1284
|
|
1285 (defvar ps-avg-char-width nil
|
|
1286 "The average width, in points, of a character, for generating Postscript.
|
|
1287 This is the value that ps-print uses to determine the length,
|
|
1288 x-dimension, of the text it has printed, and thus affects the point at
|
|
1289 which long lines wrap around.")
|
|
1290
|
|
1291 (defvar ps-space-width nil
|
|
1292 "The width of a space character, for generating Postscript.
|
|
1293 This value is used in expanding tab characters.")
|
|
1294
|
|
1295 (defvar ps-line-height nil
|
|
1296 "The height of a line, for generating Postscript.
|
|
1297 This is the value that ps-print uses to determine the height,
|
|
1298 y-dimension, of the lines of text it has printed, and thus affects the
|
|
1299 point at which page-breaks are placed.
|
|
1300 The line-height is *not* the same as the point size of the font.")
|
|
1301
|
|
1302 (defvar ps-print-prologue-1
|
|
1303 "% ISOLatin1Encoding stolen from ps_init.ps in GhostScript 2.6.1.4:
|
0
|
1304 /ISOLatin1Encoding where { pop } {
|
82
|
1305 % -- The ISO Latin-1 encoding vector isn't known, so define it.
|
|
1306 % -- The first half is the same as the standard encoding,
|
|
1307 % -- except for minus instead of hyphen at code 055.
|
0
|
1308 /ISOLatin1Encoding
|
|
1309 StandardEncoding 0 45 getinterval aload pop
|
|
1310 /minus
|
|
1311 StandardEncoding 46 82 getinterval aload pop
|
|
1312 %*** NOTE: the following are missing in the Adobe documentation,
|
|
1313 %*** but appear in the displayed table:
|
|
1314 %*** macron at 0225, dieresis at 0230, cedilla at 0233, space at 0240.
|
82
|
1315 % 0200 (128)
|
0
|
1316 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
|
|
1317 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
|
|
1318 /dotlessi /grave /acute /circumflex /tilde /macron /breve /dotaccent
|
|
1319 /dieresis /.notdef /ring /cedilla /.notdef /hungarumlaut /ogonek /caron
|
82
|
1320 % 0240 (160)
|
0
|
1321 /space /exclamdown /cent /sterling
|
|
1322 /currency /yen /brokenbar /section
|
|
1323 /dieresis /copyright /ordfeminine /guillemotleft
|
|
1324 /logicalnot /hyphen /registered /macron
|
|
1325 /degree /plusminus /twosuperior /threesuperior
|
|
1326 /acute /mu /paragraph /periodcentered
|
|
1327 /cedilla /onesuperior /ordmasculine /guillemotright
|
|
1328 /onequarter /onehalf /threequarters /questiondown
|
82
|
1329 % 0300 (192)
|
0
|
1330 /Agrave /Aacute /Acircumflex /Atilde
|
|
1331 /Adieresis /Aring /AE /Ccedilla
|
|
1332 /Egrave /Eacute /Ecircumflex /Edieresis
|
|
1333 /Igrave /Iacute /Icircumflex /Idieresis
|
|
1334 /Eth /Ntilde /Ograve /Oacute
|
|
1335 /Ocircumflex /Otilde /Odieresis /multiply
|
|
1336 /Oslash /Ugrave /Uacute /Ucircumflex
|
|
1337 /Udieresis /Yacute /Thorn /germandbls
|
82
|
1338 % 0340 (224)
|
0
|
1339 /agrave /aacute /acircumflex /atilde
|
|
1340 /adieresis /aring /ae /ccedilla
|
|
1341 /egrave /eacute /ecircumflex /edieresis
|
|
1342 /igrave /iacute /icircumflex /idieresis
|
|
1343 /eth /ntilde /ograve /oacute
|
|
1344 /ocircumflex /otilde /odieresis /divide
|
|
1345 /oslash /ugrave /uacute /ucircumflex
|
|
1346 /udieresis /yacute /thorn /ydieresis
|
|
1347 256 packedarray def
|
|
1348 } ifelse
|
|
1349
|
|
1350 /reencodeFontISO { %def
|
|
1351 dup
|
82
|
1352 length 5 add dict % Make a new font (a new dict the same size
|
|
1353 % as the old one) with room for our new symbols.
|
|
1354
|
|
1355 begin % Make the new font the current dictionary.
|
0
|
1356
|
|
1357
|
|
1358 { 1 index /FID ne
|
|
1359 { def } { pop pop } ifelse
|
82
|
1360 } forall % Copy each of the symbols from the old dictionary
|
|
1361 % to the new one except for the font ID.
|
0
|
1362
|
|
1363 /Encoding ISOLatin1Encoding def % Override the encoding with
|
|
1364 % the ISOLatin1 encoding.
|
|
1365
|
|
1366 % Use the font's bounding box to determine the ascent, descent,
|
|
1367 % and overall height; don't forget that these values have to be
|
|
1368 % transformed using the font's matrix.
|
82
|
1369
|
|
1370 % ^ (x2 y2)
|
|
1371 % | |
|
|
1372 % | v
|
|
1373 % | +----+ - -
|
|
1374 % | | | ^
|
|
1375 % | | | | Ascent (usually > 0)
|
|
1376 % | | | |
|
|
1377 % (0 0) -> +--+----+-------->
|
|
1378 % | | |
|
|
1379 % | | v Descent (usually < 0)
|
|
1380 % (x1 y1) --> +----+ - -
|
|
1381
|
|
1382 FontBBox % -- x1 y1 x2 y2
|
|
1383 FontMatrix transform /Ascent exch def pop
|
70
|
1384 FontMatrix transform /Descent exch def pop
|
82
|
1385 /FontHeight Ascent Descent sub def % use `sub' because descent < 0
|
|
1386
|
|
1387 % Define these in case they're not in the FontInfo
|
|
1388 % (also, here they're easier to get to.
|
|
1389 /UnderlinePosition 1 def
|
0
|
1390 /UnderlineThickness 1 def
|
|
1391
|
|
1392 % Get the underline position and thickness if they're defined.
|
|
1393 currentdict /FontInfo known {
|
|
1394 FontInfo
|
|
1395
|
|
1396 dup /UnderlinePosition known {
|
|
1397 dup /UnderlinePosition get
|
|
1398 0 exch FontMatrix transform exch pop
|
|
1399 /UnderlinePosition exch def
|
|
1400 } if
|
|
1401
|
|
1402 dup /UnderlineThickness known {
|
|
1403 /UnderlineThickness get
|
|
1404 0 exch FontMatrix transform exch pop
|
|
1405 /UnderlineThickness exch def
|
|
1406 } if
|
|
1407
|
|
1408 } if
|
|
1409
|
82
|
1410 currentdict % Leave the new font on the stack
|
|
1411 end % Stop using the font as the current dictionary.
|
|
1412 definefont % Put the font into the font dictionary
|
|
1413 pop % Discard the returned font.
|
0
|
1414 } bind def
|
|
1415
|
82
|
1416 /DefFont { % Font definition
|
0
|
1417 findfont exch scalefont reencodeFontISO
|
|
1418 } def
|
|
1419
|
82
|
1420 /F { % Font selection
|
0
|
1421 findfont
|
82
|
1422 dup /Ascent get /Ascent exch def
|
|
1423 dup /Descent get /Descent exch def
|
|
1424 dup /FontHeight get /FontHeight exch def
|
|
1425 dup /UnderlinePosition get /UnderlinePosition exch def
|
0
|
1426 dup /UnderlineThickness get /UnderlineThickness exch def
|
|
1427 setfont
|
|
1428 } def
|
|
1429
|
|
1430 /FG /setrgbcolor load def
|
|
1431
|
|
1432 /bg false def
|
|
1433 /BG {
|
|
1434 dup /bg exch def
|
|
1435 { mark 4 1 roll ] /bgcolor exch def } if
|
|
1436 } def
|
|
1437
|
82
|
1438 % B width C
|
|
1439 % +-----------+
|
|
1440 % | Ascent (usually > 0)
|
|
1441 % A + +
|
|
1442 % | Descent (usually < 0)
|
|
1443 % +-----------+
|
|
1444 % E width D
|
|
1445
|
0
|
1446 /dobackground { % width --
|
82
|
1447 currentpoint % -- width x y
|
0
|
1448 gsave
|
|
1449 newpath
|
82
|
1450 moveto % A (x y)
|
|
1451 0 Ascent rmoveto % B
|
|
1452 dup 0 rlineto % C
|
|
1453 0 Descent Ascent sub rlineto % D
|
|
1454 neg 0 rlineto % E
|
0
|
1455 closepath
|
|
1456 bgcolor aload pop setrgbcolor
|
|
1457 fill
|
|
1458 grestore
|
|
1459 } def
|
|
1460
|
|
1461 /dobackgroundstring { % string --
|
|
1462 stringwidth pop
|
|
1463 dobackground
|
|
1464 } def
|
|
1465
|
|
1466 /dounderline { % fromx fromy --
|
|
1467 currentpoint
|
|
1468 gsave
|
|
1469 UnderlineThickness setlinewidth
|
|
1470 4 2 roll
|
|
1471 UnderlinePosition add moveto
|
|
1472 UnderlinePosition add lineto
|
|
1473 stroke
|
|
1474 grestore
|
|
1475 } def
|
|
1476
|
82
|
1477 /eolbg { % dobackground until right margin
|
|
1478 PrintWidth % -- x-eol
|
|
1479 currentpoint pop % -- cur-x
|
|
1480 sub % -- width until eol
|
|
1481 dobackground
|
0
|
1482 } def
|
|
1483
|
82
|
1484 /eolul { % idem for underline
|
|
1485 PrintWidth % -- x-eol
|
|
1486 currentpoint exch pop % -- x-eol cur-y
|
|
1487 dounderline
|
0
|
1488 } def
|
|
1489
|
|
1490 /SL { % Soft Linefeed
|
|
1491 bg { eolbg } if
|
|
1492 ul { eolul } if
|
82
|
1493 0 currentpoint exch pop LineHeight sub moveto
|
0
|
1494 } def
|
|
1495
|
|
1496 /HL /SL load def % Hard Linefeed
|
|
1497
|
|
1498 /sp1 { currentpoint 3 -1 roll } def
|
|
1499
|
|
1500 % Some debug
|
|
1501 /dcp { currentpoint exch 40 string cvs print (, ) print = } def
|
|
1502 /dp { print 2 copy
|
|
1503 exch 40 string cvs print (, ) print = } def
|
|
1504
|
|
1505 /S {
|
|
1506 bg { dup dobackgroundstring } if
|
|
1507 ul { sp1 } if
|
|
1508 show
|
|
1509 ul { dounderline } if
|
|
1510 } def
|
|
1511
|
|
1512 /W {
|
|
1513 ul { sp1 } if
|
82
|
1514 ( ) stringwidth % Get the width of a space in the current font.
|
|
1515 pop % Discard the Y component.
|
|
1516 mul % Multiply the width of a space
|
|
1517 % by the number of spaces to plot
|
0
|
1518 bg { dup dobackground } if
|
|
1519 0 rmoveto
|
|
1520 ul { dounderline } if
|
|
1521 } def
|
|
1522
|
82
|
1523 /BeginDoc {
|
|
1524 % ---- save the state of the document (useful for ghostscript!)
|
|
1525 /docState save def
|
|
1526 % ---- [jack] Kludge: my ghostscript window is 21x27.7 instead of 21x29.7
|
|
1527 /JackGhostscript where {
|
|
1528 pop 1 27.7 29.7 div scale
|
|
1529 } if
|
|
1530 LandscapeMode {
|
|
1531 % ---- translate to bottom-right corner of Portrait page
|
|
1532 LandscapePageHeight 0 translate
|
|
1533 90 rotate
|
|
1534 } if
|
|
1535 /ColumnWidth PrintWidth InterColumn add def
|
|
1536 % ---- translate to lower left corner of TEXT
|
|
1537 LeftMargin BottomMargin translate
|
|
1538 % ---- define where printing will start
|
|
1539 /f0 F % this installs Ascent
|
|
1540 /PrintStartY PrintHeight Ascent sub def
|
|
1541 /ColumnIndex 1 def
|
|
1542 } def
|
|
1543
|
|
1544 /EndDoc {
|
|
1545 % ---- on last page but not last column, spit out the page
|
|
1546 ColumnIndex 1 eq not { showpage } if
|
|
1547 % ---- restore the state of the document (useful for ghostscript!)
|
|
1548 docState restore
|
|
1549 } def
|
|
1550
|
0
|
1551 /BeginDSCPage {
|
82
|
1552 % ---- when 1st column, save the state of the page
|
|
1553 ColumnIndex 1 eq { /pageState save def } if
|
|
1554 % ---- save the state of the column
|
|
1555 /columnState save def
|
0
|
1556 } def
|
|
1557
|
|
1558 /BeginPage {
|
|
1559 PrintHeader {
|
|
1560 PrintHeaderFrame { HeaderFrame } if
|
|
1561 HeaderText
|
|
1562 } if
|
82
|
1563 0 PrintStartY moveto % move to where printing will start
|
0
|
1564 } def
|
|
1565
|
|
1566 /EndPage {
|
|
1567 bg { eolbg } if
|
|
1568 ul { eolul } if
|
|
1569 } def
|
|
1570
|
|
1571 /EndDSCPage {
|
82
|
1572 ColumnIndex NumberOfColumns eq {
|
|
1573 % ---- on last column, spit out the page
|
|
1574 showpage
|
|
1575 % ---- restore the state of the page
|
|
1576 pageState restore
|
|
1577 /ColumnIndex 1 def
|
|
1578 } { % else
|
|
1579 % ---- restore the state of the current column
|
|
1580 columnState restore
|
|
1581 % ---- and translate to the next column
|
|
1582 ColumnWidth 0 translate
|
|
1583 /ColumnIndex ColumnIndex 1 add def
|
|
1584 } ifelse
|
0
|
1585 } def
|
|
1586
|
|
1587 /ul false def
|
|
1588
|
|
1589 /UL { /ul exch def } def
|
|
1590
|
82
|
1591 /SetHeaderLines { % nb-lines --
|
0
|
1592 /HeaderLines exch def
|
82
|
1593 % ---- bottom up
|
|
1594 HeaderPad
|
|
1595 HeaderLines 1 sub HeaderLineHeight mul add
|
|
1596 HeaderTitleLineHeight add
|
|
1597 HeaderPad add
|
|
1598 /HeaderHeight exch def
|
0
|
1599 } def
|
|
1600
|
82
|
1601 % |---------|
|
|
1602 % | tm |
|
|
1603 % |---------|
|
|
1604 % | header |
|
|
1605 % |-+-------| <-- (x y)
|
|
1606 % | ho |
|
|
1607 % |---------|
|
|
1608 % | text |
|
|
1609 % |-+-------| <-- (0 0)
|
|
1610 % | bm |
|
|
1611 % |---------|
|
|
1612
|
|
1613 /HeaderFrameStart { % -- x y
|
|
1614 0 PrintHeight HeaderOffset add
|
0
|
1615 } def
|
|
1616
|
|
1617 /HeaderFramePath {
|
82
|
1618 PrintWidth 0 rlineto
|
|
1619 0 HeaderHeight rlineto
|
|
1620 PrintWidth neg 0 rlineto
|
|
1621 0 HeaderHeight neg rlineto
|
0
|
1622 } def
|
|
1623
|
|
1624 /HeaderFrame {
|
|
1625 gsave
|
|
1626 0.4 setlinewidth
|
82
|
1627 % ---- fill a black rectangle (the shadow of the next one)
|
0
|
1628 HeaderFrameStart moveto
|
|
1629 1 -1 rmoveto
|
|
1630 HeaderFramePath
|
|
1631 0 setgray fill
|
82
|
1632 % ---- do the next rectangle ...
|
0
|
1633 HeaderFrameStart moveto
|
|
1634 HeaderFramePath
|
82
|
1635 gsave 0.9 setgray fill grestore % filled with grey
|
|
1636 gsave 0 setgray stroke grestore % drawn with black
|
0
|
1637 grestore
|
|
1638 } def
|
|
1639
|
|
1640 /HeaderStart {
|
|
1641 HeaderFrameStart
|
82
|
1642 exch HeaderPad add exch % horizontal pad
|
|
1643 % ---- bottom up
|
|
1644 HeaderPad add % vertical pad
|
|
1645 HeaderDescent sub
|
|
1646 HeaderLineHeight HeaderLines 1 sub mul add
|
0
|
1647 } def
|
|
1648
|
|
1649 /strcat {
|
|
1650 dup length 3 -1 roll dup length dup 4 -1 roll add string dup
|
|
1651 0 5 -1 roll putinterval
|
|
1652 dup 4 2 roll exch putinterval
|
|
1653 } def
|
|
1654
|
|
1655 /pagenumberstring {
|
|
1656 PageNumber 32 string cvs
|
|
1657 ShowNofN {
|
|
1658 (/) strcat
|
|
1659 PageCount 32 string cvs strcat
|
|
1660 } if
|
|
1661 } def
|
|
1662
|
|
1663 /HeaderText {
|
|
1664 HeaderStart moveto
|
|
1665
|
82
|
1666 HeaderLinesRight HeaderLinesLeft % -- rightLines leftLines
|
|
1667
|
|
1668 % ---- hack: `PN 1 and' == `PN 2 modulo'
|
|
1669
|
|
1670 % ---- if duplex and even page number, then exchange left and right
|
0
|
1671 Duplex PageNumber 1 and 0 eq and { exch } if
|
|
1672
|
82
|
1673 { % ---- process the left lines
|
0
|
1674 aload pop
|
|
1675 exch F
|
|
1676 gsave
|
|
1677 dup xcheck { exec } if
|
|
1678 show
|
|
1679 grestore
|
|
1680 0 HeaderLineHeight neg rmoveto
|
|
1681 } forall
|
|
1682
|
|
1683 HeaderStart moveto
|
|
1684
|
82
|
1685 { % ---- process the right lines
|
0
|
1686 aload pop
|
|
1687 exch F
|
|
1688 gsave
|
|
1689 dup xcheck { exec } if
|
|
1690 dup stringwidth pop
|
|
1691 PrintWidth exch sub HeaderPad 2 mul sub 0 rmoveto
|
|
1692 show
|
|
1693 grestore
|
|
1694 0 HeaderLineHeight neg rmoveto
|
|
1695 } forall
|
|
1696 } def
|
|
1697
|
|
1698 /ReportFontInfo {
|
|
1699 2 copy
|
82
|
1700 /t0 3 1 roll DefFont
|
0
|
1701 /t0 F
|
|
1702 /lh FontHeight def
|
|
1703 /sw ( ) stringwidth pop def
|
|
1704 /aw (01234567890abcdefghijklmnopqrstuvwxyz) dup length exch
|
|
1705 stringwidth pop exch div def
|
82
|
1706 /t1 12 /Helvetica-Oblique DefFont
|
0
|
1707 /t1 F
|
|
1708 gsave
|
|
1709 (For ) show
|
|
1710 128 string cvs show
|
|
1711 ( ) show
|
|
1712 32 string cvs show
|
|
1713 ( point, the line height is ) show
|
|
1714 lh 32 string cvs show
|
|
1715 (, the space width is ) show
|
|
1716 sw 32 string cvs show
|
|
1717 (,) show
|
|
1718 grestore
|
|
1719 0 FontHeight neg rmoveto
|
82
|
1720 gsave
|
|
1721 (and a crude estimate of average character width is ) show
|
|
1722 aw 32 string cvs show
|
|
1723 (.) show
|
|
1724 grestore
|
|
1725 0 FontHeight neg rmoveto
|
|
1726 } def
|
|
1727
|
|
1728 /cm { % cm to point
|
|
1729 72 mul 2.54 div
|
|
1730 } def
|
|
1731
|
|
1732 /ReportAllFontInfo {
|
|
1733 FontDirectory
|
|
1734 { % key = font name value = font dictionary
|
|
1735 pop 10 exch ReportFontInfo
|
|
1736 } forall
|
0
|
1737 } def
|
|
1738
|
82
|
1739 % 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage
|
|
1740 % 3 cm 20 cm moveto ReportAllFontInfo showpage
|
|
1741
|
|
1742 ")
|
|
1743
|
|
1744 (defvar ps-print-prologue-2
|
|
1745 "
|
|
1746 % ---- These lines must be kept together because...
|
|
1747
|
|
1748 /h0 F
|
|
1749 /HeaderTitleLineHeight FontHeight def
|
|
1750
|
|
1751 /h1 F
|
|
1752 /HeaderLineHeight FontHeight def
|
|
1753 /HeaderDescent Descent def
|
|
1754
|
|
1755 % ---- ...because `F' has a side-effect on `FontHeight' and `Descent'
|
|
1756
|
0
|
1757 ")
|
|
1758
|
|
1759 ;; Start Editing Here:
|
|
1760
|
|
1761 (defvar ps-source-buffer nil)
|
|
1762 (defvar ps-spool-buffer-name "*PostScript*")
|
|
1763 (defvar ps-spool-buffer nil)
|
|
1764
|
|
1765 (defvar ps-output-head nil)
|
|
1766 (defvar ps-output-tail nil)
|
|
1767
|
|
1768 (defvar ps-page-count 0)
|
|
1769 (defvar ps-showpage-count 0)
|
|
1770
|
|
1771 (defvar ps-current-font 0)
|
|
1772 (defvar ps-current-underline-p nil)
|
|
1773 (defvar ps-default-color (if ps-print-color-p ps-default-fg)) ; black
|
|
1774 (defvar ps-current-color ps-default-color)
|
|
1775 (defvar ps-current-bg nil)
|
|
1776
|
|
1777 (defvar ps-razchunk 0)
|
|
1778
|
82
|
1779 (defvar ps-color-format
|
|
1780 (if (eq ps-print-emacs-type 'emacs)
|
|
1781
|
|
1782 ;;Emacs understands the %f format; we'll
|
|
1783 ;;use it to limit color RGB values to
|
|
1784 ;;three decimals to cut down some on the
|
|
1785 ;;size of the PostScript output.
|
|
1786 "%0.3f %0.3f %0.3f"
|
|
1787
|
|
1788 ;; Lucid emacsen will have to make do with
|
|
1789 ;; %s (princ) for floats.
|
|
1790 "%s %s %s"))
|
0
|
1791
|
|
1792 ;; These values determine how much print-height to deduct when headers
|
|
1793 ;; are turned on. This is a pretty clumsy way of handling it, but
|
|
1794 ;; it'll do for now.
|
82
|
1795
|
|
1796 (defvar ps-header-font)
|
|
1797 (defvar ps-header-title-font)
|
|
1798
|
|
1799 (defvar ps-header-line-height)
|
|
1800 (defvar ps-header-title-line-height)
|
|
1801 (defvar ps-header-pad 0
|
|
1802 "Vertical and horizontal space in points (1/72 inch) between the header frame
|
|
1803 and the text it contains.")
|
|
1804
|
|
1805 ;; Define accessors to the dimensions list.
|
|
1806
|
|
1807 (defmacro ps-page-dimensions-get-width (dims) `(nth 0 ,dims))
|
|
1808 (defmacro ps-page-dimensions-get-height (dims) `(nth 1 ,dims))
|
|
1809
|
|
1810 (defvar ps-landscape-page-height)
|
|
1811
|
0
|
1812 (defvar ps-print-width nil)
|
|
1813 (defvar ps-print-height nil)
|
|
1814
|
|
1815 (defvar ps-height-remaining)
|
|
1816 (defvar ps-width-remaining)
|
|
1817
|
|
1818 (defvar ps-ref-bold-faces nil)
|
|
1819 (defvar ps-ref-italic-faces nil)
|
|
1820 (defvar ps-ref-underlined-faces nil)
|
|
1821
|
82
|
1822 (defvar ps-print-color-scale nil)
|
|
1823
|
0
|
1824 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1825 ;; Internal functions
|
|
1826
|
82
|
1827 (defun ps-line-lengths-internal ()
|
88
|
1828 "Display the correspondence between a line length and a font size,
|
82
|
1829 using the current ps-print setup.
|
|
1830 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
|
|
1831 (let ((buf (get-buffer-create "*Line-lengths*"))
|
|
1832 (ifs ps-font-size) ; initial font size
|
|
1833 (icw ps-avg-char-width) ; initial character width
|
|
1834 (print-width (progn (ps-get-page-dimensions)
|
|
1835 ps-print-width))
|
|
1836 (ps-setup (ps-setup)) ; setup for the current buffer
|
|
1837 (fs-min 5) ; minimum font size
|
|
1838 cw-min ; minimum character width
|
|
1839 nb-cpl-max ; maximum nb of characters per line
|
|
1840 (fs-max 14) ; maximum font size
|
|
1841 cw-max ; maximum character width
|
|
1842 nb-cpl-min ; minimum nb of characters per line
|
|
1843 fs ; current font size
|
|
1844 cw ; current character width
|
|
1845 nb-cpl ; current nb of characters per line
|
|
1846 )
|
|
1847 (setq cw-min (/ (* icw fs-min) ifs)
|
|
1848 nb-cpl-max (floor (/ print-width cw-min))
|
|
1849 cw-max (/ (* icw fs-max) ifs)
|
|
1850 nb-cpl-min (floor (/ print-width cw-max)))
|
|
1851 (setq nb-cpl nb-cpl-min)
|
|
1852 (set-buffer buf)
|
|
1853 (goto-char (point-max))
|
|
1854 (if (not (bolp)) (insert "\n"))
|
|
1855 (insert ps-setup)
|
|
1856 (insert "nb char per line / font size\n")
|
|
1857 (while (<= nb-cpl nb-cpl-max)
|
|
1858 (setq cw (/ print-width (float nb-cpl))
|
|
1859 fs (/ (* ifs cw) icw))
|
|
1860 (insert (format "%3s %s\n" nb-cpl fs))
|
|
1861 (setq nb-cpl (1+ nb-cpl)))
|
|
1862 (insert "\n")
|
|
1863 (display-buffer buf 'not-this-window)))
|
|
1864
|
|
1865 (defun ps-nb-pages (nb-lines)
|
88
|
1866 "Display an approximate correspondence between a font size and the number
|
82
|
1867 of pages the number of lines would require to print
|
|
1868 using the current ps-print setup."
|
|
1869 (let ((buf (get-buffer-create "*Nb-Pages*"))
|
|
1870 (ifs ps-font-size) ; initial font size
|
|
1871 (ilh ps-line-height) ; initial line height
|
|
1872 (page-height (progn (ps-get-page-dimensions)
|
|
1873 ps-print-height))
|
|
1874 (ps-setup (ps-setup)) ; setup for the current buffer
|
|
1875 (fs-min 4) ; minimum font size
|
|
1876 lh-min ; minimum line height
|
|
1877 nb-lpp-max ; maximum nb of lines per page
|
|
1878 nb-page-min ; minimum nb of pages
|
|
1879 (fs-max 14) ; maximum font size
|
|
1880 lh-max ; maximum line height
|
|
1881 nb-lpp-min ; minimum nb of lines per page
|
|
1882 nb-page-max ; maximum nb of pages
|
|
1883 fs ; current font size
|
|
1884 lh ; current line height
|
|
1885 nb-lpp ; current nb of lines per page
|
|
1886 nb-page ; current nb of pages
|
|
1887 )
|
|
1888 (setq lh-min (/ (* ilh fs-min) ifs)
|
|
1889 nb-lpp-max (floor (/ page-height lh-min))
|
|
1890 nb-page-min (ceiling (/ (float nb-lines) nb-lpp-max))
|
|
1891 lh-max (/ (* ilh fs-max) ifs)
|
|
1892 nb-lpp-min (floor (/ page-height lh-max))
|
|
1893 nb-page-max (ceiling (/ (float nb-lines) nb-lpp-min)))
|
|
1894 (setq nb-page nb-page-min)
|
|
1895 (set-buffer buf)
|
|
1896 (goto-char (point-max))
|
|
1897 (if (not (bolp)) (insert "\n"))
|
|
1898 (insert ps-setup)
|
|
1899 (insert (format "%d lines\n" nb-lines))
|
|
1900 (insert "nb page / font size\n")
|
|
1901 (while (<= nb-page nb-page-max)
|
|
1902 (setq nb-lpp (ceiling (/ nb-lines (float nb-page)))
|
|
1903 lh (/ page-height nb-lpp)
|
|
1904 fs (/ (* ifs lh) ilh))
|
|
1905 (insert (format "%s %s\n" nb-page fs))
|
|
1906 (setq nb-page (1+ nb-page)))
|
|
1907 (insert "\n")
|
|
1908 (display-buffer buf 'not-this-window)))
|
|
1909
|
|
1910 (defun ps-select-font ()
|
|
1911 "Choose the font name and size (scaling data)."
|
|
1912 (let ((assoc (assq ps-font-family ps-font-info-database))
|
|
1913 l fn fb fi bi sz lh sw aw)
|
|
1914 (if (null assoc)
|
|
1915 (error "Don't have data to scale font %s. Known fonts families are %s"
|
|
1916 ps-font-family
|
|
1917 (mapcar 'car ps-font-info-database)))
|
|
1918 (setq l (cdr assoc)
|
|
1919 fn (prog1 (car l) (setq l (cdr l))) ; need `pop'
|
|
1920 fb (prog1 (car l) (setq l (cdr l)))
|
|
1921 fi (prog1 (car l) (setq l (cdr l)))
|
|
1922 bi (prog1 (car l) (setq l (cdr l)))
|
|
1923 sz (prog1 (car l) (setq l (cdr l)))
|
|
1924 lh (prog1 (car l) (setq l (cdr l)))
|
|
1925 sw (prog1 (car l) (setq l (cdr l)))
|
|
1926 aw (prog1 (car l) (setq l (cdr l))))
|
|
1927
|
|
1928 (setq ps-font fn)
|
|
1929 (setq ps-font-bold fb)
|
|
1930 (setq ps-font-italic fi)
|
|
1931 (setq ps-font-bold-italic bi)
|
|
1932 ;; These data just need to be rescaled:
|
|
1933 (setq ps-line-height (/ (* lh ps-font-size) sz))
|
|
1934 (setq ps-space-width (/ (* sw ps-font-size) sz))
|
|
1935 (setq ps-avg-char-width (/ (* aw ps-font-size) sz))
|
|
1936 ps-font-family))
|
|
1937
|
|
1938 (defun ps-select-header-font ()
|
|
1939 "Choose the font name and size (scaling data) for the header."
|
|
1940 (let ((assoc (assq ps-header-font-family ps-font-info-database))
|
|
1941 l fn fb fi bi sz lh sw aw)
|
|
1942 (if (null assoc)
|
|
1943 (error "Don't have data to scale font %s. Known fonts families are %s"
|
|
1944 ps-font-family
|
|
1945 (mapcar 'car ps-font-info-database)))
|
|
1946 (setq l (cdr assoc)
|
|
1947 fn (prog1 (car l) (setq l (cdr l))) ; need `pop'
|
|
1948 fb (prog1 (car l) (setq l (cdr l)))
|
|
1949 fi (prog1 (car l) (setq l (cdr l)))
|
|
1950 bi (prog1 (car l) (setq l (cdr l)))
|
|
1951 sz (prog1 (car l) (setq l (cdr l)))
|
|
1952 lh (prog1 (car l) (setq l (cdr l)))
|
|
1953 sw (prog1 (car l) (setq l (cdr l)))
|
|
1954 aw (prog1 (car l) (setq l (cdr l))))
|
|
1955
|
|
1956 ;; Font name
|
|
1957 (setq ps-header-font fn)
|
|
1958 (setq ps-header-title-font fb)
|
|
1959 ;; Line height: These data just need to be rescaled:
|
|
1960 (setq ps-header-title-line-height (/ (* lh ps-header-title-font-size) sz))
|
|
1961 (setq ps-header-line-height (/ (* lh ps-header-font-size) sz))
|
|
1962 ps-header-font-family))
|
|
1963
|
0
|
1964 (defun ps-get-page-dimensions ()
|
82
|
1965 (let ((page-dimensions (cdr (assq ps-paper-type ps-page-dimensions-database)))
|
|
1966 page-width page-height)
|
|
1967 (cond
|
|
1968 ((null page-dimensions)
|
|
1969 (error "`ps-paper-type' must be one of:\n%s"
|
|
1970 (mapcar 'car ps-page-dimensions-database)))
|
|
1971 ((< ps-number-of-columns 1)
|
|
1972 (error "The number of columns %d should not be negative")))
|
|
1973
|
|
1974 (ps-select-font)
|
|
1975 (ps-select-header-font)
|
|
1976
|
|
1977 (setq page-width (ps-page-dimensions-get-width page-dimensions)
|
|
1978 page-height (ps-page-dimensions-get-height page-dimensions))
|
|
1979
|
|
1980 ;; Landscape mode
|
|
1981 (if ps-landscape-mode
|
|
1982 ;; exchange width and height
|
|
1983 (setq page-width (prog1 page-height (setq page-height page-width))))
|
|
1984
|
|
1985 ;; It is used to get the lower right corner (only in landscape mode)
|
|
1986 (setq ps-landscape-page-height page-height)
|
|
1987
|
|
1988 ;; | lm | text | ic | text | ic | text | rm |
|
|
1989 ;; page-width == lm + n * pw + (n - 1) * ic + rm
|
|
1990 ;; => pw == (page-width - lm -rm - (n - 1) * ic) / n
|
|
1991 (setq ps-print-width
|
|
1992 (/ (- page-width
|
|
1993 ps-left-margin ps-right-margin
|
|
1994 (* (1- ps-number-of-columns) ps-inter-column))
|
|
1995 ps-number-of-columns))
|
|
1996 (if (<= ps-print-width 0)
|
|
1997 (error "Bad horizontal layout:
|
|
1998 page-width == %s
|
|
1999 ps-left-margin == %s
|
|
2000 ps-right-margin == %s
|
|
2001 ps-inter-column == %s
|
|
2002 ps-number-of-columns == %s
|
|
2003 | lm | text | ic | text | ic | text | rm |
|
|
2004 page-width == lm + n * print-width + (n - 1) * ic + rm
|
|
2005 => print-width == %d !"
|
|
2006 page-width
|
|
2007 ps-left-margin
|
|
2008 ps-right-margin
|
|
2009 ps-inter-column
|
|
2010 ps-number-of-columns
|
|
2011 ps-print-width))
|
|
2012
|
|
2013 (setq ps-print-height
|
|
2014 (- page-height ps-bottom-margin ps-top-margin))
|
|
2015 (if (<= ps-print-height 0)
|
|
2016 (error "Bad vertical layout:
|
|
2017 ps-top-margin == %s
|
|
2018 ps-bottom-margin == %s
|
|
2019 page-height == bm + print-height + tm
|
|
2020 => print-height == %d !"
|
|
2021 ps-top-margin
|
|
2022 ps-bottom-margin
|
|
2023 ps-print-height))
|
|
2024 ;; If headers are turned on, deduct the height of the header from
|
|
2025 ;; the print height.
|
|
2026 (cond
|
|
2027 (ps-print-header
|
|
2028 (setq ps-header-pad
|
|
2029 (* ps-header-line-pad ps-header-title-line-height))
|
|
2030 (setq ps-print-height
|
|
2031 (- ps-print-height
|
|
2032 ps-header-offset
|
|
2033 ps-header-pad
|
|
2034 ps-header-title-line-height
|
|
2035 (* ps-header-line-height (- ps-header-lines 1))
|
|
2036 ps-header-pad))))
|
|
2037 (if (<= ps-print-height 0)
|
|
2038 (error "Bad vertical layout:
|
|
2039 ps-top-margin == %s
|
|
2040 ps-bottom-margin == %s
|
|
2041 ps-header-offset == %s
|
|
2042 ps-header-pad == %s
|
|
2043 header-height == %s
|
|
2044 page-height == bm + print-height + tm - ho - hh
|
|
2045 => print-height == %d !"
|
|
2046 ps-top-margin
|
|
2047 ps-bottom-margin
|
|
2048 ps-header-offset
|
|
2049 ps-header-pad
|
|
2050 (+ ps-header-pad
|
|
2051 ps-header-title-line-height
|
|
2052 (* ps-header-line-height (- ps-header-lines 1))
|
|
2053 ps-header-pad)
|
|
2054 ps-print-height))))
|
0
|
2055
|
|
2056 (defun ps-print-preprint (&optional filename)
|
|
2057 (if (and filename
|
|
2058 (or (numberp filename)
|
|
2059 (listp filename)))
|
|
2060 (let* ((name (concat (buffer-name) ".ps"))
|
|
2061 (prompt (format "Save PostScript to file: (default %s) "
|
2
|
2062 name))
|
|
2063 (res (read-file-name prompt default-directory name nil)))
|
|
2064 (if (file-directory-p res)
|
|
2065 (expand-file-name name (file-name-as-directory res))
|
|
2066 res))))
|
0
|
2067
|
|
2068 ;; The following functions implement a simple list-buffering scheme so
|
|
2069 ;; that ps-print doesn't have to repeatedly switch between buffers
|
|
2070 ;; while spooling. The functions ps-output and ps-output-string build
|
|
2071 ;; up the lists; the function ps-flush-output takes the lists and
|
|
2072 ;; insert its contents into the spool buffer (*PostScript*).
|
|
2073
|
|
2074 (defun ps-output-string-prim (string)
|
|
2075 (insert "(") ;insert start-string delimiter
|
|
2076 (save-excursion ;insert string
|
|
2077 (insert string))
|
|
2078
|
|
2079 ;; Find and quote special characters as necessary for PS
|
|
2080 (while (re-search-forward "[()\\]" nil t)
|
|
2081 (save-excursion
|
|
2082 (forward-char -1)
|
|
2083 (insert "\\")))
|
|
2084
|
|
2085 (goto-char (point-max))
|
|
2086 (insert ")")) ;insert end-string delimiter
|
|
2087
|
|
2088 (defun ps-init-output-queue ()
|
|
2089 (setq ps-output-head (list ""))
|
|
2090 (setq ps-output-tail ps-output-head))
|
|
2091
|
|
2092 (defun ps-output (&rest args)
|
|
2093 (setcdr ps-output-tail args)
|
|
2094 (while (cdr ps-output-tail)
|
|
2095 (setq ps-output-tail (cdr ps-output-tail))))
|
|
2096
|
|
2097 (defun ps-output-string (string)
|
|
2098 (ps-output t string))
|
|
2099
|
|
2100 (defun ps-flush-output ()
|
|
2101 (save-excursion
|
|
2102 (set-buffer ps-spool-buffer)
|
|
2103 (goto-char (point-max))
|
|
2104 (while ps-output-head
|
|
2105 (let ((it (car ps-output-head)))
|
|
2106 (if (not (eq t it))
|
|
2107 (insert it)
|
|
2108 (setq ps-output-head (cdr ps-output-head))
|
|
2109 (ps-output-string-prim (car ps-output-head))))
|
|
2110 (setq ps-output-head (cdr ps-output-head))))
|
|
2111 (ps-init-output-queue))
|
|
2112
|
|
2113 (defun ps-insert-file (fname)
|
|
2114 (ps-flush-output)
|
|
2115
|
|
2116 ;; Check to see that the file exists and is readable; if not, throw
|
88
|
2117 ;; an error.
|
0
|
2118 (if (not (file-readable-p fname))
|
|
2119 (error "Could not read file `%s'" fname))
|
|
2120
|
|
2121 (save-excursion
|
|
2122 (set-buffer ps-spool-buffer)
|
|
2123 (goto-char (point-max))
|
|
2124 (insert-file fname)))
|
|
2125
|
|
2126 ;; These functions insert the arrays that define the contents of the
|
|
2127 ;; headers.
|
|
2128
|
|
2129 (defun ps-generate-header-line (fonttag &optional content)
|
|
2130 (ps-output " [ " fonttag " ")
|
|
2131 (cond
|
|
2132 ;; Literal strings should be output as is -- the string must
|
|
2133 ;; contain its own PS string delimiters, '(' and ')', if necessary.
|
|
2134 ((stringp content)
|
|
2135 (ps-output content))
|
|
2136
|
|
2137 ;; Functions are called -- they should return strings; they will be
|
|
2138 ;; inserted as strings and the PS string delimiters added.
|
|
2139 ((and (symbolp content) (fboundp content))
|
|
2140 (ps-output-string (funcall content)))
|
|
2141
|
|
2142 ;; Variables will have their contents inserted. They should
|
|
2143 ;; contain strings, and will be inserted as strings.
|
|
2144 ((and (symbolp content) (boundp content))
|
|
2145 (ps-output-string (symbol-value content)))
|
|
2146
|
|
2147 ;; Anything else will get turned into an empty string.
|
|
2148 (t
|
|
2149 (ps-output-string "")))
|
|
2150 (ps-output " ]\n"))
|
|
2151
|
|
2152 (defun ps-generate-header (name contents)
|
|
2153 (ps-output "/" name " [\n")
|
|
2154 (if (> ps-header-lines 0)
|
|
2155 (let ((count 1))
|
|
2156 (ps-generate-header-line "/h0" (car contents))
|
|
2157 (while (and (< count ps-header-lines)
|
|
2158 (setq contents (cdr contents)))
|
|
2159 (ps-generate-header-line "/h1" (car contents))
|
|
2160 (setq count (+ count 1)))
|
|
2161 (ps-output "] def\n"))))
|
|
2162
|
|
2163 (defun ps-output-boolean (name bool)
|
|
2164 (ps-output (format "/%s %s def\n" name (if bool "true" "false"))))
|
|
2165
|
|
2166 (defun ps-begin-file ()
|
82
|
2167 (ps-get-page-dimensions)
|
0
|
2168 (setq ps-showpage-count 0)
|
|
2169
|
|
2170 (ps-output ps-adobe-tag)
|
|
2171 (ps-output "%%Title: " (buffer-name) "\n") ;Take job name from name of
|
|
2172 ;first buffer printed
|
|
2173 (ps-output "%%Creator: " (user-full-name) "\n")
|
|
2174 (ps-output "%%CreationDate: "
|
|
2175 (time-stamp-hh:mm:ss) " " (time-stamp-mon-dd-yyyy) "\n")
|
|
2176 (ps-output "%%Pages: (atend)\n")
|
|
2177 (ps-output "%%EndComments\n\n")
|
|
2178
|
88
|
2179 (ps-output "%%BeginProlog\n")
|
82
|
2180 (ps-output-boolean "LandscapeMode" ps-landscape-mode)
|
|
2181 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns))
|
|
2182
|
|
2183 (ps-output (format "/LandscapePageHeight %s def\n" ps-landscape-page-height))
|
|
2184 (ps-output (format "/PrintWidth %s def\n" ps-print-width))
|
|
2185 (ps-output (format "/PrintHeight %s def\n" ps-print-height))
|
|
2186
|
|
2187 (ps-output (format "/LeftMargin %s def\n" ps-left-margin))
|
|
2188 (ps-output (format "/RightMargin %s def\n" ps-right-margin)) ; not used
|
|
2189 (ps-output (format "/InterColumn %s def\n" ps-inter-column))
|
|
2190
|
|
2191 (ps-output (format "/BottomMargin %s def\n" ps-bottom-margin))
|
|
2192 (ps-output (format "/TopMargin %s def\n" ps-top-margin)) ; not used
|
|
2193 (ps-output (format "/HeaderOffset %s def\n" ps-header-offset))
|
|
2194 (ps-output (format "/HeaderPad %s def\n" ps-header-pad))
|
|
2195
|
|
2196 (ps-output-boolean "PrintHeader" ps-print-header)
|
70
|
2197 (ps-output-boolean "PrintHeaderFrame" ps-print-header-frame)
|
82
|
2198 (ps-output-boolean "ShowNofN" ps-show-n-of-n)
|
|
2199 (ps-output-boolean "Duplex" ps-spool-duplex)
|
|
2200
|
|
2201 (ps-output (format "/LineHeight %s def\n" ps-line-height))
|
|
2202
|
|
2203 (ps-output ps-print-prologue-1)
|
88
|
2204 (ps-output "%%EndProlog\n\n")
|
|
2205
|
|
2206
|
|
2207 (ps-output "%%BeginSetup\n")
|
82
|
2208
|
|
2209 ;; Header fonts
|
|
2210 (ps-output ; /h0 14 /Helvetica-Bold Font
|
|
2211 (format "/h0 %s /%s DefFont\n" ps-header-title-font-size ps-header-title-font))
|
|
2212 (ps-output ; /h1 12 /Helvetica Font
|
|
2213 (format "/h1 %s /%s DefFont\n" ps-header-font-size ps-header-font))
|
|
2214
|
|
2215 (ps-output ps-print-prologue-2)
|
|
2216
|
|
2217 ;; Text fonts
|
|
2218 (ps-output (format "/f0 %s /%s DefFont\n" ps-font-size ps-font))
|
|
2219 (ps-output (format "/f1 %s /%s DefFont\n" ps-font-size ps-font-bold))
|
|
2220 (ps-output (format "/f2 %s /%s DefFont\n" ps-font-size ps-font-italic))
|
|
2221 (ps-output (format "/f3 %s /%s DefFont\n" ps-font-size ps-font-bold-italic))
|
|
2222
|
|
2223 (ps-output "\nBeginDoc\n\n")
|
88
|
2224 (ps-output "%%EndSetup\n")
|
|
2225 )
|
0
|
2226
|
|
2227 (defun ps-header-dirpart ()
|
|
2228 (let ((fname (buffer-file-name)))
|
|
2229 (if fname
|
|
2230 (if (string-equal (buffer-name) (file-name-nondirectory fname))
|
|
2231 (file-name-directory fname)
|
|
2232 fname)
|
|
2233 "")))
|
|
2234
|
|
2235 (defun ps-get-buffer-name ()
|
82
|
2236 (cond
|
|
2237 ;; Indulge Jim this little easter egg:
|
|
2238 ((string= (buffer-name) "ps-print.el")
|
|
2239 "Hey, Cool! It's ps-print.el!!!")
|
|
2240 ;; Indulge Jack this other little easter egg:
|
|
2241 ((string= (buffer-name) "sokoban.el")
|
|
2242 "Super! C'est sokoban.el!")
|
|
2243 (t (buffer-name))))
|
0
|
2244
|
|
2245 (defun ps-begin-job ()
|
|
2246 (setq ps-page-count 0))
|
|
2247
|
|
2248 (defun ps-end-file ()
|
88
|
2249 (ps-output "\n\n%%Trailer\n")
|
82
|
2250 (ps-output (format "%%%%Pages: %d\n" (1+ (/ (1- ps-page-count)
|
88
|
2251 ps-number-of-columns))))
|
|
2252 (ps-output "EndDoc\n")
|
|
2253 (ps-output "%%EOF\n"))
|
0
|
2254
|
|
2255 (defun ps-next-page ()
|
|
2256 (ps-end-page)
|
|
2257 (ps-flush-output)
|
|
2258 (ps-begin-page))
|
|
2259
|
|
2260 (defun ps-begin-page (&optional dummypage)
|
|
2261 (ps-get-page-dimensions)
|
82
|
2262 (setq ps-width-remaining ps-print-width)
|
0
|
2263 (setq ps-height-remaining ps-print-height)
|
|
2264
|
82
|
2265 ;; Print only when a new real page begins.
|
|
2266 (when (zerop (mod ps-page-count ps-number-of-columns))
|
|
2267 (ps-output (format "\n%%%%Page: %d %d\n"
|
|
2268 (1+ (/ ps-page-count ps-number-of-columns))
|
|
2269 (1+ (/ ps-page-count ps-number-of-columns)))))
|
|
2270
|
0
|
2271 (ps-output "BeginDSCPage\n")
|
82
|
2272 (ps-output (format "/PageNumber %d def\n" (incf ps-page-count)))
|
0
|
2273 (ps-output "/PageCount 0 def\n")
|
|
2274
|
82
|
2275 (when ps-print-header
|
|
2276 (ps-generate-header "HeaderLinesLeft" ps-left-header)
|
|
2277 (ps-generate-header "HeaderLinesRight" ps-right-header)
|
|
2278 (ps-output (format "%d SetHeaderLines\n" ps-header-lines)))
|
0
|
2279
|
|
2280 (ps-output "BeginPage\n")
|
82
|
2281 (ps-set-font ps-current-font)
|
|
2282 (ps-set-bg ps-current-bg)
|
|
2283 (ps-set-color ps-current-color)
|
0
|
2284 (ps-set-underline ps-current-underline-p))
|
|
2285
|
|
2286 (defun ps-end-page ()
|
|
2287 (setq ps-showpage-count (+ 1 ps-showpage-count))
|
|
2288 (ps-output "EndPage\n")
|
|
2289 (ps-output "EndDSCPage\n"))
|
|
2290
|
|
2291 (defun ps-dummy-page ()
|
|
2292 (setq ps-showpage-count (+ 1 ps-showpage-count))
|
|
2293 (ps-output "%%Page: " (format "- %d\n" ps-showpage-count)
|
|
2294 "BeginDSCPage
|
|
2295 /PrintHeader false def
|
|
2296 BeginPage
|
|
2297 EndPage
|
|
2298 EndDSCPage\n"))
|
|
2299
|
|
2300 (defun ps-next-line ()
|
|
2301 (if (< ps-height-remaining ps-line-height)
|
|
2302 (ps-next-page)
|
82
|
2303 (setq ps-width-remaining ps-print-width)
|
0
|
2304 (setq ps-height-remaining (- ps-height-remaining ps-line-height))
|
|
2305 (ps-hard-lf)))
|
|
2306
|
|
2307 (defun ps-continue-line ()
|
|
2308 (if (< ps-height-remaining ps-line-height)
|
|
2309 (ps-next-page)
|
82
|
2310 (setq ps-width-remaining ps-print-width)
|
0
|
2311 (setq ps-height-remaining (- ps-height-remaining ps-line-height))
|
|
2312 (ps-soft-lf)))
|
|
2313
|
82
|
2314 ;; [jack] Why hard and soft ?
|
|
2315
|
0
|
2316 (defun ps-hard-lf ()
|
|
2317 (ps-output "HL\n"))
|
|
2318
|
|
2319 (defun ps-soft-lf ()
|
|
2320 (ps-output "SL\n"))
|
|
2321
|
|
2322 (defun ps-find-wrappoint (from to char-width)
|
|
2323 (let ((avail (truncate (/ ps-width-remaining char-width)))
|
|
2324 (todo (- to from)))
|
|
2325 (if (< todo avail)
|
|
2326 (cons to (* todo char-width))
|
|
2327 (cons (+ from avail) ps-width-remaining))))
|
|
2328
|
|
2329 (defun ps-basic-plot-string (from to &optional bg-color)
|
|
2330 (let* ((wrappoint (ps-find-wrappoint from to ps-avg-char-width))
|
|
2331 (to (car wrappoint))
|
|
2332 (string (buffer-substring from to)))
|
|
2333 (ps-output-string string)
|
82
|
2334 (ps-output " S\n")
|
0
|
2335 wrappoint))
|
|
2336
|
|
2337 (defun ps-basic-plot-whitespace (from to &optional bg-color)
|
|
2338 (let* ((wrappoint (ps-find-wrappoint from to ps-space-width))
|
|
2339 (to (car wrappoint)))
|
|
2340
|
|
2341 (ps-output (format "%d W\n" (- to from)))
|
|
2342 wrappoint))
|
|
2343
|
|
2344 (defun ps-plot (plotfunc from to &optional bg-color)
|
|
2345 (while (< from to)
|
|
2346 (let* ((wrappoint (funcall plotfunc from to bg-color))
|
|
2347 (plotted-to (car wrappoint))
|
|
2348 (plotted-width (cdr wrappoint)))
|
|
2349 (setq from plotted-to)
|
|
2350 (setq ps-width-remaining (- ps-width-remaining plotted-width))
|
|
2351 (if (< from to)
|
|
2352 (ps-continue-line))))
|
|
2353 (if ps-razzle-dazzle
|
|
2354 (let* ((q-todo (- (point-max) (point-min)))
|
|
2355 (q-done (- (point) (point-min)))
|
|
2356 (chunkfrac (/ q-todo 8))
|
|
2357 (chunksize (if (> chunkfrac 1000) 1000 chunkfrac)))
|
|
2358 (if (> (- q-done ps-razchunk) chunksize)
|
|
2359 (let (foo)
|
|
2360 (setq ps-razchunk q-done)
|
|
2361 (setq foo
|
|
2362 (if (< q-todo 100)
|
|
2363 (/ (* 100 q-done) q-todo)
|
|
2364 (/ q-done (/ q-todo 100))))
|
82
|
2365 (message "Formatting...%3d%%" foo))))))
|
0
|
2366
|
|
2367 (defun ps-set-font (font)
|
|
2368 (setq ps-current-font font)
|
|
2369 (ps-output (format "/f%d F\n" ps-current-font)))
|
|
2370
|
|
2371 (defun ps-set-bg (color)
|
|
2372 (if (setq ps-current-bg color)
|
|
2373 (ps-output (format ps-color-format (nth 0 color) (nth 1 color)
|
|
2374 (nth 2 color))
|
|
2375 " true BG\n")
|
|
2376 (ps-output "false BG\n")))
|
|
2377
|
|
2378 (defun ps-set-color (color)
|
|
2379 (if (setq ps-current-color color)
|
|
2380 nil
|
|
2381 (setq ps-current-color ps-default-fg))
|
|
2382 (ps-output (format ps-color-format (nth 0 ps-current-color)
|
|
2383 (nth 1 ps-current-color) (nth 2 ps-current-color))
|
|
2384 " FG\n"))
|
|
2385
|
|
2386 (defun ps-set-underline (underline-p)
|
|
2387 (ps-output (if underline-p "true" "false") " UL\n")
|
|
2388 (setq ps-current-underline-p underline-p))
|
|
2389
|
|
2390 (defun ps-plot-region (from to font fg-color &optional bg-color underline-p)
|
|
2391
|
|
2392 (if (not (equal font ps-current-font))
|
|
2393 (ps-set-font font))
|
|
2394
|
|
2395 ;; Specify a foreground color only if one's specified and it's
|
|
2396 ;; different than the current.
|
|
2397 (if (not (equal fg-color ps-current-color))
|
|
2398 (ps-set-color fg-color))
|
|
2399
|
|
2400 (if (not (equal bg-color ps-current-bg))
|
|
2401 (ps-set-bg bg-color))
|
|
2402
|
|
2403 ;; Toggle underlining if different.
|
|
2404 (if (not (equal underline-p ps-current-underline-p))
|
|
2405 (ps-set-underline underline-p))
|
|
2406
|
|
2407 ;; Starting at the beginning of the specified region...
|
|
2408 (save-excursion
|
|
2409 (goto-char from)
|
|
2410
|
|
2411 ;; ...break the region up into chunks separated by tabs, linefeeds,
|
|
2412 ;; and pagefeeds, and plot each chunk.
|
|
2413 (while (< from to)
|
|
2414 (if (re-search-forward "[\t\n\f]" to t)
|
|
2415 (let ((match (char-after (match-beginning 0))))
|
|
2416 (cond
|
|
2417 ((= match ?\t)
|
|
2418 (let ((linestart
|
|
2419 (save-excursion (beginning-of-line) (point))))
|
|
2420 (ps-plot 'ps-basic-plot-string from (- (point) 1)
|
|
2421 bg-color)
|
|
2422 (forward-char -1)
|
|
2423 (setq from (+ linestart (current-column)))
|
|
2424 (if (re-search-forward "[ \t]+" to t)
|
|
2425 (ps-plot 'ps-basic-plot-whitespace
|
|
2426 from (+ linestart (current-column))
|
|
2427 bg-color))))
|
|
2428
|
|
2429 ((= match ?\n)
|
|
2430 (ps-plot 'ps-basic-plot-string from (- (point) 1)
|
|
2431 bg-color)
|
|
2432 (ps-next-line)
|
|
2433 )
|
|
2434
|
|
2435 ((= match ?\f)
|
|
2436 (ps-plot 'ps-basic-plot-string from (- (point) 1)
|
|
2437 bg-color)
|
|
2438 (ps-next-page)))
|
|
2439 (setq from (point)))
|
|
2440 (ps-plot 'ps-basic-plot-string from to bg-color)
|
|
2441 (setq from to)))))
|
|
2442
|
|
2443 (defun ps-color-value (x-color-value)
|
|
2444 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval.
|
|
2445 (/ x-color-value ps-print-color-scale))
|
|
2446
|
|
2447 (defun ps-color-values (x-color)
|
70
|
2448 (cond ((fboundp 'x-color-values)
|
0
|
2449 (x-color-values x-color))
|
70
|
2450 ((and (fboundp 'color-instance-rgb-components)
|
82
|
2451 (ps-color-device))
|
70
|
2452 (color-instance-rgb-components
|
|
2453 (if (color-instance-p x-color) x-color
|
|
2454 (if (color-specifier-p x-color)
|
|
2455 (make-color-instance (color-name x-color))
|
|
2456 (make-color-instance x-color)))))
|
0
|
2457 (t (error "No available function to determine X color values."))))
|
|
2458
|
|
2459 (defun ps-face-attributes (face)
|
|
2460 (let ((differs (face-differs-from-default-p face)))
|
|
2461 (list (memq face ps-ref-bold-faces)
|
|
2462 (memq face ps-ref-italic-faces)
|
|
2463 (memq face ps-ref-underlined-faces)
|
|
2464 (and differs (face-foreground face))
|
|
2465 (and differs (face-background face)))))
|
|
2466
|
|
2467 (defun ps-face-attribute-list (face-or-list)
|
|
2468 (if (listp face-or-list)
|
|
2469 (let (bold-p italic-p underline-p foreground background face-attr face)
|
|
2470 (while face-or-list
|
|
2471 (setq face (car face-or-list))
|
|
2472 (setq face-attr (ps-face-attributes face))
|
|
2473 (setq bold-p (or bold-p (nth 0 face-attr)))
|
|
2474 (setq italic-p (or italic-p (nth 1 face-attr)))
|
|
2475 (setq underline-p (or underline-p (nth 2 face-attr)))
|
|
2476 (if foreground
|
|
2477 nil
|
|
2478 (setq foreground (nth 3 face-attr)))
|
|
2479 (if background
|
|
2480 nil
|
|
2481 (setq background (nth 4 face-attr)))
|
|
2482 (setq face-or-list (cdr face-or-list)))
|
|
2483 (list bold-p italic-p underline-p foreground background))
|
|
2484
|
|
2485 (ps-face-attributes face-or-list)))
|
|
2486
|
|
2487 (defun ps-plot-with-face (from to face)
|
|
2488 (if face
|
|
2489 (let* ((face-attr (ps-face-attribute-list face))
|
|
2490 (bold-p (nth 0 face-attr))
|
|
2491 (italic-p (nth 1 face-attr))
|
|
2492 (underline-p (nth 2 face-attr))
|
|
2493 (foreground (nth 3 face-attr))
|
|
2494 (background (nth 4 face-attr))
|
|
2495 (fg-color (if (and ps-print-color-p
|
82
|
2496 (ps-color-device)
|
0
|
2497 foreground)
|
|
2498 (mapcar 'ps-color-value
|
|
2499 (ps-color-values foreground))
|
|
2500 ps-default-color))
|
|
2501 (bg-color (if (and ps-print-color-p
|
82
|
2502 (ps-color-device)
|
0
|
2503 background)
|
|
2504 (mapcar 'ps-color-value
|
|
2505 (ps-color-values background)))))
|
|
2506 (ps-plot-region from to
|
|
2507 (cond ((and bold-p italic-p) 3)
|
|
2508 (italic-p 2)
|
|
2509 (bold-p 1)
|
|
2510 (t 0))
|
|
2511 ; (or fg-color '(0.0 0.0 0.0))
|
|
2512 fg-color
|
|
2513 bg-color underline-p))
|
|
2514 (goto-char to)))
|
|
2515
|
|
2516
|
|
2517 (defun ps-emacs-face-kind-p (face kind kind-regex kind-list)
|
|
2518 (let ((frame-font (face-font face))
|
|
2519 (face-defaults (face-font face t)))
|
|
2520 (or
|
|
2521 ;; Check FACE defaults:
|
|
2522 (and (listp face-defaults)
|
|
2523 (memq kind face-defaults))
|
|
2524
|
|
2525 ;; Check the user's preferences
|
|
2526 (memq face kind-list))))
|
|
2527
|
|
2528 (defun ps-xemacs-face-kind-p (face kind kind-regex kind-list)
|
|
2529 (let* ((frame-font
|
|
2530 (or (face-font-instance face) (face-font-instance 'default)))
|
|
2531 (kind-cons (and frame-font
|
|
2532 (assq kind (font-instance-properties frame-font))))
|
|
2533 (kind-spec (cdr-safe kind-cons))
|
|
2534 (case-fold-search t))
|
|
2535
|
|
2536 (or (and kind-spec (string-match kind-regex kind-spec))
|
|
2537 ;; Kludge-compatible:
|
|
2538 (memq face kind-list))))
|
|
2539
|
|
2540 (defun ps-face-bold-p (face)
|
|
2541 (if (eq ps-print-emacs-type 'emacs)
|
|
2542 (ps-emacs-face-kind-p face 'bold "-\\(bold\\|demibold\\)-"
|
|
2543 ps-bold-faces)
|
|
2544 (ps-xemacs-face-kind-p face 'WEIGHT_NAME "bold\\|demibold"
|
|
2545 ps-bold-faces)))
|
|
2546
|
|
2547 (defun ps-face-italic-p (face)
|
|
2548 (if (eq ps-print-emacs-type 'emacs)
|
|
2549 (ps-emacs-face-kind-p face 'italic "-[io]-" ps-italic-faces)
|
|
2550 (or
|
|
2551 (ps-xemacs-face-kind-p face 'ANGLE_NAME "i\\|o" ps-italic-faces)
|
|
2552 (ps-xemacs-face-kind-p face 'SLANT "i\\|o" ps-italic-faces))))
|
|
2553
|
|
2554 (defun ps-face-underlined-p (face)
|
|
2555 (or (face-underline-p face)
|
|
2556 (memq face ps-underlined-faces)))
|
|
2557
|
|
2558 ;; Ensure that face-list is fbound.
|
|
2559 (or (fboundp 'face-list) (defalias 'face-list 'list-faces))
|
|
2560
|
|
2561 (defun ps-build-reference-face-lists ()
|
|
2562 (if ps-auto-font-detect
|
70
|
2563 (let ((faces (face-list))
|
0
|
2564 the-face)
|
|
2565 (setq ps-ref-bold-faces nil
|
|
2566 ps-ref-italic-faces nil
|
|
2567 ps-ref-underlined-faces nil)
|
|
2568 (while faces
|
|
2569 (setq the-face (car faces))
|
|
2570 (if (ps-face-italic-p the-face)
|
|
2571 (setq ps-ref-italic-faces
|
|
2572 (cons the-face ps-ref-italic-faces)))
|
|
2573 (if (ps-face-bold-p the-face)
|
|
2574 (setq ps-ref-bold-faces
|
|
2575 (cons the-face ps-ref-bold-faces)))
|
|
2576 (if (ps-face-underlined-p the-face)
|
|
2577 (setq ps-ref-underlined-faces
|
|
2578 (cons the-face ps-ref-underlined-faces)))
|
|
2579 (setq faces (cdr faces))))
|
|
2580 (setq ps-ref-bold-faces ps-bold-faces)
|
|
2581 (setq ps-ref-italic-faces ps-italic-faces)
|
|
2582 (setq ps-ref-underlined-faces ps-underlined-faces))
|
|
2583 (setq ps-build-face-reference nil))
|
|
2584
|
|
2585 (defun ps-mapper (extent list)
|
|
2586 (nconc list (list (list (extent-start-position extent) 'push extent)
|
|
2587 (list (extent-end-position extent) 'pull extent)))
|
|
2588 nil)
|
|
2589
|
|
2590 (defun ps-extent-sorter (a b)
|
|
2591 (< (extent-priority a) (extent-priority b)))
|
|
2592
|
|
2593 (defun ps-print-ensure-fontified (start end)
|
|
2594 (if (and (boundp 'lazy-lock-mode) lazy-lock-mode)
|
|
2595 (if (fboundp 'lazy-lock-fontify-region)
|
82
|
2596 (lazy-lock-fontify-region start end) ; the new
|
|
2597 (lazy-lock-fontify-buffer)))) ; the old
|
0
|
2598
|
|
2599 (defun ps-generate-postscript-with-faces (from to)
|
|
2600 ;; Build the reference lists of faces if necessary.
|
|
2601 (if (or ps-always-build-face-reference
|
|
2602 ps-build-face-reference)
|
|
2603 (progn
|
|
2604 (message "Collecting face information...")
|
|
2605 (ps-build-reference-face-lists)))
|
|
2606 ;; Set the color scale. We do it here instead of in the defvar so
|
|
2607 ;; that ps-print can be dumped into emacs. This expression can't be
|
|
2608 ;; evaluated at dump-time because X isn't initialized.
|
|
2609 (setq ps-print-color-scale
|
82
|
2610 (if (and ps-print-color-p (ps-color-device))
|
0
|
2611 (float (car (ps-color-values "white")))
|
|
2612 1.0))
|
|
2613 ;; Generate some PostScript.
|
|
2614 (save-restriction
|
|
2615 (narrow-to-region from to)
|
|
2616 (let ((face 'default)
|
|
2617 (position to))
|
|
2618 (ps-print-ensure-fontified from to)
|
82
|
2619 (cond ((or (eq ps-print-emacs-type 'lucid)
|
|
2620 (eq ps-print-emacs-type 'xemacs))
|
0
|
2621 ;; Build the list of extents...
|
|
2622 (let ((a (cons 'dummy nil))
|
|
2623 record type extent extent-list)
|
|
2624 (map-extents 'ps-mapper nil from to a)
|
82
|
2625 (setq a (sort (cdr a) 'car-less-than-car))
|
0
|
2626
|
|
2627 (setq extent-list nil)
|
|
2628
|
|
2629 ;; Loop through the extents...
|
|
2630 (while a
|
|
2631 (setq record (car a))
|
|
2632
|
|
2633 (setq position (car record))
|
|
2634 (setq record (cdr record))
|
|
2635
|
|
2636 (setq type (car record))
|
|
2637 (setq record (cdr record))
|
|
2638
|
|
2639 (setq extent (car record))
|
|
2640
|
|
2641 ;; Plot up to this record.
|
|
2642 ;; XEmacs 19.12: for some reason, we're getting into a
|
|
2643 ;; situation in which some of the records have
|
|
2644 ;; positions less than 'from'. Since we've narrowed
|
|
2645 ;; the buffer, this'll generate errors. This is a
|
|
2646 ;; hack, but don't call ps-plot-with-face unless from >
|
|
2647 ;; point-min.
|
|
2648 (if (and (>= from (point-min))
|
|
2649 (<= position (point-max)))
|
|
2650 (ps-plot-with-face from position face))
|
|
2651
|
|
2652 (cond
|
|
2653 ((eq type 'push)
|
|
2654 (if (extent-face extent)
|
|
2655 (setq extent-list (sort (cons extent extent-list)
|
|
2656 'ps-extent-sorter))))
|
|
2657
|
|
2658 ((eq type 'pull)
|
|
2659 (setq extent-list (sort (delq extent extent-list)
|
|
2660 'ps-extent-sorter))))
|
|
2661
|
|
2662 (setq face
|
|
2663 (if extent-list
|
|
2664 (extent-face (car extent-list))
|
|
2665 'default))
|
|
2666
|
|
2667 (setq from position)
|
|
2668 (setq a (cdr a)))))
|
|
2669
|
|
2670 ((eq ps-print-emacs-type 'emacs)
|
|
2671 (let ((property-change from)
|
|
2672 (overlay-change from))
|
|
2673 (while (< from to)
|
|
2674 (if (< property-change to) ; Don't search for property change
|
|
2675 ; unless previous search succeeded.
|
|
2676 (setq property-change
|
|
2677 (next-property-change from nil to)))
|
|
2678 (if (< overlay-change to) ; Don't search for overlay change
|
|
2679 ; unless previous search succeeded.
|
|
2680 (setq overlay-change
|
|
2681 (min (next-overlay-change from) to)))
|
|
2682 (setq position
|
|
2683 (min property-change overlay-change))
|
2
|
2684 ;; The code below is not quite correct,
|
|
2685 ;; because a non-nil overlay invisible property
|
|
2686 ;; which is inactive according to the current value
|
|
2687 ;; of buffer-invisibility-spec nonetheless overrides
|
|
2688 ;; a face text property.
|
0
|
2689 (setq face
|
2
|
2690 (cond ((let ((prop (get-text-property from 'invisible)))
|
|
2691 ;; Decide whether this invisible property
|
|
2692 ;; really makes the text invisible.
|
|
2693 (if (eq buffer-invisibility-spec t)
|
|
2694 (not (null prop))
|
|
2695 (or (memq prop buffer-invisibility-spec)
|
|
2696 (assq prop buffer-invisibility-spec))))
|
|
2697 nil)
|
0
|
2698 ((get-text-property from 'face))
|
|
2699 (t 'default)))
|
|
2700 (let ((overlays (overlays-at from))
|
|
2701 (face-priority -1)) ; text-property
|
|
2702 (while overlays
|
|
2703 (let* ((overlay (car overlays))
|
|
2704 (overlay-face (overlay-get overlay 'face))
|
|
2705 (overlay-invisible (overlay-get overlay 'invisible))
|
|
2706 (overlay-priority (or (overlay-get overlay
|
|
2707 'priority)
|
|
2708 0)))
|
|
2709 (if (and (or overlay-invisible overlay-face)
|
|
2710 (> overlay-priority face-priority))
|
2
|
2711 (setq face (cond ((if (eq buffer-invisibility-spec t)
|
|
2712 (not (null overlay-invisible))
|
|
2713 (or (memq overlay-invisible buffer-invisibility-spec)
|
|
2714 (assq overlay-invisible buffer-invisibility-spec)))
|
|
2715 nil)
|
0
|
2716 ((and face overlay-face)))
|
|
2717 face-priority overlay-priority)))
|
|
2718 (setq overlays (cdr overlays))))
|
|
2719 ;; Plot up to this record.
|
|
2720 (ps-plot-with-face from position face)
|
|
2721 (setq from position)))))
|
|
2722 (ps-plot-with-face from to face))))
|
|
2723
|
|
2724 (defun ps-generate-postscript (from to)
|
|
2725 (ps-plot-region from to 0 nil))
|
|
2726
|
|
2727 (defun ps-generate (buffer from to genfunc)
|
|
2728 (let ((from (min to from))
|
2
|
2729 (to (max to from))
|
|
2730 ;; This avoids trouble if chars with read-only properties
|
|
2731 ;; are copied into ps-spool-buffer.
|
|
2732 (inhibit-read-only t))
|
0
|
2733 (save-restriction
|
|
2734 (narrow-to-region from to)
|
|
2735 (if ps-razzle-dazzle
|
82
|
2736 (message "Formatting...%3d%%" (setq ps-razchunk 0)))
|
0
|
2737 (set-buffer buffer)
|
|
2738 (setq ps-source-buffer buffer)
|
|
2739 (setq ps-spool-buffer (get-buffer-create ps-spool-buffer-name))
|
|
2740 (ps-init-output-queue)
|
|
2741 (let (safe-marker completed-safely needs-begin-file)
|
|
2742 (unwind-protect
|
|
2743 (progn
|
|
2744 (set-buffer ps-spool-buffer)
|
|
2745
|
|
2746 ;; Get a marker and make it point to the current end of the
|
|
2747 ;; buffer, If an error occurs, we'll delete everything from
|
|
2748 ;; the end of this marker onwards.
|
|
2749 (setq safe-marker (make-marker))
|
|
2750 (set-marker safe-marker (point-max))
|
|
2751
|
|
2752 (goto-char (point-min))
|
88
|
2753 (if (looking-at (regexp-quote ps-adobe-tag))
|
0
|
2754 nil
|
|
2755 (setq needs-begin-file t))
|
|
2756 (save-excursion
|
|
2757 (set-buffer ps-source-buffer)
|
|
2758 (if needs-begin-file (ps-begin-file))
|
|
2759 (ps-begin-job)
|
|
2760 (ps-begin-page))
|
|
2761 (set-buffer ps-source-buffer)
|
|
2762 (funcall genfunc from to)
|
|
2763 (ps-end-page)
|
|
2764
|
|
2765 (if (and ps-spool-duplex
|
|
2766 (= (mod ps-page-count 2) 1))
|
|
2767 (ps-dummy-page))
|
|
2768 (ps-flush-output)
|
|
2769
|
|
2770 ;; Back to the PS output buffer to set the page count
|
|
2771 (set-buffer ps-spool-buffer)
|
|
2772 (goto-char (point-max))
|
|
2773 (while (re-search-backward "^/PageCount 0 def$" nil t)
|
|
2774 (replace-match (format "/PageCount %d def" ps-page-count) t))
|
|
2775
|
2
|
2776 ;; Setting this variable tells the unwind form that
|
0
|
2777 ;; the postscript was generated without error.
|
|
2778 (setq completed-safely t))
|
|
2779
|
2
|
2780 ;; Unwind form: If some bad mojo occurred while generating
|
0
|
2781 ;; postscript, delete all the postscript that was generated.
|
|
2782 ;; This protects the previously spooled files from getting
|
|
2783 ;; corrupted.
|
|
2784 (if (and (markerp safe-marker) (not completed-safely))
|
|
2785 (progn
|
|
2786 (set-buffer ps-spool-buffer)
|
|
2787 (delete-region (marker-position safe-marker) (point-max))))))
|
|
2788
|
|
2789 (if ps-razzle-dazzle
|
|
2790 (message "Formatting...done")))))
|
|
2791
|
74
|
2792 ;; Permit dynamic evaluation at print time of ps-lpr-switches
|
0
|
2793 (defun ps-do-despool (filename)
|
|
2794 (if (or (not (boundp 'ps-spool-buffer))
|
82
|
2795 (not (symbol-value 'ps-spool-buffer)))
|
0
|
2796 (message "No spooled PostScript to print")
|
|
2797 (ps-end-file)
|
|
2798 (ps-flush-output)
|
|
2799 (if filename
|
|
2800 (save-excursion
|
|
2801 (if ps-razzle-dazzle
|
|
2802 (message "Saving..."))
|
|
2803 (set-buffer ps-spool-buffer)
|
|
2804 (setq filename (expand-file-name filename))
|
|
2805 (write-region (point-min) (point-max) filename)
|
|
2806 (if ps-razzle-dazzle
|
|
2807 (message "Wrote %s" filename)))
|
|
2808 ;; Else, spool to the printer
|
|
2809 (if ps-razzle-dazzle
|
|
2810 (message "Printing..."))
|
|
2811 (save-excursion
|
|
2812 (set-buffer ps-spool-buffer)
|
2
|
2813 (if (and (eq system-type 'ms-dos) (stringp dos-ps-printer))
|
|
2814 (write-region (point-min) (point-max) dos-ps-printer t 0)
|
74
|
2815 (let ((binary-process-input t) ; for MS-DOS
|
82
|
2816 (ps-lpr-sw ; Dynamic evaluation
|
|
2817 (ps-flatten-list (mapcar 'ps-eval-switch ps-lpr-switches))))
|
2
|
2818 (apply 'call-process-region
|
|
2819 (point-min) (point-max) ps-lpr-command nil
|
|
2820 (if (fboundp 'start-process) 0 nil)
|
|
2821 nil
|
74
|
2822 ps-lpr-sw))))
|
0
|
2823 (if ps-razzle-dazzle
|
|
2824 (message "Printing...done")))
|
|
2825 (kill-buffer ps-spool-buffer)))
|
|
2826
|
82
|
2827 ;; Dynamic evaluation
|
|
2828 (defun ps-eval-switch (arg)
|
|
2829 (cond ((stringp arg) arg)
|
|
2830 ((functionp arg) (apply arg nil))
|
|
2831 ((symbolp arg) (symbol-value arg))
|
|
2832 ((consp arg) (apply (car arg) (cdr arg)))
|
|
2833 (t nil)))
|
|
2834
|
|
2835 ;; `ps-flatten-list' is defined here (copied from "message.el" and
|
|
2836 ;; enhanced to handle dotted pairs as well) until we can get some
|
|
2837 ;; sensible autoloads, or `flatten-list' gets put somewhere decent.
|
|
2838
|
|
2839 ;; (ps-flatten-list '((a . b) c (d . e) (f g h) i . j))
|
|
2840 ;; => (a b c d e f g h i j)
|
|
2841
|
|
2842 (defun ps-flatten-list (&rest list)
|
|
2843 (ps-flatten-list-1 list))
|
|
2844
|
|
2845 (defun ps-flatten-list-1 (list)
|
|
2846 (cond
|
|
2847 ((null list) (list))
|
|
2848 ((consp list)
|
|
2849 (append (ps-flatten-list-1 (car list))
|
|
2850 (ps-flatten-list-1 (cdr list))))
|
|
2851 (t (list list))))
|
|
2852
|
0
|
2853 (defun ps-kill-emacs-check ()
|
|
2854 (let (ps-buffer)
|
|
2855 (if (and (setq ps-buffer (get-buffer ps-spool-buffer-name))
|
|
2856 (buffer-modified-p ps-buffer))
|
|
2857 (if (y-or-n-p "Unprinted PostScript waiting; print now? ")
|
|
2858 (ps-despool)))
|
|
2859 (if (and (setq ps-buffer (get-buffer ps-spool-buffer-name))
|
|
2860 (buffer-modified-p ps-buffer))
|
|
2861 (if (yes-or-no-p "Unprinted PostScript waiting; exit anyway? ")
|
|
2862 nil
|
|
2863 (error "Unprinted PostScript")))))
|
|
2864
|
|
2865 (if (fboundp 'add-hook)
|
|
2866 (add-hook 'kill-emacs-hook 'ps-kill-emacs-check)
|
|
2867 (if kill-emacs-hook
|
|
2868 (message "Won't override existing kill-emacs-hook")
|
|
2869 (setq kill-emacs-hook 'ps-kill-emacs-check)))
|
|
2870
|
|
2871 ;;; Sample Setup Code:
|
|
2872
|
|
2873 ;; This stuff is for anybody that's brave enough to look this far,
|
|
2874 ;; and able to figure out how to use it. It isn't really part of ps-
|
|
2875 ;; print, but I'll leave it here in hopes it might be useful:
|
|
2876
|
|
2877 ;; WARNING!!! The following code is *sample* code only. Don't use it
|
|
2878 ;; unless you understand what it does!
|
|
2879
|
|
2880 (defmacro ps-prsc () (list 'if (list 'eq 'ps-print-emacs-type ''emacs)
|
|
2881 [f22] ''f22))
|
|
2882 (defmacro ps-c-prsc () (list 'if (list 'eq 'ps-print-emacs-type ''emacs)
|
|
2883 [C-f22]
|
|
2884 ''(control f22)))
|
|
2885 (defmacro ps-s-prsc () (list 'if (list 'eq 'ps-print-emacs-type ''emacs)
|
|
2886 [S-f22]
|
|
2887 ''(shift f22)))
|
|
2888
|
|
2889 ;; Look in an article or mail message for the Subject: line. To be
|
|
2890 ;; placed in ps-left-headers.
|
|
2891 (defun ps-article-subject ()
|
|
2892 (save-excursion
|
|
2893 (goto-char (point-min))
|
2
|
2894 (if (re-search-forward "^Subject:[ \t]+\\(.*\\)$" nil t)
|
0
|
2895 (buffer-substring (match-beginning 1) (match-end 1))
|
|
2896 "Subject ???")))
|
|
2897
|
|
2898 ;; Look in an article or mail message for the From: line. Sorta-kinda
|
|
2899 ;; understands RFC-822 addresses and can pull the real name out where
|
|
2900 ;; it's provided. To be placed in ps-left-headers.
|
|
2901 (defun ps-article-author ()
|
|
2902 (save-excursion
|
|
2903 (goto-char (point-min))
|
2
|
2904 (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
|
0
|
2905 (let ((fromstring (buffer-substring (match-beginning 1) (match-end 1))))
|
|
2906 (cond
|
|
2907
|
|
2908 ;; Try first to match addresses that look like
|
|
2909 ;; thompson@wg2.waii.com (Jim Thompson)
|
|
2910 ((string-match ".*[ \t]+(\\(.*\\))" fromstring)
|
|
2911 (substring fromstring (match-beginning 1) (match-end 1)))
|
|
2912
|
|
2913 ;; Next try to match addresses that look like
|
|
2914 ;; Jim Thompson <thompson@wg2.waii.com>
|
|
2915 ((string-match "\\(.*\\)[ \t]+<.*>" fromstring)
|
|
2916 (substring fromstring (match-beginning 1) (match-end 1)))
|
|
2917
|
|
2918 ;; Couldn't find a real name -- show the address instead.
|
|
2919 (t fromstring)))
|
|
2920 "From ???")))
|
|
2921
|
|
2922 ;; A hook to bind to gnus-Article-prepare-hook. This will set the ps-
|
|
2923 ;; left-headers specially for gnus articles. Unfortunately, gnus-
|
|
2924 ;; article-mode-hook is called only once, the first time the *Article*
|
|
2925 ;; buffer enters that mode, so it would only work for the first time
|
|
2926 ;; we ran gnus. The second time, this hook wouldn't get set up. The
|
|
2927 ;; only alternative is gnus-article-prepare-hook.
|
|
2928 (defun ps-gnus-article-prepare-hook ()
|
|
2929 (setq ps-header-lines 3)
|
|
2930 (setq ps-left-header
|
|
2931 ;; The left headers will display the article's subject, its
|
|
2932 ;; author, and the newsgroup it was in.
|
|
2933 (list 'ps-article-subject 'ps-article-author 'gnus-newsgroup-name)))
|
|
2934
|
|
2935 ;; A hook to bind to vm-mode-hook to locally bind prsc and set the ps-
|
|
2936 ;; left-headers specially for mail messages. This header setup would
|
|
2937 ;; also work, I think, for RMAIL.
|
|
2938 (defun ps-vm-mode-hook ()
|
|
2939 (local-set-key (ps-prsc) 'ps-vm-print-message-from-summary)
|
|
2940 (setq ps-header-lines 3)
|
|
2941 (setq ps-left-header
|
|
2942 ;; The left headers will display the message's subject, its
|
|
2943 ;; author, and the name of the folder it was in.
|
|
2944 (list 'ps-article-subject 'ps-article-author 'buffer-name)))
|
|
2945
|
|
2946 ;; Every now and then I forget to switch from the *Summary* buffer to
|
|
2947 ;; the *Article* before hitting prsc, and a nicely formatted list of
|
|
2948 ;; article subjects shows up at the printer. This function, bound to
|
|
2949 ;; prsc for the gnus *Summary* buffer means I don't have to switch
|
|
2950 ;; buffers first.
|
74
|
2951 ;; sb: Updated for Gnus 5.
|
0
|
2952 (defun ps-gnus-print-article-from-summary ()
|
|
2953 (interactive)
|
74
|
2954 (let ((ps-buf (if (boundp 'gnus-article-buffer)
|
|
2955 gnus-article-buffer
|
|
2956 "*Article*")))
|
|
2957 (if (get-buffer ps-buf)
|
|
2958 (save-excursion
|
|
2959 (set-buffer ps-buf)
|
|
2960 (ps-spool-buffer-with-faces)))))
|
0
|
2961
|
|
2962 ;; See ps-gnus-print-article-from-summary. This function does the
|
|
2963 ;; same thing for vm.
|
|
2964 (defun ps-vm-print-message-from-summary ()
|
|
2965 (interactive)
|
82
|
2966 (if (and (boundp 'vm-mail-buffer) (symbol-value 'vm-mail-buffer))
|
0
|
2967 (save-excursion
|
82
|
2968 (set-buffer (symbol-value 'vm-mail-buffer))
|
0
|
2969 (ps-spool-buffer-with-faces))))
|
|
2970
|
|
2971 ;; A hook to bind to bind to gnus-summary-setup-buffer to locally bind
|
|
2972 ;; prsc.
|
|
2973 (defun ps-gnus-summary-setup ()
|
|
2974 (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary))
|
|
2975
|
|
2976 ;; Look in an article or mail message for the Subject: line. To be
|
|
2977 ;; placed in ps-left-headers.
|
|
2978 (defun ps-info-file ()
|
|
2979 (save-excursion
|
|
2980 (goto-char (point-min))
|
2
|
2981 (if (re-search-forward "File:[ \t]+\\([^, \t\n]*\\)" nil t)
|
0
|
2982 (buffer-substring (match-beginning 1) (match-end 1))
|
|
2983 "File ???")))
|
|
2984
|
|
2985 ;; Look in an article or mail message for the Subject: line. To be
|
|
2986 ;; placed in ps-left-headers.
|
|
2987 (defun ps-info-node ()
|
|
2988 (save-excursion
|
|
2989 (goto-char (point-min))
|
2
|
2990 (if (re-search-forward "Node:[ \t]+\\([^,\t\n]*\\)" nil t)
|
0
|
2991 (buffer-substring (match-beginning 1) (match-end 1))
|
|
2992 "Node ???")))
|
|
2993
|
|
2994 (defun ps-info-mode-hook ()
|
|
2995 (setq ps-left-header
|
|
2996 ;; The left headers will display the node name and file name.
|
|
2997 (list 'ps-info-node 'ps-info-file)))
|
|
2998
|
|
2999 ;; WARNING! The following function is a *sample* only, and is *not*
|
|
3000 ;; meant to be used as a whole unless you understand what the effects
|
82
|
3001 ;; will be! (In fact, this is a copy of Jim's setup for ps-print --
|
|
3002 ;; I'd be very surprised if it was useful to *anybody*, without
|
0
|
3003 ;; modification.)
|
|
3004
|
|
3005 (defun ps-jts-ps-setup ()
|
|
3006 (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc
|
|
3007 (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces)
|
|
3008 (global-set-key (ps-c-prsc) 'ps-despool)
|
|
3009 (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook)
|
|
3010 (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup)
|
|
3011 (add-hook 'vm-mode-hook 'ps-vm-mode-hook)
|
|
3012 (add-hook 'vm-mode-hooks 'ps-vm-mode-hook)
|
|
3013 (add-hook 'Info-mode-hook 'ps-info-mode-hook)
|
|
3014 (setq ps-spool-duplex t)
|
|
3015 (setq ps-print-color-p nil)
|
|
3016 (setq ps-lpr-command "lpr")
|
82
|
3017 (setq ps-lpr-switches '("-Jjct,duplex_long"))
|
|
3018 'ps-jts-ps-setup)
|
|
3019
|
|
3020 ;; WARNING! The following function is a *sample* only, and is *not*
|
|
3021 ;; meant to be used as a whole unless it corresponds to your needs.
|
|
3022 ;; (In fact, this is a copy of Jack's setup for ps-print --
|
|
3023 ;; I would not be that surprised if it was useful to *anybody*,
|
|
3024 ;; without modification.)
|
|
3025
|
|
3026 (defun ps-jack-setup ()
|
|
3027 (setq ps-print-color-p 'nil
|
|
3028 ps-lpr-command "lpr"
|
|
3029 ps-lpr-switches (list)
|
|
3030
|
|
3031 ps-paper-type 'a4
|
|
3032 ps-landscape-mode 't
|
|
3033 ps-number-of-columns 2
|
|
3034
|
|
3035 ps-left-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
|
|
3036 ps-right-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
|
|
3037 ps-inter-column (/ (* 72 1.0) 2.54) ; 1.0 cm
|
|
3038 ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
|
|
3039 ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
|
|
3040 ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
|
|
3041 ps-header-line-pad .15
|
|
3042 ps-print-header t
|
|
3043 ps-print-header-frame t
|
|
3044 ps-header-lines 2
|
|
3045 ps-show-n-of-n t
|
|
3046 ps-spool-duplex nil
|
|
3047
|
|
3048 ps-font-family 'Courier
|
|
3049 ps-font-size 5.5
|
|
3050 ps-header-font-family 'Helvetica
|
|
3051 ps-header-font-size 6
|
|
3052 ps-header-title-font-size 8)
|
|
3053 'ps-jack-setup)
|
0
|
3054
|
|
3055 (provide 'ps-print)
|
|
3056
|
|
3057 ;;; ps-print.el ends here
|