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 ;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.br>
8 ;; Keywords: print, PostScript
9 ;; Time-stamp: <97/08/27 13:00:37 vinicius>
12 (defconst ps-print-version
"3.05.1"
13 "ps-print.el, v 3.05.1 <97/08/24 vinicius>
15 Vinicius's last change version -- this file may have been edited as part of
16 Emacs without changes to the version number. When reporting bugs,
17 please also report the version of Emacs, if any, that ps-print was
20 Please send all bug fixes and enhancements to
21 Jacques Duthen <duthen@cegelec-red.fr>.
24 ;; This file is part of GNU Emacs.
26 ;; GNU Emacs is free software; you can redistribute it and/or modify
27 ;; it under the terms of the GNU General Public License as published by
28 ;; the Free Software Foundation; either version 2, or (at your option)
31 ;; GNU Emacs is distributed in the hope that it will be useful,
32 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
33 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 ;; GNU General Public License for more details.
36 ;; You should have received a copy of the GNU General Public License
37 ;; along with GNU Emacs; see the file COPYING. If not, write to the
38 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
39 ;; Boston, MA 02111-1307, USA.
43 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
48 ;; This package provides printing of Emacs buffers on PostScript
49 ;; printers; the buffer's bold and italic text attributes are
50 ;; preserved in the printer output. Ps-print is intended for use with
51 ;; Emacs 19 or Lucid Emacs, together with a fontifying package such as
52 ;; font-lock or hilit.
54 ;; ps-print uses the same face attributes defined through font-lock or hilit
55 ;; to print a PostScript file, but some faces are better seeing on the screen
56 ;; than on paper, specially when you have a black/white PostScript printer.
58 ;; ps-print allows a remap of face to another one that it is better to print,
59 ;; for example, the face font-lock-comment-face (if you are using font-lock)
60 ;; could have bold or italic attribute when printing, besides foreground color.
61 ;; This remap improves printing look (see How Ps-Print Maps Faces).
69 ;; Ps-print provides eight commands for generating PostScript images
73 ;; ps-print-buffer-with-faces
75 ;; ps-print-region-with-faces
77 ;; ps-spool-buffer-with-faces
79 ;; ps-spool-region-with-faces
81 ;; These commands all perform essentially the same function: they
82 ;; generate PostScript images suitable for printing on a PostScript
83 ;; printer or displaying with GhostScript. These commands are
84 ;; collectively referred to as "ps-print- commands".
86 ;; The word "print" or "spool" in the command name determines when the
87 ;; PostScript image is sent to the printer:
89 ;; print - The PostScript image is immediately sent to the
92 ;; spool - The PostScript image is saved temporarily in an
93 ;; Emacs buffer. Many images may be spooled locally
94 ;; before printing them. To send the spooled images
95 ;; to the printer, use the command `ps-despool'.
97 ;; The spooling mechanism was designed for printing lots of small
98 ;; files (mail messages or netnews articles) to save paper that would
99 ;; otherwise be wasted on banner pages, and to make it easier to find
100 ;; your output at the printer (it's easier to pick up one 50-page
101 ;; printout than to find 50 single-page printouts).
103 ;; Ps-print has a hook in the `kill-emacs-hooks' so that you won't
104 ;; accidentally quit from Emacs while you have unprinted PostScript
105 ;; waiting in the spool buffer. If you do attempt to exit with
106 ;; spooled PostScript, you'll be asked if you want to print it, and if
107 ;; you decline, you'll be asked to confirm the exit; this is modeled
108 ;; on the confirmation that Emacs uses for modified buffers.
110 ;; The word "buffer" or "region" in the command name determines how
111 ;; much of the buffer is printed:
113 ;; buffer - Print the entire buffer.
115 ;; region - Print just the current region.
117 ;; The -with-faces suffix on the command name means that the command
118 ;; will include font, color, and underline information in the
119 ;; PostScript image, so the printed image can look as pretty as the
120 ;; buffer. The ps-print- commands without the -with-faces suffix
121 ;; don't include font, color, or underline information; images printed
122 ;; with these commands aren't as pretty, but are faster to generate.
124 ;; Two ps-print- command examples:
126 ;; ps-print-buffer - print the entire buffer,
127 ;; without font, color, or
128 ;; underline information, and
129 ;; send it immediately to the
132 ;; ps-spool-region-with-faces - print just the current region;
133 ;; include font, color, and
134 ;; underline information, and
135 ;; spool the image in Emacs to
136 ;; send to the printer later.
142 ;; To print your buffer, type
144 ;; M-x ps-print-buffer
146 ;; or substitute one of the other seven ps-print- commands. The
147 ;; command will generate the PostScript image and print or spool it as
148 ;; specified. By giving the command a prefix argument
150 ;; C-u M-x ps-print-buffer
152 ;; it will save the PostScript image to a file instead of sending it
153 ;; to the printer; you will be prompted for the name of the file to
154 ;; save the image to. The prefix argument is ignored by the commands
155 ;; that spool their images, but you may save the spooled images to a
156 ;; file by giving a prefix argument to `ps-despool':
158 ;; C-u M-x ps-despool
160 ;; When invoked this way, `ps-despool' will prompt you for the name of
161 ;; the file to save to.
163 ;; Any of the `ps-print-' commands can be bound to keys; I recommend
164 ;; binding `ps-spool-buffer-with-faces', `ps-spool-region-with-faces',
165 ;; and `ps-despool'. Here are the bindings I use on my Sun 4 keyboard:
167 ;; (global-set-key 'f22 'ps-spool-buffer-with-faces) ;f22 is prsc
168 ;; (global-set-key '(shift f22) 'ps-spool-region-with-faces)
169 ;; (global-set-key '(control f22) 'ps-despool)
172 ;; The Printer Interface
173 ;; ---------------------
175 ;; The variables `ps-lpr-command' and `ps-lpr-switches' determine what
176 ;; command is used to send the PostScript images to the printer, and
177 ;; what arguments to give the command. These are analogous to
178 ;; `lpr-command' and `lpr-switches'.
180 ;; Make sure that they contain appropriate values for your system;
181 ;; see the usage notes below and the documentation of these variables.
183 ;; NOTE: `ps-lpr-command' and `ps-lpr-switches' take their initial values
184 ;; from the variables `lpr-command' and `lpr-switches'. If you have
185 ;; `lpr-command' set to invoke a pretty-printer such as `enscript',
186 ;; then ps-print won't work properly. `ps-lpr-command' must name
187 ;; a program that does not format the files it prints.
193 ;; All dimensions are floats in PostScript points.
194 ;; 1 inch == 2.54 cm == 72 points
195 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
197 ;; The variable `ps-paper-type' determines the size of paper ps-print
198 ;; formats for; it should contain one of the symbols:
199 ;; `a4' `a3' `letter' `legal' `letter-small' `tabloid'
200 ;; `ledger' `statement' `executive' `a4small' `b4' `b5'
202 ;; The variable `ps-landscape-mode' determines the orientation
203 ;; of the printing on the page:
204 ;; nil means `portrait' mode, non-nil means `landscape' mode.
205 ;; There is no oblique mode yet, though this is easy to do in ps.
207 ;; In landscape mode, the text is NOT scaled: you may print 70 lines
208 ;; in portrait mode and only 50 lignes in landscape mode.
209 ;; The margins represent margins in the printed paper:
210 ;; the top margin is the margin between the top of the page
211 ;; and the printed header, whatever the orientation is.
213 ;; The variable `ps-number-of-columns' determines the number of columns
214 ;; both in landscape and portrait mode.
216 ;; - (the standard) one column portrait mode
217 ;; - (my favorite) two columns landscape mode (which spares trees)
219 ;; - one column landscape mode for files with very long lines.
220 ;; - multi-column portrait or landscape mode
226 ;; The horizontal layout is determined by the variables
227 ;; `ps-left-margin' `ps-inter-column' `ps-right-margin'
230 ;; ------------------------------------------
232 ;; | lm | text | ic | text | ic | text | rm |
234 ;; ------------------------------------------
236 ;; If `ps-number-of-columns' is 1, `ps-inter-column' is not relevant.
237 ;; Usually, lm = rm > 0 and ic = lm
238 ;; If (ic < 0), the text of adjacent columns can overlap.
244 ;; The vertical layout is determined by the variables
245 ;; `ps-bottom-margin' `ps-top-margin' `ps-header-offset'
248 ;; |--------| |--------|
250 ;; |--------| |--------|
254 ;; |--------| or | text |
258 ;; |--------| |--------|
260 ;; |--------| |--------|
262 ;; If `ps-print-header' is nil, `ps-header-offset' is not relevant.
263 ;; The margins represent margins in the printed paper:
264 ;; the top margin is the margin between the top of the page
265 ;; and the printed header, whatever the orientation is.
271 ;; Ps-print can print headers at the top of each column; the default
272 ;; headers contain the following four items: on the left, the name of
273 ;; the buffer and, if the buffer is visiting a file, the file's
274 ;; directory; on the right, the page number and date of printing.
275 ;; The default headers look something like this:
278 ;; /home/jct/emacs-lisp/ps/new 94/12/31
280 ;; When printing on duplex printers, left and right are reversed so
281 ;; that the page numbers are toward the outside (cf. `ps-spool-duplex').
283 ;; Headers are configurable:
284 ;; To turn them off completely, set `ps-print-header' to nil.
285 ;; To turn off the header's gaudy framing box,
286 ;; set `ps-print-header-frame' to nil.
288 ;; The font family and size of text in the header are determined
289 ;; by the variables `ps-header-font-family', `ps-header-font-size' and
290 ;; `ps-header-title-font-size' (see below).
292 ;; The variable `ps-header-line-pad' determines the portion of a header
293 ;; title line height to insert between the header frame and the text
294 ;; it contains, both in the vertical and horizontal directions:
295 ;; .5 means half a line.
297 ;; Page numbers are printed in `n/m' format, indicating page n of m pages;
298 ;; to omit the total page count and just print the page number,
299 ;; set `ps-show-n-of-n' to nil.
301 ;; The amount of information in the header can be changed by changing
302 ;; the number of lines. To show less, set `ps-header-lines' to 1, and
303 ;; the header will show only the buffer name and page number. To show
304 ;; more, set `ps-header-lines' to 3, and the header will show the time of
305 ;; printing below the date.
307 ;; To change the content of the headers, change the variables
308 ;; `ps-left-header' and `ps-right-header'.
309 ;; These variables are lists, specifying top-to-bottom the text
310 ;; to display on the left or right side of the header.
311 ;; Each element of the list should be a string or a symbol.
312 ;; Strings are inserted directly into the PostScript arrays,
313 ;; and should contain the PostScript string delimiters '(' and ')'.
315 ;; Symbols in the header format lists can either represent functions
316 ;; or variables. Functions are called, and should return a string to
317 ;; show in the header. Variables should contain strings to display in
318 ;; the header. In either case, function or variable, the PostScript
319 ;; string delimiters are added by ps-print, and should not be part of
320 ;; the returned value.
322 ;; Here's an example: say we want the left header to display the text
328 ;; where we have a function to return "Moe"
330 ;; (defun moe-func ()
333 ;; a variable specifying "Larry"
335 ;; (setq larry-var "Larry")
337 ;; and a literal for "Curly". Here's how `ps-left-header' should be
340 ;; (setq ps-left-header (list 'moe-func 'larry-var "(Curly)"))
342 ;; Note that Curly has the PostScript string delimiters inside his
343 ;; quotes -- those aren't misplaced lisp delimiters!
345 ;; Without them, PostScript would attempt to call the undefined
346 ;; function Curly, which would result in a PostScript error.
348 ;; Since most printers don't report PostScript errors except by
349 ;; aborting the print job, this kind of error can be hard to track down.
351 ;; Consider yourself warned!
357 ;; If you have a duplex-capable printer (one that prints both sides of
358 ;; the paper), set `ps-spool-duplex' to t.
359 ;; Ps-print will insert blank pages to make sure each buffer starts
360 ;; on the correct side of the paper.
361 ;; Don't forget to set `ps-lpr-switches' to select duplex printing
368 ;; The variable `ps-line-number' specifies whether to number each line;
369 ;; non-nil means do so. The default is nil (don't number each line).
375 ;; Zebra stripes are a kind of background that appear "underneath" the text
376 ;; and can make the text easier to read. They look like this:
378 ;; XXXXXXXXXXXXXXXXXXXXXXXX
379 ;; XXXXXXXXXXXXXXXXXXXXXXXX
380 ;; XXXXXXXXXXXXXXXXXXXXXXXX
384 ;; XXXXXXXXXXXXXXXXXXXXXXXX
385 ;; XXXXXXXXXXXXXXXXXXXXXXXX
386 ;; XXXXXXXXXXXXXXXXXXXXXXXX
388 ;; The X's here represent rectangles filled with a light gray color.
389 ;; Each rectangle extends all the way across the page.
391 ;; The height, in lines, of each rectangle is controlled by
392 ;; the variable `ps-zebra-stripe-height', which is 3 by default.
393 ;; The distance between stripes equals the height of a stripe.
395 ;; The variable `ps-zebra-stripes' controls whether to print zebra stripes.
396 ;; Non-nil means yes, nil means no. The default is nil.
398 ;; See also section How Ps-Print Has A Text And/Or Image On Background.
404 ;; Ps-print now knows rather precisely some fonts:
405 ;; the variable `ps-font-info-database' contains information
406 ;; for a list of font families (currently mainly `Courier' `Helvetica'
407 ;; `Times' `Palatino' `Helvetica-Narrow' `NewCenturySchlbk').
408 ;; Each font family contains the font names for standard, bold, italic
409 ;; and bold-italic characters, a reference size (usually 10) and the
410 ;; corresponding line height, width of a space and average character width.
412 ;; The variable `ps-font-family' determines which font family
413 ;; is to be used for ordinary text.
414 ;; If its value does not correspond to a known font family,
415 ;; an error message is printed into the `*Messages*' buffer,
416 ;; which lists the currently available font families.
418 ;; The variable `ps-font-size' determines the size (in points)
419 ;; of the font for ordinary text, when generating Postscript.
420 ;; Its value is a float.
422 ;; Similarly, the variable `ps-header-font-family' determines
423 ;; which font family is to be used for text in the header.
424 ;; The variable `ps-header-font-size' determines the font size,
425 ;; in points, for text in the header.
426 ;; The variable `ps-header-title-font-size' determines the font size,
427 ;; in points, for the top line of text in the header.
430 ;; Adding a new font family
431 ;; ------------------------
433 ;; To use a new font family, you MUST first teach ps-print
434 ;; this font, i.e., add its information to `ps-font-info-database',
435 ;; otherwise ps-print cannot correctly place line and page breaks.
437 ;; For example, assuming `Helvetica' is unknown,
438 ;; you first need to do the following ONLY ONCE:
440 ;; - create a new buffer
441 ;; - generate the PostScript image to a file (C-u M-x ps-print-buffer)
442 ;; - open this file and find the line:
443 ;; `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
444 ;; - delete the leading `%' (which is the PostScript comment character)
445 ;; - replace in this line `Courier' by the new font (say `Helvetica')
447 ;; `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
448 ;; - send this file to the printer (or to ghostscript).
449 ;; You should read the following on the output page:
451 ;; For Helvetica 10 point, the line height is 11.56, the space width is 2.78
452 ;; and a crude estimate of average character width is 5.09243
454 ;; - Add these values to the `ps-font-info-database':
455 ;; (setq ps-font-info-database
457 ;; '((Helvetica ; the family name
458 ;; "Helvetica" "Helvetica-Bold" "Helvetica-Oblique" "Helvetica-BoldOblique"
459 ;; 10.0 11.56 2.78 5.09243))
460 ;; ps-font-info-database))
461 ;; - Now you can use this font family with any size:
462 ;; (setq ps-font-family 'Helvetica)
463 ;; - if you want to use this family in another emacs session, you must
464 ;; put into your `~/.emacs':
465 ;; (require 'ps-print)
466 ;; (setq ps-font-info-database (append ...)))
467 ;; if you don't want to load ps-print, you have to copy the whole value:
468 ;; (setq ps-font-info-database '(<your stuff> <the standard stuff>))
469 ;; or, if you can wait until the `ps-print-hook' is implemented, do:
470 ;; (add-hook 'ps-print-hook '(setq ps-font-info-database (append ...)))
471 ;; This does not work yet, since there is no `ps-print-hook' yet.
473 ;; You can create new `mixed' font families like:
475 ;; "Courier-Bold" "Helvetica"
476 ;; "Zapf-Chancery-MediumItalic" "NewCenturySchlbk-BoldItalic"
477 ;; 10.0 10.55 6.0 6.0)
478 ;; Now you can use your new font family with any size:
479 ;; (setq ps-font-family 'my-mixed-family)
481 ;; You can get information on all the fonts resident in YOUR printer
482 ;; by uncommenting the line:
483 ;; % 3 cm 20 cm moveto ReportAllFontInfo showpage
485 ;; The PostScript file should be sent to YOUR PostScript printer.
486 ;; If you send it to ghostscript or to another PostScript printer,
487 ;; you may get slightly different results.
488 ;; Anyway, as ghostscript fonts are autoload, you won't get
492 ;; How Ps-Print Deals With Faces
493 ;; -----------------------------
495 ;; The ps-print-*-with-faces commands attempt to determine which faces
496 ;; should be printed in bold or italic, but their guesses aren't
497 ;; always right. For example, you might want to map colors into faces
498 ;; so that blue faces print in bold, and red faces in italic.
500 ;; It is possible to force ps-print to consider specific faces bold or
501 ;; italic, no matter what font they are displayed in, by setting the
502 ;; variables `ps-bold-faces' and `ps-italic-faces'. These variables
503 ;; contain lists of faces that ps-print should consider bold or
504 ;; italic; to set them, put code like the following into your .emacs
507 ;; (setq ps-bold-faces '(my-blue-face))
508 ;; (setq ps-italic-faces '(my-red-face))
510 ;; Faces like bold-italic that are both bold and italic should go in
513 ;; Ps-print keeps internal lists of which fonts are bold and which are
514 ;; italic; these lists are built the first time you invoke ps-print.
515 ;; For the sake of efficiency, the lists are built only once; the same
516 ;; lists are referred in later invocations of ps-print.
518 ;; Because these lists are built only once, it's possible for them to
519 ;; get out of sync, if a face changes, or if new faces are added. To
520 ;; get the lists back in sync, you can set the variable
521 ;; `ps-build-face-reference' to t, and the lists will be rebuilt the
522 ;; next time ps-print is invoked.
525 ;; How Ps-Print Deals With Color
526 ;; -----------------------------
528 ;; Ps-print detects faces with foreground and background colors
529 ;; defined and embeds color information in the PostScript image.
530 ;; The default foreground and background colors are defined by the
531 ;; variables `ps-default-fg' and `ps-default-bg'.
532 ;; On black-and-white printers, colors are displayed in grayscale.
533 ;; To turn off color output, set `ps-print-color-p' to nil.
536 ;; How Ps-Print Maps Faces
537 ;; -----------------------
539 ;; As ps-print uses PostScript to print buffers, it is possible to have
540 ;; other attributes associated with faces. So the new attributes used
543 ;; strikeout - like underline, but the line is in middle of text.
544 ;; overline - like underline, but the line is over the text.
545 ;; shadow - text will have a shadow.
546 ;; box - text will be surrounded by a box.
547 ;; outline - print characters as hollow outlines.
549 ;; See the documentation for `ps-extend-face' and `ps-extend-face-list'.
551 ;; Let's, for example, remap font-lock-keyword-face to another foreground color
552 ;; and bold attribute:
554 ;; (ps-extend-face '(font-lock-keyword-face "RoyalBlue" nil bold) 'MERGE)
556 ;; If you want to use a new face, define it first with `defface',
557 ;; and then call `ps-extend-face' to specify how to print it.
559 ;; NOTE: the only face attributes that have an effect are bold, italic and
560 ;; underline. All other attributes are ignored.
563 ;; How Ps-Print Has A Text And/Or Image On Background
564 ;; --------------------------------------------------
566 ;; Ps-print can print texts and/or EPS PostScript images on background; it is
567 ;; possible to define the following text attributes: font name, font size,
568 ;; initial position, angle, gray scale and pages to print.
570 ;; It has the following EPS PostScript images attributes: file name containing
571 ;; the image, initial position, X and Y scales, angle and pages to print.
573 ;; See documentation for `ps-print-background-text' and
574 ;; `ps-print-background-image'.
576 ;; For example, if we wish to print text "preliminary" on all pages and text
577 ;; "special" on page 5 and from page 11 to page 17, we could specify:
579 ;; (setq ps-print-background-text
582 ;; "LeftMargin" "BottomMargin PrintHeight add" ; X and Y position
583 ;; ; (upper left corner)
585 ;; "PrintHeight neg PrintWidth atan" ; angle
586 ;; 5 (11 . 17)) ; page list
589 ;; Similarly, we could print image "~/images/EPS-image1.ps" on all pages and
590 ;; image "~/images/EPS-image2.ps" on page 5 and from page 11 to page 17, we
593 ;; (setq ps-print-background-image
594 ;; '(("~/images/EPS-image1.ps"
595 ;; "LeftMargin" "BottomMargin") ; X and Y position (lower left corner)
596 ;; ("~/images/EPS-image2.ps"
597 ;; "LeftMargin" "BottomMargin PrintHeight 2 div add" ; X and Y position
598 ;; ; (upper left corner)
600 ;; 5 (11 . 17)) ; page list
603 ;; If it is not possible to read (or does not exist) an image file, that file
606 ;; The printing order is:
608 ;; 1. Print zebra stripes
609 ;; 2. Print background texts that it should be on all pages
610 ;; 3. Print background images that it should be on all pages
611 ;; 4. Print background texts only for current page (if any)
612 ;; 5. Print background images only for current page (if any)
614 ;; 7. Print buffer text (with faces, if specified) and line number
620 ;; Some tools are provided to help you customize your font setup.
622 ;; `ps-setup' returns (some part of) the current setup.
624 ;; To avoid wrapping too many lines, you may want to adjust the
625 ;; left and right margins and the font size. On UN*X systems, do:
626 ;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
627 ;; to determine the longest lines of your file.
628 ;; Then, the command `ps-line-lengths' will give you the correspondence
629 ;; between a line length (number of characters) and the maximum font
630 ;; size which doesn't wrap such a line with the current ps-print setup.
632 ;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
633 ;; the correspondence between a number of pages and the maximum font
634 ;; size which allow the number of lines of the current buffer or of
635 ;; its current region to fit in this number of pages.
637 ;; NOTE: line folding is not taken into account in this process and could
638 ;; change the results.
641 ;; New since version 1.5
642 ;; ---------------------
644 ;; Color output capability.
645 ;; Automatic detection of font attributes (bold, italic).
646 ;; Configurable headers with page numbers.
648 ;; Support for different paper sizes.
649 ;; Better conformance to PostScript Document Structure Conventions.
652 ;; New since version 2.8
653 ;; ---------------------
655 ;; [vinicius] 970809 Vinicius Jose Latorre <vinicius@cpqd.br>
657 ;; Handle control characters.
659 ;; New face attributes.
662 ;; Text and/or image on background.
664 ;; [jack] 960517 Jacques Duthen <duthen@cegelec-red.fr>
666 ;; Font family and float size for text and header.
669 ;; Tools for page setup.
672 ;; Known bugs and limitations of ps-print:
673 ;; --------------------------------------
675 ;; Although color printing will work in XEmacs 19.12, it doesn't work
676 ;; well; in particular, bold or italic fonts don't print in the right
679 ;; Invisible properties aren't correctly ignored in XEmacs 19.12.
681 ;; Automatic font-attribute detection doesn't work well, especially
682 ;; with hilit19 and older versions of get-create-face. Users having
683 ;; problems with auto-font detection should use the lists
684 ;; `ps-italic-faces' and `ps-bold-faces' and/or turn off automatic
685 ;; detection by setting `ps-auto-font-detect' to nil.
687 ;; Automatic font-attribute detection doesn't work with XEmacs 19.12
688 ;; in tty mode; use the lists `ps-italic-faces' and `ps-bold-faces'
691 ;; Still too slow; could use some hand-optimization.
693 ;; Default background color isn't working.
695 ;; Faces are always treated as opaque.
697 ;; Epoch and Emacs 18 not supported. At all.
699 ;; Fixed-pitch fonts work better for line folding, but are not required.
701 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' don't take care
708 ;; Add `ps-print-hook' (I don't know how to do that (yet!)).
709 ;; Add 4-up capability (really needed?).
710 ;; Add `ps-non-bold-faces' and `ps-non-italic-faces' (should be easy).
711 ;; Put one header per page over the columns (easy but needed?).
712 ;; Improve the memory management for big files (hard?).
713 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' should take care
719 ;; Thanks to Jim Thompson <?@?> for the 2.8 version I started from.
722 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for adding support for
723 ;; color and the invisible property.
725 ;; Thanks to Avishai Yacobi, avishaiy@mcil.comm.mot.com, for writing
726 ;; the initial port to Emacs 19. His code is no longer part of
727 ;; ps-print, but his work is still appreciated.
729 ;; Thanks to Remi Houdaille and Michel Train, michel@metasoft.fdn.org,
730 ;; for adding underline support. Their code also is no longer part of
731 ;; ps-print, but their efforts are not forgotten.
733 ;; Thanks also to all of you who mailed code to add features to
734 ;; ps-print; although I didn't use your code, I still appreciate your
735 ;; sharing it with me.
737 ;; Thanks to all who mailed comments, encouragement, and criticism.
738 ;; Thanks also to all who responded to my survey; I had too many
739 ;; responses to reply to them all, but I greatly appreciate your
743 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
750 (unless (featurep 'lisp-float-type
)
751 (error "`ps-print' requires floating point support"))
753 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
756 ;;; Interface to the command system
758 (defgroup ps-print nil
759 "Postscript generator for Emacs 19"
763 (defgroup ps-print-horizontal nil
764 "Horizontal page layout"
769 (defgroup ps-print-vertical nil
770 "Vertical page layout"
775 (defgroup ps-print-header nil
781 (defgroup ps-print-font nil
782 "Fonts customization"
787 (defgroup ps-print-color nil
788 "Color customization"
793 (defgroup ps-print-face nil
794 "Faces customization"
801 (defcustom ps-lpr-command lpr-command
802 "*The shell command for printing a PostScript file."
806 (defcustom ps-lpr-switches lpr-switches
807 "*A list of extra switches to pass to `ps-lpr-command'."
808 :type
'(repeat string
)
813 ;; All page dimensions are in PostScript points.
814 ;; 1 inch == 2.54 cm == 72 points
815 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
817 ;; Letter 8.5 inch x 11.0 inch
818 ;; Legal 8.5 inch x 14.0 inch
819 ;; A4 8.26 inch x 11.69 inch = 21.0 cm x 29.7 cm
821 ;; LetterSmall 7.68 inch x 10.16 inch
822 ;; Tabloid 11.0 inch x 17.0 inch
823 ;; Ledger 17.0 inch x 11.0 inch
824 ;; Statement 5.5 inch x 8.5 inch
825 ;; Executive 7.5 inch x 10.0 inch
826 ;; A3 11.69 inch x 16.5 inch = 29.7 cm x 42.0 cm
827 ;; A4Small 7.47 inch x 10.85 inch
828 ;; B4 10.125 inch x 14.33 inch
829 ;; B5 7.16 inch x 10.125 inch
831 (defcustom ps-page-dimensions-database
832 (list (list 'a4
(/ (* 72 21.0) 2.54) (/ (* 72 29.7) 2.54))
833 (list 'a3
(/ (* 72 29.7) 2.54) (/ (* 72 42.0) 2.54))
834 (list 'letter
(* 72 8.5) (* 72 11.0))
835 (list 'legal
(* 72 8.5) (* 72 14.0))
836 (list 'letter-small
(* 72 7.68) (* 72 10.16))
837 (list 'tabloid
(* 72 11.0) (* 72 17.0))
838 (list 'ledger
(* 72 17.0) (* 72 11.0))
839 (list 'statement
(* 72 5.5) (* 72 8.5))
840 (list 'executive
(* 72 7.5) (* 72 10.0))
841 (list 'a4small
(* 72 7.47) (* 72 10.85))
842 (list 'b4
(* 72 10.125) (* 72 14.33))
843 (list 'b5
(* 72 7.16) (* 72 10.125)))
844 "*List associating a symbolic paper type to its width and height.
845 see `ps-paper-type'."
846 :type
'(repeat (list :tag
"Paper Type"
848 (number :tag
"Width")
849 (number :tag
"Height")))
852 (defcustom ps-paper-type
'letter
853 "*Specifies the size of paper to format for.
854 Should be one of the paper types defined in `ps-page-dimensions-database', for
855 example `letter', `legal' or `a4'."
856 :type
'(symbol :validate
(lambda (wid)
857 (if (assq (widget-value wid
)
858 ps-page-dimensions-database
)
860 (widget-put wid
:error
"Unknown paper size")
864 (defcustom ps-landscape-mode nil
865 "*Non-nil means print in landscape mode."
869 (defcustom ps-number-of-columns
(if ps-landscape-mode
2 1)
870 "*Specifies the number of columns"
874 (defcustom ps-zebra-stripes nil
875 "*Non-nil means print zebra stripes.
876 See also documentation for `ps-print-n-zebra'."
880 (defcustom ps-zebra-stripe-height
3
881 "*Number of zebra stripe lines.
882 See also documentation for `ps-print-zebra'."
886 (defcustom ps-line-number nil
887 "*Non-nil means print line number."
891 (defcustom ps-print-background-image nil
892 "*EPS image list to be printed on background.
896 (FILENAME X Y XSCALE YSCALE ROTATION PAGES...)
898 FILENAME is a file name which contains an EPS image or some PostScript
899 programming like EPS.
900 FILENAME is ignored, if it doesn't exist or is read protected.
902 X and Y are relative positions on paper to put the image.
903 If X and Y are nil, the image is centralized on paper.
905 XSCALE and YSCALE are scale factor to be applied to image before printing.
906 If XSCALE and YSCALE are nil, the original size is used.
908 ROTATION is the image rotation angle; if nil, the default is 0.
910 PAGES designates the page to print background image.
911 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
913 If PAGES is nil, print background image on all pages.
915 X, Y, XSCALE, YSCALE and ROTATION may be a floating point number,
916 an integer number or a string. If it is a string, the string should contain
917 PostScript programming that returns a float or integer value.
919 For example, if you wish to print an EPS image on all pages do:
921 '((\"~/images/EPS-image.ps\"))"
925 (defcustom ps-print-background-text nil
926 "*Text list to be printed on background.
930 (STRING X Y FONT FONTSIZE GRAY ROTATION PAGES...)
932 STRING is the text to be printed on background.
934 X and Y are positions on paper to put the text.
935 If X and Y are nil, the text is positioned at lower left corner.
937 FONT is a font name to be used on printing the text.
938 If nil, \"Times-Roman\" is used.
940 FONTSIZE is font size to be used, if nil, 200 is used.
942 GRAY is the text gray factor (should be very light like 0.8).
943 If nil, the default is 0.85.
945 ROTATION is the text rotation angle; if nil, the angle is given by
946 the diagonal from lower left corner to upper right corner.
948 PAGES designates the page to print background text.
949 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
951 If PAGES is nil, print background text on all pages.
953 X, Y, FONTSIZE, GRAY and ROTATION may be a floating point number,
954 an integer number or a string. If it is a string, the string should contain
955 PostScript programming that returns a float or integer value.
957 For example, if you wish to print text \"Preliminary\" on all pages do:
959 '((\"Preliminary\"))"
963 ;;; Horizontal layout
965 ;; ------------------------------------------
967 ;; | lm | text | ic | text | ic | text | rm |
969 ;; ------------------------------------------
971 (defcustom ps-left-margin
(/ (* 72 2.0) 2.54) ; 2 cm
972 "*Left margin in points (1/72 inch)."
974 :group
'ps-print-horizontal
)
976 (defcustom ps-right-margin
(/ (* 72 2.0) 2.54) ; 2 cm
977 "*Right margin in points (1/72 inch)."
979 :group
'ps-print-horizontal
)
981 (defcustom ps-inter-column
(/ (* 72 2.0) 2.54) ; 2 cm
982 "*Horizontal space between columns in points (1/72 inch)."
984 :group
'ps-print-horizontal
)
1000 (defcustom ps-bottom-margin
(/ (* 72 1.5) 2.54) ; 1.5 cm
1001 "*Bottom margin in points (1/72 inch)."
1003 :group
'ps-print-vertical
)
1005 (defcustom ps-top-margin
(/ (* 72 1.5) 2.54) ; 1.5 cm
1006 "*Top margin in points (1/72 inch)."
1008 :group
'ps-print-vertical
)
1010 (defcustom ps-header-offset
(/ (* 72 1.0) 2.54) ; 1.0 cm
1011 "*Vertical space in points (1/72 inch) between the main text and the header."
1013 :group
'ps-print-vertical
)
1015 (defcustom ps-header-line-pad
0.15
1016 "*Portion of a header title line height to insert between the header frame
1017 and the text it contains, both in the vertical and horizontal directions."
1019 :group
'ps-print-vertical
)
1023 (defcustom ps-print-header t
1024 "*Non-nil means print a header at the top of each page.
1025 By default, the header displays the buffer name, page number, and, if
1026 the buffer is visiting a file, the file's directory. Headers are
1027 customizable by changing variables `ps-left-header' and
1030 :group
'ps-print-header
)
1032 (defcustom ps-print-header-frame t
1033 "*Non-nil means draw a gaudy frame around the header."
1035 :group
'ps-print-header
)
1037 (defcustom ps-header-lines
2
1038 "*Number of lines to display in page header, when generating Postscript."
1040 :group
'ps-print-header
)
1041 (make-variable-buffer-local 'ps-header-lines
)
1043 (defcustom ps-show-n-of-n t
1044 "*Non-nil means show page numbers as N/M, meaning page N of M.
1045 Note: page numbers are displayed as part of headers, see variable
1046 `ps-print-headers'."
1048 :group
'ps-print-header
)
1050 (defcustom ps-spool-duplex nil
; Not many people have duplex
1051 ; printers, so default to nil.
1052 "*Non-nil indicates spooling is for a two-sided printer.
1053 For a duplex printer, the `ps-spool-*' commands will insert blank pages
1054 as needed between print jobs so that the next buffer printed will
1055 start on the right page. Also, if headers are turned on, the headers
1056 will be reversed on duplex printers so that the page numbers fall to
1057 the left on even-numbered pages."
1059 :group
'ps-print-header
)
1063 (defcustom ps-font-info-database
1064 '((Courier ; the family key
1065 "Courier" "Courier-Bold" "Courier-Oblique" "Courier-BoldOblique"
1067 (Helvetica ; the family key
1068 "Helvetica" "Helvetica-Bold" "Helvetica-Oblique" "Helvetica-BoldOblique"
1069 10.0 11.56 2.78 5.09243)
1071 "Times-Roman" "Times-Bold" "Times-Italic" "Times-BoldItalic"
1072 10.0 11.0 2.5 4.71432)
1074 "Palatino-Roman" "Palatino-Bold" "Palatino-Italic" "Palatino-BoldItalic"
1075 10.0 12.1 2.5 5.08676)
1077 "Helvetica-Narrow" "Helvetica-Narrow-Bold"
1078 "Helvetica-Narrow-Oblique" "Helvetica-Narrow-BoldOblique"
1079 10.0 11.56 2.2796 4.17579)
1081 "NewCenturySchlbk-Roman" "NewCenturySchlbk-Bold"
1082 "NewCenturySchlbk-Italic" "NewCenturySchlbk-BoldItalic"
1083 10.0 12.15 2.78 5.31162)
1084 ;; got no bold for the next ones
1086 "AvantGarde-Book" "AvantGarde-Book"
1087 "AvantGarde-BookOblique" "AvantGarde-BookOblique"
1088 10.0 11.77 2.77 5.45189)
1090 "AvantGarde-Demi" "AvantGarde-Demi"
1091 "AvantGarde-DemiOblique" "AvantGarde-DemiOblique"
1092 10.0 12.72 2.8 5.51351)
1094 "Bookman-Demi" "Bookman-Demi"
1095 "Bookman-DemiItalic" "Bookman-DemiItalic"
1096 10.0 11.77 3.4 6.05946)
1098 "Bookman-Light" "Bookman-Light"
1099 "Bookman-LightItalic" "Bookman-LightItalic"
1100 10.0 11.79 3.2 5.67027)
1101 ;; got no bold and no italic for the next ones
1103 "Symbol" "Symbol" "Symbol" "Symbol"
1104 10.0 13.03 2.5 3.24324)
1106 "Zapf-Dingbats" "Zapf-Dingbats" "Zapf-Dingbats" "Zapf-Dingbats"
1107 10.0 9.63 2.78 2.78)
1108 (Zapf-Chancery-MediumItalic
1109 "Zapf-Chancery-MediumItalic" "Zapf-Chancery-MediumItalic"
1110 "Zapf-Chancery-MediumItalic" "Zapf-Chancery-MediumItalic"
1111 10.0 11.45 2.2 4.10811)
1113 "*Font info database: font family (the key), name, bold, italic, bold-italic,
1114 reference size, line height, space width, average character width.
1115 To get the info for another specific font (say Helvetica), do the following:
1116 - create a new buffer
1117 - generate the PostScript image to a file (C-u M-x ps-print-buffer)
1118 - open this file and delete the leading `%' (which is the Postscript
1119 comment character) from the line
1120 `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
1122 `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
1123 - add the values to `ps-font-info-database'.
1124 You can get all the fonts of YOUR printer using `ReportAllFontInfo'."
1125 :type
'(repeat (list :tag
"Font Definition"
1126 (symbol :tag
"Font")
1127 (string :tag
"Name")
1128 (string :tag
"Bold")
1129 (string :tag
"Italic")
1130 (string :tag
"Bold-Italic")
1131 (number :tag
"Reference Size")
1132 (number :tag
"Line Height")
1133 (number :tag
"Space Width")
1134 (number :tag
"Average Character Width")))
1135 :group
'ps-print-font
)
1137 (defcustom ps-font-family
'Courier
1138 "Font family name for ordinary text, when generating Postscript."
1140 :group
'ps-print-font
)
1142 (defcustom ps-font-size
(if ps-landscape-mode
7 8.5)
1143 "Font size, in points, for ordinary text, when generating Postscript."
1145 :group
'ps-print-font
)
1147 (defcustom ps-header-font-family
'Helvetica
1148 "Font family name for text in the header, when generating Postscript."
1150 :group
'ps-print-font
)
1152 (defcustom ps-header-font-size
(if ps-landscape-mode
10 12)
1153 "Font size, in points, for text in the header, when generating Postscript."
1155 :group
'ps-print-font
)
1157 (defcustom ps-header-title-font-size
(if ps-landscape-mode
12 14)
1158 "Font size, in points, for the top line of text in the header,
1159 when generating Postscript."
1161 :group
'ps-print-font
)
1165 ;; Printing color requires x-color-values.
1166 (defcustom ps-print-color-p
(or (fboundp 'x-color-values
) ; Emacs
1167 (fboundp 'pixel-components
)) ; XEmacs
1168 "*If non-nil, print the buffer's text in color."
1170 :group
'ps-print-color
)
1172 (defcustom ps-default-fg
'(0.0
0.0 0.0)
1173 "*RGB values of the default foreground color. Defaults to black."
1174 :type
'(list (number :tag
"Red") (number :tag
"Green") (number :tag
"Blue"))
1175 :group
'ps-print-color
)
1177 (defcustom ps-default-bg
'(1.0
1.0 1.0)
1178 "*RGB values of the default background color. Defaults to white."
1179 :type
'(list (number :tag
"Red") (number :tag
"Green") (number :tag
"Blue"))
1180 :group
'ps-print-color
)
1182 (defcustom ps-auto-font-detect t
1183 "*Non-nil means automatically detect bold/italic face attributes.
1184 nil means rely solely on the lists `ps-bold-faces', `ps-italic-faces',
1185 and `ps-underlined-faces'."
1187 :group
'ps-print-font
)
1189 (defcustom ps-bold-faces
1190 (unless ps-print-color-p
1191 '(font-lock-function-name-face
1192 font-lock-builtin-face
1193 font-lock-variable-name-face
1194 font-lock-keyword-face
1195 font-lock-warning-face
))
1196 "*A list of the \(non-bold\) faces that should be printed in bold font.
1197 This applies to generating Postscript."
1198 :type
'(repeat face
)
1199 :group
'ps-print-face
)
1201 (defcustom ps-italic-faces
1202 (unless ps-print-color-p
1203 '(font-lock-variable-name-face
1204 font-lock-string-face
1205 font-lock-comment-face
1206 font-lock-warning-face
))
1207 "*A list of the \(non-italic\) faces that should be printed in italic font.
1208 This applies to generating Postscript."
1209 :type
'(repeat face
)
1210 :group
'ps-print-face
)
1212 (defcustom ps-underlined-faces
1213 (unless ps-print-color-p
1214 '(font-lock-function-name-face
1216 font-lock-reference-face
1217 font-lock-warning-face
))
1218 "*A list of the \(non-underlined\) faces that should be printed underlined.
1219 This applies to generating Postscript."
1220 :type
'(repeat face
)
1221 :group
'ps-print-face
)
1223 (defcustom ps-left-header
1224 (list 'ps-get-buffer-name
'ps-header-dirpart
)
1225 "*The items to display (each on a line) on the left part of the page header.
1226 This applies to generating Postscript.
1228 The value should be a list of strings and symbols, each representing an
1229 entry in the PostScript array HeaderLinesLeft.
1231 Strings are inserted unchanged into the array; those representing
1232 PostScript string literals should be delimited with PostScript string
1233 delimiters '(' and ')'.
1235 For symbols with bound functions, the function is called and should
1236 return a string to be inserted into the array. For symbols with bound
1237 values, the value should be a string to be inserted into the array.
1238 In either case, function or variable, the string value has PostScript
1239 string delimiters added to it."
1240 :type
'(repeat (choice string symbol
))
1241 :group
'ps-print-header
)
1242 (make-variable-buffer-local 'ps-left-header
)
1244 (defcustom ps-right-header
1245 (list "/pagenumberstring load" 'time-stamp-mon-dd-yyyy
'time-stamp-hh
:mm
:ss
)
1246 "*The items to display (each on a line) on the right part of the page header.
1247 This applies to generating Postscript.
1249 See the variable `ps-left-header' for a description of the format of
1251 :type
'(repeat (choice string symbol
))
1252 :group
'ps-print-header
)
1253 (make-variable-buffer-local 'ps-right-header
)
1255 (defcustom ps-razzle-dazzle t
1256 "*Non-nil means report progress while formatting buffer."
1260 (defcustom ps-adobe-tag
"%!PS-Adobe-3.0\n"
1261 "*Contains the header line identifying the output as PostScript.
1262 By default, `ps-adobe-tag' contains the standard identifier. Some
1263 printers require slightly different versions of this line."
1267 (defcustom ps-build-face-reference t
1268 "*Non-nil means build the reference face lists.
1270 Ps-print sets this value to nil after it builds its internal reference
1271 lists of bold and italic faces. By settings its value back to t, you
1272 can force ps-print to rebuild the lists the next time you invoke one
1273 of the ...-with-faces commands.
1275 You should set this value back to t after you change the attributes of
1276 any face, or create new faces. Most users shouldn't have to worry
1277 about its setting, though."
1279 :group
'ps-print-face
)
1281 (defcustom ps-always-build-face-reference nil
1282 "*Non-nil means always rebuild the reference face lists.
1284 If this variable is non-nil, ps-print will rebuild its internal
1285 reference lists of bold and italic faces *every* time one of the
1286 -with-faces commands is called. Most users shouldn't need to set this
1289 :group
'ps-print-face
)
1291 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1295 (defun ps-print-buffer (&optional filename
)
1296 "Generate and print a PostScript image of the buffer.
1298 When called with a numeric prefix argument (C-u), prompts the user for
1299 the name of a file to save the PostScript image in, instead of sending
1302 More specifically, the FILENAME argument is treated as follows: if it
1303 is nil, send the image to the printer. If FILENAME is a string, save
1304 the PostScript image in a file with that name. If FILENAME is a
1305 number, prompt the user for the name of the file to save in."
1306 (interactive (list (ps-print-preprint current-prefix-arg
)))
1307 (ps-print-without-faces (point-min) (point-max) filename
))
1311 (defun ps-print-buffer-with-faces (&optional filename
)
1312 "Generate and print a PostScript image of the buffer.
1313 Like `ps-print-buffer', but includes font, color, and underline
1314 information in the generated image. This command works only if you
1315 are using a window system, so it has a way to determine color values."
1316 (interactive (list (ps-print-preprint current-prefix-arg
)))
1317 (ps-print-with-faces (point-min) (point-max) filename
))
1321 (defun ps-print-region (from to
&optional filename
)
1322 "Generate and print a PostScript image of the region.
1323 Like `ps-print-buffer', but prints just the current region."
1324 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg
)))
1325 (ps-print-without-faces from to filename t
))
1329 (defun ps-print-region-with-faces (from to
&optional filename
)
1330 "Generate and print a PostScript image of the region.
1331 Like `ps-print-region', but includes font, color, and underline
1332 information in the generated image. This command works only if you
1333 are using a window system, so it has a way to determine color values."
1334 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg
)))
1335 (ps-print-with-faces from to filename t
))
1339 (defun ps-spool-buffer ()
1340 "Generate and spool a PostScript image of the buffer.
1341 Like `ps-print-buffer' except that the PostScript image is saved in a
1342 local buffer to be sent to the printer later.
1344 Use the command `ps-despool' to send the spooled images to the printer."
1346 (ps-spool-without-faces (point-min) (point-max)))
1350 (defun ps-spool-buffer-with-faces ()
1351 "Generate and spool a PostScript image of the buffer.
1352 Like `ps-spool-buffer', but includes font, color, and underline
1353 information in the generated image. This command works only if you
1354 are using a window system, so it has a way to determine color values.
1356 Use the command `ps-despool' to send the spooled images to the printer."
1358 (ps-spool-with-faces (point-min) (point-max)))
1362 (defun ps-spool-region (from to
)
1363 "Generate a PostScript image of the region and spool locally.
1364 Like `ps-spool-buffer', but spools just the current region.
1366 Use the command `ps-despool' to send the spooled images to the printer."
1368 (ps-spool-without-faces from to t
))
1372 (defun ps-spool-region-with-faces (from to
)
1373 "Generate a PostScript image of the region and spool locally.
1374 Like `ps-spool-region', but includes font, color, and underline
1375 information in the generated image. This command works only if you
1376 are using a window system, so it has a way to determine color values.
1378 Use the command `ps-despool' to send the spooled images to the printer."
1380 (ps-spool-with-faces from to t
))
1383 (defun ps-despool (&optional filename
)
1384 "Send the spooled PostScript to the printer.
1386 When called with a numeric prefix argument (C-u), prompt the user for
1387 the name of a file to save the spooled PostScript in, instead of sending
1390 More specifically, the FILENAME argument is treated as follows: if it
1391 is nil, send the image to the printer. If FILENAME is a string, save
1392 the PostScript image in a file with that name. If FILENAME is a
1393 number, prompt the user for the name of the file to save in."
1394 (interactive (list (ps-print-preprint current-prefix-arg
)))
1395 (ps-do-despool filename
))
1398 (defun ps-line-lengths ()
1399 "*Display the correspondence between a line length and a font size,
1400 using the current ps-print setup.
1401 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
1403 (ps-line-lengths-internal))
1406 (defun ps-nb-pages-buffer (nb-lines)
1407 "*Display an approximate correspondence between a font size and the number
1408 of pages the current buffer would require to print
1409 using the current ps-print setup."
1410 (interactive (list (count-lines (point-min) (point-max))))
1411 (ps-nb-pages nb-lines
))
1414 (defun ps-nb-pages-region (nb-lines)
1415 "*Display an approximate correspondence between a font size and the number
1416 of pages the current region would require to print
1417 using the current ps-print setup."
1418 (interactive (list (count-lines (mark) (point))))
1419 (ps-nb-pages nb-lines
))
1423 "*Return the current setup"
1426 \(setq ps-print-color-p %s
1427 ps-lpr-command \"%s\"
1431 ps-landscape-mode %s
1432 ps-number-of-columns %s
1435 ps-zebra-stripe-height %s
1438 ps-print-background-image %s
1440 ps-print-background-text %s
1448 ps-header-line-pad %s
1450 ps-print-header-frame %s
1457 ps-header-font-family '%s
1458 ps-header-font-size %s
1459 ps-header-title-font-size %s)
1466 ps-number-of-columns
1468 ps-zebra-stripe-height
1470 ps-print-background-image
1471 ps-print-background-text
1480 ps-print-header-frame
1486 ps-header-font-family
1488 ps-header-title-font-size
))
1490 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1491 ;; Utility functions and variables:
1493 (defvar ps-print-emacs-type
1494 (cond ((string-match "XEmacs" emacs-version
) 'xemacs
)
1495 ((string-match "Lucid" emacs-version
) 'lucid
)
1496 ((string-match "Epoch" emacs-version
) 'epoch
)
1499 (if (or (eq ps-print-emacs-type
'lucid
)
1500 (eq ps-print-emacs-type
'xemacs
))
1501 (if (< emacs-minor-version
12)
1502 (setq ps-print-color-p nil
))
1503 (require 'faces
)) ; face-font, face-underline-p,
1506 (require 'time-stamp
)
1509 "Font family name for ordinary text, when generating Postscript.")
1511 (defvar ps-font-bold nil
1512 "Font family name for bold text, when generating Postscript.")
1514 (defvar ps-font-italic nil
1515 "Font family name for italic text, when generating Postscript.")
1517 (defvar ps-font-bold-italic nil
1518 "Font family name for bold italic text, when generating Postscript.")
1520 (defvar ps-avg-char-width nil
1521 "The average width, in points, of a character, for generating Postscript.
1522 This is the value that ps-print uses to determine the length,
1523 x-dimension, of the text it has printed, and thus affects the point at
1524 which long lines wrap around.")
1526 (defvar ps-space-width nil
1527 "The width of a space character, for generating Postscript.
1528 This value is used in expanding tab characters.")
1530 (defvar ps-line-height nil
1531 "The height of a line, for generating Postscript.
1532 This is the value that ps-print uses to determine the height,
1533 y-dimension, of the lines of text it has printed, and thus affects the
1534 point at which page-breaks are placed.
1535 The line-height is *not* the same as the point size of the font.")
1537 (defvar ps-print-prologue-1
1538 "% ISOLatin1Encoding stolen from ps_init.ps in GhostScript 2.6.1.4:
1539 /ISOLatin1Encoding where { pop } {
1540 % -- The ISO Latin-1 encoding vector isn't known, so define it.
1541 % -- The first half is the same as the standard encoding,
1542 % -- except for minus instead of hyphen at code 055.
1544 StandardEncoding 0 45 getinterval aload pop
1546 StandardEncoding 46 82 getinterval aload pop
1547 %*** NOTE: the following are missing in the Adobe documentation,
1548 %*** but appear in the displayed table:
1549 %*** macron at 0225, dieresis at 0230, cedilla at 0233, space at 0240.
1551 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
1552 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
1553 /dotlessi /grave /acute /circumflex /tilde /macron /breve /dotaccent
1554 /dieresis /.notdef /ring /cedilla /.notdef /hungarumlaut /ogonek /caron
1556 /space /exclamdown /cent /sterling
1557 /currency /yen /brokenbar /section
1558 /dieresis /copyright /ordfeminine /guillemotleft
1559 /logicalnot /hyphen /registered /macron
1560 /degree /plusminus /twosuperior /threesuperior
1561 /acute /mu /paragraph /periodcentered
1562 /cedilla /onesuperior /ordmasculine /guillemotright
1563 /onequarter /onehalf /threequarters /questiondown
1565 /Agrave /Aacute /Acircumflex /Atilde
1566 /Adieresis /Aring /AE /Ccedilla
1567 /Egrave /Eacute /Ecircumflex /Edieresis
1568 /Igrave /Iacute /Icircumflex /Idieresis
1569 /Eth /Ntilde /Ograve /Oacute
1570 /Ocircumflex /Otilde /Odieresis /multiply
1571 /Oslash /Ugrave /Uacute /Ucircumflex
1572 /Udieresis /Yacute /Thorn /germandbls
1574 /agrave /aacute /acircumflex /atilde
1575 /adieresis /aring /ae /ccedilla
1576 /egrave /eacute /ecircumflex /edieresis
1577 /igrave /iacute /icircumflex /idieresis
1578 /eth /ntilde /ograve /oacute
1579 /ocircumflex /otilde /odieresis /divide
1580 /oslash /ugrave /uacute /ucircumflex
1581 /udieresis /yacute /thorn /ydieresis
1585 /reencodeFontISO { %def
1587 length 12 add dict % Make a new font (a new dict the same size
1588 % as the old one) with room for our new symbols.
1590 begin % Make the new font the current dictionary.
1594 { def } { pop pop } ifelse
1595 } forall % Copy each of the symbols from the old dictionary
1596 % to the new one except for the font ID.
1598 /Encoding ISOLatin1Encoding def % Override the encoding with
1599 % the ISOLatin1 encoding.
1601 % Use the font's bounding box to determine the ascent, descent,
1602 % and overall height; don't forget that these values have to be
1603 % transformed using the font's matrix.
1610 % | | | | Ascent (usually > 0)
1612 % (0 0) -> +--+----+-------->
1614 % | | v Descent (usually < 0)
1615 % (x1 y1) --> +----+ - -
1617 FontBBox % -- x1 y1 x2 y2
1618 FontMatrix transform /Ascent exch def pop
1619 FontMatrix transform /Descent exch def pop
1620 /FontHeight Ascent Descent sub def % use `sub' because descent < 0
1622 % Define these in case they're not in the FontInfo
1623 % (also, here they're easier to get to).
1624 /UnderlinePosition Descent 0.70 mul def
1625 /OverlinePosition Descent UnderlinePosition sub Ascent add def
1626 /StrikeoutPosition Ascent 0.30 mul def
1627 /LineThickness 0 50 FontMatrix transform exch pop def
1628 /Xshadow 0 80 FontMatrix transform exch pop def
1629 /Yshadow 0 -90 FontMatrix transform exch pop def
1630 /SpaceBackground Descent neg UnderlinePosition add def
1631 /XBox Descent neg def
1632 /YBox LineThickness 0.7 mul def
1634 currentdict % Leave the new font on the stack
1635 end % Stop using the font as the current dictionary.
1636 definefont % Put the font into the font dictionary
1637 pop % Discard the returned font.
1640 /DefFont { % Font definition
1641 findfont exch scalefont reencodeFontISO
1644 /F { % Font selection
1646 dup /Ascent get /Ascent exch def
1647 dup /Descent get /Descent exch def
1648 dup /FontHeight get /FontHeight exch def
1649 dup /UnderlinePosition get /UnderlinePosition exch def
1650 dup /OverlinePosition get /OverlinePosition exch def
1651 dup /StrikeoutPosition get /StrikeoutPosition exch def
1652 dup /LineThickness get /LineThickness exch def
1653 dup /Xshadow get /Xshadow exch def
1654 dup /Yshadow get /Yshadow exch def
1655 dup /SpaceBackground get /SpaceBackground exch def
1656 dup /XBox get /XBox exch def
1657 dup /YBox get /YBox exch def
1661 /FG /setrgbcolor load def
1674 % | Ascent (usually > 0)
1676 % | Descent (usually < 0)
1680 /dobackground { % width --
1681 currentpoint % -- width x y
1685 0 Ascent rmoveto % B
1687 0 Descent Ascent sub rlineto % D
1690 bgcolor aload pop setrgbcolor
1695 /eolbg { % dobackground until right margin
1696 PrintWidth % -- x-eol
1697 currentpoint pop % -- cur-x
1698 sub % -- width until eol
1702 /PLN {PrintLineNumber {doLineNumber}if} def
1704 /SL { % Soft Linefeed
1706 0 currentpoint exch pop LineHeight sub moveto
1709 /HL {SL PLN} def % Hard Linefeed
1712 /dcp { currentpoint exch 40 string cvs print (, ) print = } def
1713 /dp { print 2 copy exch 40 string cvs print (, ) print = } def
1716 ( ) stringwidth % Get the width of a space in the current font.
1717 pop % Discard the Y component.
1718 mul % Multiply the width of a space
1719 % by the number of spaces to plot
1720 bg { dup dobackground } if
1725 /EF {/Effect exch def} def
1727 % stack: string |- --
1728 % effect: 1 - underline 2 - strikeout 4 - overline
1729 % 8 - shadow 16 - box 32 - outline
1731 /xx currentpoint dup Descent add /yy exch def
1732 Ascent add /YY exch def def
1733 dup stringwidth pop xx add /XX exch def
1735 /yy yy Yshadow add def
1736 /XX XX Xshadow add def
1741 {SpaceBackground doBox}
1742 {xx yy XX YY doRect}
1745 Effect 16 and 0 ne {false 0 doBox}if % box
1746 Effect 8 and 0 ne {dup doShadow}if % shadow
1748 {true doOutline} % outline
1749 {show} % normal text
1751 Effect 1 and 0 ne {UnderlinePosition Hline}if % underline
1752 Effect 2 and 0 ne {StrikeoutPosition Hline}if % strikeout
1753 Effect 4 and 0 ne {OverlinePosition Hline}if % overline
1756 % stack: position |- --
1758 currentpoint exch pop add dup
1764 LineThickness setlinewidth stroke
1768 % stack: fill-or-not delta |- --
1771 xx XBox sub dd sub yy YBox sub dd sub
1772 XX XBox add dd add YY YBox add dd add
1776 % stack: fill-or-not lower-x lower-y upper-x upper-y |- --
1789 % top of stack: fill-or-not
1791 {LineThickness setlinewidth stroke}
1796 % stack: string |- --
1799 Xshadow Yshadow rmoveto
1806 % stack: string fill-or-not |- --
1809 /-ox- currentpoint /-oy- exch def def
1811 LineThickness setlinewidth
1814 st dup true charpath
1815 -fillp- {gsave FillBgColor grestore}if
1817 -oy- add /-oy- exch def
1818 -ox- add /-ox- exch def
1826 /FillBgColor {bgcolor aload pop setrgbcolor fill} bind def
1828 /L0 6 /Times-Italic DefFont
1834 0.0 0.0 0.0 setrgbcolor
1835 /L0 findfont setfont
1838 {LineNumber 6 string cvs ( ) strcat}
1840 dup stringwidth pop neg 0 rmoveto
1844 /LineNumber LineNumber 1 add def
1851 /double-zebra NumberOfZebra NumberOfZebra add def
1852 /yiter double-zebra LineHeight mul neg def
1853 /xiter PrintWidth InterColumn add def
1854 NumberOfColumns {LinesPerColumn doColumnZebra xiter 0 rmoveto}repeat
1858 % stack: lines-per-column |- --
1861 dup double-zebra idiv {NumberOfZebra doZebra 0 yiter rmoveto}repeat
1863 dup 0 le {pop}{dup NumberOfZebra gt {pop NumberOfZebra}if doZebra}ifelse
1867 % stack: zebra-height (in lines) |- --
1869 /zh exch 0.05 sub LineHeight mul def
1871 0 LineHeight 0.65 mul rmoveto
1872 PrintWidth 0 rlineto
1874 PrintWidth neg 0 rlineto
1880 % tx ty rotation xscale yscale xpos ypos BeginBackImage
1882 /-save-image- save def
1891 -save-image- restore
1894 % string fontsize fontname rotation gray xpos ypos ShowBackText
1900 findfont exch dup /-offset- exch -0.25 mul def scalefont setfont
1902 /-saveLineThickness- LineThickness def
1903 /LineThickness 1 def
1905 /LineThickness -saveLineThickness- def
1910 % ---- save the state of the document (useful for ghostscript!)
1912 % ---- [jack] Kludge: my ghostscript window is 21x27.7 instead of 21x29.7
1913 /JackGhostscript where {
1914 pop 1 27.7 29.7 div scale
1917 % ---- translate to bottom-right corner of Portrait page
1918 LandscapePageHeight 0 translate
1921 /ColumnWidth PrintWidth InterColumn add def
1922 % ---- translate to lower left corner of TEXT
1923 LeftMargin BottomMargin translate
1924 % ---- define where printing will start
1925 /f0 F % this installs Ascent
1926 /PrintStartY PrintHeight Ascent sub def
1931 % ---- on last page but not last column, spit out the page
1932 ColumnIndex 1 eq not { showpage } if
1933 % ---- restore the state of the document (useful for ghostscript!)
1938 % ---- when 1st column, save the state of the page
1939 ColumnIndex 1 eq { /pageState save def } if
1940 % ---- save the state of the column
1941 /columnState save def
1945 % ---- when 1st column, print all background effects
1947 0 PrintStartY moveto % move to where printing will start
1948 Zebra {printZebra}if
1949 printGlobalBackground
1950 printLocalBackground
1953 PrintHeaderFrame { HeaderFrame } if
1956 0 PrintStartY moveto % move to where printing will start
1965 ColumnIndex NumberOfColumns eq {
1966 % ---- on last column, spit out the page
1968 % ---- restore the state of the page
1972 % ---- restore the state of the current column
1974 % ---- and translate to the next column
1975 ColumnWidth 0 translate
1976 /ColumnIndex ColumnIndex 1 add def
1980 /SetHeaderLines { % nb-lines --
1981 /HeaderLines exch def
1984 HeaderLines 1 sub HeaderLineHeight mul add
1985 HeaderTitleLineHeight add
1987 /HeaderHeight exch def
1994 % |-+-------| <-- (x y)
1998 % |-+-------| <-- (0 0)
2002 /HeaderFrameStart { % -- x y
2003 0 PrintHeight HeaderOffset add
2007 PrintWidth 0 rlineto
2008 0 HeaderHeight rlineto
2009 PrintWidth neg 0 rlineto
2010 0 HeaderHeight neg rlineto
2016 % ---- fill a black rectangle (the shadow of the next one)
2017 HeaderFrameStart moveto
2021 % ---- do the next rectangle ...
2022 HeaderFrameStart moveto
2024 gsave 0.9 setgray fill grestore % filled with grey
2025 gsave 0 setgray stroke grestore % drawn with black
2031 exch HeaderPad add exch % horizontal pad
2033 HeaderPad add % vertical pad
2035 HeaderLineHeight HeaderLines 1 sub mul add
2039 dup length 3 -1 roll dup length dup 4 -1 roll add string dup
2040 0 5 -1 roll putinterval
2041 dup 4 2 roll exch putinterval
2045 PageNumber 32 string cvs
2048 PageCount 32 string cvs strcat
2055 HeaderLinesRight HeaderLinesLeft % -- rightLines leftLines
2057 % ---- hack: `PN 1 and' == `PN 2 modulo'
2059 % ---- if duplex and even page number, then exchange left and right
2060 Duplex PageNumber 1 and 0 eq and { exch } if
2062 { % ---- process the left lines
2066 dup xcheck { exec } if
2069 0 HeaderLineHeight neg rmoveto
2074 { % ---- process the right lines
2078 dup xcheck { exec } if
2080 PrintWidth exch sub HeaderPad 2 mul sub 0 rmoveto
2083 0 HeaderLineHeight neg rmoveto
2089 /t0 3 1 roll DefFont
2092 /sw ( ) stringwidth pop def
2093 /aw (01234567890abcdefghijklmnopqrstuvwxyz) dup length exch
2094 stringwidth pop exch div def
2095 /t1 12 /Helvetica-Oblique DefFont
2102 ( point, the line height is ) show
2103 lh 32 string cvs show
2104 (, the space width is ) show
2105 sw 32 string cvs show
2108 0 FontHeight neg rmoveto
2110 (and a crude estimate of average character width is ) show
2111 aw 32 string cvs show
2114 0 FontHeight neg rmoveto
2121 /ReportAllFontInfo {
2123 { % key = font name value = font dictionary
2124 pop 10 exch ReportFontInfo
2128 % 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage
2129 % 3 cm 20 cm moveto ReportAllFontInfo showpage
2133 (defvar ps-print-prologue-2
2135 % ---- These lines must be kept together because...
2138 /HeaderTitleLineHeight FontHeight def
2141 /HeaderLineHeight FontHeight def
2142 /HeaderDescent Descent def
2144 % ---- ...because `F' has a side-effect on `FontHeight' and `Descent'
2148 ;; Start Editing Here:
2150 (defvar ps-source-buffer nil
)
2151 (defvar ps-spool-buffer-name
"*PostScript*")
2152 (defvar ps-spool-buffer nil
)
2154 (defvar ps-output-head nil
)
2155 (defvar ps-output-tail nil
)
2157 (defvar ps-page-count
0)
2158 (defvar ps-showline-count
1)
2160 (defvar ps-background-pages nil
)
2161 (defvar ps-background-all-pages nil
)
2162 (defvar ps-background-text-count
0)
2163 (defvar ps-background-image-count
0)
2165 (defvar ps-current-font
0)
2166 (defvar ps-default-color
(if ps-print-color-p ps-default-fg
)) ; black
2167 (defvar ps-current-color ps-default-color
)
2168 (defvar ps-current-bg nil
)
2170 (defvar ps-razchunk
0)
2172 (defvar ps-color-format
2173 (if (eq ps-print-emacs-type
'emacs
)
2175 ;;Emacs understands the %f format; we'll
2176 ;;use it to limit color RGB values to
2177 ;;three decimals to cut down some on the
2178 ;;size of the PostScript output.
2181 ;; Lucid emacsen will have to make do with
2182 ;; %s (princ) for floats.
2185 ;; These values determine how much print-height to deduct when headers
2186 ;; are turned on. This is a pretty clumsy way of handling it, but
2187 ;; it'll do for now.
2189 (defvar ps-header-font nil
)
2190 (defvar ps-header-title-font nil
)
2192 (defvar ps-header-line-height nil
)
2193 (defvar ps-header-title-line-height nil
)
2194 (defvar ps-header-pad
0
2195 "Vertical and horizontal space in points (1/72 inch) between the header frame
2196 and the text it contains.")
2198 ;; Define accessors to the dimensions list.
2200 (defmacro ps-page-dimensions-get-width
(dims) `(nth 0 ,dims
))
2201 (defmacro ps-page-dimensions-get-height
(dims) `(nth 1 ,dims
))
2203 (defvar ps-landscape-page-height nil
)
2205 (defvar ps-print-width nil
)
2206 (defvar ps-print-height nil
)
2208 (defvar ps-height-remaining
)
2209 (defvar ps-width-remaining
)
2211 (defvar ps-print-color-scale nil
)
2214 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2215 ;; Internal Variables
2218 (defvar ps-print-face-extension-alist nil
2219 "Alist of symbolic faces *WITH* extension features (box, outline, etc).
2220 An element of this list has the following form:
2222 (FACE . [BITS FG BG])
2224 FACE is a symbol denoting a face name
2225 BITS is a bit vector, where each bit correspond
2226 to a feature (bold, underline, etc)
2227 (see documentation for `ps-print-face-map-alist')
2228 FG foreground color (string or nil)
2229 BG background color (string or nil)
2231 Don't change this list directly; instead,
2232 use `ps-extend-face' and `ps-extend-face-list'.
2233 See documentation for `ps-extend-face' for valid extension symbol.")
2236 (defvar ps-print-face-alist nil
2237 "Alist of symbolic faces *WITHOUT* extension features (box, outline, etc).
2239 An element of this list has the same form as an element of
2240 `ps-print-face-extension-alist'.
2242 Don't change this list directly; this list is used by `ps-face-attributes',
2243 `ps-map-face' and `ps-build-reference-face-lists'.")
2246 (defconst ps-print-face-map-alist
2255 "Alist of all features and the corresponding bit mask.
2256 Each symbol correspond to one bit in a bit vector.")
2259 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2264 (defun ps-extend-face-list (face-extension-list &optional merge-p
)
2265 "Extend face in `ps-print-face-extension-alist'.
2267 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION-LIST are merged
2268 with face extension in `ps-print-face-extension-alist'; otherwise, overrides.
2270 The elements in FACE-EXTENSION-LIST is like those for `ps-extend-face'.
2272 See `ps-extend-face' for documentation."
2273 (while face-extension-list
2274 (ps-extend-face (car face-extension-list
) merge-p
)
2275 (setq face-extension-list
(cdr face-extension-list
))))
2279 (defun ps-extend-face (face-extension &optional merge-p
)
2280 "Extend face in `ps-print-face-extension-alist'.
2282 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION-LIST are merged
2283 with face extensions in `ps-print-face-extension-alist'; otherwise, overrides.
2285 The elements of FACE-EXTENSION list have the form:
2287 (FACE-NAME FOREGROUND BACKGROUND EXTENSION...)
2289 FACE-NAME is a face name symbol.
2291 FOREGROUND and BACKGROUND may be nil or a string that denotes the
2292 foreground and background colors respectively.
2294 EXTENSION is one of the following symbols:
2295 bold - use bold font.
2296 italic - use italic font.
2297 underline - put a line under text.
2298 strikeout - like underline, but the line is in middle of text.
2299 overline - like underline, but the line is over the text.
2300 shadow - text will have a shadow.
2301 box - text will be surrounded by a box.
2302 outline - print characters as hollow outlines.
2304 If EXTENSION is any other symbol, it is ignored."
2305 (let* ((face-name (nth 0 face-extension
))
2306 (foreground (nth 1 face-extension
))
2307 (background (nth 2 face-extension
))
2308 (ps-face (cdr (assq face-name ps-print-face-extension-alist
)))
2309 (face-vector (or ps-face
(vector 0 nil nil
)))
2310 (face-bit (ps-extension-bit face-extension
)))
2312 (aset face-vector
0 (if merge-p
2313 (logior (aref face-vector
0) face-bit
)
2315 (and foreground
(stringp foreground
) (aset face-vector
1 foreground
))
2316 (and background
(stringp background
) (aset face-vector
2 background
))
2317 ;; if face does not exist, insert it
2319 (setq ps-print-face-extension-alist
2320 (cons (cons face-name face-vector
)
2321 ps-print-face-extension-alist
)))))
2324 (defun ps-extension-bit (face-extension)
2326 ;; map valid symbol extension to bit vector
2327 (setq face-extension
(cdr (cdr face-extension
)))
2328 (while (setq face-extension
(cdr face-extension
))
2329 (setq face-bit
(logior face-bit
2330 (or (cdr (assq (car face-extension
)
2331 ps-print-face-map-alist
))
2336 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2337 ;; Internal functions and variables
2340 (defun ps-print-without-faces (from to
&optional filename region-p
)
2341 (ps-printing-region region-p
)
2342 (ps-generate (current-buffer) from to
'ps-generate-postscript
)
2343 (ps-do-despool filename
))
2346 (defun ps-spool-without-faces (from to
&optional region-p
)
2347 (ps-printing-region region-p
)
2348 (ps-generate (current-buffer) from to
'ps-generate-postscript
))
2351 (defun ps-print-with-faces (from to
&optional filename region-p
)
2352 (ps-printing-region region-p
)
2353 (ps-generate (current-buffer) from to
'ps-generate-postscript-with-faces
)
2354 (ps-do-despool filename
))
2357 (defun ps-spool-with-faces (from to
&optional region-p
)
2358 (ps-printing-region region-p
)
2359 (ps-generate (current-buffer) from to
'ps-generate-postscript-with-faces
))
2362 (defsubst ps-count-lines
(from to
)
2363 (+ (count-lines from to
)
2364 (save-excursion (goto-char to
)
2365 (if (= (current-column) 0) 1 0))))
2368 (defvar ps-printing-region nil
2369 "Variable used to indicate if it is printing a region.
2370 If non-nil, it is a cons, the car of which is the line number
2371 where the region begins, and its cdr is the total number of lines
2372 in the buffer. Formatting functions can use this information
2373 to print the original line number (and not the number of lines printed),
2374 and to indicate in the header that the printout is of a partial file.")
2377 (defun ps-printing-region (region-p)
2378 (setq ps-printing-region
2380 (cons (ps-count-lines (point-min) (region-beginning))
2381 (ps-count-lines (point-min) (point-max))))))
2384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2385 ;; Internal functions
2387 (defun ps-line-lengths-internal ()
2388 "Display the correspondence between a line length and a font size,
2389 using the current ps-print setup.
2390 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2391 (let ((buf (get-buffer-create "*Line-lengths*"))
2392 (ifs ps-font-size
) ; initial font size
2393 (icw ps-avg-char-width
) ; initial character width
2394 (print-width (progn (ps-get-page-dimensions)
2396 (ps-setup (ps-setup)) ; setup for the current buffer
2397 (fs-min 5) ; minimum font size
2398 cw-min
; minimum character width
2399 nb-cpl-max
; maximum nb of characters per line
2400 (fs-max 14) ; maximum font size
2401 cw-max
; maximum character width
2402 nb-cpl-min
; minimum nb of characters per line
2403 fs
; current font size
2404 cw
; current character width
2405 nb-cpl
; current nb of characters per line
2407 (setq cw-min
(/ (* icw fs-min
) ifs
)
2408 nb-cpl-max
(floor (/ print-width cw-min
))
2409 cw-max
(/ (* icw fs-max
) ifs
)
2410 nb-cpl-min
(floor (/ print-width cw-max
)))
2411 (setq nb-cpl nb-cpl-min
)
2413 (goto-char (point-max))
2414 (if (not (bolp)) (insert "\n"))
2416 (insert "nb char per line / font size\n")
2417 (while (<= nb-cpl nb-cpl-max
)
2418 (setq cw
(/ print-width
(float nb-cpl
))
2419 fs
(/ (* ifs cw
) icw
))
2420 (insert (format "%3s %s\n" nb-cpl fs
))
2421 (setq nb-cpl
(1+ nb-cpl
)))
2423 (display-buffer buf
'not-this-window
)))
2425 (defun ps-nb-pages (nb-lines)
2426 "Display an approximate correspondence between a font size and the number
2427 of pages the number of lines would require to print
2428 using the current ps-print setup."
2429 (let ((buf (get-buffer-create "*Nb-Pages*"))
2430 (ifs ps-font-size
) ; initial font size
2431 (ilh ps-line-height
) ; initial line height
2432 (page-height (progn (ps-get-page-dimensions)
2434 (ps-setup (ps-setup)) ; setup for the current buffer
2435 (fs-min 4) ; minimum font size
2436 lh-min
; minimum line height
2437 nb-lpp-max
; maximum nb of lines per page
2438 nb-page-min
; minimum nb of pages
2439 (fs-max 14) ; maximum font size
2440 lh-max
; maximum line height
2441 nb-lpp-min
; minimum nb of lines per page
2442 nb-page-max
; maximum nb of pages
2443 fs
; current font size
2444 lh
; current line height
2445 nb-lpp
; current nb of lines per page
2446 nb-page
; current nb of pages
2448 (setq lh-min
(/ (* ilh fs-min
) ifs
)
2449 nb-lpp-max
(floor (/ page-height lh-min
))
2450 nb-page-min
(ceiling (/ (float nb-lines
) nb-lpp-max
))
2451 lh-max
(/ (* ilh fs-max
) ifs
)
2452 nb-lpp-min
(floor (/ page-height lh-max
))
2453 nb-page-max
(ceiling (/ (float nb-lines
) nb-lpp-min
)))
2454 (setq nb-page nb-page-min
)
2456 (goto-char (point-max))
2457 (if (not (bolp)) (insert "\n"))
2459 (insert (format "%d lines\n" nb-lines
))
2460 (insert "nb page / font size\n")
2461 (while (<= nb-page nb-page-max
)
2462 (setq nb-lpp
(ceiling (/ nb-lines
(float nb-page
)))
2463 lh
(/ page-height nb-lpp
)
2464 fs
(/ (* ifs lh
) ilh
))
2465 (insert (format "%s %s\n" nb-page fs
))
2466 (setq nb-page
(1+ nb-page
)))
2468 (display-buffer buf
'not-this-window
)))
2470 (defun ps-select-font ()
2471 "Choose the font name and size (scaling data)."
2472 (let ((assoc (assq ps-font-family ps-font-info-database
))
2473 l fn fb fi bi sz lh sw aw
)
2475 (error "Don't have data to scale font %s. Known fonts families are %s"
2477 (mapcar 'car ps-font-info-database
)))
2479 fn
(prog1 (car l
) (setq l
(cdr l
))) ; need `pop'
2480 fb
(prog1 (car l
) (setq l
(cdr l
)))
2481 fi
(prog1 (car l
) (setq l
(cdr l
)))
2482 bi
(prog1 (car l
) (setq l
(cdr l
)))
2483 sz
(prog1 (car l
) (setq l
(cdr l
)))
2484 lh
(prog1 (car l
) (setq l
(cdr l
)))
2485 sw
(prog1 (car l
) (setq l
(cdr l
)))
2486 aw
(prog1 (car l
) (setq l
(cdr l
))))
2489 (setq ps-font-bold fb
)
2490 (setq ps-font-italic fi
)
2491 (setq ps-font-bold-italic bi
)
2492 ;; These data just need to be rescaled:
2493 (setq ps-line-height
(/ (* lh ps-font-size
) sz
))
2494 (setq ps-space-width
(/ (* sw ps-font-size
) sz
))
2495 (setq ps-avg-char-width
(/ (* aw ps-font-size
) sz
))
2498 (defun ps-select-header-font ()
2499 "Choose the font name and size (scaling data) for the header."
2500 (let ((assoc (assq ps-header-font-family ps-font-info-database
))
2501 l fn fb fi bi sz lh sw aw
)
2503 (error "Don't have data to scale font %s. Known fonts families are %s"
2505 (mapcar 'car ps-font-info-database
)))
2507 fn
(prog1 (car l
) (setq l
(cdr l
))) ; need `pop'
2508 fb
(prog1 (car l
) (setq l
(cdr l
)))
2509 fi
(prog1 (car l
) (setq l
(cdr l
)))
2510 bi
(prog1 (car l
) (setq l
(cdr l
)))
2511 sz
(prog1 (car l
) (setq l
(cdr l
)))
2512 lh
(prog1 (car l
) (setq l
(cdr l
)))
2513 sw
(prog1 (car l
) (setq l
(cdr l
)))
2514 aw
(prog1 (car l
) (setq l
(cdr l
))))
2517 (setq ps-header-font fn
)
2518 (setq ps-header-title-font fb
)
2519 ;; Line height: These data just need to be rescaled:
2520 (setq ps-header-title-line-height
(/ (* lh ps-header-title-font-size
) sz
))
2521 (setq ps-header-line-height
(/ (* lh ps-header-font-size
) sz
))
2522 ps-header-font-family
))
2524 (defun ps-get-page-dimensions ()
2525 (let ((page-dimensions (cdr (assq ps-paper-type ps-page-dimensions-database
)))
2526 page-width page-height
)
2528 ((null page-dimensions
)
2529 (error "`ps-paper-type' must be one of:\n%s"
2530 (mapcar 'car ps-page-dimensions-database
)))
2531 ((< ps-number-of-columns
1)
2532 (error "The number of columns %d should not be negative" ps-number-of-columns
)))
2535 (ps-select-header-font)
2537 (setq page-width
(ps-page-dimensions-get-width page-dimensions
)
2538 page-height
(ps-page-dimensions-get-height page-dimensions
))
2541 (if ps-landscape-mode
2542 ;; exchange width and height
2543 (setq page-width
(prog1 page-height
(setq page-height page-width
))))
2545 ;; It is used to get the lower right corner (only in landscape mode)
2546 (setq ps-landscape-page-height page-height
)
2548 ;; | lm | text | ic | text | ic | text | rm |
2549 ;; page-width == lm + n * pw + (n - 1) * ic + rm
2550 ;; => pw == (page-width - lm -rm - (n - 1) * ic) / n
2551 (setq ps-print-width
2553 ps-left-margin ps-right-margin
2554 (* (1- ps-number-of-columns
) ps-inter-column
))
2555 ps-number-of-columns
))
2556 (if (<= ps-print-width
0)
2557 (error "Bad horizontal layout:
2559 ps-left-margin == %s
2560 ps-right-margin == %s
2561 ps-inter-column == %s
2562 ps-number-of-columns == %s
2563 | lm | text | ic | text | ic | text | rm |
2564 page-width == lm + n * print-width + (n - 1) * ic + rm
2565 => print-width == %d !"
2570 ps-number-of-columns
2573 (setq ps-print-height
2574 (- page-height ps-bottom-margin ps-top-margin
))
2575 (if (<= ps-print-height
0)
2576 (error "Bad vertical layout:
2578 ps-bottom-margin == %s
2579 page-height == bm + print-height + tm
2580 => print-height == %d !"
2584 ;; If headers are turned on, deduct the height of the header from
2585 ;; the print height.
2589 (* ps-header-line-pad ps-header-title-line-height
))
2590 (setq ps-print-height
2594 ps-header-title-line-height
2595 (* ps-header-line-height
(- ps-header-lines
1))
2597 (if (<= ps-print-height
0)
2598 (error "Bad vertical layout:
2600 ps-bottom-margin == %s
2601 ps-header-offset == %s
2604 page-height == bm + print-height + tm - ho - hh
2605 => print-height == %d !"
2611 ps-header-title-line-height
2612 (* ps-header-line-height
(- ps-header-lines
1))
2616 (defun ps-print-preprint (&optional filename
)
2618 (or (numberp filename
)
2620 (let* ((name (concat (buffer-name) ".ps"))
2621 (prompt (format "Save PostScript to file: (default %s) "
2623 (res (read-file-name prompt default-directory name nil
)))
2624 (if (file-directory-p res
)
2625 (expand-file-name name
(file-name-as-directory res
))
2628 ;; The following functions implement a simple list-buffering scheme so
2629 ;; that ps-print doesn't have to repeatedly switch between buffers
2630 ;; while spooling. The functions ps-output and ps-output-string build
2631 ;; up the lists; the function ps-flush-output takes the lists and
2632 ;; insert its contents into the spool buffer (*PostScript*).
2634 (defun ps-output-string-prim (string)
2635 (insert "(") ;insert start-string delimiter
2636 (save-excursion ;insert string
2639 ;; Find and quote special characters as necessary for PS
2640 (while (re-search-forward "[()\\]" nil t
)
2645 (goto-char (point-max))
2646 (insert ")")) ;insert end-string delimiter
2648 (defun ps-init-output-queue ()
2649 (setq ps-output-head
(list ""))
2650 (setq ps-output-tail ps-output-head
))
2652 (defun ps-output (&rest args
)
2653 (setcdr ps-output-tail args
)
2654 (while (cdr ps-output-tail
)
2655 (setq ps-output-tail
(cdr ps-output-tail
))))
2657 (defun ps-output-string (string)
2658 (ps-output t string
))
2660 (defun ps-output-list (the-list)
2661 (mapcar 'ps-output the-list
))
2663 (defun ps-flush-output ()
2665 (set-buffer ps-spool-buffer
)
2666 (goto-char (point-max))
2667 (while ps-output-head
2668 (let ((it (car ps-output-head
)))
2671 (setq ps-output-head
(cdr ps-output-head
))
2672 (ps-output-string-prim (car ps-output-head
))))
2673 (setq ps-output-head
(cdr ps-output-head
))))
2674 (ps-init-output-queue))
2676 (defun ps-insert-file (fname)
2678 ;; Check to see that the file exists and is readable; if not, throw
2680 (or (file-readable-p fname
)
2681 (error "Could not read file `%s'" fname
))
2683 (set-buffer ps-spool-buffer
)
2684 (goto-char (point-max))
2685 (insert-file fname
)))
2687 ;; These functions insert the arrays that define the contents of the
2690 (defun ps-generate-header-line (fonttag &optional content
)
2691 (ps-output " [ " fonttag
" ")
2693 ;; Literal strings should be output as is -- the string must
2694 ;; contain its own PS string delimiters, '(' and ')', if necessary.
2696 (ps-output content
))
2698 ;; Functions are called -- they should return strings; they will be
2699 ;; inserted as strings and the PS string delimiters added.
2700 ((and (symbolp content
) (fboundp content
))
2701 (ps-output-string (funcall content
)))
2703 ;; Variables will have their contents inserted. They should
2704 ;; contain strings, and will be inserted as strings.
2705 ((and (symbolp content
) (boundp content
))
2706 (ps-output-string (symbol-value content
)))
2708 ;; Anything else will get turned into an empty string.
2710 (ps-output-string "")))
2713 (defun ps-generate-header (name contents
)
2714 (ps-output "/" name
" [\n")
2715 (if (> ps-header-lines
0)
2717 (ps-generate-header-line "/h0" (car contents
))
2718 (while (and (< count ps-header-lines
)
2719 (setq contents
(cdr contents
)))
2720 (ps-generate-header-line "/h1" (car contents
))
2721 (setq count
(+ count
1)))
2722 (ps-output "] def\n"))))
2724 (defun ps-output-boolean (name bool
)
2725 (ps-output (format "/%s %s def\n" name
(if bool
"true" "false"))))
2727 (defun ps-background-pages (page-list func
)
2731 (let ((start (if (consp pages
) (car pages
) pages
))
2732 (end (if (consp pages
) (cdr pages
) pages
)))
2733 (and (integerp start
) (integerp end
) (<= start end
)
2734 (add-to-list 'ps-background-pages
(vector start end func
)))))
2736 (setq ps-background-all-pages
(cons func ps-background-all-pages
))))
2739 (defun ps-get-boundingbox ()
2741 (set-buffer ps-spool-buffer
)
2743 (if (re-search-forward
2744 "^%%BoundingBox:\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)"
2746 (vector (string-to-number ; lower x
2747 (buffer-substring (match-beginning 1) (match-end 1)))
2748 (string-to-number ; lower y
2749 (buffer-substring (match-beginning 2) (match-end 2)))
2750 (string-to-number ; upper x
2751 (buffer-substring (match-beginning 3) (match-end 3)))
2752 (string-to-number ; upper y
2753 (buffer-substring (match-beginning 4) (match-end 4))))
2754 (vector 0 0 0 0)))))
2757 ;; Emacs understands the %f format; we'll use it to limit color RGB values
2758 ;; to three decimals to cut down some on the size of the PostScript output.
2759 ;; Lucid emacsen will have to make do with %s (princ) for floats.
2761 (defvar ps-float-format
(if (eq ps-print-emacs-type
'emacs
)
2763 "%s ")) ; Lucid emacsen
2766 (defun ps-float-format (value &optional default
)
2767 (let ((literal (or value default
)))
2769 (format (if (numberp literal
)
2776 (defun ps-background-text ()
2779 (setq ps-background-text-count
(1+ ps-background-text-count
))
2780 (ps-output (format "/ShowBackText-%d {\n" ps-background-text-count
))
2781 (ps-output-string (nth 0 text
)) ; text
2784 (ps-float-format (nth 4 text
) 200.0) ; font size
2785 (format "/%s " (or (nth 3 text
) "Times-Roman")) ; font name
2786 (ps-float-format (nth 6 text
)
2787 "PrintHeight PrintPageWidth atan") ; rotation
2788 (ps-float-format (nth 5 text
) 0.85) ; gray
2789 (ps-float-format (nth 1 text
) "0") ; x position
2790 (ps-float-format (nth 2 text
) "BottomMargin") ; y position
2791 "\nShowBackText} def\n")
2792 (ps-background-pages (nthcdr 7 text
) ; page list
2793 (format "ShowBackText-%d\n"
2794 ps-background-text-count
)))
2795 ps-print-background-text
))
2798 (defun ps-background-image ()
2801 (let ((image-file (expand-file-name (nth 0 image
))))
2802 (if (file-readable-p image-file
)
2804 (setq ps-background-image-count
(1+ ps-background-image-count
))
2806 (format "/ShowBackImage-%d {\n--back-- " ps-background-image-count
)
2807 (ps-float-format (nth 5 image
) 0.0) ; rotation
2808 (ps-float-format (nth 3 image
) 1.0) ; x scale
2809 (ps-float-format (nth 4 image
) 1.0) ; y scale
2810 (ps-float-format (nth 1 image
) ; x position
2811 "PrintPageWidth 2 div")
2812 (ps-float-format (nth 2 image
) ; y position
2813 "PrintHeight 2 div BottomMargin add")
2814 "\nBeginBackImage\n")
2815 (ps-insert-file image-file
)
2816 ;; coordinate adjustment to centralize image
2817 ;; around x and y position
2818 (let ((box (ps-get-boundingbox)))
2820 (set-buffer ps-spool-buffer
)
2822 (if (re-search-backward "^--back--" nil t
)
2826 (- (+ (/ (- (aref box
2) (aref box
0)) 2.0)
2829 (- (+ (/ (- (aref box
3) (aref box
1)) 2.0)
2832 (ps-output "\nEndBackImage} def\n")
2833 (ps-background-pages (nthcdr 6 image
) ; page list
2834 (format "ShowBackImage-%d\n"
2835 ps-background-image-count
))))))
2836 ps-print-background-image
))
2839 (defun ps-background (page-number)
2840 (let (has-local-background)
2841 (mapcar '(lambda (range)
2842 (and (<= (aref range
0) page-number
)
2843 (<= page-number
(aref range
1))
2844 (if has-local-background
2845 (ps-output (aref range
2))
2846 (setq has-local-background t
)
2847 (ps-output "/printLocalBackground {\n"
2849 ps-background-pages
)
2850 (and has-local-background
(ps-output "} def\n"))))
2853 (defun ps-begin-file ()
2854 (ps-get-page-dimensions)
2855 (setq ps-showline-count
(if ps-printing-region
(car ps-printing-region
) 1)
2856 ps-background-text-count
0
2857 ps-background-image-count
0
2858 ps-background-pages nil
2859 ps-background-all-pages nil
)
2861 (ps-output ps-adobe-tag
)
2862 (ps-output "%%Title: " (buffer-name)) ;Take job name from name of
2863 ;first buffer printed
2864 (ps-output "\n%%Creator: " (user-full-name))
2865 (ps-output "\n%%CreationDate: "
2866 (time-stamp-hh:mm
:ss
) " " (time-stamp-mon-dd-yyyy)
2868 (if ps-landscape-mode
"Landscape" "Portrait"))
2869 (ps-output "\n%% DocumentFonts: Times-Roman Times-Italic "
2870 ps-font
" " ps-font-bold
" " ps-font-italic
" "
2871 ps-font-bold-italic
" "
2872 ps-header-font
" " ps-header-title-font
)
2873 (ps-output "\n%%Pages: (atend)\n")
2874 (ps-output "%%EndComments\n\n")
2876 (ps-output-boolean "LandscapeMode" ps-landscape-mode
)
2877 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns
))
2879 (ps-output (format "/LandscapePageHeight %s def\n" ps-landscape-page-height
))
2880 (ps-output (format "/PrintPageWidth %s def\n"
2881 (- (* (+ ps-print-width ps-inter-column
)
2882 ps-number-of-columns
)
2884 (ps-output (format "/PrintWidth %s def\n" ps-print-width
))
2885 (ps-output (format "/PrintHeight %s def\n" ps-print-height
))
2887 (ps-output (format "/LeftMargin %s def\n" ps-left-margin
))
2888 (ps-output (format "/RightMargin %s def\n" ps-right-margin
)) ; not used
2889 (ps-output (format "/InterColumn %s def\n" ps-inter-column
))
2891 (ps-output (format "/BottomMargin %s def\n" ps-bottom-margin
))
2892 (ps-output (format "/TopMargin %s def\n" ps-top-margin
)) ; not used
2893 (ps-output (format "/HeaderOffset %s def\n" ps-header-offset
))
2894 (ps-output (format "/HeaderPad %s def\n" ps-header-pad
))
2896 (ps-output-boolean "PrintHeader" ps-print-header
)
2897 (ps-output-boolean "PrintHeaderFrame" ps-print-header-frame
)
2898 (ps-output-boolean "ShowNofN" ps-show-n-of-n
)
2899 (ps-output-boolean "Duplex" ps-spool-duplex
)
2901 (ps-output (format "/LineHeight %s def\n" ps-line-height
)
2902 (format "/LinesPerColumn %d def\n"
2903 (round (/ (+ ps-print-height
2904 (* ps-line-height
0.45))
2907 (ps-output-boolean "Zebra" ps-zebra-stripes
)
2908 (ps-output (format "/NumberOfZebra %d def\n" ps-zebra-stripe-height
))
2910 (ps-output-boolean "PrintLineNumber" ps-line-number
)
2911 (ps-output (format "/Lines %d def\n"
2912 (if ps-printing-region
2913 (cdr ps-printing-region
)
2914 (ps-count-lines (point-min) (point-max)))))
2916 (ps-background-text)
2917 (ps-background-image)
2918 (setq ps-background-all-pages
(nreverse ps-background-all-pages
)
2919 ps-background-pages
(nreverse ps-background-pages
))
2921 (ps-output ps-print-prologue-1
)
2923 (ps-output "/printGlobalBackground {\n")
2924 (ps-output-list ps-background-all-pages
)
2925 (ps-output "} def\n/printLocalBackground {\n} def\n")
2928 (ps-output ; /h0 14 /Helvetica-Bold Font
2929 (format "/h0 %s /%s DefFont\n" ps-header-title-font-size ps-header-title-font
))
2930 (ps-output ; /h1 12 /Helvetica Font
2931 (format "/h1 %s /%s DefFont\n" ps-header-font-size ps-header-font
))
2933 (ps-output ps-print-prologue-2
)
2936 (ps-output (format "/f0 %s /%s DefFont\n" ps-font-size ps-font
))
2937 (ps-output (format "/f1 %s /%s DefFont\n" ps-font-size ps-font-bold
))
2938 (ps-output (format "/f2 %s /%s DefFont\n" ps-font-size ps-font-italic
))
2939 (ps-output (format "/f3 %s /%s DefFont\n" ps-font-size ps-font-bold-italic
))
2941 (ps-output "\nBeginDoc\n\n")
2942 (ps-output "%%EndPrologue\n"))
2944 (defun ps-header-dirpart ()
2945 (let ((fname (buffer-file-name)))
2947 (if (string-equal (buffer-name) (file-name-nondirectory fname
))
2948 (file-name-directory fname
)
2952 (defun ps-get-buffer-name ()
2954 ;; Indulge Jim this little easter egg:
2955 ((string= (buffer-name) "ps-print.el")
2956 "Hey, Cool! It's ps-print.el!!!")
2957 ;; Indulge Jack this other little easter egg:
2958 ((string= (buffer-name) "sokoban.el")
2959 "Super! C'est sokoban.el!")
2961 (and ps-printing-region
"Subset of: ")
2963 (and (buffer-modified-p) " (unsaved)")))))
2965 (defun ps-begin-job ()
2966 (setq ps-page-count
0))
2968 (defun ps-end-file ()
2969 (ps-output "\n%%Trailer\n")
2970 (ps-output (format "%%%%Pages: %d\n" (1+ (/ (1- ps-page-count
)
2971 ps-number-of-columns
))))
2972 (ps-output "\nEndDoc\n\n%%EOF\n"))
2975 (defun ps-next-page ()
2980 (defun ps-header-page (&optional inc-p
)
2981 (if (zerop (mod ps-page-count ps-number-of-columns
))
2982 ;; Print only when a new real page begins.
2983 (let ((page-number (1+ (/ ps-page-count ps-number-of-columns
))))
2984 (ps-output (format "\n%%%%Page: %d %d\n" page-number page-number
))
2985 (ps-output "BeginDSCPage\n")
2986 (ps-background page-number
)
2987 (and inc-p
(incf ps-page-count
)))
2988 ;; Print when any other page begins.
2989 (ps-output "BeginDSCPage\n")))
2991 (defun ps-begin-page (&optional dummypage
)
2992 (ps-get-page-dimensions)
2993 (setq ps-width-remaining ps-print-width
)
2994 (setq ps-height-remaining ps-print-height
)
2998 (ps-output (format "/LineNumber %d def\n" ps-showline-count
)
2999 (format "/PageNumber %d def\n" (incf ps-page-count
)))
3000 (ps-output "/PageCount 0 def\n")
3002 (when ps-print-header
3003 (ps-generate-header "HeaderLinesLeft" ps-left-header
)
3004 (ps-generate-header "HeaderLinesRight" ps-right-header
)
3005 (ps-output (format "%d SetHeaderLines\n" ps-header-lines
)))
3007 (ps-output "BeginPage\n")
3008 (ps-set-font ps-current-font
)
3009 (ps-set-bg ps-current-bg
)
3010 (ps-set-color ps-current-color
))
3012 (defun ps-end-page ()
3013 (ps-output "EndPage\nEndDSCPage\n"))
3015 (defun ps-dummy-page ()
3017 (ps-output "/PrintHeader false def
3022 (defun ps-next-line ()
3023 (setq ps-showline-count
(1+ ps-showline-count
))
3024 (if (< ps-height-remaining ps-line-height
)
3026 (setq ps-width-remaining ps-print-width
)
3027 (setq ps-height-remaining
(- ps-height-remaining ps-line-height
))
3030 (defun ps-continue-line ()
3031 (if (< ps-height-remaining ps-line-height
)
3033 (setq ps-width-remaining ps-print-width
)
3034 (setq ps-height-remaining
(- ps-height-remaining ps-line-height
))
3037 ;; [jack] Why hard and soft ?
3039 (defun ps-hard-lf ()
3042 (defun ps-soft-lf ()
3045 (defun ps-find-wrappoint (from to char-width
)
3046 (let ((avail (truncate (/ ps-width-remaining char-width
)))
3049 (cons to
(* todo char-width
))
3050 (cons (+ from avail
) ps-width-remaining
))))
3052 (defun ps-basic-plot-string (from to
&optional bg-color
)
3053 (let* ((wrappoint (ps-find-wrappoint from to ps-avg-char-width
))
3054 (to (car wrappoint
))
3055 (string (buffer-substring-no-properties from to
)))
3056 (ps-output-string string
)
3060 (defun ps-basic-plot-whitespace (from to
&optional bg-color
)
3061 (let* ((wrappoint (ps-find-wrappoint from to ps-space-width
))
3062 (to (car wrappoint
)))
3063 (ps-output (format "%d W\n" (- to from
)))
3066 (defun ps-plot (plotfunc from to
&optional bg-color
)
3068 (let* ((wrappoint (funcall plotfunc from to bg-color
))
3069 (plotted-to (car wrappoint
))
3070 (plotted-width (cdr wrappoint
)))
3071 (setq from plotted-to
)
3072 (setq ps-width-remaining
(- ps-width-remaining plotted-width
))
3074 (ps-continue-line))))
3075 (if ps-razzle-dazzle
3076 (let* ((q-todo (- (point-max) (point-min)))
3077 (q-done (- (point) (point-min)))
3078 (chunkfrac (/ q-todo
8))
3079 (chunksize (if (> chunkfrac
1000) 1000 chunkfrac
)))
3080 (if (> (- q-done ps-razchunk
) chunksize
)
3082 (setq ps-razchunk q-done
)
3085 (/ (* 100 q-done
) q-todo
)
3086 (/ q-done
(/ q-todo
100))))
3087 (message "Formatting...%3d%%" foo
))))))
3089 (defun ps-set-font (font)
3090 (setq ps-current-font font
)
3091 (ps-output (format "/f%d F\n" ps-current-font
)))
3093 (defun ps-set-bg (color)
3094 (if (setq ps-current-bg color
)
3095 (ps-output (format ps-color-format
(nth 0 color
) (nth 1 color
)
3098 (ps-output "false BG\n")))
3100 (defun ps-set-color (color)
3101 (setq ps-current-color
(or color ps-default-fg
))
3102 (ps-output (format ps-color-format
(nth 0 ps-current-color
)
3103 (nth 1 ps-current-color
) (nth 2 ps-current-color
))
3107 (defvar ps-current-effect
0)
3110 (defun ps-plot-region (from to font
&optional fg-color bg-color effects
)
3111 (if (not (equal font ps-current-font
))
3114 ;; Specify a foreground color only if one's specified and it's
3115 ;; different than the current.
3116 (if (not (equal fg-color ps-current-color
))
3117 (ps-set-color fg-color
))
3119 (if (not (equal bg-color ps-current-bg
))
3120 (ps-set-bg bg-color
))
3122 ;; Specify effects (underline, overline, box, etc)
3124 ((not (integerp effects
))
3125 (ps-output "0 EF\n")
3126 (setq ps-current-effect
0))
3127 ((/= effects ps-current-effect
)
3128 (ps-output (number-to-string effects
) " EF\n")
3129 (setq ps-current-effect effects
)))
3131 ;; Starting at the beginning of the specified region...
3135 ;; ...break the region up into chunks separated by tabs, linefeeds,
3136 ;; pagefeeds, control characters, and plot each chunk.
3138 (if (re-search-forward "[\000-\037\177-\377]" to t
)
3139 ;; region with some control characters
3140 (let ((match (char-after (match-beginning 0))))
3141 (if (= match ?
\t) ; tab
3143 (save-excursion (beginning-of-line) (point))))
3144 (ps-plot 'ps-basic-plot-string from
(- (point) 1)
3147 (setq from
(+ linestart
(current-column)))
3148 (if (re-search-forward "[ \t]+" to t
)
3149 (ps-plot 'ps-basic-plot-whitespace
3150 from
(+ linestart
(current-column))
3152 ;; any other control character except tab
3153 (ps-plot 'ps-basic-plot-string from
(- (point) 1) bg-color
)
3155 ((= match ?
\n) ; newline
3158 ((= match ?
\f) ; form feed
3161 ((<= match ?
\037) ; characters from ^@ to ^_
3162 (ps-control-character (format "^%c" (+ match ?
@))))
3164 ((= match ?
\177) ; del (127) is printed ^?
3165 (ps-control-character "^?"))
3167 (t ; characters from 128 to 255
3168 (ps-control-character (format "\\%o" match
)))))
3169 (setq from
(point)))
3170 ;; region without control characters
3171 (ps-plot 'ps-basic-plot-string from to bg-color
)
3174 (defun ps-control-character (str)
3175 (let* ((from (1- (point)))
3178 (wrappoint (ps-find-wrappoint from to ps-avg-char-width
)))
3179 (if (< (car wrappoint
) to
)
3181 (setq ps-width-remaining
(- ps-width-remaining
(* len ps-avg-char-width
)))
3182 (ps-output-string str
)
3183 (ps-output " S\n")))
3185 (defun ps-color-value (x-color-value)
3186 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval.
3187 (/ x-color-value ps-print-color-scale
))
3189 (defun ps-color-values (x-color)
3190 (cond ((fboundp 'x-color-values
)
3191 (x-color-values x-color
))
3192 ((fboundp 'pixel-components
)
3193 (pixel-components x-color
))
3194 (t (error "No available function to determine X color values."))))
3197 (defun ps-face-attributes (face)
3198 "Return face attribute vector.
3200 If FACE is not in `ps-print-face-extension-alist' or in
3201 `ps-print-face-alist', insert it on `ps-print-face-alist' and
3202 return the attribute vector.
3204 If FACE is not a valid face name, it is used default face."
3205 (cdr (or (assq face ps-print-face-extension-alist
)
3206 (assq face ps-print-face-alist
)
3207 (let* ((the-face (if (facep face
) face
'default
))
3208 (new-face (ps-screen-to-bit-face the-face
)))
3209 (or (and (eq the-face
'default
)
3210 (assq the-face ps-print-face-alist
))
3211 (setq ps-print-face-alist
(cons new-face ps-print-face-alist
)))
3215 (defun ps-face-attribute-list (face-or-list)
3216 (if (listp face-or-list
)
3218 (let ((effects 0) foreground background face-attr face
)
3220 (setq face
(car face-or-list
)
3221 face-attr
(ps-face-attributes face
)
3222 effects
(logior effects
(aref face-attr
0)))
3223 (or foreground
(setq foreground
(aref face-attr
1)))
3224 (or background
(setq background
(aref face-attr
2)))
3225 (setq face-or-list
(cdr face-or-list
)))
3226 (vector effects foreground background
))
3228 (ps-face-attributes face-or-list
)))
3231 (defun ps-plot-with-face (from to face
)
3233 (let* ((face-bit (ps-face-attribute-list face
))
3234 (effect (aref face-bit
0))
3235 (foreground (aref face-bit
1))
3236 (background (aref face-bit
2))
3237 (fg-color (if (and ps-print-color-p foreground
)
3238 (mapcar 'ps-color-value
3239 (ps-color-values foreground
))
3241 (bg-color (if (and ps-print-color-p background
)
3242 (mapcar 'ps-color-value
3243 (ps-color-values background
)))))
3244 (ps-plot-region from to
(logand effect
3)
3245 fg-color bg-color
(lsh effect -
2)))
3246 (ps-plot-region from to
0))
3250 (defun ps-emacs-face-kind-p (face kind kind-regex kind-list
)
3251 (let ((frame-font (face-font face
))
3252 (face-defaults (face-font face t
)))
3254 ;; Check FACE defaults:
3255 (and (listp face-defaults
)
3256 (memq kind face-defaults
))
3257 ;; Check the user's preferences
3258 (memq face kind-list
))))
3260 (defun ps-xemacs-face-kind-p (face kind kind-regex kind-list
)
3261 (let* ((frame-font (or (face-font face
) (face-font 'default
)))
3262 (kind-cons (assq kind
(x-font-properties frame-font
)))
3263 (kind-spec (cdr-safe kind-cons
))
3264 (case-fold-search t
))
3266 (or (and kind-spec
(string-match kind-regex kind-spec
))
3267 ;; Kludge-compatible:
3268 (memq face kind-list
))))
3270 (defun ps-face-bold-p (face)
3271 (if (eq ps-print-emacs-type
'emacs
)
3272 (ps-emacs-face-kind-p face
'bold
"-\\(bold\\|demibold\\)-"
3274 (ps-xemacs-face-kind-p face
'WEIGHT_NAME
"bold\\|demibold"
3277 (defun ps-face-italic-p (face)
3278 (if (eq ps-print-emacs-type
'emacs
)
3279 (ps-emacs-face-kind-p face
'italic
"-[io]-" ps-italic-faces
)
3281 (ps-xemacs-face-kind-p face
'ANGLE_NAME
"i\\|o" ps-italic-faces
)
3282 (ps-xemacs-face-kind-p face
'SLANT
"i\\|o" ps-italic-faces
))))
3284 (defun ps-face-underlined-p (face)
3285 (or (face-underline-p face
)
3286 (memq face ps-underlined-faces
)))
3289 ;; Ensure that face-list is fbound.
3290 (or (fboundp 'face-list
) (defalias 'face-list
'list-faces
))
3293 (defun ps-build-reference-face-lists ()
3294 (setq ps-print-face-alist nil
)
3295 (if ps-auto-font-detect
3296 (mapcar 'ps-map-face
(face-list))
3297 (mapcar 'ps-set-face-bold ps-bold-faces
)
3298 (mapcar 'ps-set-face-italic ps-italic-faces
)
3299 (mapcar 'ps-set-face-underline ps-underlined-faces
))
3300 (setq ps-build-face-reference nil
))
3303 (defun ps-set-face-bold (face)
3304 (ps-set-face-attribute face
1))
3306 (defun ps-set-face-italic (face)
3307 (ps-set-face-attribute face
2))
3309 (defun ps-set-face-underline (face)
3310 (ps-set-face-attribute face
4))
3313 (defun ps-set-face-attribute (face effect
)
3314 (let ((face-bit (cdr (ps-map-face face
))))
3315 (aset face-bit
0 (logior (aref face-bit
0) effect
))))
3318 (defun ps-map-face (face)
3319 (let* ((face-map (ps-screen-to-bit-face face
))
3320 (ps-face-bit (cdr (assq (car face-map
) ps-print-face-alist
))))
3322 ;; if face exists, merge both
3323 (let ((face-bit (cdr face-map
)))
3324 (aset ps-face-bit
0 (logior (aref ps-face-bit
0) (aref face-bit
0)))
3325 (or (aref ps-face-bit
1) (aset ps-face-bit
1 (aref face-bit
1)))
3326 (or (aref ps-face-bit
2) (aset ps-face-bit
2 (aref face-bit
2))))
3327 ;; if face does not exist, insert it
3328 (setq ps-print-face-alist
(cons face-map ps-print-face-alist
)))
3332 (defun ps-screen-to-bit-face (face)
3334 (vector (logior (if (ps-face-bold-p face
) 1 0) ; bold
3335 (if (ps-face-italic-p face
) 2 0) ; italic
3336 (if (ps-face-underlined-p face
) 4 0)) ; underline
3337 (face-foreground face
)
3338 (face-background face
))))
3341 (defun ps-mapper (extent list
)
3342 (nconc list
(list (list (extent-start-position extent
) 'push extent
)
3343 (list (extent-end-position extent
) 'pull extent
)))
3346 (defun ps-extent-sorter (a b
)
3347 (< (extent-priority a
) (extent-priority b
)))
3349 (defun ps-print-ensure-fontified (start end
)
3350 (if (and (boundp 'lazy-lock-mode
) lazy-lock-mode
)
3351 (if (fboundp 'lazy-lock-fontify-region
)
3352 (lazy-lock-fontify-region start end
) ; the new
3353 (lazy-lock-fontify-buffer)))) ; the old
3355 (defun ps-generate-postscript-with-faces (from to
)
3356 ;; Some initialization...
3357 (setq ps-current-effect
0)
3359 ;; Build the reference lists of faces if necessary.
3360 (if (or ps-always-build-face-reference
3361 ps-build-face-reference
)
3363 (message "Collecting face information...")
3364 (ps-build-reference-face-lists)))
3365 ;; Set the color scale. We do it here instead of in the defvar so
3366 ;; that ps-print can be dumped into emacs. This expression can't be
3367 ;; evaluated at dump-time because X isn't initialized.
3368 (setq ps-print-color-scale
3369 (if ps-print-color-p
3370 (float (car (ps-color-values "white")))
3372 ;; Generate some PostScript.
3374 (narrow-to-region from to
)
3375 (let ((face 'default
)
3377 (ps-print-ensure-fontified from to
)
3379 ((or (eq ps-print-emacs-type
'lucid
)
3380 (eq ps-print-emacs-type
'xemacs
))
3381 ;; Build the list of extents...
3382 (let ((a (cons 'dummy nil
))
3383 record type extent extent-list
)
3384 (map-extents 'ps-mapper nil from to a
)
3385 (setq a
(sort (cdr a
) 'car-less-than-car
))
3387 (setq extent-list nil
)
3389 ;; Loop through the extents...
3391 (setq record
(car a
))
3393 (setq position
(car record
))
3394 (setq record
(cdr record
))
3396 (setq type
(car record
))
3397 (setq record
(cdr record
))
3399 (setq extent
(car record
))
3401 ;; Plot up to this record.
3402 ;; XEmacs 19.12: for some reason, we're getting into a
3403 ;; situation in which some of the records have
3404 ;; positions less than 'from'. Since we've narrowed
3405 ;; the buffer, this'll generate errors. This is a
3406 ;; hack, but don't call ps-plot-with-face unless from >
3408 (if (and (>= from
(point-min))
3409 (<= position
(point-max)))
3410 (ps-plot-with-face from position face
))
3414 (if (extent-face extent
)
3415 (setq extent-list
(sort (cons extent extent-list
)
3416 'ps-extent-sorter
))))
3419 (setq extent-list
(sort (delq extent extent-list
)
3420 'ps-extent-sorter
))))
3424 (extent-face (car extent-list
))
3427 (setq from position
)
3430 ((eq ps-print-emacs-type
'emacs
)
3431 (let ((property-change from
)
3432 (overlay-change from
))
3434 (if (< property-change to
) ; Don't search for property change
3435 ; unless previous search succeeded.
3436 (setq property-change
3437 (next-property-change from nil to
)))
3438 (if (< overlay-change to
) ; Don't search for overlay change
3439 ; unless previous search succeeded.
3440 (setq overlay-change
3441 (min (next-overlay-change from
) to
)))
3443 (min property-change overlay-change
))
3444 ;; The code below is not quite correct,
3445 ;; because a non-nil overlay invisible property
3446 ;; which is inactive according to the current value
3447 ;; of buffer-invisibility-spec nonetheless overrides
3448 ;; a face text property.
3450 (cond ((let ((prop (get-text-property from
'invisible
)))
3451 ;; Decide whether this invisible property
3452 ;; really makes the text invisible.
3453 (if (eq buffer-invisibility-spec t
)
3455 (or (memq prop buffer-invisibility-spec
)
3456 (assq prop buffer-invisibility-spec
))))
3458 ((get-text-property from
'face
))
3460 (let ((overlays (overlays-at from
))
3461 (face-priority -
1)) ; text-property
3463 (let* ((overlay (car overlays
))
3464 (overlay-face (overlay-get overlay
'face
))
3465 (overlay-invisible (overlay-get overlay
'invisible
))
3466 (overlay-priority (or (overlay-get overlay
3469 (if (and (or overlay-invisible overlay-face
)
3470 (> overlay-priority face-priority
))
3471 (setq face
(cond ((if (eq buffer-invisibility-spec t
)
3472 (not (null overlay-invisible
))
3473 (or (memq overlay-invisible
3474 buffer-invisibility-spec
)
3475 (assq overlay-invisible
3476 buffer-invisibility-spec
)))
3478 ((and face overlay-face
)))
3479 face-priority overlay-priority
)))
3480 (setq overlays
(cdr overlays
))))
3481 ;; Plot up to this record.
3482 (ps-plot-with-face from position face
)
3483 (setq from position
)))))
3484 (ps-plot-with-face from to face
))))
3486 (defun ps-generate-postscript (from to
)
3487 (ps-plot-region from to
0 nil
))
3489 (defun ps-generate (buffer from to genfunc
)
3491 (let ((from (min to from
))
3493 ;; This avoids trouble if chars with read-only properties
3494 ;; are copied into ps-spool-buffer.
3495 (inhibit-read-only t
))
3497 (narrow-to-region from to
)
3498 (if ps-razzle-dazzle
3499 (message "Formatting...%3d%%" (setq ps-razchunk
0)))
3501 (setq ps-source-buffer buffer
)
3502 (setq ps-spool-buffer
(get-buffer-create ps-spool-buffer-name
))
3503 (ps-init-output-queue)
3504 (let (safe-marker completed-safely needs-begin-file
)
3507 (set-buffer ps-spool-buffer
)
3509 ;; Get a marker and make it point to the current end of the
3510 ;; buffer, If an error occurs, we'll delete everything from
3511 ;; the end of this marker onwards.
3512 (setq safe-marker
(make-marker))
3513 (set-marker safe-marker
(point-max))
3515 (goto-char (point-min))
3516 (if (looking-at (regexp-quote ps-adobe-tag
))
3518 (setq needs-begin-file t
))
3520 (set-buffer ps-source-buffer
)
3521 (if needs-begin-file
(ps-begin-file))
3524 (set-buffer ps-source-buffer
)
3525 (funcall genfunc from to
)
3528 (if (and ps-spool-duplex
3529 (= (mod ps-page-count
2) 1))
3533 ;; Back to the PS output buffer to set the page count
3534 (set-buffer ps-spool-buffer
)
3535 (goto-char (point-max))
3536 (while (re-search-backward "^/PageCount 0 def$" nil t
)
3537 (replace-match (format "/PageCount %d def" ps-page-count
) t
))
3539 ;; Setting this variable tells the unwind form that the
3540 ;; the postscript was generated without error.
3541 (setq completed-safely t
))
3543 ;; Unwind form: If some bad mojo occurred while generating
3544 ;; postscript, delete all the postscript that was generated.
3545 ;; This protects the previously spooled files from getting
3547 (if (and (markerp safe-marker
) (not completed-safely
))
3549 (set-buffer ps-spool-buffer
)
3550 (delete-region (marker-position safe-marker
) (point-max))))))
3552 (if ps-razzle-dazzle
3553 (message "Formatting...done"))))))
3555 (defun ps-do-despool (filename)
3556 (if (or (not (boundp 'ps-spool-buffer
))
3557 (not (symbol-value 'ps-spool-buffer
)))
3558 (message "No spooled PostScript to print")
3563 (if ps-razzle-dazzle
3564 (message "Saving..."))
3565 (set-buffer ps-spool-buffer
)
3566 (setq filename
(expand-file-name filename
))
3567 (write-region (point-min) (point-max) filename
)
3568 (if ps-razzle-dazzle
3569 (message "Wrote %s" filename
)))
3570 ;; Else, spool to the printer
3571 (if ps-razzle-dazzle
3572 (message "Printing..."))
3574 (set-buffer ps-spool-buffer
)
3575 (if (and (eq system-type
'ms-dos
)
3576 (stringp (symbol-value 'dos-ps-printer
)))
3577 (write-region (point-min) (point-max)
3578 (symbol-value 'dos-ps-printer
) t
0)
3579 (let ((binary-process-input t
)) ; for MS-DOS
3580 (apply 'call-process-region
3581 (point-min) (point-max) ps-lpr-command nil
3582 (if (fboundp 'start-process
) 0 nil
)
3585 (if ps-razzle-dazzle
3586 (message "Printing...done")))
3587 (kill-buffer ps-spool-buffer
)))
3589 (defun ps-kill-emacs-check ()
3591 (if (and (setq ps-buffer
(get-buffer ps-spool-buffer-name
))
3592 (buffer-modified-p ps-buffer
))
3593 (if (y-or-n-p "Unprinted PostScript waiting; print now? ")
3595 (if (and (setq ps-buffer
(get-buffer ps-spool-buffer-name
))
3596 (buffer-modified-p ps-buffer
))
3597 (if (yes-or-no-p "Unprinted PostScript waiting; exit anyway? ")
3599 (error "Unprinted PostScript")))))
3601 (if (fboundp 'add-hook
)
3602 (funcall 'add-hook
'kill-emacs-hook
'ps-kill-emacs-check
)
3604 (message "Won't override existing kill-emacs-hook")
3605 (setq kill-emacs-hook
'ps-kill-emacs-check
)))
3607 ;;; Sample Setup Code:
3609 ;; This stuff is for anybody that's brave enough to look this far,
3610 ;; and able to figure out how to use it. It isn't really part of
3611 ;; ps-print, but I'll leave it here in hopes it might be useful:
3613 ;; WARNING!!! The following code is *sample* code only. Don't use it
3614 ;; unless you understand what it does!
3616 (defmacro ps-prsc
()
3617 `(if (eq ps-print-emacs-type
'emacs
) [f22] 'f22))
3618 (defmacro ps-c-prsc ()
3619 `(if (eq ps-print-emacs-type 'emacs) [C-f22] '(control f22)))
3620 (defmacro ps-s-prsc ()
3621 `(if (eq ps-print-emacs-type 'emacs) [S-f22] '(shift f22)))
3623 ;; A hook to bind to `rmail-mode-hook' to locally bind prsc and set the
3624 ;; `ps-left-headers' specially for mail messages.
3625 (defun ps-rmail-mode-hook ()
3626 (local-set-key (ps-prsc) 'ps-rmail-print-message-from-summary)
3627 (setq ps-header-lines 3
3629 ;; The left headers will display the message's subject, its
3630 ;; author, and the name of the folder it was in.
3631 '(ps-article-subject ps-article-author buffer-name)))
3633 ;; See `ps-gnus-print-article-from-summary'. This function does the
3634 ;; same thing for rmail.
3635 (defun ps-rmail-print-message-from-summary ()
3637 (ps-print-message-from-summary 'rmail-summary-buffer "RMAIL"))
3639 ;; Used in `ps-rmail-print-article-from-summary',
3640 ;; `ps-gnus-print-article-from-summary' and `ps-vm-print-message-from-summary'.
3641 (defun ps-print-message-from-summary (summary-buffer summary-default)
3642 (let ((ps-buf (or (and (boundp summary-buffer)
3643 (symbol-value summary-buffer))
3645 (and (get-buffer ps-buf)
3648 (ps-spool-buffer-with-faces)))))
3650 ;; Look in an article or mail message for the Subject: line. To be
3651 ;; placed in `ps-left-headers'.
3652 (defun ps-article-subject ()
3654 (goto-char (point-min))
3655 (if (re-search-forward "^Subject:[ \t]+\\(.*\\)$" nil t)
3656 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
3659 ;; Look in an article or mail message for the From: line. Sorta-kinda
3660 ;; understands RFC-822 addresses and can pull the real name out where
3661 ;; it's provided. To be placed in `ps-left-headers'.
3662 (defun ps-article-author ()
3664 (goto-char (point-min))
3665 (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
3666 (let ((fromstring (buffer-substring-no-properties (match-beginning 1)
3670 ;; Try first to match addresses that look like
3671 ;; thompson@wg2.waii.com (Jim Thompson)
3672 ((string-match ".*[ \t]+(\\(.*\\))" fromstring)
3673 (substring fromstring (match-beginning 1) (match-end 1)))
3675 ;; Next try to match addresses that look like
3676 ;; Jim Thompson <thompson@wg2.waii.com>
3677 ((string-match "\\(.*\\)[ \t]+<.*>" fromstring)
3678 (substring fromstring (match-beginning 1) (match-end 1)))
3680 ;; Couldn't find a real name -- show the address instead.
3684 ;; A hook to bind to `gnus-article-prepare-hook'. This will set the
3685 ;; `ps-left-headers' specially for gnus articles. Unfortunately,
3686 ;; `gnus-article-mode-hook' is called only once, the first time the *Article*
3687 ;; buffer enters that mode, so it would only work for the first time
3688 ;; we ran gnus. The second time, this hook wouldn't get set up. The
3689 ;; only alternative is `gnus-article-prepare-hook'.
3690 (defun ps-gnus-article-prepare-hook ()
3691 (setq ps-header-lines 3)
3692 (setq ps-left-header
3693 ;; The left headers will display the article's subject, its
3694 ;; author, and the newsgroup it was in.
3695 (list 'ps-article-subject 'ps-article-author 'gnus-newsgroup-name)))
3697 ;; A hook to bind to `vm-mode-hook' to locally bind prsc and set the
3698 ;; `ps-left-headers' specially for mail messages.
3699 (defun ps-vm-mode-hook ()
3700 (local-set-key (ps-prsc) 'ps-vm-print-message-from-summary)
3701 (setq ps-header-lines 3)
3702 (setq ps-left-header
3703 ;; The left headers will display the message's subject, its
3704 ;; author, and the name of the folder it was in.
3705 (list 'ps-article-subject 'ps-article-author 'buffer-name)))
3707 ;; Every now and then I forget to switch from the *Summary* buffer to
3708 ;; the *Article* before hitting prsc, and a nicely formatted list of
3709 ;; article subjects shows up at the printer. This function, bound to
3710 ;; prsc for the gnus *Summary* buffer means I don't have to switch
3712 ;; sb: Updated for Gnus 5.
3713 (defun ps-gnus-print-article-from-summary ()
3715 (ps-print-message-from-summary 'gnus-article-buffer "*Article*"))
3717 ;; See `ps-gnus-print-article-from-summary'. This function does the
3718 ;; same thing for vm.
3719 (defun ps-vm-print-message-from-summary ()
3721 (ps-print-message-from-summary 'vm-mail-buffer ""))
3723 ;; A hook to bind to bind to `gnus-summary-setup-buffer' to locally bind
3725 (defun ps-gnus-summary-setup ()
3726 (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary))
3728 ;; Look in an article or mail message for the Subject: line. To be
3729 ;; placed in `ps-left-headers'.
3730 (defun ps-info-file ()
3732 (goto-char (point-min))
3733 (if (re-search-forward "File:[ \t]+\\([^, \t\n]*\\)" nil t)
3734 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
3737 ;; Look in an article or mail message for the Subject: line. To be
3738 ;; placed in `ps-left-headers'.
3739 (defun ps-info-node ()
3741 (goto-char (point-min))
3742 (if (re-search-forward "Node:[ \t]+\\([^,\t\n]*\\)" nil t)
3743 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
3746 (defun ps-info-mode-hook ()
3747 (setq ps-left-header
3748 ;; The left headers will display the node name and file name.
3749 (list 'ps-info-node 'ps-info-file)))
3751 ;; WARNING! The following function is a *sample* only, and is *not*
3752 ;; meant to be used as a whole unless you understand what the effects
3753 ;; will be! (In fact, this is a copy of Jim's setup for ps-print --
3754 ;; I'd be very surprised if it was useful to *anybody*, without
3757 (defun ps-jts-ps-setup ()
3758 (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc
3759 (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces)
3760 (global-set-key (ps-c-prsc) 'ps-despool)
3761 (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook)
3762 (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup)
3763 (add-hook 'vm-mode-hook 'ps-vm-mode-hook)
3764 (add-hook 'vm-mode-hooks 'ps-vm-mode-hook)
3765 (add-hook 'Info-mode-hook 'ps-info-mode-hook)
3766 (setq ps-spool-duplex t)
3767 (setq ps-print-color-p nil)
3768 (setq ps-lpr-command "lpr")
3769 (setq ps-lpr-switches '("-Jjct,duplex_long"))
3772 ;; WARNING! The following function is a *sample* only, and is *not*
3773 ;; meant to be used as a whole unless it corresponds to your needs.
3774 ;; (In fact, this is a copy of Jack's setup for ps-print --
3775 ;; I would not be that surprised if it was useful to *anybody*,
3776 ;; without modification.)
3778 (defun ps-jack-setup ()
3779 (setq ps-print-color-p nil
3780 ps-lpr-command "lpr"
3781 ps-lpr-switches (list)
3785 ps-number-of-columns 2
3787 ps-left-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
3788 ps-right-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
3789 ps-inter-column (/ (* 72 1.0) 2.54) ; 1.0 cm
3790 ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
3791 ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
3792 ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
3793 ps-header-line-pad .15
3795 ps-print-header-frame t
3800 ps-font-family 'Courier
3802 ps-header-font-family 'Helvetica
3803 ps-header-font-size 6
3804 ps-header-title-font-size 8)
3809 ;;; ps-print.el ends here