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