1 ;;; ps-print.el --- Print text from the buffer as PostScript
3 ;; Copyright (C) 1993-2000 Free Software Foundation, Inc.
5 ;; Author: Jim Thompson (was <thompson@wg2.waii.com>)
6 ;; Author: Jacques Duthen (was <duthen@cegelec-red.fr>)
7 ;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br>
8 ;; Author: Kenichi Handa <handa@etl.go.jp> (multi-byte characters)
9 ;; Maintainer: Kenichi Handa <handa@etl.go.jp> (multi-byte characters)
10 ;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br>
11 ;; Keywords: wp, print, PostScript
12 ;; Time-stamp: <2000/04/24 12:23:14 vinicius>
15 (defconst ps-print-version "5.2"
16 "ps-print.el, v 5.2 <2000/04/24 vinicius>
18 Vinicius's last change version -- this file may have been edited as part of
19 Emacs without changes to the version number. When reporting bugs, please also
20 report the version of Emacs, if any, that ps-print was distributed with.
22 Please send all bug fixes and enhancements to
23 Vinicius Jose Latorre <vinicius@cpqd.com.br>.
26 ;; This file is part of GNU Emacs.
28 ;; GNU Emacs is free software; you can redistribute it and/or modify
29 ;; it under the terms of the GNU General Public License as published by
30 ;; the Free Software Foundation; either version 2, or (at your option)
33 ;; GNU Emacs is distributed in the hope that it will be useful,
34 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
35 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 ;; GNU General Public License for more details.
38 ;; You should have received a copy of the GNU General Public License
39 ;; along with GNU Emacs; see the file COPYING. If not, write to the
40 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
41 ;; Boston, MA 02111-1307, USA.
45 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50 ;; This package provides printing of Emacs buffers on PostScript printers;
51 ;; the buffer's bold and italic text attributes are preserved in the printer
52 ;; output. ps-print is intended for use with Emacs or Lucid Emacs, together
53 ;; with a fontifying package such as font-lock or hilit.
55 ;; ps-print uses the same face attributes defined through font-lock or hilit
56 ;; to print a PostScript file, but some faces are better seeing on the screen
57 ;; than on paper, specially when you have a black/white PostScript printer.
59 ;; ps-print allows a remap of face to another one that it is better to print,
60 ;; for example, the face font-lock-comment-face (if you are using font-lock)
61 ;; could have bold or italic attribute when printing, besides foreground color.
62 ;; This remap improves printing look (see How Ps-Print Maps Faces).
68 ;; ps-print provides eight commands for generating PostScript images
72 ;; ps-print-buffer-with-faces
74 ;; ps-print-region-with-faces
76 ;; ps-spool-buffer-with-faces
78 ;; ps-spool-region-with-faces
80 ;; These commands all perform essentially the same function: they
81 ;; generate PostScript images suitable for printing on a PostScript
82 ;; printer or displaying with GhostScript. These commands are
83 ;; collectively referred to as "ps-print- commands".
85 ;; The word "print" or "spool" in the command name determines when the
86 ;; PostScript image is sent to the printer:
88 ;; print - The PostScript image is immediately sent to the
91 ;; spool - The PostScript image is saved temporarily in an
92 ;; Emacs buffer. Many images may be spooled locally
93 ;; before printing them. To send the spooled images
94 ;; to the printer, use the command `ps-despool'.
96 ;; The spooling mechanism was designed for printing lots of small
97 ;; files (mail messages or netnews articles) to save paper that would
98 ;; otherwise be wasted on banner pages, and to make it easier to find
99 ;; your output at the printer (it's easier to pick up one 50-page
100 ;; printout than to find 50 single-page printouts).
102 ;; ps-print has a hook in the `kill-emacs-hook' so that you won't
103 ;; accidentally quit from Emacs while you have unprinted PostScript
104 ;; waiting in the spool buffer. If you do attempt to exit with
105 ;; spooled PostScript, you'll be asked if you want to print it, and if
106 ;; you decline, you'll be asked to confirm the exit; this is modeled
107 ;; on the confirmation that Emacs uses for modified buffers.
109 ;; The word "buffer" or "region" in the command name determines how
110 ;; much of the buffer is printed:
112 ;; buffer - Print the entire buffer.
114 ;; region - Print just the current region.
116 ;; The -with-faces suffix on the command name means that the command
117 ;; will include font, color, and underline information in the
118 ;; PostScript image, so the printed image can look as pretty as the
119 ;; buffer. The ps-print- commands without the -with-faces suffix
120 ;; don't include font, color, or underline information; images printed
121 ;; with these commands aren't as pretty, but are faster to generate.
123 ;; Two ps-print- command examples:
125 ;; ps-print-buffer - print the entire buffer,
126 ;; without font, color, or
127 ;; underline information, and
128 ;; send it immediately to the
131 ;; ps-spool-region-with-faces - print just the current region;
132 ;; include font, color, and
133 ;; underline information, and
134 ;; spool the image in Emacs to
135 ;; send to the printer later.
141 ;; To print your buffer, type
143 ;; M-x ps-print-buffer
145 ;; or substitute one of the other seven ps-print- commands. The
146 ;; command will generate the PostScript image and print or spool it as
147 ;; specified. By giving the command a prefix argument
149 ;; C-u M-x ps-print-buffer
151 ;; it will save the PostScript image to a file instead of sending it
152 ;; to the printer; you will be prompted for the name of the file to
153 ;; save the image to. The prefix argument is ignored by the commands
154 ;; that spool their images, but you may save the spooled images to a
155 ;; file by giving a prefix argument to `ps-despool':
157 ;; C-u M-x ps-despool
159 ;; When invoked this way, `ps-despool' will prompt you for the name of
160 ;; the file to save to.
162 ;; Any of the `ps-print-' commands can be bound to keys; I recommend
163 ;; binding `ps-spool-buffer-with-faces', `ps-spool-region-with-faces',
164 ;; and `ps-despool'. Here are the bindings I use on my Sun 4 keyboard:
166 ;; (global-set-key 'f22 'ps-spool-buffer-with-faces) ;f22 is prsc
167 ;; (global-set-key '(shift f22) 'ps-spool-region-with-faces)
168 ;; (global-set-key '(control f22) 'ps-despool)
171 ;; The Printer Interface
172 ;; ---------------------
174 ;; The variables `ps-lpr-command' and `ps-lpr-switches' determine what
175 ;; command is used to send the PostScript images to the printer, and
176 ;; what arguments to give the command. These are analogous to
177 ;; `lpr-command' and `lpr-switches'.
179 ;; Make sure that they contain appropriate values for your system;
180 ;; see the usage notes below and the documentation of these variables.
182 ;; The variable `ps-printer-name' determines the name of a local printer for
183 ;; printing PostScript files.
185 ;; NOTE: `ps-lpr-command' and `ps-lpr-switches' take their initial values
186 ;; from the variables `lpr-command' and `lpr-switches'. If you have
187 ;; `lpr-command' set to invoke a pretty-printer such as `enscript',
188 ;; then ps-print won't work properly. `ps-lpr-command' must name
189 ;; a program that does not format the files it prints.
190 ;; `ps-printer-name' takes its initial value from the variable
193 ;; The variable `ps-print-region-function' specifies a function to print the
194 ;; region on a PostScript printer.
195 ;; See definition of `call-process-region' for calling conventions. The fourth
196 ;; and the sixth arguments are both nil.
198 ;; If you're using NTEmacs, don't forget to customize the following variables:
199 ;; `ps-printer-name', `ps-lpr-command', `ps-lpr-switches' and
200 ;; `ps-spool-config'. See these variables documentation in the code or by
201 ;; typing, for example, C-h v ps-printer-name RET.
207 ;; All dimensions are floats in PostScript points.
208 ;; 1 inch == 2.54 cm == 72 points
209 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
211 ;; The variable `ps-paper-type' determines the size of paper ps-print formats
212 ;; for; it should contain one of the symbols: `a4' `a3' `letter' `legal'
213 ;; `letter-small' `tabloid' `ledger' `statement' `executive' `a4small' `b4'
216 ;; The variable `ps-landscape-mode' determines the orientation of the printing
217 ;; on the page: nil means `portrait' mode, non-nil means `landscape' mode.
218 ;; There is no oblique mode yet, though this is easy to do in ps.
220 ;; In landscape mode, the text is NOT scaled: you may print 70 lines in portrait
221 ;; mode and only 50 lines in landscape mode. The margins represent margins in
222 ;; the printed paper: the top margin is the margin between the top of the page
223 ;; and the printed header, whatever the orientation is.
225 ;; The variable `ps-number-of-columns' determines the number of columns both in
226 ;; landscape and portrait mode.
228 ;; - (the standard) one column portrait mode.
229 ;; - (my favorite) two columns landscape mode (which spares trees).
231 ;; - one column landscape mode for files with very long lines.
232 ;; - multi-column portrait or landscape mode.
234 ;; The variable `ps-print-upside-down' determines other orientation for printing
235 ;; page: nil means `normal' printing, non-nil means `upside-down' printing. The
236 ;; default value is nil (`normal' printing).
238 ;; The `upside-down' orientation can be used in portrait or landscape mode.
244 ;; The horizontal layout is determined by the variables
245 ;; `ps-left-margin' `ps-inter-column' `ps-right-margin'
248 ;; ------------------------------------------
250 ;; | lm | text | ic | text | ic | text | rm |
252 ;; ------------------------------------------
254 ;; If `ps-number-of-columns' is 1, `ps-inter-column' is not relevant.
255 ;; Usually, lm = rm > 0 and ic = lm
256 ;; If (ic < 0), the text of adjacent columns can overlap.
262 ;; The vertical layout is determined by the variables
263 ;; `ps-bottom-margin' `ps-top-margin' `ps-header-offset'
266 ;; |--------| |--------|
268 ;; |--------| |--------|
272 ;; |--------| or | text |
276 ;; |--------| |--------|
278 ;; |--------| |--------|
280 ;; If `ps-print-header' is nil, `ps-header-offset' is not relevant.
281 ;; The margins represent margins in the printed paper:
282 ;; the top margin is the margin between the top of the page
283 ;; and the printed header, whatever the orientation is.
289 ;; ps-print can print headers at the top of each column or at the top
290 ;; of each page; the default headers contain the following four items:
291 ;; on the left, the name of the buffer and, if the buffer is visiting
292 ;; a file, the file's directory; on the right, the page number and
293 ;; date of printing. The default headers look something like this:
296 ;; /home/jct/emacs-lisp/ps/new 94/12/31
298 ;; When printing on duplex printers, left and right are reversed so
299 ;; that the page numbers are toward the outside (cf. `ps-spool-duplex').
301 ;; Headers are configurable:
302 ;; To turn them off completely, set `ps-print-header' to nil.
303 ;; To turn off the header's gaudy framing box,
304 ;; set `ps-print-header-frame' to nil.
306 ;; To print only one header at the top of each page,
307 ;; set `ps-print-only-one-header' to t.
309 ;; The font family and size of text in the header are determined
310 ;; by the variables `ps-header-font-family', `ps-header-font-size' and
311 ;; `ps-header-title-font-size' (see below).
313 ;; The variable `ps-header-line-pad' determines the portion of a header
314 ;; title line height to insert between the header frame and the text
315 ;; it contains, both in the vertical and horizontal directions:
316 ;; .5 means half a line.
318 ;; Page numbers are printed in `n/m' format, indicating page n of m pages;
319 ;; to omit the total page count and just print the page number,
320 ;; set `ps-show-n-of-n' to nil.
322 ;; The amount of information in the header can be changed by changing
323 ;; the number of lines. To show less, set `ps-header-lines' to 1, and
324 ;; the header will show only the buffer name and page number. To show
325 ;; more, set `ps-header-lines' to 3, and the header will show the time of
326 ;; printing below the date.
328 ;; To change the content of the headers, change the variables
329 ;; `ps-left-header' and `ps-right-header'.
330 ;; These variables are lists, specifying top-to-bottom the text
331 ;; to display on the left or right side of the header.
332 ;; Each element of the list should be a string or a symbol.
333 ;; Strings are inserted directly into the PostScript arrays,
334 ;; and should contain the PostScript string delimiters '(' and ')'.
336 ;; Symbols in the header format lists can either represent functions
337 ;; or variables. Functions are called, and should return a string to
338 ;; show in the header. Variables should contain strings to display in
339 ;; the header. In either case, function or variable, the PostScript
340 ;; string delimiters are added by ps-print, and should not be part of
341 ;; the returned value.
343 ;; Here's an example: say we want the left header to display the text
349 ;; where we have a function to return "Moe"
351 ;; (defun moe-func ()
354 ;; a variable specifying "Larry"
356 ;; (setq larry-var "Larry")
358 ;; and a literal for "Curly". Here's how `ps-left-header' should be
361 ;; (setq ps-left-header (list 'moe-func 'larry-var "(Curly)"))
363 ;; Note that Curly has the PostScript string delimiters inside his
364 ;; quotes -- those aren't misplaced lisp delimiters!
366 ;; Without them, PostScript would attempt to call the undefined
367 ;; function Curly, which would result in a PostScript error.
369 ;; Since most printers don't report PostScript errors except by
370 ;; aborting the print job, this kind of error can be hard to track down.
372 ;; Consider yourself warned!
375 ;; PostScript Prologue Header
376 ;; --------------------------
378 ;; It is possible to add PostScript prologue header comments besides that
379 ;; ps-print generates by setting the variable `ps-print-prologue-header'.
381 ;; `ps-print-prologue-header' may be a string or a symbol function which returns
382 ;; a string. Note that this string is inserted on PostScript prologue header
383 ;; section which is used to define some document characteristic through
384 ;; PostScript special comments, like "%%Requirements: jog\n".
386 ;; By default `ps-print-prologue-header' is nil.
388 ;; ps-print always inserts the %%Requirements: comment, so if you need to insert
389 ;; more requirements put them first in `ps-print-prologue-header' using the
390 ;; "%%+" comment. For example, if you need to set numcopies to 3 and jog on
391 ;; requirements and set %%LanguageLevel: to 2, do:
393 ;; (setq ps-print-prologue-header
394 ;; "%%+ numcopies(3) jog\n%%LanguageLevel: 2\n")
396 ;; The duplex requirement is inserted by ps-print (see section Duplex Printers).
398 ;; Do not forget to terminate the string with "\n".
400 ;; For more information about PostScript document comments, see:
401 ;; PostScript Language Reference Manual (2nd edition)
402 ;; Adobe Systems Incorporated
403 ;; Appendix G: Document Structuring Conventions -- Version 3.0
405 ;; It is also possible to add an user defined PostScript prologue code before
406 ;; all generated prologue code by setting the variable
407 ;; `ps-user-defined-prologue'.
409 ;; `ps-user-defined-prologue' may be a string or a symbol function which returns
410 ;; a string. Note that this string is inserted after `ps-adobe-tag' and
411 ;; PostScript prologue comments, and before ps-print PostScript prologue code
412 ;; section. That is, this string is inserted after error handler initialization
413 ;; and before ps-print settings.
415 ;; By default `ps-user-defined-prologue' is nil.
417 ;; It's recommended to initiate and terminate the string with "\n".
419 ;; It's strongly recommended only insert PostScript code and/or comments
420 ;; specific for your printing system particularities. For example, some special
421 ;; initialization that only your printing system needs.
423 ;; Do not insert code for duplex printing, n-up printing or error handler,
424 ;; ps-print handles this in a suitable way.
426 ;; For more information about PostScript, see:
427 ;; PostScript Language Reference Manual (2nd edition)
428 ;; Adobe Systems Incorporated
431 ;; PostScript Error Handler
432 ;; ------------------------
434 ;; ps-print instruments generated PostScript code with an error handler.
436 ;; The variable `ps-error-handler-message' specifies where the error handler
437 ;; message should be sent.
441 ;; none catch the error and *DON'T* send any message.
443 ;; paper catch the error and print on paper the error message.
444 ;; This is the default value.
446 ;; system catch the error and send back the error message to
447 ;; printing system. This is useful only if printing system
448 ;; send back an email reporting the error, or if there is
449 ;; some other alternative way to report back the error from
450 ;; the system to you.
452 ;; paper-and-system catch the error, print on paper the error message and
453 ;; send back the error message to printing system.
455 ;; Any other value is treated as `paper'.
461 ;; If you have a duplex-capable printer (one that prints both sides of the
462 ;; paper), set `ps-spool-duplex' to t.
463 ;; ps-print will insert blank pages to make sure each buffer starts on the
464 ;; correct side of the paper.
466 ;; The variable `ps-spool-config' specifies who is the responsable for setting
467 ;; duplex and page size switches. Valid values are:
469 ;; lpr-switches duplex and page size are configured by `ps-lpr-switches'.
470 ;; Don't forget to set `ps-lpr-switches' to select duplex
471 ;; printing for your printer.
473 ;; setpagedevice duplex and page size are configured by ps-print using the
474 ;; setpagedevice PostScript operator.
476 ;; nil duplex and page size are configured by ps-print *not* using
477 ;; the setpagedevice PostScript operator.
479 ;; Any other value is treated as nil.
481 ;; The default value is `lpr-switches'.
483 ;; WARNING: The setpagedevice PostScript operator affects ghostview utility when
484 ;; viewing file generated using landscape. Also on some printers,
485 ;; setpagedevice affects zebra stripes; on other printers,
486 ;; setpagedevice affects the left margin.
487 ;; Besides all that, if your printer does not have the paper size
488 ;; specified by setpagedevice, your printing will be aborted.
489 ;; So, if you need to use setpagedevice, set `ps-spool-config' to
490 ;; `setpagedevice', generate a test file and send it to your printer;
491 ;; if the printed file isn't ok, set `ps-spool-config' to nil.
493 ;; The variable `ps-spool-tumble' specifies how the page images on opposite
494 ;; sides of a sheet are oriented with respect to each other. If
495 ;; `ps-spool-tumble' is nil, produces output suitable for binding on the left or
496 ;; right. If `ps-spool-tumble' is non-nil, produces output suitable for binding
497 ;; at the top or bottom. It has effect only when `ps-spool-duplex' is non-nil.
498 ;; The default value is nil.
500 ;; Some printer system prints a header page and forces the first page be printed
501 ;; on header page back, when using duplex. If your printer system has this
502 ;; behavior, set variable `ps-banner-page-when-duplexing' to t.
504 ;; When `ps-banner-page-when-duplexing' is non-nil means the very first page is
505 ;; skipped. It's like the very first character of buffer (or region) is ^L
508 ;; The default for `ps-banner-page-when-duplexing' is nil (*don't* skip the very
515 ;; The variable `ps-n-up-printing' specifies the number of pages per sheet of
516 ;; paper. The value specified must be between 1 and 100. The default is 1.
518 ;; NOTE: some PostScript printer may crash printing if `ps-n-up-printing' is set
519 ;; to a high value (for example, 23). If this happens, set a lower value.
521 ;; The variable `ps-n-up-margin' specifies the margin in points between the
522 ;; sheet border and the n-up printing. The default is 1 cm (or 0.3937 inches,
525 ;; If variable `ps-n-up-border-p' is non-nil a border is drawn around each page.
528 ;; The variable `ps-n-up-filling' specifies how page matrix is filled on each
529 ;; sheet of paper. Following are the valid values for `ps-n-up-filling' with a
530 ;; filling example using a 3x4 page matrix:
532 ;; left-top 1 2 3 4 left-bottom 9 10 11 12
534 ;; 9 10 11 12 1 2 3 4
536 ;; right-top 4 3 2 1 right-bottom 12 11 10 9
538 ;; 12 11 10 9 4 3 2 1
540 ;; top-left 1 4 7 10 bottom-left 3 6 9 12
544 ;; top-right 10 7 4 1 bottom-right 12 9 6 3
548 ;; Any other value is treated as left-top.
550 ;; The default value is left-top.
553 ;; Control And 8-bit Characters
554 ;; ----------------------------
556 ;; The variable `ps-print-control-characters' specifies whether you want to see
557 ;; a printable form for control and 8-bit characters, that is, instead of
558 ;; sending, for example, a ^D (\004) to printer, it is sent the string "^D".
560 ;; Valid values for `ps-print-control-characters' are:
562 ;; 8-bit This is the value to use when you want an ASCII encoding of
563 ;; any control or non-ASCII character. Control characters are
564 ;; encoded as "^D", and non-ASCII characters have an
567 ;; control-8-bit This is the value to use when you want an ASCII encoding of
568 ;; any control character, whether it is 7 or 8-bit.
569 ;; European 8-bits accented characters are printed according
572 ;; control Only ASCII control characters have an ASCII encoding.
573 ;; European 8-bits accented characters are printed according
576 ;; nil No ASCII encoding. Any character is printed according the
579 ;; Any other value is treated as nil.
581 ;; The default is `control-8-bit'.
583 ;; Characters TAB, NEWLINE and FORMFEED are always treated by ps-print engine.
586 ;; Printing Multi-byte Buffer
587 ;; --------------------------
589 ;; See ps-mule.el for documentation.
595 ;; The variable `ps-line-number' specifies whether to number each line;
596 ;; non-nil means do so. The default is nil (don't number each line).
598 ;; The variable `ps-line-number-step' specifies the interval that line number is
599 ;; printed. For example, if `ps-line-number-step' is set to 2, the printing
612 ;; integer an integer that specifies the interval that line number is
613 ;; printed. If it's lesser than or equal to zero, it's used the
616 ;; `zebra' specifies that only the line number of the first line in a zebra
617 ;; stripe is to be printed.
619 ;; Any other value is treated as `zebra'.
620 ;; The default value is 1, so each line number is printed.
626 ;; Zebra stripes are a kind of background that appear "underneath" the text
627 ;; and can make the text easier to read. They look like this:
629 ;; XXXXXXXXXXXXXXXXXXXXXXXX
630 ;; XXXXXXXXXXXXXXXXXXXXXXXX
631 ;; XXXXXXXXXXXXXXXXXXXXXXXX
635 ;; XXXXXXXXXXXXXXXXXXXXXXXX
636 ;; XXXXXXXXXXXXXXXXXXXXXXXX
637 ;; XXXXXXXXXXXXXXXXXXXXXXXX
639 ;; The blocks of X's represent rectangles filled with a light gray color.
640 ;; Each rectangle extends all the way across the page.
642 ;; The height, in lines, of each rectangle is controlled by
643 ;; the variable `ps-zebra-stripe-height', which is 3 by default.
644 ;; The distance between stripes equals the height of a stripe.
646 ;; The variable `ps-zebra-stripes' controls whether to print zebra stripes.
647 ;; Non-nil means yes, nil means no. The default is nil.
649 ;; The variable `ps-zebra-color' controls the zebra stripes gray scale or RGB
650 ;; color. It should be a float number between 0.0 (black color) and 1.0 (white
651 ;; color), a string which is a color name, or a list of 3 numbers which
652 ;; corresponds to the Red Green Blue color scale.
653 ;; The default is 0.95 (or "gray95", or '(0.95 0.95 0.95)).
655 ;; See also section How Ps-Print Has A Text And/Or Image On Background.
661 ;; ps-print has the following hook variables:
664 ;; It is evaluated once before any printing process. This is the right
665 ;; place to initialize ps-print global data.
666 ;; For an example, see section Adding a New Font Family.
668 ;; `ps-print-begin-sheet-hook'
669 ;; It is evaluated on each beginning of sheet of paper.
670 ;; If `ps-n-up-printing' is equal to 1, `ps-print-begin-page-hook' is never
673 ;; `ps-print-begin-page-hook'
674 ;; It is evaluated on each beginning of page, except in the beginning
675 ;; of page that `ps-print-begin-sheet-hook' is evaluated.
677 ;; `ps-print-begin-column-hook'
678 ;; It is evaluated on each beginning of column, except in the beginning
679 ;; of column that `ps-print-begin-page-hook' is evaluated or that
680 ;; `ps-print-begin-sheet-hook' is evaluated.
686 ;; ps-print now knows rather precisely some fonts: the variable
687 ;; `ps-font-info-database' contains information for a list of font families
688 ;; (currently mainly `Courier' `Helvetica' `Times' `Palatino' `Helvetica-Narrow'
689 ;; `NewCenturySchlbk'). Each font family contains the font names for standard,
690 ;; bold, italic and bold-italic characters, a reference size (usually 10) and
691 ;; the corresponding line height, width of a space and average character width.
693 ;; The variable `ps-font-family' determines which font family is to be used for
694 ;; ordinary text. If its value does not correspond to a known font family, an
695 ;; error message is printed into the `*Messages*' buffer, which lists the
696 ;; currently available font families.
698 ;; The variable `ps-font-size' determines the size (in points) of the font for
699 ;; ordinary text, when generating PostScript. Its value is a float or a cons of
700 ;; floats which has the following form:
702 ;; (LANDSCAPE-SIZE . PORTRAIT-SIZE)
704 ;; Similarly, the variable `ps-header-font-family' determines which font family
705 ;; is to be used for text in the header.
707 ;; The variable `ps-header-font-size' determines the font size, in points, for
708 ;; text in the header (similar to `ps-font-size').
710 ;; The variable `ps-header-title-font-size' determines the font size, in points,
711 ;; for the top line of text in the header (similar to `ps-font-size').
714 ;; Adding a New Font Family
715 ;; ------------------------
717 ;; To use a new font family, you MUST first teach ps-print
718 ;; this font, i.e., add its information to `ps-font-info-database',
719 ;; otherwise ps-print cannot correctly place line and page breaks.
721 ;; For example, assuming `Helvetica' is unknown,
722 ;; you first need to do the following ONLY ONCE:
724 ;; - create a new buffer
725 ;; - generate the PostScript image to a file (C-u M-x ps-print-buffer)
726 ;; - open this file and find the line:
727 ;; `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
728 ;; - delete the leading `%' (which is the PostScript comment character)
729 ;; - replace in this line `Courier' by the new font (say `Helvetica')
731 ;; `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
732 ;; - send this file to the printer (or to ghostscript).
733 ;; You should read the following on the output page:
735 ;; For Helvetica 10 point, the line height is 11.56, the space width is 2.78
736 ;; and a crude estimate of average character width is 5.09243
738 ;; - Add these values to the `ps-font-info-database':
739 ;; (setq ps-font-info-database
741 ;; '((Helvetica ; the family key
742 ;; (fonts (normal . "Helvetica")
743 ;; (bold . "Helvetica-Bold")
744 ;; (italic . "Helvetica-Oblique")
745 ;; (bold-italic . "Helvetica-BoldOblique"))
747 ;; (line-height . 11.56)
748 ;; (space-width . 2.78)
749 ;; (avg-char-width . 5.09243)))
750 ;; ps-font-info-database))
751 ;; - Now you can use this font family with any size:
752 ;; (setq ps-font-family 'Helvetica)
753 ;; - if you want to use this family in another emacs session, you must
754 ;; put into your `~/.emacs':
755 ;; (require 'ps-print)
756 ;; (setq ps-font-info-database (append ...)))
757 ;; if you don't want to load ps-print, you have to copy the whole value:
758 ;; (setq ps-font-info-database '(<your stuff> <the standard stuff>))
759 ;; or, use `ps-print-hook' (see section Hooks):
760 ;; (add-hook 'ps-print-hook
762 ;; (or (assq 'Helvetica ps-font-info-database)
763 ;; (setq ps-font-info-database (append ...)))))
765 ;; You can create new `mixed' font families like:
767 ;; (fonts (normal . "Courier-Bold")
768 ;; (bold . "Helvetica")
769 ;; (italic . "Zapf-Chancery-MediumItalic")
770 ;; (bold-italic . "NewCenturySchlbk-BoldItalic")
771 ;; (w3-table-hack-x-face . "LineDrawNormal"))
773 ;; (line-height . 10.55)
774 ;; (space-width . 6.0)
775 ;; (avg-char-width . 6.0))
777 ;; Now you can use your new font family with any size:
778 ;; (setq ps-font-family 'my-mixed-family)
780 ;; Note that on above example the `w3-table-hack-x-face' entry refers to
781 ;; a face symbol, so when printing this face it'll be used the font
782 ;; `LineDrawNormal'. If the face `w3-table-hack-x-face' is remapped to
783 ;; use bold and/or italic attribute, the corresponding entry (bold, italic
784 ;; or bold-italic) will be used instead of `w3-table-hack-x-face' entry.
786 ;; Note also that the font family entry order is irrelevant, so the above
787 ;; example could also be written:
790 ;; (fonts (w3-table-hack-x-face . "LineDrawNormal")
791 ;; (bold . "Helvetica")
792 ;; (bold-italic . "NewCenturySchlbk-BoldItalic")
793 ;; (italic . "Zapf-Chancery-MediumItalic")
794 ;; (normal . "Courier-Bold"))
795 ;; (avg-char-width . 6.0)
796 ;; (space-width . 6.0)
797 ;; (line-height . 10.55))
799 ;; Despite the note above, it is recommended that some convention about
800 ;; entry order be used.
802 ;; You can get information on all the fonts resident in YOUR printer
803 ;; by uncommenting the line:
804 ;; % 3 cm 20 cm moveto ReportAllFontInfo showpage
806 ;; The PostScript file should be sent to YOUR PostScript printer.
807 ;; If you send it to ghostscript or to another PostScript printer,
808 ;; you may get slightly different results.
809 ;; Anyway, as ghostscript fonts are autoload, you won't get
813 ;; How Ps-Print Deals With Faces
814 ;; -----------------------------
816 ;; The ps-print-*-with-faces commands attempt to determine which faces
817 ;; should be printed in bold or italic, but their guesses aren't
818 ;; always right. For example, you might want to map colors into faces
819 ;; so that blue faces print in bold, and red faces in italic.
821 ;; It is possible to force ps-print to consider specific faces bold,
822 ;; italic or underline, no matter what font they are displayed in, by setting
823 ;; the variables `ps-bold-faces', `ps-italic-faces' and `ps-underlined-faces'.
824 ;; These variables contain lists of faces that ps-print should consider bold,
825 ;; italic or underline; to set them, put code like the following into your
828 ;; (setq ps-bold-faces '(my-blue-face))
829 ;; (setq ps-italic-faces '(my-red-face))
830 ;; (setq ps-underlined-faces '(my-green-face))
832 ;; Faces like bold-italic that are both bold and italic should go in
835 ;; ps-print keeps internal lists of which fonts are bold and which are
836 ;; italic; these lists are built the first time you invoke ps-print.
837 ;; For the sake of efficiency, the lists are built only once; the same
838 ;; lists are referred in later invocations of ps-print.
840 ;; Because these lists are built only once, it's possible for them to
841 ;; get out of sync, if a face changes, or if new faces are added. To
842 ;; get the lists back in sync, you can set the variable
843 ;; `ps-build-face-reference' to t, and the lists will be rebuilt the
844 ;; next time ps-print is invoked. If you need that the lists always be
845 ;; rebuilt when ps-print is invoked, set the variable
846 ;; `ps-always-build-face-reference' to t.
848 ;; If you need to print without worrying about face background color, set the
849 ;; variable `ps-use-face-background' which specifies if face background should
850 ;; be used. Valid values are:
852 ;; t always use face background color.
853 ;; nil never use face background color.
854 ;; (face...) list of faces whose background color will be used.
856 ;; Any other value will be treated as t.
857 ;; The default value is t.
860 ;; How Ps-Print Deals With Color
861 ;; -----------------------------
863 ;; ps-print detects faces with foreground and background colors
864 ;; defined and embeds color information in the PostScript image.
865 ;; The default foreground and background colors are defined by the
866 ;; variables `ps-default-fg' and `ps-default-bg'.
867 ;; On black-and-white printers, colors are displayed in gray scale.
868 ;; To turn off color output, set `ps-print-color-p' to nil.
871 ;; How Ps-Print Maps Faces
872 ;; -----------------------
874 ;; As ps-print uses PostScript to print buffers, it is possible to have
875 ;; other attributes associated with faces. So the new attributes used
878 ;; strikeout - like underline, but the line is in middle of text.
879 ;; overline - like underline, but the line is over the text.
880 ;; shadow - text will have a shadow.
881 ;; box - text will be surrounded by a box.
882 ;; outline - print characters as hollow outlines.
884 ;; See the documentation for `ps-extend-face'.
886 ;; Let's, for example, remap `font-lock-keyword-face' to another foreground
887 ;; color and bold attribute:
889 ;; (ps-extend-face '(font-lock-keyword-face "RoyalBlue" nil bold) 'MERGE)
891 ;; If you want to use a new face, define it first with `defface',
892 ;; and then call `ps-extend-face' to specify how to print it.
895 ;; How Ps-Print Has A Text And/Or Image On Background
896 ;; --------------------------------------------------
898 ;; ps-print can print texts and/or EPS PostScript images on background; it is
899 ;; possible to define the following text attributes: font name, font size,
900 ;; initial position, angle, gray scale and pages to print.
902 ;; It has the following EPS PostScript images attributes: file name containing
903 ;; the image, initial position, X and Y scales, angle and pages to print.
905 ;; See documentation for `ps-print-background-text' and
906 ;; `ps-print-background-image'.
908 ;; For example, if we wish to print text "preliminary" on all pages and text
909 ;; "special" on page 5 and from page 11 to page 17, we could specify:
911 ;; (setq ps-print-background-text
914 ;; "LeftMargin" "BottomMargin PrintHeight add" ; X and Y position
915 ;; ; (upper left corner)
917 ;; "PrintHeight neg PrintPageWidth atan" ; angle
918 ;; 5 (11 . 17)) ; page list
921 ;; Similarly, we could print image "~/images/EPS-image1.ps" on all pages and
922 ;; image "~/images/EPS-image2.ps" on page 5 and from page 11 to page 17, we
925 ;; (setq ps-print-background-image
926 ;; '(("~/images/EPS-image1.ps"
927 ;; "LeftMargin" "BottomMargin") ; X and Y position (lower left corner)
928 ;; ("~/images/EPS-image2.ps"
929 ;; "LeftMargin" "BottomMargin PrintHeight 2 div add" ; X and Y position
930 ;; ; (upper left corner)
932 ;; 5 (11 . 17)) ; page list
935 ;; If it is not possible to read (or does not exist) an image file, that file
938 ;; The printing order is:
940 ;; 1. Print background color
941 ;; 2. Print zebra stripes
942 ;; 3. Print background texts that it should be on all pages
943 ;; 4. Print background images that it should be on all pages
944 ;; 5. Print background texts only for current page (if any)
945 ;; 6. Print background images only for current page (if any)
947 ;; 8. Print buffer text (with faces, if specified) and line number
953 ;; Some tools are provided to help you customize your font setup.
955 ;; `ps-setup' returns (some part of) the current setup.
957 ;; To avoid wrapping too many lines, you may want to adjust the
958 ;; left and right margins and the font size. On UN*X systems, do:
959 ;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
960 ;; to determine the longest lines of your file.
961 ;; Then, the command `ps-line-lengths' will give you the correspondence
962 ;; between a line length (number of characters) and the maximum font
963 ;; size which doesn't wrap such a line with the current ps-print setup.
965 ;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
966 ;; the correspondence between a number of pages and the maximum font
967 ;; size which allow the number of lines of the current buffer or of
968 ;; its current region to fit in this number of pages.
970 ;; NOTE: line folding is not taken into account in this process and could
971 ;; change the results.
973 ;; The command `ps-print-customize' activates a customization buffer for
977 ;; New since version 1.5
978 ;; ---------------------
980 ;; Color output capability.
981 ;; Automatic detection of font attributes (bold, italic).
982 ;; Configurable headers with page numbers.
984 ;; Support for different paper sizes.
985 ;; Better conformance to PostScript Document Structure Conventions.
988 ;; New since version 2.8
989 ;; ---------------------
991 ;; [vinicius] 20000310 Vinicius Jose Latorre <vinicius@cpqd.com.br>
993 ;; PostScript error handler.
994 ;; `ps-user-defined-prologue' and `ps-error-handler-message'.
996 ;; [vinicius] 991211 Vinicius Jose Latorre <vinicius@cpqd.com.br>
998 ;; `ps-print-customize'.
1000 ;; [vinicius] 990703 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1002 ;; Better customization.
1003 ;; `ps-banner-page-when-duplexing' and `ps-zebra-color'.
1005 ;; [vinicius] 990513 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1008 ;; Hook: `ps-print-begin-sheet-hook'.
1010 ;; [keinichi] 990509 Kein'ichi Handa <handa@etl.go.jp>
1012 ;; `ps-print-region-function'
1014 ;; [vinicius] 990301 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1016 ;; PostScript tumble and setpagedevice.
1018 ;; [vinicius] 980922 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1020 ;; PostScript prologue header comment insertion.
1021 ;; Skip invisible text better.
1023 ;; [keinichi] 980819 Kein'ichi Handa <handa@etl.go.jp>
1025 ;; Multi-byte buffer handling.
1027 ;; [vinicius] 980306 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1029 ;; Skip invisible text.
1031 ;; [vinicius] 971130 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1033 ;; Hooks: `ps-print-hook', `ps-print-begin-page-hook' and
1034 ;; `ps-print-begin-column-hook'.
1035 ;; Put one header per page over the columns.
1036 ;; Better database font management.
1037 ;; Better control characters handling.
1039 ;; [vinicius] 971121 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1041 ;; Dynamic evaluation at print time of `ps-lpr-switches'.
1042 ;; Handle control characters.
1044 ;; New face attributes.
1047 ;; Text and/or image on background.
1049 ;; [jack] 960517 Jacques Duthen <duthen@cegelec-red.fr>
1051 ;; Font family and float size for text and header.
1053 ;; Multiple columns.
1054 ;; Tools for page setup.
1057 ;; Known bugs and limitations of ps-print
1058 ;; --------------------------------------
1060 ;; Although color printing will work in XEmacs 19.12, it doesn't work
1061 ;; well; in particular, bold or italic fonts don't print in the right
1062 ;; background color.
1064 ;; Invisible properties aren't correctly ignored in XEmacs 19.12.
1066 ;; Automatic font-attribute detection doesn't work well, especially
1067 ;; with hilit19 and older versions of get-create-face. Users having
1068 ;; problems with auto-font detection should use the lists
1069 ;; `ps-italic-faces', `ps-bold-faces' and `ps-underlined-faces' and/or
1070 ;; turn off automatic detection by setting `ps-auto-font-detect' to nil.
1072 ;; Automatic font-attribute detection doesn't work with XEmacs 19.12
1073 ;; in tty mode; use the lists `ps-italic-faces', `ps-bold-faces' and
1074 ;; `ps-underlined-faces' instead.
1076 ;; Still too slow; could use some hand-optimization.
1078 ;; Default background color isn't working.
1080 ;; Faces are always treated as opaque.
1082 ;; Epoch and Emacs 19 not supported. At all.
1084 ;; Fixed-pitch fonts work better for line folding, but are not required.
1086 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' don't take care
1087 ;; of folding lines.
1093 ;; Avoid page break inside a paragraph.
1094 ;; Add `ps-non-bold-faces' and `ps-non-italic-faces' (should be easy).
1095 ;; Improve the memory management for big files (hard?).
1096 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' should take care
1097 ;; of folding lines.
1103 ;; Thanks to David X Callaway <dxc@xprt.net> for helping debugging PostScript
1104 ;; level 1 compatibility.
1106 ;; Thanks to Colin Marquardt <colin.marquardt@usa.alcatel.com> for upside-down
1107 ;; and line number step suggestions.
1109 ;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for user defined PostScript
1110 ;; prologue code suggestion.
1112 ;; Thanks to Kein'ichi Handa <handa@etl.go.jp> for multi-byte buffer handling.
1114 ;; Thanks to Matthew O Persico <Matthew.Persico@lazard.com> for line number on
1117 ;; Thanks to Theodore Jump <tjump@cais.com> for adjust PostScript code order on
1120 ;; Thanks to Roland Ducournau <ducour@lirmm.fr> for
1121 ;; `ps-print-control-characters' variable documentation.
1123 ;; Thanks to Marcus G Daniels <marcus@cathcart.sysc.pdx.edu> for a better
1124 ;; database font management.
1126 ;; Thanks to Martin Boyer <gamin@videotron.ca> for some ideas on putting one
1127 ;; header per page over the columns and correct line numbers when printing a
1130 ;; Thanks to Steven L Baur <steve@miranova.com> for dynamic evaluation at
1131 ;; print time of `ps-lpr-switches'.
1133 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for handling control characters
1134 ;; (his code was severely modified, but the main idea was kept).
1136 ;; Thanks to some suggestions on:
1137 ;; * Face color map: Marco Melgazzi <marco@techie.com>
1138 ;; * XEmacs compatibility: William J. Henney <will@astrosmo.unam.mx>
1139 ;; * Check `ps-paper-type': Sudhakar Frederick <sfrederi@asc.corp.mot.com>
1141 ;; Thanks to Jacques Duthen <duthen@cegelec-red.fr> (Jack) for the 3.4 version
1142 ;; I started from. [vinicius]
1144 ;; Thanks to Jim Thompson <?@?> for the 2.8 version I started from.
1147 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for adding support for
1148 ;; color and the invisible property.
1150 ;; Thanks to Avishai Yacobi, avishaiy@mcil.comm.mot.com, for writing
1151 ;; the initial port to Emacs 19. His code is no longer part of
1152 ;; ps-print, but his work is still appreciated.
1154 ;; Thanks to Remi Houdaille and Michel Train, michel@metasoft.fdn.org,
1155 ;; for adding underline support. Their code also is no longer part of
1156 ;; ps-print, but their efforts are not forgotten.
1158 ;; Thanks also to all of you who mailed code to add features to
1159 ;; ps-print; although I didn't use your code, I still appreciate your
1160 ;; sharing it with me.
1162 ;; Thanks to all who mailed comments, encouragement, and criticism.
1163 ;; Thanks also to all who responded to my survey; I had too many
1164 ;; responses to reply to them all, but I greatly appreciate your
1168 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1172 (unless (featurep 'lisp-float-type)
1173 (error "`ps-print' requires floating point support"))
1176 ;; For Emacs 20.2 and the earlier version.
1178 (or (fboundp 'set-buffer-multibyte)
1179 (defun set-buffer-multibyte (arg)
1180 (setq enable-multibyte-characters arg)))
1182 (or (fboundp 'string-as-unibyte)
1183 (defun string-as-unibyte (arg) arg))
1185 (or (fboundp 'string-as-multibyte)
1186 (defun string-as-multibyte (arg) arg))
1188 (or (fboundp 'charset-after)
1189 (defun charset-after (&optional arg)
1190 (char-charset (char-after arg))))
1193 (or (fboundp 'line-beginning-position)
1194 (defun line-beginning-position (&optional n)
1196 (and n (/= n 1) (forward-line (1- n)))
1201 (defconst ps-windows-system
1202 (memq system-type '(win32 w32 mswindows ms-dos windows-nt)))
1203 (defconst ps-lp-system
1204 (memq system-type '(usq-unix-v dgux hpux irix)))
1207 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1211 ;;; Interface to the command system
1213 (defgroup postscript nil
1218 (defgroup ps-print nil
1219 "PostScript generator for Emacs 19"
1224 (defgroup ps-print-horizontal nil
1225 "Horizontal page layout"
1230 (defgroup ps-print-vertical nil
1231 "Vertical page layout"
1236 (defgroup ps-print-headers nil
1242 (defgroup ps-print-font nil
1243 "Fonts customization"
1248 (defgroup ps-print-color nil
1249 "Color customization"
1254 (defgroup ps-print-face nil
1255 "Faces customization"
1261 (defgroup ps-print-n-up nil
1262 "N-up customization"
1267 (defgroup ps-print-zebra nil
1268 "Zebra customization"
1273 (defgroup ps-print-background nil
1274 "Background customization"
1279 (defgroup ps-print-printer nil
1280 "Printer customization"
1285 (defgroup ps-print-page nil
1286 "Page customization"
1291 (defgroup ps-print-miscellany nil
1292 "Miscellany customization"
1298 (defcustom ps-error-handler-message 'paper
1299 "*Specify where the error handler message should be sent.
1303 `none' catch the error and *DON'T* send any message.
1305 `paper' catch the error and print on paper the error message.
1307 `system' catch the error and send back the error message to
1308 printing system. This is useful only if printing system
1309 send back an email reporting the error, or if there is
1310 some other alternative way to report back the error from
1313 `paper-and-system' catch the error, print on paper the error message and
1314 send back the error message to printing system.
1316 Any other value is treated as `paper'."
1317 :type '(choice :tag "Error Handler Message"
1318 (const none) (const paper)
1319 (const system) (const paper-and-system))
1320 :group 'ps-print-miscellany)
1322 (defcustom ps-user-defined-prologue nil
1323 "*User defined PostScript prologue code inserted before all prologue code.
1325 `ps-user-defined-prologue' may be a string or a symbol function which returns a
1326 string. Note that this string is inserted after `ps-adobe-tag' and PostScript
1327 prologue comments, and before ps-print PostScript prologue code section. That
1328 is, this string is inserted after error handler initialization and before
1331 It's recommended to initiate and terminate the string with \"\\n\".
1333 It's strongly recommended only insert PostScript code and/or comments specific
1334 for your printing system particularities. For example, some special
1335 initialization that only your printing system needs.
1337 Do not insert code for duplex printing, n-up printing or error handler, ps-print
1338 handles this in a suitable way.
1340 For more information about PostScript, see:
1341 PostScript Language Reference Manual (2nd edition)
1342 Adobe Systems Incorporated"
1343 :type '(choice :tag "User Defined Prologue"
1344 string symbol (const :tag "none" nil))
1345 :group 'ps-print-miscellany)
1347 (defcustom ps-print-prologue-header nil
1348 "*PostScript prologue header comments besides that ps-print generates.
1350 `ps-print-prologue-header' may be a string or a symbol function which
1351 returns a string. Note that this string is inserted on PostScript prologue
1352 header section which is used to define some document characteristic through
1353 PostScript special comments, like \"%%Requirements: jog\\n\".
1355 ps-print always inserts the %%Requirements: comment, so if you need to insert
1356 more requirements put them first in `ps-print-prologue-header' using the
1357 \"%%+\" comment. For example, if you need to set numcopies to 3 and jog on
1358 requirements and set %%LanguageLevel: to 2, do:
1360 (setq ps-print-prologue-header
1361 \"%%+ numcopies(3) jog\\n%%LanguageLevel: 2\\n\")
1363 The duplex requirement is inserted by ps-print (see `ps-spool-duplex').
1365 Do not forget to terminate the string with \"\\n\".
1367 For more information about PostScript document comments, see:
1368 PostScript Language Reference Manual (2nd edition)
1369 Adobe Systems Incorporated
1370 Appendix G: Document Structuring Conventions -- Version 3.0"
1371 :type '(choice :tag "Prologue Header"
1372 string symbol (const :tag "none" nil))
1373 :group 'ps-print-miscellany)
1375 (defcustom ps-printer-name (and (boundp 'printer-name)
1377 "*The name of a local printer for printing PostScript files.
1379 On Unix-like systems, a string value should be a name understood by
1380 lpr's -P option; a value of nil means use the value of `printer-name'
1381 instead. Any other value will be ignored.
1383 On MS-DOS and MS-Windows systems, a string value is taken as the name of
1384 the printer device or port to which PostScript files are written,
1385 provided `ps-lpr-command' is \"\". By default it is the same as
1386 `printer-name'; typical non-default settings would be \"LPT1\" to
1387 \"LPT3\" for parallel printers, or \"COM1\" to \"COM4\" or \"AUX\" for
1388 serial printers, or \"//hostname/printer\" for a shared network printer.
1389 You can also set it to a name of a file, in which case the output gets
1390 appended to that file. \(Note that `ps-print' package already has
1391 facilities for printing to a file, so you might as well use them instead
1392 of changing the setting of this variable.\) If you want to silently
1393 discard the printed output, set this to \"NUL\"."
1394 :type '(choice :tag "Printer Name"
1395 (file :tag "Print to file")
1396 (string :tag "Pipe to ps-lpr-command")
1397 (const :tag "Same as printer-name" nil))
1398 :group 'ps-print-printer)
1400 (defcustom ps-lpr-command lpr-command
1401 "*Name of program for printing a PostScript file.
1403 On MS-DOS and MS-Windows systems, if the value is an empty string then
1404 Emacs will write directly to the printer port named by `ps-printer-name'.
1405 The programs `print' and `nprint' (the standard print programs on Windows
1406 NT and Novell Netware respectively) are handled specially, using
1407 `ps-printer-name' as the destination for output; any other program is
1408 treated like `lpr' except that an explicit filename is given as the last
1411 :group 'ps-print-printer)
1413 (defcustom ps-lpr-switches lpr-switches
1414 "*A list of extra switches to pass to `ps-lpr-command'."
1415 :type '(repeat :tag "PostScript lpr Switches"
1416 (choice string symbol (repeat sexp)))
1417 :group 'ps-print-printer)
1419 (defcustom ps-print-region-function nil
1420 "*Specify a function to print the region on a PostScript printer.
1421 See definition of `call-process-region' for calling conventions. The fourth and
1422 the sixth arguments are both nil."
1424 :group 'ps-print-printer)
1428 ;; All page dimensions are in PostScript points.
1429 ;; 1 inch == 2.54 cm == 72 points
1430 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
1432 ;; Letter 8.5 inch x 11.0 inch
1433 ;; Legal 8.5 inch x 14.0 inch
1434 ;; A4 8.26 inch x 11.69 inch = 21.0 cm x 29.7 cm
1436 ;; LetterSmall 7.68 inch x 10.16 inch
1437 ;; Tabloid 11.0 inch x 17.0 inch
1438 ;; Ledger 17.0 inch x 11.0 inch
1439 ;; Statement 5.5 inch x 8.5 inch
1440 ;; Executive 7.5 inch x 10.0 inch
1441 ;; A3 11.69 inch x 16.5 inch = 29.7 cm x 42.0 cm
1442 ;; A4Small 7.47 inch x 10.85 inch
1443 ;; B4 10.125 inch x 14.33 inch
1444 ;; B5 7.16 inch x 10.125 inch
1446 (defcustom ps-page-dimensions-database
1447 (list (list 'a4 (/ (* 72 21.0) 2.54) (/ (* 72 29.7) 2.54) "A4")
1448 (list 'a3 (/ (* 72 29.7) 2.54) (/ (* 72 42.0) 2.54) "A3")
1449 (list 'letter (* 72 8.5) (* 72 11.0) "Letter")
1450 (list 'legal (* 72 8.5) (* 72 14.0) "Legal")
1451 (list 'letter-small (* 72 7.68) (* 72 10.16) "LetterSmall")
1452 (list 'tabloid (* 72 11.0) (* 72 17.0) "Tabloid")
1453 (list 'ledger (* 72 17.0) (* 72 11.0) "Ledger")
1454 (list 'statement (* 72 5.5) (* 72 8.5) "Statement")
1455 (list 'executive (* 72 7.5) (* 72 10.0) "Executive")
1456 (list 'a4small (* 72 7.47) (* 72 10.85) "A4Small")
1457 (list 'b4 (* 72 10.125) (* 72 14.33) "B4")
1458 (list 'b5 (* 72 7.16) (* 72 10.125) "B5"))
1459 "*List associating a symbolic paper type to its width, height and doc media.
1460 See `ps-paper-type'."
1461 :type '(repeat (list :tag "Paper Type"
1462 (symbol :tag "Name")
1463 (number :tag "Width")
1464 (number :tag "Height")
1465 (string :tag "Media")))
1466 :group 'ps-print-page)
1469 (defcustom ps-paper-type 'letter
1470 "*Specify the size of paper to format for.
1471 Should be one of the paper types defined in `ps-page-dimensions-database', for
1472 example `letter', `legal' or `a4'."
1473 :type '(symbol :validate (lambda (wid)
1474 (if (assq (widget-value wid)
1475 ps-page-dimensions-database)
1477 (widget-put wid :error "Unknown paper size")
1479 :group 'ps-print-page)
1481 (defcustom ps-landscape-mode nil
1482 "*Non-nil means print in landscape mode."
1484 :group 'ps-print-page)
1486 (defcustom ps-print-upside-down nil
1487 "*Non-nil means print upside-down."
1489 :group 'ps-print-page)
1491 (defcustom ps-print-control-characters 'control-8-bit
1492 "*Specify the printable form for control and 8-bit characters.
1493 That is, instead of sending, for example, a ^D (\\004) to printer,
1494 it is sent the string \"^D\".
1498 `8-bit' This is the value to use when you want an ASCII encoding of
1499 any control or non-ASCII character. Control characters are
1500 encoded as \"^D\", and non-ASCII characters have an
1503 `control-8-bit' This is the value to use when you want an ASCII encoding of
1504 any control character, whether it is 7 or 8-bit.
1505 European 8-bits accented characters are printed according
1508 `control' Only ASCII control characters have an ASCII encoding.
1509 European 8-bits accented characters are printed according
1512 nil No ASCII encoding. Any character is printed according the
1515 Any other value is treated as nil."
1516 :type '(choice :tag "Control Char"
1517 (const 8-bit) (const control-8-bit)
1518 (const control) (const :tag "nil" nil))
1519 :group 'ps-print-miscellany)
1521 (defcustom ps-n-up-printing 1
1522 "*Specify the number of pages per sheet paper."
1524 :tag "N Up Printing"
1527 (if (and (< 0 (widget-value wid))
1528 (<= (widget-value wid) 100))
1532 "Number of pages per sheet paper must be between 1 and 100.")
1534 :group 'ps-print-n-up)
1536 (defcustom ps-n-up-margin (/ (* 72 1.0) 2.54) ; 1 cm
1537 "*Specify the margin in points between the sheet border and n-up printing."
1539 :group 'ps-print-n-up)
1541 (defcustom ps-n-up-border-p t
1542 "*Non-nil means a border is drawn around each page."
1544 :group 'ps-print-n-up)
1546 (defcustom ps-n-up-filling 'left-top
1547 "*Specify how page matrix is filled on each sheet of paper.
1549 Following are the valid values for `ps-n-up-filling' with a filling example
1550 using a 3x4 page matrix:
1552 `left-top' 1 2 3 4 `left-bottom' 9 10 11 12
1556 `right-top' 4 3 2 1 `right-bottom' 12 11 10 9
1560 `top-left' 1 4 7 10 `bottom-left' 3 6 9 12
1564 `top-right' 10 7 4 1 `bottom-right' 12 9 6 3
1568 Any other value is treated as `left-top'."
1569 :type '(choice :tag "N-Up Filling"
1570 (const left-top) (const left-bottom)
1571 (const right-top) (const right-bottom)
1572 (const top-left) (const bottom-left)
1573 (const top-right) (const bottom-right))
1574 :group 'ps-print-n-up)
1576 (defcustom ps-number-of-columns (if ps-landscape-mode 2 1)
1577 "*Specify the number of columns"
1579 :group 'ps-print-miscellany)
1581 (defcustom ps-zebra-stripes nil
1582 "*Non-nil means print zebra stripes.
1583 See also documentation for `ps-zebra-stripe-height' and `ps-zebra-color'."
1585 :group 'ps-print-zebra)
1587 (defcustom ps-zebra-stripe-height 3
1588 "*Number of zebra stripe lines.
1589 See also documentation for `ps-zebra-stripes' and `ps-zebra-color'."
1591 :group 'ps-print-zebra)
1593 (defcustom ps-zebra-color 0.95
1594 "*Zebra stripe gray scale or RGB color.
1595 See also documentation for `ps-zebra-stripes' and `ps-zebra-stripe-height'."
1596 :type '(choice :tag "Zebra Gray/Color"
1597 (number :tag "Gray Scale" :value 0.95)
1598 (string :tag "Color Name" :value "gray95")
1599 (list :tag "RGB Color" :value (0.95 0.95 0.95)
1601 (number :tag "Green")
1602 (number :tag "Blue")))
1603 :group 'ps-print-zebra)
1605 (defcustom ps-line-number nil
1606 "*Non-nil means print line number."
1608 :group 'ps-print-miscellany)
1610 (defcustom ps-line-number-step 1
1611 "*Specify the interval that line number is printed.
1613 For example, `ps-line-number-step' is set to 2, the printing will look like:
1625 integer an integer that specifies the interval that line number is
1626 printed. If it's lesser than or equal to zero, it's used the
1629 `zebra' specifies that only the line number of the first line in a zebra
1630 stripe is to be printed.
1632 Any other value is treated as `zebra'."
1633 :type '(choice :tag "Line Number Step"
1634 (integer :tag "Step Interval")
1635 (const :tag "Synchronize Zebra" zebra))
1636 :group 'ps-print-miscellany)
1638 (defcustom ps-print-background-image nil
1639 "*EPS image list to be printed on background.
1643 (FILENAME X Y XSCALE YSCALE ROTATION PAGES...)
1645 FILENAME is a file name which contains an EPS image or some PostScript
1646 programming like EPS.
1647 FILENAME is ignored, if it doesn't exist or is read protected.
1649 X and Y are relative positions on paper to put the image.
1650 If X and Y are nil, the image is centralized on paper.
1652 XSCALE and YSCALE are scale factor to be applied to image before printing.
1653 If XSCALE and YSCALE are nil, the original size is used.
1655 ROTATION is the image rotation angle; if nil, the default is 0.
1657 PAGES designates the page to print background image.
1658 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1660 If PAGES is nil, print background image on all pages.
1662 X, Y, XSCALE, YSCALE and ROTATION may be a floating point number,
1663 an integer number or a string. If it is a string, the string should contain
1664 PostScript programming that returns a float or integer value.
1666 For example, if you wish to print an EPS image on all pages do:
1668 '((\"~/images/EPS-image.ps\"))"
1669 :type '(repeat (list (file :tag "EPS File")
1670 (choice :tag "X" (const :tag "default" nil) number string)
1671 (choice :tag "Y" (const :tag "default" nil) number string)
1672 (choice :tag "X Scale" (const :tag "default" nil) number string)
1673 (choice :tag "Y Scale" (const :tag "default" nil) number string)
1674 (choice :tag "Rotation" (const :tag "default" nil) number string)
1675 (repeat :tag "Pages" :inline t
1676 (radio (integer :tag "Page")
1678 (integer :tag "From")
1679 (integer :tag "To"))))))
1680 :group 'ps-print-background)
1682 (defcustom ps-print-background-text nil
1683 "*Text list to be printed on background.
1687 (STRING X Y FONT FONTSIZE GRAY ROTATION PAGES...)
1689 STRING is the text to be printed on background.
1691 X and Y are positions on paper to put the text.
1692 If X and Y are nil, the text is positioned at lower left corner.
1694 FONT is a font name to be used on printing the text.
1695 If nil, \"Times-Roman\" is used.
1697 FONTSIZE is font size to be used, if nil, 200 is used.
1699 GRAY is the text gray factor (should be very light like 0.8).
1700 If nil, the default is 0.85.
1702 ROTATION is the text rotation angle; if nil, the angle is given by
1703 the diagonal from lower left corner to upper right corner.
1705 PAGES designates the page to print background text.
1706 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1708 If PAGES is nil, print background text on all pages.
1710 X, Y, FONTSIZE, GRAY and ROTATION may be a floating point number,
1711 an integer number or a string. If it is a string, the string should contain
1712 PostScript programming that returns a float or integer value.
1714 For example, if you wish to print text \"Preliminary\" on all pages do:
1716 '((\"Preliminary\"))"
1717 :type '(repeat (list (string :tag "Text")
1718 (choice :tag "X" (const :tag "default" nil) number string)
1719 (choice :tag "Y" (const :tag "default" nil) number string)
1720 (choice :tag "Font" (const :tag "default" nil) string)
1721 (choice :tag "Fontsize" (const :tag "default" nil) number string)
1722 (choice :tag "Gray" (const :tag "default" nil) number string)
1723 (choice :tag "Rotation" (const :tag "default" nil) number string)
1724 (repeat :tag "Pages" :inline t
1725 (radio (integer :tag "Page")
1727 (integer :tag "From")
1728 (integer :tag "To"))))))
1729 :group 'ps-print-background)
1731 ;;; Horizontal layout
1733 ;; ------------------------------------------
1735 ;; | lm | text | ic | text | ic | text | rm |
1737 ;; ------------------------------------------
1739 (defcustom ps-left-margin (/ (* 72 2.0) 2.54) ; 2 cm
1740 "*Left margin in points (1/72 inch)."
1742 :group 'ps-print-horizontal)
1744 (defcustom ps-right-margin (/ (* 72 2.0) 2.54) ; 2 cm
1745 "*Right margin in points (1/72 inch)."
1747 :group 'ps-print-horizontal)
1749 (defcustom ps-inter-column (/ (* 72 2.0) 2.54) ; 2 cm
1750 "*Horizontal space between columns in points (1/72 inch)."
1752 :group 'ps-print-horizontal)
1768 (defcustom ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
1769 "*Bottom margin in points (1/72 inch)."
1771 :group 'ps-print-vertical)
1773 (defcustom ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
1774 "*Top margin in points (1/72 inch)."
1776 :group 'ps-print-vertical)
1778 (defcustom ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
1779 "*Vertical space in points (1/72 inch) between the main text and the header."
1781 :group 'ps-print-vertical)
1783 (defcustom ps-header-line-pad 0.15
1784 "*Portion of a header title line height to insert between the header frame
1785 and the text it contains, both in the vertical and horizontal directions."
1787 :group 'ps-print-vertical)
1791 (defcustom ps-print-header t
1792 "*Non-nil means print a header at the top of each page.
1793 By default, the header displays the buffer name, page number, and, if
1794 the buffer is visiting a file, the file's directory. Headers are
1795 customizable by changing variables `ps-left-header' and
1798 :group 'ps-print-headers)
1800 (defcustom ps-print-only-one-header nil
1801 "*Non-nil means print only one header at the top of each page.
1802 This is useful when printing more than one column, so it is possible
1803 to have only one header over all columns or one header per column.
1804 See also `ps-print-header'."
1806 :group 'ps-print-headers)
1808 (defcustom ps-print-header-frame t
1809 "*Non-nil means draw a gaudy frame around the header."
1811 :group 'ps-print-headers)
1813 (defcustom ps-header-lines 2
1814 "*Number of lines to display in page header, when generating PostScript."
1816 :group 'ps-print-headers)
1818 (defcustom ps-show-n-of-n t
1819 "*Non-nil means show page numbers as N/M, meaning page N of M.
1820 NOTE: page numbers are displayed as part of headers,
1821 see variable `ps-print-header'."
1823 :group 'ps-print-headers)
1825 (defcustom ps-spool-config
1826 (if ps-windows-system
1829 "*Specify who is responsable for setting duplex and page size switches.
1833 `lpr-switches' duplex and page size are configured by `ps-lpr-switches'.
1834 Don't forget to set `ps-lpr-switches' to select duplex
1835 printing for your printer.
1837 `setpagedevice' duplex and page size are configured by ps-print using the
1838 setpagedevice PostScript operator.
1840 nil duplex and page size are configured by ps-print *not* using
1841 the setpagedevice PostScript operator.
1843 Any other value is treated as nil.
1845 WARNING: The setpagedevice PostScript operator affects ghostview utility when
1846 viewing file generated using landscape. Also on some printers,
1847 setpagedevice affects zebra stripes; on other printers, setpagedevice
1848 affects the left margin.
1849 Besides all that, if your printer does not have the paper size
1850 specified by setpagedevice, your printing will be aborted.
1851 So, if you need to use setpagedevice, set `ps-spool-config' to
1852 `setpagedevice', generate a test file and send it to your printer; if
1853 the printed file isn't ok, set `ps-spool-config' to nil."
1854 :type '(choice :tag "Spool Config"
1855 (const lpr-switches) (const setpagedevice)
1856 (const :tag "nil" nil))
1857 :group 'ps-print-headers)
1859 (defcustom ps-spool-duplex nil ; Not many people have duplex printers,
1860 ; so default to nil.
1861 "*Non-nil generates PostScript for a two-sided printer.
1862 For a duplex printer, the `ps-spool-*' and `ps-print-*' commands will insert
1863 blank pages as needed between print jobs so that the next buffer printed will
1864 start on the right page. Also, if headers are turned on, the headers will be
1865 reversed on duplex printers so that the page numbers fall to the left on
1866 even-numbered pages.
1868 See also `ps-spool-tumble'."
1870 :group 'ps-print-headers)
1872 (defcustom ps-spool-tumble nil
1873 "*Specify how the page images on opposite sides of a sheet are oriented.
1874 If `ps-spool-tumble' is nil, produces output suitable for binding on the left or
1875 right. If `ps-spool-tumble' is non-nil, produces output suitable for binding at
1878 It has effect only when `ps-spool-duplex' is non-nil."
1880 :group 'ps-print-headers)
1884 (defcustom ps-font-info-database
1885 '((Courier ; the family key
1886 (fonts (normal . "Courier")
1887 (bold . "Courier-Bold")
1888 (italic . "Courier-Oblique")
1889 (bold-italic . "Courier-BoldOblique"))
1891 (line-height . 10.55)
1893 (avg-char-width . 6.0))
1894 (Helvetica ; the family key
1895 (fonts (normal . "Helvetica")
1896 (bold . "Helvetica-Bold")
1897 (italic . "Helvetica-Oblique")
1898 (bold-italic . "Helvetica-BoldOblique"))
1900 (line-height . 11.56)
1901 (space-width . 2.78)
1902 (avg-char-width . 5.09243))
1904 (fonts (normal . "Times-Roman")
1905 (bold . "Times-Bold")
1906 (italic . "Times-Italic")
1907 (bold-italic . "Times-BoldItalic"))
1909 (line-height . 11.0)
1911 (avg-char-width . 4.71432))
1913 (fonts (normal . "Palatino-Roman")
1914 (bold . "Palatino-Bold")
1915 (italic . "Palatino-Italic")
1916 (bold-italic . "Palatino-BoldItalic"))
1918 (line-height . 12.1)
1920 (avg-char-width . 5.08676))
1922 (fonts (normal . "Helvetica-Narrow")
1923 (bold . "Helvetica-Narrow-Bold")
1924 (italic . "Helvetica-Narrow-Oblique")
1925 (bold-italic . "Helvetica-Narrow-BoldOblique"))
1927 (line-height . 11.56)
1928 (space-width . 2.2796)
1929 (avg-char-width . 4.17579))
1931 (fonts (normal . "NewCenturySchlbk-Roman")
1932 (bold . "NewCenturySchlbk-Bold")
1933 (italic . "NewCenturySchlbk-Italic")
1934 (bold-italic . "NewCenturySchlbk-BoldItalic"))
1936 (line-height . 12.15)
1937 (space-width . 2.78)
1938 (avg-char-width . 5.31162))
1939 ;; got no bold for the next ones
1941 (fonts (normal . "AvantGarde-Book")
1942 (italic . "AvantGarde-BookOblique"))
1944 (line-height . 11.77)
1945 (space-width . 2.77)
1946 (avg-char-width . 5.45189))
1948 (fonts (normal . "AvantGarde-Demi")
1949 (italic . "AvantGarde-DemiOblique"))
1951 (line-height . 12.72)
1953 (avg-char-width . 5.51351))
1955 (fonts (normal . "Bookman-Demi")
1956 (italic . "Bookman-DemiItalic"))
1958 (line-height . 11.77)
1960 (avg-char-width . 6.05946))
1962 (fonts (normal . "Bookman-Light")
1963 (italic . "Bookman-LightItalic"))
1965 (line-height . 11.79)
1967 (avg-char-width . 5.67027))
1968 ;; got no bold and no italic for the next ones
1970 (fonts (normal . "Symbol"))
1972 (line-height . 13.03)
1974 (avg-char-width . 3.24324))
1976 (fonts (normal . "Zapf-Dingbats"))
1978 (line-height . 9.63)
1979 (space-width . 2.78)
1980 (avg-char-width . 2.78))
1981 (Zapf-Chancery-MediumItalic
1982 (fonts (normal . "Zapf-Chancery-MediumItalic"))
1984 (line-height . 11.45)
1986 (avg-char-width . 4.10811))
1988 "*Font info database: font family (the key), name, bold, italic, bold-italic,
1989 reference size, line height, space width, average character width.
1990 To get the info for another specific font (say Helvetica), do the following:
1991 - create a new buffer
1992 - generate the PostScript image to a file (C-u M-x ps-print-buffer)
1993 - open this file and delete the leading `%' (which is the PostScript
1994 comment character) from the line
1995 `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
1997 `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
1998 - add the values to `ps-font-info-database'.
1999 You can get all the fonts of YOUR printer using `ReportAllFontInfo'."
2000 :type '(repeat (list :tag "Font Definition"
2001 (symbol :tag "Font Family")
2003 (const :format "" fonts)
2004 (repeat :tag "Faces"
2005 (cons (choice (const normal)
2009 (symbol :tag "Face"))
2010 (string :tag "Font Name"))))
2012 (const :format "" size)
2013 (number :tag "Reference Size"))
2015 (const :format "" line-height)
2016 (number :tag "Line Height"))
2018 (const :format "" space-width)
2019 (number :tag "Space Width"))
2021 (const :format "" avg-char-width)
2022 (number :tag "Average Character Width"))))
2023 :group 'ps-print-font)
2025 (defcustom ps-font-family 'Courier
2026 "*Font family name for ordinary text, when generating PostScript."
2028 :group 'ps-print-font)
2030 (defcustom ps-font-size '(7 . 8.5)
2031 "*Font size, in points, for ordinary text, when generating PostScript."
2032 :type '(choice (number :tag "Text Size")
2033 (cons :tag "Landscape/Portrait"
2034 (number :tag "Landscape Text Size")
2035 (number :tag "Portrait Text Size")))
2036 :group 'ps-print-font)
2038 (defcustom ps-header-font-family 'Helvetica
2039 "*Font family name for text in the header, when generating PostScript."
2041 :group 'ps-print-font)
2043 (defcustom ps-header-font-size '(10 . 12)
2044 "*Font size, in points, for text in the header, when generating PostScript."
2045 :type '(choice (number :tag "Header Size")
2046 (cons :tag "Landscape/Portrait"
2047 (number :tag "Landscape Header Size")
2048 (number :tag "Portrait Header Size")))
2049 :group 'ps-print-font)
2051 (defcustom ps-header-title-font-size '(12 . 14)
2052 "*Font size, in points, for the top line of text in header, in PostScript."
2053 :type '(choice (number :tag "Header Title Size")
2054 (cons :tag "Landscape/Portrait"
2055 (number :tag "Landscape Header Title Size")
2056 (number :tag "Portrait Header Title Size")))
2057 :group 'ps-print-font)
2061 ;; Printing color requires x-color-values.
2062 (defcustom ps-print-color-p (or (fboundp 'x-color-values) ; Emacs
2063 (fboundp 'color-instance-rgb-components))
2065 "*Non-nil means print the buffer's text in color."
2067 :group 'ps-print-color)
2069 (defcustom ps-default-fg '(0.0 0.0 0.0)
2070 "*RGB values of the default foreground color. Defaults to black."
2071 :type '(choice :tag "Default Foreground Gray/Color"
2072 (number :tag "Gray Scale" :value 0.0)
2073 (string :tag "Color Name" :value "black")
2074 (list :tag "RGB Color" :value (0.0 0.0 0.0)
2076 (number :tag "Green")
2077 (number :tag "Blue")))
2078 :group 'ps-print-color)
2080 (defcustom ps-default-bg '(1.0 1.0 1.0)
2081 "*RGB values of the default background color. Defaults to white."
2082 :type '(choice :tag "Default Background Gray/Color"
2083 (number :tag "Gray Scale" :value 1.0)
2084 (string :tag "Color Name" :value "white")
2085 (list :tag "RGB Color" :value (1.0 1.0 1.0)
2087 (number :tag "Green")
2088 (number :tag "Blue")))
2089 :group 'ps-print-color)
2091 (defcustom ps-auto-font-detect t
2092 "*Non-nil means automatically detect bold/italic face attributes.
2093 If nil, we rely solely on the lists `ps-bold-faces', `ps-italic-faces',
2094 and `ps-underlined-faces'."
2096 :group 'ps-print-font)
2098 (defcustom ps-bold-faces
2099 (unless ps-print-color-p
2100 '(font-lock-function-name-face
2101 font-lock-builtin-face
2102 font-lock-variable-name-face
2103 font-lock-keyword-face
2104 font-lock-warning-face))
2105 "*A list of the \(non-bold\) faces that should be printed in bold font.
2106 This applies to generating PostScript."
2107 :type '(repeat face)
2108 :group 'ps-print-face)
2110 (defcustom ps-italic-faces
2111 (unless ps-print-color-p
2112 '(font-lock-variable-name-face
2114 font-lock-string-face
2115 font-lock-comment-face
2116 font-lock-warning-face))
2117 "*A list of the \(non-italic\) faces that should be printed in italic font.
2118 This applies to generating PostScript."
2119 :type '(repeat face)
2120 :group 'ps-print-face)
2122 (defcustom ps-underlined-faces
2123 (unless ps-print-color-p
2124 '(font-lock-function-name-face
2125 font-lock-constant-face
2126 font-lock-warning-face))
2127 "*A list of the \(non-underlined\) faces that should be printed underlined.
2128 This applies to generating PostScript."
2129 :type '(repeat face)
2130 :group 'ps-print-face)
2132 (defcustom ps-use-face-background nil
2133 "*Specify if face background should be used.
2137 t always use face background color.
2138 nil never use face background color.
2139 (face...) list of faces whose background color will be used.
2141 Any other value will be treated as t."
2142 :type '(choice :tag "Use Face Background"
2143 (const :tag "Always Use Face Background" t)
2144 (const :tag "Never Use Face Background" nil)
2145 (repeat :menu-tag "Face Background List"
2146 :tag "Face Background List"
2148 :group 'ps-print-face)
2150 (defcustom ps-left-header
2151 (list 'ps-get-buffer-name 'ps-header-dirpart)
2152 "*The items to display (each on a line) on the left part of the page header.
2153 This applies to generating PostScript.
2155 The value should be a list of strings and symbols, each representing an
2156 entry in the PostScript array HeaderLinesLeft.
2158 Strings are inserted unchanged into the array; those representing
2159 PostScript string literals should be delimited with PostScript string
2160 delimiters '(' and ')'.
2162 For symbols with bound functions, the function is called and should
2163 return a string to be inserted into the array. For symbols with bound
2164 values, the value should be a string to be inserted into the array.
2165 In either case, function or variable, the string value has PostScript
2166 string delimiters added to it."
2167 :type '(repeat (choice string symbol))
2168 :group 'ps-print-headers)
2170 (defcustom ps-right-header
2171 (list "/pagenumberstring load" 'time-stamp-mon-dd-yyyy 'time-stamp-hh:mm:ss)
2172 "*The items to display (each on a line) on the right part of the page header.
2173 This applies to generating PostScript.
2175 See the variable `ps-left-header' for a description of the format of
2177 :type '(repeat (choice string symbol))
2178 :group 'ps-print-headers)
2180 (defcustom ps-razzle-dazzle t
2181 "*Non-nil means report progress while formatting buffer."
2183 :group 'ps-print-miscellany)
2185 (defcustom ps-adobe-tag "%!PS-Adobe-3.0\n"
2186 "*Contains the header line identifying the output as PostScript.
2187 By default, `ps-adobe-tag' contains the standard identifier. Some
2188 printers require slightly different versions of this line."
2190 :group 'ps-print-miscellany)
2192 (defcustom ps-build-face-reference t
2193 "*Non-nil means build the reference face lists.
2195 ps-print sets this value to nil after it builds its internal reference
2196 lists of bold and italic faces. By settings its value back to t, you
2197 can force ps-print to rebuild the lists the next time you invoke one
2198 of the ...-with-faces commands.
2200 You should set this value back to t after you change the attributes of
2201 any face, or create new faces. Most users shouldn't have to worry
2202 about its setting, though."
2204 :group 'ps-print-face)
2206 (defcustom ps-always-build-face-reference nil
2207 "*Non-nil means always rebuild the reference face lists.
2209 If this variable is non-nil, ps-print will rebuild its internal
2210 reference lists of bold and italic faces *every* time one of the
2211 ...-with-faces commands is called. Most users shouldn't need to set this
2214 :group 'ps-print-face)
2216 (defcustom ps-banner-page-when-duplexing nil
2217 "*Non-nil means the very first page is skipped.
2218 It's like the very first character of buffer (or region) is ^L (\\014)."
2220 :group 'ps-print-headers)
2222 (defcustom ps-postscript-code-directory data-directory
2223 "*Directory where it's located the PostScript prologue file used by ps-print.
2224 By default, this directory is the same as in the variable `data-directory'."
2226 :group 'ps-print-miscellany)
2229 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2234 (defun ps-print-customize ()
2235 "Customization of ps-print group."
2237 (customize-group 'ps-print))
2240 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2245 (defun ps-print-buffer (&optional filename)
2246 "Generate and print a PostScript image of the buffer.
2248 Interactively, when you use a prefix argument (C-u), the command
2249 prompts the user for a file name, and saves the PostScript image
2250 in that file instead of sending it to the printer.
2252 Noninteractively, the argument FILENAME is treated as follows: if it
2253 is nil, send the image to the printer. If FILENAME is a string, save
2254 the PostScript image in a file with that name."
2255 (interactive (list (ps-print-preprint current-prefix-arg)))
2256 (ps-print-without-faces (point-min) (point-max) filename))
2260 (defun ps-print-buffer-with-faces (&optional filename)
2261 "Generate and print a PostScript image of the buffer.
2262 Like `ps-print-buffer', but includes font, color, and underline
2263 information in the generated image. This command works only if you
2264 are using a window system, so it has a way to determine color values."
2265 (interactive (list (ps-print-preprint current-prefix-arg)))
2266 (ps-print-with-faces (point-min) (point-max) filename))
2270 (defun ps-print-region (from to &optional filename)
2271 "Generate and print a PostScript image of the region.
2272 Like `ps-print-buffer', but prints just the current region."
2273 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
2274 (ps-print-without-faces from to filename t))
2278 (defun ps-print-region-with-faces (from to &optional filename)
2279 "Generate and print a PostScript image of the region.
2280 Like `ps-print-region', but includes font, color, and underline
2281 information in the generated image. This command works only if you
2282 are using a window system, so it has a way to determine color values."
2283 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
2284 (ps-print-with-faces from to filename t))
2288 (defun ps-spool-buffer ()
2289 "Generate and spool a PostScript image of the buffer.
2290 Like `ps-print-buffer' except that the PostScript image is saved in a
2291 local buffer to be sent to the printer later.
2293 Use the command `ps-despool' to send the spooled images to the printer."
2295 (ps-spool-without-faces (point-min) (point-max)))
2299 (defun ps-spool-buffer-with-faces ()
2300 "Generate and spool a PostScript image of the buffer.
2301 Like `ps-spool-buffer', but includes font, color, and underline
2302 information in the generated image. This command works only if you
2303 are using a window system, so it has a way to determine color values.
2305 Use the command `ps-despool' to send the spooled images to the printer."
2307 (ps-spool-with-faces (point-min) (point-max)))
2311 (defun ps-spool-region (from to)
2312 "Generate a PostScript image of the region and spool locally.
2313 Like `ps-spool-buffer', but spools just the current region.
2315 Use the command `ps-despool' to send the spooled images to the printer."
2317 (ps-spool-without-faces from to t))
2321 (defun ps-spool-region-with-faces (from to)
2322 "Generate a PostScript image of the region and spool locally.
2323 Like `ps-spool-region', but includes font, color, and underline
2324 information in the generated image. This command works only if you
2325 are using a window system, so it has a way to determine color values.
2327 Use the command `ps-despool' to send the spooled images to the printer."
2329 (ps-spool-with-faces from to t))
2332 (defun ps-despool (&optional filename)
2333 "Send the spooled PostScript to the printer.
2335 Interactively, when you use a prefix argument (C-u), the command
2336 prompts the user for a file name, and saves the spooled PostScript
2337 image in that file instead of sending it to the printer.
2339 Noninteractively, the argument FILENAME is treated as follows: if it
2340 is nil, send the image to the printer. If FILENAME is a string, save
2341 the PostScript image in a file with that name."
2342 (interactive (list (ps-print-preprint current-prefix-arg)))
2343 (ps-do-despool filename))
2346 (defun ps-line-lengths ()
2347 "Display the correspondence between a line length and a font size,
2348 using the current ps-print setup.
2349 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2351 (ps-line-lengths-internal))
2354 (defun ps-nb-pages-buffer (nb-lines)
2355 "Display number of pages to print this buffer, for various font heights.
2356 The table depends on the current ps-print setup."
2357 (interactive (list (count-lines (point-min) (point-max))))
2358 (ps-nb-pages nb-lines))
2361 (defun ps-nb-pages-region (nb-lines)
2362 "Display number of pages to print the region, for various font heights.
2363 The table depends on the current ps-print setup."
2364 (interactive (list (count-lines (mark) (point))))
2365 (ps-nb-pages nb-lines))
2369 "Return the current PostScript-generation setup."
2372 \(setq ps-print-color-p %s
2376 ps-print-region-function %s
2379 ps-landscape-mode %s
2380 ps-print-upside-down %s
2381 ps-number-of-columns %s
2384 ps-zebra-stripe-height %s
2387 ps-line-number-step %s
2392 ps-use-face-background %s
2394 ps-print-control-characters %s
2396 ps-print-background-image %s
2398 ps-print-background-text %s
2400 ps-error-handler-message %s
2401 ps-user-defined-prologue %s
2402 ps-print-prologue-header %s
2410 ps-header-line-pad %s
2412 ps-print-only-one-header %s
2413 ps-print-header-frame %s
2419 ps-banner-page-when-duplexing %s
2426 ps-multibyte-buffer %s
2429 ps-header-font-family %s
2430 ps-header-font-size %s
2431 ps-header-title-font-size %s)
2435 (ps-print-quote ps-lpr-switches)
2437 (ps-print-quote ps-print-region-function)
2438 (ps-print-quote ps-paper-type)
2440 ps-print-upside-down
2441 ps-number-of-columns
2443 ps-zebra-stripe-height
2444 (ps-print-quote ps-zebra-color)
2446 (ps-print-quote ps-line-number-step)
2447 (ps-print-quote ps-default-fg)
2448 (ps-print-quote ps-default-bg)
2449 (ps-print-quote ps-use-face-background)
2450 (ps-print-quote ps-print-control-characters)
2451 (ps-print-quote ps-print-background-image)
2452 (ps-print-quote ps-print-background-text)
2453 (ps-print-quote ps-error-handler-message)
2454 (ps-print-quote ps-user-defined-prologue)
2455 (ps-print-quote ps-print-prologue-header)
2464 ps-print-only-one-header
2465 ps-print-header-frame
2468 (ps-print-quote ps-spool-config)
2471 ps-banner-page-when-duplexing
2475 (ps-print-quote ps-n-up-filling)
2476 (ps-print-quote ps-multibyte-buffer) ; see `ps-mule.el'
2477 (ps-print-quote ps-font-family)
2478 (ps-print-quote ps-font-size)
2479 (ps-print-quote ps-header-font-family)
2480 (ps-print-quote ps-header-font-size)
2481 (ps-print-quote ps-header-title-font-size)))
2484 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2485 ;; Utility functions and variables:
2488 (defun ps-print-quote (sym)
2491 ((or (symbolp sym) (listp sym))
2498 (defvar ps-print-emacs-type
2499 (cond ((string-match "XEmacs" emacs-version) 'xemacs)
2500 ((string-match "Lucid" emacs-version) 'lucid)
2501 ((string-match "Epoch" emacs-version) 'epoch)
2504 (if (or (eq ps-print-emacs-type 'lucid)
2505 (eq ps-print-emacs-type 'xemacs))
2506 (if (< emacs-minor-version 12)
2507 (setq ps-print-color-p nil))
2508 (require 'faces)) ; face-font, face-underline-p,
2511 ;; Return t if the device (which can be changed during an emacs session)
2512 ;; can handle colors.
2513 ;; This is function is not yet implemented for GNU emacs.
2514 (cond ((and (eq ps-print-emacs-type 'xemacs)
2515 (>= emacs-minor-version 12)) ; xemacs
2516 (defun ps-color-device ()
2517 (eq (device-class) 'color))
2521 (defun ps-color-device ()
2526 (require 'time-stamp)
2529 (defun ps-prologue-file (filenumber)
2531 (let* ((filename (format "%sps-prin%d.ps"
2532 ps-postscript-code-directory filenumber))
2534 (or (find-file-noselect filename 'no-warn 'rawfile)
2535 (error "ps-print PostScript prologue `%s' file was not found."
2540 (kill-buffer buffer)))))
2543 (defvar ps-mark-code-directory nil)
2545 (defvar ps-print-prologue-0 ""
2546 "ps-print PostScript error handler.")
2548 (defvar ps-print-prologue-1 ""
2549 "ps-print PostScript prologue begin.")
2551 (defvar ps-print-prologue-2 ""
2552 "ps-print PostScript prologue end.")
2554 (defvar ps-print-duplex-feature ""
2555 "ps-print PostScript duplex feature.")
2557 ;; Start Editing Here:
2559 (defvar ps-source-buffer nil)
2560 (defvar ps-spool-buffer-name "*PostScript*")
2561 (defvar ps-spool-buffer nil)
2563 (defvar ps-output-head nil)
2564 (defvar ps-output-tail nil)
2566 (defvar ps-page-postscript 0)
2567 (defvar ps-page-order 0)
2568 (defvar ps-page-count 0)
2569 (defvar ps-showline-count 1)
2571 (defvar ps-control-or-escape-regexp nil)
2573 (defvar ps-background-pages nil)
2574 (defvar ps-background-all-pages nil)
2575 (defvar ps-background-text-count 0)
2576 (defvar ps-background-image-count 0)
2578 (defvar ps-current-font 0)
2579 (defvar ps-default-foreground nil)
2580 (defvar ps-default-color nil)
2581 (defvar ps-current-color nil)
2582 (defvar ps-current-bg nil)
2584 (defvar ps-razchunk 0)
2586 (defvar ps-color-p nil)
2587 (defvar ps-color-format
2588 (if (eq ps-print-emacs-type 'emacs)
2590 ;; Emacs understands the %f format; we'll use it to limit color RGB
2591 ;; values to three decimals to cut down some on the size of the
2592 ;; PostScript output.
2595 ;; Lucid emacsen will have to make do with %s (princ) for floats.
2598 ;; These values determine how much print-height to deduct when headers
2599 ;; are turned on. This is a pretty clumsy way of handling it, but
2600 ;; it'll do for now.
2602 (defvar ps-header-pad 0
2603 "Vertical and horizontal space between the header frame and the text.
2604 This is in units of points (1/72 inch).")
2606 ;; Define accessors to the dimensions list.
2608 (defmacro ps-page-dimensions-get-width (dims) `(nth 0 ,dims))
2609 (defmacro ps-page-dimensions-get-height (dims) `(nth 1 ,dims))
2610 (defmacro ps-page-dimensions-get-media (dims) `(nth 2 ,dims))
2612 (defvar ps-landscape-page-height nil)
2614 (defvar ps-print-width nil)
2615 (defvar ps-print-height nil)
2617 (defvar ps-height-remaining nil)
2618 (defvar ps-width-remaining nil)
2620 (defvar ps-print-color-scale nil)
2622 (defvar ps-font-size-internal nil)
2623 (defvar ps-header-font-size-internal nil)
2624 (defvar ps-header-title-font-size-internal nil)
2627 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2628 ;; Internal Variables
2631 (defvar ps-print-face-extension-alist nil
2632 "Alist of symbolic faces *WITH* extension features (box, outline, etc).
2633 An element of this list has the following form:
2635 (FACE . [BITS FG BG])
2637 FACE is a symbol denoting a face name
2638 BITS is a bit vector, where each bit correspond
2639 to a feature (bold, underline, etc)
2640 (see documentation for `ps-print-face-map-alist')
2641 FG foreground color (string or nil)
2642 BG background color (string or nil)
2644 Don't change this list directly; instead,
2645 use `ps-extend-face' and `ps-extend-face-list'.
2646 See documentation for `ps-extend-face' for valid extension symbol.")
2649 (defvar ps-print-face-alist nil
2650 "Alist of symbolic faces *WITHOUT* extension features (box, outline, etc).
2652 An element of this list has the same form as an element of
2653 `ps-print-face-extension-alist'.
2655 Don't change this list directly; this list is used by `ps-face-attributes',
2656 `ps-map-face' and `ps-build-reference-face-lists'.")
2659 (defconst ps-print-face-map-alist
2668 "Alist of all features and the corresponding bit mask.
2669 Each symbol correspond to one bit in a bit vector.")
2672 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2677 (defun ps-extend-face-list (face-extension-list &optional merge-p)
2678 "Extend face in `ps-print-face-extension-alist'.
2680 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION-LIST are merged
2681 with face extension in `ps-print-face-extension-alist'; otherwise, overrides.
2683 The elements in FACE-EXTENSION-LIST is like those for `ps-extend-face'.
2685 See `ps-extend-face' for documentation."
2686 (while face-extension-list
2687 (ps-extend-face (car face-extension-list) merge-p)
2688 (setq face-extension-list (cdr face-extension-list))))
2692 (defun ps-extend-face (face-extension &optional merge-p)
2693 "Extend face in `ps-print-face-extension-alist'.
2695 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION list are merged
2696 with face extensions in `ps-print-face-extension-alist'; otherwise, overrides.
2698 The elements of FACE-EXTENSION list have the form:
2700 (FACE-NAME FOREGROUND BACKGROUND EXTENSION...)
2702 FACE-NAME is a face name symbol.
2704 FOREGROUND and BACKGROUND may be nil or a string that denotes the
2705 foreground and background colors respectively.
2707 EXTENSION is one of the following symbols:
2708 bold - use bold font.
2709 italic - use italic font.
2710 underline - put a line under text.
2711 strikeout - like underline, but the line is in middle of text.
2712 overline - like underline, but the line is over the text.
2713 shadow - text will have a shadow.
2714 box - text will be surrounded by a box.
2715 outline - print characters as hollow outlines.
2717 If EXTENSION is any other symbol, it is ignored."
2718 (let* ((face-name (nth 0 face-extension))
2719 (foreground (nth 1 face-extension))
2720 (background (nth 2 face-extension))
2721 (ps-face (cdr (assq face-name ps-print-face-extension-alist)))
2722 (face-vector (or ps-face (vector 0 nil nil)))
2723 (face-bit (ps-extension-bit face-extension)))
2725 (aset face-vector 0 (if merge-p
2726 (logior (aref face-vector 0) face-bit)
2728 (and foreground (stringp foreground) (aset face-vector 1 foreground))
2729 (and background (stringp background) (aset face-vector 2 background))
2730 ;; if face does not exist, insert it
2732 (setq ps-print-face-extension-alist
2733 (cons (cons face-name face-vector)
2734 ps-print-face-extension-alist)))))
2737 (defun ps-extension-bit (face-extension)
2739 ;; map valid symbol extension to bit vector
2740 (setq face-extension (cdr (cdr face-extension)))
2741 (while (setq face-extension (cdr face-extension))
2742 (setq face-bit (logior face-bit
2743 (or (cdr (assq (car face-extension)
2744 ps-print-face-map-alist))
2749 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2750 ;; Adapted from font-lock: (obsolete stuff)
2751 ;; Originally face attributes were specified via `font-lock-face-attributes'.
2752 ;; Users then changed the default face attributes by setting that variable.
2753 ;; However, we try and be back-compatible and respect its value if set except
2754 ;; for faces where M-x customize has been used to save changes for the face.
2757 (defun ps-font-lock-face-attributes ()
2758 (and (boundp 'font-lock-mode) (symbol-value 'font-lock-mode)
2759 (boundp 'font-lock-face-attributes)
2760 (let ((face-attributes font-lock-face-attributes))
2761 (while face-attributes
2762 (let* ((face-attribute
2763 (car (prog1 face-attributes
2764 (setq face-attributes (cdr face-attributes)))))
2765 (face (car face-attribute)))
2766 ;; Rustle up a `defface' SPEC from a
2767 ;; `font-lock-face-attributes' entry.
2768 (unless (get face 'saved-face)
2769 (let ((foreground (nth 1 face-attribute))
2770 (background (nth 2 face-attribute))
2771 (bold-p (nth 3 face-attribute))
2772 (italic-p (nth 4 face-attribute))
2773 (underline-p (nth 5 face-attribute))
2776 (setq face-spec (cons ':foreground
2777 (cons foreground face-spec))))
2779 (setq face-spec (cons ':background
2780 (cons background face-spec))))
2782 (setq face-spec (append '(:bold t) face-spec)))
2784 (setq face-spec (append '(:italic t) face-spec)))
2786 (setq face-spec (append '(:underline t) face-spec)))
2787 (custom-declare-face face (list (list t face-spec)) nil)
2791 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2792 ;; Internal functions and variables
2795 (make-local-hook 'ps-print-hook)
2796 (make-local-hook 'ps-print-begin-sheet-hook)
2797 (make-local-hook 'ps-print-begin-page-hook)
2798 (make-local-hook 'ps-print-begin-column-hook)
2801 (defun ps-print-without-faces (from to &optional filename region-p)
2802 (ps-spool-without-faces from to region-p)
2803 (ps-do-despool filename))
2806 (defun ps-spool-without-faces (from to &optional region-p)
2807 (run-hooks 'ps-print-hook)
2808 (ps-printing-region region-p from)
2809 (ps-generate (current-buffer) from to 'ps-generate-postscript))
2812 (defun ps-print-with-faces (from to &optional filename region-p)
2813 (ps-spool-with-faces from to region-p)
2814 (ps-do-despool filename))
2817 (defun ps-spool-with-faces (from to &optional region-p)
2818 (run-hooks 'ps-print-hook)
2819 (ps-printing-region region-p from)
2820 (ps-generate (current-buffer) from to 'ps-generate-postscript-with-faces))
2823 (defun ps-count-lines (from to)
2824 (+ (count-lines from to)
2827 (if (= (current-column) 0) 1 0))))
2830 (defvar ps-printing-region nil
2831 "Variable used to indicate if the region that ps-print is printing.
2832 It is a cons, the car of which is the line number where the region begins, and
2833 its cdr is the total number of lines in the buffer. Formatting functions can
2834 use this information to print the original line number (and not the number of
2835 lines printed), and to indicate in the header that the printout is of a partial
2839 (defvar ps-printing-region-p nil
2840 "Non-nil means ps-print is printing a region.")
2843 (defun ps-printing-region (region-p from)
2844 (setq ps-printing-region-p region-p
2847 (ps-count-lines (point-min) from)
2849 (ps-count-lines (point-min) (point-max)))))
2852 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2853 ;; Internal functions
2856 (defsubst ps-font-alist (font-sym)
2857 (get font-sym 'fonts))
2859 (defun ps-font (font-sym font-type)
2860 "Font family name for text of `font-type', when generating PostScript."
2861 (let* ((font-list (ps-font-alist font-sym))
2862 (normal-font (cdr (assq 'normal font-list))))
2863 (while (and font-list (not (eq font-type (car (car font-list)))))
2864 (setq font-list (cdr font-list)))
2865 (or (cdr (car font-list)) normal-font)))
2867 (defun ps-fonts (font-sym)
2868 (mapcar 'cdr (ps-font-alist font-sym)))
2870 (defun ps-font-number (font-sym font-type)
2871 (or (ps-alist-position font-type (ps-font-alist font-sym))
2874 (defsubst ps-line-height (font-sym)
2875 "The height of a line, for generating PostScript.
2876 This is the value that ps-print uses to determine the height,
2877 y-dimension, of the lines of text it has printed, and thus affects the
2878 point at which page-breaks are placed.
2879 The line-height is *not* the same as the point size of the font."
2880 (get font-sym 'line-height))
2882 (defsubst ps-title-line-height (font-sym)
2883 "The height of a `title' line, for generating PostScript.
2884 This is the value that ps-print uses to determine the height,
2885 y-dimension, of the lines of text it has printed, and thus affects the
2886 point at which page-breaks are placed.
2887 The title-line-height is *not* the same as the point size of the font."
2888 (get font-sym 'title-line-height))
2890 (defsubst ps-space-width (font-sym)
2891 "The width of a space character, for generating PostScript.
2892 This value is used in expanding tab characters."
2893 (get font-sym 'space-width))
2895 (defsubst ps-avg-char-width (font-sym)
2896 "The average width, in points, of a character, for generating PostScript.
2897 This is the value that ps-print uses to determine the length,
2898 x-dimension, of the text it has printed, and thus affects the point at
2899 which long lines wrap around."
2900 (get font-sym 'avg-char-width))
2902 (defun ps-line-lengths-internal ()
2903 "Display the correspondence between a line length and a font size,
2904 using the current ps-print setup.
2905 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2906 (let ((buf (get-buffer-create "*Line-lengths*"))
2907 (ifs ps-font-size-internal) ; initial font size
2908 (icw (ps-avg-char-width 'ps-font-for-text)) ; initial character width
2909 (print-width (progn (ps-get-page-dimensions)
2911 (ps-setup (ps-setup)) ; setup for the current buffer
2912 (fs-min 5) ; minimum font size
2913 cw-min ; minimum character width
2914 nb-cpl-max ; maximum nb of characters per line
2915 (fs-max 14) ; maximum font size
2916 cw-max ; maximum character width
2917 nb-cpl-min ; minimum nb of characters per line
2918 fs ; current font size
2919 cw ; current character width
2920 nb-cpl ; current nb of characters per line
2922 (setq cw-min (/ (* icw fs-min) ifs)
2923 nb-cpl-max (floor (/ print-width cw-min))
2924 cw-max (/ (* icw fs-max) ifs)
2925 nb-cpl-min (floor (/ print-width cw-max))
2928 (goto-char (point-max))
2929 (or (bolp) (insert "\n"))
2931 "nb char per line / font size\n")
2932 (while (<= nb-cpl nb-cpl-max)
2933 (setq cw (/ print-width (float nb-cpl))
2934 fs (/ (* ifs cw) icw))
2935 (insert (format "%3s %s\n" nb-cpl fs))
2936 (setq nb-cpl (1+ nb-cpl)))
2938 (display-buffer buf 'not-this-window)))
2940 (defun ps-nb-pages (nb-lines)
2941 "Display correspondence between font size and the number of pages.
2942 The correspondence is based on having NB-LINES lines of text,
2943 and on the current ps-print setup."
2944 (let ((buf (get-buffer-create "*Nb-Pages*"))
2945 (ifs ps-font-size-internal) ; initial font size
2946 (ilh (ps-line-height 'ps-font-for-text)) ; initial line height
2947 (page-height (progn (ps-get-page-dimensions)
2949 (ps-setup (ps-setup)) ; setup for the current buffer
2950 (fs-min 4) ; minimum font size
2951 lh-min ; minimum line height
2952 nb-lpp-max ; maximum nb of lines per page
2953 nb-page-min ; minimum nb of pages
2954 (fs-max 14) ; maximum font size
2955 lh-max ; maximum line height
2956 nb-lpp-min ; minimum nb of lines per page
2957 nb-page-max ; maximum nb of pages
2958 fs ; current font size
2959 lh ; current line height
2960 nb-lpp ; current nb of lines per page
2961 nb-page ; current nb of pages
2963 (setq lh-min (/ (* ilh fs-min) ifs)
2964 nb-lpp-max (floor (/ page-height lh-min))
2965 nb-page-min (ceiling (/ (float nb-lines) nb-lpp-max))
2966 lh-max (/ (* ilh fs-max) ifs)
2967 nb-lpp-min (floor (/ page-height lh-max))
2968 nb-page-max (ceiling (/ (float nb-lines) nb-lpp-min))
2969 nb-page nb-page-min)
2971 (goto-char (point-max))
2972 (or (bolp) (insert "\n"))
2974 (format "%d lines\n" nb-lines)
2975 "nb page / font size\n")
2976 (while (<= nb-page nb-page-max)
2977 (setq nb-lpp (ceiling (/ nb-lines (float nb-page)))
2978 lh (/ page-height nb-lpp)
2979 fs (/ (* ifs lh) ilh))
2980 (insert (format "%s %s\n" nb-page fs))
2981 (setq nb-page (1+ nb-page)))
2983 (display-buffer buf 'not-this-window)))
2985 ;; macros used in `ps-select-font'
2986 (defmacro ps-lookup (key) `(cdr (assq ,key font-entry)))
2987 (defmacro ps-size-scale (key) `(/ (* (ps-lookup ,key) font-size) size))
2989 (defun ps-select-font (font-family sym font-size title-font-size)
2990 (let ((font-entry (cdr (assq font-family ps-font-info-database))))
2992 (error "Don't have data to scale font %s. Known fonts families are %s"
2994 (mapcar 'car ps-font-info-database)))
2995 (let ((size (ps-lookup 'size)))
2996 (put sym 'fonts (ps-lookup 'fonts))
2997 (put sym 'space-width (ps-size-scale 'space-width))
2998 (put sym 'avg-char-width (ps-size-scale 'avg-char-width))
2999 (put sym 'line-height (ps-size-scale 'line-height))
3000 (put sym 'title-line-height
3001 (/ (* (ps-lookup 'line-height) title-font-size) size)))))
3003 (defun ps-get-page-dimensions ()
3004 (let ((page-dimensions (cdr (assq ps-paper-type ps-page-dimensions-database)))
3005 page-width page-height)
3007 ((null page-dimensions)
3008 (error "`ps-paper-type' must be one of:\n%s"
3009 (mapcar 'car ps-page-dimensions-database)))
3010 ((< ps-number-of-columns 1)
3011 (error "The number of columns %d should be positive"
3012 ps-number-of-columns)))
3014 (ps-select-font ps-font-family 'ps-font-for-text
3015 ps-font-size-internal ps-font-size-internal)
3016 (ps-select-font ps-header-font-family 'ps-font-for-header
3017 ps-header-font-size-internal
3018 ps-header-title-font-size-internal)
3020 (setq page-width (ps-page-dimensions-get-width page-dimensions)
3021 page-height (ps-page-dimensions-get-height page-dimensions))
3024 (if ps-landscape-mode
3025 ;; exchange width and height
3026 (setq page-width (prog1 page-height (setq page-height page-width))))
3028 ;; It is used to get the lower right corner (only in landscape mode)
3029 (setq ps-landscape-page-height page-height)
3031 ;; | lm | text | ic | text | ic | text | rm |
3032 ;; page-width == lm + n * pw + (n - 1) * ic + rm
3033 ;; => pw == (page-width - lm -rm - (n - 1) * ic) / n
3034 (setq ps-print-width (/ (- page-width
3035 ps-left-margin ps-right-margin
3036 (* (1- ps-number-of-columns) ps-inter-column))
3037 ps-number-of-columns))
3038 (if (<= ps-print-width 0)
3039 (error "Bad horizontal layout:
3041 ps-left-margin == %s
3042 ps-right-margin == %s
3043 ps-inter-column == %s
3044 ps-number-of-columns == %s
3045 | lm | text | ic | text | ic | text | rm |
3046 page-width == lm + n * print-width + (n - 1) * ic + rm
3047 => print-width == %d !"
3052 ps-number-of-columns
3055 (setq ps-print-height
3056 (- page-height ps-bottom-margin ps-top-margin))
3057 (if (<= ps-print-height 0)
3058 (error "Bad vertical layout:
3060 ps-bottom-margin == %s
3061 page-height == bm + print-height + tm
3062 => print-height == %d !"
3066 ;; If headers are turned on, deduct the height of the header from
3067 ;; the print height.
3069 (setq ps-header-pad (* ps-header-line-pad
3070 (ps-title-line-height 'ps-font-for-header))
3071 ps-print-height (- ps-print-height
3074 (ps-title-line-height 'ps-font-for-header)
3075 (* (ps-line-height 'ps-font-for-header)
3076 (1- ps-header-lines))
3078 (if (<= ps-print-height 0)
3079 (error "Bad vertical layout:
3081 ps-bottom-margin == %s
3082 ps-header-offset == %s
3085 page-height == bm + print-height + tm - ho - hh
3086 => print-height == %d !"
3092 (ps-title-line-height 'ps-font-for-header)
3093 (* (ps-line-height 'ps-font-for-header)
3094 (1- ps-header-lines))
3098 (defun ps-print-preprint (prefix-arg)
3100 (or (numberp prefix-arg)
3102 (let* ((name (concat (file-name-nondirectory (or (buffer-file-name)
3105 (prompt (format "Save PostScript to file: (default %s) " name))
3106 (res (read-file-name prompt default-directory name nil)))
3107 (while (cond ((not (file-writable-p res))
3109 (setq prompt "is unwritable"))
3110 ((file-exists-p res)
3111 (setq prompt "exists")
3112 (not (y-or-n-p (format "File `%s' exists; overwrite? "
3115 (setq res (read-file-name
3116 (format "File %s; save PostScript to file: " prompt)
3117 (file-name-directory res) nil nil
3118 (file-name-nondirectory res))))
3119 (if (file-directory-p res)
3120 (expand-file-name name (file-name-as-directory res))
3123 ;; The following functions implement a simple list-buffering scheme so
3124 ;; that ps-print doesn't have to repeatedly switch between buffers
3125 ;; while spooling. The functions `ps-output' and `ps-output-string' build
3126 ;; up the lists; the function `ps-flush-output' takes the lists and
3127 ;; insert its contents into the spool buffer (*PostScript*).
3129 (defvar ps-string-escape-codes
3130 (let ((table (make-vector 256 nil))
3132 ;; control characters
3133 (while (<= char ?\037)
3134 (aset table char (format "\\%03o" char))
3135 (setq char (1+ char)))
3136 ;; printable characters
3137 (while (< char ?\177)
3138 (aset table char (format "%c" char))
3139 (setq char (1+ char)))
3140 ;; DEL and 8-bit characters
3141 (while (<= char ?\377)
3142 (aset table char (format "\\%o" char))
3143 (setq char (1+ char)))
3144 ;; Override ASCII formatting characters with named escape code:
3145 (aset table ?\n "\\n") ; [NL] linefeed
3146 (aset table ?\r "\\r") ; [CR] carriage return
3147 (aset table ?\t "\\t") ; [HT] horizontal tab
3148 (aset table ?\b "\\b") ; [BS] backspace
3149 (aset table ?\f "\\f") ; [NP] form feed
3150 ;; Escape PostScript escape and string delimiter characters:
3151 (aset table ?\\ "\\\\")
3152 (aset table ?\( "\\(")
3153 (aset table ?\) "\\)")
3155 "Vector used to map characters to PostScript string escape codes.")
3157 (defun ps-output-string-prim (string)
3158 (insert "(") ;insert start-string delimiter
3159 (save-excursion ;insert string
3160 (insert (string-as-unibyte string)))
3161 ;; Find and quote special characters as necessary for PS
3162 ;; This skips everything except control chars, non-ASCII chars, (, ) and \.
3163 (while (progn (skip-chars-forward " -'*-[]-~") (not (eobp)))
3164 (let ((special (following-char)))
3166 (insert (aref ps-string-escape-codes special))))
3167 (goto-char (point-max))
3168 (insert ")")) ;insert end-string delimiter
3170 (defun ps-init-output-queue ()
3171 (setq ps-output-head '("")
3172 ps-output-tail ps-output-head))
3174 (defun ps-output (&rest args)
3175 (setcdr ps-output-tail args)
3176 (while (cdr ps-output-tail)
3177 (setq ps-output-tail (cdr ps-output-tail))))
3179 (defun ps-output-string (string)
3180 (ps-output t string))
3182 (defun ps-output-list (the-list)
3183 (mapcar 'ps-output the-list))
3185 ;; Output strings in the list ARGS in the PostScript prologue part.
3186 (defun ps-output-prologue (args)
3187 (ps-output 'prologue (if (stringp args) (list args) args)))
3189 (defun ps-flush-output ()
3191 (set-buffer ps-spool-buffer)
3192 (goto-char (point-max))
3193 (while ps-output-head
3194 (let ((it (car ps-output-head)))
3197 (setq ps-output-head (cdr ps-output-head))
3198 (ps-output-string-prim (car ps-output-head)))
3200 (setq ps-output-head (cdr ps-output-head))
3202 (search-backward "\nBeginDoc")
3204 (apply 'insert (car ps-output-head))))
3207 (setq ps-output-head (cdr ps-output-head))))
3208 (ps-init-output-queue))
3210 (defun ps-insert-file (fname)
3213 (set-buffer ps-spool-buffer)
3214 (goto-char (point-max))
3215 (insert-file fname)))
3217 ;; These functions insert the arrays that define the contents of the
3220 (defun ps-generate-header-line (fonttag &optional content)
3221 (ps-output " [ " fonttag " ")
3223 ;; Literal strings should be output as is -- the string must
3224 ;; contain its own PS string delimiters, '(' and ')', if necessary.
3226 (ps-output content))
3228 ;; Functions are called -- they should return strings; they will be
3229 ;; inserted as strings and the PS string delimiters added.
3230 ((and (symbolp content) (fboundp content))
3231 (ps-output-string (funcall content)))
3233 ;; Variables will have their contents inserted. They should
3234 ;; contain strings, and will be inserted as strings.
3235 ((and (symbolp content) (boundp content))
3236 (ps-output-string (symbol-value content)))
3238 ;; Anything else will get turned into an empty string.
3240 (ps-output-string "")))
3243 (defun ps-generate-header (name contents)
3244 (ps-output "/" name " [\n")
3245 (if (> ps-header-lines 0)
3247 (ps-generate-header-line "/h0" (car contents))
3248 (while (and (< count ps-header-lines)
3249 (setq contents (cdr contents)))
3250 (ps-generate-header-line "/h1" (car contents))
3251 (setq count (1+ count)))
3252 (ps-output "] def\n"))))
3255 (defun ps-output-boolean (name bool)
3256 (ps-output (format "/%s %s def\n" name (if bool "true" "false"))))
3259 (defun ps-background-pages (page-list func)
3263 (let ((start (if (consp pages) (car pages) pages))
3264 (end (if (consp pages) (cdr pages) pages)))
3265 (and (integerp start) (integerp end) (<= start end)
3266 (add-to-list 'ps-background-pages (vector start end func)))))
3268 (setq ps-background-all-pages (cons func ps-background-all-pages))))
3271 (defconst ps-boundingbox-re
3273 \\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)")
3276 (defun ps-get-boundingbox ()
3278 (set-buffer ps-spool-buffer)
3280 (if (re-search-forward ps-boundingbox-re nil t)
3281 (vector (string-to-number ; lower x
3282 (buffer-substring (match-beginning 1) (match-end 1)))
3283 (string-to-number ; lower y
3284 (buffer-substring (match-beginning 2) (match-end 2)))
3285 (string-to-number ; upper x
3286 (buffer-substring (match-beginning 3) (match-end 3)))
3287 (string-to-number ; upper y
3288 (buffer-substring (match-beginning 4) (match-end 4))))
3289 (vector 0 0 0 0)))))
3292 ;; Emacs understands the %f format; we'll use it to limit color RGB values
3293 ;; to three decimals to cut down some on the size of the PostScript output.
3294 ;; Lucid emacsen will have to make do with %s (princ) for floats.
3296 (defvar ps-float-format (if (eq ps-print-emacs-type 'emacs)
3298 "%s ")) ; Lucid emacsen
3301 (defun ps-float-format (value &optional default)
3302 (let ((literal (or value default)))
3304 (format (if (numberp literal)
3311 (defun ps-background-text ()
3314 (setq ps-background-text-count (1+ ps-background-text-count))
3315 (ps-output (format "/ShowBackText-%d {\n" ps-background-text-count))
3316 (ps-output-string (nth 0 text)) ; text
3319 (ps-float-format (nth 4 text) 200.0) ; font size
3320 (format "/%s " (or (nth 3 text) "Times-Roman")) ; font name
3321 (ps-float-format (nth 6 text)
3322 "PrintHeight PrintPageWidth atan") ; rotation
3323 (ps-float-format (nth 5 text) 0.85) ; gray
3324 (ps-float-format (nth 1 text) "0") ; x position
3325 (ps-float-format (nth 2 text) "BottomMargin") ; y position
3326 "\nShowBackText} def\n")
3327 (ps-background-pages (nthcdr 7 text) ; page list
3328 (format "ShowBackText-%d\n"
3329 ps-background-text-count)))
3330 ps-print-background-text))
3333 (defun ps-background-image ()
3336 (let ((image-file (expand-file-name (nth 0 image))))
3337 (when (file-readable-p image-file)
3338 (setq ps-background-image-count (1+ ps-background-image-count))
3340 (format "/ShowBackImage-%d {\n--back-- "
3341 ps-background-image-count)
3342 (ps-float-format (nth 5 image) 0.0) ; rotation
3343 (ps-float-format (nth 3 image) 1.0) ; x scale
3344 (ps-float-format (nth 4 image) 1.0) ; y scale
3345 (ps-float-format (nth 1 image) ; x position
3346 "PrintPageWidth 2 div")
3347 (ps-float-format (nth 2 image) ; y position
3348 "PrintHeight 2 div BottomMargin add")
3349 "\nBeginBackImage\n")
3350 (ps-insert-file image-file)
3351 ;; coordinate adjustment to centralize image
3352 ;; around x and y position
3353 (let ((box (ps-get-boundingbox)))
3355 (set-buffer ps-spool-buffer)
3357 (if (re-search-backward "^--back--" nil t)
3361 (- (+ (/ (- (aref box 2) (aref box 0)) 2.0)
3364 (- (+ (/ (- (aref box 3) (aref box 1)) 2.0)
3367 (ps-output "\nEndBackImage} def\n")
3368 (ps-background-pages (nthcdr 6 image) ; page list
3369 (format "ShowBackImage-%d\n"
3370 ps-background-image-count)))))
3371 ps-print-background-image))
3374 (defun ps-background (page-number)
3375 (let (has-local-background)
3376 (mapcar #'(lambda (range)
3377 (and (<= (aref range 0) page-number)
3378 (<= page-number (aref range 1))
3379 (if has-local-background
3380 (ps-output (aref range 2))
3381 (setq has-local-background t)
3382 (ps-output "/printLocalBackground {\n"
3384 ps-background-pages)
3385 (and has-local-background (ps-output "} def\n"))))
3388 ;; Return a list of the distinct elements of LIST.
3389 ;; Elements are compared with `equal'.
3390 (defun ps-remove-duplicates (list)
3391 (let (new (tail list))
3393 (or (member (car tail) new)
3394 (setq new (cons (car tail) new)))
3395 (setq tail (cdr tail)))
3399 ;; Find the first occurrence of ITEM in LIST.
3400 ;; Return the index of the matching item, or nil if not found.
3401 ;; Elements are compared with `eq'.
3402 (defun ps-alist-position (item list)
3403 (let ((tail list) (index 0) found)
3405 (if (setq found (eq (car (car tail)) item))
3407 (setq index (1+ index)
3412 (defconst ps-n-up-database
3549 ;; Ledger paper size is a special case, it is the only paper size where the
3550 ;; normal size is landscaped, that is, the height is smaller than width.
3551 ;; So, we use the special value `pag' in the `landscape' field.
3695 "Alist which is the page matrix database used for N-up printing.
3697 Each element has the following form:
3700 (MAX LANDSCAPE LINES COLUMNS COL-MISSING)
3704 PAGE is the page size used (see `ps-paper-type').
3705 MAX is the maximum elements of this page matrix.
3706 LANDSCAPE specifies if page matrix is landscaped, has the following valid
3708 nil the sheet is in portrait mode.
3709 t the sheet is in landscape mode.
3710 pag the sheet is in portrait mode and page is in landscape mode.
3711 LINES is the number of lines of page matrix.
3712 COLUMNS is the number of columns of page matrix.
3713 COL-MISSING is the number of columns missing to fill the sheet.")
3716 (defmacro ps-n-up-landscape (mat) `(nth 1 ,mat))
3717 (defmacro ps-n-up-lines (mat) `(nth 2 ,mat))
3718 (defmacro ps-n-up-columns (mat) `(nth 3 ,mat))
3719 (defmacro ps-n-up-missing (mat) `(nth 4 ,mat))
3722 (defun ps-n-up-printing ()
3723 ;; force `ps-n-up-printing' be in range 1 to 100.
3724 (setq ps-n-up-printing (max (min ps-n-up-printing 100) 1))
3725 ;; find suitable page matrix for a given `ps-paper-type'.
3726 (let ((the-list (cdr (assq ps-paper-type ps-n-up-database))))
3728 (while (> ps-n-up-printing (caar the-list))
3729 (setq the-list (cdr the-list))))
3733 (defconst ps-n-up-filling-database
3735 "PageWidth" ; N-Up-XColumn
3737 "N-Up-End 1 sub PageWidth mul neg" ; N-Up-XLine
3738 "LandscapePageHeight neg" ; N-Up-YLine
3739 "N-Up-Lines" ; N-Up-Repeat
3740 "N-Up-Columns" ; N-Up-End
3744 "PageWidth" ; N-Up-XColumn
3746 "N-Up-End 1 sub PageWidth mul neg" ; N-Up-XLine
3747 "LandscapePageHeight" ; N-Up-YLine
3748 "N-Up-Lines" ; N-Up-Repeat
3749 "N-Up-Columns" ; N-Up-End
3751 "N-Up-Repeat 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3753 "PageWidth neg" ; N-Up-XColumn
3755 "N-Up-End 1 sub PageWidth mul" ; N-Up-XLine
3756 "LandscapePageHeight neg" ; N-Up-YLine
3757 "N-Up-Lines" ; N-Up-Repeat
3758 "N-Up-Columns" ; N-Up-End
3759 "N-Up-End 1 sub PageWidth mul" ; N-Up-XStart
3762 "PageWidth neg" ; N-Up-XColumn
3764 "N-Up-End 1 sub PageWidth mul" ; N-Up-XLine
3765 "LandscapePageHeight" ; N-Up-YLine
3766 "N-Up-Lines" ; N-Up-Repeat
3767 "N-Up-Columns" ; N-Up-End
3768 "N-Up-End 1 sub PageWidth mul" ; N-Up-XStart
3769 "N-Up-Repeat 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3772 "LandscapePageHeight neg" ; N-Up-YColumn
3773 "PageWidth" ; N-Up-XLine
3774 "N-Up-End 1 sub LandscapePageHeight mul" ; N-Up-YLine
3775 "N-Up-Columns" ; N-Up-Repeat
3776 "N-Up-Lines" ; N-Up-End
3781 "LandscapePageHeight" ; N-Up-YColumn
3782 "PageWidth" ; N-Up-XLine
3783 "N-Up-End 1 sub LandscapePageHeight mul neg" ; N-Up-YLine
3784 "N-Up-Columns" ; N-Up-Repeat
3785 "N-Up-Lines" ; N-Up-End
3787 "N-Up-End 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3790 "LandscapePageHeight neg" ; N-Up-YColumn
3791 "PageWidth neg" ; N-Up-XLine
3792 "N-Up-End 1 sub LandscapePageHeight mul" ; N-Up-YLine
3793 "N-Up-Columns" ; N-Up-Repeat
3794 "N-Up-Lines" ; N-Up-End
3795 "N-Up-Repeat 1 sub PageWidth mul" ; N-Up-XStart
3799 "LandscapePageHeight" ; N-Up-YColumn
3800 "PageWidth neg" ; N-Up-XLine
3801 "N-Up-End 1 sub LandscapePageHeight mul neg" ; N-Up-YLine
3802 "N-Up-Columns" ; N-Up-Repeat
3803 "N-Up-Lines" ; N-Up-End
3804 "N-Up-Repeat 1 sub PageWidth mul" ; N-Up-XStart
3805 "N-Up-End 1 sub LandscapePageHeight mul neg")) ; N-Up-YStart
3806 "Alist for n-up printing initializations.
3808 Each element has the following form:
3810 (KIND XCOL YCOL XLIN YLIN REPEAT END XSTART YSTART)
3813 KIND is a valid value of `ps-n-up-filling'.
3814 XCOL YCOL are the relative position for the next column.
3815 XLIN YLIN are the relative position for the beginning of next line.
3816 REPEAT is the number of repetions for external loop.
3817 END is the number of repetions for internal loop and also the number of pages in
3819 XSTART YSTART are the relative position for the first page in a sheet.")
3822 (defun ps-n-up-filling ()
3823 (cdr (or (assq ps-n-up-filling ps-n-up-filling-database)
3824 (assq 'left-top ps-n-up-filling-database))))
3827 (defmacro ps-n-up-xcolumn (init) `(nth 0 ,init))
3828 (defmacro ps-n-up-ycolumn (init) `(nth 1 ,init))
3829 (defmacro ps-n-up-xline (init) `(nth 2 ,init))
3830 (defmacro ps-n-up-yline (init) `(nth 3 ,init))
3831 (defmacro ps-n-up-repeat (init) `(nth 4 ,init))
3832 (defmacro ps-n-up-end (init) `(nth 5 ,init))
3833 (defmacro ps-n-up-xstart (init) `(nth 6 ,init))
3834 (defmacro ps-n-up-ystart (init) `(nth 7 ,init))
3837 (defconst ps-error-handler-alist
3841 (paper-and-system . 3))
3842 "Alist for error handler message")
3845 (defun ps-begin-file ()
3846 (ps-get-page-dimensions)
3847 (setq ps-page-postscript 0
3849 ps-background-text-count 0
3850 ps-background-image-count 0
3851 ps-background-pages nil
3852 ps-background-all-pages nil)
3854 (let ((dimensions (cdr (assq ps-paper-type ps-page-dimensions-database)))
3855 (tumble (if ps-landscape-mode (not ps-spool-tumble) ps-spool-tumble))
3856 (n-up (ps-n-up-printing))
3857 (n-up-filling (ps-n-up-filling)))
3858 (and (> ps-n-up-printing 1) (setq tumble (not tumble)))
3861 "%%Title: " (buffer-name) ; Take job name from name of
3862 ; first buffer printed
3863 "\n%%Creator: " (user-full-name)
3864 " (using ps-print v" ps-print-version
3865 ")\n%%CreationDate: "
3866 (time-stamp-hh:mm:ss) " " (time-stamp-mon-dd-yyyy)
3868 (if ps-landscape-mode "Landscape" "Portrait")
3869 "\n%%DocumentNeededResources: font Times-Roman Times-Italic\n%%+ font "
3870 (mapconcat 'identity
3871 (ps-remove-duplicates
3872 (append (ps-fonts 'ps-font-for-text)
3873 (list (ps-font 'ps-font-for-header 'normal)
3874 (ps-font 'ps-font-for-header 'bold))))
3876 "\n%%DocumentMedia: " (ps-page-dimensions-get-media dimensions)
3877 (format " %d" (round (ps-page-dimensions-get-width dimensions)))
3878 (format " %d" (round (ps-page-dimensions-get-height dimensions)))
3879 " 0 () ()\n%%PageOrder: Ascend\n%%Pages: (atend)\n%%Requirements:"
3881 (format " duplex%s" (if tumble "(tumble)\n" "\n"))
3884 (ps-insert-string ps-print-prologue-header)
3886 (ps-output "%%EndComments\n\n%%BeginPrologue\n\n"
3887 "/languagelevel where{pop}{/languagelevel 1 def}ifelse\n"
3888 (format "/ErrorMessage %s def\n\n"
3889 (or (cdr (assoc ps-error-handler-message
3890 ps-error-handler-alist))
3893 "\n%%BeginProcSet: UserDefinedPrologue\n\n")
3895 (ps-insert-string ps-user-defined-prologue)
3897 (ps-output "\n%%EndProcSet\n\n")
3899 (ps-output-boolean "LandscapeMode "
3900 (or ps-landscape-mode
3901 (eq (ps-n-up-landscape n-up) 'pag)))
3902 (ps-output-boolean "UpsideDown " ps-print-upside-down)
3903 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns)
3905 (format "/LandscapePageHeight %s def\n" ps-landscape-page-height)
3906 (format "/PrintPageWidth %s def\n"
3907 (- (* (+ ps-print-width ps-inter-column)
3908 ps-number-of-columns)
3910 (format "/PrintWidth %s def\n" ps-print-width)
3911 (format "/PrintHeight %s def\n" ps-print-height)
3913 (format "/LeftMargin %s def\n" ps-left-margin)
3914 (format "/RightMargin %s def\n" ps-right-margin)
3915 (format "/InterColumn %s def\n" ps-inter-column)
3917 (format "/BottomMargin %s def\n" ps-bottom-margin)
3918 (format "/TopMargin %s def\n" ps-top-margin) ; not used
3919 (format "/HeaderOffset %s def\n" ps-header-offset)
3920 (format "/HeaderPad %s def\n" ps-header-pad))
3922 (ps-output-boolean "PrintHeader " ps-print-header)
3923 (ps-output-boolean "PrintOnlyOneHeader" ps-print-only-one-header)
3924 (ps-output-boolean "PrintHeaderFrame " ps-print-header-frame)
3925 (ps-output-boolean "ShowNofN " ps-show-n-of-n)
3926 (ps-output-boolean "DuplexValue " ps-spool-duplex)
3927 (ps-output-boolean "TumbleValue " tumble)
3929 (let ((line-height (ps-line-height 'ps-font-for-text)))
3930 (ps-output (format "/LineHeight %s def\n" line-height)
3931 (format "/LinesPerColumn %d def\n"
3932 (round (/ (+ ps-print-height
3933 (* line-height 0.45))
3936 (ps-output-boolean "Zebra " ps-zebra-stripes)
3937 (ps-output-boolean "PrintLineNumber " ps-line-number)
3938 (ps-output-boolean "SyncLineZebra " (not (integerp ps-line-number-step)))
3939 (ps-output (format "/PrintLineStep %d def\n"
3940 (if (integerp ps-line-number-step)
3943 (format "/ZebraHeight %d def\n" ps-zebra-stripe-height)
3945 (ps-format-color ps-zebra-color 0.95)
3946 "def\n/BackgroundColor "
3947 (ps-format-color ps-default-bg 1.0)
3948 "def\n/UseSetpagedevice "
3949 (if (eq ps-spool-config 'setpagedevice)
3950 "/setpagedevice where{pop languagelevel 2 eq}{false}ifelse"
3952 " def\n\n/PageWidth "
3953 "PrintPageWidth LeftMargin add RightMargin add def\n\n"
3954 (format "/N-Up %d def\n" ps-n-up-printing))
3955 (ps-output-boolean "N-Up-Landscape" (eq (ps-n-up-landscape n-up) t))
3956 (ps-output-boolean "N-Up-Border " ps-n-up-border-p)
3957 (ps-output (format "/N-Up-Lines %d def\n" (ps-n-up-lines n-up))
3958 (format "/N-Up-Columns %d def\n" (ps-n-up-columns n-up))
3959 (format "/N-Up-Missing %d def\n" (ps-n-up-missing n-up))
3960 (format "/N-Up-Margin %s def\n" ps-n-up-margin)
3962 (if ps-landscape-mode
3963 (ps-n-up-end n-up-filling)
3964 (ps-n-up-repeat n-up-filling))
3966 (if ps-landscape-mode
3967 (ps-n-up-repeat n-up-filling)
3968 (ps-n-up-end n-up-filling))
3969 " def\n/N-Up-XColumn " (ps-n-up-xcolumn n-up-filling)
3970 " def\n/N-Up-YColumn " (ps-n-up-ycolumn n-up-filling)
3971 " def\n/N-Up-XLine " (ps-n-up-xline n-up-filling)
3972 " def\n/N-Up-YLine " (ps-n-up-yline n-up-filling)
3973 " def\n/N-Up-XStart " (ps-n-up-xstart n-up-filling)
3974 " def\n/N-Up-YStart " (ps-n-up-ystart n-up-filling) " def\n")
3976 (ps-background-text)
3977 (ps-background-image)
3978 (setq ps-background-all-pages (nreverse ps-background-all-pages)
3979 ps-background-pages (nreverse ps-background-pages))
3981 (ps-output "\n" ps-print-prologue-1)
3983 (ps-output "\n/printGlobalBackground {\n")
3984 (ps-output-list ps-background-all-pages)
3985 (ps-output "} def\n/printLocalBackground {\n} def\n")
3988 (ps-output (format "/h0 %s (%s) cvn DefFont\n" ; /h0 14 /Helvetica-Bold DefFont
3989 ps-header-title-font-size-internal
3990 (ps-font 'ps-font-for-header 'bold))
3991 (format "/h1 %s (%s) cvn DefFont\n" ; /h1 12 /Helvetica DefFont
3992 ps-header-font-size-internal
3993 (ps-font 'ps-font-for-header 'normal)))
3995 (ps-output "\n" ps-print-prologue-2 "\n")
3998 (let ((font (ps-font-alist 'ps-font-for-text))
4001 (ps-output (format "/f%d %s (%s) cvn DefFont\n"
4003 ps-font-size-internal
4004 (ps-font 'ps-font-for-text (car (car font)))))
4005 (setq font (cdr font)
4008 (let ((font-entry (cdr (assq ps-font-family ps-font-info-database))))
4009 (ps-output (format "/SpaceWidthRatio %f def\n"
4010 (/ (ps-lookup 'space-width) (ps-lookup 'size)))))
4012 (ps-output "\n%%EndPrologue\n\n%%BeginSetup\n")
4013 (unless (eq ps-spool-config 'lpr-switches)
4014 (ps-output "\n%%BeginFeature: *Duplex "
4015 (ps-boolean-capitalized ps-spool-duplex)
4017 (ps-boolean-capitalized tumble)
4019 ps-print-duplex-feature
4020 "\n%%EndFeature\n")))
4021 (ps-output "\n/Lines 0 def\n/PageCount 0 def\n\nBeginDoc\n%%EndSetup\n")
4022 (and ps-banner-page-when-duplexing
4023 (ps-output "\n%%Page: 0 0\nsave showpage restore\n")))
4026 (defun ps-format-color (color &optional default)
4027 (let ((the-color (if (stringp color)
4028 (ps-color-scale color)
4030 (if (and the-color (listp the-color))
4032 (format ps-color-format
4037 (ps-float-format (if (numberp the-color) the-color default)))))
4040 (defun ps-insert-string (prologue)
4041 (let ((str (if (functionp prologue)
4048 (defun ps-boolean-capitalized (bool)
4049 (if bool "True" "False"))
4052 (defun ps-header-dirpart ()
4053 (let ((fname (buffer-file-name)))
4055 (if (string-equal (buffer-name) (file-name-nondirectory fname))
4056 (abbreviate-file-name (file-name-directory fname))
4061 (defun ps-get-buffer-name ()
4063 ;; Indulge Jim this little easter egg:
4064 ((string= (buffer-name) "ps-print.el")
4065 "Hey, Cool! It's ps-print.el!!!")
4066 ;; Indulge Jack this other little easter egg:
4067 ((string= (buffer-name) "sokoban.el")
4068 "Super! C'est sokoban.el!")
4070 (and ps-printing-region-p "Subset of: ")
4072 (and (buffer-modified-p) " (unsaved)")))))
4075 (defun ps-get-font-size (font-sym)
4076 (let ((font-size (symbol-value font-sym)))
4077 (cond ((numberp font-size)
4079 ((and (consp font-size)
4080 (numberp (car font-size))
4081 (numberp (cdr font-size)))
4082 (if ps-landscape-mode
4086 (error "Invalid font size `%S' for `%S'" font-size font-sym)))))
4089 (defun ps-begin-job ()
4090 (let ((last-char (aref ps-postscript-code-directory
4091 (1- (length ps-postscript-code-directory)))))
4092 (or (eq last-char ?/)
4093 (and ps-windows-system (eq last-char ?\\))
4094 (setq ps-postscript-code-directory
4095 (concat ps-postscript-code-directory "/"))))
4096 (or (equal ps-mark-code-directory ps-postscript-code-directory)
4097 (setq ps-print-prologue-0 (ps-prologue-file 0)
4098 ps-print-prologue-1 (ps-prologue-file 1)
4099 ps-print-prologue-2 (ps-prologue-file 2)
4100 ps-print-duplex-feature (ps-prologue-file 3)
4101 ps-mark-code-directory ps-postscript-code-directory))
4102 (or (listp ps-use-face-background)
4103 (setq ps-use-face-background t))
4104 (and (integerp ps-line-number-step)
4105 (<= ps-line-number-step 0)
4106 (setq ps-line-number-step 1))
4108 (set-buffer ps-spool-buffer)
4109 (goto-char (point-max))
4110 (and (re-search-backward "^%%Trailer$" nil t)
4111 (delete-region (match-beginning 0) (point-max))))
4112 (setq ps-showline-count (car ps-printing-region)
4114 ps-font-size-internal (ps-get-font-size 'ps-font-size)
4115 ps-header-font-size-internal (ps-get-font-size 'ps-header-font-size)
4116 ps-header-title-font-size-internal
4117 (ps-get-font-size 'ps-header-title-font-size)
4118 ps-control-or-escape-regexp
4119 (cond ((eq ps-print-control-characters '8-bit)
4120 (string-as-unibyte "[\000-\037\177-\377]"))
4121 ((eq ps-print-control-characters 'control-8-bit)
4122 (string-as-unibyte "[\000-\037\177-\237]"))
4123 ((eq ps-print-control-characters 'control)
4126 ps-default-foreground (ps-rgb-color ps-default-fg 0.0)
4127 ps-default-color (and ps-print-color-p ps-default-foreground)
4128 ps-current-color ps-default-color
4129 ;; Set the color scale. We do it here instead of in the defvar so
4130 ;; that ps-print can be dumped into emacs. This expression can't be
4131 ;; evaluated at dump-time because X isn't initialized.
4132 ps-color-p (and ps-print-color-p (ps-color-device))
4133 ps-print-color-scale (if ps-color-p
4134 (float (car (ps-color-values "white")))
4138 (defun ps-rgb-color (color default)
4139 (cond ((and color (listp color)) color)
4140 ((stringp color) (ps-color-scale color))
4141 ((numberp color) (list color color color))
4142 (t (list default default default))
4146 (defmacro ps-page-number ()
4147 `(1+ (/ (1- ps-page-count) ps-number-of-columns)))
4149 (defun ps-end-file (needs-begin-file)
4151 ;; Back to the PS output buffer to set the last page n-up printing
4153 (let ((pages-per-sheet (mod ps-page-postscript ps-n-up-printing))
4155 (set-buffer ps-spool-buffer)
4156 (goto-char (point-max))
4157 (and (> pages-per-sheet 0)
4158 (re-search-backward "^[0-9]+ BeginSheet$" nil t)
4159 (replace-match (format "%d BeginSheet" pages-per-sheet) t))))
4161 (and ps-spool-duplex (= (mod ps-page-order 2) 1)
4163 ;; Set end of PostScript file
4164 (ps-output "EndSheet\n\n%%Trailer\n%%Pages: "
4166 (if (and needs-begin-file ps-banner-page-when-duplexing)
4169 "\n\nEndDoc\n\n%%EOF\n"))
4172 (defun ps-next-page ()
4178 (defun ps-header-sheet ()
4179 ;; Print only when a new sheet begins.
4180 (setq ps-page-postscript (1+ ps-page-postscript)
4181 ps-page-order (1+ ps-page-order))
4182 (and (> ps-page-order 1)
4183 (ps-output "EndSheet\n"))
4184 (ps-output (format "\n%%%%Page: %d %d\n"
4185 ps-page-postscript ps-page-order))
4186 (ps-output (format "%d BeginSheet\nBeginDSCPage\n" ps-n-up-printing)))
4189 (defsubst ps-header-page ()
4190 ;; set total line and page number when printing has finished
4191 ;; (see `ps-generate')
4194 (zerop (mod ps-page-count ps-number-of-columns))
4195 (setq ps-page-count (1+ ps-page-count)))
4197 (if (zerop (mod ps-page-postscript ps-n-up-printing))
4198 ;; Print only when a new sheet begins.
4201 'ps-print-begin-sheet-hook)
4202 ;; Print only when a new page begins.
4203 (setq ps-page-postscript (1+ ps-page-postscript))
4204 (ps-output "BeginDSCPage\n")
4205 'ps-print-begin-page-hook)
4206 (ps-background ps-page-postscript))
4207 ;; Print only when a new column begins.
4208 (ps-output "BeginDSCPage\n")
4209 'ps-print-begin-column-hook)))
4211 (defun ps-begin-page ()
4212 (ps-get-page-dimensions)
4213 (setq ps-width-remaining ps-print-width
4214 ps-height-remaining ps-print-height)
4218 (ps-output (format "/LineNumber %d def\n" ps-showline-count)
4219 (format "/PageNumber %d def\n" (if ps-print-only-one-header
4223 (when ps-print-header
4224 (ps-generate-header "HeaderLinesLeft" ps-left-header)
4225 (ps-generate-header "HeaderLinesRight" ps-right-header)
4226 (ps-output (format "%d SetHeaderLines\n" ps-header-lines)))
4228 (ps-output "BeginPage\n")
4229 (ps-set-font ps-current-font)
4230 (ps-set-bg ps-current-bg)
4231 (ps-set-color ps-current-color)
4232 (ps-mule-begin-page))
4234 (defun ps-end-page ()
4235 (ps-output "EndPage\nEndDSCPage\n"))
4237 (defun ps-dummy-page ()
4238 (let ((ps-n-up-printing 0))
4240 (ps-output "/PrintHeader false def
4242 /PrintLineNumber false def
4246 (setq ps-page-postscript ps-n-up-printing))
4248 (defun ps-next-line ()
4249 (setq ps-showline-count (1+ ps-showline-count))
4250 (let ((lh (ps-line-height 'ps-font-for-text)))
4251 (if (< ps-height-remaining lh)
4253 (setq ps-width-remaining ps-print-width
4254 ps-height-remaining (- ps-height-remaining lh))
4255 (ps-output "HL\n"))))
4257 (defun ps-continue-line ()
4258 (let ((lh (ps-line-height 'ps-font-for-text)))
4259 (if (< ps-height-remaining lh)
4261 (setq ps-width-remaining ps-print-width
4262 ps-height-remaining (- ps-height-remaining lh))
4263 (ps-output "SL\n"))))
4265 (defun ps-find-wrappoint (from to char-width)
4266 (let ((avail (truncate (/ ps-width-remaining char-width)))
4269 (cons to (* todo char-width))
4270 (cons (+ from avail) ps-width-remaining))))
4272 (defun ps-basic-plot-string (from to &optional bg-color)
4273 (let* ((wrappoint (ps-find-wrappoint from to
4274 (ps-avg-char-width 'ps-font-for-text)))
4275 (to (car wrappoint))
4276 (string (buffer-substring-no-properties from to)))
4277 (ps-mule-prepare-ascii-font string)
4278 (ps-output-string string)
4282 (defun ps-basic-plot-whitespace (from to &optional bg-color)
4283 (let* ((wrappoint (ps-find-wrappoint from to
4284 (ps-space-width 'ps-font-for-text)))
4285 (to (car wrappoint)))
4286 (ps-output (format "%d W\n" (- to from)))
4289 (defun ps-plot (plotfunc from to &optional bg-color)
4291 (let* ((wrappoint (funcall plotfunc from to bg-color))
4292 (plotted-to (car wrappoint))
4293 (plotted-width (cdr wrappoint)))
4294 (setq from plotted-to
4295 ps-width-remaining (- ps-width-remaining plotted-width))
4297 (ps-continue-line))))
4298 (if ps-razzle-dazzle
4299 (let* ((q-todo (- (point-max) (point-min)))
4300 (q-done (- (point) (point-min)))
4301 (chunkfrac (/ q-todo 8))
4302 (chunksize (min chunkfrac 1000)))
4303 (if (> (- q-done ps-razchunk) chunksize)
4305 (setq ps-razchunk q-done)
4306 (message "Formatting...%3d%%"
4308 (/ (* 100 q-done) q-todo)
4309 (/ q-done (/ q-todo 100)))
4312 (defvar ps-last-font nil)
4314 (defun ps-set-font (font)
4315 (setq ps-last-font (format "f%d" (setq ps-current-font font)))
4316 (ps-output (format "/%s F\n" ps-last-font)))
4318 (defun ps-set-bg (color)
4319 (if (setq ps-current-bg color)
4320 (ps-output (format ps-color-format
4321 (nth 0 color) (nth 1 color) (nth 2 color))
4323 (ps-output "false BG\n")))
4325 (defun ps-set-color (color)
4326 (setq ps-current-color (or color ps-default-foreground))
4327 (ps-output (format ps-color-format
4328 (nth 0 ps-current-color)
4329 (nth 1 ps-current-color) (nth 2 ps-current-color))
4333 (defvar ps-current-effect 0)
4336 (defun ps-plot-region (from to font &optional fg-color bg-color effects)
4337 (if (not (equal font ps-current-font))
4340 ;; Specify a foreground color only if one's specified and it's
4341 ;; different than the current.
4342 (if (not (equal fg-color ps-current-color))
4343 (ps-set-color fg-color))
4345 (if (not (equal bg-color ps-current-bg))
4346 (ps-set-bg bg-color))
4348 ;; Specify effects (underline, overline, box, etc)
4350 ((not (integerp effects))
4351 (ps-output "0 EF\n")
4352 (setq ps-current-effect 0))
4353 ((/= effects ps-current-effect)
4354 (ps-output (number-to-string effects) " EF\n")
4355 (setq ps-current-effect effects)))
4357 ;; Starting at the beginning of the specified region...
4361 ;; ...break the region up into chunks separated by tabs, linefeeds,
4362 ;; pagefeeds, control characters, and plot each chunk.
4364 (if (re-search-forward ps-control-or-escape-regexp to t)
4365 ;; region with some control characters or some multi-byte characters
4366 (let* ((match-point (match-beginning 0))
4367 (match (char-after match-point))
4368 (composition (find-composition from (1+ match-point))))
4370 (if (and (nth 2 composition)
4371 (<= (car composition) match-point))
4373 (setq match-point (car composition)
4375 (goto-char (nth 1 composition)))
4376 (setq composition nil)))
4377 (when (< from match-point)
4378 (ps-mule-set-ascii-font)
4379 (ps-plot 'ps-basic-plot-string from match-point bg-color))
4381 ((= match ?\t) ; tab
4382 (let ((linestart (line-beginning-position)))
4384 (setq from (+ linestart (current-column)))
4385 (when (re-search-forward "[ \t]+" to t)
4386 (ps-mule-set-ascii-font)
4387 (ps-plot 'ps-basic-plot-whitespace
4388 from (+ linestart (current-column))
4391 ((= match ?\n) ; newline
4394 ((= match ?\f) ; form feed
4395 ;; do not skip page if previous character is NEWLINE and
4396 ;; it is a beginning of page.
4397 (or (and (= (char-after (1- match-point)) ?\n)
4398 (= ps-height-remaining ps-print-height))
4401 (composition ; a composite sequence
4402 (ps-plot 'ps-mule-plot-composition match-point (point) bg-color))
4404 ; characters from ^@ to ^_ and
4405 ((> match 255) ; a multi-byte character
4406 (let* ((charset (char-charset match))
4407 (composition (find-composition match-point to))
4408 (stop (if (nth 2 composition) (car composition) to)))
4409 (or (eq charset 'composition)
4410 (while (and (< (point) stop) (eq (charset-after) charset))
4412 (ps-plot 'ps-mule-plot-string match-point (point) bg-color)))
4414 (t ; characters from 127 to 255
4415 (ps-control-character match)))
4416 (setq from (point)))
4417 ;; region without control characters nor multi-byte characters
4418 (ps-mule-set-ascii-font)
4419 (ps-plot 'ps-basic-plot-string from to bg-color)
4422 (defvar ps-string-control-codes
4423 (let ((table (make-vector 256 nil))
4425 ;; control character
4426 (while (<= char ?\037)
4427 (aset table char (format "^%c" (+ char ?@)))
4428 (setq char (1+ char)))
4429 ;; printable character
4430 (while (< char ?\177)
4431 (aset table char (format "%c" char))
4432 (setq char (1+ char)))
4434 (aset table char "^?")
4436 (while (<= (setq char (1+ char)) ?\377)
4437 (aset table char (format "\\%o" char)))
4439 "Vector used to map characters to a printable string.")
4441 (defun ps-control-character (char)
4442 (let* ((str (aref ps-string-control-codes char))
4446 (char-width (ps-avg-char-width 'ps-font-for-text))
4447 (wrappoint (ps-find-wrappoint from to char-width)))
4448 (if (< (car wrappoint) to)
4450 (setq ps-width-remaining (- ps-width-remaining (* len char-width)))
4451 (ps-mule-prepare-ascii-font str)
4452 (ps-output-string str)
4453 (ps-output " S\n")))
4455 (defun ps-color-scale (color)
4456 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval.
4457 (mapcar #'(lambda (value) (/ value ps-print-color-scale))
4458 (ps-color-values color)))
4461 (cond ((eq ps-print-emacs-type 'emacs) ; emacs
4463 (defun ps-color-values (x-color)
4464 (if (fboundp 'x-color-values)
4465 (x-color-values x-color)
4466 (error "No available function to determine X color values.")))
4471 (defun ps-color-values (x-color)
4472 (let ((the-color (if (color-specifier-p x-color)
4473 (color-name x-color)
4476 ((fboundp 'x-color-values)
4477 (x-color-values the-color))
4478 ((and (fboundp 'color-instance-rgb-components)
4480 (color-instance-rgb-components
4481 (if (color-instance-p x-color)
4483 (make-color-instance the-color))))
4485 (error "No available function to determine X color values.")))))
4489 (defun ps-face-attributes (face)
4490 "Return face attribute vector.
4492 If FACE is not in `ps-print-face-extension-alist' or in
4493 `ps-print-face-alist', insert it on `ps-print-face-alist' and
4494 return the attribute vector.
4496 If FACE is not a valid face name, it is used default face."
4497 (cdr (or (assq face ps-print-face-extension-alist)
4498 (assq face ps-print-face-alist)
4499 (let* ((the-face (if (facep face) face 'default))
4500 (new-face (ps-screen-to-bit-face the-face)))
4501 (or (and (eq the-face 'default)
4502 (assq the-face ps-print-face-alist))
4503 (setq ps-print-face-alist (cons new-face ps-print-face-alist)))
4507 (defun ps-face-background (face background)
4508 (and (or (eq ps-use-face-background t)
4509 (cond ((symbolp face)
4510 (memq face ps-use-face-background))
4514 (if (memq (car face) ps-use-face-background)
4517 (setq face (cdr face))))
4525 (defun ps-face-attribute-list (face-or-list)
4526 (if (listp face-or-list)
4529 foreground background face-attr face)
4531 (setq face (car face-or-list)
4532 face-or-list (cdr face-or-list)
4533 face-attr (ps-face-attributes face)
4534 effects (logior effects (aref face-attr 0)))
4535 (or foreground (setq foreground (aref face-attr 1)))
4537 (setq background (ps-face-background face (aref face-attr 2)))))
4538 (vector effects foreground background))
4540 (ps-face-attributes face-or-list)))
4543 (defconst ps-font-type (vector nil 'bold 'italic 'bold-italic))
4546 (defun ps-plot-with-face (from to face)
4548 ((null face) ; print text with null face
4549 (ps-plot-region from to 0))
4550 ((eq face 'emacs--invisible--face)) ; skip invisible text!!!
4551 (t ; otherwise, text has a valid face
4552 (let* ((face-bit (ps-face-attribute-list face))
4553 (effect (aref face-bit 0))
4554 (foreground (aref face-bit 1))
4555 (background (ps-face-background face (aref face-bit 2)))
4556 (fg-color (if (and ps-color-p foreground)
4557 (ps-color-scale foreground)
4559 (bg-color (and ps-color-p background
4560 (ps-color-scale background))))
4563 (ps-font-number 'ps-font-for-text
4564 (or (aref ps-font-type (logand effect 3))
4566 fg-color bg-color (lsh effect -2)))))
4570 (defun ps-xemacs-face-kind-p (face kind kind-regex kind-list)
4571 (let* ((frame-font (or (face-font-instance face)
4572 (face-font-instance 'default)))
4573 (kind-cons (and frame-font
4575 (font-instance-properties frame-font))))
4576 (kind-spec (cdr-safe kind-cons))
4577 (case-fold-search t))
4578 (or (and kind-spec (string-match kind-regex kind-spec))
4579 ;; Kludge-compatible:
4580 (memq face kind-list))))
4583 (cond ((eq ps-print-emacs-type 'emacs) ; emacs
4585 (defun ps-face-bold-p (face)
4586 (or (face-bold-p face)
4587 (memq face ps-bold-faces)))
4589 (defun ps-face-italic-p (face)
4590 (or (face-italic-p face)
4591 (memq face ps-italic-faces)))
4596 (defun ps-face-bold-p (face)
4597 (ps-xemacs-face-kind-p face 'WEIGHT_NAME "bold\\|demibold"
4600 (defun ps-face-italic-p (face)
4601 (or (ps-xemacs-face-kind-p face 'ANGLE_NAME "i\\|o" ps-italic-faces)
4602 (ps-xemacs-face-kind-p face 'SLANT "i\\|o" ps-italic-faces)))
4606 (defun ps-face-underlined-p (face)
4607 (or (face-underline-p face)
4608 (memq face ps-underlined-faces)))
4611 ;; Ensure that face-list is fbound.
4612 (or (fboundp 'face-list) (defalias 'face-list 'list-faces))
4615 (defun ps-build-reference-face-lists ()
4616 ;; Ensure that face database is updated with faces on
4617 ;; `font-lock-face-attributes' (obsolete stuff)
4618 (ps-font-lock-face-attributes)
4619 ;; Now, rebuild reference face lists
4620 (setq ps-print-face-alist nil)
4621 (if ps-auto-font-detect
4622 (mapcar 'ps-map-face (face-list))
4623 (mapcar 'ps-set-face-bold ps-bold-faces)
4624 (mapcar 'ps-set-face-italic ps-italic-faces)
4625 (mapcar 'ps-set-face-underline ps-underlined-faces))
4626 (setq ps-build-face-reference nil))
4629 (defun ps-set-face-bold (face)
4630 (ps-set-face-attribute face 1))
4632 (defun ps-set-face-italic (face)
4633 (ps-set-face-attribute face 2))
4635 (defun ps-set-face-underline (face)
4636 (ps-set-face-attribute face 4))
4639 (defun ps-set-face-attribute (face effect)
4640 (let ((face-bit (cdr (ps-map-face face))))
4641 (aset face-bit 0 (logior (aref face-bit 0) effect))))
4644 (defun ps-map-face (face)
4645 (let* ((face-map (ps-screen-to-bit-face face))
4646 (ps-face-bit (cdr (assq (car face-map) ps-print-face-alist))))
4648 ;; if face exists, merge both
4649 (let ((face-bit (cdr face-map)))
4650 (aset ps-face-bit 0 (logior (aref ps-face-bit 0) (aref face-bit 0)))
4651 (or (aref ps-face-bit 1) (aset ps-face-bit 1 (aref face-bit 1)))
4652 (or (aref ps-face-bit 2) (aset ps-face-bit 2 (aref face-bit 2))))
4653 ;; if face does not exist, insert it
4654 (setq ps-print-face-alist (cons face-map ps-print-face-alist)))
4658 (defun ps-screen-to-bit-face (face)
4660 (vector (logior (if (ps-face-bold-p face) 1 0) ; bold
4661 (if (ps-face-italic-p face) 2 0) ; italic
4662 (if (ps-face-underlined-p face) 4 0)) ; underline
4663 (face-foreground face)
4664 (face-background face))))
4667 (cond ((not (eq ps-print-emacs-type 'emacs))
4671 (defun ps-mapper (extent list)
4672 (nconc list (list (list (extent-start-position extent) 'push extent)
4673 (list (extent-end-position extent) 'pull extent)))
4676 (defun ps-extent-sorter (a b)
4677 (< (extent-priority a) (extent-priority b)))
4681 (defun ps-print-ensure-fontified (start end)
4682 (and (boundp 'lazy-lock-mode) (symbol-value 'lazy-lock-mode)
4683 (lazy-lock-fontify-region start end)))
4685 (defun ps-generate-postscript-with-faces (from to)
4686 ;; Some initialization...
4687 (setq ps-current-effect 0)
4689 ;; Build the reference lists of faces if necessary.
4690 (if (or ps-always-build-face-reference
4691 ps-build-face-reference)
4693 (message "Collecting face information...")
4694 (ps-build-reference-face-lists)))
4695 ;; Generate some PostScript.
4697 (narrow-to-region from to)
4698 (ps-print-ensure-fontified from to)
4699 (let ((face 'default)
4702 ((or (eq ps-print-emacs-type 'lucid)
4703 (eq ps-print-emacs-type 'xemacs))
4704 ;; Build the list of extents...
4705 (let ((a (cons 'dummy nil))
4706 record type extent extent-list)
4707 (map-extents 'ps-mapper nil from to a)
4708 (setq a (sort (cdr a) 'car-less-than-car)
4711 ;; Loop through the extents...
4713 (setq record (car a)
4715 position (car record)
4721 extent (car record))
4723 ;; Plot up to this record.
4724 ;; XEmacs 19.12: for some reason, we're getting into a
4725 ;; situation in which some of the records have
4726 ;; positions less than 'from'. Since we've narrowed
4727 ;; the buffer, this'll generate errors. This is a
4728 ;; hack, but don't call ps-plot-with-face unless from >
4730 (and (>= from (point-min)) (<= position (point-max))
4731 (ps-plot-with-face from position face))
4735 (and (extent-face extent)
4736 (setq extent-list (sort (cons extent extent-list)
4737 'ps-extent-sorter))))
4740 (setq extent-list (sort (delq extent extent-list)
4741 'ps-extent-sorter))))
4743 (setq face (if extent-list
4744 (extent-face (car extent-list))
4749 ((eq ps-print-emacs-type 'emacs)
4750 (let ((property-change from)
4751 (overlay-change from)
4752 (save-buffer-invisibility-spec buffer-invisibility-spec)
4753 (buffer-invisibility-spec nil))
4755 (and (< property-change to) ; Don't search for property change
4756 ; unless previous search succeeded.
4757 (setq property-change (next-property-change from nil to)))
4758 (and (< overlay-change to) ; Don't search for overlay change
4759 ; unless previous search succeeded.
4760 (setq overlay-change (min (next-overlay-change from) to)))
4761 (setq position (min property-change overlay-change))
4762 ;; The code below is not quite correct,
4763 ;; because a non-nil overlay invisible property
4764 ;; which is inactive according to the current value
4765 ;; of buffer-invisibility-spec nonetheless overrides
4766 ;; a face text property.
4768 (cond ((let ((prop (get-text-property from 'invisible)))
4769 ;; Decide whether this invisible property
4770 ;; really makes the text invisible.
4771 (if (eq save-buffer-invisibility-spec t)
4773 (or (memq prop save-buffer-invisibility-spec)
4774 (assq prop save-buffer-invisibility-spec))))
4775 'emacs--invisible--face)
4776 ((get-text-property from 'face))
4778 (let ((overlays (overlays-at from))
4779 (face-priority -1)) ; text-property
4780 (while (and overlays
4781 (not (eq face 'emacs--invisible--face)))
4782 (let* ((overlay (car overlays))
4783 (overlay-invisible (overlay-get overlay 'invisible))
4784 (overlay-priority (or (overlay-get overlay 'priority)
4786 (and (> overlay-priority face-priority)
4788 (cond ((if (eq save-buffer-invisibility-spec t)
4789 (not (null overlay-invisible))
4790 (or (memq overlay-invisible
4791 save-buffer-invisibility-spec)
4792 (assq overlay-invisible
4793 save-buffer-invisibility-spec)))
4794 'emacs--invisible--face)
4795 ((overlay-get overlay 'face))
4797 face-priority overlay-priority)))
4798 (setq overlays (cdr overlays))))
4799 ;; Plot up to this record.
4800 (ps-plot-with-face from position face)
4801 (setq from position)))))
4802 (ps-plot-with-face from to face))))
4804 (defun ps-generate-postscript (from to)
4805 (ps-plot-region from to 0 nil))
4807 (defun ps-generate (buffer from to genfunc)
4809 (let ((from (min to from))
4811 ;; This avoids trouble if chars with read-only properties
4812 ;; are copied into ps-spool-buffer.
4813 (inhibit-read-only t))
4815 (narrow-to-region from to)
4816 (and ps-razzle-dazzle
4817 (message "Formatting...%3d%%" (setq ps-razchunk 0)))
4818 (setq ps-source-buffer buffer
4819 ps-spool-buffer (get-buffer-create ps-spool-buffer-name))
4820 (ps-init-output-queue)
4821 (let (safe-marker completed-safely needs-begin-file)
4824 (set-buffer ps-spool-buffer)
4825 (set-buffer-multibyte nil)
4827 ;; Get a marker and make it point to the current end of the
4828 ;; buffer, If an error occurs, we'll delete everything from
4829 ;; the end of this marker onwards.
4830 (setq safe-marker (make-marker))
4831 (set-marker safe-marker (point-max))
4833 (goto-char (point-min))
4834 (or (looking-at (regexp-quote ps-adobe-tag))
4835 (setq needs-begin-file t))
4837 (set-buffer ps-source-buffer)
4839 (when needs-begin-file
4841 (ps-mule-initialize))
4842 (ps-mule-begin-job from to)
4844 (set-buffer ps-source-buffer)
4845 (funcall genfunc from to)
4848 (ps-end-file needs-begin-file)
4851 ;; Setting this variable tells the unwind form that the
4852 ;; the PostScript was generated without error.
4853 (setq completed-safely t))
4855 ;; Unwind form: If some bad mojo occurred while generating
4856 ;; PostScript, delete all the PostScript that was generated.
4857 ;; This protects the previously spooled files from getting
4859 (and (markerp safe-marker) (not completed-safely)
4861 (set-buffer ps-spool-buffer)
4862 (delete-region (marker-position safe-marker) (point-max))))))
4864 (and ps-razzle-dazzle (message "Formatting...done"))))))
4867 (defun ps-end-job ()
4869 (let ((total-lines (cdr ps-printing-region))
4870 (total-pages (if ps-print-only-one-header
4874 (set-buffer ps-spool-buffer)
4875 ;; Back to the PS output buffer to set the page count
4876 (goto-char (point-min))
4877 (and (re-search-forward "^/Lines 0 def\n/PageCount 0 def$" nil t)
4878 (replace-match (format "/Lines %d def\n/PageCount %d def"
4879 total-lines total-pages) t))))
4882 (defconst ps-printer-name-option
4883 (cond (ps-windows-system
4891 ;; Permit dynamic evaluation at print time of `ps-lpr-switches'.
4892 (defun ps-do-despool (filename)
4893 (if (or (not (boundp 'ps-spool-buffer))
4894 (not (symbol-value 'ps-spool-buffer)))
4895 (message "No spooled PostScript to print")
4898 (and ps-razzle-dazzle (message "Saving..."))
4899 (set-buffer ps-spool-buffer)
4900 (setq filename (expand-file-name filename))
4901 (let ((coding-system-for-write 'raw-text-unix))
4902 (write-region (point-min) (point-max) filename))
4903 (and ps-razzle-dazzle (message "Wrote %s" filename)))
4904 ;; Else, spool to the printer
4905 (and ps-razzle-dazzle (message "Printing..."))
4907 (set-buffer ps-spool-buffer)
4908 (let* ((coding-system-for-write 'raw-text-unix)
4909 (ps-printer-name (or ps-printer-name
4910 (and (boundp 'printer-name)
4913 (append (and (stringp ps-printer-name)
4914 (list (concat ps-printer-name-option
4917 (apply (or ps-print-region-function 'call-process-region)
4918 (point-min) (point-max) ps-lpr-command nil
4919 (and (fboundp 'start-process) 0)
4921 (ps-flatten-list ; dynamic evaluation
4922 (mapcar 'ps-eval-switch ps-lpr-switches)))))
4923 (and ps-razzle-dazzle (message "Printing...done")))
4924 (kill-buffer ps-spool-buffer)))
4926 ;; Dynamic evaluation
4927 (defun ps-eval-switch (arg)
4928 (cond ((stringp arg) arg)
4929 ((functionp arg) (apply arg nil))
4930 ((symbolp arg) (symbol-value arg))
4931 ((consp arg) (apply (car arg) (cdr arg)))
4934 ;; `ps-flatten-list' is defined here (copied from "message.el" and
4935 ;; enhanced to handle dotted pairs as well) until we can get some
4936 ;; sensible autoloads, or `flatten-list' gets put somewhere decent.
4938 ;; (ps-flatten-list '((a . b) c (d . e) (f g h) i . j))
4939 ;; => (a b c d e f g h i j)
4941 (defun ps-flatten-list (&rest list)
4942 (ps-flatten-list-1 list))
4944 (defun ps-flatten-list-1 (list)
4945 (cond ((null list) nil)
4946 ((consp list) (append (ps-flatten-list-1 (car list))
4947 (ps-flatten-list-1 (cdr list))))
4950 (defun ps-kill-emacs-check ()
4952 (and (setq ps-buffer (get-buffer ps-spool-buffer-name))
4953 (buffer-modified-p ps-buffer)
4954 (y-or-n-p "Unprinted PostScript waiting; print now? ")
4956 (and (setq ps-buffer (get-buffer ps-spool-buffer-name))
4957 (buffer-modified-p ps-buffer)
4958 (not (yes-or-no-p "Unprinted PostScript waiting; exit anyway? "))
4959 (error "Unprinted PostScript"))))
4961 (cond ((fboundp 'add-hook)
4962 (funcall 'add-hook 'kill-emacs-hook 'ps-kill-emacs-check))
4964 (message "Won't override existing `kill-emacs-hook'"))
4966 (setq kill-emacs-hook 'ps-kill-emacs-check)))
4969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4970 ;;; Sample Setup Code:
4973 ;; This stuff is for anybody that's brave enough to look this far,
4974 ;; and able to figure out how to use it. It isn't really part of
4975 ;; ps-print, but I'll leave it here in hopes it might be useful:
4977 ;; WARNING!!! The following code is *sample* code only.
4978 ;; Don't use it unless you understand what it does!
4980 (defmacro ps-prsc ()
4981 `(if (eq ps-print-emacs-type 'emacs) [f22] 'f22))
4982 (defmacro ps-c-prsc ()
4983 `(if (eq ps-print-emacs-type 'emacs) [C-f22] '(control f22)))
4984 (defmacro ps-s-prsc ()
4985 `(if (eq ps-print-emacs-type 'emacs) [S-f22] '(shift f22)))
4987 ;; A hook to bind to `rmail-mode-hook' to locally bind prsc and set the
4988 ;; `ps-left-headers' specially for mail messages.
4989 (defun ps-rmail-mode-hook ()
4990 (local-set-key (ps-prsc) 'ps-rmail-print-message-from-summary)
4991 (setq ps-header-lines 3
4993 ;; The left headers will display the message's subject, its
4994 ;; author, and the name of the folder it was in.
4995 '(ps-article-subject ps-article-author buffer-name)))
4997 ;; See `ps-gnus-print-article-from-summary'. This function does the
4998 ;; same thing for rmail.
4999 (defun ps-rmail-print-message-from-summary ()
5001 (ps-print-message-from-summary 'rmail-summary-buffer "RMAIL"))
5003 ;; Used in `ps-rmail-print-article-from-summary',
5004 ;; `ps-gnus-print-article-from-summary' and `ps-vm-print-message-from-summary'.
5005 (defun ps-print-message-from-summary (summary-buffer summary-default)
5006 (let ((ps-buf (or (and (boundp summary-buffer)
5007 (symbol-value summary-buffer))
5009 (and (get-buffer ps-buf)
5012 (ps-spool-buffer-with-faces)))))
5014 ;; Look in an article or mail message for the Subject: line. To be
5015 ;; placed in `ps-left-headers'.
5016 (defun ps-article-subject ()
5018 (goto-char (point-min))
5019 (if (re-search-forward "^Subject:[ \t]+\\(.*\\)$" nil t)
5020 (buffer-substring (match-beginning 1) (match-end 1))
5023 ;; Look in an article or mail message for the From: line. Sorta-kinda
5024 ;; understands RFC-822 addresses and can pull the real name out where
5025 ;; it's provided. To be placed in `ps-left-headers'.
5026 (defun ps-article-author ()
5028 (goto-char (point-min))
5029 (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
5030 (let ((fromstring (buffer-substring (match-beginning 1) (match-end 1))))
5033 ;; Try first to match addresses that look like
5034 ;; thompson@wg2.waii.com (Jim Thompson)
5035 ((string-match ".*[ \t]+(\\(.*\\))" fromstring)
5036 (substring fromstring (match-beginning 1) (match-end 1)))
5038 ;; Next try to match addresses that look like
5039 ;; Jim Thompson <thompson@wg2.waii.com> or
5040 ;; "Jim Thompson" <thompson@wg2.waii.com>
5041 ((string-match "\\(\"?\\)\\(.*\\)\\1[ \t]+<.*>" fromstring)
5042 (substring fromstring (match-beginning 2) (match-end 2)))
5044 ;; Couldn't find a real name -- show the address instead.
5048 ;; A hook to bind to `gnus-article-prepare-hook'. This will set the
5049 ;; `ps-left-headers' specially for gnus articles. Unfortunately,
5050 ;; `gnus-article-mode-hook' is called only once, the first time the *Article*
5051 ;; buffer enters that mode, so it would only work for the first time
5052 ;; we ran gnus. The second time, this hook wouldn't get set up. The
5053 ;; only alternative is `gnus-article-prepare-hook'.
5054 (defun ps-gnus-article-prepare-hook ()
5055 (setq ps-header-lines 3
5057 ;; The left headers will display the article's subject, its
5058 ;; author, and the newsgroup it was in.
5059 '(ps-article-subject ps-article-author gnus-newsgroup-name)))
5061 ;; A hook to bind to `vm-mode-hook' to locally bind prsc and set the
5062 ;; `ps-left-headers' specially for mail messages.
5063 (defun ps-vm-mode-hook ()
5064 (local-set-key (ps-prsc) 'ps-vm-print-message-from-summary)
5065 (setq ps-header-lines 3
5067 ;; The left headers will display the message's subject, its
5068 ;; author, and the name of the folder it was in.
5069 '(ps-article-subject ps-article-author buffer-name)))
5071 ;; Every now and then I forget to switch from the *Summary* buffer to
5072 ;; the *Article* before hitting prsc, and a nicely formatted list of
5073 ;; article subjects shows up at the printer. This function, bound to
5074 ;; prsc for the gnus *Summary* buffer means I don't have to switch
5076 ;; sb: Updated for Gnus 5.
5077 (defun ps-gnus-print-article-from-summary ()
5079 (ps-print-message-from-summary 'gnus-article-buffer "*Article*"))
5081 ;; See `ps-gnus-print-article-from-summary'. This function does the
5082 ;; same thing for vm.
5083 (defun ps-vm-print-message-from-summary ()
5085 (ps-print-message-from-summary 'vm-mail-buffer ""))
5087 ;; A hook to bind to bind to `gnus-summary-setup-buffer' to locally bind
5089 (defun ps-gnus-summary-setup ()
5090 (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary))
5092 ;; Look in an article or mail message for the Subject: line. To be
5093 ;; placed in `ps-left-headers'.
5094 (defun ps-info-file ()
5096 (goto-char (point-min))
5097 (if (re-search-forward "File:[ \t]+\\([^, \t\n]*\\)" nil t)
5098 (buffer-substring (match-beginning 1) (match-end 1))
5101 ;; Look in an article or mail message for the Subject: line. To be
5102 ;; placed in `ps-left-headers'.
5103 (defun ps-info-node ()
5105 (goto-char (point-min))
5106 (if (re-search-forward "Node:[ \t]+\\([^,\t\n]*\\)" nil t)
5107 (buffer-substring (match-beginning 1) (match-end 1))
5110 (defun ps-info-mode-hook ()
5111 (setq ps-left-header
5112 ;; The left headers will display the node name and file name.
5113 '(ps-info-node ps-info-file)))
5115 ;; WARNING! The following function is a *sample* only, and is *not*
5116 ;; meant to be used as a whole unless you understand what the effects
5117 ;; will be! (In fact, this is a copy of Jim's setup for ps-print --
5118 ;; I'd be very surprised if it was useful to *anybody*, without
5121 (defun ps-jts-ps-setup ()
5122 (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc
5123 (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces)
5124 (global-set-key (ps-c-prsc) 'ps-despool)
5125 (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook)
5126 (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup)
5127 (add-hook 'vm-mode-hook 'ps-vm-mode-hook)
5128 (add-hook 'vm-mode-hooks 'ps-vm-mode-hook)
5129 (add-hook 'Info-mode-hook 'ps-info-mode-hook)
5130 (setq ps-spool-duplex t
5131 ps-print-color-p nil
5132 ps-lpr-command "lpr"
5133 ps-lpr-switches '("-Jjct,duplex_long"))
5136 ;; WARNING! The following function is a *sample* only, and is *not*
5137 ;; meant to be used as a whole unless it corresponds to your needs.
5138 ;; (In fact, this is a copy of Jack's setup for ps-print --
5139 ;; I would not be that surprised if it was useful to *anybody*,
5140 ;; without modification.)
5142 (defun ps-jack-setup ()
5143 (setq ps-print-color-p nil
5144 ps-lpr-command "lpr"
5149 ps-number-of-columns 2
5151 ps-left-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
5152 ps-right-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
5153 ps-inter-column (/ (* 72 1.0) 2.54) ; 1.0 cm
5154 ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
5155 ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
5156 ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
5157 ps-header-line-pad .15
5159 ps-print-header-frame t
5164 ps-font-family 'Courier
5166 ps-header-font-family 'Helvetica
5167 ps-header-font-size 6
5168 ps-header-title-font-size 8)
5172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5173 ;; To make this file smaller, some commands go in a separate file.
5174 ;; But autoload them here to make the separation invisible.
5176 (autoload 'ps-mule-prepare-ascii-font "ps-mule"
5177 "Setup special ASCII font for STRING.
5178 STRING should contain only ASCII characters.")
5180 (autoload 'ps-mule-set-ascii-font "ps-mule"
5181 "Adjust current font if current charset is not ASCII.")
5183 (autoload 'ps-mule-plot-string "ps-mule"
5184 "Generate PostScript code for ploting characters in the region FROM and TO.
5186 It is assumed that all characters in this region belong to the same charset.
5188 Optional argument BG-COLOR specifies background color.
5192 (ENDPOS . RUN-WIDTH)
5194 Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of
5197 (autoload 'ps-mule-initialize "ps-mule"
5198 "Initialize global data for printing multi-byte characters.")
5200 (autoload 'ps-mule-begin-job "ps-mule"
5201 "Start printing job for multi-byte chars between FROM and TO.
5202 This checks if all multi-byte characters in the region are printable or not.")
5204 (autoload 'ps-mule-begin-page "ps-mule"
5205 "Initialize multi-byte charset for printing current page.")
5208 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5212 ;;; ps-print.el ends here