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