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 blocks of X's 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'.
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.
560 ;; How Ps-Print Has A Text And/Or Image On Background
561 ;; --------------------------------------------------
563 ;; Ps-print can print texts and/or EPS PostScript images on background; it is
564 ;; possible to define the following text attributes: font name, font size,
565 ;; initial position, angle, gray scale and pages to print.
567 ;; It has the following EPS PostScript images attributes: file name containing
568 ;; the image, initial position, X and Y scales, angle and pages to print.
570 ;; See documentation for `ps-print-background-text' and
571 ;; `ps-print-background-image'.
573 ;; For example, if we wish to print text "preliminary" on all pages and text
574 ;; "special" on page 5 and from page 11 to page 17, we could specify:
576 ;; (setq ps-print-background-text
579 ;; "LeftMargin" "BottomMargin PrintHeight add" ; X and Y position
580 ;; ; (upper left corner)
582 ;; "PrintHeight neg PrintWidth atan" ; angle
583 ;; 5 (11 . 17)) ; page list
586 ;; Similarly, we could print image "~/images/EPS-image1.ps" on all pages and
587 ;; image "~/images/EPS-image2.ps" on page 5 and from page 11 to page 17, we
590 ;; (setq ps-print-background-image
591 ;; '(("~/images/EPS-image1.ps"
592 ;; "LeftMargin" "BottomMargin") ; X and Y position (lower left corner)
593 ;; ("~/images/EPS-image2.ps"
594 ;; "LeftMargin" "BottomMargin PrintHeight 2 div add" ; X and Y position
595 ;; ; (upper left corner)
597 ;; 5 (11 . 17)) ; page list
600 ;; If it is not possible to read (or does not exist) an image file, that file
603 ;; The printing order is:
605 ;; 1. Print zebra stripes
606 ;; 2. Print background texts that it should be on all pages
607 ;; 3. Print background images that it should be on all pages
608 ;; 4. Print background texts only for current page (if any)
609 ;; 5. Print background images only for current page (if any)
611 ;; 7. Print buffer text (with faces, if specified) and line number
617 ;; Some tools are provided to help you customize your font setup.
619 ;; `ps-setup' returns (some part of) the current setup.
621 ;; To avoid wrapping too many lines, you may want to adjust the
622 ;; left and right margins and the font size. On UN*X systems, do:
623 ;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
624 ;; to determine the longest lines of your file.
625 ;; Then, the command `ps-line-lengths' will give you the correspondence
626 ;; between a line length (number of characters) and the maximum font
627 ;; size which doesn't wrap such a line with the current ps-print setup.
629 ;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
630 ;; the correspondence between a number of pages and the maximum font
631 ;; size which allow the number of lines of the current buffer or of
632 ;; its current region to fit in this number of pages.
634 ;; NOTE: line folding is not taken into account in this process and could
635 ;; change the results.
638 ;; New since version 1.5
639 ;; ---------------------
641 ;; Color output capability.
642 ;; Automatic detection of font attributes (bold, italic).
643 ;; Configurable headers with page numbers.
645 ;; Support for different paper sizes.
646 ;; Better conformance to PostScript Document Structure Conventions.
649 ;; New since version 2.8
650 ;; ---------------------
652 ;; [vinicius] 970809 Vinicius Jose Latorre <vinicius@cpqd.br>
654 ;; Handle control characters.
656 ;; New face attributes.
659 ;; Text and/or image on background.
661 ;; [jack] 960517 Jacques Duthen <duthen@cegelec-red.fr>
663 ;; Font family and float size for text and header.
666 ;; Tools for page setup.
669 ;; Known bugs and limitations of ps-print:
670 ;; --------------------------------------
672 ;; Although color printing will work in XEmacs 19.12, it doesn't work
673 ;; well; in particular, bold or italic fonts don't print in the right
676 ;; Invisible properties aren't correctly ignored in XEmacs 19.12.
678 ;; Automatic font-attribute detection doesn't work well, especially
679 ;; with hilit19 and older versions of get-create-face. Users having
680 ;; problems with auto-font detection should use the lists
681 ;; `ps-italic-faces' and `ps-bold-faces' and/or turn off automatic
682 ;; detection by setting `ps-auto-font-detect' to nil.
684 ;; Automatic font-attribute detection doesn't work with XEmacs 19.12
685 ;; in tty mode; use the lists `ps-italic-faces' and `ps-bold-faces'
688 ;; Still too slow; could use some hand-optimization.
690 ;; Default background color isn't working.
692 ;; Faces are always treated as opaque.
694 ;; Epoch and Emacs 18 not supported. At all.
696 ;; Fixed-pitch fonts work better for line folding, but are not required.
698 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' don't take care
705 ;; Add `ps-print-hook' (I don't know how to do that (yet!)).
706 ;; Add 4-up capability (really needed?).
707 ;; Add `ps-non-bold-faces' and `ps-non-italic-faces' (should be easy).
708 ;; Put one header per page over the columns (easy but needed?).
709 ;; Improve the memory management for big files (hard?).
710 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' should take care
716 ;; Thanks to Jim Thompson <?@?> for the 2.8 version I started from.
719 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for adding support for
720 ;; color and the invisible property.
722 ;; Thanks to Avishai Yacobi, avishaiy@mcil.comm.mot.com, for writing
723 ;; the initial port to Emacs 19. His code is no longer part of
724 ;; ps-print, but his work is still appreciated.
726 ;; Thanks to Remi Houdaille and Michel Train, michel@metasoft.fdn.org,
727 ;; for adding underline support. Their code also is no longer part of
728 ;; ps-print, but their efforts are not forgotten.
730 ;; Thanks also to all of you who mailed code to add features to
731 ;; ps-print; although I didn't use your code, I still appreciate your
732 ;; sharing it with me.
734 ;; Thanks to all who mailed comments, encouragement, and criticism.
735 ;; Thanks also to all who responded to my survey; I had too many
736 ;; responses to reply to them all, but I greatly appreciate your
740 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
747 (unless (featurep 'lisp-float-type
)
748 (error "`ps-print' requires floating point support"))
750 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
753 ;;; Interface to the command system
755 (defgroup ps-print nil
756 "Postscript generator for Emacs 19"
760 (defgroup ps-print-horizontal nil
761 "Horizontal page layout"
766 (defgroup ps-print-vertical nil
767 "Vertical page layout"
772 (defgroup ps-print-header nil
778 (defgroup ps-print-font nil
779 "Fonts customization"
784 (defgroup ps-print-color nil
785 "Color customization"
790 (defgroup ps-print-face nil
791 "Faces customization"
798 (defcustom ps-lpr-command lpr-command
799 "*The shell command for printing a PostScript file."
803 (defcustom ps-lpr-switches lpr-switches
804 "*A list of extra switches to pass to `ps-lpr-command'."
805 :type
'(repeat string
)
810 ;; All page dimensions are in PostScript points.
811 ;; 1 inch == 2.54 cm == 72 points
812 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
814 ;; Letter 8.5 inch x 11.0 inch
815 ;; Legal 8.5 inch x 14.0 inch
816 ;; A4 8.26 inch x 11.69 inch = 21.0 cm x 29.7 cm
818 ;; LetterSmall 7.68 inch x 10.16 inch
819 ;; Tabloid 11.0 inch x 17.0 inch
820 ;; Ledger 17.0 inch x 11.0 inch
821 ;; Statement 5.5 inch x 8.5 inch
822 ;; Executive 7.5 inch x 10.0 inch
823 ;; A3 11.69 inch x 16.5 inch = 29.7 cm x 42.0 cm
824 ;; A4Small 7.47 inch x 10.85 inch
825 ;; B4 10.125 inch x 14.33 inch
826 ;; B5 7.16 inch x 10.125 inch
828 (defcustom ps-page-dimensions-database
829 (list (list 'a4
(/ (* 72 21.0) 2.54) (/ (* 72 29.7) 2.54))
830 (list 'a3
(/ (* 72 29.7) 2.54) (/ (* 72 42.0) 2.54))
831 (list 'letter
(* 72 8.5) (* 72 11.0))
832 (list 'legal
(* 72 8.5) (* 72 14.0))
833 (list 'letter-small
(* 72 7.68) (* 72 10.16))
834 (list 'tabloid
(* 72 11.0) (* 72 17.0))
835 (list 'ledger
(* 72 17.0) (* 72 11.0))
836 (list 'statement
(* 72 5.5) (* 72 8.5))
837 (list 'executive
(* 72 7.5) (* 72 10.0))
838 (list 'a4small
(* 72 7.47) (* 72 10.85))
839 (list 'b4
(* 72 10.125) (* 72 14.33))
840 (list 'b5
(* 72 7.16) (* 72 10.125)))
841 "*List associating a symbolic paper type to its width and height.
842 see `ps-paper-type'."
843 :type
'(repeat (list :tag
"Paper Type"
845 (number :tag
"Width")
846 (number :tag
"Height")))
849 (defcustom ps-paper-type
'letter
850 "*Specifies the size of paper to format for.
851 Should be one of the paper types defined in `ps-page-dimensions-database', for
852 example `letter', `legal' or `a4'."
853 :type
'(symbol :validate
(lambda (wid)
854 (if (assq (widget-value wid
)
855 ps-page-dimensions-database
)
857 (widget-put wid
:error
"Unknown paper size")
861 (defcustom ps-landscape-mode nil
862 "*Non-nil means print in landscape mode."
866 (defcustom ps-number-of-columns
(if ps-landscape-mode
2 1)
867 "*Specifies the number of columns"
871 (defcustom ps-zebra-stripes nil
872 "*Non-nil means print zebra stripes.
873 See also documentation for `ps-zebra-stripe-height'."
877 (defcustom ps-zebra-stripe-height
3
878 "*Number of zebra stripe lines.
879 See also documentation for `ps-zebra-stripes'."
883 (defcustom ps-line-number nil
884 "*Non-nil means print line number."
888 (defcustom ps-print-background-image nil
889 "*EPS image list to be printed on background.
893 (FILENAME X Y XSCALE YSCALE ROTATION PAGES...)
895 FILENAME is a file name which contains an EPS image or some PostScript
896 programming like EPS.
897 FILENAME is ignored, if it doesn't exist or is read protected.
899 X and Y are relative positions on paper to put the image.
900 If X and Y are nil, the image is centralized on paper.
902 XSCALE and YSCALE are scale factor to be applied to image before printing.
903 If XSCALE and YSCALE are nil, the original size is used.
905 ROTATION is the image rotation angle; if nil, the default is 0.
907 PAGES designates the page to print background image.
908 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
910 If PAGES is nil, print background image on all pages.
912 X, Y, XSCALE, YSCALE and ROTATION may be a floating point number,
913 an integer number or a string. If it is a string, the string should contain
914 PostScript programming that returns a float or integer value.
916 For example, if you wish to print an EPS image on all pages do:
918 '((\"~/images/EPS-image.ps\"))"
922 (defcustom ps-print-background-text nil
923 "*Text list to be printed on background.
927 (STRING X Y FONT FONTSIZE GRAY ROTATION PAGES...)
929 STRING is the text to be printed on background.
931 X and Y are positions on paper to put the text.
932 If X and Y are nil, the text is positioned at lower left corner.
934 FONT is a font name to be used on printing the text.
935 If nil, \"Times-Roman\" is used.
937 FONTSIZE is font size to be used, if nil, 200 is used.
939 GRAY is the text gray factor (should be very light like 0.8).
940 If nil, the default is 0.85.
942 ROTATION is the text rotation angle; if nil, the angle is given by
943 the diagonal from lower left corner to upper right corner.
945 PAGES designates the page to print background text.
946 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
948 If PAGES is nil, print background text on all pages.
950 X, Y, FONTSIZE, GRAY and ROTATION may be a floating point number,
951 an integer number or a string. If it is a string, the string should contain
952 PostScript programming that returns a float or integer value.
954 For example, if you wish to print text \"Preliminary\" on all pages do:
956 '((\"Preliminary\"))"
960 ;;; Horizontal layout
962 ;; ------------------------------------------
964 ;; | lm | text | ic | text | ic | text | rm |
966 ;; ------------------------------------------
968 (defcustom ps-left-margin
(/ (* 72 2.0) 2.54) ; 2 cm
969 "*Left margin in points (1/72 inch)."
971 :group
'ps-print-horizontal
)
973 (defcustom ps-right-margin
(/ (* 72 2.0) 2.54) ; 2 cm
974 "*Right margin in points (1/72 inch)."
976 :group
'ps-print-horizontal
)
978 (defcustom ps-inter-column
(/ (* 72 2.0) 2.54) ; 2 cm
979 "*Horizontal space between columns in points (1/72 inch)."
981 :group
'ps-print-horizontal
)
997 (defcustom ps-bottom-margin
(/ (* 72 1.5) 2.54) ; 1.5 cm
998 "*Bottom margin in points (1/72 inch)."
1000 :group
'ps-print-vertical
)
1002 (defcustom ps-top-margin
(/ (* 72 1.5) 2.54) ; 1.5 cm
1003 "*Top margin in points (1/72 inch)."
1005 :group
'ps-print-vertical
)
1007 (defcustom ps-header-offset
(/ (* 72 1.0) 2.54) ; 1.0 cm
1008 "*Vertical space in points (1/72 inch) between the main text and the header."
1010 :group
'ps-print-vertical
)
1012 (defcustom ps-header-line-pad
0.15
1013 "*Portion of a header title line height to insert between the header frame
1014 and the text it contains, both in the vertical and horizontal directions."
1016 :group
'ps-print-vertical
)
1020 (defcustom ps-print-header t
1021 "*Non-nil means print a header at the top of each page.
1022 By default, the header displays the buffer name, page number, and, if
1023 the buffer is visiting a file, the file's directory. Headers are
1024 customizable by changing variables `ps-left-header' and
1027 :group
'ps-print-header
)
1029 (defcustom ps-print-header-frame t
1030 "*Non-nil means draw a gaudy frame around the header."
1032 :group
'ps-print-header
)
1034 (defcustom ps-header-lines
2
1035 "*Number of lines to display in page header, when generating Postscript."
1037 :group
'ps-print-header
)
1038 (make-variable-buffer-local 'ps-header-lines
)
1040 (defcustom ps-show-n-of-n t
1041 "*Non-nil means show page numbers as N/M, meaning page N of M.
1042 Note: page numbers are displayed as part of headers, see variable
1043 `ps-print-headers'."
1045 :group
'ps-print-header
)
1047 (defcustom ps-spool-duplex nil
; Not many people have duplex
1048 ; printers, so default to nil.
1049 "*Non-nil indicates spooling is for a two-sided printer.
1050 For a duplex printer, the `ps-spool-*' commands will insert blank pages
1051 as needed between print jobs so that the next buffer printed will
1052 start on the right page. Also, if headers are turned on, the headers
1053 will be reversed on duplex printers so that the page numbers fall to
1054 the left on even-numbered pages."
1056 :group
'ps-print-header
)
1060 (defcustom ps-font-info-database
1061 '((Courier ; the family key
1062 "Courier" "Courier-Bold" "Courier-Oblique" "Courier-BoldOblique"
1064 (Helvetica ; the family key
1065 "Helvetica" "Helvetica-Bold" "Helvetica-Oblique" "Helvetica-BoldOblique"
1066 10.0 11.56 2.78 5.09243)
1068 "Times-Roman" "Times-Bold" "Times-Italic" "Times-BoldItalic"
1069 10.0 11.0 2.5 4.71432)
1071 "Palatino-Roman" "Palatino-Bold" "Palatino-Italic" "Palatino-BoldItalic"
1072 10.0 12.1 2.5 5.08676)
1074 "Helvetica-Narrow" "Helvetica-Narrow-Bold"
1075 "Helvetica-Narrow-Oblique" "Helvetica-Narrow-BoldOblique"
1076 10.0 11.56 2.2796 4.17579)
1078 "NewCenturySchlbk-Roman" "NewCenturySchlbk-Bold"
1079 "NewCenturySchlbk-Italic" "NewCenturySchlbk-BoldItalic"
1080 10.0 12.15 2.78 5.31162)
1081 ;; got no bold for the next ones
1083 "AvantGarde-Book" "AvantGarde-Book"
1084 "AvantGarde-BookOblique" "AvantGarde-BookOblique"
1085 10.0 11.77 2.77 5.45189)
1087 "AvantGarde-Demi" "AvantGarde-Demi"
1088 "AvantGarde-DemiOblique" "AvantGarde-DemiOblique"
1089 10.0 12.72 2.8 5.51351)
1091 "Bookman-Demi" "Bookman-Demi"
1092 "Bookman-DemiItalic" "Bookman-DemiItalic"
1093 10.0 11.77 3.4 6.05946)
1095 "Bookman-Light" "Bookman-Light"
1096 "Bookman-LightItalic" "Bookman-LightItalic"
1097 10.0 11.79 3.2 5.67027)
1098 ;; got no bold and no italic for the next ones
1100 "Symbol" "Symbol" "Symbol" "Symbol"
1101 10.0 13.03 2.5 3.24324)
1103 "Zapf-Dingbats" "Zapf-Dingbats" "Zapf-Dingbats" "Zapf-Dingbats"
1104 10.0 9.63 2.78 2.78)
1105 (Zapf-Chancery-MediumItalic
1106 "Zapf-Chancery-MediumItalic" "Zapf-Chancery-MediumItalic"
1107 "Zapf-Chancery-MediumItalic" "Zapf-Chancery-MediumItalic"
1108 10.0 11.45 2.2 4.10811)
1110 "*Font info database: font family (the key), name, bold, italic, bold-italic,
1111 reference size, line height, space width, average character width.
1112 To get the info for another specific font (say Helvetica), do the following:
1113 - create a new buffer
1114 - generate the PostScript image to a file (C-u M-x ps-print-buffer)
1115 - open this file and delete the leading `%' (which is the Postscript
1116 comment character) from the line
1117 `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
1119 `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
1120 - add the values to `ps-font-info-database'.
1121 You can get all the fonts of YOUR printer using `ReportAllFontInfo'."
1122 :type
'(repeat (list :tag
"Font Definition"
1123 (symbol :tag
"Font")
1124 (string :tag
"Name")
1125 (string :tag
"Bold")
1126 (string :tag
"Italic")
1127 (string :tag
"Bold-Italic")
1128 (number :tag
"Reference Size")
1129 (number :tag
"Line Height")
1130 (number :tag
"Space Width")
1131 (number :tag
"Average Character Width")))
1132 :group
'ps-print-font
)
1134 (defcustom ps-font-family
'Courier
1135 "Font family name for ordinary text, when generating Postscript."
1137 :group
'ps-print-font
)
1139 (defcustom ps-font-size
(if ps-landscape-mode
7 8.5)
1140 "Font size, in points, for ordinary text, when generating Postscript."
1142 :group
'ps-print-font
)
1144 (defcustom ps-header-font-family
'Helvetica
1145 "Font family name for text in the header, when generating Postscript."
1147 :group
'ps-print-font
)
1149 (defcustom ps-header-font-size
(if ps-landscape-mode
10 12)
1150 "Font size, in points, for text in the header, when generating Postscript."
1152 :group
'ps-print-font
)
1154 (defcustom ps-header-title-font-size
(if ps-landscape-mode
12 14)
1155 "Font size, in points, for the top line of text in the header,
1156 when generating Postscript."
1158 :group
'ps-print-font
)
1162 ;; Printing color requires x-color-values.
1163 (defcustom ps-print-color-p
(or (fboundp 'x-color-values
) ; Emacs
1164 (fboundp 'pixel-components
)) ; XEmacs
1165 "*If non-nil, print the buffer's text in color."
1167 :group
'ps-print-color
)
1169 (defcustom ps-default-fg
'(0.0
0.0 0.0)
1170 "*RGB values of the default foreground color. Defaults to black."
1171 :type
'(list (number :tag
"Red") (number :tag
"Green") (number :tag
"Blue"))
1172 :group
'ps-print-color
)
1174 (defcustom ps-default-bg
'(1.0
1.0 1.0)
1175 "*RGB values of the default background color. Defaults to white."
1176 :type
'(list (number :tag
"Red") (number :tag
"Green") (number :tag
"Blue"))
1177 :group
'ps-print-color
)
1179 (defcustom ps-auto-font-detect t
1180 "*Non-nil means automatically detect bold/italic face attributes.
1181 If nil, we rely solely on the lists `ps-bold-faces', `ps-italic-faces',
1182 and `ps-underlined-faces'."
1184 :group
'ps-print-font
)
1186 (defcustom ps-bold-faces
1187 (unless ps-print-color-p
1188 '(font-lock-function-name-face
1189 font-lock-builtin-face
1190 font-lock-variable-name-face
1191 font-lock-keyword-face
1192 font-lock-warning-face
))
1193 "*A list of the \(non-bold\) faces that should be printed in bold font.
1194 This applies to generating Postscript."
1195 :type
'(repeat face
)
1196 :group
'ps-print-face
)
1198 (defcustom ps-italic-faces
1199 (unless ps-print-color-p
1200 '(font-lock-variable-name-face
1201 font-lock-string-face
1202 font-lock-comment-face
1203 font-lock-warning-face
))
1204 "*A list of the \(non-italic\) faces that should be printed in italic font.
1205 This applies to generating Postscript."
1206 :type
'(repeat face
)
1207 :group
'ps-print-face
)
1209 (defcustom ps-underlined-faces
1210 (unless ps-print-color-p
1211 '(font-lock-function-name-face
1213 font-lock-reference-face
1214 font-lock-warning-face
))
1215 "*A list of the \(non-underlined\) faces that should be printed underlined.
1216 This applies to generating Postscript."
1217 :type
'(repeat face
)
1218 :group
'ps-print-face
)
1220 (defcustom ps-left-header
1221 (list 'ps-get-buffer-name
'ps-header-dirpart
)
1222 "*The items to display (each on a line) on the left part of the page header.
1223 This applies to generating Postscript.
1225 The value should be a list of strings and symbols, each representing an
1226 entry in the PostScript array HeaderLinesLeft.
1228 Strings are inserted unchanged into the array; those representing
1229 PostScript string literals should be delimited with PostScript string
1230 delimiters '(' and ')'.
1232 For symbols with bound functions, the function is called and should
1233 return a string to be inserted into the array. For symbols with bound
1234 values, the value should be a string to be inserted into the array.
1235 In either case, function or variable, the string value has PostScript
1236 string delimiters added to it."
1237 :type
'(repeat (choice string symbol
))
1238 :group
'ps-print-header
)
1239 (make-variable-buffer-local 'ps-left-header
)
1241 (defcustom ps-right-header
1242 (list "/pagenumberstring load" 'time-stamp-mon-dd-yyyy
'time-stamp-hh
:mm
:ss
)
1243 "*The items to display (each on a line) on the right part of the page header.
1244 This applies to generating Postscript.
1246 See the variable `ps-left-header' for a description of the format of
1248 :type
'(repeat (choice string symbol
))
1249 :group
'ps-print-header
)
1250 (make-variable-buffer-local 'ps-right-header
)
1252 (defcustom ps-razzle-dazzle t
1253 "*Non-nil means report progress while formatting buffer."
1257 (defcustom ps-adobe-tag
"%!PS-Adobe-3.0\n"
1258 "*Contains the header line identifying the output as PostScript.
1259 By default, `ps-adobe-tag' contains the standard identifier. Some
1260 printers require slightly different versions of this line."
1264 (defcustom ps-build-face-reference t
1265 "*Non-nil means build the reference face lists.
1267 Ps-print sets this value to nil after it builds its internal reference
1268 lists of bold and italic faces. By settings its value back to t, you
1269 can force ps-print to rebuild the lists the next time you invoke one
1270 of the ...-with-faces commands.
1272 You should set this value back to t after you change the attributes of
1273 any face, or create new faces. Most users shouldn't have to worry
1274 about its setting, though."
1276 :group
'ps-print-face
)
1278 (defcustom ps-always-build-face-reference nil
1279 "*Non-nil means always rebuild the reference face lists.
1281 If this variable is non-nil, ps-print will rebuild its internal
1282 reference lists of bold and italic faces *every* time one of the
1283 -with-faces commands is called. Most users shouldn't need to set this
1286 :group
'ps-print-face
)
1288 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1292 (defun ps-print-buffer (&optional filename
)
1293 "Generate and print a PostScript image of the buffer.
1295 When called with a numeric prefix argument (C-u), prompts the user for
1296 the name of a file to save the PostScript image in, instead of sending
1299 More specifically, the FILENAME argument is treated as follows: if it
1300 is nil, send the image to the printer. If FILENAME is a string, save
1301 the PostScript image in a file with that name. If FILENAME is a
1302 number, prompt the user for the name of the file to save in."
1303 (interactive (list (ps-print-preprint current-prefix-arg
)))
1304 (ps-print-without-faces (point-min) (point-max) filename
))
1308 (defun ps-print-buffer-with-faces (&optional filename
)
1309 "Generate and print a PostScript image of the buffer.
1310 Like `ps-print-buffer', but includes font, color, and underline
1311 information in the generated image. This command works only if you
1312 are using a window system, so it has a way to determine color values."
1313 (interactive (list (ps-print-preprint current-prefix-arg
)))
1314 (ps-print-with-faces (point-min) (point-max) filename
))
1318 (defun ps-print-region (from to
&optional filename
)
1319 "Generate and print a PostScript image of the region.
1320 Like `ps-print-buffer', but prints just the current region."
1321 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg
)))
1322 (ps-print-without-faces from to filename t
))
1326 (defun ps-print-region-with-faces (from to
&optional filename
)
1327 "Generate and print a PostScript image of the region.
1328 Like `ps-print-region', but includes font, color, and underline
1329 information in the generated image. This command works only if you
1330 are using a window system, so it has a way to determine color values."
1331 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg
)))
1332 (ps-print-with-faces from to filename t
))
1336 (defun ps-spool-buffer ()
1337 "Generate and spool a PostScript image of the buffer.
1338 Like `ps-print-buffer' except that the PostScript image is saved in a
1339 local buffer to be sent to the printer later.
1341 Use the command `ps-despool' to send the spooled images to the printer."
1343 (ps-spool-without-faces (point-min) (point-max)))
1347 (defun ps-spool-buffer-with-faces ()
1348 "Generate and spool a PostScript image of the buffer.
1349 Like `ps-spool-buffer', but includes font, color, and underline
1350 information in the generated image. This command works only if you
1351 are using a window system, so it has a way to determine color values.
1353 Use the command `ps-despool' to send the spooled images to the printer."
1355 (ps-spool-with-faces (point-min) (point-max)))
1359 (defun ps-spool-region (from to
)
1360 "Generate a PostScript image of the region and spool locally.
1361 Like `ps-spool-buffer', but spools just the current region.
1363 Use the command `ps-despool' to send the spooled images to the printer."
1365 (ps-spool-without-faces from to t
))
1369 (defun ps-spool-region-with-faces (from to
)
1370 "Generate a PostScript image of the region and spool locally.
1371 Like `ps-spool-region', but includes font, color, and underline
1372 information in the generated image. This command works only if you
1373 are using a window system, so it has a way to determine color values.
1375 Use the command `ps-despool' to send the spooled images to the printer."
1377 (ps-spool-with-faces from to t
))
1380 (defun ps-despool (&optional filename
)
1381 "Send the spooled PostScript to the printer.
1383 When called with a numeric prefix argument (C-u), prompt the user for
1384 the name of a file to save the spooled PostScript in, instead of sending
1387 More specifically, the FILENAME argument is treated as follows: if it
1388 is nil, send the image to the printer. If FILENAME is a string, save
1389 the PostScript image in a file with that name. If FILENAME is a
1390 number, prompt the user for the name of the file to save in."
1391 (interactive (list (ps-print-preprint current-prefix-arg
)))
1392 (ps-do-despool filename
))
1395 (defun ps-line-lengths ()
1396 "Display the correspondence between a line length and a font size,
1397 using the current ps-print setup.
1398 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
1400 (ps-line-lengths-internal))
1403 (defun ps-nb-pages-buffer (nb-lines)
1404 "Display number of pages to print this buffer, for various font heights.
1405 The table depends on the current ps-print setup."
1406 (interactive (list (count-lines (point-min) (point-max))))
1407 (ps-nb-pages nb-lines
))
1410 (defun ps-nb-pages-region (nb-lines)
1411 "Display number of pages to print the region, for various font heights.
1412 The table depends on the current ps-print setup."
1413 (interactive (list (count-lines (mark) (point))))
1414 (ps-nb-pages nb-lines
))
1418 "Return the current setup."
1421 \(setq ps-print-color-p %s
1422 ps-lpr-command \"%s\"
1426 ps-landscape-mode %s
1427 ps-number-of-columns %s
1430 ps-zebra-stripe-height %s
1433 ps-print-background-image %s
1435 ps-print-background-text %s
1443 ps-header-line-pad %s
1445 ps-print-header-frame %s
1452 ps-header-font-family '%s
1453 ps-header-font-size %s
1454 ps-header-title-font-size %s)
1461 ps-number-of-columns
1463 ps-zebra-stripe-height
1465 ps-print-background-image
1466 ps-print-background-text
1475 ps-print-header-frame
1481 ps-header-font-family
1483 ps-header-title-font-size
))
1485 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1486 ;; Utility functions and variables:
1488 (defvar ps-print-emacs-type
1489 (cond ((string-match "XEmacs" emacs-version
) 'xemacs
)
1490 ((string-match "Lucid" emacs-version
) 'lucid
)
1491 ((string-match "Epoch" emacs-version
) 'epoch
)
1494 (if (or (eq ps-print-emacs-type
'lucid
)
1495 (eq ps-print-emacs-type
'xemacs
))
1496 (if (< emacs-minor-version
12)
1497 (setq ps-print-color-p nil
))
1498 (require 'faces
)) ; face-font, face-underline-p,
1501 (require 'time-stamp
)
1504 "Font family name for ordinary text, when generating Postscript.")
1506 (defvar ps-font-bold nil
1507 "Font family name for bold text, when generating Postscript.")
1509 (defvar ps-font-italic nil
1510 "Font family name for italic text, when generating Postscript.")
1512 (defvar ps-font-bold-italic nil
1513 "Font family name for bold italic text, when generating Postscript.")
1515 (defvar ps-avg-char-width nil
1516 "The average width, in points, of a character, for generating Postscript.
1517 This is the value that ps-print uses to determine the length,
1518 x-dimension, of the text it has printed, and thus affects the point at
1519 which long lines wrap around.")
1521 (defvar ps-space-width nil
1522 "The width of a space character, for generating Postscript.
1523 This value is used in expanding tab characters.")
1525 (defvar ps-line-height nil
1526 "The height of a line, for generating Postscript.
1527 This is the value that ps-print uses to determine the height,
1528 y-dimension, of the lines of text it has printed, and thus affects the
1529 point at which page-breaks are placed.
1530 The line-height is *not* the same as the point size of the font.")
1532 (defvar ps-print-prologue-1
1533 "% ISOLatin1Encoding stolen from ps_init.ps in GhostScript 2.6.1.4:
1534 /ISOLatin1Encoding where { pop } {
1535 % -- The ISO Latin-1 encoding vector isn't known, so define it.
1536 % -- The first half is the same as the standard encoding,
1537 % -- except for minus instead of hyphen at code 055.
1539 StandardEncoding 0 45 getinterval aload pop
1541 StandardEncoding 46 82 getinterval aload pop
1542 %*** NOTE: the following are missing in the Adobe documentation,
1543 %*** but appear in the displayed table:
1544 %*** macron at 0225, dieresis at 0230, cedilla at 0233, space at 0240.
1546 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
1547 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
1548 /dotlessi /grave /acute /circumflex /tilde /macron /breve /dotaccent
1549 /dieresis /.notdef /ring /cedilla /.notdef /hungarumlaut /ogonek /caron
1551 /space /exclamdown /cent /sterling
1552 /currency /yen /brokenbar /section
1553 /dieresis /copyright /ordfeminine /guillemotleft
1554 /logicalnot /hyphen /registered /macron
1555 /degree /plusminus /twosuperior /threesuperior
1556 /acute /mu /paragraph /periodcentered
1557 /cedilla /onesuperior /ordmasculine /guillemotright
1558 /onequarter /onehalf /threequarters /questiondown
1560 /Agrave /Aacute /Acircumflex /Atilde
1561 /Adieresis /Aring /AE /Ccedilla
1562 /Egrave /Eacute /Ecircumflex /Edieresis
1563 /Igrave /Iacute /Icircumflex /Idieresis
1564 /Eth /Ntilde /Ograve /Oacute
1565 /Ocircumflex /Otilde /Odieresis /multiply
1566 /Oslash /Ugrave /Uacute /Ucircumflex
1567 /Udieresis /Yacute /Thorn /germandbls
1569 /agrave /aacute /acircumflex /atilde
1570 /adieresis /aring /ae /ccedilla
1571 /egrave /eacute /ecircumflex /edieresis
1572 /igrave /iacute /icircumflex /idieresis
1573 /eth /ntilde /ograve /oacute
1574 /ocircumflex /otilde /odieresis /divide
1575 /oslash /ugrave /uacute /ucircumflex
1576 /udieresis /yacute /thorn /ydieresis
1580 /reencodeFontISO { %def
1582 length 12 add dict % Make a new font (a new dict the same size
1583 % as the old one) with room for our new symbols.
1585 begin % Make the new font the current dictionary.
1589 { def } { pop pop } ifelse
1590 } forall % Copy each of the symbols from the old dictionary
1591 % to the new one except for the font ID.
1593 /Encoding ISOLatin1Encoding def % Override the encoding with
1594 % the ISOLatin1 encoding.
1596 % Use the font's bounding box to determine the ascent, descent,
1597 % and overall height; don't forget that these values have to be
1598 % transformed using the font's matrix.
1605 % | | | | Ascent (usually > 0)
1607 % (0 0) -> +--+----+-------->
1609 % | | v Descent (usually < 0)
1610 % (x1 y1) --> +----+ - -
1612 FontBBox % -- x1 y1 x2 y2
1613 FontMatrix transform /Ascent exch def pop
1614 FontMatrix transform /Descent exch def pop
1615 /FontHeight Ascent Descent sub def % use `sub' because descent < 0
1617 % Define these in case they're not in the FontInfo
1618 % (also, here they're easier to get to).
1619 /UnderlinePosition Descent 0.70 mul def
1620 /OverlinePosition Descent UnderlinePosition sub Ascent add def
1621 /StrikeoutPosition Ascent 0.30 mul def
1622 /LineThickness 0 50 FontMatrix transform exch pop def
1623 /Xshadow 0 80 FontMatrix transform exch pop def
1624 /Yshadow 0 -90 FontMatrix transform exch pop def
1625 /SpaceBackground Descent neg UnderlinePosition add def
1626 /XBox Descent neg def
1627 /YBox LineThickness 0.7 mul def
1629 currentdict % Leave the new font on the stack
1630 end % Stop using the font as the current dictionary.
1631 definefont % Put the font into the font dictionary
1632 pop % Discard the returned font.
1635 /DefFont { % Font definition
1636 findfont exch scalefont reencodeFontISO
1639 /F { % Font selection
1641 dup /Ascent get /Ascent exch def
1642 dup /Descent get /Descent exch def
1643 dup /FontHeight get /FontHeight exch def
1644 dup /UnderlinePosition get /UnderlinePosition exch def
1645 dup /OverlinePosition get /OverlinePosition exch def
1646 dup /StrikeoutPosition get /StrikeoutPosition exch def
1647 dup /LineThickness get /LineThickness exch def
1648 dup /Xshadow get /Xshadow exch def
1649 dup /Yshadow get /Yshadow exch def
1650 dup /SpaceBackground get /SpaceBackground exch def
1651 dup /XBox get /XBox exch def
1652 dup /YBox get /YBox exch def
1656 /FG /setrgbcolor load def
1669 % | Ascent (usually > 0)
1671 % | Descent (usually < 0)
1675 /dobackground { % width --
1676 currentpoint % -- width x y
1680 0 Ascent rmoveto % B
1682 0 Descent Ascent sub rlineto % D
1685 bgcolor aload pop setrgbcolor
1690 /eolbg { % dobackground until right margin
1691 PrintWidth % -- x-eol
1692 currentpoint pop % -- cur-x
1693 sub % -- width until eol
1697 /PLN {PrintLineNumber {doLineNumber}if} def
1699 /SL { % Soft Linefeed
1701 0 currentpoint exch pop LineHeight sub moveto
1704 /HL {SL PLN} def % Hard Linefeed
1707 /dcp { currentpoint exch 40 string cvs print (, ) print = } def
1708 /dp { print 2 copy exch 40 string cvs print (, ) print = } def
1711 ( ) stringwidth % Get the width of a space in the current font.
1712 pop % Discard the Y component.
1713 mul % Multiply the width of a space
1714 % by the number of spaces to plot
1715 bg { dup dobackground } if
1720 /EF {/Effect exch def} def
1722 % stack: string |- --
1723 % effect: 1 - underline 2 - strikeout 4 - overline
1724 % 8 - shadow 16 - box 32 - outline
1726 /xx currentpoint dup Descent add /yy exch def
1727 Ascent add /YY exch def def
1728 dup stringwidth pop xx add /XX exch def
1730 /yy yy Yshadow add def
1731 /XX XX Xshadow add def
1736 {SpaceBackground doBox}
1737 {xx yy XX YY doRect}
1740 Effect 16 and 0 ne {false 0 doBox}if % box
1741 Effect 8 and 0 ne {dup doShadow}if % shadow
1743 {true doOutline} % outline
1744 {show} % normal text
1746 Effect 1 and 0 ne {UnderlinePosition Hline}if % underline
1747 Effect 2 and 0 ne {StrikeoutPosition Hline}if % strikeout
1748 Effect 4 and 0 ne {OverlinePosition Hline}if % overline
1751 % stack: position |- --
1753 currentpoint exch pop add dup
1759 LineThickness setlinewidth stroke
1763 % stack: fill-or-not delta |- --
1766 xx XBox sub dd sub yy YBox sub dd sub
1767 XX XBox add dd add YY YBox add dd add
1771 % stack: fill-or-not lower-x lower-y upper-x upper-y |- --
1784 % top of stack: fill-or-not
1786 {LineThickness setlinewidth stroke}
1791 % stack: string |- --
1794 Xshadow Yshadow rmoveto
1801 % stack: string fill-or-not |- --
1804 /-ox- currentpoint /-oy- exch def def
1806 LineThickness setlinewidth
1809 st dup true charpath
1810 -fillp- {gsave FillBgColor grestore}if
1812 -oy- add /-oy- exch def
1813 -ox- add /-ox- exch def
1821 /FillBgColor {bgcolor aload pop setrgbcolor fill} bind def
1823 /L0 6 /Times-Italic DefFont
1829 0.0 0.0 0.0 setrgbcolor
1830 /L0 findfont setfont
1833 {LineNumber 6 string cvs ( ) strcat}
1835 dup stringwidth pop neg 0 rmoveto
1839 /LineNumber LineNumber 1 add def
1846 /double-zebra NumberOfZebra NumberOfZebra add def
1847 /yiter double-zebra LineHeight mul neg def
1848 /xiter PrintWidth InterColumn add def
1849 NumberOfColumns {LinesPerColumn doColumnZebra xiter 0 rmoveto}repeat
1853 % stack: lines-per-column |- --
1856 dup double-zebra idiv {NumberOfZebra doZebra 0 yiter rmoveto}repeat
1858 dup 0 le {pop}{dup NumberOfZebra gt {pop NumberOfZebra}if doZebra}ifelse
1862 % stack: zebra-height (in lines) |- --
1864 /zh exch 0.05 sub LineHeight mul def
1866 0 LineHeight 0.65 mul rmoveto
1867 PrintWidth 0 rlineto
1869 PrintWidth neg 0 rlineto
1875 % tx ty rotation xscale yscale xpos ypos BeginBackImage
1877 /-save-image- save def
1886 -save-image- restore
1889 % string fontsize fontname rotation gray xpos ypos ShowBackText
1895 findfont exch dup /-offset- exch -0.25 mul def scalefont setfont
1897 /-saveLineThickness- LineThickness def
1898 /LineThickness 1 def
1900 /LineThickness -saveLineThickness- def
1905 % ---- save the state of the document (useful for ghostscript!)
1907 % ---- [jack] Kludge: my ghostscript window is 21x27.7 instead of 21x29.7
1908 /JackGhostscript where {
1909 pop 1 27.7 29.7 div scale
1912 % ---- translate to bottom-right corner of Portrait page
1913 LandscapePageHeight 0 translate
1916 /ColumnWidth PrintWidth InterColumn add def
1917 % ---- translate to lower left corner of TEXT
1918 LeftMargin BottomMargin translate
1919 % ---- define where printing will start
1920 /f0 F % this installs Ascent
1921 /PrintStartY PrintHeight Ascent sub def
1926 % ---- on last page but not last column, spit out the page
1927 ColumnIndex 1 eq not { showpage } if
1928 % ---- restore the state of the document (useful for ghostscript!)
1933 % ---- when 1st column, save the state of the page
1934 ColumnIndex 1 eq { /pageState save def } if
1935 % ---- save the state of the column
1936 /columnState save def
1940 % ---- when 1st column, print all background effects
1942 0 PrintStartY moveto % move to where printing will start
1943 Zebra {printZebra}if
1944 printGlobalBackground
1945 printLocalBackground
1948 PrintHeaderFrame { HeaderFrame } if
1951 0 PrintStartY moveto % move to where printing will start
1960 ColumnIndex NumberOfColumns eq {
1961 % ---- on last column, spit out the page
1963 % ---- restore the state of the page
1967 % ---- restore the state of the current column
1969 % ---- and translate to the next column
1970 ColumnWidth 0 translate
1971 /ColumnIndex ColumnIndex 1 add def
1975 /SetHeaderLines { % nb-lines --
1976 /HeaderLines exch def
1979 HeaderLines 1 sub HeaderLineHeight mul add
1980 HeaderTitleLineHeight add
1982 /HeaderHeight exch def
1989 % |-+-------| <-- (x y)
1993 % |-+-------| <-- (0 0)
1997 /HeaderFrameStart { % -- x y
1998 0 PrintHeight HeaderOffset add
2002 PrintWidth 0 rlineto
2003 0 HeaderHeight rlineto
2004 PrintWidth neg 0 rlineto
2005 0 HeaderHeight neg rlineto
2011 % ---- fill a black rectangle (the shadow of the next one)
2012 HeaderFrameStart moveto
2016 % ---- do the next rectangle ...
2017 HeaderFrameStart moveto
2019 gsave 0.9 setgray fill grestore % filled with grey
2020 gsave 0 setgray stroke grestore % drawn with black
2026 exch HeaderPad add exch % horizontal pad
2028 HeaderPad add % vertical pad
2030 HeaderLineHeight HeaderLines 1 sub mul add
2034 dup length 3 -1 roll dup length dup 4 -1 roll add string dup
2035 0 5 -1 roll putinterval
2036 dup 4 2 roll exch putinterval
2040 PageNumber 32 string cvs
2043 PageCount 32 string cvs strcat
2050 HeaderLinesRight HeaderLinesLeft % -- rightLines leftLines
2052 % ---- hack: `PN 1 and' == `PN 2 modulo'
2054 % ---- if duplex and even page number, then exchange left and right
2055 Duplex PageNumber 1 and 0 eq and { exch } if
2057 { % ---- process the left lines
2061 dup xcheck { exec } if
2064 0 HeaderLineHeight neg rmoveto
2069 { % ---- process the right lines
2073 dup xcheck { exec } if
2075 PrintWidth exch sub HeaderPad 2 mul sub 0 rmoveto
2078 0 HeaderLineHeight neg rmoveto
2084 /t0 3 1 roll DefFont
2087 /sw ( ) stringwidth pop def
2088 /aw (01234567890abcdefghijklmnopqrstuvwxyz) dup length exch
2089 stringwidth pop exch div def
2090 /t1 12 /Helvetica-Oblique DefFont
2097 ( point, the line height is ) show
2098 lh 32 string cvs show
2099 (, the space width is ) show
2100 sw 32 string cvs show
2103 0 FontHeight neg rmoveto
2105 (and a crude estimate of average character width is ) show
2106 aw 32 string cvs show
2109 0 FontHeight neg rmoveto
2116 /ReportAllFontInfo {
2118 { % key = font name value = font dictionary
2119 pop 10 exch ReportFontInfo
2123 % 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage
2124 % 3 cm 20 cm moveto ReportAllFontInfo showpage
2128 (defvar ps-print-prologue-2
2130 % ---- These lines must be kept together because...
2133 /HeaderTitleLineHeight FontHeight def
2136 /HeaderLineHeight FontHeight def
2137 /HeaderDescent Descent def
2139 % ---- ...because `F' has a side-effect on `FontHeight' and `Descent'
2143 ;; Start Editing Here:
2145 (defvar ps-source-buffer nil
)
2146 (defvar ps-spool-buffer-name
"*PostScript*")
2147 (defvar ps-spool-buffer nil
)
2149 (defvar ps-output-head nil
)
2150 (defvar ps-output-tail nil
)
2152 (defvar ps-page-count
0)
2153 (defvar ps-showline-count
1)
2155 (defvar ps-background-pages nil
)
2156 (defvar ps-background-all-pages nil
)
2157 (defvar ps-background-text-count
0)
2158 (defvar ps-background-image-count
0)
2160 (defvar ps-current-font
0)
2161 (defvar ps-default-color
(if ps-print-color-p ps-default-fg
)) ; black
2162 (defvar ps-current-color ps-default-color
)
2163 (defvar ps-current-bg nil
)
2165 (defvar ps-razchunk
0)
2167 (defvar ps-color-format
2168 (if (eq ps-print-emacs-type
'emacs
)
2170 ;;Emacs understands the %f format; we'll
2171 ;;use it to limit color RGB values to
2172 ;;three decimals to cut down some on the
2173 ;;size of the PostScript output.
2176 ;; Lucid emacsen will have to make do with
2177 ;; %s (princ) for floats.
2180 ;; These values determine how much print-height to deduct when headers
2181 ;; are turned on. This is a pretty clumsy way of handling it, but
2182 ;; it'll do for now.
2184 (defvar ps-header-font nil
)
2185 (defvar ps-header-title-font nil
)
2187 (defvar ps-header-line-height nil
)
2188 (defvar ps-header-title-line-height nil
)
2189 (defvar ps-header-pad
0
2190 "Vertical and horizontal space in points (1/72 inch) between the header frame
2191 and the text it contains.")
2193 ;; Define accessors to the dimensions list.
2195 (defmacro ps-page-dimensions-get-width
(dims) `(nth 0 ,dims
))
2196 (defmacro ps-page-dimensions-get-height
(dims) `(nth 1 ,dims
))
2198 (defvar ps-landscape-page-height nil
)
2200 (defvar ps-print-width nil
)
2201 (defvar ps-print-height nil
)
2203 (defvar ps-height-remaining
)
2204 (defvar ps-width-remaining
)
2206 (defvar ps-print-color-scale nil
)
2209 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2210 ;; Internal Variables
2213 (defvar ps-print-face-extension-alist nil
2214 "Alist of symbolic faces *WITH* extension features (box, outline, etc).
2215 An element of this list has the following form:
2217 (FACE . [BITS FG BG])
2219 FACE is a symbol denoting a face name
2220 BITS is a bit vector, where each bit correspond
2221 to a feature (bold, underline, etc)
2222 (see documentation for `ps-print-face-map-alist')
2223 FG foreground color (string or nil)
2224 BG background color (string or nil)
2226 Don't change this list directly; instead,
2227 use `ps-extend-face' and `ps-extend-face-list'.
2228 See documentation for `ps-extend-face' for valid extension symbol.")
2231 (defvar ps-print-face-alist nil
2232 "Alist of symbolic faces *WITHOUT* extension features (box, outline, etc).
2234 An element of this list has the same form as an element of
2235 `ps-print-face-extension-alist'.
2237 Don't change this list directly; this list is used by `ps-face-attributes',
2238 `ps-map-face' and `ps-build-reference-face-lists'.")
2241 (defconst ps-print-face-map-alist
2250 "Alist of all features and the corresponding bit mask.
2251 Each symbol correspond to one bit in a bit vector.")
2254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2259 (defun ps-extend-face-list (face-extension-list &optional merge-p
)
2260 "Extend face in `ps-print-face-extension-alist'.
2262 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION-LIST are merged
2263 with face extension in `ps-print-face-extension-alist'; otherwise, overrides.
2265 The elements in FACE-EXTENSION-LIST is like those for `ps-extend-face'.
2267 See `ps-extend-face' for documentation."
2268 (while face-extension-list
2269 (ps-extend-face (car face-extension-list
) merge-p
)
2270 (setq face-extension-list
(cdr face-extension-list
))))
2274 (defun ps-extend-face (face-extension &optional merge-p
)
2275 "Extend face in `ps-print-face-extension-alist'.
2277 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION-LIST are merged
2278 with face extensions in `ps-print-face-extension-alist'; otherwise, overrides.
2280 The elements of FACE-EXTENSION list have the form:
2282 (FACE-NAME FOREGROUND BACKGROUND EXTENSION...)
2284 FACE-NAME is a face name symbol.
2286 FOREGROUND and BACKGROUND may be nil or a string that denotes the
2287 foreground and background colors respectively.
2289 EXTENSION is one of the following symbols:
2290 bold - use bold font.
2291 italic - use italic font.
2292 underline - put a line under text.
2293 strikeout - like underline, but the line is in middle of text.
2294 overline - like underline, but the line is over the text.
2295 shadow - text will have a shadow.
2296 box - text will be surrounded by a box.
2297 outline - print characters as hollow outlines.
2299 If EXTENSION is any other symbol, it is ignored."
2300 (let* ((face-name (nth 0 face-extension
))
2301 (foreground (nth 1 face-extension
))
2302 (background (nth 2 face-extension
))
2303 (ps-face (cdr (assq face-name ps-print-face-extension-alist
)))
2304 (face-vector (or ps-face
(vector 0 nil nil
)))
2305 (face-bit (ps-extension-bit face-extension
)))
2307 (aset face-vector
0 (if merge-p
2308 (logior (aref face-vector
0) face-bit
)
2310 (and foreground
(stringp foreground
) (aset face-vector
1 foreground
))
2311 (and background
(stringp background
) (aset face-vector
2 background
))
2312 ;; if face does not exist, insert it
2314 (setq ps-print-face-extension-alist
2315 (cons (cons face-name face-vector
)
2316 ps-print-face-extension-alist
)))))
2319 (defun ps-extension-bit (face-extension)
2321 ;; map valid symbol extension to bit vector
2322 (setq face-extension
(cdr (cdr face-extension
)))
2323 (while (setq face-extension
(cdr face-extension
))
2324 (setq face-bit
(logior face-bit
2325 (or (cdr (assq (car face-extension
)
2326 ps-print-face-map-alist
))
2331 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2332 ;; Internal functions and variables
2335 (defun ps-print-without-faces (from to
&optional filename region-p
)
2336 (ps-printing-region region-p
)
2337 (ps-generate (current-buffer) from to
'ps-generate-postscript
)
2338 (ps-do-despool filename
))
2341 (defun ps-spool-without-faces (from to
&optional region-p
)
2342 (ps-printing-region region-p
)
2343 (ps-generate (current-buffer) from to
'ps-generate-postscript
))
2346 (defun ps-print-with-faces (from to
&optional filename region-p
)
2347 (ps-printing-region region-p
)
2348 (ps-generate (current-buffer) from to
'ps-generate-postscript-with-faces
)
2349 (ps-do-despool filename
))
2352 (defun ps-spool-with-faces (from to
&optional region-p
)
2353 (ps-printing-region region-p
)
2354 (ps-generate (current-buffer) from to
'ps-generate-postscript-with-faces
))
2357 (defsubst ps-count-lines
(from to
)
2358 (+ (count-lines from to
)
2359 (save-excursion (goto-char to
)
2360 (if (= (current-column) 0) 1 0))))
2363 (defvar ps-printing-region nil
2364 "Variable used to indicate if it is printing a region.
2365 If non-nil, it is a cons, the car of which is the line number
2366 where the region begins, and its cdr is the total number of lines
2367 in the buffer. Formatting functions can use this information
2368 to print the original line number (and not the number of lines printed),
2369 and to indicate in the header that the printout is of a partial file.")
2372 (defun ps-printing-region (region-p)
2373 (setq ps-printing-region
2375 (cons (ps-count-lines (point-min) (region-beginning))
2376 (ps-count-lines (point-min) (point-max))))))
2379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2380 ;; Internal functions
2382 (defun ps-line-lengths-internal ()
2383 "Display the correspondence between a line length and a font size,
2384 using the current ps-print setup.
2385 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2386 (let ((buf (get-buffer-create "*Line-lengths*"))
2387 (ifs ps-font-size
) ; initial font size
2388 (icw ps-avg-char-width
) ; initial character width
2389 (print-width (progn (ps-get-page-dimensions)
2391 (ps-setup (ps-setup)) ; setup for the current buffer
2392 (fs-min 5) ; minimum font size
2393 cw-min
; minimum character width
2394 nb-cpl-max
; maximum nb of characters per line
2395 (fs-max 14) ; maximum font size
2396 cw-max
; maximum character width
2397 nb-cpl-min
; minimum nb of characters per line
2398 fs
; current font size
2399 cw
; current character width
2400 nb-cpl
; current nb of characters per line
2402 (setq cw-min
(/ (* icw fs-min
) ifs
)
2403 nb-cpl-max
(floor (/ print-width cw-min
))
2404 cw-max
(/ (* icw fs-max
) ifs
)
2405 nb-cpl-min
(floor (/ print-width cw-max
)))
2406 (setq nb-cpl nb-cpl-min
)
2408 (goto-char (point-max))
2409 (if (not (bolp)) (insert "\n"))
2411 (insert "nb char per line / font size\n")
2412 (while (<= nb-cpl nb-cpl-max
)
2413 (setq cw
(/ print-width
(float nb-cpl
))
2414 fs
(/ (* ifs cw
) icw
))
2415 (insert (format "%3s %s\n" nb-cpl fs
))
2416 (setq nb-cpl
(1+ nb-cpl
)))
2418 (display-buffer buf
'not-this-window
)))
2420 (defun ps-nb-pages (nb-lines)
2421 "Display an approximate correspondence between a font size and the number
2422 of pages the number of lines would require to print
2423 using the current ps-print setup."
2424 (let ((buf (get-buffer-create "*Nb-Pages*"))
2425 (ifs ps-font-size
) ; initial font size
2426 (ilh ps-line-height
) ; initial line height
2427 (page-height (progn (ps-get-page-dimensions)
2429 (ps-setup (ps-setup)) ; setup for the current buffer
2430 (fs-min 4) ; minimum font size
2431 lh-min
; minimum line height
2432 nb-lpp-max
; maximum nb of lines per page
2433 nb-page-min
; minimum nb of pages
2434 (fs-max 14) ; maximum font size
2435 lh-max
; maximum line height
2436 nb-lpp-min
; minimum nb of lines per page
2437 nb-page-max
; maximum nb of pages
2438 fs
; current font size
2439 lh
; current line height
2440 nb-lpp
; current nb of lines per page
2441 nb-page
; current nb of pages
2443 (setq lh-min
(/ (* ilh fs-min
) ifs
)
2444 nb-lpp-max
(floor (/ page-height lh-min
))
2445 nb-page-min
(ceiling (/ (float nb-lines
) nb-lpp-max
))
2446 lh-max
(/ (* ilh fs-max
) ifs
)
2447 nb-lpp-min
(floor (/ page-height lh-max
))
2448 nb-page-max
(ceiling (/ (float nb-lines
) nb-lpp-min
)))
2449 (setq nb-page nb-page-min
)
2451 (goto-char (point-max))
2452 (if (not (bolp)) (insert "\n"))
2454 (insert (format "%d lines\n" nb-lines
))
2455 (insert "nb page / font size\n")
2456 (while (<= nb-page nb-page-max
)
2457 (setq nb-lpp
(ceiling (/ nb-lines
(float nb-page
)))
2458 lh
(/ page-height nb-lpp
)
2459 fs
(/ (* ifs lh
) ilh
))
2460 (insert (format "%s %s\n" nb-page fs
))
2461 (setq nb-page
(1+ nb-page
)))
2463 (display-buffer buf
'not-this-window
)))
2465 (defun ps-select-font ()
2466 "Choose the font name and size (scaling data)."
2467 (let ((assoc (assq ps-font-family ps-font-info-database
))
2468 l fn fb fi bi sz lh sw aw
)
2470 (error "Don't have data to scale font %s. Known fonts families are %s"
2472 (mapcar 'car ps-font-info-database
)))
2474 fn
(prog1 (car l
) (setq l
(cdr l
))) ; need `pop'
2475 fb
(prog1 (car l
) (setq l
(cdr l
)))
2476 fi
(prog1 (car l
) (setq l
(cdr l
)))
2477 bi
(prog1 (car l
) (setq l
(cdr l
)))
2478 sz
(prog1 (car l
) (setq l
(cdr l
)))
2479 lh
(prog1 (car l
) (setq l
(cdr l
)))
2480 sw
(prog1 (car l
) (setq l
(cdr l
)))
2481 aw
(prog1 (car l
) (setq l
(cdr l
))))
2484 (setq ps-font-bold fb
)
2485 (setq ps-font-italic fi
)
2486 (setq ps-font-bold-italic bi
)
2487 ;; These data just need to be rescaled:
2488 (setq ps-line-height
(/ (* lh ps-font-size
) sz
))
2489 (setq ps-space-width
(/ (* sw ps-font-size
) sz
))
2490 (setq ps-avg-char-width
(/ (* aw ps-font-size
) sz
))
2493 (defun ps-select-header-font ()
2494 "Choose the font name and size (scaling data) for the header."
2495 (let ((assoc (assq ps-header-font-family ps-font-info-database
))
2496 l fn fb fi bi sz lh sw aw
)
2498 (error "Don't have data to scale font %s. Known fonts families are %s"
2500 (mapcar 'car ps-font-info-database
)))
2502 fn
(prog1 (car l
) (setq l
(cdr l
))) ; need `pop'
2503 fb
(prog1 (car l
) (setq l
(cdr l
)))
2504 fi
(prog1 (car l
) (setq l
(cdr l
)))
2505 bi
(prog1 (car l
) (setq l
(cdr l
)))
2506 sz
(prog1 (car l
) (setq l
(cdr l
)))
2507 lh
(prog1 (car l
) (setq l
(cdr l
)))
2508 sw
(prog1 (car l
) (setq l
(cdr l
)))
2509 aw
(prog1 (car l
) (setq l
(cdr l
))))
2512 (setq ps-header-font fn
)
2513 (setq ps-header-title-font fb
)
2514 ;; Line height: These data just need to be rescaled:
2515 (setq ps-header-title-line-height
(/ (* lh ps-header-title-font-size
) sz
))
2516 (setq ps-header-line-height
(/ (* lh ps-header-font-size
) sz
))
2517 ps-header-font-family
))
2519 (defun ps-get-page-dimensions ()
2520 (let ((page-dimensions (cdr (assq ps-paper-type ps-page-dimensions-database
)))
2521 page-width page-height
)
2523 ((null page-dimensions
)
2524 (error "`ps-paper-type' must be one of:\n%s"
2525 (mapcar 'car ps-page-dimensions-database
)))
2526 ((< ps-number-of-columns
1)
2527 (error "The number of columns %d should not be negative" ps-number-of-columns
)))
2530 (ps-select-header-font)
2532 (setq page-width
(ps-page-dimensions-get-width page-dimensions
)
2533 page-height
(ps-page-dimensions-get-height page-dimensions
))
2536 (if ps-landscape-mode
2537 ;; exchange width and height
2538 (setq page-width
(prog1 page-height
(setq page-height page-width
))))
2540 ;; It is used to get the lower right corner (only in landscape mode)
2541 (setq ps-landscape-page-height page-height
)
2543 ;; | lm | text | ic | text | ic | text | rm |
2544 ;; page-width == lm + n * pw + (n - 1) * ic + rm
2545 ;; => pw == (page-width - lm -rm - (n - 1) * ic) / n
2546 (setq ps-print-width
2548 ps-left-margin ps-right-margin
2549 (* (1- ps-number-of-columns
) ps-inter-column
))
2550 ps-number-of-columns
))
2551 (if (<= ps-print-width
0)
2552 (error "Bad horizontal layout:
2554 ps-left-margin == %s
2555 ps-right-margin == %s
2556 ps-inter-column == %s
2557 ps-number-of-columns == %s
2558 | lm | text | ic | text | ic | text | rm |
2559 page-width == lm + n * print-width + (n - 1) * ic + rm
2560 => print-width == %d !"
2565 ps-number-of-columns
2568 (setq ps-print-height
2569 (- page-height ps-bottom-margin ps-top-margin
))
2570 (if (<= ps-print-height
0)
2571 (error "Bad vertical layout:
2573 ps-bottom-margin == %s
2574 page-height == bm + print-height + tm
2575 => print-height == %d !"
2579 ;; If headers are turned on, deduct the height of the header from
2580 ;; the print height.
2584 (* ps-header-line-pad ps-header-title-line-height
))
2585 (setq ps-print-height
2589 ps-header-title-line-height
2590 (* ps-header-line-height
(- ps-header-lines
1))
2592 (if (<= ps-print-height
0)
2593 (error "Bad vertical layout:
2595 ps-bottom-margin == %s
2596 ps-header-offset == %s
2599 page-height == bm + print-height + tm - ho - hh
2600 => print-height == %d !"
2606 ps-header-title-line-height
2607 (* ps-header-line-height
(- ps-header-lines
1))
2611 (defun ps-print-preprint (&optional filename
)
2613 (or (numberp filename
)
2615 (let* ((name (concat (buffer-name) ".ps"))
2616 (prompt (format "Save PostScript to file: (default %s) "
2618 (res (read-file-name prompt default-directory name nil
)))
2619 (if (file-directory-p res
)
2620 (expand-file-name name
(file-name-as-directory res
))
2623 ;; The following functions implement a simple list-buffering scheme so
2624 ;; that ps-print doesn't have to repeatedly switch between buffers
2625 ;; while spooling. The functions ps-output and ps-output-string build
2626 ;; up the lists; the function ps-flush-output takes the lists and
2627 ;; insert its contents into the spool buffer (*PostScript*).
2629 (defun ps-output-string-prim (string)
2630 (insert "(") ;insert start-string delimiter
2631 (save-excursion ;insert string
2634 ;; Find and quote special characters as necessary for PS
2635 (while (re-search-forward "[()\\]" nil t
)
2640 (goto-char (point-max))
2641 (insert ")")) ;insert end-string delimiter
2643 (defun ps-init-output-queue ()
2644 (setq ps-output-head
(list ""))
2645 (setq ps-output-tail ps-output-head
))
2647 (defun ps-output (&rest args
)
2648 (setcdr ps-output-tail args
)
2649 (while (cdr ps-output-tail
)
2650 (setq ps-output-tail
(cdr ps-output-tail
))))
2652 (defun ps-output-string (string)
2653 (ps-output t string
))
2655 (defun ps-output-list (the-list)
2656 (mapcar 'ps-output the-list
))
2658 (defun ps-flush-output ()
2660 (set-buffer ps-spool-buffer
)
2661 (goto-char (point-max))
2662 (while ps-output-head
2663 (let ((it (car ps-output-head
)))
2666 (setq ps-output-head
(cdr ps-output-head
))
2667 (ps-output-string-prim (car ps-output-head
))))
2668 (setq ps-output-head
(cdr ps-output-head
))))
2669 (ps-init-output-queue))
2671 (defun ps-insert-file (fname)
2673 ;; Check to see that the file exists and is readable; if not, throw
2675 (or (file-readable-p fname
)
2676 (error "Could not read file `%s'" fname
))
2678 (set-buffer ps-spool-buffer
)
2679 (goto-char (point-max))
2680 (insert-file fname
)))
2682 ;; These functions insert the arrays that define the contents of the
2685 (defun ps-generate-header-line (fonttag &optional content
)
2686 (ps-output " [ " fonttag
" ")
2688 ;; Literal strings should be output as is -- the string must
2689 ;; contain its own PS string delimiters, '(' and ')', if necessary.
2691 (ps-output content
))
2693 ;; Functions are called -- they should return strings; they will be
2694 ;; inserted as strings and the PS string delimiters added.
2695 ((and (symbolp content
) (fboundp content
))
2696 (ps-output-string (funcall content
)))
2698 ;; Variables will have their contents inserted. They should
2699 ;; contain strings, and will be inserted as strings.
2700 ((and (symbolp content
) (boundp content
))
2701 (ps-output-string (symbol-value content
)))
2703 ;; Anything else will get turned into an empty string.
2705 (ps-output-string "")))
2708 (defun ps-generate-header (name contents
)
2709 (ps-output "/" name
" [\n")
2710 (if (> ps-header-lines
0)
2712 (ps-generate-header-line "/h0" (car contents
))
2713 (while (and (< count ps-header-lines
)
2714 (setq contents
(cdr contents
)))
2715 (ps-generate-header-line "/h1" (car contents
))
2716 (setq count
(+ count
1)))
2717 (ps-output "] def\n"))))
2719 (defun ps-output-boolean (name bool
)
2720 (ps-output (format "/%s %s def\n" name
(if bool
"true" "false"))))
2723 (defun ps-background-pages (page-list func
)
2727 (let ((start (if (consp pages
) (car pages
) pages
))
2728 (end (if (consp pages
) (cdr pages
) pages
)))
2729 (and (integerp start
) (integerp end
) (<= start end
)
2730 (add-to-list 'ps-background-pages
(vector start end func
)))))
2732 (setq ps-background-all-pages
(cons func ps-background-all-pages
))))
2735 (defun ps-get-boundingbox ()
2737 (set-buffer ps-spool-buffer
)
2739 (if (re-search-forward
2740 "^%%BoundingBox:\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)"
2742 (vector (string-to-number ; lower x
2743 (buffer-substring (match-beginning 1) (match-end 1)))
2744 (string-to-number ; lower y
2745 (buffer-substring (match-beginning 2) (match-end 2)))
2746 (string-to-number ; upper x
2747 (buffer-substring (match-beginning 3) (match-end 3)))
2748 (string-to-number ; upper y
2749 (buffer-substring (match-beginning 4) (match-end 4))))
2750 (vector 0 0 0 0)))))
2753 ;; Emacs understands the %f format; we'll use it to limit color RGB values
2754 ;; to three decimals to cut down some on the size of the PostScript output.
2755 ;; Lucid emacsen will have to make do with %s (princ) for floats.
2757 (defvar ps-float-format
(if (eq ps-print-emacs-type
'emacs
)
2759 "%s ")) ; Lucid emacsen
2762 (defun ps-float-format (value &optional default
)
2763 (let ((literal (or value default
)))
2765 (format (if (numberp literal
)
2772 (defun ps-background-text ()
2775 (setq ps-background-text-count
(1+ ps-background-text-count
))
2776 (ps-output (format "/ShowBackText-%d {\n" ps-background-text-count
))
2777 (ps-output-string (nth 0 text
)) ; text
2780 (ps-float-format (nth 4 text
) 200.0) ; font size
2781 (format "/%s " (or (nth 3 text
) "Times-Roman")) ; font name
2782 (ps-float-format (nth 6 text
)
2783 "PrintHeight PrintPageWidth atan") ; rotation
2784 (ps-float-format (nth 5 text
) 0.85) ; gray
2785 (ps-float-format (nth 1 text
) "0") ; x position
2786 (ps-float-format (nth 2 text
) "BottomMargin") ; y position
2787 "\nShowBackText} def\n")
2788 (ps-background-pages (nthcdr 7 text
) ; page list
2789 (format "ShowBackText-%d\n"
2790 ps-background-text-count
)))
2791 ps-print-background-text
))
2794 (defun ps-background-image ()
2797 (let ((image-file (expand-file-name (nth 0 image
))))
2798 (if (file-readable-p image-file
)
2800 (setq ps-background-image-count
(1+ ps-background-image-count
))
2802 (format "/ShowBackImage-%d {\n--back-- " ps-background-image-count
)
2803 (ps-float-format (nth 5 image
) 0.0) ; rotation
2804 (ps-float-format (nth 3 image
) 1.0) ; x scale
2805 (ps-float-format (nth 4 image
) 1.0) ; y scale
2806 (ps-float-format (nth 1 image
) ; x position
2807 "PrintPageWidth 2 div")
2808 (ps-float-format (nth 2 image
) ; y position
2809 "PrintHeight 2 div BottomMargin add")
2810 "\nBeginBackImage\n")
2811 (ps-insert-file image-file
)
2812 ;; coordinate adjustment to centralize image
2813 ;; around x and y position
2814 (let ((box (ps-get-boundingbox)))
2816 (set-buffer ps-spool-buffer
)
2818 (if (re-search-backward "^--back--" nil t
)
2822 (- (+ (/ (- (aref box
2) (aref box
0)) 2.0)
2825 (- (+ (/ (- (aref box
3) (aref box
1)) 2.0)
2828 (ps-output "\nEndBackImage} def\n")
2829 (ps-background-pages (nthcdr 6 image
) ; page list
2830 (format "ShowBackImage-%d\n"
2831 ps-background-image-count
))))))
2832 ps-print-background-image
))
2835 (defun ps-background (page-number)
2836 (let (has-local-background)
2837 (mapcar '(lambda (range)
2838 (and (<= (aref range
0) page-number
)
2839 (<= page-number
(aref range
1))
2840 (if has-local-background
2841 (ps-output (aref range
2))
2842 (setq has-local-background t
)
2843 (ps-output "/printLocalBackground {\n"
2845 ps-background-pages
)
2846 (and has-local-background
(ps-output "} def\n"))))
2849 (defun ps-begin-file ()
2850 (ps-get-page-dimensions)
2851 (setq ps-showline-count
(if ps-printing-region
(car ps-printing-region
) 1)
2852 ps-background-text-count
0
2853 ps-background-image-count
0
2854 ps-background-pages nil
2855 ps-background-all-pages nil
)
2857 (ps-output ps-adobe-tag
)
2858 (ps-output "%%Title: " (buffer-name)) ;Take job name from name of
2859 ;first buffer printed
2860 (ps-output "\n%%Creator: " (user-full-name))
2861 (ps-output "\n%%CreationDate: "
2862 (time-stamp-hh:mm
:ss
) " " (time-stamp-mon-dd-yyyy)
2864 (if ps-landscape-mode
"Landscape" "Portrait"))
2865 (ps-output "\n%% DocumentFonts: Times-Roman Times-Italic "
2866 ps-font
" " ps-font-bold
" " ps-font-italic
" "
2867 ps-font-bold-italic
" "
2868 ps-header-font
" " ps-header-title-font
)
2869 (ps-output "\n%%Pages: (atend)\n")
2870 (ps-output "%%EndComments\n\n")
2872 (ps-output-boolean "LandscapeMode" ps-landscape-mode
)
2873 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns
))
2875 (ps-output (format "/LandscapePageHeight %s def\n" ps-landscape-page-height
))
2876 (ps-output (format "/PrintPageWidth %s def\n"
2877 (- (* (+ ps-print-width ps-inter-column
)
2878 ps-number-of-columns
)
2880 (ps-output (format "/PrintWidth %s def\n" ps-print-width
))
2881 (ps-output (format "/PrintHeight %s def\n" ps-print-height
))
2883 (ps-output (format "/LeftMargin %s def\n" ps-left-margin
))
2884 (ps-output (format "/RightMargin %s def\n" ps-right-margin
)) ; not used
2885 (ps-output (format "/InterColumn %s def\n" ps-inter-column
))
2887 (ps-output (format "/BottomMargin %s def\n" ps-bottom-margin
))
2888 (ps-output (format "/TopMargin %s def\n" ps-top-margin
)) ; not used
2889 (ps-output (format "/HeaderOffset %s def\n" ps-header-offset
))
2890 (ps-output (format "/HeaderPad %s def\n" ps-header-pad
))
2892 (ps-output-boolean "PrintHeader" ps-print-header
)
2893 (ps-output-boolean "PrintHeaderFrame" ps-print-header-frame
)
2894 (ps-output-boolean "ShowNofN" ps-show-n-of-n
)
2895 (ps-output-boolean "Duplex" ps-spool-duplex
)
2897 (ps-output (format "/LineHeight %s def\n" ps-line-height
)
2898 (format "/LinesPerColumn %d def\n"
2899 (round (/ (+ ps-print-height
2900 (* ps-line-height
0.45))
2903 (ps-output-boolean "Zebra" ps-zebra-stripes
)
2904 (ps-output (format "/NumberOfZebra %d def\n" ps-zebra-stripe-height
))
2906 (ps-output-boolean "PrintLineNumber" ps-line-number
)
2907 (ps-output (format "/Lines %d def\n"
2908 (if ps-printing-region
2909 (cdr ps-printing-region
)
2910 (ps-count-lines (point-min) (point-max)))))
2912 (ps-background-text)
2913 (ps-background-image)
2914 (setq ps-background-all-pages
(nreverse ps-background-all-pages
)
2915 ps-background-pages
(nreverse ps-background-pages
))
2917 (ps-output ps-print-prologue-1
)
2919 (ps-output "/printGlobalBackground {\n")
2920 (ps-output-list ps-background-all-pages
)
2921 (ps-output "} def\n/printLocalBackground {\n} def\n")
2924 (ps-output ; /h0 14 /Helvetica-Bold Font
2925 (format "/h0 %s /%s DefFont\n" ps-header-title-font-size ps-header-title-font
))
2926 (ps-output ; /h1 12 /Helvetica Font
2927 (format "/h1 %s /%s DefFont\n" ps-header-font-size ps-header-font
))
2929 (ps-output ps-print-prologue-2
)
2932 (ps-output (format "/f0 %s /%s DefFont\n" ps-font-size ps-font
))
2933 (ps-output (format "/f1 %s /%s DefFont\n" ps-font-size ps-font-bold
))
2934 (ps-output (format "/f2 %s /%s DefFont\n" ps-font-size ps-font-italic
))
2935 (ps-output (format "/f3 %s /%s DefFont\n" ps-font-size ps-font-bold-italic
))
2937 (ps-output "\nBeginDoc\n\n")
2938 (ps-output "%%EndPrologue\n"))
2940 (defun ps-header-dirpart ()
2941 (let ((fname (buffer-file-name)))
2943 (if (string-equal (buffer-name) (file-name-nondirectory fname
))
2944 (file-name-directory fname
)
2948 (defun ps-get-buffer-name ()
2950 ;; Indulge Jim this little easter egg:
2951 ((string= (buffer-name) "ps-print.el")
2952 "Hey, Cool! It's ps-print.el!!!")
2953 ;; Indulge Jack this other little easter egg:
2954 ((string= (buffer-name) "sokoban.el")
2955 "Super! C'est sokoban.el!")
2957 (and ps-printing-region
"Subset of: ")
2959 (and (buffer-modified-p) " (unsaved)")))))
2961 (defun ps-begin-job ()
2962 (setq ps-page-count
0))
2964 (defun ps-end-file ()
2965 (ps-output "\n%%Trailer\n")
2966 (ps-output (format "%%%%Pages: %d\n" (1+ (/ (1- ps-page-count
)
2967 ps-number-of-columns
))))
2968 (ps-output "\nEndDoc\n\n%%EOF\n"))
2971 (defun ps-next-page ()
2976 (defun ps-header-page (&optional inc-p
)
2977 (if (zerop (mod ps-page-count ps-number-of-columns
))
2978 ;; Print only when a new real page begins.
2979 (let ((page-number (1+ (/ ps-page-count ps-number-of-columns
))))
2980 (ps-output (format "\n%%%%Page: %d %d\n" page-number page-number
))
2981 (ps-output "BeginDSCPage\n")
2982 (ps-background page-number
)
2983 (and inc-p
(incf ps-page-count
)))
2984 ;; Print when any other page begins.
2985 (ps-output "BeginDSCPage\n")))
2987 (defun ps-begin-page (&optional dummypage
)
2988 (ps-get-page-dimensions)
2989 (setq ps-width-remaining ps-print-width
)
2990 (setq ps-height-remaining ps-print-height
)
2994 (ps-output (format "/LineNumber %d def\n" ps-showline-count
)
2995 (format "/PageNumber %d def\n" (incf ps-page-count
)))
2996 (ps-output "/PageCount 0 def\n")
2998 (when ps-print-header
2999 (ps-generate-header "HeaderLinesLeft" ps-left-header
)
3000 (ps-generate-header "HeaderLinesRight" ps-right-header
)
3001 (ps-output (format "%d SetHeaderLines\n" ps-header-lines
)))
3003 (ps-output "BeginPage\n")
3004 (ps-set-font ps-current-font
)
3005 (ps-set-bg ps-current-bg
)
3006 (ps-set-color ps-current-color
))
3008 (defun ps-end-page ()
3009 (ps-output "EndPage\nEndDSCPage\n"))
3011 (defun ps-dummy-page ()
3013 (ps-output "/PrintHeader false def
3018 (defun ps-next-line ()
3019 (setq ps-showline-count
(1+ ps-showline-count
))
3020 (if (< ps-height-remaining ps-line-height
)
3022 (setq ps-width-remaining ps-print-width
)
3023 (setq ps-height-remaining
(- ps-height-remaining ps-line-height
))
3026 (defun ps-continue-line ()
3027 (if (< ps-height-remaining ps-line-height
)
3029 (setq ps-width-remaining ps-print-width
)
3030 (setq ps-height-remaining
(- ps-height-remaining ps-line-height
))
3033 ;; [jack] Why hard and soft ?
3035 (defun ps-hard-lf ()
3038 (defun ps-soft-lf ()
3041 (defun ps-find-wrappoint (from to char-width
)
3042 (let ((avail (truncate (/ ps-width-remaining char-width
)))
3045 (cons to
(* todo char-width
))
3046 (cons (+ from avail
) ps-width-remaining
))))
3048 (defun ps-basic-plot-string (from to
&optional bg-color
)
3049 (let* ((wrappoint (ps-find-wrappoint from to ps-avg-char-width
))
3050 (to (car wrappoint
))
3051 (string (buffer-substring-no-properties from to
)))
3052 (ps-output-string string
)
3056 (defun ps-basic-plot-whitespace (from to
&optional bg-color
)
3057 (let* ((wrappoint (ps-find-wrappoint from to ps-space-width
))
3058 (to (car wrappoint
)))
3059 (ps-output (format "%d W\n" (- to from
)))
3062 (defun ps-plot (plotfunc from to
&optional bg-color
)
3064 (let* ((wrappoint (funcall plotfunc from to bg-color
))
3065 (plotted-to (car wrappoint
))
3066 (plotted-width (cdr wrappoint
)))
3067 (setq from plotted-to
)
3068 (setq ps-width-remaining
(- ps-width-remaining plotted-width
))
3070 (ps-continue-line))))
3071 (if ps-razzle-dazzle
3072 (let* ((q-todo (- (point-max) (point-min)))
3073 (q-done (- (point) (point-min)))
3074 (chunkfrac (/ q-todo
8))
3075 (chunksize (if (> chunkfrac
1000) 1000 chunkfrac
)))
3076 (if (> (- q-done ps-razchunk
) chunksize
)
3078 (setq ps-razchunk q-done
)
3081 (/ (* 100 q-done
) q-todo
)
3082 (/ q-done
(/ q-todo
100))))
3083 (message "Formatting...%3d%%" foo
))))))
3085 (defun ps-set-font (font)
3086 (setq ps-current-font font
)
3087 (ps-output (format "/f%d F\n" ps-current-font
)))
3089 (defun ps-set-bg (color)
3090 (if (setq ps-current-bg color
)
3091 (ps-output (format ps-color-format
(nth 0 color
) (nth 1 color
)
3094 (ps-output "false BG\n")))
3096 (defun ps-set-color (color)
3097 (setq ps-current-color
(or color ps-default-fg
))
3098 (ps-output (format ps-color-format
(nth 0 ps-current-color
)
3099 (nth 1 ps-current-color
) (nth 2 ps-current-color
))
3103 (defvar ps-current-effect
0)
3106 (defun ps-plot-region (from to font
&optional fg-color bg-color effects
)
3107 (if (not (equal font ps-current-font
))
3110 ;; Specify a foreground color only if one's specified and it's
3111 ;; different than the current.
3112 (if (not (equal fg-color ps-current-color
))
3113 (ps-set-color fg-color
))
3115 (if (not (equal bg-color ps-current-bg
))
3116 (ps-set-bg bg-color
))
3118 ;; Specify effects (underline, overline, box, etc)
3120 ((not (integerp effects
))
3121 (ps-output "0 EF\n")
3122 (setq ps-current-effect
0))
3123 ((/= effects ps-current-effect
)
3124 (ps-output (number-to-string effects
) " EF\n")
3125 (setq ps-current-effect effects
)))
3127 ;; Starting at the beginning of the specified region...
3131 ;; ...break the region up into chunks separated by tabs, linefeeds,
3132 ;; pagefeeds, control characters, and plot each chunk.
3134 (if (re-search-forward "[\000-\037\177-\377]" to t
)
3135 ;; region with some control characters
3136 (let ((match (char-after (match-beginning 0))))
3137 (if (= match ?
\t) ; tab
3139 (save-excursion (beginning-of-line) (point))))
3140 (ps-plot 'ps-basic-plot-string from
(- (point) 1)
3143 (setq from
(+ linestart
(current-column)))
3144 (if (re-search-forward "[ \t]+" to t
)
3145 (ps-plot 'ps-basic-plot-whitespace
3146 from
(+ linestart
(current-column))
3148 ;; any other control character except tab
3149 (ps-plot 'ps-basic-plot-string from
(- (point) 1) bg-color
)
3151 ((= match ?
\n) ; newline
3154 ((= match ?
\f) ; form feed
3157 ((<= match ?
\037) ; characters from ^@ to ^_
3158 (ps-control-character (format "^%c" (+ match ?
@))))
3160 ((= match ?
\177) ; del (127) is printed ^?
3161 (ps-control-character "^?"))
3163 (t ; characters from 128 to 255
3164 (ps-control-character (format "\\%o" match
)))))
3165 (setq from
(point)))
3166 ;; region without control characters
3167 (ps-plot 'ps-basic-plot-string from to bg-color
)
3170 (defun ps-control-character (str)
3171 (let* ((from (1- (point)))
3174 (wrappoint (ps-find-wrappoint from to ps-avg-char-width
)))
3175 (if (< (car wrappoint
) to
)
3177 (setq ps-width-remaining
(- ps-width-remaining
(* len ps-avg-char-width
)))
3178 (ps-output-string str
)
3179 (ps-output " S\n")))
3181 (defun ps-color-value (x-color-value)
3182 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval.
3183 (/ x-color-value ps-print-color-scale
))
3185 (defun ps-color-values (x-color)
3186 (cond ((fboundp 'x-color-values
)
3187 (x-color-values x-color
))
3188 ((fboundp 'pixel-components
)
3189 (pixel-components x-color
))
3190 (t (error "No available function to determine X color values."))))
3193 (defun ps-face-attributes (face)
3194 "Return face attribute vector.
3196 If FACE is not in `ps-print-face-extension-alist' or in
3197 `ps-print-face-alist', insert it on `ps-print-face-alist' and
3198 return the attribute vector.
3200 If FACE is not a valid face name, it is used default face."
3201 (cdr (or (assq face ps-print-face-extension-alist
)
3202 (assq face ps-print-face-alist
)
3203 (let* ((the-face (if (facep face
) face
'default
))
3204 (new-face (ps-screen-to-bit-face the-face
)))
3205 (or (and (eq the-face
'default
)
3206 (assq the-face ps-print-face-alist
))
3207 (setq ps-print-face-alist
(cons new-face ps-print-face-alist
)))
3211 (defun ps-face-attribute-list (face-or-list)
3212 (if (listp face-or-list
)
3214 (let ((effects 0) foreground background face-attr face
)
3216 (setq face
(car face-or-list
)
3217 face-attr
(ps-face-attributes face
)
3218 effects
(logior effects
(aref face-attr
0)))
3219 (or foreground
(setq foreground
(aref face-attr
1)))
3220 (or background
(setq background
(aref face-attr
2)))
3221 (setq face-or-list
(cdr face-or-list
)))
3222 (vector effects foreground background
))
3224 (ps-face-attributes face-or-list
)))
3227 (defun ps-plot-with-face (from to face
)
3229 (let* ((face-bit (ps-face-attribute-list face
))
3230 (effect (aref face-bit
0))
3231 (foreground (aref face-bit
1))
3232 (background (aref face-bit
2))
3233 (fg-color (if (and ps-print-color-p foreground
)
3234 (mapcar 'ps-color-value
3235 (ps-color-values foreground
))
3237 (bg-color (if (and ps-print-color-p background
)
3238 (mapcar 'ps-color-value
3239 (ps-color-values background
)))))
3240 (ps-plot-region from to
(logand effect
3)
3241 fg-color bg-color
(lsh effect -
2)))
3242 (ps-plot-region from to
0))
3246 (defun ps-xemacs-face-kind-p (face kind kind-regex kind-list
)
3247 (let* ((frame-font (or (face-font face
) (face-font 'default
)))
3248 (kind-cons (assq kind
(x-font-properties frame-font
)))
3249 (kind-spec (cdr-safe kind-cons
))
3250 (case-fold-search t
))
3252 (or (and kind-spec
(string-match kind-regex kind-spec
))
3253 ;; Kludge-compatible:
3254 (memq face kind-list
))))
3256 (defun ps-face-bold-p (face)
3257 (if (eq ps-print-emacs-type
'emacs
)
3258 (or (face-bold-p face
)
3259 (memq face ps-bold-faces
))
3260 (ps-xemacs-face-kind-p face
'WEIGHT_NAME
"bold\\|demibold"
3263 (defun ps-face-italic-p (face)
3264 (if (eq ps-print-emacs-type
'emacs
)
3265 (or (face-italic-p face
)
3266 (memq face ps-italic-faces
))
3268 (ps-xemacs-face-kind-p face
'ANGLE_NAME
"i\\|o" ps-italic-faces
)
3269 (ps-xemacs-face-kind-p face
'SLANT
"i\\|o" ps-italic-faces
))))
3271 (defun ps-face-underlined-p (face)
3272 (or (face-underline-p face
)
3273 (memq face ps-underlined-faces
)))
3276 ;; Ensure that face-list is fbound.
3277 (or (fboundp 'face-list
) (defalias 'face-list
'list-faces
))
3280 (defun ps-build-reference-face-lists ()
3281 (setq ps-print-face-alist nil
)
3282 (if ps-auto-font-detect
3283 (mapcar 'ps-map-face
(face-list))
3284 (mapcar 'ps-set-face-bold ps-bold-faces
)
3285 (mapcar 'ps-set-face-italic ps-italic-faces
)
3286 (mapcar 'ps-set-face-underline ps-underlined-faces
))
3287 (setq ps-build-face-reference nil
))
3290 (defun ps-set-face-bold (face)
3291 (ps-set-face-attribute face
1))
3293 (defun ps-set-face-italic (face)
3294 (ps-set-face-attribute face
2))
3296 (defun ps-set-face-underline (face)
3297 (ps-set-face-attribute face
4))
3300 (defun ps-set-face-attribute (face effect
)
3301 (let ((face-bit (cdr (ps-map-face face
))))
3302 (aset face-bit
0 (logior (aref face-bit
0) effect
))))
3305 (defun ps-map-face (face)
3306 (let* ((face-map (ps-screen-to-bit-face face
))
3307 (ps-face-bit (cdr (assq (car face-map
) ps-print-face-alist
))))
3309 ;; if face exists, merge both
3310 (let ((face-bit (cdr face-map
)))
3311 (aset ps-face-bit
0 (logior (aref ps-face-bit
0) (aref face-bit
0)))
3312 (or (aref ps-face-bit
1) (aset ps-face-bit
1 (aref face-bit
1)))
3313 (or (aref ps-face-bit
2) (aset ps-face-bit
2 (aref face-bit
2))))
3314 ;; if face does not exist, insert it
3315 (setq ps-print-face-alist
(cons face-map ps-print-face-alist
)))
3319 (defun ps-screen-to-bit-face (face)
3321 (vector (logior (if (ps-face-bold-p face
) 1 0) ; bold
3322 (if (ps-face-italic-p face
) 2 0) ; italic
3323 (if (ps-face-underlined-p face
) 4 0)) ; underline
3324 (face-foreground face
)
3325 (face-background face
))))
3328 (defun ps-mapper (extent list
)
3329 (nconc list
(list (list (extent-start-position extent
) 'push extent
)
3330 (list (extent-end-position extent
) 'pull extent
)))
3333 (defun ps-extent-sorter (a b
)
3334 (< (extent-priority a
) (extent-priority b
)))
3336 (defun ps-print-ensure-fontified (start end
)
3337 (if (and (boundp 'lazy-lock-mode
) lazy-lock-mode
)
3338 (if (fboundp 'lazy-lock-fontify-region
)
3339 (lazy-lock-fontify-region start end
) ; the new
3340 (lazy-lock-fontify-buffer)))) ; the old
3342 (defun ps-generate-postscript-with-faces (from to
)
3343 ;; Some initialization...
3344 (setq ps-current-effect
0)
3346 ;; Build the reference lists of faces if necessary.
3347 (if (or ps-always-build-face-reference
3348 ps-build-face-reference
)
3350 (message "Collecting face information...")
3351 (ps-build-reference-face-lists)))
3352 ;; Set the color scale. We do it here instead of in the defvar so
3353 ;; that ps-print can be dumped into emacs. This expression can't be
3354 ;; evaluated at dump-time because X isn't initialized.
3355 (setq ps-print-color-scale
3356 (if ps-print-color-p
3357 (float (car (ps-color-values "white")))
3359 ;; Generate some PostScript.
3361 (narrow-to-region from to
)
3362 (let ((face 'default
)
3364 (ps-print-ensure-fontified from to
)
3366 ((or (eq ps-print-emacs-type
'lucid
)
3367 (eq ps-print-emacs-type
'xemacs
))
3368 ;; Build the list of extents...
3369 (let ((a (cons 'dummy nil
))
3370 record type extent extent-list
)
3371 (map-extents 'ps-mapper nil from to a
)
3372 (setq a
(sort (cdr a
) 'car-less-than-car
))
3374 (setq extent-list nil
)
3376 ;; Loop through the extents...
3378 (setq record
(car a
))
3380 (setq position
(car record
))
3381 (setq record
(cdr record
))
3383 (setq type
(car record
))
3384 (setq record
(cdr record
))
3386 (setq extent
(car record
))
3388 ;; Plot up to this record.
3389 ;; XEmacs 19.12: for some reason, we're getting into a
3390 ;; situation in which some of the records have
3391 ;; positions less than 'from'. Since we've narrowed
3392 ;; the buffer, this'll generate errors. This is a
3393 ;; hack, but don't call ps-plot-with-face unless from >
3395 (if (and (>= from
(point-min))
3396 (<= position
(point-max)))
3397 (ps-plot-with-face from position face
))
3401 (if (extent-face extent
)
3402 (setq extent-list
(sort (cons extent extent-list
)
3403 'ps-extent-sorter
))))
3406 (setq extent-list
(sort (delq extent extent-list
)
3407 'ps-extent-sorter
))))
3411 (extent-face (car extent-list
))
3414 (setq from position
)
3417 ((eq ps-print-emacs-type
'emacs
)
3418 (let ((property-change from
)
3419 (overlay-change from
))
3421 (if (< property-change to
) ; Don't search for property change
3422 ; unless previous search succeeded.
3423 (setq property-change
3424 (next-property-change from nil to
)))
3425 (if (< overlay-change to
) ; Don't search for overlay change
3426 ; unless previous search succeeded.
3427 (setq overlay-change
3428 (min (next-overlay-change from
) to
)))
3430 (min property-change overlay-change
))
3431 ;; The code below is not quite correct,
3432 ;; because a non-nil overlay invisible property
3433 ;; which is inactive according to the current value
3434 ;; of buffer-invisibility-spec nonetheless overrides
3435 ;; a face text property.
3437 (cond ((let ((prop (get-text-property from
'invisible
)))
3438 ;; Decide whether this invisible property
3439 ;; really makes the text invisible.
3440 (if (eq buffer-invisibility-spec t
)
3442 (or (memq prop buffer-invisibility-spec
)
3443 (assq prop buffer-invisibility-spec
))))
3445 ((get-text-property from
'face
))
3447 (let ((overlays (overlays-at from
))
3448 (face-priority -
1)) ; text-property
3450 (let* ((overlay (car overlays
))
3451 (overlay-face (overlay-get overlay
'face
))
3452 (overlay-invisible (overlay-get overlay
'invisible
))
3453 (overlay-priority (or (overlay-get overlay
3456 (if (and (or overlay-invisible overlay-face
)
3457 (> overlay-priority face-priority
))
3458 (setq face
(cond ((if (eq buffer-invisibility-spec t
)
3459 (not (null overlay-invisible
))
3460 (or (memq overlay-invisible
3461 buffer-invisibility-spec
)
3462 (assq overlay-invisible
3463 buffer-invisibility-spec
)))
3465 ((and face overlay-face
)))
3466 face-priority overlay-priority
)))
3467 (setq overlays
(cdr overlays
))))
3468 ;; Plot up to this record.
3469 (ps-plot-with-face from position face
)
3470 (setq from position
)))))
3471 (ps-plot-with-face from to face
))))
3473 (defun ps-generate-postscript (from to
)
3474 (ps-plot-region from to
0 nil
))
3476 (defun ps-generate (buffer from to genfunc
)
3478 (let ((from (min to from
))
3480 ;; This avoids trouble if chars with read-only properties
3481 ;; are copied into ps-spool-buffer.
3482 (inhibit-read-only t
))
3484 (narrow-to-region from to
)
3485 (if ps-razzle-dazzle
3486 (message "Formatting...%3d%%" (setq ps-razchunk
0)))
3488 (setq ps-source-buffer buffer
)
3489 (setq ps-spool-buffer
(get-buffer-create ps-spool-buffer-name
))
3490 (ps-init-output-queue)
3491 (let (safe-marker completed-safely needs-begin-file
)
3494 (set-buffer ps-spool-buffer
)
3496 ;; Get a marker and make it point to the current end of the
3497 ;; buffer, If an error occurs, we'll delete everything from
3498 ;; the end of this marker onwards.
3499 (setq safe-marker
(make-marker))
3500 (set-marker safe-marker
(point-max))
3502 (goto-char (point-min))
3503 (if (looking-at (regexp-quote ps-adobe-tag
))
3505 (setq needs-begin-file t
))
3507 (set-buffer ps-source-buffer
)
3508 (if needs-begin-file
(ps-begin-file))
3511 (set-buffer ps-source-buffer
)
3512 (funcall genfunc from to
)
3515 (if (and ps-spool-duplex
3516 (= (mod ps-page-count
2) 1))
3520 ;; Back to the PS output buffer to set the page count
3521 (set-buffer ps-spool-buffer
)
3522 (goto-char (point-max))
3523 (while (re-search-backward "^/PageCount 0 def$" nil t
)
3524 (replace-match (format "/PageCount %d def" ps-page-count
) t
))
3526 ;; Setting this variable tells the unwind form that the
3527 ;; the postscript was generated without error.
3528 (setq completed-safely t
))
3530 ;; Unwind form: If some bad mojo occurred while generating
3531 ;; postscript, delete all the postscript that was generated.
3532 ;; This protects the previously spooled files from getting
3534 (if (and (markerp safe-marker
) (not completed-safely
))
3536 (set-buffer ps-spool-buffer
)
3537 (delete-region (marker-position safe-marker
) (point-max))))))
3539 (if ps-razzle-dazzle
3540 (message "Formatting...done"))))))
3542 (defun ps-do-despool (filename)
3543 (if (or (not (boundp 'ps-spool-buffer
))
3544 (not (symbol-value 'ps-spool-buffer
)))
3545 (message "No spooled PostScript to print")
3550 (if ps-razzle-dazzle
3551 (message "Saving..."))
3552 (set-buffer ps-spool-buffer
)
3553 (setq filename
(expand-file-name filename
))
3554 (write-region (point-min) (point-max) filename
)
3555 (if ps-razzle-dazzle
3556 (message "Wrote %s" filename
)))
3557 ;; Else, spool to the printer
3558 (if ps-razzle-dazzle
3559 (message "Printing..."))
3561 (set-buffer ps-spool-buffer
)
3562 (if (and (eq system-type
'ms-dos
)
3563 (stringp (symbol-value 'dos-ps-printer
)))
3564 (write-region (point-min) (point-max)
3565 (symbol-value 'dos-ps-printer
) t
0)
3566 (let ((binary-process-input t
)) ; for MS-DOS
3567 (apply 'call-process-region
3568 (point-min) (point-max) ps-lpr-command nil
3569 (if (fboundp 'start-process
) 0 nil
)
3572 (if ps-razzle-dazzle
3573 (message "Printing...done")))
3574 (kill-buffer ps-spool-buffer
)))
3576 (defun ps-kill-emacs-check ()
3578 (if (and (setq ps-buffer
(get-buffer ps-spool-buffer-name
))
3579 (buffer-modified-p ps-buffer
))
3580 (if (y-or-n-p "Unprinted PostScript waiting; print now? ")
3582 (if (and (setq ps-buffer
(get-buffer ps-spool-buffer-name
))
3583 (buffer-modified-p ps-buffer
))
3584 (if (yes-or-no-p "Unprinted PostScript waiting; exit anyway? ")
3586 (error "Unprinted PostScript")))))
3588 (if (fboundp 'add-hook
)
3589 (funcall 'add-hook
'kill-emacs-hook
'ps-kill-emacs-check
)
3591 (message "Won't override existing kill-emacs-hook")
3592 (setq kill-emacs-hook
'ps-kill-emacs-check
)))
3594 ;;; Sample Setup Code:
3596 ;; This stuff is for anybody that's brave enough to look this far,
3597 ;; and able to figure out how to use it. It isn't really part of
3598 ;; ps-print, but I'll leave it here in hopes it might be useful:
3600 ;; WARNING!!! The following code is *sample* code only. Don't use it
3601 ;; unless you understand what it does!
3603 (defmacro ps-prsc
()
3604 `(if (eq ps-print-emacs-type
'emacs
) [f22] 'f22))
3605 (defmacro ps-c-prsc ()
3606 `(if (eq ps-print-emacs-type 'emacs) [C-f22] '(control f22)))
3607 (defmacro ps-s-prsc ()
3608 `(if (eq ps-print-emacs-type 'emacs) [S-f22] '(shift f22)))
3610 ;; A hook to bind to `rmail-mode-hook' to locally bind prsc and set the
3611 ;; `ps-left-headers' specially for mail messages.
3612 (defun ps-rmail-mode-hook ()
3613 (local-set-key (ps-prsc) 'ps-rmail-print-message-from-summary)
3614 (setq ps-header-lines 3
3616 ;; The left headers will display the message's subject, its
3617 ;; author, and the name of the folder it was in.
3618 '(ps-article-subject ps-article-author buffer-name)))
3620 ;; See `ps-gnus-print-article-from-summary'. This function does the
3621 ;; same thing for rmail.
3622 (defun ps-rmail-print-message-from-summary ()
3624 (ps-print-message-from-summary 'rmail-summary-buffer "RMAIL"))
3626 ;; Used in `ps-rmail-print-article-from-summary',
3627 ;; `ps-gnus-print-article-from-summary' and `ps-vm-print-message-from-summary'.
3628 (defun ps-print-message-from-summary (summary-buffer summary-default)
3629 (let ((ps-buf (or (and (boundp summary-buffer)
3630 (symbol-value summary-buffer))
3632 (and (get-buffer ps-buf)
3635 (ps-spool-buffer-with-faces)))))
3637 ;; Look in an article or mail message for the Subject: line. To be
3638 ;; placed in `ps-left-headers'.
3639 (defun ps-article-subject ()
3641 (goto-char (point-min))
3642 (if (re-search-forward "^Subject:[ \t]+\\(.*\\)$" nil t)
3643 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
3646 ;; Look in an article or mail message for the From: line. Sorta-kinda
3647 ;; understands RFC-822 addresses and can pull the real name out where
3648 ;; it's provided. To be placed in `ps-left-headers'.
3649 (defun ps-article-author ()
3651 (goto-char (point-min))
3652 (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
3653 (let ((fromstring (buffer-substring-no-properties (match-beginning 1)
3657 ;; Try first to match addresses that look like
3658 ;; thompson@wg2.waii.com (Jim Thompson)
3659 ((string-match ".*[ \t]+(\\(.*\\))" fromstring)
3660 (substring fromstring (match-beginning 1) (match-end 1)))
3662 ;; Next try to match addresses that look like
3663 ;; Jim Thompson <thompson@wg2.waii.com>
3664 ((string-match "\\(.*\\)[ \t]+<.*>" fromstring)
3665 (substring fromstring (match-beginning 1) (match-end 1)))
3667 ;; Couldn't find a real name -- show the address instead.
3671 ;; A hook to bind to `gnus-article-prepare-hook'. This will set the
3672 ;; `ps-left-headers' specially for gnus articles. Unfortunately,
3673 ;; `gnus-article-mode-hook' is called only once, the first time the *Article*
3674 ;; buffer enters that mode, so it would only work for the first time
3675 ;; we ran gnus. The second time, this hook wouldn't get set up. The
3676 ;; only alternative is `gnus-article-prepare-hook'.
3677 (defun ps-gnus-article-prepare-hook ()
3678 (setq ps-header-lines 3)
3679 (setq ps-left-header
3680 ;; The left headers will display the article's subject, its
3681 ;; author, and the newsgroup it was in.
3682 (list 'ps-article-subject 'ps-article-author 'gnus-newsgroup-name)))
3684 ;; A hook to bind to `vm-mode-hook' to locally bind prsc and set the
3685 ;; `ps-left-headers' specially for mail messages.
3686 (defun ps-vm-mode-hook ()
3687 (local-set-key (ps-prsc) 'ps-vm-print-message-from-summary)
3688 (setq ps-header-lines 3)
3689 (setq ps-left-header
3690 ;; The left headers will display the message's subject, its
3691 ;; author, and the name of the folder it was in.
3692 (list 'ps-article-subject 'ps-article-author 'buffer-name)))
3694 ;; Every now and then I forget to switch from the *Summary* buffer to
3695 ;; the *Article* before hitting prsc, and a nicely formatted list of
3696 ;; article subjects shows up at the printer. This function, bound to
3697 ;; prsc for the gnus *Summary* buffer means I don't have to switch
3699 ;; sb: Updated for Gnus 5.
3700 (defun ps-gnus-print-article-from-summary ()
3702 (ps-print-message-from-summary 'gnus-article-buffer "*Article*"))
3704 ;; See `ps-gnus-print-article-from-summary'. This function does the
3705 ;; same thing for vm.
3706 (defun ps-vm-print-message-from-summary ()
3708 (ps-print-message-from-summary 'vm-mail-buffer ""))
3710 ;; A hook to bind to bind to `gnus-summary-setup-buffer' to locally bind
3712 (defun ps-gnus-summary-setup ()
3713 (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary))
3715 ;; Look in an article or mail message for the Subject: line. To be
3716 ;; placed in `ps-left-headers'.
3717 (defun ps-info-file ()
3719 (goto-char (point-min))
3720 (if (re-search-forward "File:[ \t]+\\([^, \t\n]*\\)" nil t)
3721 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
3724 ;; Look in an article or mail message for the Subject: line. To be
3725 ;; placed in `ps-left-headers'.
3726 (defun ps-info-node ()
3728 (goto-char (point-min))
3729 (if (re-search-forward "Node:[ \t]+\\([^,\t\n]*\\)" nil t)
3730 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
3733 (defun ps-info-mode-hook ()
3734 (setq ps-left-header
3735 ;; The left headers will display the node name and file name.
3736 (list 'ps-info-node 'ps-info-file)))
3738 ;; WARNING! The following function is a *sample* only, and is *not*
3739 ;; meant to be used as a whole unless you understand what the effects
3740 ;; will be! (In fact, this is a copy of Jim's setup for ps-print --
3741 ;; I'd be very surprised if it was useful to *anybody*, without
3744 (defun ps-jts-ps-setup ()
3745 (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc
3746 (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces)
3747 (global-set-key (ps-c-prsc) 'ps-despool)
3748 (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook)
3749 (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup)
3750 (add-hook 'vm-mode-hook 'ps-vm-mode-hook)
3751 (add-hook 'vm-mode-hooks 'ps-vm-mode-hook)
3752 (add-hook 'Info-mode-hook 'ps-info-mode-hook)
3753 (setq ps-spool-duplex t)
3754 (setq ps-print-color-p nil)
3755 (setq ps-lpr-command "lpr")
3756 (setq ps-lpr-switches '("-Jjct,duplex_long"))
3759 ;; WARNING! The following function is a *sample* only, and is *not*
3760 ;; meant to be used as a whole unless it corresponds to your needs.
3761 ;; (In fact, this is a copy of Jack's setup for ps-print --
3762 ;; I would not be that surprised if it was useful to *anybody*,
3763 ;; without modification.)
3765 (defun ps-jack-setup ()
3766 (setq ps-print-color-p nil
3767 ps-lpr-command "lpr"
3768 ps-lpr-switches (list)
3772 ps-number-of-columns 2
3774 ps-left-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
3775 ps-right-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
3776 ps-inter-column (/ (* 72 1.0) 2.54) ; 1.0 cm
3777 ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
3778 ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
3779 ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
3780 ps-header-line-pad .15
3782 ps-print-header-frame t
3787 ps-font-family 'Courier
3789 ps-header-font-family 'Helvetica
3790 ps-header-font-size 6
3791 ps-header-title-font-size 8)
3796 ;;; ps-print.el ends here