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